Inherited Attributes
An inherited attribute at a node in parse tree is defined using the attribute values at the parent or siblings. Inherited attributes are convenient for expressing the dependence of a programming language construct on the context in which it appears. For example, we can use an inherited attribute to keep track of whether an identifier appears on the left or the right side of an assignment in order to decide whether the address or the value of the identifier is needed.
| Production rule | Semantic rule |
|---|---|
| S → T L | L.in:=T.type |
| T → int | T.type:=integer |
| T → float | T.type:=float |
| T → char | T.type:=char |
| T → double | T.type:=double |
| L → L1, id | L1.in=L.in
enter_type(id.entry, L.in) |
| L → id | enter_type(id.entry, L.in) |
Read more about this topic: Attribute Grammar
Famous quotes containing the words inherited and/or attributes:
“The painter ... does not fit the paints to the world. He most certainly does not fit the world to himself. He fits himself to the paint. The self is the servant who bears the paintbox and its inherited contents.”
—Annie Dillard (b. 1945)
“The world of the egotist is, inevitably, a narrow world, and the boundaries of self are limited to the close horizon of personality.... But, within this horizon, there is room for many attributes that are excellent....”
—Ellen Glasgow (18731945)