Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i prove that this grammar is ambiguous?

Tags:

grammar

S -> bA|aB
A -> a|aS|bAA
B -> b|bS|aBB

Any easy method other than trying to find a string that would generate two parse trees ?

Can someone please give me a string that can prove this.

like image 957
crowso Avatar asked Feb 02 '11 18:02

crowso


People also ask

What is ambiguous grammar explain with example?

More Detail. A Grammar that makes more than one Leftmost Derivation (or Rightmost Derivation) for the similar sentence is called Ambiguous Grammar. Example − Verify whether the following Grammar is Ambiguous or Not. E → E+E|E ∗ E|id.

Why the grammar is ambiguous?

A grammar is ambiguous if there exists a sequence of token that can be derived by two different leftmost derivations. An obvious question is whether there is a better, unambiguous, grammar for simple expressions.

Which grammar is are ambiguous?

In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree, while an unambiguous grammar is a context-free grammar for which every valid string has a unique leftmost derivation or parse tree.

Which of the following grammar S is are ambiguous i's → AA → BB → є II S → AA → bb a є B → A є III S → AA BA →?

Detailed Solution The correct answer is option 4. A is ambiguous because λ can be generated using leftmost derivation having two different parse trees with an empty string. B is ambiguous grammar with string abab. C is an ambiguous grammar with string abbbb.


2 Answers

There is a string though: bbaaba

S -> bA -> bbAA -> bbaA -> bbaaS -> bbaabA -> bbaaba
S -> bA -> bbAA -> bbaSA -> bbaaBA -> bbaabA -> bbaaba
like image 196
Shweta Avatar answered Sep 20 '22 22:09

Shweta


There is no easy method for proving a context-free grammar ambiguous -- in fact, the question is undecidable, by reduction to the Post correspondence problem.

like image 31
Jim Lewis Avatar answered Sep 19 '22 22:09

Jim Lewis