Lalr - Parser: S' - S S - BBB S - Aab S - Bba B - A
Lalr - Parser: S' - S S - BBB S - Aab S - Bba B - A
LALR -PARSER
There are three issues which arise here—
1. Whether LALR is equivalent to SLR.
2. Shift/Reduce conflict in the cases of LR(1) and LALR.
3. Reduce/Reduce conflict in the cases of LR(1) and LALR.
S’ -> S
S -> Bbb
S -> aab
S -> bBa
B -> a
I0 : S’ -> .S
S -> .Bbb
S -> .aab
S -> .bBa
B -> .a
I1: S’ -> S.
I2: S -> B.bb
I3: S -> a.ab
B -> a.
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.
In the underlined item, there is a shift/reduce conflict. To avoid this conflict, we work
with LR(1) parser.
1
Vishwa Deepak 04cs1029
*************************************************************
S’-> S
S-> aAd
S-> bBd
S-> aBe
S-> bAe
A-> c
2
Vishwa Deepak 04cs1029
B-> c
The underlined items are of our interest. We see that when we make the Parsing table for
LR (1), we will get something like this…
3
Vishwa Deepak 04cs1029
a ……………… d e
I1 . .
I2 . .
. . .
. . .
.
I6 ………………. r6 r7
.. . .
. . .
. .
. . .
I9 …………………. r7 r6
.
This table on reduction to the LALR parsing table, comes up in the forms of-
a ……………… d e
I1 . .
I2 . .
. . .
. . .
.
I69 ………………. r6/r7 r7/r6
.. . .
. . .
. .
. . .
I9 …………………. r7 r6
4
Vishwa Deepak 04cs1029
So, we find that the LALR gains reduce-reduce conflict whereas the corresponding LR (1)
counterpart was void of it. This is a proof enough that LALR is less potent than LR (1).
But, since we have already proved that the LALR is void of shift-reduce conflicts (given that
the corresponding LR(1) is devoid of the same), whereas SLR (or LR (0)) is not necessarily
void of shift-reduce conflict, the LALR grammar is more potent than the SLR grammar.
LR (1)
LALR
So, we have answered all the queries on LALR that we raised intuitively.