Terence Parr schrieb:
> this also gets rid of initValue issue.  We don't really know how to  
> return a "neutral" value when the stack is empty.
> 
> Ter

Just when I found a suitable C# feature to circumvent this issue... :P 
Go ahead with the change!

Johannes

> On May 2, 2008, at 2:19 PM, Terence Parr wrote:
> 
>> JimPoints out also that we should not be guarding our scope stacks.
>> Let's begin with the guards we added for referencing rule properties.
>> In version 3.0.1, if the else clause is not executed, s is null and
>> you get a null pointer at $s.st.
>>
>> ('else' s=stat)? ... {$s.st}
>>
>> For 3.1, we have guarded all of those property references with s! 
>> =null?
>> s.st:null. That is good.
>>
>> Now Imagine how we guard stack stuff. consider the following rule:
>>
>> block
>> scope { int x; }
>>      :       '{' stat+ '}'
>>      ;
>>
>> Ref $block::x currently checks that the stack is not empty before
>> calling peek() to avoid a stack underflow exception. Jim argues that
>> we should take that guard back out because it is a programming error
>> to refer to $block::x when the stack is not properly set up. I think
>> I'm agreeing with him. Is like accessing the local variable in an
>> enclosing function but when there is no invoking function.
>>
>> We would need to change these templates:
>>
>> scopeAttributeRef(scope,attr,index,negIndex) ::= <<
>> <if(negIndex)>
>> ((<scope>_stack.size()-<negIndex>-1)>=0?
>> ((<scope>_scope)<scope>_stack.elementAt(<scope>_stack.size()-
>> <negIndex>-1)).<attr.name>:<initValue(attr.type)>)
>> <else>
>> <if(index)>
>> ((<index>\<<scope>_stack.size())?
>> ((<
>> scope
>> _scope
>> )<scope>_stack.elementAt(<index>)).<attr.name>:<initValue(attr.type)>)
>> <else>
>> ((<scope>_stack.size()>0)?
>> ((<
>> scope>_scope)<scope>_stack.peek()).<attr.name>:<initValue(attr.type)>)
>> <endif>
>> <endif>
>> scopeSetAttributeRef(scope,attr,expr,index,negIndex) ::= <<
>> if ( <scope>_stack.size()>0 ) {
>> <if(negIndex)>
>> ((<scope>_scope)<scope>_stack.elementAt(<scope>_stack.size()-
>> <negIndex>-1)).<attr.name> =<expr>;
>> <else>
>> <if(index)>
>> ((<scope>_scope)<scope>_stack.elementAt(<index>)).<attr.name> =<expr>;
>> <else>
>> ((<scope>_scope)<scope>_stack.peek()).<attr.name> =<expr>;
>> <endif>
>> <endif>
>> }
>> to avoid (<scope>_stack.size()>0) tests.
>>
>> Is it okay for me to remove the stack guards for dynamic scoping
>> stuff?  quick change to these two templates.
>>
>> Ter
>> _______________________________________________
>> antlr-dev mailing list
>> [email protected]
>> http://www.antlr.org:8080/mailman/listinfo/antlr-dev
> 
> _______________________________________________
> antlr-dev mailing list
> [email protected]
> http://www.antlr.org:8080/mailman/listinfo/antlr-dev
> 

_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org:8080/mailman/listinfo/antlr-dev

Reply via email to