[antlr-interest] [Bug Report] C target mishandles failed validating semantic predicate

John Grout j.grout at computer.org
Mon Nov 8 08:50:22 PST 2010


When passing a duplicate argument to an argument-processing rule like

walletArgs
@declarations {
         ANTLR3_BOOLEAN b_nameArg, b_passwdArg, b_typeArg, b_userArg; }
@init {
         b_nameArg = ANTLR3_FALSE;
         b_passwdArg = ANTLR3_FALSE;
         b_typeArg = ANTLR3_FALSE;
         b_userArg = ANTLR3_FALSE;
}
     : ( nameArg {!b_nameArg}? {b_nameArg = ANTLR3_TRUE;} |
         passwdArg {!b_passwdArg}? {b_passwdArg = ANTLR3_TRUE;} |
         typeArg {!b_typeArg}? {b_typeArg = ANTLR3_TRUE;} |
         userArg {!b_userArg}? {b_userArg = ANTLR3_TRUE;} )*
     -> ^( ARGUMENT_LIST nameArg? passwdArg? typeArg? userArg? )
     ;

the C target creates a FailedPredicateException (the corresponding
ANTLR3_BOOLEAN variable is already ANTLR3_TRUE)... but the code
then falls through to execute the subsequent semantic action (and,
apparently, to the rewrite rule) rather than branching to  
rulewalletArgsEx,
which is where the rule throws its exceptions.  There is an exception  
check
and a branch to rulewalletArgsEx a few statements _before_ the  
validating
semantic predicate is tested, but none afterward.

As expected, the Java target throws a FailedPredicateException.

Full example on request (I've already sent it to Aaron Leiby, whom I
thank for pointing out the specific error which also turns up in my
own grammar, and Jim I).

John R. Grout
j.grout at computer.org



More information about the antlr-interest mailing list