[antlr-interest] BUG? - Predicates subject to precedence error

Austin Hastings Austin_Hastings at Yahoo.com
Sun Oct 7 07:47:50 PDT 2007


I'm currently in predicate hell, which I will happily detail once I get out.

In the mean time, though, I've stumbled on the unpleasant fact that if 
you specify a predicate like:

rule : { condition1 || condition2 }? stuff ;

the predicate will be inserted at the whim of ANTLR into various places, 
possibly including a condition that includes a synthetic predicate.

The resulting code looks like this:

if (
     (
       (
         synpred6()
         &&decl_specifiers_stack.size() <= 0
         || (
              (decl_specifiers_scope) decl_specifiers_stack.peek()
            ).allowStorageClass
        )
     )
    )
{

Particularly, the conjunction of the synthetic predicate with the rule 
is not guarded by placing parens around the rule. Since logical and (&&) 
has higher precedence than logical or (||) the sense of the rule is changed.

I don't know if this is a string-template bug or a tool bug. Sorry.

=Austin



More information about the antlr-interest mailing list