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.2.2 Semantic Functions

Although it is possible to evaluate some attributes at parse time, we will asume that all attributes are evaluated after the program has been parsed. Values are assigned to local attributes by equations called semantic functions. Local attributes are those which fall within the scope of a production as it appears in the parse tree. For example:

       Syntax                 Semantics
       E0  E1 + T         E0.Value := E1.Value + T.Value

Here, the production is EE+T. The subscripts are used only to distinguish the two E's. The attribute Value is associated with both E's and with T. If this production were in a parse tree, it would be denoted:

The value of the attribute Value is passed up the parse tree because E1.Value and T.Value are used to compute E0.Value. Such attributes are termed synthesized attributes. Attributes whose values are apssed down the tree are called inherited attributes.

Terminals may have only synthesized attributes, and their values are assigned by the lexical analyzer. Inherited values of the Start symbol. If any, are given values by way of parameters when attribute evaluation begins.

Send questions and comments to: Karen Lemone