GATE Computer ScienceVery hardGATE CS

A table-driven predictive parser for E → T E'; E' → + T E' | ε; T → F T'; T' → * F T' | ε; F → ( E ) | id parses ( id + id ) * id + id. One move is either replacing a non-terminal on the stack by a production body (an ε body also counts) or matching and popping a terminal; the final acceptance on $ is not counted. How many moves does the parser make?

  1. A. 31
  2. B. 29
  3. C. 28
  4. D. 33

Correct answer: B. 29

The number of moves equals the number of productions applied (including ε-productions) plus the number of terminal matches. The input has 9 terminals, giving 9 matches, and 20 production applications, a total of 29. (For id + id * id the same count is 16.)

More Compiler Design questions

Exams that ask this topic