Example for LL(1) Grammar which is NOT LALR?

后端 未结 2 1010
灰色年华
灰色年华 2020-12-29 14:44

I am learning now about parsers on my Theory Of Compilation course. I need to find an example for grammar which is in LL(1) but not in LALR. I know it should be exist. ple

2条回答
  •  粉色の甜心
    2020-12-29 15:03

    From the Dragon book (Second Edition, p. 242):

    The class of grammars that can be parsed using LR methods is a proper superset of the class of grammars that can be parsed with predictive or LL methods. For a grammar to be LR(k), we must be able to recognize the occurrence of the right side of a production in a right-sentential form, with k input symbols of lookahead. This requirement is far less stringent than that for LL(k) grammars where we must be able to recognize the use of a production seeing only the first k symbols of what the right side derives. Thus, it should not be surprising that LR grammars can describe more languages than LL grammars.

提交回复
热议问题