The GATE Grind

GATE 2024 CS (CS1) – Question 37

Compiler Design · Syntax-Directed Translation · 2 marks · Multiple choice

Consider the SDD: S→DHTU {S.val=D.val+H.val+T.val+U.val}; D→"M"D1 {D.val=5+D1.val}; D→ε {D.val=−5}; H→"L"H1 {H.val=5*10+H1.val}; H→ε {H.val=−10}; T→"C"T1 {T.val=5*100+T1.val}; T→ε {T.val=−5}; U→"K" {U.val=5}. Given "MMLK" as the input, which is the CORRECT value of S.val?

  1. 45
  2. 50
  3. 55
  4. 65

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) 45

Explanation

Input `MMLK` is derived as $S\to D\,H\,T\,U$ with $D\to M\,M\,\varepsilon$, $H\to L\,\varepsilon$, $T\to\varepsilon$, $U\to K$.

$S.val=5+40+(-5)+5=\mathbf{45}$, option (A).

More Syntax-Directed Translation questions

All Syntax-Directed Translation questions →