[antlr-interest] Calling templates in actions
Terence Parr
parrt at cs.usfca.edu
Sat Mar 15 18:31:34 PDT 2008
Insert templates into other templates using ST attributes and then
"set attribute".
output(headers,cruft) ::= <<
<headers>
<cruft>
>>
Then just create an output template and then set the headers template
to another template instance.
Ter
On Mar 15, 2008, at 9:26 AM, Carl Crowder wrote:
> Hello,
>
> I'm writing a grammar for a scripting language which gets
> translated into Java. Basically I want to add the Java gumph like
> imports, class definition at the top of the generated class.
>
> At the minute I'm thinking I can do it in the @init action on the
> first rule in the tree parser like this:
>
> script
> @init { %start(); }
> : constructor function_def* EOF;
>
> However that simply instantiates a template. Doing $st = $start();
> just sets retval.st to be that template. What I need is some way to
> chain templates together from within an action. Is that possible?
> Or is there another, better solution for this?
>
> Thanks!
> Carl
>
More information about the antlr-interest
mailing list