[antlr-interest] Shortcircuiting the tree parser

Oliver Zeigermann oliver.zeigermann at gmail.com
Sun Jan 25 13:43:35 PST 2009


2009/1/25 Johannes Luber <jaluber at gmx.de>:
> Carter Cheng schrieb:
>> Thanks everyone for the replies to my previous post. I have been wondering about one additional point
>> when it comes to tree parsers. For alot of AST's when doing semantic
> analysis you tend to have alot
>> of separable distinct tasks which only need parts of the constructed
> tree. I am curious if there is
>> a way to underspecify the tree grammar and tell it explicitly not to
> descend certain portions of the
>> AST and only focus on certain parts. I apologize if this has been
> addressed before.
>>
>> Thanks in advance,
>>
>> Carter.
>>
> Well, you could use the . to mark certain nodes and subtrees as "just
> have to be here".
>

Which isn't that easy as the wildcard '.' does not work for tree
roots. Additionally, nodes matched by wildcards do not seem to get
copied to the output tree automatically.

What you could do is to have simple Java code that scans (and copies
if desired) the tree until it finds - say - an expression an calls a
tree parser with this sub tree. You can take BaseTreeAdaptor#dupTree
for inspiration how to traverse a random tree.

- Oliver


More information about the antlr-interest mailing list