[antlr-interest] Two More Bugs in ANTLRv4

Jan Finis finis at in.tum.de
Thu Feb 23 00:46:26 PST 2012


Hi,

I encountered two more bugs in ANTLRv4, tested with the parrt/antlr4 
fork pulled yesterday from github:

First Bug:

The following rule does not work:
expr
   : 'x'
   | e1=expr '?'
   | e1=expr e2=expr
   ;

Error: The following sets of rules are mutually left-recursive [expr]

It seems to be the concatenation operation of two expressions (last 
alternative). If I leave it out, it works fine.

I am sure that I did not have this bug with my old 4.0ea ANTLR build. So 
it must be introduced lately.

Second Bug:

If you take the rule from above and leave out the second alternative 
like that:

expr
   : 'x'
   | e1=expr e2=expr
   ;

then the following exception is thrown:

         [java] can't find rule grammarSpec or tree structure error: 
(COMBINED_GRAMMAR ANTLRv4 (RULES (RULE expr (BLOCK (ALT 'x') (ALT (= e1 
expr[1]) (= e2 expr[1]))))))
         [java] java.lang.reflect.InvocationTargetException
         [java]     at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         [java]     at 
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         [java]     at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         [java]     at java.lang.reflect.Method.invoke(Unknown Source)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.visit(GrammarTreeVisitor.java:192)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.visitGrammar(GrammarTreeVisitor.java:186)
         [java]     at 
org.antlr.v4.semantics.SymbolCollector.process(SymbolCollector.java:69)
         [java]     at 
org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:95)
         [java]     at 
org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:301)
         [java]     at org.antlr.v4.Tool.process(Tool.java:290)
         [java]     at 
org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:254)
         [java]     at org.antlr.v4.Tool.main(Tool.java:144)
         [java] Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
         [java]     at 
org.antlr.v4.semantics.SymbolCollector.discoverOuterAlt(SymbolCollector.java:112)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.outerAlternative(GrammarTreeVisitor.java:2197)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.ruleBlock(GrammarTreeVisitor.java:2105)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.rule(GrammarTreeVisitor.java:1576)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.rules(GrammarTreeVisitor.java:1096)
         [java]     at 
org.antlr.v4.parse.GrammarTreeVisitor.grammarSpec(GrammarTreeVisitor.java:307)
         [java]     ... 12 more
         [java] error(9):  internal error: Rule expr[1] undefined
         [java] error(9):  internal error: Rule expr[1] undefined
         [java] Exception in thread "main" java.lang.NullPointerException
         [java]     at 
org.antlr.v4.automata.ParserATNFactory.elemList(ParserATNFactory.java:386)
         [java]     at 
org.antlr.v4.automata.ParserATNFactory.alt(ParserATNFactory.java:375)
         [java]     at 
org.antlr.v4.parse.ATNBuilder.alternative(ATNBuilder.java:615)
         [java]     at 
org.antlr.v4.parse.ATNBuilder.ruleBlock(ATNBuilder.java:294)
         [java]     at 
org.antlr.v4.automata.ParserATNFactory._createATN(ParserATNFactory.java:127)
         [java]     at 
org.antlr.v4.automata.ParserATNFactory.createATN(ParserATNFactory.java:109)
         [java]     at 
org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:309)
         [java]     at org.antlr.v4.Tool.process(Tool.java:290)
         [java]     at 
org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:254)
         [java]     at org.antlr.v4.Tool.main(Tool.java:144)

Regards,
Jan


More information about the antlr-interest mailing list