GATE Computer ScienceHardGATE CS (PYQ pattern)

Build the SLR(1) table of the ambiguous grammar E → E + E | E * E | id (augmented with S′ → E). How many LR(0) states are there, and how many ACTION cells are multiply defined?

  1. A. 7 states, 2 cells
  2. B. 9 states, 4 cells
  3. C. 7 states, 6 cells
  4. D. 7 states, 4 cells

Correct answer: D. 7 states, 4 cells

States: I0, S′ → E· (with E → E·+E, E·*E), E → id·, E → E+·E, E → E*·E, E → E+E·, E → E*E·: 7. FOLLOW(E) = {+, *, $}. In E+E· and E*E· the reduce on + and * meets the shifts on + and *: 2 cells in each of those 2 states = 4 (the $ cells are plain reduces).

More Compiler Design questions

Exams that ask this topic