
Syntax-directed Translation 159
| LOCAL { $$ = 2; }
;
type: FLOAT { $$ = 10; }
| INT { $$ = 20; }
;
varlist: NAME { insert($0, $-1, $1); }
| varlist NAME { insert(S0, $-1, $2); }
;
It would be useful to have the class and type available in the actions for varlist, both for type
checking and to enter into the Symbol Table. In yacc, it is possible to access the symbols on its
internal stack to the left of the current token, via $0, $-1, etc. In the example above, $0 in the call to
insert() refers to the value of the symbol type which is stacked just before the symbo1/s for the
varlist production and will have the value 1 or 2, depending on whether ...