[antlr-interest] [v3] Syntax error leads to a null pointer exception

John B. Brodie jbb at acm.org
Wed Aug 16 09:44:51 PDT 2006


Greetings!

Hope this isn't a duplicate -- this grammar:

grammar T;

options {
    output=AST;
}

@members {
int bar;
}

tokens {
    FOO;
}

program
    :    id+=IDENTIFIER ('.' id+=IDENTIFIER)* -> ^(PATH $id+)
    ;
        
IDENTIFIER
    :    ('a'..'z'|'A'..'Z')+
    ;

gets this from org.antlr.Tool:

ANTLR Parser Generator   Early Access Version 3.0b3 (July 21, 2006)  1989-2006
11:1: syntax error: antlr: t.g:11:1: unexpected token: tokens {
0:0: syntax error: assign.types: <AST>:0:0: unexpected end of subtree
0:0: syntax error: define: <AST>:0:0: unexpected end of subtree
internal error: t.g : java.lang.NullPointerException
org.antlr.tool.DefineGrammarItemsWalker.trimGrammar(DefineGrammarItemsWalker.java:88)
org.antlr.tool.DefineGrammarItemsWalker.finish(DefineGrammarItemsWalker.java:71)
org.antlr.tool.DefineGrammarItemsWalker.grammar(DefineGrammarItemsWalker.java:192)
org.antlr.tool.Grammar.setGrammarContent(Grammar.java:491)
org.antlr.tool.Grammar.<init>(Grammar.java:409)
org.antlr.Tool.process(Tool.java:246)
org.antlr.Tool.main(Tool.java:70)


So the tokens{} must appear before the @members{}, OK, Not sure why, but OK
(some things in life just are the way they are ;-)

But then why does reporting that syntax error deserve a nullpointer?

   -jbb


More information about the antlr-interest mailing list