Site icon i2tutorials

Compiler Design-Constructing SLR parsing tables

Constructing SLR parsing tables

 

The SLR and LR(0) are similar to each other except for the reduced entry.

The reduced productions are written only in the FOLLOW of the variable whose production is reduced.

 

There are different steps involved in SLR parsing:

  1. Write context-free grammar for the given input string.
  2. Check ambiguity of grammar
  3. In given grammar, add augment production 
  4. Create a canonical collection of LR items.
  5. Draw a data flow Diagram or DFA
  6. Construct an SLR parsing table.

 

SLR table Construction

Steps to create an SLR table are as follows:

  1. 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.
  2. If a state (Ii) is going to some other state (Ij) on a variable then it corresponds to the go-to move in the Go to part.
  3. 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 reduced entry along with their production numbers.

 

Reference Link

Constructing SLR parsing tables

Exit mobile version