22,169 views
43 43 votes

Consider the grammar with non-terminals $N=\left\{S,C,S_1\right\}$, terminals $T=\left\{a, b, i, t, e\right\}$, with $S$ as the start symbol, and the following set of rules:

$S \rightarrow iCtSS_1 \mid a$

$S_1 \rightarrow eS \mid \epsilon$

$C \rightarrow b$

The grammar is NOT LL(1) because:

  1. it is left recursive

  2. it is right recursive

  3. it is ambiguous

  4. it is not context-free

6 Answers

Best answer
58 58 votes

Here, we can expand any one of $S_1$ to $\in$ and other to $ea$, but which one will it be need not matter, because in the end we will still get the same string.

This means that the Grammar is Ambiguous. $\text{LL(1)}$ cannot be ambiguous. Here's a Proof for that

$${\color{Magenta}{\underline{\textbf{LL(1) Derivations}}}} $$

${\color{Blue}{\textbf{L}} }$eft to  Right Scan of input

   ${\color{Blue}{\textbf{L}} }$eftmost Derivation

       ${\color{Blue}{\textbf{(1)}} }$ look ahead $1$ token at each step

$\text{Alternative characterization of LL(1) Grammars:}$

Whenever $A \rightarrow \alpha \mid \beta \in G$

  1. $\text{FIRST}(\alpha) \cap \text{FIRST}(\beta) = \{\},$ and
  2. If $\alpha \overset{\ast}{\implies} \varepsilon$ then $\text{FIRST}(\beta) \cap \text{FOLLOW}(A) = \{\}.$

$\textbf{Corollary:}$ No Ambiguous Grammar is $\text{LL(1)}.$

Correct Answer: C.

• edited by
14 14 votes

Finding a counter-example for ambiguity is a bit time consuming here. Go for option elimination.

Option A is wrong, because clearly it's not Left Recursive. ( Only A → Aa is Left Recursive )

Option B is wrong, because Right Recusrsion is not an issue for a grammar to be LL(1)

Option D is wrong, because any grammar of the form A → *anything* is Context-free.

So, Option C is correct.


Edit:

This grammar represents the Dangling Else problem. This language is inherently ambiguous.

If $S_1$ then $S_2$  else $S_3$ $|$ If $S_1$ then $S_2$ 

Here, we have an optional else, which creates ambiguity.

 

We'll always have two (exactly two) parse trees for the statement

if $<S>$ then if $<S>$  then $<S>$ else $<S>$

• edited by
1 flag:
✌ Edit necessary (Bit_by_Bit “existence of an ambiguous grammar does not mean the language itself is "inherently ambiguous."”)
5 5 votes
It is left factored version of the dangling else grammar. As we know,left factoring eliminates non determinism,but can not eliminate ambiguity,So ans should be (C)  

PS.

1) Surely its not left recursive .

2) Right recursion is not an issue for LL(1) .

3) It is context free .
0 0 votes
Given grammar is not LL(1) it doesn't mean it is ambiguous....it can be unambiguous also......

So u need to check ...for string for which it is ambiguous...then option c is correct...

In this case definitely option elimination give u option c... easy one only.
0 0 votes
for option C can we say that ?

there are two entries for S1 for terminal ‘e’  in parsing table….so grammar couldn’t decide whether to use S-->epsilon or

S-->eS

Hence grammar is ambigious.
Answer:
Position:
Show:

Related questions

34 34 votes
5 answers 5 answers
15.2k
15.2k views
go_editor asked Apr 23, 2016
15,217 views
Consider the CFG with $\left\{S, A, B\right\}$ as the non-terminal alphabet, $\{a, b\}$ as the terminal alphabet, $S$ as the start symbol and the following set of product...
33 33 votes
3 answers 3 answers
15.8k
15.8k views
Kathleen asked Sep 21, 2014
15,804 views
Consider the CFG with $\left\{S, A, B\right\}$ as the non-terminal alphabet, $\{a, b\}$ as the terminal alphabet, $S$ as the start symbol and the following set of product...
96 96 votes
11 answers 11 answers
54.5k
54.5k views
Kathleen asked Sep 21, 2014
54,515 views
Consider the following two statements:P: Every regular grammar is LL(1)Q: Every regular set has a LR(1) grammarWhich of the following is TRUE?Both P and Q are trueP is tr...
24 24 votes
3 answers 3 answers
13.2k
13.2k views
Kathleen asked Sep 21, 2014
13,203 views
Which one of the following is a top-down parser?Recursive descent parser.Operator precedence parser.An LR(k) parser.An LALR(k) parser.