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

Panayiotis panayk at gmail.com
Wed May 30 09:49:55 PDT 2007


Thanks.

'$f' and '$we' are indeed labels, but they refer to elements that have 
*already* been parsed:

product_or_stronger_r_value
    :    f=factor
        (
            {$f.is_l_value}? (multiplicative_operator factor)+
        |    (multiplicative_operator factor)*
        )
    ;

And so on. The problem comes from the fact that both l-values and 
r-values (which make up the 'expression' rule) can be wrapped in 
parentheses and this makes it very difficult (for me) to make the 
grammar LL(k) (or even LL(*)) parsable in any other way.

So in this case I'd think it's safe to use them in the predicate and 
hoisting might even break the parser. Besides, this is an exercise in 
compiler construction and I don't think the professor would be very 
appreciative of ANTLR's fancy algorithm doing all the work for me!  
:-)       I am aiming for LL(1) with no more than a few predicates.

Panayiotis

Terence Parr wrote:

> Hi. Predicates cannot in general reference local variables or 
> parameters because they can be hoisted out of that rule.  Usually this 
> is no problem.  I suspect your use of $f and so on is not correct as 
> it probably references a labeled element after the predicate.  try 
> stuff like input.LT(1) etc...
>
> Ter
> On May 29, 2007, at 12:16 PM, Panayiotis wrote:
>
>> Hi!
>>
>> In ANTLR 3 is the new semantic predicate hoisting feature turned on 
>> by default?
>> I believe it is, because I'm getting javac errors like:
>>
>> [21:47:11] \tmp\antlrworks\pclParser.java:4225: cannot find symbol
>> [21:47:11] symbol  : variable f
>> [21:47:11] location: class pclParser
>> [21:47:11]                         if ( 
>> (((evalPredicate(we,"$we.is_l_value")&&evalPredicate(f,"$f.is_l_value"))||evalPredicate(we,"$we.is_l_value"))) 
>> ) {
>>
>> when in fact "$we.is_l_value" and "$f.is_l_value" never appear in the 
>> same rule. Either that or am I doing something fundamentally wrong :-) .
>> There were literally dozens of similar errors that disappeared as 
>> soon as I added the option "k=1;". Is there a similar option to 
>> disable predicate hoisting and any other advanced features ANTLR may 
>> have enabled by default?
>>
>> I need to get this working within the week, so I'll greatly 
>> appreciate any help you can offer me!


More information about the antlr-interest mailing list