Converting ambiguous grammar to unambiguous

后端 未结 2 1382
清歌不尽
清歌不尽 2020-12-25 12:48

I did not understand how a unambiguous grammar is derived from a ambiguous grammar? Consider the example on site: Example. How was the grammar derived is confusing to me. <

2条回答
  •  甜味超标
    2020-12-25 13:16

    From Wikipedia (on Recognizing ambiguous grammars):

    Some ambiguous grammars can be converted into unambiguous grammars, but no general procedure for doing this is possible just as no algorithm exists for detecting ambiguous grammars.

    In order to come up with the second grammar, you have to find a grammar that is

    1. Equivalent to the first one: Both generate the same language
    2. Unambiguous: For every sentence of the language, the parse tree is unique

提交回复
热议问题