Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 10

SLR PARSING

LR(0) Isn’t Good Enough
 LR(0) is the simplest technique in the LR 
family. 

 Too weak to be of practical use for 
a very limited set of grammars

 Today we will consider SLR(1) where the S
stands for simple
How to construct SLR parsing
table?
 E->T+E
 E->T
 T->i

 Step 1: Create Augmented Grammar


 E’ -> E
 E->T+E
 E->T
 T->i
How to construct parsing table?...

• Step 2: 1
5

E’ -> .E Accepted
E->.T+E E -> T+E.
E E’ -> E .
E->.T
T->.i
T E
0 4
2 E -> T+.E
E->T.+E + E->.T+E
E->.T T
E->T.
T->.i
2
i i
3

T ->i. 3
Parsing Table
i + $ E T
0 S3 1 2
1 accepted
2 S4 r2
3
r3 r3
4 s3 5 2

5
r1

1. E->T+E 1. Follow(E)-> {$}


2. E->T 2. Follow(T)->{+,$}
3. T->i
Conflicts
 Multiple entries ……….
 SR Conflict
 RR Conflict
SR Conflict
 S->Aa | bAc | dc | bda
 A -> d
 Step 1:
 S’ -> S
 S->Aa
 S-> bAc
 S-> dc
 S-> bda
 A -> d
SR conflict
If A->  α. a β
1 B-> γ .
0
S’ ->. S If follow(B) contains letter
S S’ -> S.
S->.Aa followed by . Symbol in A
S-> .bAc production, then its SR
S-> .dc A
conflict.
S-> .bda 2
A -> .d Here, follow(A) = {a,c}
S->A.a
b

d
4 3
S-> b.Ac d A->d.
A -> .d S->bd.a
S-> d.c
S-> b.da
A -> d.
RR Conflict
 S’ -> S
 S->Aa
 S-> Bc
 S-> bBa
 B-> d
 A -> d
RR conflict
If A->  α.
0 B-> γ .

S’ -> .S If follow(A) Πfollow(B) ≠ φ


S->.Aa
S-> .Bc then its RR conflict.
S-> .bBa
B-> .d Here, follow(A) = {a}
A ->.d follow(B) = {c,a}

A->d.
B->d.

You might also like