SLR (1) ParsingSLR (1) refers to simple LR Parsing. It is same as LR(0) parsing. The only difference is in the parsing table.To construct SLR (1) parsing table, we use canonical collection of LR (0) item. In the SLR (1) parsing, we place the reduce move only in the follow of left hand side. Various steps involved in the SLR (1) Parsing:
SLR (1) Table ConstructionThe steps which use to construct SLR (1) Table is given below: If a state (Ii) is going to some other state (Ij) on a terminal then it corresponds to a shift move in the action part. If a state (Ii) is going to some other state (Ij) on a variable then it correspond to go to move in the Go to part. If a state (Ii) contains the final item like A → ab• which has no transitions to the next state then the production is known as reduce production. For all terminals X in FOLLOW (A), write the reduce entry along with their production numbers. ExampleSLR ( 1 ) GrammarS → E Add Augment Production and insert '•' symbol at the first position for every production in G S` → •E I0 State: Add Augment production to the I0 State and Compute the Closure I0 = Closure (S` → •E) Add all productions starting with E in to I0 State because "." is followed by the non-terminal. So, the I0 State becomes I0 = S` → •E Add all productions starting with T and F in modified I0 State because "." is followed by the non-terminal. So, the I0 State becomes. I0= S` → •E I1= Go to (I0, E) = closure (S` → E•, E → E• + T) Add all productions starting with T and F in I5 State because "." is followed by the non-terminal. So, the I5 State becomes I5 = E → E +•T Go to (I5, F) = Closure (T → F•) = (same as I3) I6= Go to (I2, *) = Closure (T → T * •F) Add all productions starting with F in I6 State because "." is followed by the non-terminal. So, the I6 State becomes I6 = T → T * •F Go to (I6, id) = Closure (F → id•) = (same as I4) I7= Go to (I5, T) = Closure (E → E + T•) = E → E + T• Drawing DFA:SLR (1) TableExplanation:First (E) = First (E + T) ∪ First (T)
Next TopicCLR (1) Parsing |