[antlr-interest] skipping evaluation of some AST nodes

Harald Mueller harald_m_mueller at gmx.de
Tue Nov 27 23:45:57 PST 2007


Hi -
my gut feeling is that this should be done with a manually programmed visitor, NOT with a tree parser. Tree parsers are *parsers*, i.e., they traverse *everything*. If actions should pick only parts of a structure, they should be programmed with a visitor which does just that. To that end, I would generate separate types for each node in an AST so that the standard visitor pattern can be applied; but a big "switch on AST head token type" top-level fork calling many specialized visiting methods might also be a useful design.
Regards
Harald

-------- Original-Nachricht --------
> Datum: Tue, 27 Nov 2007 15:34:40 -0600
> Von: "Mark Volkmann" <r.mark.volkmann at gmail.com>
> An: antlr-interest at antlr.org
> Betreff: [antlr-interest] skipping evaluation of some AST nodes

> This is related to an earlier question I asked, but stated in a different
> way.
> Suppose I have part of an AST that looks like this.
> 
> ^(a b c) { some-action }
> 
> So b and c are child nodes of a.
> If I match on the expression above then the rules for a, b, and c will
> all be processed and their actions will be executed.
> What I'd like to do is have "some-action" above be in control of what
> happens.
> It would examine the results of the rule b action and then possibly
> decide to not process the rule for c which would avoid executing its
> action.
> I know I could write the action for rule c to just store information
> about what might be executed later, but I'm wondering if there is a
> way to avoid that kind of bookkeeping and just specify in the action
> for rule c what I want done if "some-action" decides it should be
> done.
> 
> Is there a way to do this?
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.

-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer


More information about the antlr-interest mailing list