Compiler Design and Construction - Old Questions

5.  Consider the grammar


Calculate the canonical LR(0) items.

6 marks | Asked in 2068

The augmented grammar of given grammar is,

    C‘→ C

    C → AB

    A → a

    B → b

Next, we obtain the canonical collection of sets of LR(0) items, as follows,

I0 = closure ({C‘ → •C}) = {C‘ → •C, C → •AB, A → •a}

goto(I0, C) = closure(C‘ → C•) = { C‘ → C•} = I1

goto(I0, A) = closure(C → A•B) = { C → A•B, B → •b} = I2

goto(I0, a) = closure(A → a•) = { A → a• } = I3

goto(I2, B) = closure(C → AB•) = { C → AB•} = I4

goto(I2, b) = closure(B → b•) = { B → b•} = I5

Now, the canonical collection of sets of LR(0) items for given grammar are: