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

Kieran Simpson kierans777 at gmail.com
Tue Apr 10 18:13:55 PDT 2012

Looking at that the Java code that is generated for the same grammar, 
again a FailedPredicateException is thrown if the gated semantic 
predicate is false

if ( !((continueProcessingBlock)) ) {
     throw new FailedPredicateException(input, "myTreeRule", 

According to the Antlr book (and 
gated semantic predicates shouldn't throw exceptions.

The caveat however is what I've read deals with parsers (something that 
produces an AST) not a tree walker/grammar so perhaps gated semantic 
predicates are treated differently.


On 23/07/64 5:59 AM, Kieran Simpson wrote:
> 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