[antlr-interest] conditional tree jumping,

Jeff Barnes Jeff.Barnes at codesic.com
Sat Feb 18 21:00:13 PST 2006


Hi Craig,
 
I'm no tree parser guru, but I believe you want to return a boolean instead of an object from the condition rule. Perhaps you can evaluate the result of the expression rule on the result alt. You may, however, want to refactor the result=expression to something like result=booleanExpression since a condition implies a boolean, at least in my mind it does... ;)
 
Regards,
Jeff

________________________________

From: antlr-interest-bounces at antlr.org on behalf of Craig Main
Sent: Sat 2/18/2006 1:55 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] conditional tree jumping,



Hi,

 

Is there any way of only evaluating the true part when the condition is true, and the false part if the condition is false in the below tree?

 

statement                          {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");}

                                 | {log.Debug("inside");}

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

                                   {log.Debug("outside");}

                                 ;

 

condition                        

returns [object result]             {log.Debug(null); result = null; object l, r;}

                                 : #(TOK_OR l=condition r=condition)

                                  | #(TOK_AND l=condition r=condition)

                                  | #(NOT_EQUAL l=condition r=condition)

                                  | #(EQUAL l=condition r=condition)

                                  | #(LTHAN l=condition r=condition)

                                  | #(GTHAN l=condition r=condition)

                                  | #(LTE l=condition r=condition)

                                  | #(GTE l=condition r=condition)

                                 | result=expression {log.Debug("condition->expression");}

                                 ;

 

Regards

Craig



More information about the antlr-interest mailing list