
180 Compilers – Principles and Practice
$$ = tree_node(gentemp("plus"));
ival($$) = x + y;
subtype($$) = subtype($1); type($$) = subtype($1);
subtype(install (name($$),subtype($$),ival($$)))
= subtype($1);}
else{sprintf(s,"not int [%s %s]\n",name($1),
name($3)); yyerror(s);}
}
In the above, tree_node() is a utility function which generates a new Node with a given name
attribute. Unique names with specified prefix are generated by gentemp().
We have given below one more portion of the evaluator – LET construct which substitutes a value
for an identifier in an expression.
| LET ID ’=’ expr { Symbol *sp; sp = lookup(name($2)); type(sp) = ID; ...