[antlr-interest] best method of outputting multiple templates from AST?

Robert Hill rob.hill at blueyonder.co.uk
Mon Oct 16 15:47:29 PDT 2006


	
If have a fair few rules which must output bits of code in more than one
place in the final output file, whats the best way to do this?
Eg, say im generating a kind of loop and I need to add a variable to the
start of a function method but need to generate the code further down in the
body.
I guess what I'd like would be something like the following.

Rule
:	^(blah1 blah2)
-> template1(id={blah}) , template2(pos={blah2)

Also I'd like to accumulate a bunch of these templates In a single block
somewhere to keep them together, nomatter where I come across them in my
language, do I just declare a single template in java code as a parser
member and fill it in from all the rules?

I just struggling a bit with the whole chaining up the templates to make one
big output string at the root rule..

Any pointers would be much appreciated.

Cheers!

Rob







More information about the antlr-interest mailing list