[antlr-interest] ANTLR 3 and StringTemplate

Kay Roepke kroepke at dolphin-services.de
Mon Jul 24 11:01:31 PDT 2006


On 22. Jul 2006, at 21:40 Uhr, Scott Amort wrote:

>  Should I instead just implement an
> alternative in C++ (although this seems like reworking the wheel
> considering how useful StringTemplate appears to be)?  Finally, will
> ANTLR 3 with its use of StringTemplate offer any solutions?

You could do a C++ port of StringTemplate, instead of doing yet- 
another-template-thingy ;)
v3 has support to directly use templates and assign values to  
template variables from within your grammar.
This works similarly to AST support. Obviously this feature is only  
available to targets that have
a native ST implementation available.
The other (main) use of ST in v3 is code generation, but that's in  
Java, so that doesn't help you with your
problem. :(

For the far future, I plan to do an Objective-C port of ST for ANTLR  
as well as for standalone use.
I don't know if anyone else plans to do a port to another C-based  
language, but it'd be nice to have.

If you don't mind the performance hit, you could try to interface  
with a language such as Java or Python.
Especially Python should be easy (*I think* there is a C++ bridge for  
Python). That wouldn't give you the template output
of v3, but you'd be able to use ST via your own code (or in actions).

If all fails you could use JNI to bridge over to Java. That's yucky  
and cumbersome but should work. But if you are ready
to make that investment it would really be more feasible to do a C++  
port. Most of the stuff should be easy to port especially
given that ST uses ANTLR 2 for its grammars (for which you already  
have a C++ version :))

HTH,

-k



More information about the antlr-interest mailing list