[antlr-interest] Multiple pass tree walking Q

Robert Hill rob.hill at blueyonder.co.uk
Wed Oct 4 11:46:49 PDT 2006


> > I want to make multiple passes over a tree but only utilise parts
> > of the tree for each pass so I've duplicated the tree grammar 3
> > times , adding actions only for the parts that matter at each pass.
>   I have already added a wiki entry about this on the to do list:
> 
> http://www.antlr.org/wiki/display/ANTLR3/allow+skipping+of+entire
> +subtrees+during+tree+parsing

That's what I was trying with the  ^(TOKEN .*) -  I tried loads of
combinations, looking at the source to see if I was getting close, but it
was having none of it hehehe.. oh well!

> > So the question is , how do you ignore (remove) whole branches of a
> > tree? At the moment if I add a node into the parser output I have
> > to change all 3 tree walkers in response. If I know that the tokens
> > that pass 1 will no longer be affected, how can I remove all the
> > unwanted rules from that grammar so It only looks at the tokens it
> > needs?
> I think what we really need is a filter mode for trees just like we
> have for lexer's.  This would be almost a declarative approach where
> you say what trees you want to match and what actions to execute when
> you see it.  For example,
> 
> tree grammar TP;
> 
> options {filter=true;}
> 
> IDENTITY
> 	:	^(MULT i:INT j:INT)
> {$i.text.equals("1")||$j.text.equals("1")}?
> 		-> i
> 	;
> 
> pretty sweet.   of course I need tree grammars to be able to generate
> trees before I can do this.

Yup, that would be pretty sweet, at least you wouldn't have to include whole
trees of un-actioned tokens. I like that, for me that would pretty much
solve the whole single tree multiple pass problem.

So then.. When will it be ready? stop that slacking mate & jump to it ;) LOL

> The idea will be that it tries all patterns looking for a match in
> the order specified.  An index can be used to speedthings up by only
> attempting rules on nodes in the tree that can possibly match.  For
> example if there is only one MULT node in the entire tree, don't walk
> the entire tree looking for that pattern.
> 
> added this is a wiki entry:
> 
> http://www.antlr.org/wiki/display/ANTLR3/filter+tree+grammar+mode
> 
> Ter

It would definitely be a useful tool to have, you shouldn't have made the
beta so good, then I wouldn't think it was 100% complete with everything I
want LOL
;)

Cheers,
Rob





More information about the antlr-interest mailing list