Spread Knowledge

CS606 - Compiler Construction - Lecture Handout 27

User Rating:  / 0
PoorBest 

Related Content: CS606 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Compiler Construction

LR Table Construction

LR Table Construction

The initial state is the one that contains the item [S' → •S, $]. All remaining entries are marked “error”. Let us go through an example and construct the LR table for the augmented grammar

  1. S' → E
  2. E → T – E
  3. E → T
  4. T → F × T
  5. T → F
  6. F → id

The FIRST sets we would need are

Symbol FIRST
S' { id }
E { id }
T { id }
F { id }
id { id }
× { × }
{ – }

We construct the canonical collection of set of LR(1)

canonical collection

canonical collection of set of LR(1)

filling the LR(1)

Apply

Apply1

non-terminal A ∈ G

final table

Let us parse the expression x – y × z using the LR(1) table. The scanner will encode the input string as id – id × id $ where $ is the EOF marker

using the LR(1) table