GATE 2024 CS (CS1) – Question 37
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?
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$.
- $D$: innermost $D\to\varepsilon$ gives $-5$; one $M$ gives $5+(-5)=0$; the second $M$ gives $5+0=5$. So $D.val=5$.
- $H$: $H\to\varepsilon$ gives $-10$; one $L$ gives $50+(-10)=40$. So $H.val=40$.
- $T$: $T\to\varepsilon$ gives $T.val=-5$.
- $U$: $U\to K$ gives $U.val=5$.
$S.val=5+40+(-5)+5=\mathbf{45}$, option (A).