[antlr-interest] Tree walking Q
Terence Parr
parrt at cs.usfca.edu
Sat Jun 4 16:06:58 PDT 2005
On Jun 4, 2005, at 3:37 PM, Gerald B. Rosenberg wrote:
> The basic question: Is there a way to set a default token rule for
> use during tree parsing? The objective is to skip tokens that are
> not within a select subset that are to be processed by a particular
> tree-parser run.
>
> My AST is rather large and complex, to the point where I cannot, as
> a practical matter, define tree-parser rules for all potential
> tokens. The ANTLR generated tree-walker quits if it encounters an
> unknown token.
>
> Is there a default rule identifier? Or, is there another mechanism
> to enable the tree-parser to simply walk past those tokens not
> otherwise identified to the parser?
Hi. In the lexer, we such a filtering mechanism, but there isn't
such a beast for tree parsing unless than the brute force "find this
subtree" kind of thing. Syntactic predicates like this might work ok:
filterRule : (alt1)=>alt1
| (alt2) => alt2
...
| .
;
where the last alt matches any node. The only problem is that it
would look only for matching root nodes and then descend. this would
work fine if the list were flat, but then you'd not be needing a tree
walker ;)
I suggest you look at JBurg, which is technically used for generating
machine instructions but it does a great job of finding subtrees in a
large tree. You can even assign costs to each subtree match and it
will find the best match. Now that I say it, it is exactly what you
want. JBurg should merge nicely with ANTLR :)
Ter
More information about the antlr-interest
mailing list