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".
5 * Author: Ceriel J.H. Jacobs
8 /* E X P R E S S I O N S */
10 /* $Id: expression.g,v 1.48 1994/06/24 12:40:50 ceriel Exp $ */
28 extern char options[];
31 /* inline, we need room for pdp/11
38 ] { *p = dot2leaf(Value);
39 (*p)->nd_type = toktype;
44 qualident(t_node **p;)
47 IDENT { *p = dot2leaf(Name); }
53 selector(register t_node **pnd;)
56 '.' { nd = dot2leaf(Select); nd->nd_NEXT = *pnd; *pnd = nd; }
57 IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; }
60 ExpList(t_node **pnd;)
64 expression(pnd) { *pnd = nd = dot2node(Link,*pnd,NULLNODE);
68 ',' { nd->nd_RIGHT = dot2leaf(Link);
71 expression(&(nd->nd_LEFT))
75 ConstExpression(register t_node **pnd;)
80 * Changed rule in new Modula-2.
81 * Check that the expression is a constant expression and evaluate!
84 DO_DEBUG(options['C'], print("CONSTANT EXPRESSION\n"));
85 DO_DEBUG(options['C'], PrNode(*pnd, 0));
87 if (ChkExpression(pnd) &&
88 (*pnd)->nd_class != Set &&
89 (*pnd)->nd_class != Value &&
90 ! (options['l'] && (*pnd)->nd_class == Def && IsProc((*pnd)))) {
91 error("constant expression expected");
94 DO_DEBUG(options['C'], print("RESULTS IN\n"));
95 DO_DEBUG(options['C'], PrNode(*pnd, 0));
99 expression(register t_node **pnd;)
102 SimpleExpression(pnd)
105 [ '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ]
106 { *pnd = dot2node(Oper, *pnd, NULLNODE); }
107 SimpleExpression(&((*pnd)->nd_RIGHT))
112 /* Inline in expression
114 '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN
118 SimpleExpression(register t_node **pnd;)
120 register t_node *nd = 0;
124 { nd = dot2leaf(Uoper);
125 /* priority of unary operator ??? */
139 { nd = dot2node(Oper, nd, NULLNODE); }
140 term(&(nd->nd_RIGHT))
145 /* Inline in "SimpleExpression"
155 factor(pnd) { nd = *pnd; }
158 [ '*' | '/' | DIV | MOD | AND ]
159 { nd = dot2node(Oper, nd, NULLNODE); }
160 factor(&(nd->nd_RIGHT))
167 '*' | '/' | DIV | MOD | AND
171 factor(register t_node **p;)
180 { *p = dot2node(Call, *p, NULLNODE); }
181 ActualParameters(&((*p)->nd_RIGHT))
186 { nd = nd1; nd->nd_LEFT = *p; *p = nd; }
198 ] { *p = dot2leaf(Value);
199 (*p)->nd_type = toktype;
202 '(' { nd = dot2leaf(Uoper); }
204 { /* In some cases we must leave the '(' as an unary
205 operator, because otherwise we cannot see that the
206 factor was not a designator
208 register int class = (*p)->nd_class;
210 if (class == Arrsel ||
221 NOT { *p = dot2leaf(Uoper); }
222 factor(&((*p)->nd_RIGHT))
225 bare_set(t_node **pnd;)
230 *pnd = nd = dot2leaf(Xset);
231 nd->nd_type = bitset_type;
235 [ { nd = nd->nd_RIGHT; }
243 ActualParameters(t_node **pnd;):
244 '(' ExpList(pnd)? ')'
247 element(register t_node *nd;) :
248 expression(&(nd->nd_RIGHT))
251 { nd->nd_RIGHT = dot2node(Link, nd->nd_RIGHT, NULLNODE);}
252 expression(&(nd->nd_RIGHT->nd_RIGHT))
255 { nd->nd_RIGHT = dot2node(Link, nd->nd_RIGHT, NULLNODE);
256 nd->nd_RIGHT->nd_symb = ',';
260 designator(t_node **pnd;)
266 designator_tail(register t_node **pnd;):
267 visible_designator_tail(pnd)
272 visible_designator_tail(pnd)
277 visible_designator_tail(t_node **pnd;)
279 register t_node *nd = *pnd;
281 '[' { nd = dot2node(Arrsel, nd, NULLNODE); }
282 expression(&(nd->nd_RIGHT))
285 { nd = dot2node(Arrsel, nd, NULLNODE);
287 expression(&(nd->nd_RIGHT))
292 '^' { *pnd = dot2node(Arrow, NULLNODE, nd); }