Example for CLR Parsing
Let us take an example and understand CLR Parsing.
Example:
Consider the grammar S → AA
A → aA/b
and construct the CLR(1) parser for the given grammar.
Sol: S → AA
A → aA/b
The augmented grammar is : S’→ .S,S
S → AA
A → aA/b
Closure (I) = S’ → .S,$
S → .AA, $
A → .aA, a/b
A → .b, a/b
| Goto (Io, $) = I1 S1 → S.,$ Goto (Io, A) = I2 S→ A.A,$ A→ .aA,$ A → .b, $ Goto (Io,a) = I3 A → a.A, a/b A → .aA, a/b A → .b, a/b Goto (I3, b) = I8 A → b., a/b Goto (I3, a) = I3 A → a.A, a/b A → .aA, a/b A → .b, a/b Goto (I3, b) = I4 A → b., a/b | Goto (Io, b) = I4 A → b, a/b Goto (I4, A) = I5 S → AA., $ Goto (I2, a) = I6 A → a.A, $ A → .aA, $ A → .b/$ Goto (I2, b) = I7 A → b, $ Goto (I0, A) = I9 A → aA. $ Goto (I0, a) = I6 A→ a.A, $ A → .aA, $ A → .b, $ Goto (I0, b) = I7 A→ b., $ |
Reference Link