9,297 views

2 Answers

5 votes
5 votes

If our intention is to only check if this grammar is LL(1) or not then we dont need to do any of these first ,follow calculation then creating LL(1) parsing table and check if one cell contain multiple entries or not .

By looking at the grammar we can conclude that it is not LL(1) as it is left recursive .

The left recursive productions are

1)A→ ASd

2)C→ Cg.

now we can eliminate the left recursion and try to check for LL(1) or not but that is a topic for another question  we have to consider the grammar which we have given.

First we need to compute the first and follow set for the grammar.

Non terminal First Follow
$S$ $\left \{ a,\epsilon \right \}$ $\left \{ a,f,d,dollor \right \}$
$A$ $\left \{ a,d,\epsilon \right \}$ $\left \{ a,h,b,d \right \}$
$B$ $\left \{ a,h,\epsilon \right \}$ $\left \{ a,b,f,d,dollor \right \}$
$C$ $\left \{ a,f \right \}$ $\left \{ a,b,f,d,g,dollor \right \}$
$D$ $\left \{ a,\epsilon \right \}$ $\left \{ a,f,d,dollor \right \}$

 

Now we have to draw LL(1) parsing table:-

  $a$ $b$ $c$ $d$ $f$ $g$ $h$ $Dollor$
$S$

$S → aABbCD$

$S→ \epsilon$

    $S->\epsilon$ $S->\epsilon$     $S->\epsilon$
$A$

$A-> ASd$ 

$A-> \epsilon$

$A-> \epsilon$  

$A-> ASd$

$A-> \epsilon$

    $A-> \epsilon$  
$B$

$B-> Sac$

$B-> \epsilon$

$B-> \epsilon$   $B-> \epsilon$ $B-> \epsilon$   $B-> hC$ $B-> \epsilon$
$C$ $C-> Sf$       $C-> Sf$      
$D$

$D-> aBD$

$D-> \epsilon$

    $D-> \epsilon$ $D-> \epsilon$     $D-> \epsilon$

As we can see multiple entries in single cell then we can conclude it is not LL(1).

 

Related questions

2 votes
2 votes
1 answer
2
sripo asked Nov 10, 2018
3,247 views
Can you give an example which is not LL(1) but is CLR(1)
0 votes
0 votes
1 answer
3
Rahul Ranjan 1 asked Mar 19, 2018
4,964 views
Given a grammar :$E \rightarrow E + T / T$$T \rightarrow i$Can I directly say that grammar is not $LL(1)$ because $LL(1)$ can't parse Left Recursive Grammar, without dra...