[antlr-interest] StringTemplate in tree grammar strategy

Christian Andersson dt05ca4 at student.lth.se
Wed Oct 10 01:03:45 PDT 2007


Hi all!

These questions is all about using StringTemplates in a tree grammar!

The background is that I have a 2 pass approach where I have a c dialect
grammar that builds the AST and a tree grammar that is suppose to gather
all the information there is about the structs in a file.

After reading the ANTLR reference, that when you choose output=template
you are forced to write template rewrite rules for every single rule in
the tree grammar? This is not an option since I only want the struct
syntax output. Please correct if wrong!

Then there are the other options output=template and rewrite=true.
Now this seems better now I only need to write template rewrite rules for
those rules that my struct syntax uses. However now I get all of my input
as output, though my struct syntax tokens can be changed using the
template rewriting the tokenbuffer. This is clearly not what I want
either, I still only want the structs type info as output.

So my question is, what is the best strategy to solve this using
stringtemplate?

Now I have a second question regarding only StringTemplates. A struct can
contain a infinite set of different types even new struct declarations
inside the given struct. What is a good strategy to write this template?
I was thinking maybee that the struct template could receive different
lists of the different types, however then the order of the types will be
changed based on its type and I dont want that. I really would like to
write the contents of the struct while walking the struct but then Im back
at the problems above.


I´m quite new to StringTemplate so all guidance and strategy solving these
problems will be appreciated!


BR Christian





More information about the antlr-interest mailing list