Assigning type information to declared variables
Type information is constructed during a tree traversal and then stored with the associated variables in the symbol table. This would usually be part of the traversal that populates the symbol table, as presented in the previous chapter. In this section, we will traverse the syntax tree looking for variable declarations, as we did previously, but this time, we need to propagate type information by using synthesized and/or inherited attributes.
For type information to be available at the time that we are inserting variables into the symbol table, the type information must be computed at some prior point in time. This type information is computed either by a preceding tree traversal or during parsing when the syntax tree is constructed. Consider the following grammar rule and semantic action from Chapter 5, Syntax Trees:
FieldDecl: Type VarDecls ';' {
$$=j0.node("FieldDecl",1030,$1,$2); };
The semantic...