|
![]() |
6.7 SummaryThis 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. |