Assignment No 3
Assignment No 3
3
Q.1. For the given grammar, show the canonical collection of LR (1) items, then construct
the CLR (1) parsing table.
Show all the possible sequences of actions on input 'abbcde' for grammar 1.
Grammar 1:
S → aABe
A → Abc
A→b
B→d
2. Goto Operations:
- On `S`, go to I1:
I1:
S' → S., $
- On `a`, go to I2:
I2:
S → a.ABe, $
A → .Abc, e
A → .b, e
B → .d, e
- On `A`, go to I3:
I3:
S → aA.Be, $
B → .d, e
- On `B`, go to I4:
I4:
S → aAB.e, $
- On `e`, go to I5:
I5:
S → aABe., $
- On `b`, go to I6:
I6:
A → b., e
- On `d`, go to I7:
I7:
B → d., e
- On `c`, go to I8:
I8:
A → Ab.c, e
- On `b`, go to I9:
I9:
A → Abc., e
0 S2 1 3
1 acc
2 S6 3 4
3 S7
4 S5
5 acc
6 9
Grammar 2:
S → xAy | xBy | xAz
A → aS | q
B→q
2. Goto Operations:
- On `S`, go to I1:
I1:
S' → S., $
- On `x`, go to I2:
I2:
S → x.Ay, $
S → x.By, $
S → x.Az, $
A → .aS, y
A → .q, y
B → .q, y
- On `A`, go to I3:
I3:
S → xA.y, $
- On `B`, go to I4:
I4:
S → xB.y, $
- On `y`, go to I5:
I5:
S → xAy., $
S → xBy., $
S → xAz., $
- On `a`, go to I6:
I6:
A → a.S, y
S → .xAy, y
S → .xBy, y
S → .xAz, y
- On `q`, go to I7:
I7:
A → q., y
B → q., y
Canonical Collection of Items:
I0, I1, I2, I3, I4, I5, I6, I7
0 S2 1
1 acc
2 S6 S7 3 4
3 S5
4 S5