GateAI
Syntax-Directed Translation

GATE CSE 2023 · Q60

NAT2 marksMedium

Time

Consider the syntax directed translation given by the following grammar and semantic rules. Here N,I,FN, I, F and BB are non-terminals. NN is the starting non-terminal, and #\#, 0\mathbf{0} and 1\mathbf{1} are lexical tokens corresponding to input letters “#”, “0” and “1”, respectively. X.valX.val denotes the synthesized attribute (a numeric value) associated with a non-terminal XX. I1I_1 and F1F_1 denote occurrences of II and FF on the right hand side of a production, respectively. For the tokens 0\mathbf{0} and 1\mathbf{1}, 0.val=0\mathbf{0}.val = 0 and 1.val=1\mathbf{1}.val = 1. N→I # FN.val=I.val+F.valI→I1 BI.val=(2 I1.val)+B.valI→BI.val=B.valF→B F1F.val=12(B.val+F1.val)F→BF.val=12B.valB→0B.val=0.valB→1B.val=1.val \begin{array}{llll} N & \rightarrow & I \, \# \, F & N.val = I.val + F.val I & \rightarrow & I_1 \, B & I.val = (2 \, I_1.val) + B.val I & \rightarrow & B & I.val = B.val F & \rightarrow & B \, F_1 & F.val = \frac{1}{2}(B.val + F_1.val) F & \rightarrow & B & F.val = \frac{1}{2} B.val B & \rightarrow & \mathbf{0} & B.val = \mathbf{0}.val B & \rightarrow & \mathbf{1} & B.val = \mathbf{1}.val \end{array} The value computed by the translation scheme for the input string 10#011 10\#011 is ________. (Rounded off to three decimal places)

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 2.375

Syntax-Directed Translation

To find the computed value for the input string 10#011, we evaluate the synthesized attributes for the integer part (II) corresponding to 10 and the fractional part (FF) corresponding to 011.

### 1. Integer Part: 10

  • The leftmost bit 1 derives:

    B→1  ⟹  B.val=1B \rightarrow 1 \implies B.val = 1
    I→B  ⟹  I.val=B.val=1I \rightarrow B \implies I.val = B.val = 1
  • The next bit 0 derives:

    B→0  ⟹  B.val=0B \rightarrow 0 \implies B.val = 0
    I→I1 B  ⟹  I.val=(2×1)+0=2I \rightarrow I_1 \, B \implies I.val = (2 \times 1) + 0 = 2

Thus, I.val=2I.val = 2.

---

### 2. Fractional Part: 011 Since F→B F1F \rightarrow B \, F_1 is right-recursive, evaluation occurs bottom-up from right to left:

  • For the rightmost bit 1 (3rd bit after #):

    B→1  ⟹  B.val=1B \rightarrow 1 \implies B.val = 1
    F→B  ⟹  F.val=12×1=0.5F \rightarrow B \implies F.val = \frac{1}{2} \times 1 = 0.5
  • For the middle bit 1 (2nd bit after #):

    B→1  ⟹  B.val=1B \rightarrow 1 \implies B.val = 1
    F→B F1  ⟹  F.val=12(1+0.5)=1.52=0.75F \rightarrow B \, F_1 \implies F.val = \frac{1}{2}(1 + 0.5) = \frac{1.5}{2} = 0.75
  • For the leftmost bit 0 (1st bit after #):

    B→0  ⟹  B.val=0B \rightarrow 0 \implies B.val = 0
    F→B F1  ⟹  F.val=12(0+0.75)=0.752=0.375F \rightarrow B \, F_1 \implies F.val = \frac{1}{2}(0 + 0.75) = \frac{0.75}{2} = 0.375

Thus, F.val=0.375F.val = 0.375.

---

### 3. Final Value:

N.val=I.val+F.val=2+0.375=2.375N.val = I.val + F.val = 2 + 0.375 = 2.375

Rounded off to three decimal places, the value is 2.375 (official range: 2.374 to 2.376).

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 Q60 of the GATE CSE 2023 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. 2 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2023.

How GATE tests Syntax-Directed Translation

More from GATE CSE 2023

Share this solution

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

GateAI solution cardGATE CSE 2023 · Q60 · NAT

Consider the syntax directed translation given by the following grammar and semantic rules. Here N, I, F and B are non-terminals. N is the starting non-terminal, and \#, 0 and 1 are lexical tokens corresponding to input letters “#”, “0” and “1”, respectively. X.val denotes the synthesized attribute (a numeric value) associated with a non-terminal X. I1 and F1 denote occurrences of I and F on the right hand side of a production, respectively. For the tokens 0 and 1, 0.val = 0 and 1.val = 1. llll N & → & I \# F & N.val = I.val + F.val I & → & I1 B & I.val = (2 I1.val) + B.val I & → & B & I.val = B.val F & → & B F1 & F.val = (1)/(2)(B.val + F1.val) F & → & B & F.val = (1)/(2) B.val B & → & 0 & B.val = 0.val B & → & 1 & B.val = 1.val The value computed by the translation scheme for the input string 10\#011 is … (Rounded off to three decimal places)

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.