LL(2) language that is not LL(1)

僤鯓⒐⒋嵵緔 提交于 2020-05-25 11:24:50

问题


In order to further my understanding of parsers and grammars, I'm searching for a (hopefully simple) example of a language that is LL(2) but not LL(1). That is, a language that can be generated by an LL(2) grammar but not by any LL(1) grammar.

Are there useful languages in that class ? I.e could we imagine a computer language that is LL(2) but not LL(1) ?


回答1:


Parsing Techniques by Grune and Jacobs presents an example. An older version of this book is available online at

http://dickgrune.com/Books/PTAPG_1st_Edition/BookBody.pdf

and the example is on page 181.




回答2:


The example mentioned in the book linked in Gunther's answer:

S -> a S A | epsilon
A -> a^k b S | c

is a grammar describing an LL(k+1) language that is not LL(k). In particular,

S -> a S A | epsilon
A -> a b S | c

is a grammar describing an LL(2) language that is not LL(1).



来源:https://stackoverflow.com/questions/10634197/ll2-language-that-is-not-ll1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!