Exams › GATE › Technical
Given the following syntax-directed translation rules: Rule 1: `R → AB { B.i = R.i - 1; A.i = B.i; R.i = A.i + 1; }` Rule 2: `P → CD { P.i = C.i + D.i; D.i = C.i + 2; }` Rule 3: `Q → EF { Q.i = E.i + F.i; }` Which ONE is the correct option among the following?
- Rule 1 is S-attributed and L-attributed; Rule 2 is S-attributed and not L-attributed; Rule 3 is neither S-attributed nor L-attributed
- Rule 1 is neither S-attributed nor L-attributed; Rule 2 is S-attributed and L-attributed; Rule 3 is S-attributed and L-attributed
- 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
- Rule 1 is S-attributed and not L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
Correct answer: Rule 1 is S-attributed and not L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
Solution
Rule 1 uses inherited attributes and also assigns to the left-hand side, so it is not S-attributed; it is not L-attributed because `A.i` depends on `B.i`, a right sibling. Rule 2 has an inherited attribute for `D`, so it is not S-attributed, but it is L-attributed since `D.i` depends only on the left sibling `C.i`. Rule 3 uses only synthesized attributes, so it is both S-attributed and L-attributed.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →