## digitalmars.D.learn - BNF Question

• BCS (5/5) Sep 02 2007 What is the difference between an Identity Expression and a Equal Expres...
• Xinok (12/20) Sep 02 2007 An equal expression is when the data in two objects is compared.
• BCS (7/28) Sep 02 2007 However what you describe is at the semantic level and the grammar is to...
• Kirk McDonald (12/40) Sep 02 2007 The grammar is merely confusing. It might be better written as:
• Jascha Wetzel (20/58) Sep 03 2007 This one isn't actually a problem. But you will find that there are more...
• BCS (4/25) Sep 03 2007 Oouch!
```What is the difference between an Identity Expression and a Equal Expression?
both have a "ShiftExpression is ShiftExpression" and a "ShiftExpression !is
ShiftExpressionand".

http://www.digitalmars.com/d/expression.html#EqualExpression
http://www.digitalmars.com/d/expression.html#IdentityExpression
```
Sep 02 2007
Xinok <xnknet gmail.com> writes:
```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:
What is the difference between an Identity Expression and a Equal
Expression? both have a "ShiftExpression is ShiftExpression" and a
"ShiftExpression !is ShiftExpressionand".

http://www.digitalmars.com/d/expression.html#EqualExpression
http://www.digitalmars.com/d/expression.html#IdentityExpression

```
Sep 02 2007
```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.

What is the difference between an Identity Expression and a Equal
Expression? both have a "ShiftExpression is ShiftExpression" and a
"ShiftExpression !is ShiftExpressionand".

http://www.digitalmars.com/d/expression.html#EqualExpression
http://www.digitalmars.com/d/expression.html#IdentityExpression

```
Sep 02 2007
Kirk McDonald <kirklin.mcdonald gmail.com> writes:
```BCS wrote:

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
```
Sep 02 2007
Jascha Wetzel <"[firstname]" mainia.de> writes:
```This one isn't actually a problem. But you will find that there are more
tricky ambiguities. For example:

void main()
{
foo.bar.baz;
}

"foo.bar.baz" could be a type,
"foo.bar" could be a type and ".baz" a property,
"foo" could be an object, "bar" a member, and "baz" a member of that,
resulting in 3 different syntax trees:
BasicType
IdentifierList
or
PrimaryExpression
BasicType . Identifier
or
PostfixExpression
PostfixExpression . PrimaryExpression

The differences are only semantical.

Kirk McDonald wrote:
BCS wrote:

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

```
Sep 03 2007
```Reply to Jascha,

This one isn't actually a problem. But you will find that there are
more tricky ambiguities. For example:

void main()
{
foo.bar.baz;
}
"foo.bar.baz" could be a type,
"foo.bar" could be a type and ".baz" a property,
"foo" could be an object, "bar" a member, and "baz" a member of that,
resulting in 3 different syntax trees:
BasicType
IdentifierList
or
PrimaryExpression
BasicType . Identifier
or
PostfixExpression
PostfixExpression . PrimaryExpression
The differences are only semantical.

Oouch!

I think I'll look at handling dot chains as "Identifier . DotChain" and figure
out what it is at semantic time.
```
Sep 03 2007