Question

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;}R \rightarrow 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;}P \rightarrow CD \; \{ P.i = C.i + D.i; \; D.i = C.i + 2; \}
Rule 3: Q→EF  {Q.i=E.i+F.i;}Q \rightarrow EF \; \{ Q.i = E.i + F.i; \}

Which ONE is the CORRECT option among the following?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2025 answer key

Solution

Check each rule against the definitions of S-attributed (only synthesized attributes) and L-attributed (inherited attributes depend only on parent or left siblings).

  • Rule 1: Computes attributes of RHS symbols A.iA.i and B.iB.i (so it is not S-attributed), and A.i=B.iA.i = B.i depends on BB, which is to the right of AA in R→ABR \rightarrow AB (so it is not L-attributed).
  • Rule 2: Computes D.i=C.i+2D.i = C.i + 2, which is an inherited attribute of RHS symbol DD (so it is not S-attributed). Since D.iD.i depends only on its left sibling C.iC.i, and P.iP.i is a synthesized attribute of the LHS symbol PP, Rule 2 is L-attributed.
  • Rule 3: Computes only the synthesized attribute Q.iQ.i of the LHS symbol from the attributes of its children EE and FF. Hence Rule 3 is both S-attributed and L-attributed.
Final answer

Option (C)

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2025 Computer Science and Information Technology - Session 2 (CS2)
Question
22 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.