. Conceptually both:
- parse input token stream
- build parse tree
- traverse the parse tree to evaluate the semantic rules at the parse tree nodes
. Evaluation may:
- generate code
- save information in the symbol table
- issue error messages
- perform any other activity
To avoid repeated traversal of the parse tree, actions are taken simultaneously when a token is found. So calculation of attributes goes along with the construction of the parse tree.
Along with the evaluation of the semantic rules the compiler may simultaneously generate code, save the information in the symbol table, and/or issue error messages etc. at the same time while building the parse tree.
This saves multiple passes of the parse tree.
|