edited by
437 views
0 votes
0 votes
We know that a grammar is contain

1-left recursive

2-ambiguous

3-Common prefix

Then grammar is not LL(1)

 
If let I constructed M-TABLE or PARSE TABLE

of grammar which is not contain left recursive and common prefixes .

Let consider I am not able to find out grammar is ambiguous or not ,

If LL(1) parse table contains multiple choice in  same  row and  column then

Can I said that grammar is ambiguous or not?
edited by

1 Answer

0 votes
0 votes
When is a CFG ambiguous?

If we can find an $x \in L(G)$ such that for that particular $x$ we can have at least 2 different parse trees , then we can say that the grammar is ambiguous.

In compilers , in the syntax analysis phase , a parse tree is constructed by the parser with the use of LL(1) parsing table [Considering only LL(1) parsers here ]and is passed on to the semantic analysis phase.

How does this parsing takes place?

String is kept into the input buffer and each symbol is read from left to right and accordingly stack is either pushed with the RHS of a production or is popped.[Assuming here that you know how the  process works].

Now where is the problem regarding ambiguity here?

Suppose i/p symbol is 'a' , and in a particular cell in the parsing table , say $Table[E][a]$ has two or more entries , this mean we've multiple choices here , using any might lead to an acceptance by the parser , but would lead to completely different parse trees , right?

Now can we say that grammar is ambiguous? No , we cannot always say that the grammar is Ambiguous. Why? By using a particular production , out of one possible production , might lead to acceptance , might not .

LL(1) parsers might get confused as to which production to be used in this case , and since LL(1) parsers are predictive parsers , it rejects grammar with multiple entries , so to reject the possibility of a possible backtracking while parsing .

Related questions

0 votes
0 votes
1 answer
1
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...
1 votes
1 votes
1 answer
2
0 votes
0 votes
1 answer
3
shivanisrivarshini asked Mar 10, 2018
577 views
Can we have a grammar $G$ which is $LL(1)$ but not $SLR(1)$ ,If so given example grammar