[antlr-interest] Composite grammars, multiple lexer imports

Benjamin S Wolf jokeserver at gmail.com
Tue Jan 31 08:58:01 PST 2012


I had this same issue some time ago, and I resolved it by having my
combined grammar import only one lexer, which imports the other. Try
importing lx2 from lx1 or vice versa, and have par import the top one.

On Tue, Jan 31, 2012 at 7:40 AM, Jonathan Roberts
<plasticfridge at googlemail.com> wrote:
> 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.
>
> 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