[antlr-interest] Can't create AST Node?
Monty Zukowski
monty at codetransform.com
Thu Jul 8 21:30:25 PDT 2004
On Jul 8, 2004, at 1:23 PM, Tiller, Michael ((M.M.)) wrote:
> With regards to ANTLR 'fest, I'm happy to share my experiences and
> ideas
> (even if I don't have any actual code worth/able to share). I don't
> doubt the value of tree parsers in many circumstances and, to be
> honest,
> I don't know if there is really a barrier to enjoying the best of both
> worlds. I'm just at the point where I'm tired of wrestling the het-AST
> support. With time, ANTLR may very well support the best of both
> worlds.
>
That would be great if you could come out to it!
One of the goals of antlr is to have it make sense to normal
programmers. We certainly intend to make it easy and understandable
for people to use het-ASTs. However, I don't think any of the main
contributors to the code base have used them in practice. Perhaps
Loring has.
> I think there may be some interesting possibilities for using
> introspection on the Java side to deal with tree walking. For example,
> do you really need first child, next sibling, etc when you can get a
> complete inventory of fields?!? I mean why not make a tree walker that
> works with native objects rather than having to create special AST
> nodes? Couldn't you just use java.reflect + instanceof (I'm no Java
> expert and I'm not sure how "portable" it would be). That way you
> could
> both walk existing Java classes and potentially create new ones as you
> went. The idea is AST=java.Object, children=java.reflect.Fields and
> you
> just use/create native Java objects. No special base classes (for
> example). Perhaps the overhead would be too much?!? Just a thought.
>
The models don't quite match. Object fields don't show the order in
which things arrived, unless they are in arrays or collections. But
sometimes the order is important, and that can be captured in a
child/sibling tree naturally. I had to wrestle with that in the SQL
grammar I just worked on. But it worked out OK, it just required some
extra restructuring of the grammar and tree building stuff.
> One last comment, I suspect that it might be useful to provide
> automatic
> "visitor generation" for people where visitors seem more attractive
> (ala
> SableCC?).
Seems like that would be easy enough to add.
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