Consider the following grammar:

                         

Prove the above grammar is LL (1). Draw the parsing table. Now check whether the string β€œab” and β€œacbd” are the languages of the above grammar. (Derive each step with the help of a stack.)

 

Added 2 years ago
Active
Viewed 1081
Ans

            S → aABb

             A → c|πœ–

             B → d|πœ–

Left Factoring is a grammar transformation technique. It consists in "factoring out" prefixes which are common to two or more productions. Ex.    A -> α β | α γ

Left Recursion is a property a grammar has whenever you can derive from a given variable (non terminal) a RHS that begins with the same variable, in one or more steps.  Ex.   A -> A α

 

In the above grammar, there is no Left Factoring, or Left Recursion. So, we can say that this is LL(1).

FIRST(S)={a}

FIRST(A)={c,πœ–}

FIRST(B)={d,πœ–}

FOLLOW(S)={$}

FOLLOW(A)={d,b}

FOLLOW(B)={b}

 

LL(1) Parsing Table:

 

a

b

c

d

$

S → aABb

S → aABb

 

 

 

 

A → c|πœ–

 

A → πœ–

A → c

A → πœ–

 

B → d|πœ–

 

B → πœ–

 

B → d

 

 

Checking the acceptance of the string ‘ab’

 

Stack

Input

Action

Output

$S

ab$

Top of stack is Nonterminal, so expand

S → aABb

$bBAa

ab$

Top of stack is Terminal, so pops off

 

$bBA

b$

Top of stack is Nonterminal, so expand

A → πœ–

$bB

b$

Top of stack is Nonterminal, so expand

B → πœ–

$b

b$

Top of stack is Terminal, so pops off

 

$

$

Accept, successful completion

 

 

Checking the acceptance of the string ‘acdb’

 

Stack

Input

Action

Output

$S

acdb$

Top of stack is Nonterminal, so expand

S → aABb

$bBAa

acdb$

Top of stack is Terminal, so pops off

 

$bBA

cdb$

Top of stack is Nonterminal, so expand

A → c

$bBc

cdb$

Top of stack is Terminal, so pops off

 

$bB

db$

Top of stack is Nonterminal, so expand

B → d

$bd

db$

Top of stack is Terminal, so pops off

 

$b

b$

Top of stack is Terminal, so pops off

 

$

$

Accept, successful completion

 



Related Questions