Compiler Design and Construction - Old Questions

7.  What do you mean by kernel and non-kernel items? Compute the kernel items for LR(0) for the following grammar.

        

6 marks | Asked in 2069

Kernel Items

The initial item S‘ → •S and all the other items those with no dot (.) at the beginning of R.H.S are called the kernel items. For example, For any production A→ αBβ

    Kernels are A→ α.Bβ, A→ αB.β, A→ αBβ.

Non-Kernel Items

All items except first item S‘ → •S with dot (.) at the beginning of R.H.S are called the non-kernel items. For example A→ .αBβ


Now,

The augmented grammar of the given grammar is,

    S‘ → S

    S → CC

    C → bC | d

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

I0 = closure ({S‘ → •S}) = {S‘ → •S, S → •CC, C → •bC,  C → •d}

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

goto (I0, C) = closure ({S → C•C}) = {S → C•C, C → •bC, C→ •d} = I2

goto (I0, b) = closure ({C→ b•C}) = {C → b•C, C → •bC, C → •d} = I3

goto (I0, d) = closure ({C → d•}) = {C → d•} = I4

goto (I2, C) = closure ({S → CC•}) = {S → CC•} = I5

goto (I2, b) = closure ({C → b•C}) = {C → b•C, C → •bC, C → •d} = I3

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

goto (I3, C) = closure ({C → bC•}) = {C → bC•} = I6

goto (I3, b) = closure ({C → b•C}) = {C→ b•C, C → •bC, C → •d} = I3

goto (I3, d) = closure ({C → d•}) = {C → d•} = I4

Now the Kernel items for LR(0) for the given grammar are;

States

Kernel Items

I0

S‘  → •S

I1

S‘  → S•

I2

 → C•C

I3

 → b•C

I4

 → d•

I5

 → CC•

I6

C → bC•