SLR(1) Parser
It is the weakest of all 3 methods but it is easiest to implement The parsing can be done as follows:
- Construction of a set of canonical items.
- Construction of SLR parsing table.
- Parsing of the input string.
Example:
Construct the SLR parser for the grammar
S → AA
A → aA/ b
Solution:
Step 1: Construct a canonical set of items
Define the augmented grammar
S’ → S
S → AA
S → aA/ b
Initially I : S’ → S
Closure ( I ) : S’ → • S
S → • AA
A → • aA/ •b
Goto: (I0 , S ) = I1
S’ ⟶ S•
Goto: (I0 , A ) = I2
S’ ⟶ A•A
A ⟶ •aA / • b
Goto: (I0 , a ) = I3
S’ ⟶ a•A
A ⟶ •aA / • b
Goto: (I0 , b ) = I4
S’ ⟶ b•
Goto: (I2 , A ) = I5
S ⟶ AA•
Goto: (I0 , a ) = I5
A ⟶ a•A
A ⟶ •aA / • b
Goto: (I2 , b ) = I7
A ⟶ b•
Goto: (I0 , A ) = I2
A ⟶ aA•
Reference Link
