Given the following syntax directed translation rules:
- Rule 1:
- Rule 2:
- Rule 3:
Which ONE is the CORRECT option among the following?
View worked solution
Answer: C
To determine the classification of each syntax-directed translation (SDT) rule, we use the definitions of -attributed and -attributed definitions:
- -attributed SDD: Uses only synthesized attributes (attributes of the parent are computed from the attributes of its children).
- -attributed SDD: Allows both synthesized and inherited attributes. However, an inherited attribute of a child on the right-hand side can only depend on the attributes of the parent or the siblings to its left.
Let's analyze each rule:
- Rule 1 (): The action
A.i = B.idefines the attribute of child using the attribute of child , which lies to its right. This violates the -attributed condition. Since it uses inherited attributes, it is also not -attributed. Thus, Rule 1 is neither -attributed nor -attributed. - Rule 2 (): The action
D.i = C.i + 2defines the inherited attribute of using its left sibling , which is allowed in -attributed. The actionP.i = C.i + D.idefines the head's attribute using its children, which is also allowed. Since it defines an inherited attribute of a child (), it is not -attributed. Thus, Rule 2 is not -attributed and is -attributed. - Rule 3 (): The action
Q.i = E.i + F.ionly defines the attribute of the head using the attributes of its children. This behaves purely as a synthesized attribute. Thus, Rule 3 is both -attributed and -attributed.
Hence, the correct option is C.
Free practice · Your answers on this page are not saved.
