Don't walk the tree to evaluate the expression; walk the tree to generate byte code and then interpret the byte code. The overall problem then gets simpler and the resulting code runs faster.
--Loring ----- Original Message ---- > From: Jane Eisenstein <[email protected]> > To: "Farr, John" <[email protected]> > Cc: "[email protected]" <[email protected]> > Sent: Sat, May 29, 2010 2:15:56 PM > Subject: Re: [antlr-interest] short circuiting further evaluation > > Thanks. Using gated semantic predicates nicely simplifies the logic in each > rule > (while doubling the number of rules). It doesn't stop the parse though > -- just the evaluation. Is there a clean way to determine the > condition's final result and return it without having to complete the parse > of > the entire expression? Jane On May 28, 2010, at 10:22 AM, > Farr, John wrote: > The message I posted on April 8 with the subject > "Processing/traversing a rule -- dealing with conditionals" may help > you. > > --John > > > -----Original > Message----- > From: > href="mailto:[email protected]">[email protected] > > [mailto: > href="mailto:[email protected]">[email protected]] > > On Behalf Of Jane Eisenstein > Sent: Friday, May 28, 2010 7:47 AM > > To: > href="mailto:[email protected]">[email protected] > > Subject: [antlr-interest] short circuiting further evaluation > > > I'm working with a simple expression grammar: > > > condition: conditional_expression EOF > > ; > > conditional_expression > > : conditional_term > > ( OR conditional_expression > )? > ; > > conditional_term > > : conditional_factor > > ( AND conditional_term )? > > ; > > conditional_factor > > : conditional_primary > > | NOT conditional_primary > > ; > > conditional_primary > > : ID > | LEFT_PAREN > conditional_expression RIGHT_PAREN > ; > > > At runtime, ID tokens evaluate to either true or false. Once it is clear the > condition as a whole will evaluate to either true or false, I'd like to stop > the > evaluation and return the value of the condition. So far, all I've managed to > do > is short-circuit further ID evaluations once an upper level outcome is > know. > > Is there a way to short circuit the entire parse? I'm not > sure how to even tell it would be time to do so. > > Jane > > > > > > > List: > href="http://www.antlr.org/mailman/listinfo/antlr-interest" target=_blank > >http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: > > target=_blank > >http://www.antlr.org/mailman/options/antlr-interest/your-email-address > > > > [CONFIDENTIALITY AND PRIVACY NOTICE] > > > Information transmitted by this email is proprietary to Medtronic and is > intended for use only by the individual or entity to which it is addressed, > and > may contain information that is private, privileged, confidential or exempt > from > disclosure under applicable law. If you are not the intended recipient or it > appears that this mail has been forwarded to you without proper authority, > you > are notified that any use or dissemination of this information in any manner > is > strictly prohibited. In such cases, please delete this mail from your > records. > > To view this notice in other languages you can either > select the following link or manually copy and paste the link into the > address > bar of a web browser: > target=_blank >http://emaildisclaimer.medtronic.com > > List: > target=_blank > >http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: > href="http://www.antlr.org/mailman/options/antlr-interest/your-email-address" > target=_blank > >http://www.antlr.org/mailman/options/antlr-interest/your-email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
