6.0 Introduction

6.1 Static Checking

6.2 Attribute Grammars

6.3 Translation to an IR

6.4 Semantic Analyzer Generators

6.5 More on Attribute Grammars

6.6 Attribute Evaluation

6.7 Summary

Web References

Exercises

6.7 Summary

This module decsribes semantic analysis, the bridge between the front-end and the back-end of compiling. The specification of semantics is often done using attribute grammars, and much of this module is devoted to attribute grammars. Attributes are evaluated at compile-time; however, some processing toward generation of the evaluator may be moved back to compiler generation time.

Grammatical restrictions and efficient evaluation are interconnected in many cases. Thus, the attributes described by L-attributed grammars can be evaluated at parse-time by a top-down parser or after the parse in a single pass down the tree.

The attributes described by S-attributed grammars can be evaluated at parse-time by a bottom-up parser or after the parse by a single pass up the tree.

For unrestricted attribute grammars, tree-walk evaluators may require multiple passes over the parse tree. More efficient evaluators may be obtained by creating a dependency graph from the parse tree and the semantic functions. A dependency graph ensures that the attributes upon which a semantic function depends are evaluated first.

Another task of semantic analysis is creation of an intermediate representation of the program.

Yet another task of semantic analysis is Symbol Table creation.

Send questions and comments to: Karen Lemone