I am looking into the grammar of C# 5.0 and don't quite understand the use of "base". In the reference manual, there is a notion of "base access" defined as:
base-access:
base . identifier
base [ expression-list ]
Where base
is a keyword, and it appears that this is the only case. However, I encounter C# inputs such as
base.WithAdditionalDiagnostics<TNode>(node, diagnostics);
Can someone point me out which grammar rule this statement refers to? As 'base' appears to be a normal keyword, not contextual, I assume that there should be a specific grammar rule for this case, and base
cannot simply be an identifier.
C is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, and so on.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Quote from wikipedia: "A successor to the programming language B, C was originally developed at Bell Labs by Dennis Ritchie between 1972 and 1973 to construct utilities running on Unix." The creators want that everyone "see" his language. So he named it "C".
I believe it should actually be
base-access:
base . identifier type-argument-list_opt
base [ expression-list ]
... which would make it just like member-access:
member-access:
primary-expression . identifier type-argument-list_opt
predefined-type . identifier type-argument-list_opt
qualified-alias-member . identifier type-argument-list_opt
In other words, in an expression
base.WithAdditionalDiagnostics<TNode>(node, diagnostics);
only
base.WithAdditionalDiagnostics<TNode>
is the base-access part - and the rest is parsed as it would be for other calls such as x.WithAdditionalDiagnostics<TNode>(node, diagnostics)
.
From section 7.6.8 of the C# 5 spec:
At binding-time, base-access expressions of the form
base.I
andbase[E]
are evaluated exactly as if they were written((B)this).I
and((B)this)[E]
, whereB
is the base class of the class or struct in which the construct occurs. Thus,base.I
andbase[E]
correspond tothis.I
andthis[E]
, exceptthis
is viewed as an instance of the base class.
Without the additional type-argument-listopt though, I think your existing expression wouldn't parse.
This is actually specified correctly in the 4th edition of the ECMA-334 specification; I shall raise it as a bug with the C# specification (and make sure it doesn't get broken for the 5th edition).
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