Professional Documents
Culture Documents
LR (1) & Lalr Parser: Prepared By: Nitin Goyal - 04Cs1026 Jitendra Bindal - 04Cs1027
LR (1) & Lalr Parser: Prepared By: Nitin Goyal - 04Cs1026 Jitendra Bindal - 04Cs1027
Prepared By:
NITIN GOYAL - 04CS1026
2. S -> CC
3. C -> cC
4. C -> d
SET OF ITEMS:
4 & 7
8 & 9
LALR PARSING TABLE
SHIFT-REDUCE CONFLICT
COMPARISON OF LR (1) AND LALR:
1. If LR (1) has shift-reduce conflict then
LALR will also have it.
2. If LR (1) does not have shift-reduce conflict
LALR will also not have it.
3. Any shift-reduce conflict which can be
removed by LR (1) can also be removed by
LALR.
4. For cases where there are no common
cores SLR and LALR produce same parsing
tables.
SHIFT-REDUCE CONFLICT
LR(1) Parser-
How Does a shift-Reduce conflict arises?
IA : { E->α..βc, F->γ. } & FOLLOW(F)={β}
For Eg. I3 : {E->L.=R , R-> L. } &
Follow(E)={=}
For Solving this Problem by LALR Parser:
IA={E->α.βc,ω1 ; F->γ.,δ1}
IB={E->α.βc,ω2 ; F->γ.,δ2}
IAB={E->α.βc,ω1|ω2 ; F->γ.,δ1|δ2}
SHIFT-REDUCE CONFLICT
COMPARISON OF SLR AND LALR:
1. If SLR has shift-reduce conflict then LALR may or may
not remove it.
2. SLR and LALR tables for a grammar always have
same number of states.
SLR
(Some of them are solved in….)
LR (1)
(All those solved are preserved in…)
LALR
So, we have answered all the queries on
LALR that we raised intuitively.
Visit:
http://www.facweb.iitkgp.ernet.in/~niloy/COURSE/Autumn2006/Compi
ler/main.html#Lecture