in Compiler Design edited by
12,779 views
40 votes
40 votes

The grammar $ S \to aSa \mid bS \mid c$ is 

  1. LL(1) but not LR(1)
  2. LR(1) but not LL(1)
  3. Both LL(1) and LR(1)
  4. Neither LL(1) nor LR(1)
in Compiler Design edited by
12.8k views

2 Comments

We will take First(S) and try to find if any transition of terminals may cause more than one entry –below is the pictorial.

As all the terminal transition while determining the First(S) is unique so it’s LL(1) and subsequently we can deduce it’s LR(0). 

0
0
10
10

2 Answers

8 votes
8 votes
Best answer
The $\textsf{LL(1)}$ parsing table for the given grammar is:

$\begin{array}{|c|c|c|} \hline
& a&b&c \\ \hline
S& S\to aSa & S\to b & S \to c \\ \hline
\end{array}$

For any given input symbol $a,b$ or $c,$ the parser has a unique move from the start and the only state – so no conflicts.

As there is no conflict in $\text{LL(1)}$ parsing table, the given grammar is $\textsf{LL(1)}$ and since every $\textsf{LL(1)}$ is also $\textsf{LR(1)},$ the given grammar is $\textsf{LL(1)}$ as well as $\textsf{LR(1)}.$
selected by
46 votes
46 votes

Correct Option: C

For LL(1) take First(S). and do intersection between the result. if intersection is Phi then LL(1) else not.

Making a parsing table and checking if there are two or more entries under any terminal. If yes then neither LL(1) nor LR(1).

edited by

4 Comments

What's the intersection here?
0
0
{a} intersection {€} =Phi. Still It's not LL(1).
0
0

@raja11sep Yes, the line is wrong.

The correct line should be:-

  1. If prod are of the form $A → \alpha_1| \alpha_2|...| \alpha_n| $ then if first set of atleast any 2 productions (not first(A) )have common elements → Grammar is not LL(1).
  2. If prod are of the form $A → \alpha| \epsilon$ then if $First (\alpha)$ ∩ $Follow(A) ≠ ∅$ → Not LL(1)

 Whenever we have $\epsilon$ we should take intersection of first of every prod except null with follow of that variable (here S).

So, in S$→ aSa | \epsilon$

$First(aSa) $∩$ Follow(S) = {a} $∩$ {a} = {a} → Not LL(1)$

2
2
Answer:

Related questions