[antlr-interest] skipping evaluation of some AST nodes

Harald Mueller harald_m_mueller at gmx.de
Wed Nov 28 06:44:49 PST 2007


Hi again -

my second gut feeling says that you can do the following:

rule
    { ... compResult; }
   : ^(a 
       b    { compResult = some-action; }
       c[compResult]
      ) 
   ;

- i.e. you must run through everything; but you can compute things along your way and then pass them into subsequent subtree traversals (or even out to someone else via a returns or an "out" object).

What you cannot do, is change the order: Left things are traversed before right things. So if you want to have a representation of perl's statements

    statement if condition;

or 

    statement unless condition;

you must make sure that the condition subtree is to the *left* of the statement subtree - but that's easy.

Regards
Harald M.



-------- Original-Nachricht --------
> Datum: Wed, 28 Nov 2007 08:45:57 +0100
> Von: "Harald Mueller" <harald_m_mueller at gmx.de>
> An: "Mark Volkmann" <r.mark.volkmann at gmail.com>, antlr-interest at antlr.org
> Betreff: Re: [antlr-interest] skipping evaluation of some AST nodes

> 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

-- 
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten 
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser


More information about the antlr-interest mailing list