Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by VISHWA DEEPAK 04CS1029

Similar presentations


Presentation on theme: "Prepared by VISHWA DEEPAK 04CS1029"— Presentation transcript:

1 Prepared by VISHWA DEEPAK 04CS1029
LALR PARSER Compiler Prepared by VISHWA DEEPAK 04CS1029 24-Feb-19 Vishwa Deepak CS1029

2 There are three issues which arise here—
Whether LALR is equivalent to SLR. Shift/Reduce conflict in the cases of LR(1) and LALR. Reduce/Reduce conflict in the cases of LR(1) and LALR. 24-Feb-19 Vishwa Deepak CS1029

3 Taking an example Grammar
S’ -> S S -> Bbb S -> aab S -> bBa B -> a 24-Feb-19 Vishwa Deepak CS1029

4 Items using SLR PARSER I0 : S’ -> .S S -> .Bbb S -> .aab
S -> .bBa B -> .a I1: S’ -> S. I2: S -> B.bb I3: S -> a.ab B -> a. 24-Feb-19 Vishwa Deepak CS1029

5 Underlined item shows shift/reduce conflict.
I4: S -> b.Ba B -> .a I5: S-> Bb.b I6: S -> aa.b I7: S -> bB.a I8: B -> a. I9: S-> Bbb. I10: S -> aab. I11: S -> bBa. Underlined item shows shift/reduce conflict. 24-Feb-19 Vishwa Deepak CS1029

6 Items using LR(1) PARSER
I0 : S’ -> .S , $ S -> .Bbb ,$ S -> .aab , $ S -> .bBa , $ B -> .a ,a|b I1: S’ -> S. ,$ I2: S -> B.bb , $ I3: S -> a.ab ,$ B -> a. , b I4: S -> b.Ba , $ B -> .a ,a 24-Feb-19 Vishwa Deepak CS1029

7 & Number of states in SLR parser = Number of states in LR(1) parser.
I5: S-> Bb.b ,$ I6: S -> aa.b ,$ I7: S -> bB.a ,$ I8: B -> a. ,a I9: S-> Bbb. ,$ I10: S -> aab. ,$ I11: S -> bBa. ,$ In the underlined item , we find that there is no shift / reduce conflict. Here LALR = LR(1) & Number of states in SLR parser = Number of states in LR(1) parser. 24-Feb-19 Vishwa Deepak CS1029

8 NEXT GRAMMAR (EXAMPLE) #To discuss reduce/reduce conflict
S-> aAd S-> bBd S-> aBe S-> bAe A-> c B-> c 24-Feb-19 Vishwa Deepak CS1029

9 Items using LR(1) PARSER
I0 : S’-> .S , $ S-> . aAd, $ S-> . bBd, $ S-> . aBe, $ S-> . bAe, $ I1: S’-> S ., $ I2: S-> a . Ad, $ S-> a . Be, $ A-> .c, d B->.c, e I3: S-> b . Bd, $ S-> b . Ae, $ A->.c, e B->.c,d 24-Feb-19 Vishwa Deepak CS1029

10 The underlined items are of our interest.
I4: S->aA.d, $ I5: S-> aB.e,$ I6: A->c. , d B->c. , e I7: S->bB.d, $ I8: S->bA.e, $ I9: B->c. , d A->c. , e I10: S->aAd. , $ I11: S->aBe., $ I12: S->bBd., $ I13: S->aBe., $ The underlined items are of our interest. There is no reduce/reduce conflict in the underlined items, due to different follows. 24-Feb-19 Vishwa Deepak CS1029

11 LR and LALR parsing tables
LR parser Item d e I I I r r7 I r r6 LALR parser Item d e I I I r6/r7 r6/r7 I 24-Feb-19 Vishwa Deepak CS1029

12 In the last slide we found that even there was no R/R conflict in LR(1) parser, it appeared in LALR parser. This shows that LALR is less potent than LR(1) parser ,since it gains R/R conflict. LALR is free of S/R conflict , if LR(1) is. But SLR may be having this conflict. So, SLR is least potent among all the three. 24-Feb-19 Vishwa Deepak CS1029

13 CONCLUSION SHIFT-REDUCE CONFLICT present in SLR 
Some of them are solved in…. LR (1) All those solved are preserved in… LALR 24-Feb-19 Vishwa Deepak CS1029


Download ppt "Prepared by VISHWA DEEPAK 04CS1029"

Similar presentations


Ads by Google