GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Productions of the grammar are numbered: (1) E → E + T; (2) E → T; (3) T → T * F; (4) T → F; (5) F → ( E ); (6) F → id. An LR parser parses "id * ( id + id ) * id". In which order are the productions used for reductions (first reduction first)?

  1. A. 2, 3, 3, 4, 6, 5, 1, 2, 4, 6, 4, 6, 6
  2. B. 2, 3, 6, 3, 5, 1, 4, 6, 2, 4, 6, 4, 6
  3. C. 6, 4, 6, 4, 2, 6, 4, 1, 5, 3, 6, 3, 2
  4. D. 6, 6, 4, 6, 4, 2, 1, 5, 6, 4, 3, 3, 2

Correct answer: C. 6, 4, 6, 4, 2, 6, 4, 1, 5, 3, 6, 3, 2

A bottom-up parser reduces the handles of a rightmost derivation in reverse; the production numbers in reduction order are 6, 4, 6, 4, 2, 6, 4, 1, 5, 3, 6, 3, 2. Preorder of the tree gives the leftmost derivation instead.

More Compiler Design questions

Exams that ask this topic