Compiler Design and Construction - Old Questions

4.  Differentiate between LR(0) and LR(1) algorithm.

6 marks | Asked in 2073

Difference between LR(0) and LR(1) algorithm

  • LR(0)requires just the canonical items for the construction of a parsing table, but LR(1) requires the loookahead symbol as well.
  • LR(1) allows us to choose the correct reductions and allows the use of grammar that are not uniquely invertible while LR(0) does not.
  • LR(0) reduces at all items whereas LR(1) reduces only at lookahead symbols.
  • LR(0) = canonical items and LR(1) = LR(0) + lookahead symbol.
  • In canonical LR(0) collection, state/item is in the form:

        E.g. I2 = { C → AB•}

        whereas In cannonical LR(1) collection, state/item is in the form: 

        E.g. I2 = { C →d•, e/d} where e & d are lookahead symbol.

  • Construction of canonical LR(0) collection starts with C = {closure({S‘→.S})} whereas Construction of canonical LR(1) collection starts with C = {closure({S‘→.S, $})} where S is the start symbol.
  • LR(0) algorithm is simple than LR(1) algorithm.
  • In LR(0), there may be conflict in parsing table while LL(1) parsing uses lookahead to avoid unnecessary conflicts in parsing table.