GATE Computer ScienceVery hardGATE CS

Grammar: E → E + T | T; T → T * F | F; F → ( E ) | id. An SLR(1) parser parses id + id * ( id + id ) * id. Counting every shift, every reduce and the final accept as one action, how many parser actions are executed?

  1. A. 31
  2. B. 28
  3. C. 27
  4. D. 25

Correct answer: B. 28

There are 11 tokens, so 11 shifts. Reductions: 6 F-reductions (5 ids and one parenthesised E), 6 T-reductions (4 of the form T → F, 2 of the form T → T * F) and 4 E-reductions (2 of E → T and 2 of E → E + T), a total of 16. 11 + 16 + 1 accept = 28.

More Compiler Design questions

Exams that ask this topic