[antlr-interest] Can't create AST Node?

Monty Zukowski monty at codetransform.com
Thu Jul 8 11:28:07 PDT 2004


On Jul 8, 2004, at 10:52 AM, Tiller, Michael ((M.M.)) wrote:
>> Not sure if you answered this before, but why do you want to use
>> heterogenous trees?
>
> Sort of a, "Tell me you need a TV in your golf cart" kind of question?
> :-)
>
> I'm hard pressed to provide a more defendable answer than "because that
> is the way I think".  It's sort of like the object models between
> Smalltalk, Java, C++ etc.  Some people are comfortable with the
> "everything is a subclass of Object" way of doing things while others
> say "why do you needlessly abstract things into a common base class".
>
> When I think about the various structures in the language I'm parsing, 
> I
> think of them as distinctly different entities (declarations, type
> definitions, expressions) and not as just a bunch of homogenous nodes.
> That is just the way I think about it.  I feel much more comfortable
> working with an object knowing what it is and what I can expect from it
> without having to do a bunch of run-time type interrogation and 
> casting.

Yeah, but that can get cumbersome at the object level with recursion 
and alternatives.  It depends a great deal on the complexity of the 
language.  With SQL I had to do some contortions to get it to fit into 
a regular object structure.  However, then it was really easy to 
manipulate it from C++, which is what my client wanted.  In this case I 
think heterogenous trees were appropriate.

>
> Think about it this way.  Imagine trying to program in Java or C++ and
> not ever using the "." (as in computer.drives[1].head.position) and
> instead having to interrogate every object using only "getFirstChild()"
> and "getNextSibling()" and having only type and text information.
> Imagine trying to express what I just typed? (i.e.
> computer.drives[1].head.position) You get something like:
> ...

> Yikes!  Isn't "computer.drives[1].position.head" much simpler and
> statically checkable?

Sure it is.  Tree grammars are appropriate for walking but not 
searching.  When you translate you typically walk the whole tree.  
Sometimes you index the tree with a symbol table.  But rarely do you 
say 'give me the first term of the third expression in the for loop.'

>
> Granted, tree parsers make this a lot easier, but I'm not using tree
> parsers (and perhaps I'm just dense, but I don't think they will help 
> me
> in what I'm trying to do).

Still not sure what you are trying to do :)

Monty



 
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