CLR 1 Parsing - Javatpoint
CLR 1 Parsing - Javatpoint
In the CLR (1), we place the reduce node only in the lookahead symbols.
ADVERTISEMENT ADVERTISEMENT
LR (1) item
ADVERTISEMENT
The look ahead is used to determine that where we place the final item.
The look ahead always add $ symbol for the argument production.
Example
CLR ( 1 ) Grammar
S → AA
A → aA
A→b
Add Augment Production, insert '•' symbol at the first position for every production in G and also add
the lookahead.
ADVERTISEMENT ADVERTISEMENT
S` → •S, $
S → •AA, $
A → •aA, a/b
A → •b, a/b
I0 State:
Add all productions starting with S in to I0 State because "." is followed by the non-terminal. So, the I0
State becomes
I0 = S` → •S, $
S → •AA, $
Add all productions starting with A in modified I0 State because "." is followed by the non-terminal. So,
the I0 State becomes.
I0= S` → •S, $
S → •AA, $
A → •aA, a/b
A → •b, a/b
I1= Go to (I0, S) = closure (S` → S•, $) = S` → S•, $
I2= Go to (I0, A) = closure ( S → A•A, $ )
Add all productions starting with A in I2 State because "." is followed by the non-terminal. So, the I2
State becomes
I2= S → A•A, $
A → •aA, $
A → •b, $
Add all productions starting with A in I3 State because "." is followed by the non-terminal. So, the I3
State becomes
Add all productions starting with A in I6 State because "." is followed by the non-terminal. So, the I6
State becomes
I6 = A → a•A, $
A → •aA, $
A → •b, $
S → AA ... (1)
A → aA ....(2)
A → b ... (3)