[antlr-interest] Composite Grammar [C Target]

Jim Idle jimi at temporal-wave.com
Tue Sep 25 16:50:56 PDT 2012


To use common tokens, take the .tokens file generated by one of the
grammars, merge it with the other .token files, then use tokenVocab
option. You need to keep the token numbers contiguous and unique.

JIm

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Justin Murray
Sent: Wednesday, September 26, 2012 3:50 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Composite Grammar [C Target]

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

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list