GateAI
Syntax-Directed Translation

GATE CSE 2024 Set 1 · Q37

MCQ2 marksMedium

Time

Consider the following syntax-directed definition (SDD). Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.valS.val)?

GATE CSE 2024 Set 1 Q37 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 45

Syntax-Directed Translation

To find S.valS.val for the input string "MMLK", we parse the input according to the grammar S→D H T US \rightarrow D\,H\,T\,U [cite: 7]:

  1. Evaluating DD for substring "MM":

    • D→"M" D1D \rightarrow \text{"M"}\,D_1

    • D1→"M" D2D_1 \rightarrow \text{"M"}\,D_2

    • D2→ϵ  ⟹  D2.val=−5D_2 \rightarrow \epsilon \implies D_2.val = -5

    • D1.val=5+D2.val=5+(−5)=0D_1.val = 5 + D_2.val = 5 + (-5) = 0

    • D.val=5+D1.val=5+0=5D.val = 5 + D_1.val = 5 + 0 = 5

  2. Evaluating HH for substring "L":

    • H→"L" H1H \rightarrow \text{"L"}\,H_1

    • H1→ϵ  ⟹  H1.val=−10H_1 \rightarrow \epsilon \implies H_1.val = -10

    • H.val=5×10+H1.val=50+(−10)=40H.val = 5 \times 10 + H_1.val = 50 + (-10) = 40

  3. Evaluating TT for substring ϵ\epsilon:

    • T→ϵ  ⟹  T.val=−5T \rightarrow \epsilon \implies T.val = -5

  4. Evaluating UU for substring "K":

    • U→"K"  ⟹  U.val=5U \rightarrow \text{"K"} \implies U.val = 5

  5. Evaluating S.valS.val:

    S.val=D.val+H.val+T.val+U.valS.val = D.val + H.val + T.val + U.val
    S.val=5+40+(−5)+5=45S.val = 5 + 40 + (-5) + 5 = 45

Therefore, the correct option is (A).

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 Q37 of the GATE CSE 2024 Set 1 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 2024 Set 1.

How GATE tests Syntax-Directed Translation

More from GATE CSE 2024 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 1 · Q37 · MCQ

Consider the following syntax-directed definition (SDD). Given "MMLK" as the input, which one of the following options is the CORRECT value computed by the SDD (in the attribute S.val)?

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.