GATE 2025 CS (CS2) – Question 22
Given the following syntax directed translation rules:
Rule 1: $R \to AB\ \{B.i = R.i - 1;\ A.i = B.i;\ R.i = A.i + 1;\}$
Rule 2: $P \to CD\ \{P.i = C.i + D.i;\ D.i = C.i + 2;\}$
Rule 3: $Q \to EF\ \{Q.i = E.i + F.i;\}$
Which ONE is the CORRECT option among the following?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) 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
Explanation
Rule 1: A.i depends on the right sibling B.i, so it is not L-attributed, and it also assigns an inherited attribute, so it is not S-attributed. Rule 2: D.i is inherited from the left sibling C, so it is L-attributed but not S-attributed. Rule 3 uses only synthesized attributes, so it is both.