0% found this document useful (0 votes)
62 views3 pages

Q. Verify That The Given Grammar Is LL (1), LR (0), SLR

The document verifies that a given grammar is LL(1), LR(0), and SLR(1). It is determined to be: LL(1) because the FIRST and FOLLOW sets are computed and the parse table shows no conflicts between productions. LR(0) because drawing the canonical collection of LR(0) items shows that all final items have only one production, so there are no shift-reduce or reduce-reduce conflicts. SLR(1) because any grammar that is LR(0) will also be SLR(1), as an SLR(1) parser can parse any LR(0) grammar.

Uploaded by

Faisal Shehzad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views3 pages

Q. Verify That The Given Grammar Is LL (1), LR (0), SLR

The document verifies that a given grammar is LL(1), LR(0), and SLR(1). It is determined to be: LL(1) because the FIRST and FOLLOW sets are computed and the parse table shows no conflicts between productions. LR(0) because drawing the canonical collection of LR(0) items shows that all final items have only one production, so there are no shift-reduce or reduce-reduce conflicts. SLR(1) because any grammar that is LR(0) will also be SLR(1), as an SLR(1) parser can parse any LR(0) grammar.

Uploaded by

Faisal Shehzad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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