[antlr-interest] Urgent: how to "include" a grammar defined in a separate file

Ric Klaren ric.klaren at gmail.com
Wed Jun 15 00:46:09 PDT 2005


On 6/15/05, Rupinder S. Gill <rupigill0 at yahoo.com> wrote:
> (I posted a query a week ago but didn't receive a satisfactory response.) 
> I have a grammar for logical-expressions from which I need to build the
> following: 
> - Java lexer and parser 
> - C# lexer and parser 
> - Two java tree-walkers 
> - One C# tree-walkers 
> 
> The two java tree-walkers are in independent projects; both projects do
> depend on the project that defines the grammar (and contains lexer and
> parser).  C# lexer, parser and tree-walker can be in the same project.  I
> want to keep only one copy of the common.g file (one containing parser and
> lexer sections).  How do I this? 
> 
> Grammar inheritance nor importVocab seem to be up to the task.  Or am I
> missing something?

I have no idea what you exactly want from this description. Is your
problem that you want a language independent .g file and then mix in
C# or java code? In that case look in the archive for the terms
'literate programming'  you should be able to turn up some posts by
Monty on how he set stuff like that up in the past.

Or is it more that you have trouble structuring the importVocab
exportVocab directives across all .g files?

Anycase antlr has no #include like directives. Grammar inheritance is
something I personally stay clear from (although some people seem to
like it). You could use the C preprocessor, m4, TCL/perl or other
scripting to achieve include file style setups.

Cheers,

Ric


More information about the antlr-interest mailing list