in Compiler Design
23,306 views
37 votes
37 votes

The grammar $A \rightarrow AA \mid (A) \mid \epsilon$ is not suitable for predictive-parsing because the grammar is:

  1. ambiguous

  2. left-recursive

  3. right-recursive

  4. an operator-grammar

in Compiler Design
23.3k views

2 Comments

The given grammar is Ambiguous and left recursive....

But it's also not operator grammar

Because property is (NO two variable in right side or No null production).

What's correct answer??
0
0
Had it been a recursive descent parser (with backtracking), then this same grammar shall be suitable right?
0
0

4 Answers

72 votes
72 votes
Best answer

both A and B can be answers but A is a better answer. Because we have standard procedure for removing left-recursion but ambiguity is not easy to remove. - checking if a given CFG is ambiguous is a undecidable problem.

edited by

3 Comments

Since ambiguity is undecidable problem so left recursion should be answer then, isn't it?
1
1
A->AA

both left recursive and right recursive??
2
2
1
1
15 votes
15 votes

Any Grammar which is Left Recursive will cause any Predictive Parser to fall into an infinite loop. No matter if it is ambiguous or not, it won't be parsable. This is more stronger than saying it is ambiguous so fails.

Hence, answer = option B

4 Comments

It can not be parse when ambiguous. Ambiguous is more appropiate then left recursive as we can remove left recursion easily.
1
1
But in key answer is B
0
0
There is no official answer key before GATE 2011. Which key are you talking about?
17
17
7 votes
7 votes

Since given grammar can have more than 1  parse trees for string '(())', so grammar is ambiguous,

and also A → AA has left recursion.

For predictive-parsing, i.e. LL(1),    grammar should be:

  • Free from ambiguity
  • Free from left recursion
  • Free from left factoring(Non Determinism)

Given grammar contains both ambiguity and left recursion, so it can not have a predictive parser. .We can remove left recursion easily but ambiguity of CFL is not easy to remove.(as it is undecidable)

option A is more appropriate. 

edited by
by
4 votes
4 votes
for checking if the given grammar is LL(1) or not first you will check if it's left reccursive or not(because it is easy to check) if its left recursive it is surely not LL(1) but if it's not left recursive then only you need to check for ambiguity . if it turn out to be ambiguous we can say grammar is surely not LL(1).

so answer should be B.. that it is left recursive..no need to check for ambiguity

note : even if grammar is not ambiguous we can't be sure that it is LL(1).

for finding that you have to make the LL(1) parsing table and if no two production collide in a same shell of the table you can say there is no conflict hence LL(1)

1 comment

@Sneha negi

note : even if grammar is not ambiguous we can't be sure that it is LL(1).

but we can say the same for left recursion also , that if a grammar is not left recursive then also it may or may not be LL(1), as it may be either ambiguous(2 parse trees possible for some string) or not left factored.

so A is the correct one here. 

0
0
Answer:

Related questions