[antlr-interest] AST generation: EXPRESSION TREE example.

Monty Zukowski monty at codetransform.com
Wed Jun 2 21:33:24 PDT 2004


On Jun 2, 2004, at 2:58 PM, Bharath Sundararaman wrote:

> To generate
> an AST with a decent structure (based on my needs), my understanding 
> is that
> I have to add qualifiers (^, !) to each rule and modify existing rules 
> to
> make them AST friendly. Is this a cumbersome process?

Well, it can be.  Loring and I were recently debating what makes a good 
tree, and some of that ended up here a month or so ago in a dialog 
between me and John Mitchell about the NULL node placeholder.  I 
believe the java grammar builds a tree, my C grammar is also a good 
example.  In my latest ANTLR contract I was building a SQL tree but I 
had special considerations because everything had to be accessible from 
an embedded language.  I concluded that there are very many different 
reasons for wanting a tree that will guide a strategy toward building 
them.

So, are you doing source to source translation?  Are you translating to 
a different language, or to the same language (like my C toolkit does)? 
  Are you only building a tree for analysis?  Are you building a tree to 
be manipulated directly by raw code or will it always be manipulated by 
a tree grammar (my recommendation.)  Do you have to preserve 
formatting?  Comments?  Original possibly extraneous parenthesis?

Let's work this through and maybe I can write up a guide for it when 
I've got some "free" time.

Please, anybody join in and tell me what you're doing and let me know 
what's worked for you and what hasn't and what your questions are.  
I'll probably only get to this once or twice a day but hopefully we can 
ferret out some real life questions and solutions over the next week or 
so.  I know we've got plenty of experts out there too.  This is the 
kind of stuff that will help shape ANTLR 3.  Loring's got some amazing 
tree integration stuff on the horizon but there is always a place for 
understanding why people want trees and how to use them most 
effectively.

Monty Zukowski

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit -- 
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html



 
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