You are on page 1of 3

Q. Verify that the given grammar is LL(1), LR(0), SLR(1).

S  dA

S  aB

A  bA

Ac

B  bB

bc

ANS: Augmented Grammar:

S’  S

S  dA | aB

A  bA | c

B  bB | c

1. LL(1) :

FIRST(X) and FOLLOW (X) compute

FIRST(S) = {d, a}

FOLLOW(S) = {$}

FIRST(A) = {b, c}

FOLLOW(A) = {$}

FIRST(B) = {b, c}

FOLLOW(B) = {$}
Parse Table:

Non-Terminals Input Symbols

X a b c d $
S S  aB S  dA
A A  bA Ac
B B  bB Bc

No conflicts in (FIRST / FIRST) , (FIRST / FOLLOW) , (FOLLOW / FOLLOW) ,


the grammar G is LL(1)

Proof:

A grammar is LL(1) if and only if it has two distinct productions such as A  a | b and:

1. For both productions a and b , we must be able to derive a string with a


terminal such as ‘c’ or ‘d’. True.
2. One of a or b derives the empty string E. Not concerned.
3. If y  E , then a does not derive any string beginning with a terminal in
FOLLOW (A) and vice versa. Not concerned.

Hence LL(1).

2. LR(0) :
Proof:

After drawing a canonical collection of LR(0) items, we can go to final items, such as I1 , I9 ,
I4 , I6 , I7 , I10 , I11 to check for SR or RR conflicts.

In all these states, there is only one final item, which means there is no RR shift move which
means no SR conflict.

Hence LR(0).

3. SLR(1) :

If a grammar is LR(0) having no SR and RR conflicts, then the grammar will also be SLR(1).
Any LR(0) grammar can also be parsed by an SLR(1) parser.

Hence SLR(1).

Therefore the grammar is LL(1) , LR(0) , SLR(1).

You might also like