[antlr-interest] problem with validating semantic predicate (related to backtracking)

Tom Smith yotommy at gmail.com
Tue Aug 4 11:02:42 PDT 2009


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);
	}


More information about the antlr-interest mailing list