[antlr-interest] tokenVocab and certain rules cause NullPointerException in org.antlr.Tool

Erik Kratochvil discontinuum at gmail.com
Fri Feb 1 09:51:39 PST 2008


Good evening (at least to all in my timezone ;).

I have encountered an extremely odd behaviour while experimenting with
the following grammar:

grammar Expr;
options { tokenVocab = Basic; }
r: (~S)+;
S:';';
W:' ';

The Basic.tokens file contains one line only (well, two lines as a
matter of fact because antlr expects a newline after each token
definition)

Gosub=10

The problem is that the Lexer/Parser cannot be generated,
org.antlr.Tool fails with

ANTLR Parser Generator  Version 3.0.1 (August 13, 2007)  1989-2007
error(10):  internal error: Expr.g : java.lang.NullPointerException
org.antlr.codegen.Target.getTokenTypeAsTargetLabel(Target.java:146)
org.antlr.codegen.CodeGenerator.getTokenTypeAsTargetLabel(CodeGenerator.java:825)
...
org.antlr.Tool.main(Tool.java:70)

The funny thing is that if I slightly change the rule *r*, the
Lexer/Parser is generated without any complaint.

grammar Expr;
options { tokenVocab = Basic; }
r: (S)+; // S instead of ~S
S:';';
W:' ';

The truly funny thing is that when I remove the tokenVocab clause from
the original grammar, the Lexer/Parser is -again- generated without
any complaint.

grammar Expr;
// no tokenVocab here
r: (~S)+;
S:';';
W:' ';

Does anyone know what may be wrong?


-- 
Erik Kratochvil


More information about the antlr-interest mailing list