[antlr-interest] Re: Translators Should Use Tree Grammars

atripp54321 atripp at comcast.net
Mon Nov 22 06:40:17 PST 2004



--- In antlr-interest at yahoogroups.com, "John D. Mitchell"
<johnm-antlr at n...> wrote:
> >>>>> "atripp54321" == atripp54321  <atripp at c...> writes:
> [...]
> 
> >> I'll counter by saying we shouldn't be printing back this way. ;)
> >> Templates are the name of the game for generating output :) If
the
> >> output is very similar to the input, a better way is to just do
my
> >> tricks: either TokenStreamRewriteEngine or track token order in
the tree
> >> so you can dump automatically :)
> 
> > Yea, I suppose a treewalker is fine when the output is so very
close to
> > just a printing of the inorder traversal of the AST.  But I'm
still not
> > convinced that a treewalker is the best for very complex
AST-to-AST
> > transformations.
> 
> I'm confused.  Are you talking about source output or tree
manipulations
> (or both)?

I'm saying that a treewalker may be ok for source output, but
I still don't think it's good for tree manipulations.

> 
> For emitting source, a tree walker which builds up attributes on
the way
> down and emits (using e.g., StringTemplates) when coming back up is
pretty
> slick.

Isn't the only thing it needs to "build up" the level if indentation?

Also, your "pretty slick" phrase worries me.
The goal is always to write code that works and can be easily
understood by others, not to be clever.

To (mis) quote Kernighan: "If you ever find a section of your
code that you find particularly clever, strike it out and
do it again."

> 
> For generating new trees, you might want to check out the recent
thread
> where Loring and I talked about tree creation instruction streams.

OK, thanks.
> 
> Take care,
> 	John





 
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