Hi Martijn, The state stack is unreliable in combination with semantic predicates and "cannot" be used in that manner. Instead you should use a construct like . or ^(IF .*) to skip the subtree in your walker.
Sam -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Martijn Reuvers Sent: Tuesday, May 05, 2009 11:56 AM To: Micha; [email protected] Subject: Re: [antlr-interest] Skip subtree in tree grammar Hello Micheal, Somehow we've managed to forget to include the antlr-list in our conversation, so here the update and solution for the others. I've used the stack solution (which I can probably use for other conditionals too). It seems to work fine, I wrote the following method: public boolean isContentEvaluable() { return phase > 0 && (isConditionalStackEmpty() || peekConditionalResult()); } The method is used in function_content's rules and determines if each rule should evaluate or not. As said the solution is backed by a stack which is pushed/popped in @init and @after with boolean results. Ignore the phase, which is not relevant for this solution. Finally: I am still curious if you can skip a tree grammar subtree altogether (the if statement in this mail conversation), so if someone knows, I'd love to hear that too! Thanks for thinking along! Martijn On Tue, May 5, 2009 at 6:00 PM, Micha <[email protected]> wrote: > On Tuesday 05 May 2009 17:39:55 you wrote: >> Hi Michael, >> >> Thanks for your reply. Preferably I would just like to move the >> treestream up to after the if-statement (if the value is false). But I >> don't know how to calculate the proper index from here and to properly >> pop/push it. >> >> With your solution you mean overread_function_content* contains the >> same rules as function_content, except without any logic? > > yes > >> Another thing I was thinking of but haven't tried yet, is to push the >> conditional result on a stack and in function_content (its subrules), >> peek the stack and if the stack is either empty (we're not in a >> conditional check) or the top returns true - evaluate, else do >> nothing. This might work, but I haven't tried it yet. > > that was another solution I thought about. I think this depends on the > grammar... > > > cheers > Michael > > List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: 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 -~----------~----~----~----~------~----~------~--~---
