numerous template errors generating OracleSQL grammar using Antlr-3.5-complete.jar

倾然丶 夕夏残阳落幕 提交于 2020-01-04 05:55:07

问题


The same oracle SQL grammar generates without errors using Antlr-3.3-complete.jar and compiles successfully using Netbeans/GCC or Visual Studio.

Generating the grammar with Antlr-3.5-complete.jar generates 23500 lines of warning messages describing template errors including several hundred exceptions.

The code is generated using the following command line:

java -d64 -Xmn2000M -Xmx8000M -jar antlr-3.5-complete.jar OracleSQL_v2.g 

antlr-3.5-complete.jar was downloaded from the antlr.org site on 3/22/2013.

The grammar is based on the Oracle PL/SQL grammar from the antlr.org site posted by Ivan.Brezina.

The generated code has 282 undeclared identifiers. Many $tokenRef variables are undeclared in the generated parser synpred subroutines. Also, the generated lexer has 100 cases of

error C2065: '_empty' : undeclared identifier

Here is a subset of the template errors:

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

回答1:


Due to a bug in releases before 3.5, these messages were unintentionally suppressed. Some of the targets have been updated to correct the problems, but it appears you are using a target that hasn't been updated yet (you didn't specify).

Also note that the messages about template errors are warning messages, not errors. Your output should still be generated.

Can you post a small example to reproduce the compiler errors?




回答2:


I've got the same errors. The grammar's taken from http://www.antlr3.org/grammar/list.html

All you need to reproduce the errors is to download, provide antlr-3.4-complete.jar (modify Makefile) instead of attached antlr-3.3-complete.jar and run Makefile.

A lot of warning-errors during processing grammar. Output source file produced, however can't be compiled, because ANTLR 3.4 and 3.5 generates lines like:

void ;
#undef RETURN_TYPE
#define RETURN_TYPE void

Typing

grep undef.*RETURN_TYPE OracleSQLParser.c | nl
shows that first 1135 cases were filled properly using template C.stg. From 1136 until end of generated source all occurrences are filled by void.

When I switch output from C target to java, no errors seen.




回答3:


I encountered same problem about “undeclared _empty”. Simplest example I found is:

foo: ( 'A'+ 'B' )+ 'A'+ ;

(This error case seems relating "Cyclic DFA" pattern. But I don't understand what it really means.)

ANTLR 3.5.1 generates parser source like:

static const ANTLR3_INT32 * const dfa2_transitions[] =
{
    dfa2_T1, dfa2_T0, _empty, _empty
};

And this cause compile error against for undeclared "_empty".

Before that part, I found:

/** Used when there is no transition table entry for a particular state */
#define dfa2_T_empty        NULL

I guess "_empty" should be "dfa2_T_empty" in generated code.

I currently put quick workaround in my grammar file. But I'm not sure this works fine at runtime.

@header {
   #define _empty NULL
}


来源:https://stackoverflow.com/questions/15578292/numerous-template-errors-generating-oraclesql-grammar-using-antlr-3-5-complete-j

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