LR parser
description
Transcript of LR parser
![Page 1: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/1.jpg)
LR parser
![Page 2: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/2.jpg)
Types of LR Parser
• LR Parser– SLR(1) or LR(0)– CLR or LR(1)– LALR
![Page 3: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/3.jpg)
Construct LR parser for given grammer
• E->E+T
• E->T
• T->T*F
• T->F
• F->(E)
• F->id
![Page 4: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/4.jpg)
• Take first production rule in Io state
• Then if rule A->a.Bb is a rule and B->c/d is production then then add B->.c , B->.d in closure.
• In I4 state don’t expand E->.T because I2 have same one.No need to apply it.
I1
I2
I3
I4
I5
![Page 5: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/5.jpg)
![Page 6: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/6.jpg)
![Page 7: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/7.jpg)
CLR or LR(1)
• S->CC
• C->aC
• C->d
![Page 8: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/8.jpg)
• In first production add $ as its canonical collection.
• If production is [A->aBb, a1] & if there is production
B->.b1,c then add
B->.b1,c
c belongs to First(b a1)
Here S’->.S null,$
so first (null $) is $ that’s why
S->.CC,$
Here C->.aC
So first (C)={a,d}
first(C $)={a,d} that’s why
C->.aC,a/d
No need to expand I3 =goto(I3,a)
![Page 9: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/9.jpg)
![Page 10: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/10.jpg)
LALR CLR
![Page 11: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/11.jpg)
![Page 12: LR parser](https://reader035.fdocuments.us/reader035/viewer/2022070411/568146f2550346895db425b2/html5/thumbnails/12.jpg)