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,
pretty sweet. of course I need tree grammars to be able to generate trees before I can do this.
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.