|
6.2.2 Semantic FunctionsAlthough 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 |