[antlr-interest] What is going on here?

Michael Richter ttmrichter at gmail.com
Sun Jan 10 02:00:59 PST 2010


Here's a snippet from a grammar I'm working on that's just failing in the
most bizarre ways.

grammar junk;

tokens {
    INTERFACE = 'INTERFACE';
    IDENT = 'IDENT';
    END = 'END';
}

interface
    :   INTERFACE IDENT import* declaration* END '.'
    ;

import : ;

When I run antlr on it I get the following output:

error(100): junk.g:10:9: syntax error: antlr: junk.g:10:9: unexpected token:
INTERFACE
error(100): junk.g:10:19: syntax error: antlr: junk.g:10:19: unexpected
token: IDENT
error(100): junk.g:10:50: syntax error: antlr: junk.g:10:50: unexpected
token: '.'
error(100): junk.g:13:1: syntax error: antlr: junk.g:13:1: unexpected token:
import
error(150):  grammar file junk.g has no rules
error(100): junk.g:0:0: syntax error: assign.types: <AST>:0:0: unexpected
end of subtree
error(100): junk.g:0:0: syntax error: define: <AST>:0:0: unexpected end of
subtree
error(10):  internal error: junk.g : java.lang.NullPointerException
org.antlr.grammar.v2.DefineGrammarItemsWalker.trimGrammar(DefineGrammarItemsWalker.java:94)
org.antlr.grammar.v2.DefineGrammarItemsWalker.finish(DefineGrammarItemsWalker.java:77)
org.antlr.grammar.v2.DefineGrammarItemsWalker.grammar(DefineGrammarItemsWalker.java:206)
org.antlr.tool.Grammar.defineGrammarSymbols(Grammar.java:702)
org.antlr.tool.CompositeGrammar.defineGrammarSymbols(CompositeGrammar.java:351)
org.antlr.Tool.process(Tool.java:451)
org.antlr.Tool.main(Tool.java:91)

I have tried renaming the INTERFACE token, the IDENT token, the interface
production, etc. in various combinations and none of it works.  What
incredibly obvious thing am I overlooking?


More information about the antlr-interest mailing list