Skip to content
GATEiit

GATE CSE 2024 Session 1 Q37: Value computed by an SDD for the input MMLK

Question

Consider the following syntax-directed definition (SDD).

ProductionSemantic rule
S→DHTUS \to DHTUS.val=D.val+H.val+T.val+U.val;S.val = D.val + H.val + T.val + U.val;
D→"M" D1D \to \text{"M"}\, D_1D.val=5+D1.val;D.val = 5 + D_1.val;
D→ϵD \to \epsilonD.val=−5;D.val = -5;
H→"L" H1H \to \text{"L"}\, H_1H.val=5∗10+H1.val;H.val = 5 * 10 + H_1.val;
H→ϵH \to \epsilonH.val=−10;H.val = -10;
T→"C" T1T \to \text{"C"}\, T_1T.val=5∗100+T1.val;T.val = 5 * 100 + T_1.val;
T→ϵT \to \epsilonT.val=−5;T.val = -5;
U→"K"U \to \text{"K"}U.val=5;U.val = 5;

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)?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: A (official GATE 2024 final answer key)

Concept used: Synthesized attributes evaluated bottom-up over the parse tree.

First step: Split MMLK into D = MM, H = L, T = ε, U = K and evaluate each part, starting from its ε-production.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2024 Session 1 CS question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key