While I was looking through the C# Language Specification v4.0
I noticed that there is a group of rules defined as this:
invocationExpression:
primaryExpression '(' argumentList? ')'
primary-expression:
primary-no-array-creation-expression
array-creation-expression
primary-no-array-creation-expression:
literal
simple-name
parenthesized-expression
member-access
invocation-expression
element-access
this-access
base-access
post-increment-expression
post-decrement-expression
object-creation-expression
delegate-creation-expression
anonymous-object-creation-expression
typeof-expression
checked-expression
unchecked-expression
default-value-expression
anonymous-method-expression
base-access:
'base' '.' identifier
'base' '[' argument-list ']'
When I tried to match this statement (which is correct statement by the way, I've seen it used in a project)
base.VisitList<T>(list, visitor);
to the given rules I didn't see a way how this can be done. Shouldn't be base-access
defined as:
base-access:
'base' '.' identifier type-parameter-list(opt)
'base' '[' argument-list ']'
or something similar to this in such a way the grammar be able to capture the statement?
EDIT The example I saw was in the C# version of the project db4o
and it is something like this (I deleted most of the declarations and left only the important ones)
internal abstract class ExpressionVisitor
{
protected virtual void VisitList<T>()
{
}
}
internal class HashCodeCalculation : ExpressionVisitor
{
protected override void VisitList<T>()
{
base.VisitList<T>();
}
}
It indeed looks like there might be an error in the specification.
The way to parse the expression
this.VisitList<T>(list, visitor)
is as follows:
invocation-expression
primary-expression '(' argumentList? ')'
primary-no-array-creation-expression '(' argumentList? ')'
member-access '(' argumentList? ')'
primary-expression '.' identifier type-argument-listopt '(' argumentList? ')'
this-access '.' identifier type-argument-listopt '(' argumentList? ')'
'this' '.' identifier type-argument-listopt '(' argumentList? ')'
And so on.
In other words, this-access
is defined as
this-access:
'this'
It would make a lot of sense if base-access
were defined as
base-access:
'base'
Then the way to parse the expression
base.VisitList<T>(list, visitor)
would be as follows:
invocation-expression
primary-expression '(' argumentList? ')'
primary-no-array-creation-expression '(' argumentList? ')'
member-access '(' argumentList? ')'
primary-expression '.' identifier type-argument-listopt '(' argumentList? ')'
base-access '.' identifier type-argument-listopt '(' argumentList? ')'
'base' '.' identifier type-argument-listopt '(' argumentList? ')'
And so on.
But it isn't.
I doubt this is really valid C# code. Maybe you saw it in C++?
The following code fails to compile with a syntax error:
public class VisitList<T> : List<T>
{
public VisitList(int n)
: base.VisitList<T>(n)
{
}
}
This works:
public class VisitList<T> : List<T>
{
public VisitList(int n)
: base(n)
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With