GATE Computer ScienceVery hardGATE CSE

Syntax-directed definition: E → E1 $ T { E.val = E1.val * 2 + T.val }; E → T { E.val = T.val }; T → num { T.val = num.lexval }. For the input 3 $ 4 $ 5 $ 6, what is E.val at the root? (The grammar is left-recursive, so the parse groups from the left.)

  1. A. 56
  2. B. 30
  3. C. 55
  4. D. 60

Correct answer: A. 56

Evaluate left to right: 3 → 3·2+4 = 10 → 10·2+5 = 25 → 25·2+6 = 56. (A right-grouping would give 30.)

More Compiler Design questions

Exams that ask this topic