Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / m2mm / statement.g
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  *
5  * Author: Ceriel J.H. Jacobs
6  */
7
8 /* S T A T E M E N T S */
9
10 /* stripped down version from the one in the Modula-2 compiler */
11
12 /* $Id: statement.g,v 1.3 1997/02/21 17:22:42 ceriel Exp $ */
13
14 {
15 #include        "idf.h"
16 #include        "LLlex.h"
17
18 static int loopcount;
19 }
20
21 statement :
22 [
23         /*
24          * This part is not in the reference grammar. The reference grammar
25          * states : assignment | ProcedureCall | ...
26          * but this gives LL(1) conflicts
27          */
28         designator
29         [
30                 ActualParameters?
31         |
32                 [ BECOMES       
33                 | %erroneous
34                   '='           { error("':=' expected instead of '='");
35                                   DOT = BECOMES;
36                                 }
37                 ]
38                 expression
39         ]
40         /*
41          * end of changed part
42          */
43 |
44         IfStatement
45 |
46         CaseStatement
47 |
48         WHILE
49         expression
50         DO
51         StatementSequence
52         END
53 |
54         REPEAT
55         StatementSequence
56         UNTIL
57         expression
58 |
59                                 { loopcount++; }
60         LOOP
61         StatementSequence
62         END
63                                 { loopcount--; }
64 |
65         ForStatement
66 |
67         WithStatement
68 |
69         EXIT
70                         { if (!loopcount) error("EXIT not in a LOOP"); }
71 |
72         ReturnStatement
73 |
74         /* empty */
75 ]
76 ;
77
78 StatementSequence :
79         statement
80         [ %persistent
81                 ';'
82                 statement
83         ]*
84 ;
85
86 IfStatement :
87         IF expression
88         THEN StatementSequence
89         [
90                 ELSIF expression
91                 THEN StatementSequence
92         ]*
93         [
94                 ELSE StatementSequence
95         ]?
96         END
97 ;
98
99 CaseStatement :
100         CASE expression
101         OF case
102         [
103                 '|' case
104         ]*
105         [ ELSE StatementSequence
106         ]?
107         END
108 ;
109
110 case :
111         [ CaseLabelList ':'
112           StatementSequence
113         ]?
114 ;
115
116 ForStatement :
117         FOR IDENT BECOMES expression TO expression
118         [
119                 BY ConstExpression
120         |
121         ]
122         DO StatementSequence
123         END
124 ;
125
126 WithStatement :
127         WITH designator DO StatementSequence
128         END
129 ;
130
131 ReturnStatement :
132         RETURN
133         [
134                 expression
135         |
136         ]
137 ;