[antlr-interest] Translating from one language to another

Andy Tripp antlr at jazillian.com
Tue Jul 22 08:38:15 PDT 2008


A "quick and dirty" alternative approach to StringTemplate is
to write some code that just walks your AST, printing out code.
This: http://www.jazillian.com/antlr/emitter.html
just walks a Java AST and prints Java code.

David Tauzell wrote:
> I'd like to translate from language A to java.  I've written a grammar 
> that parses language A and generates an AST.   The language is mostly 
> like java, except there are a few cases where I'll need to change the 
> input.  For example, something like:
> 
>     a.b.c.d = foo
> 
> will be converted to
> 
>     a.get("b").get("c").get("d").setValue(foo)
> 
> Other stuff like:
> 
>    if( foo == "bar") {
>       ...
>    }
> 
> can stay like it is.
> 
> I'm not sure what is the best way to proceed.  Should I somehow use 
> StringTemplate?  Should I walk the AST and generate output? Is this 
> question to vague? Do I just need to buy the ANTLR book and learn more 
> about ANTLR?
> 
> Thanks,
>     Dave
> 
> 



More information about the antlr-interest mailing list