Given the following syntax directed translation rules:
Rule 1: R→ABR→AB [B.i=R.i−1;A.i=B.iR.i=A.i+1;B.i=R.i−1;A.i=B.iR.i=A.i+1;]
Rule 2: P→CDP→CD [P.i=C.i+D.i;D.i=C.i+2P.i=C.i+D.i;D.i=C.i+2]
Rule 3: Q→EFQ→EF [Q.i=E.i+F.i;Q.i=E.i+F.i;]
Which ONE is the CORRECT option among the following?
Correct Answer :
Rule 1 is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
Solution :
The correct option is: Rule 1 is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed.
To determine the correct classification of each Syntax-Directed Translation (SDT) rule, let us first review the definitions of S-attributed and L-attributed definitions:
1. S-attributed definition:
An SDD is S-attributed if it uses only synthesized attributes. In a syntax-directed definition, a synthesized attribute at a node is computed from the attributes of its children. In grammar terms, for a production , only the attribute of the left-hand side symbol is computed, and it depends solely on the attributes of the right-hand side symbols .
2. L-attributed definition:
An SDD is L-attributed if every attribute is either synthesized, or inherited with the restriction that the inherited attributes of a sibling symbol on the right-hand side of a production can depend only on:
- The inherited attributes of the left-hand side parent head .
- The attributes (either synthesized or inherited) of sibling symbols that lie to the left of .
Note that every S-attributed definition is also an L-attributed definition, because S-attributed definitions do not have any inherited attributes and thus trivially satisfy the constraints of L-attributed definitions.
Let us analyze each rule step-by-step:
Analysis of Rule 1:
Production:
Semantic Rules:
Looking at the action , the attribute of the symbol (which is to the left of ) depends on the attribute of the symbol (which is to the right of ). This right-to-left dependency violates the constraint of L-attributed definitions. Furthermore, since it contains inherited attributes (such as and ), it is not S-attributed. Thus, Rule 1 is neither S-attributed nor L-attributed.
Analysis of Rule 2:
Production:
Semantic Rules:
Here, the inherited attribute of (which is ) depends on (an attribute of its left sibling symbol ). This is a valid dependency for an L-attributed definition. The attribute of the head is synthesized from the right-hand side attributes. Because it contains the inherited attribute on the right-hand side, it is not S-attributed. Therefore, Rule 2 is not S-attributed but is L-attributed.
Analysis of Rule 3:
Production:
Semantic Rules:
In this rule, the attribute of the left-hand side head is computed using only the attributes of the right-hand side symbols and . There are no inherited attributes computed for any of the right-hand side symbols. This makes the rule S-attributed. Since all S-attributed definitions are a subset of L-attributed definitions, Rule 3 is both S-attributed and L-attributed.
Access expert-curated educational resources and study materials—completely free.
Create, conduct, and manage professional online assessments with Mindyard. Perfect for teachers and institutes.
Copyright © 2026 Mindyard. All Rights Reserved.