ANTLR - OutOfMemoryError表达式语法

时间:2015-12-22 08:14:27

标签: out-of-memory antlr

我使用ANTLRT来解析表达式。当我添加以下规则时,ANTLR会耗尽内存(请参阅末尾的日志片段。)

comp_expr returns [ AbstractLogicalExpression expr ]:
                expr1=or_type_expr LOG_LT expr2=or_type_expr { $expr = BinaryLogExpr.create( BinaryLogExpr.OP_TYPE.LT,
                                                                                       $expr1.expr, $expr2.expr ); } |
                expr1=or_type_expr LOG_GT expr2=or_type_expr { $expr = BinaryLogExpr.create( BinaryLogExpr.OP_TYPE.GT,
                                                                                       $expr1.expr, $expr2.expr ); } |
                or_type_expr { $expr = $or_type_expr.expr; };

相同语法中的类似规则(例如or_type_expr)工作得很好。 LOG_LT和LOG_GT目前定义如下:

LOG_GT:         '>>';
LOG_LT:         '<<';

然而,我尝试了其他字符序列(例如&#39; .LT。&#39;和#39; .GT&#39;因此)但效果是一样的。

让它恢复工作的唯一方法是注释掉包含LOG_LT和LOG_GT的整个替代项。

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at org.antlr.v4.runtime.atn.ArrayPredictionContext.<init>(ArrayPredictionContext.java:48)
    at org.antlr.v4.runtime.atn.PredictionContext.merge(PredictionContext.java:195)
    at org.antlr.v4.runtime.atn.PredictionContext.mergeArrays(PredictionContext.java:418)
    at org.antlr.v4.runtime.atn.PredictionContext.merge(PredictionContext.java:197)
    at org.antlr.v4.runtime.atn.PredictionContext.mergeArrays(PredictionContext.java:418)
    at org.antlr.v4.runtime.atn.PredictionContext.merge(PredictionContext.java:197)
    at org.antlr.v4.runtime.atn.ATNConfigSet.add(ATNConfigSet.java:178)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1551)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1535)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1603)

ANTLR版本是4.5.1,Java运行时。

有人遇到这个问题并在解决之前解决了吗?

0 个答案:

没有答案