[antlr-interest] Multiple outputs ANTLR + ST

Damien Urruty lepilache at hotmail.com
Fri Feb 12 13:27:51 PST 2010


Hi Fridi, thanks for your answer,
With your solution, I don't see how i can differentiate the output : I want to save the function prototypes in a.h file, and the function bodies in a .m file. To do this, I parse my input, and I have a rule method for example : 
method : type name arguments body           ;
I have to call 2 different template functions, one that returns only the prototype, and the second one that returns the entire method. For example : 
methodHeaderFile(type, name, arguments, body) ::=<< <type> <name> <arguments; separator=" : "> >>methodMFile(type, name, arguments, body) ::=<< <type> <name> <arguments; separator=" : ">{   <body>}>>
And I don't see how to do it with your solution, because the same template is called (foo1Tmpl()), and will return always the same code. Anyway thanks for your answer !
Bye, Dam.

> Date: Thu, 11 Feb 2010 20:45:14 +0100
> From: fridi70 at gmx.de
> To: lepilache at hotmail.com
> Subject: Re: [antlr-interest] Multiple outputs ANTLR + ST
> 
> Hi Dam,
> 
> one approach that I have used was to redirect the templates output by
> my own java  code that I added to the ruls as actions.
> So if a rule returns a template, i.e. add that template to a list of
> your choice.
> 
> @members {
>     ArrayList<StringTemplate> myTmpls = new ArrayList<StringTemplate>();
> }
> ...
> 
> 
> rule1
>     : f1=foo1 foo2 { myTmpls.add(f1.st); }
>     ;
> 
> foo1
>     : i=IDENT -> foo1Tmpl({value=$i.text})
>     ;
> 
> foo2
>     : ...
> 
> So I think you do not have to return the templates up to the
> entryRule,  you can do whatever you  want with them.
> 
> Hope that helps,
>   fridi
> 
> 
> Damien Urruty schrieb:
> >
> >
> >
> > Hi there,
> >
> > First of all, thanks a lot for this brilliant tool ! I have a problem, and I don't know how to solve it.
> >
> > I want to generate multiple output files, for example a .h and a .m for Objective-C. The point is that I can bind only one template to my parser, with :
> >
> > parser.setTemplateLib(tmpl);
> >
> > when I call parser.entryRule(), then the toString(), I can get only the generated code for this template tmpl.
> >
> > Is it possible to bind multiple templates, and parse once my input, or do I have to parse it 2 times, assigning a different template each time ?
> >
> > Hope I'm clear.
> >
> > Thanks in advance !
> >
> > Dam.
> >  		 	   		  
> > _________________________________________________________________
> > Discutez en direct avec vos amis sur Messenger !
> > http://www.windowslive.fr/messenger
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> >
> >   
> 
> 
 		 	   		  
_________________________________________________________________
Découvrez Windows 7 en 7 secondes !
http://clk.atdmt.com/FRM/go/181574577/direct/01/


More information about the antlr-interest mailing list