ANTLR4 相互左递归

标签 antlr grammar antlr4 left-recursion

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

考虑(简化的)java 语法。这不会编译:

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

ANTLR 输出以下错误:

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

是的,我还看到了左递归。但我没有看到相互左递归,只有一种常见的左递归。

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

最佳答案

已确认这是一个错误。该修复计划在下一个里程碑 4.x 中进行。 请参阅https://github.com/antlr/antlr4/issues/564

关于ANTLR4 相互左递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23626376/

相关文章:

c - ANTLR4 C 语法不支持 __cdecl?

java - Antlr 输入字符串时出错

c - 在 C 目标中用 antlr3 解析一些特定的语句

c# - ANTLR4 与 Unity3D

exception - antlr4 在 .g4 语法文件上工作正常,但 gradle generateGrammarSources 在同一个文件上失败,TokenStreamException : unexpected char: '-'/"

java - ANTLR 4.5 : line 1:22 mismatched input 'randomly' expecting DIRECTION

javascript - ANTLR PCRE 文法转 JS 目标

c++ - 提升精神: parse boolean expression and reduce to canonical normal form

json - JSON 数组 LL(1) 是否可解析?

python - yacc 无法归约 (Python Lex-Yacc)