Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1, X2, X3, X4, X5 and X6 be the placeholders for the non-terminals D, T, L or L1 in the following table: Production rule Semantic action D → T L X1.type = X2.type T → int T.type = int T → float T.type = float L → L1, id X3.type = X4.type addType(id.entry, X5.type) L → id addType(id.entry, X6.type) Which one of the following are the appropriate choices for X1, X2, X3 and X4?
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1, X2, X3, X4, X5 and X6 be the placeholders for the non-terminals D, T, L or L1 in the following table: Production rule Semantic action D → T L X1.type = X2.type T → int T.type = int T → float T.type = float L → L1, id X3.type = X4.type addType(id.entry, X5.type) L → id addType(id.entry, X6.type) Which one of the following are the appropriate choices for X1, X2, X3 and X4? Correct Answer X<sub>1</sub> = L, X<sub>2</sub> = T, X<sub>3</sub> = L<sub>1</sub>, X<sub>4</sub> = L
Concepts:
Synthesized attributes:
A Synthesized attribute is an attribute of the non-terminal on the left-hand side of a production. Synthesized attributes represent information that is being passed up the parse tree. The attribute can take value only from its children.
S-attributed SDT
If an SDT uses only synthesized attributes, it is called as S-attributed SDT.
Inherited attributes:
An attribute of a nonterminal on the right-hand side of a production is called an inherited attribute. The attribute can take value either from its parent or from its siblings.
L-attributed SDT
If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT.
In SDT:
D → T L {X1.type = X2.type}
L.type = T.type (Inherited attributed )
∴ X1 = L and X2 = T
T can be int or float
In SDT:
L → L1, id {X3.type = X4.type}
L1.type = L.type (Inherited attributed)
∴ X3 = L1 and X4 = L
Hence option 1 is correct.