[antlr-interest] Composite Grammar [C Target]
Justin Murray
jmurray at aerotech.com
Tue Sep 25 12:49:33 PDT 2012
Hello,
I'm trying to use composite grammars, and can't seem to get off of the
ground. Basically, I have two separate parsers. One preprocesses the
source, and the other compiles it. Naturally, they have a few tokens in
common, such as a newline, and I'd prefer to only define that token
once. This sounds to me like exactly what composite grammars were
designed to do. So I made a CommonTokens.g:
lexer grammar CommonTokens;
NEWLINE_ : ('\r'? '\n');
Then in my grammar, I added an import:
grammar AerobasicPreprocessor;
import CommonTokens;
options { language=C; }
line : SOMEOTHERTOKENS_ NEWLINE_;
...
When I run the ANTLR tool on this grammar, I get some less than helpful
errors:
error(100): AerobasicPreprocessor.g:4:1: syntax error: antlr:
org.antlr.runtime.EarlyExitException
error(150): grammar file AerobasicPreprocessor.g has no rules
error(100): AerobasicPreprocessor.g:0:1: syntax error: assign.types:
org.antlr.runtime.EarlyExitException
org\antlr\grammar\v3\DefineGrammarItemsWalker.g: node from line 326:1
required (...)+ loop did not match anything at input ';'
What am I doing wrong?
Thanks,
- Justin
More information about the antlr-interest
mailing list