[antlr-interest] ArrayIndexOutOfBoundsException in ANTLR 3.0

Gerard van de Glind g.vandeglind at beinformed.nl
Thu Aug 14 05:57:53 PDT 2008


Hi all,

I have a grammar that contains the following rule alternatives:

      |     (DATE_FUNC LPAREN formula COMMA formula COMMA)=>
            DATE_FUNC
                  LPAREN
                        f1=formula COMMA
                        f2=formula COMMA
                        f3=formula
                  RPAREN
            -> ^(DATE_FUNC $f1 $f2 $f3)
      |     DATE_FUNC
                  LPAREN
                        s1=stringAtom COMMA
                        s2=STRING_LITERAL
                  RPAREN
            -> ^(DATE_FUNC $s1 $s2)

The first alternative is a date function with 3 formula arguments.
The second has a stringAtom and STRING_LITERAL argument.

Note the syntactic predicate in the first alternative.
This predicate is needed because formula and stringAtom are recursive and have similar alternatives.
For example brackets can be obtained via both formula and stringAtom.

If I try to parse an invalid expression, e.g. 'DATE_FUNC()' then I get the following stacktrace:

                  java.lang.ArrayIndexOutOfBoundsException: -1
                  at org.antlr.runtime.DFA.predict(DFA.java:44)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.dateAtom(BIExpressionParser.java:5548)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.synpred5_fragment(BIExpressionParser.java:6978)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.synpred5(BIExpressionParser.java:7157)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.equalityExpression(BIExpressionParser.java:2048)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.conditionalNotExpression(BIExpressionParser.java:1307)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.conditionalAndExpression(BIExpressionParser.java:1177)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.conditionalOrExpression(BIExpressionParser.java:1083)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.condition(BIExpressionParser.java:1030)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.conditionEOF(BIExpressionParser.java:980)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.synpred2_fragment(BIExpressionParser.java:6921)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.synpred2(BIExpressionParser.java:7241)
                  at nl.beinformed.bi.common.expressions.parser.BIExpressionParser.expression(BIExpressionParser.java:771)
                  at nl.beinformed.bi.common.expressions.ExpressionParser.parseExpression(ExpressionParser.java:57)

I hoped to get a RecognitionException, but I get an ArrayIndexOutOfBoundsException.

Regards, Gerard

Btw: I use ANTLR 3.0.1 and generate Java code from my grammar.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080814/9a7b7ab3/attachment-0001.html 


More information about the antlr-interest mailing list