[antlr-interest] Composite grammars, multiple lexer imports

Jonathan Roberts plasticfridge at googlemail.com
Tue Jan 31 07:40:28 PST 2012


Hello all,

Hope you can help.

I am trying to build a combined Antlr grammar that has multiple lexer
imports. However, I am struggling to achieve the end goal. Below is a
trivial example but generates the same errors I am suffering.

3 files: par.g(The combined parser/lexer), lx1.g (a lexer only grammar) and
lx2.g (a lexer only grammar)

par.g

grammar par;

import lx1, lx2;

a : INT  ID ;

lx1.g

lexer grammar lx1;

INT : '0'..'9'+ ;
WS : (' '|'\n')+ {skip();} ;

lx2.g

lexer grammar lx2;

ID : 'a'..'z'+ ;

Whenever I try to generate code from these grammars I get the following
error

error(103): lx2.g:6:1: parser rule a not allowed in lexer

Hope someone can help.

p.s. the reason for me doing this is that my current grammar generates code
that javac refuses to couple as it is too large! I was hopping that
splitting into multiple grammars would reduce file sizes so I may compile
my code.


More information about the antlr-interest mailing list