Professional Documents
Culture Documents
What is clr1?
CLR parsing refers to the canonical lookahead. We will use the canonical collection of
LR(1) items for the construction of the CLR(1) parsing table. Generally, CLR(1) parsing
has more number of states as compared to SLR(1) parsing. In the CLR(1), the reduced
node will be placed only in the lookahead symbols.
LR(1) item is the collection of LR(0) item and lookahead. The lookahead symbol is used
to determine the place of the final item. For every augmented grammar, the lookahead
will be $.
Example
Grammar
E => BB
B => cB / d
Add augment production and insert ‘.’ symbol at the beginning of every production in
Grammar Add the lookahead also.
E’ => .E, $
E => .BB,$
B => .cB, c/d
I0 state
Add all the production beginning with E into I0 State because “.” is at the first place of
production before the non-terminal. So, the I0 State becomes:
I0 = E’ => .E, $
E => .BB, $
Add all the production begins with “B” in the modified I0 State because “.” is at the first
place of production before the non-terminal. So, the I0 State becomes:
E’ => .E, $
E => .BB, $
B => .cB, c/d
B => .d, c/d
Add all the production beginning with B into the I2 State because “.” is at the first place
of production before the non-terminal. So, the I2 State becomes:
E => B.B, $
B => .cB, $
B => .d, $
I3 = Go to on (I0 c) = Closure (B => c.B, c/d)
Add all the production beginning with B into the I6 State because “.” is at the first place
of production before the non-terminal. So, the I6 state becomes
B => c.B, $
B => .cB, $
B => .d, $
Drawing DFA
-----------------------------------draw dfa-------------------
Production to be numbered as follows:
E’ => E
E => BB (1)
B => cB(2) /d (3)
c d $ E B
I0 S3 S4 1 2
I1 accept
I2 S6 S7 5
I3 S3 S4 8
I4 r3 r3
I5 r1
I6 S6 S7 9
I7 r3
I8 r2 r2
I9 r2