Monday, 5 June 2017

What is difference between LR(0) item and LR(1) item?


                    In LR(0) and SLR(1), items which we use, are called LR(0) items which are of the form (A->.BCD or A->B.CD etc.). In CLR(1) and LALR(1), items which we use, are called as LR(1) items. These are of the form (A->.BCD, α).  Here α is a Lookahead symbol which represents the terminals after A .  

How To find Lookahead Symbol?

1. We start with item (S'->.S). It has Lookahead symbol $ as we assume that string ends at symbol $. So complete LR(1) item becomes (S'->.S, $).
2. If (A->.BCD, α) is item in closure, then next item will be (B->.DEF, FIRST(CDα).
Similarly,  
                  If (A->B.CD, α) is item in closure, then next item will be (C->.GHI, FIRST(Dα).
                 If (A->BC.D, α) is item in closure, then next item will be (C->.JKL, FIRST(α).
3. When we have to find first item of next closure, then Lookahead symbols are retained from the previous closure.
                     

No comments:

Post a comment