[antlr-interest] Generating initializers and headers

Nikolas Everett nik9000 at gmail.com
Wed Jan 30 13:56:18 PST 2008


So far I think I have two options:

1.  Create a custom StringTemplateGroup which provides string templates that
proxy calls to all the StringTemplates that I'm going to need.  I could pull
out all the stringtemplates that I need and build the files with them.
That'd be simple enough.
2.  Create seperate template grammars that build everything I need.

I'll poke around with these two options and let the group know what I did.

Thanks for the help.

On Jan 29, 2008 2:06 PM, Arnulf Heller <aheller at gmx.at> wrote:

> At 14:02 29.01.2008, you wrote:
> >I've been puzzling over this for a few days, and haven't thought of
> >anything useful, so I figured I'd ask the group.
> >
> >I'm looking to generate C code from antlr/stringtemplate.  I'd like
> >to generate methods in a .c file, method signatures in a .h file,
> >and probably some sort of initialization method in the .c file.  My
> >problem is that any part of the AST could generate code in any of
> >those 3 places.  What is the normal way to handle this?
>
> hi,
>
> look at the ANTLR3 sources (src\org\antlr\codegen\CodeGenerator.java,
> src\org\antlr\codegen\templates\cpp\CPP.stg)
>
> I think this is what you are looking for.
>
> They keep two string templates in a group (that share type
> definitions etc.) and throw the parsing output onto them:
>
>                 headerFileST.setAttribute("actions", actions);
>                 outputFileST.setAttribute("actions", actions);
>                 headerFileST.setAttribute("buildTemplate", new
> Boolean(grammar.buildTemplate()));
>                 outputFileST.setAttribute("buildTemplate", new
> Boolean(grammar.buildTemplate()));
>                 headerFileST.setAttribute("buildAST", new
> Boolean(grammar.buildAST()));
>                 outputFileST.setAttribute("buildAST", new
> Boolean(grammar.buildAST()));
>                 outputFileST.setAttribute("rewriteMode",
> Boolean.valueOf(grammar.rewriteMode()));
>                 headerFileST.setAttribute("rewriteMode",
> Boolean.valueOf(grammar.rewriteMode()));
>                 outputFileST.setAttribute("backtracking",
> Boolean.valueOf(canBacktrack));
>                 headerFileST.setAttribute("backtracking",
> Boolean.valueOf(canBacktrack));
>
> cheers,
> arnulf
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080130/9e028e5e/attachment.html 


More information about the antlr-interest mailing list