-
Notifications
You must be signed in to change notification settings - Fork 89
Primary expressions (ref)
Primary expressions are a grammar category referring to expressions that have a closed structure and are otherwise simple. Primary expressions and plain expressions do not differ at the semantic level.
primary_expr =
Lexical_structure_(ref):literal
| qualified_identifier
| 'this'
| 'base'
| grouping_expr
| member_reference_expr
| tuple_ctor
| indexer_reference_expr
this
expression can only be used within non-static methods and
indicates a reference to the current instance of the class (which posses
this method).
Expression like this.foo
can be shortened to foo
unless it would generate an identifier ambiguity with some variable
being in this lexical scope.
The this
keyword can be also used to call instance constructor from
another constructor.
base
expression can only be used within non-static methods and
indicates a reference to the current instance of the class coerced to
the type of the base class. Calls made on base pointer are non virtual.
The base keyword can be also used to call instance constructor of base class from another constructor.
grouping_expr =
'(' Expressions_(ref):expr ')'
A grouping expression allows to enforce particular syntax decomposition of expression.
member_reference_expr =
primary_expr '.' IDENTIFIER
This expression allows referring to the field or method that the object represented by primary_expr contains.
tuple_ctor =
'(' expr ',' expr { ',' expr } ')'
The type of that tuple is type_1 * ... * type_n where type_1 and the following are types of corresponding expressions.
indexer_reference_expr =
expr '[' expr { ',' expr } ']'
This expression allows to refer to indexed (even by multiple indexes) fields of objects represented by leftmost expr where second (and further) expr are indexes values of the field we want to refer to. expr must refer to object with an indexer defined. This includes arrays, strings, hashtables and other collections.