BNF Question

Kirk McDonald kirklin.mcdonald at gmail.com
Sun Sep 2 22:53:30 PDT 2007


BCS wrote:
> Reply to Xinok,
> 
>> An equal expression is when the data in two objects is compared.
>> int[] arr1 = [10, 20, 30], arr2 = [10, 20, 30];
>> if(arr1 == arr2){ } // True
>> An identity expresion is when the pointer values (and .length in
>> arrays)
>> in two objects is compared.
>> int[] arr1 = [10, 20, 30], arr2 = arr1;
>> if(arr1 is arr2){ } // True
>> For primitive types, there is no difference between using == and is.
>> int a = 15, b = 15;
>> if(a == b){ } // True
>> if(a is b){ } // True
>> BCS wrote:
>>
> 
> However what you describe is at the semantic level and the grammar is 
> totally at the syntax level. What I was looking at is that this:
> 
> a is b
> 
> can be parsed as an Identity Expression and an Equal Expression.
> 
> If the distinction is a semantic issue then this makes D context 
> sensitive. If it is not a semantic issue, then it is redundant or 
> conflicting.
> 

The grammar is merely confusing. It might be better written as:

EqualExpression:
	ShiftExpression
	ShiftExpression == ShiftExpression
	ShiftExpression != ShiftExpression
	IdentityExpression

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list