GATE Computer ScienceVery hardGATE CS (PYQ pattern)

An LR parser for E → T E′; E′ → + T E′ | ε; T → F T′; T′ → * F T′ | ε; F → ( E ) | id parses "id + id * id". How many reductions does it make (not counting accept), and how many of them are by ε-productions?

  1. A. 11 reductions, 2 by ε-productions
  2. B. 8 reductions, 3 by ε-productions
  3. C. 13 reductions, 5 by ε-productions
  4. D. 11 reductions, 3 by ε-productions

Correct answer: D. 11 reductions, 3 by ε-productions

Reductions: F → id, T′ → ε (before +), T → F T′; F → id; F → id, T′ → ε (at $), T′ → * F T′, T → F T′, E′ → ε, E′ → + T E′, E → T E′. That is 11, of which T′ → ε twice and E′ → ε once are ε-reductions. (No T′ → ε occurs between the second id and *, because * is shifted.)

More Compiler Design questions

Exams that ask this topic