GateAI
Syntax-Directed Translation

GATE CSE 2020 · Q33

MCQ2 marksMedium

Time

Consider the productions A→PQ\text{A} \rightarrow \text{PQ} and A→XY\text{A} \rightarrow \text{XY}. Each of the five non-terminals A, P, Q, X, and Y has two attributes: ss is a synthesized attribute, and ii is an inherited attribute. Consider the following rules. Rule 1: P.ii = A.ii + 2, Q.ii = P.ii + A.ii, and A.ss = P.ss + Q.ss Rule 2: X.ii = A.ii + Y.ss and Y.ii = X.ss + A.ii Which one of the following is TRUE?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) Only Rule 1 is L-attributed.

Syntax-Directed Translation

In a Syntax-Directed Definition (SDD), an attribute grammar is L-attributed if each inherited attribute of a grammar symbol XjX_j on the right-hand side of a production A→X1X2…XnA \to X_1 X_2 \dots X_n depends only on:

  1. The inherited attributes of the parent non-terminal AA.

  2. The attributes (synthesized or inherited) of symbols X1,X2,…,Xj−1X_1, X_2, \dots, X_{j-1} appearing to the left of XjX_j.

  3. Inherited attributes of XjX_j itself, such that no cycles are formed.

Let us evaluate each rule:

  • Rule 1 for A→PQA \to PQ:

    • P.i=A.i+2\text{P}.i = \text{A}.i + 2: Inherited attribute of P\text{P} depends only on the parent's inherited attribute A.i\text{A}.i. (Valid)

    • Q.i=P.i+A.i\text{Q}.i = \text{P}.i + \text{A}.i: Inherited attribute of Q\text{Q} depends on P.i\text{P}.i (a symbol to the left of Q\text{Q}) and A.i\text{A}.i (parent). (Valid)

    • A.s=P.s+Q.s\text{A}.s = \text{P}.s + \text{Q}.s: Synthesized attribute of parent depends on attributes of its children. (Valid)

    Therefore, Rule 1 is L-attributed.

  • Rule 2 for A→XYA \to XY:

    • X.i=A.i+Y.s\text{X}.i = \text{A}.i + \text{Y}.s: Inherited attribute of X\text{X} depends on Y.s\text{Y}.s, where Y\text{Y} appears to the right of X\text{X}. This violates the L-attributed definition.

    Therefore, Rule 2 is not L-attributed.

Hence, only Rule 1 is L-attributed, making (B) the correct option.

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 Q33 of the GATE CSE 2020 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. 4 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2020.

How GATE tests Syntax-Directed Translation

More from GATE CSE 2020

Share this solution

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

GateAI solution cardGATE CSE 2020 · Q33 · MCQ

Consider the productions A → PQ and A → XY. Each of the five non-terminals A, P, Q, X, and Y has two attributes: s is a synthesized attribute, and i is an inherited attribute. Consider the following rules. Rule 1: P.i = A.i + 2, Q.i = P.i + A.i, and A.s = P.s + Q.s Rule 2: X.i = A.i + Y.s and Y.i = X.s + A.i Which one of the following is TRUE?

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.