]> git.mdlowis.com Git - proto/obnc.git/commitdiff
Added declarations section to procedure declarations
authormike lowis <mike@mdlowis.com>
Tue, 4 May 2021 03:14:52 +0000 (23:14 -0400)
committermike lowis <mike@mdlowis.com>
Tue, 4 May 2021 03:14:52 +0000 (23:14 -0400)
cerise/src/grammar.c
cerise/tests/Module.m

index d0287d0183a69cd8d2a430ae5a7942a8d92e2388..5ffb654378ed627f6ffa3143f7149f1fe836fe00 100644 (file)
@@ -370,33 +370,6 @@ RULE(statement_seq)
     while (!matches(p, END) && !matches(p, ELSE) && !matches(p, ELSIF) && !matches(p, RETURN));
 }
 
-RULE(proc_decl)
-{
-    expect(p, PROCEDURE);
-    (void)expect_text(p, IDENT);
-    (void)accept(p, '*');
-    expect(p, '(');
-    while (!matches(p, ')'))
-    {
-        (void)expect_text(p, IDENT);
-        expect(p, ':');
-        type(p, item);
-    }
-    expect(p, ')');
-    if (accept(p, ':'))
-    {
-        type(p, item);
-    }
-    expect(p, BEGIN);
-    statement_seq(p, item);
-    if (accept(p, RETURN))
-    {
-        expression(p, item);
-        expect(p, ';');
-    }
-    expect(p, END);
-}
-
 RULE(var_decl)
 {
     (void)item;
@@ -471,6 +444,59 @@ RULE(const_decl)
     while (matches(p, IDENT));
 }
 
+RULE(proc_decl)
+{
+    expect(p, PROCEDURE);
+    (void)expect_text(p, IDENT);
+    (void)accept(p, '*');
+
+    /* construct the proc type */
+    expect(p, '(');
+    while (!matches(p, ')'))
+    {
+        (void)expect_text(p, IDENT);
+        expect(p, ':');
+        type(p, item);
+    }
+    expect(p, ')');
+    if (accept(p, ':'))
+    {
+        type(p, item);
+    }
+
+    /* parse the declarations */
+    if (accept(p, CONST))
+    {
+        const_decl(p, item);
+    }
+
+    if (accept(p, TYPE))
+    {
+        type_decl(p, item);
+    }
+
+    if (accept(p, VAR))
+    {
+        var_decl(p, item);
+    }
+
+    while (matches(p, PROCEDURE))
+    {
+        proc_decl(p, item);
+    }
+
+    /* parse the body of the procedure */
+    expect(p, BEGIN);
+    statement_seq(p, item);
+    if (accept(p, RETURN))
+    {
+        expression(p, item);
+        expect(p, ';');
+    }
+    expect(p, END);
+}
+
+
 RULE(import_list)
 {
     (void)item;
index 2cd4ebad1171f10c6fd824e72c1ad9f2114813f8..9d8dbdf784d61a0f8945865e5976bb7d89ec1dc7 100644 (file)
@@ -19,7 +19,10 @@ var
   b : Int
   c : Int
 
-procedure Foo*(e : Int)
+procedure Foo*(e : Int) : Int
+  const FOO = 2
+#  type foo : Int
+  var z : Int
 begin
   c = b * b;
   return c;