Antlr3 使用Antlr-3.5-complete.jar生成OracleSQL语法时出现大量模板错误

Antlr3 使用Antlr-3.5-complete.jar生成OracleSQL语法时出现大量模板错误,antlr3,Antlr3,相同的oracle SQL语法使用Antlr-3.3-complete.jar生成而没有错误,并使用Netbeans/GCC或Visual Studio成功编译 使用Antlr-3.5-complete.jar生成语法会生成23500行警告消息,描述模板错误,包括数百个异常 使用以下命令行生成代码: java -d64 -Xmn2000M -Xmx8000M -jar antlr-3.5-complete.jar OracleSQL_v2.g antlr-3.5-complete.jar于2

相同的oracle SQL语法使用Antlr-3.3-complete.jar生成而没有错误,并使用Netbeans/GCC或Visual Studio成功编译

使用Antlr-3.5-complete.jar生成语法会生成23500行警告消息,描述模板错误,包括数百个异常

使用以下命令行生成代码:

java -d64 -Xmn2000M -Xmx8000M -jar antlr-3.5-complete.jar OracleSQL_v2.g 
antlr-3.5-complete.jar于2013年3月22日从antlr.org网站下载

该语法基于Ivan.Brezina发布的antlr.org网站上的Oracle PL/SQL语法

生成的代码有282个未声明的标识符。许多
$tokenRef
变量在生成的解析器synpred子例程中未声明。此外,生成的lexer有100个

error C2065: '_empty' : undeclared identifier
以下是模板错误的子集:

warning(24):  template error: context [/outputFile /parser] 1:1 could not pass through undefined attribute filterMode

600+ duplicate errors:
warning(24):  template error: context [/outputFile /parser /genericParser /_sub45 /ruleAttributeScopeFuncMacro] 1:4 no such property or can't access: null.attributes

warning(24):  template error: context [/outputFile /parser /genericParser] 155:5 no such property or can't access: null.apifuncs

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleInitializations /ruleInitializations] 4:1 no such property or can't access: null.attributes

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /element /matchSet /matchSet /_sub127 /createNodeFromToken] 1:4 no such property or can't access: null.node

20 duplicate errors:
warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleInitializations /ruleInitializations] 4:1 no such property or can't access: null.attributes

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /element /block /_sub86 /altSwitchCase /alt /element /blockSingleAlt /alt /rewriteCode /rewriteAlt /rewriteElementList /rewriteElement /rewriteTree /rewriteElement /rewriteImaginaryTokenRefRoot /createImaginaryNode] 1:4 no such property or can't access: null.node

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /element /block /_sub86 /altSwitchCase /alt /element /blockSingleAlt /alt /rewriteCode /rewriteAlt /rewriteElementList /rewriteElement /rewriteTree /rewriteElement /rewriteOptionalBlock /rewriteElementList /rewriteElement /rewriteTokenRef /createRewriteNodeFromElement] 1:4 no such property or can't access: null.node

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /element /block /_sub86 /altSwitchCase /alt /element /blockSingleAlt /alt /rewriteCode /rewriteAlt /rewriteElementList /rewriteElement /rewriteTree /rewriteElement /rewriteTree /rewriteElement /rewriteImaginaryTokenRefRoot /createImaginaryNode] 1:4 no such property or can't access: null.node

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /element /block /_sub86 /altSwitchCase /alt /element /blockSingleAlt /alt /rewriteCode /rewriteAlt /rewriteElementList /rewriteElement /rewriteTree /rewriteElement /rewriteTree /rewriteElement /rewriteTokenRef /createRewriteNodeFromElement] 1:4 no such property or can't access: null.node

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /element /block /_sub86 /altSwitchCase /alt /rewriteCode /rewriteAlt /rewriteElementList /rewriteElement /rewriteTree /rewriteElement /rewriteImaginaryTokenRefRoot /createImaginaryNode] 1:4 no such property or can't access: null.node

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleInitializations /ruleInitializations] 4:1 no such property or can't access: null.attributes

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleBlockSingleAlt /alt /rewriteCode /rewriteAlt /rewriteElementList /rewriteElement /rewriteTree /rewriteElement /rewriteImaginaryTokenRefRoot /createImaginaryNode] 1:4 no such property or can't access: null.node

warning(24):  template error: context [/outputFile /parser /genericParser /rule /ruleInitializations /ruleInitializations] 4:1 no such property or can't access: null.attributes



200+ duplicate exceptions:

Caused by: org.stringtemplate.v4.misc.STNoSuchPropertyException: no such property: java.lang.String.referencedRule
    at org.stringtemplate.v4.misc.ObjectModelAdaptor.throwNoSuchProperty(ObjectModelAdaptor.java:106)
    at org.stringtemplate.v4.misc.ObjectModelAdaptor.lookupMethod(ObjectModelAdaptor.java:99)
    at org.stringtemplate.v4.misc.ObjectModelAdaptor.getProperty(ObjectModelAdaptor.java:67)
    at org.stringtemplate.v4.Interpreter.getObjectProperty(Interpreter.java:1158)
    at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:210)
    at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:703)
    at org.stringtemplate.v4.Interpreter.writeIterator(Interpreter.java:733)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:708)
    at org.stringtemplate.v4.Interpreter.writeObjectWithOptions(Interpreter.java:665)
    at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:292)
    at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:703)
    at org.stringtemplate.v4.Interpreter.writeObjectNoOptions(Interpreter.java:635)
    at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:285)
    at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:703)
    at org.stringtemplate.v4.Interpreter.writeIterator(Interpreter.java:733)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:708)
    at org.stringtemplate.v4.Interpreter.writeObjectWithOptions(Interpreter.java:665)
    at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:292)
    at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:703)
    at org.stringtemplate.v4.Interpreter.writeObjectNoOptions(Interpreter.java:635)
    at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:285)
    at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145)
    at org.stringtemplate.v4.Interpreter.writeObject(Interpreter.java:703)
    at org.stringtemplate.v4.Interpreter.writeObjectNoOptions(Interpreter.java:635)
    at org.stringtemplate.v4.Interpreter._exec(Interpreter.java:285)
    at org.stringtemplate.v4.Interpreter.exec(Interpreter.java:145)
    at org.stringtemplate.v4.ST.write(ST.java:415)
    at org.antlr.codegen.CodeGenerator.write(CodeGenerator.java:1296)
    at org.antlr.codegen.CTarget.genRecognizerFile(CTarget.java:54)
    at org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:459)
    at org.antlr.Tool.generateRecognizer(Tool.java:696)
    at org.antlr.Tool.process(Tool.java:509)
    at org.antlr.Tool.main(Tool.java:98)
Caused by: java.lang.NoSuchFieldException: referencedRule
    at java.lang.Class.getField(Class.java:1537)
    at org.stringtemplate.v4.misc.ObjectModelAdaptor.lookupMethod(ObjectModelAdaptor.java:88)
    ... 35 more

1800+ duplicate errors for [headerReturnScope, ruleAttributeScopeDecl, and ruleDeclarations]:
warning(24):  template error: context [/headerFile /_sub143 /ruleAttributeScopeDecl] 1:4 no such property or can't access: null.attributes

由于3.5之前版本中的错误,这些消息被无意中抑制。某些目标已更新以更正问题,但您使用的目标似乎尚未更新(您未指定)

还要注意,关于模板错误的消息是警告消息,而不是错误。您的输出仍应生成


你能发布一个小例子来重现编译器错误吗?

我也有同样的错误。语法取自

复制错误所需的只是下载、提供antlr-3.4-complete.jar(修改Makefile)而不是附带的antlr-3.3-complete.jar并运行Makefile

在处理语法过程中出现许多警告错误。但无法编译生成的输出源文件,因为ANTLR 3.4和3.5生成如下行:

void ;
#undef RETURN_TYPE
#define RETURN_TYPE void
打字 grep unde.*RETURN_TYPE OracleSQLParser.c | nl显示,前1135个案例是使用模板c.stg正确填充的。从1136年到生成的源结束,所有引用都由void填充


当我将输出从C目标切换到java时,没有看到任何错误。

我遇到了关于“未声明的空”的相同问题。 我发现的最简单的例子是:

foo: ( 'A'+ 'B' )+ 'A'+ ;
(这个错误案例似乎与“循环DFA”模式有关,但我不明白它的真正含义。)

ANTLR 3.5.1生成的解析器源代码如下:

static const ANTLR3_INT32 * const dfa2_transitions[] =
{
    dfa2_T1, dfa2_T0, _empty, _empty
};
这会导致针对未声明的“_empty”的编译错误

在那部分之前,我发现:

/** Used when there is no transition table entry for a particular state */
#define dfa2_T_empty        NULL
我猜在生成的代码中“_empty”应该是“dfa2_T_empty”

我目前在语法文件中加入了快速解决方法。但我不确定这在运行时是否正常

@header {
   #define _empty NULL
}

生成C/Cpp解析器时也会出现相同的错误。所有这些都只是警告,似乎并没有妨碍实际的解析。
@header {
   #define _empty NULL
}