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

查看:25
本文介绍了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]

是的,我也看到了左递归.但我没有看到相互左递归,只有一个普通的.

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天全站免登陆