
152 An Introduction to Compiler Construction in a Java World
4.5.3 Simple Variables
Simple variables are represented in the AST as JVariable nodes. A simple variable could
denote a local variable, a field or a type. Analysis of simple variables involves looking up
their names in the symbol table to find their types. If a variable is not found in the symbol
table, then we examine the Type for the surrounding class (in which the variable appears)
to see if it is a field. If it is a field, then the field selection is made explicit by rewriting the
tree as a JFieldSelection.
The code for analyze() in JVariable is as follows:
public JExpr e s sion analyze (