1 /* $Id: comm2.y,v 2.12 1994/06/24 13:21:58 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
9 * delay inclusion of machine dependent stuff (see comm0.h)
11 #define _include #include
17 static item_t *last_it, *o_it;
20 /* ========== Machine independent Yacc definitions ========== */
33 %token <y_strp> MODULE
41 %token NUMBER0 /* keep NUMBER* in this order */
45 %token <y_valu> NUMBER
76 %left '<' '>' OP_LE OP_GE
82 %type <y_valu> absexp optabs1 optabs2
86 /* ========== Machine dependent Yacc definitions ========== */
92 /* ========== Machine independent rules ========== */
95 #define LISTLINE(n) if (listflag) listline(n); \
96 else if (listtemp) { listflag = listtemp; listeoln = 1; }
98 #define LISTLINE(n) /* empty */
102 #define RELODONE /* empty */
104 #define RELODONE assert(relonami == 0)
107 program : /* empty */
109 | program MODULE /* not in PASS_1 */
113 { newident($2, DOTTYP); newlabel($2);}
115 { if ($2 < 0 || $2 > 9) {
116 serror("bad f/b label");
119 newlabel(fb_shift((int)$2));
122 { emit1((int)$2); LISTLINE(0);}
124 { emit2((int)$2); LISTLINE(0);}
126 { emit4((long)$2); LISTLINE(0);}
127 | program operation ';'
128 | program operation '\n'
129 { lineno++; LISTLINE(1); RELODONE;}
130 | program '#' NUMBER STRING '\n'
132 if (modulename) strncpy(modulename, stringbuf, STRINGMAX-1);
133 LISTLINE(1); RELODONE;
136 { serror("syntax error"); yyerrok;
137 lineno++; LISTLINE(1); RELODONE;
148 listcolm += printx(VALWIDTH, $3.val);
150 newequate($1, $3.typ);
157 else if ((dflag & 01000) == 0)
163 | COMMON IDENT ',' absexp
166 { if (pass == PASS_1) newbase($2);}
168 { if ($2.val == 0 && pass == PASS_3)
169 warning("assertion failed");
171 | SYMB STRING ',' expr { o_it = last_it; }
173 { if ((sflag & SYM_SMB) && PASS_SYMB) {
178 ($4.typ & S_TYP) == S_UND
180 serror("expression undefined");
188 /* No value is known at
190 Generate reference to other
194 $4.val = new_string(o_it->i_name);
200 *stringbuf ? stringbuf : (char *) 0,
202 ($4.typ & (S_EXT|S_TYP))
204 ((unsigned short)$6<<8)
211 | SYMD STRING ',' absexp ',' absexp
212 { if ((sflag & SYM_SMB) && PASS_SYMB) {
214 *stringbuf ? stringbuf : (char *) 0,
216 (DOTTYP & (S_EXT|S_TYP))
218 ((unsigned short)$4<<8)
226 { if ((sflag & SYM_LIN) && PASS_SYMB) {
240 { if ((sflag & SYM_LIN) && PASS_SYMB) {
254 { if (DOTSCT == NULL)
257 DOTSCT->s_zero += $2;
265 { $1->i_type |= S_EXT;}
266 | externlist ',' IDENT
267 { $3->i_type |= S_EXT;}
273 if (rflag != 0 && PASS_RELO)
274 newrelo($1.typ, (int)$<y_word>0|MACHREL_BWR);
276 emitx($1.val, (int)$<y_word>0);
281 if (rflag != 0 && PASS_RELO)
282 newrelo($3.typ, (int)$<y_word>0|MACHREL_BWR);
284 emitx($3.val, (int)$<y_word>0);
288 { serror("expr syntax err");
289 $$.val = 0; $$.typ = S_UND;
292 { $$.val = $1; $$.typ = S_ABS;}
296 $$.typ = $1->i_type & ~S_EXT;
299 { if (stringlen != 1)
300 serror("too many chars");
301 $$.val = stringbuf[0];
304 | ASC_LPAR expr ASC_RPAR
307 { $$.val = ($1.val || $3.val);
308 $$.typ = combine($1.typ, $3.typ, 0);
311 { $$.val = ($1.val && $3.val);
312 $$.typ = combine($1.typ, $3.typ, 0);
315 { $$.val = ($1.val | $3.val);
316 $$.typ = combine($1.typ, $3.typ, 0);
319 { $$.val = ($1.val ^ $3.val);
320 $$.typ = combine($1.typ, $3.typ, 0);
323 { $$.val = ($1.val & $3.val);
324 $$.typ = combine($1.typ, $3.typ, 0);
327 { $$.val = ($1.val == $3.val);
328 $$.typ = combine($1.typ, $3.typ, '>');
331 { $$.val = ($1.val != $3.val);
332 $$.typ = combine($1.typ, $3.typ, '>');
335 { $$.val = ($1.val < $3.val);
336 $$.typ = combine($1.typ, $3.typ, '>');
339 { $$.val = ($1.val > $3.val);
340 $$.typ = combine($1.typ, $3.typ, '>');
343 { $$.val = ($1.val <= $3.val);
344 $$.typ = combine($1.typ, $3.typ, '>');
347 { $$.val = ($1.val >= $3.val);
348 $$.typ = combine($1.typ, $3.typ, '>');
351 { $$.val = ($1.val >> $3.val);
352 $$.typ = combine($1.typ, $3.typ, 0);
355 { $$.val = ($1.val << $3.val);
356 $$.typ = combine($1.typ, $3.typ, 0);
359 { $$.val = ($1.val + $3.val);
360 $$.typ = combine($1.typ, $3.typ, '+');
363 { $$.val = ($1.val - $3.val);
364 $$.typ = combine($1.typ, $3.typ, '-');
367 { $$.val = ($1.val * $3.val);
368 $$.typ = combine($1.typ, $3.typ, 0);
373 serror("divide by zero");
376 $$.val = ($1.val / $3.val);
377 $$.typ = combine($1.typ, $3.typ, 0);
382 serror("divide by zero");
385 $$.val = ($1.val % $3.val);
386 $$.typ = combine($1.typ, $3.typ, 0);
390 $$.typ = combine(S_ABS, $2.typ, 0);
394 $$.typ = combine(S_ABS, $2.typ, 0);
398 $$.typ = combine(S_ABS, $2.typ, 0);
402 $$.typ = DOTTYP|S_DOT;
409 { if (($1.typ & ~S_EXT) != S_ABS)
410 serror("must be absolute");
427 /* ========== Machine dependent rules ========== */