[antlr-interest] tree parsers vs visitors & xml translators etc...
Terence Parr
parrt at jguru.com
Thu May 9 20:23:23 PDT 2002
Heh, just found a very good reason to use a tree grammar over a simple
AST visitor or any other translator you'd find in the XML world:
visitors have to look for your pattern over the whole tree whereas a
tree grammar specifies precisely where to look and, most importantly,
when to stop looking! On large ASTs such as those representing Java
programs this can be a big win.
For example, I'm working on the java parser / tree parser we have. My
first tree phase will pick up class/interface and method definitions.
Naturally, these are all at the outermost layers within the Java ASTs
and it would not make sense to look into every expression in your java
program looking for class defs. The tree parser knows these constructs
exist at the highest level and therefore does not traverse all the
expressions (I use '.' wildcard to terminate the walk when I know
there's no hope of finding deeper class defs).
I'm guessing that most visitor patterns and all XSLT type stuff will
search the whole damn tree looking for node of type CLASS_DEF.
<snicker>.
Can anybody comment on the visitor/xslt side? How would you do this
"find class defs" problem efficiently?
Hooray for tree grammars! And now back to your regularly scheduled
lives...
Ter
--
Co-founder, http://www.jguru.com
Creator, ANTLR Parser Generator: http://www.antlr.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list