GateAI
Syntax-Directed Translation

GATE CSE 2025 Set 2 · Q22

MCQ1 markMedium

Time

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 \to 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 \to CD \{P.i = C.i + D.i; D.i = C.i + 2;\} Rule 3: Q→EF{Q.i=E.i+F.i;}Q \to EF \{Q.i = E.i + F.i;\} Which ONE is the CORRECT option among the following?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official 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

Syntax-Directed Translation

To determine whether each syntax-directed definition (SDD) rule is S-attributed or L-attributed, we apply the standard definitions:

  1. S-attributed SDD: Uses only synthesized attributes (i.e., attributes of the non-terminal on the LHS are computed solely from attributes of the children on the RHS).

  2. L-attributed SDD: Allows both synthesized and inherited attributes. For any production A→X1X2…XnA \to X_1 X_2 \dots X_n, an inherited attribute of XjX_j may depend only on:

    • Inherited attributes of the head AA, and/or

    • Attributes of symbols X1,X2,…,Xj−1X_1, X_2, \dots, X_{j-1} appearing to the left of XjX_j.

    *(Every S-attributed SDD is also an L-attributed SDD).*

---

### Analysis of Each Rule:

  • Rule 1: R→AB{B.i=R.i−1;A.i=B.i;R.i=A.i+1;}R \to AB \{B.i = R.i - 1; A.i = B.i; R.i = A.i + 1;\}

    • In A.i=B.iA.i = B.i, the attribute of the symbol AA depends on BB, which lies to its right. This violates the L-attributed property.

    • Since it contains inherited attributes (B.iB.i and A.iA.i), it is also not S-attributed.

    • Therefore, Rule 1 is neither S-attributed nor L-attributed.

  • Rule 2: P→CD{P.i=C.i+D.i;D.i=C.i+2;}P \to CD \{P.i = C.i + D.i; D.i = C.i + 2;\}

    • P.i=C.i+D.iP.i = C.i + D.i computes a synthesized attribute for the head PP from children CC and DD.

    • D.i=C.i+2D.i = C.i + 2 computes an inherited attribute for DD using CC, which is strictly to the left of DD. This satisfies the L-attributed condition.

    • Because it includes the inherited attribute D.iD.i, it is not S-attributed.

    • Therefore, Rule 2 is not S-attributed and is L-attributed.

  • Rule 3: Q→EF{Q.i=E.i+F.i;}Q \to EF \{Q.i = E.i + F.i;\}

    • Q.iQ.i is computed solely from the attributes of its children EE and FF.

    • This uses only synthesized attributes, so it is S-attributed.

    • Every S-attributed grammar is also L-attributed.

    • Therefore, Rule 3 is S-attributed and L-attributed.

Matching these classifications with the choices gives Option (C) as the correct answer.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Syntax-Directed Translation previous year question is Q22 of the GATE CSE 2025 Set 2 paper. Find more GATE CSE PYQs on Syntax-Directed Translation in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Syntax-Directed Translation PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Syntax-Directed Translation in GATE CSE

Syntax-Directed Translation has 9 GATE CSE PYQs across 9 papers from 2016 to 2026. This is the only 1-mark MCQ among them, and it is the only one in GATE CSE 2025 Set 2.

How GATE tests Syntax-Directed Translation

More from GATE CSE 2025 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2025 Set 2 · Q22 · MCQ

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?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.