Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / m2mm / expression.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 /* E X P R E S S I O N S */
9
10 /* stripped down version of the one in the Modula-2 compiler */
11
12 /* $Id: expression.g,v 1.3 1994/06/24 12:44:53 ceriel Exp $ */
13
14 qualident :
15         IDENT
16         [
17                 selector
18         ]*
19 ;
20
21 selector :
22         '.' IDENT
23 ;
24
25 ExpList :
26         expression
27         [
28                 ',' expression
29         ]*
30 ;
31
32 ConstExpression :
33         expression
34         /*
35          * Changed rule in new Modula-2.
36          */
37 ;
38
39 expression :
40         SimpleExpression
41         [
42                 /* relation */
43                 [ '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ]
44                 SimpleExpression
45         |
46                 /* empty */
47         ]
48 ;
49
50 SimpleExpression :
51         [
52                 '+' 
53         |
54                 '-'
55         |
56                 /* empty */
57         ]
58         term
59         [
60                 /* AddOperator */
61                 [ '+' | '-' | OR ] term
62         ]*
63 ;
64
65 term :
66         factor
67         [
68                 /* MulOperator */
69                 [ '*' | '/' | DIV | MOD | AND ] factor
70         ]*
71 ;
72
73 factor :
74         qualident
75         [
76                 designator_tail?
77                 [
78                         ActualParameters
79                 |
80                         /* empty */
81                 ]
82         |
83                 bare_set
84         ]
85 |
86         bare_set
87 | %default
88         [ %default
89                 INTEGER
90         |
91                 REAL
92         |
93                 STRING
94         ]
95 |
96         '(' expression ')'
97 |
98         NOT factor
99 ;
100
101 bare_set :
102         '{'
103         [
104                 element
105                 [
106                         ',' element
107                 ]*
108         |
109                 /* empty */
110         ]
111         '}'
112 ;
113
114 ActualParameters :
115         '(' ExpList? ')'
116 ;
117
118 element :
119         expression
120         [
121                 UPTO expression
122         |
123                 /* empty */
124         ]
125 ;
126
127 designator :
128         qualident designator_tail?
129 ;
130
131 designator_tail :
132         visible_designator_tail
133         [ %persistent
134             %default
135                 selector
136         |
137                 visible_designator_tail
138         ]*
139 ;
140
141 visible_designator_tail :
142         '['
143                 expression
144                 [
145                         ',' expression
146                 ]*
147         ']'
148 |
149         '^'
150 ;