ANTLR4相互左递归 [英] ANTLR4 Mutual left recursion

查看:153
本文介绍了ANTLR4相互左递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚遇到ANTLR 4.2.2的一个奇怪问题:

I just ran into a strange problem with ANTLR 4.2.2:

考虑一个(简化的)Java语法.无法编译:

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

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

ANTLR输出以下错误:

ANTLR outputs the following error:

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

是的,我还看到了左递归.但是我看不到 mutual 左递归,只有一个通常的递归.

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

当我删除(classOrInterfaceType)周围的括号时,它可以正常编译.当然,括号是多余的,但是语法是自动生成的,并且在某些情况下,代码生成器总是插入括号.那么这是什么问题呢?

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?

推荐答案

已确认这是一个错误.该修复程序计划用于下一个里程碑4.x. 参见 https://github.com/antlr/antlr4/issues/564

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

这篇关于ANTLR4相互左递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆