[antlr-interest] Multiple pass tree walking Q
Paul Johnson
gt54-antlr at cyconix.com
Wed Oct 4 01:12:53 PDT 2006
Hill, Robert wrote:
> I've pretty much gone down the multiple tree parser routes, its a real
> pain in the ass though, as if you modify your parser, you then have to
> modify all the tree parser grammars too. I must be missing something
> here. :(
> there must be a rule that ignores a whole branch, but i've tried all
> sorts and haven't succeeded ,
>
> ignoreme : ^(.*) ... if only :)
>
> which is why i ended up with 3 tree parse phases. I just get this
> nagging feeling im missing the point.
You won't like this reply, but this is why I don't use tree grammars.
I've got 8 passes, each of which needs to modify the AST. I manually
parse the tree, and cut out branches when I've finished with them (or
replace nodes, or whatever).
The recursive tree parse in each pass is (almost) trivial, so a grammar
would buy me little. I do have occasional complications with having to
find my context in the tree, parsing node lists right-to-left instead of
left-to-right, and so on, but no major problems, and certainly nothing
that would justify maintaining 8 different grammars. One major advantage
is that I can trivially add extra passes that do almost nothing, except
maybe some cleaning up for the next pass.
Disclaimer: I've never actually tried the tree grammar route, so I (too)
may have missed easy ways to do what I'm now doing manually.
There's a lot on this in the archives - have a look. You could start
with Andy Tripp's reply in the "How much use is ANTLR for manipulating
ASTs?" thread (18/06/2005).
Paul
More information about the antlr-interest
mailing list