ANTLR4 Mutual left recursion

痞子三分冷 提交于 2019-12-11 01:08:49

问题


I just ran into a strange problem with ANTLR 4.2.2:

Consider a (simplified) java grammar. This does not compile:

 classOrInterfaceType
    :  (classOrInterfaceType) '.' Identifier
    |  Identifier 
    ;

ANTLR outputs the following error:

error(119): Java.g4::: The following sets of rules are mutually left-recursive [classOrInterfaceType]

Yes, I also see a left recursion. But I do not see a mutual left recursion, only a usual one.

When I remove the parenthesis around (classOrInterfaceType), then it compiles fine. Of course, the parenthesis are superfluous, but the grammar is generated automatically and the code generator always inserts parenthesis in some situations. So what is the problem here?


回答1:


It has been confirmed that this is a bug. The fix is scheduled for the next milestone 4.x. See https://github.com/antlr/antlr4/issues/564



来源:https://stackoverflow.com/questions/23626376/antlr4-mutual-left-recursion

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