[antlr-interest] Generating initializers and headers

Nikolas Everett nik9000 at gmail.com
Tue Jan 29 05:02:15 PST 2008


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?

I have been using an OutputStream that can recognize escape sequences to
change which file its writing to.  This lets me write 1 template per
construction of the form
methodDef(name, stuff...) ::= <<
stream <name>.c:
  blah blah blah
stream <name>.h:
  extern blah blah blah
stream <name>Initializer.c:
  metadata goes here

This gets the job done, but doesn't feel all that elegant so its probably
not the right way to do it.

--Nik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080129/1bbc9232/attachment.html 


More information about the antlr-interest mailing list