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;
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;