[antlr-interest] Can I target C and Java from one grammar file?

Andy Grove andy.grove at codefutures.com
Thu Jan 22 09:40:44 PST 2009


Hi,

I need to generate C and Java from an ANTLR grammar containing  
actions. Is there a preprocessor approach I can use rather than  
maintaining two versions of the grammar?

I'm thinking that the grammar would look something like this:

selectStatement[int initRule]
//IFDEF JAVA
@init 	{if(initRule) sse.pushCall(sse.SELECTSTAT);}
//ELIFDEF CPP
@init 	{if(initRule) sse->pushCall(sse.SELECTSTAT);}
//END
	:
	q = queryExpression[true]
	;

Are there tools out there already or do I need to roll my own?

Thanks,

Andy Grove
Chief Architect
CodeFutures Corporation










More information about the antlr-interest mailing list