[antlr-interest] Trouble with syntactic predicates that reference semantic predicates that rely on a current dynamic attribute scope

Terence Parr parrt at cs.usfca.edu
Fri Jul 25 10:31:51 PDT 2008


Hi Sam,

Wow!I had not thought of this. The problem is that the predicate gets  
hoisted out of rule2 and is evaluated before entry into rule2. The  
code to push the new scope is not executed. crap...yeah, there are  
general issues with predicates to get hoisted out of context... I  
cannot really look inside to see your actions to know what to do. I  
will say, however, that you are not using proper syntax to access the  
scope. it must be $rule2::a not a. In fact, I am surprised that works  
at all! is that really compile?  int a will be inside of a class.  'a'  
all by itself should not compile.
Ter

On Jul 25, 2008, at 9:33 AM, Sam Harwell wrote:

> Wow that’s a big statement!
>
> Consider the following setup:
>
> rule2
> scope
> {
>     int a;
> }
> @init
> {
>     a = -1;
> }
> : { (a < 0) }? rule3 { ((a=1) >= 0) /* intentional assignment */ }?
> ;
>
> rule1
> : ((rule2) => rule2)+
> ;
>
> rule0
> : (rule1) => rule1
> | rule4
> ;
>
> In evaluating the syntactic predicate in rule0, the semantic  
> predicate at the beginning of rule2 is evaluated without pushing a  
> new dynamic attribute scope. I can detect the lack of a dynamic  
> scope (rule2_stack.Count == 0), but there is a path for rule0 to be  
> reached inside rule2, in which case the semantic predicate is  
> checking the value of a in the wrong scope. Is this a bug?
>
> Sam
>



More information about the antlr-interest mailing list