[antlr-interest] Semantic predicate hoisting - How to turn off? (somewhat urgent)

Panayiotis panayk at gmail.com
Thu May 31 15:02:04 PDT 2007


Ter, the following seems to do the trick:

//hack
product_or_stronger_r_value returns [boolean is_l_value]
    :    f = factor {$is_l_value = $f.is_l_value;}
        (
            {$is_l_value}? (multiplicative_operator factor)+
        |    (multiplicative_operator factor)*
        )
    ;

So the DFA doesn't have a problem with "$f" after all. It's just that 
"f" is not defined within the code that is generated for (ironically) 
"factor". But "is_l_value" *is* defined, so the above hack works.

As you can see from the generated code (below) the value of 
"$f.is_l_value" is irrelevant but of course the compiler can't ignore 
it, hence the error.

if 
((((evalPredicate(we,"$we.is_l_value")&&evalPredicate(f,"$f.is_l_value"))||evalPredicate(we,"$we.is_l_value"))) 
) {

I suspect this will be very difficult to fix in the general case, so 
could we expect an option to disable hoisting locally or globally in a 
future version? (as useful as hoisting certainly is in most cases)

I really appreciate the time you took to help me,
Panayiotis


More information about the antlr-interest mailing list