[antlr-interest] Gated semantic predicates in C tree walker causing exceptions

Kieran Simpson kierans777 at gmail.com
Mon Apr 9 21:18:26 PDT 2012


For my tree grammar, I've come across the situation where I want to 
ignore the rest of the subtree we're currently in as well as any 
subtrees of the current tree.

As part of the rule, a variable continueProcessingBlock can get set to 
false, and the actions for parts of the rule check the boolean before 
taking action.

When it comes to the part of the rule where I want to descend into child 
trees, I was wanting to use a gated semantic predicate to decide whether 
or not to as in the example below:

myTreeRule
@init {
   bool continueProcessingBlock = true;
}
  :
    // .... matcher rules for nodes in the tree
    // can set continueProcessingBlock to false

    // Do we descend into subtrees?
    ({continueProcessingBlock}?=> myTreeRule*)
  ;

However the C code generated "throws" a FailedPredicateException.  It 
was my understanding that a gated semantic predicate is evaluated and if 
the result is false, then the walker moves on as opposed to a semantic 
predicate (non gated?) which would throw the FailedPredicateException.

Is this a bug, or a misunderstanding on my part?  Is there a better way 
to achieve the outcome?

Cheers,



More information about the antlr-interest mailing list