Slide 5.1: Synthesized attributes
Slide 5.3: A translational-semantics example
Home

Inherited Attributes


An inherited attribute for a nonterminal B at a parse-tree node N is defined by a semantic rule associated with the production at the parent of N. An inherited attribute at node N is defined only in terms of attribute values at N's parent, N itself, and N's siblings. The following syntax-directed definitions takes a simple declaration <D> consisting of a basic type <T> followed by a list L of identifiers. <T> can be int or float.

For each identifier on the list, the type is entered into the symbol-table entry for the identifier. The function addType is called with two arguments:
  Production Semantic Rules
1. <D> ::= <T> <L> Inh(<L>) = Type(<T>)
2. <T> ::= int Type(<T>) = integer
3. <T> ::= float Type(<T>) = float
4. <L> ::= <L1> , id Inh(<L1>) = Inh(<L>)
addType[Entry(id), Inh(<L>)]
5. <L> ::= id addType[Entry(id), Inh(<L>)]
It properly installs the type Inh(<L>) as the type of the represented identifier id. The following figure shows a dependency graph for the input string “float   id1, id2, id3”.