ANTLR的一些错误解决方案

antlr书写和编译的典型错误:

错误1:
2013-04-27 16:34:53,116 ERROR ql.Driver (SessionState.java:printError(401)) - FAILED: RewriteEmptyStreamException token valueList
org.antlr.runtime.tree.RewriteEmptyStreamException: token valueList
        at org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:158)
        at org.antlr.runtime.tree.RewriteRuleTokenStream.next(RewriteRuleTokenStream.java:57)
        at org.apache.hadoop.hive.ql.parse.HiveParser.partitionValuesExper(HiveParser.java:17876)
        at org.apache.hadoop.hive.ql.parse.HiveParser.partitionExper(HiveParser.java:17569)
        at org.apache.hadoop.hive.ql.parse.HiveParser.partitionTemplate(HiveParser.java:17306)
        at org.apache.hadoop.hive.ql.parse.HiveParser.tablePartition(HiveParser.java:16794)
        at org.apache.hadoop.hive.ql.parse.HiveParser.createTableStatement(HiveParser.java:3783)
        at org.apache.hadoop.hive.ql.parse.HiveParser.ddlStatement(HiveParser.java:1836)
        at org.apache.hadoop.hive.ql.parse.HiveParser.execStatement(HiveParser.java:959)
        at org.apache.hadoop.hive.ql.parse.HiveParser.statement(HiveParser.java:644)
        at org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:439)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:416)
        at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:335)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:893)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:259)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:216)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:412)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:755)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:613)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:156)


解决方法:
本问题产生原因是赋值定义不对,产生错误的代码定义:
partitionValuesExper
@init { msgs.push(" partitionValuesExper specification"); }
@after { msgs.pop(); }
    :KW_VALUES  KW_LESS KW_THEN LPAREN value=stringOrNumOrFunc RPAREN 
    -> ^(TOK_VALUES_LESS  $value )
    |KW_VALUES  KW_GREATER KW_THEN LPAREN value=stringOrNumOrFunc RPAREN 
     -> ^(TOK_VALUES_GREATER  $value )
    | KW_VALUES LPAREN valueList=(stringOrNumOrFuncList)
 RPAREN
     -> ^(TOK_VALUES   $valueList )


错误出现在
KW_VALUES LPAREN valueList=(stringOrNumOrFuncList) RPAREN
去掉括号,改为:
valueList=stringOrNumOrFuncList

错误2:
”reference to rewrite element tableSubPartition without reference on left of ->“
通常这个错误的伴随Decision can match input such as "..." using multiple alternatives错误出现

解决方法:
错误的原因是不服和LL文法定义,特别是歧义的片段定义副本有如identity等变量定义,让状态机产生歧义,解决方法是将相同的部分提取出来,分层定义即可。



猜你喜欢

转载自denniszjw.iteye.com/blog/1856149