[antlr-interest] Re: AST writer

atripp54321 atripp at comcast.net
Sun Jul 18 19:03:14 PDT 2004


--- In antlr-interest at yahoogroups.com, "thrutchy" <eric_mahurin at y...>
wrote:
> Is there a way to write out an AST in the same format as it was
parsed
> into the AST without having to write a tree-parser rule for each
rule
> of the parser?  To do this, I would assume you couldn't put in any
> "!"/"^" in the rules and the text can't be munged or ignored (i.e.
> whitespace/comments).
> 
> I would like to write a language munger that does this:
> 
> 1. Read language input into an AST
> 
> 2. Do manipulations to the AST (via a tree-walker or manually)
> 
> 3. Write the AST out in the same input language
> 
> I would prefer not to have to specify the language twice - once in
the
> parser and once in the writer.

It seems to me that if you avoid "!" and all the other fancy
ANTLR constructs in your grammar (other than "^", which you do
need, as Monty points out), then your language output really
could be just an in-order traversal of the AST.

One thing you might want to try is to compare the java.g that
compes with ANTLR with the print() method in
this code that prints out a Java AST:
http://jazillian.com/antlr/JavaEmitter.java
The java.g strips out all the "syntax stuff", and this code
puts it all back in.

Andy



 
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