Can all ambiguous grammars be converted to unambiguous grammars?

后端 未结 1 625
南方客
南方客 2021-01-23 22:59

There are grammars we convert to unambiguous by using left recursion. Are there grammars that cannot be converted to unambiguous grammars?

相关标签:
1条回答
  • 2021-01-23 23:12

    There are unambiguous context-free grammars for most practical languages (ignoring context-sensitive features such as variable declarations, whitespace sensitivity, etc.).

    But there is no algorithm which can find an unambiguous grammar given an ambiguous grammar. Furthermore, there is not even an algorithm which can tell you for certain whether a given grammar is ambiguous. These are both undecidable problems.

    And, to answer your question, yes there are context-free languages for which there is no unambiguous grammar. Such languages are said to be inherently ambiguous.

    0 讨论(0)
提交回复
热议问题