2013-03-22 38 views
2

使用Antlr-3.3-complete.jar生成的相同的Oracle SQL語法沒有錯誤,並且使用Netbeans/GCC或Visual Studio成功編譯。使用Antlr-3.5-complete.jar生成OracleSQL語法的大量模板錯誤

使用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子例程中未聲明。此外,所產生的詞法分析器具有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 

回答

2

由於3.5之前的版本中的一個bug,這些消息被無意中抑制。一些目標已更新以糾正問題,但似乎您正在使用尚未更新的目標(您未指定)。

另請注意,有關模板錯誤的消息是警告消息,而不是錯誤。您的輸出仍應該生成。

你可以發佈一個小例子來重現編譯器錯誤嗎?

+0

生成C/Cpp解析器時發生同樣的錯誤。這只是警告,似乎並不妨礙實際的解析。 – 2013-05-17 02:10:55

0

我有同樣的錯誤。語法取自http://www.antlr3.org/grammar/list.html

所有你需要重現的錯誤是下載,提供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 undef.*RETURN_TYPE OracleSQLParser.c | nl
表明第一1135箱子使用模板C.stg適當填充。從1136年直到源生成結束,所有事件都由虛空填充。

當我將輸出從C target切換到java時,沒有發現錯誤。

0

我遇到了關於「未聲明_empty」的相同問題。我發現 簡單的例子是:

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」 中生成的代碼。

我目前在我的語法文件中使用了快速解決方法。但我不確定這在運行時正常工作。