[antlr-interest] Jumping around in (my|a?) tree :-)

Craig Main craig at palantir.co.za
Thu Jul 14 08:07:18 PDT 2005


Hi,

Given the following declaration for an "if" statement.


statement   

// here is the "other" statements part

            {log.Debug(null); object result = null;}

          : #(ASSIGN id:ID result=expression { log.Info(string.Format("{0} =
{1}", id.getText(), result)); } ) 
          | #(TOK_CONST cid:ID ASSIGN result=term) {log.Info("constant
decl");}

// here is the "if" part.

          | {log.Debug("inside");}
            #(TOK_IF condition (statement)* ({log.Debug("in-else");}
TOK_ELSE (statement)* {log.Debug("out-else");})?)
            {log.Debug("outside");}
          ;

The tree is looking good and all is working nicely - thanks for all the kind
assistance while I tore all my hair out with the tree syntax. The inside,
outside, in-else and out-else logging is working in the correct contexts.

Is there a way of making the tree only match the (statement*) in the
affirmative portion of the tree if the "if" condition is true, and only
match the (statement)* portion in the negative section of the "if" statement
if the condition is false?

Regards
Craig




More information about the antlr-interest mailing list