GATE Computer ScienceVery hardGATE CSE · NIELIT

Grammar: E → E + T | T; T → T * F | F; F → id. An SLR(1) parser parses id + id * id + id * id (followed by $). Counting each shift and each reduce as one move (excluding the final accept), how many shift moves and reduce moves are made?

  1. A. 9 shifts and 12 reduces
  2. B. 9 shifts and 13 reduces
  3. C. 8 shifts and 14 reduces
  4. D. 9 shifts and 15 reduces

Correct answer: B. 9 shifts and 13 reduces

Every id and operator is shifted (5 + 4 = 9); reduces: 5 for F→id, 3 for T→F (one per term), 2 for T→T*F, 1 for E→T and 2 for E→E+T = 13.

More Compiler Design questions

Exams that ask this topic