[antlr-interest] Re: Example of source-to-source translation, searching archives

atripp54321 atripp at comcast.net
Sun Jul 18 18:35:12 PDT 2004


There are a few links on Monty's site that talk about this.
See this one for example:

http://codetransform.com/fun_with_antlr.html

The big design issue is whether to use ANTLR's treewalking
capability, or just write your own code to walk the AST.
If you just want to write your own, you could take a look
at my JavaEmitter code (look for JavaEmitter under "share list"
at antlr.org). That code simply walks through a Java AST,
printing it out as Java code. You could just make changes
to its print() method to output some slight variation of Java,
for example.

On my Jazillian C-to-Java translator, I initially had built
a C AST and tried to convert it to a Java AST. I tried several
techniques to do the AST transformation: ANTLR's treewalking stuff,
a couple of tree-manipulation languages (e.g. TXL), and hand-written
code. I found all of them too cumbersome and ended up 
writing my own mechanism that doesn't involve ASTs.
Unless the source and target languages are very similar, you're
in for a lot of work :)

Andy

--- In antlr-interest at yahoogroups.com, "johnj1984" <johnj1984 at y...>
wrote:
> Hello All,  
>   Is there any concrete example of a source-to-source antlr project 
> somewhere? I've read the excellent XL Lexer/Parser tutorial, 
> unfortunately that stops just when it gets interesting: How do I
use 
> AST trees to generate source code for another language? Most
examples 
> I've seen stop at using the AST to compute expressions.
> 
>   Also, how can I search the yahoo archives through more than 200 
> posts? Every search I do seems to only search posts 127** to 126**..
> 
>   Thanks in advance!



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list