Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900