Consider the productions and . Each of the five non-terminals and has two attributes: is a synthesized attribute, and is an inherited attribute. Consider the following rules.
- Rule and
- Rule and
Which one of the following is TRUE?
View worked solution
Answer: B
To determine whether the rules are -attributed, let us recall the definition of an -attributed Syntax-Directed Definition (SDD):
For a production , an inherited attribute of a symbol on the right-hand side can only depend on:
- Inherited attributes of the head non-terminal .
- Any attributes (synthesized or inherited) of the symbols that lie to the left of .
Synthesized attributes of the head can depend on any attributes of the children on the right-hand side.
Analysis of Rule 1:
- : The inherited attribute depends on (inherited attribute of the head ). This is valid.
- : The inherited attribute depends on (attribute of , which is to the left of ) and (inherited attribute of the head ). This is valid.
- : The synthesized attribute of the head depends on the attributes of its children. This is valid.
Since all dependencies satisfy the conditions, Rule 1 is -attributed.
Analysis of Rule 2:
- : The inherited attribute depends on (synthesized attribute of ). Since lies to the right of , this dependency on a right sibling is invalid for an -attributed definition.
Thus, Rule 2 is not -attributed.
Therefore, only Rule 1 is -attributed. The correct option is B.
Free practice · Your answers on this page are not saved.
