I have narrowed down my problem.  The validating semantic predicate
properly throws a FailedPredicateException in a regular tree grammar,
but does not when filter=true.

I added the following TreeMatcher.g to the VecMath example from the
new book.  (I invoke this TreeMatcher before the Printer.)  Note that
the INT alternative has a validating semantic predicate that is
guaranteed to fail.  However when I run the program, no sign of the
FailedPredicateException.

Am I wrong to expect this?

Thanks,
Tom.

tree grammar TreeMatcher;

options {
        tokenVocab=VecMath;      // use token vocabulary from VecMath.g
        output = AST;
        ASTLabelType = CommonTree;
        filter = true;
}

topdown:        expr;

// START: expr
expr:   ^('+' expr expr)
    |   ^('*' expr expr)
    |   ^('.' expr expr)
    |   ^(VEC expr (expr)*)
    |   INT {false}?
    |   ID
    ;
// END: expr


On Tue, Aug 4, 2009 at 2:02 PM, Tom Smith<[email protected]> wrote:
> I have a rule (in a tree pattern matcher) that uses a validating
> semantic predicate.  When the predicate returns false, I expected to
> catch a FailedPredicateException and take some custom action.
> However, the FailedPredicateException is not getting thrown.  Looking
> at the generated code, the problem appears to be that the exception
> only gets thrown conditionally (if state.backtracking==0).  For some
> reason that is beyond my meager understanding, state.backtracking = 1
> when the semantic predicate fails.
>
> Any clues for me?
>
> Thanks,
> Tom Smith.
>
> tree grammar Trans;
>
> options {
>        tokenVocab=SsipAST;
>        output=AST;
>        ASTLabelType=CommonTree;
>        filter = true;
> }
> ...
> transition
> scope {
>    ...
> }
> @init {
>    ...
> }
>        :       ^(TRANSITION s1=stateName s2=stateName arcBody[$s1.text])
>        { checkTransition($s1.text, $s2.text) }?
>        { System.err.println("Transition from " + $s1.text + " to " +
> $s2.text + " is OK"); }
>        ;
>        catch [FailedPredicateException fpe] {
>                String msg = String.format("In transition from \%s to \%s, 
> liveness
> is not consistent", $s1.text, $s2.text);
>                throw new SemanticException(msg);
>        }
>

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to