0

Here is an ambiguous CFG:

S -> aSb|bA|Ba
A -> bA|B
B -> aB|A|ε

You can easily check the ambiguity of the grammar by parsing the string "ba".

Are there any algorithms to fix the ambiguity of a CFG like the one above?

Thanks for the help

  • No there is no general algorithm to proof that certain grammar is ambiguous and to proof that two grammars are equivalent and so there is no algorithm to resolve ambiguity in grammar - this is one of called "unsolvable problem". – Grijesh Chauhan Apr 16 '14 at 13:04

1 Answers1

2

Checking whether a grammar is ambiguous or not is an Undecidable problem, which means that there exists no algorithm which will correctly output Yes/No to this problem every time.

The undecidablity is shown by showing that it is equivalen to Post Correspondence Problem, which is also undecidable.

Pranav Raj
  • 781
  • 1
  • 8
  • 19
  • @ValentinLorentz No, this question is for CFG not (regular grammar) and we don't have any general algorithm to that can check wheather grammar is ambiguity or not. Pranav Raj's answer is perfectly correct. – Grijesh Chauhan Apr 21 '14 at 13:35