Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top