1 / 13

LALR PARSER

LALR PARSER. Prepared by VISHWA DEEPAK 04CS1029. 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. Taking an example Grammar. S’ -> S S -> Bbb

apu
Télécharger la présentation

LALR PARSER

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LALR PARSER Prepared by VISHWA DEEPAK 04CS1029 Vishwa Deepak 04CS1029

  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. Vishwa Deepak 04CS1029

  3. Taking an example Grammar • S’ -> S • S -> Bbb • S -> aab • S -> bBa • B -> a Vishwa Deepak 04CS1029

  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. Vishwa Deepak 04CS1029

  5. 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. Vishwa Deepak 04CS1029

  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 Vishwa Deepak 04CS1029

  7. 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. Vishwa Deepak 04CS1029

  8. NEXT GRAMMAR (EXAMPLE)#To discuss reduce/reduce conflict • S’-> S • S-> aAd • S-> bBd • S-> aBe • S-> bAe • A-> c • B-> c Vishwa Deepak 04CS1029

  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 Vishwa Deepak 04CS1029

  10. 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. Vishwa Deepak 04CS1029

  11. LR parser Item d e I1 .. .. I2 .. .. .. .. .. I6 r6 r7 .. .. .. I9 r7 r6 .. .. .. LALR parser Item d e I1 .. .. I2 .. .. .. .. .. I69 r6/r7 r6/r7 .. .. .. I10 .. .. .. .. .. LR and LALR parsing tables Vishwa Deepak 04CS1029

  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. Vishwa Deepak 04CS1029

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

More Related