Home › Previous year questions › GATE 2025 CS (CS2) › Question 22GATE 2025 CS (CS2) – Question 22 Compiler Design · Syntax-Directed Translation · 1 mark · Multiple choice
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?
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 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.
More Syntax-Directed Translation questions GATE 2024 CS (CS1) Q37 – Consider the SDD: S→DHTU S.val=D.val+H.val+T.val+U.val; D→"M"D1 D.val=5+D1.val; D→ε… GATE 2024 CS (CS2) Q29 – Which of the following statements is/are FALSE? GATE 2023 CS Q60 – Consider the syntax directed translation given by the following grammar and semantic… GATE 2022 CS Q65 – Consider the following grammar along with translation rules. S S 1\ \#\ T\S.val=S 1.val *… GATE 2021 CS (CS1) Q36 – Consider the following grammar (that admits a series of declarations, followed by… GATE 2020 CS Q43 – Consider the productions A → PQ and A → XY. Each of the five non-terminals A, P, Q, X, and… All Syntax-Directed Translation questions →