От: | VladD2 | www.nemerle.org | |
Дата: | 22.12.04 02:09 | ||
Оценка: |
9.2.3 Grammar ambiguities
The productions for simple-name (§14.5.2) and member-access (§14.5.4) can give rise to ambiguities in the
grammar for expressions. [Example: The statement:
F(G<A, B>(7));
could be interpreted as a call to F with two arguments, G < A and B > (7). Alternatively, it could be
interpreted as a call to F with one argument, which is a call to a generic method G with two type arguments
and one regular argument. end example]
If a sequence of tokens can be parsed (in context) as a simple-name (§14.5.2), member-access (§14.5.4), or
pointer-member-access (§25.5.2) ending with a type-argument-list (§26.5.1), the token immediately
following the closing > token is examined. If it is one of
( ) ] : ; , . ? == !=
then the type-argument-list is retained as part of the simple-name, member-access or pointer-member-access
and any other possible parse of the sequence of tokens is discarded. Otherwise, the type-argument-list is not
considered to be part of the simple-name, member-access or pointer-member-access, even if there is no other
possible parse of the sequence of tokens. [Note: These rules are not applied when parsing a type-argument-
list in a namespace-or-type-name (§10.8). end note] [Example: The statement:
F(G<A, B>(7));
will, according to this rule, be interpreted as a call to F with one argument, which is a call to a generic
method G with two type arguments and one regular argument. The statements
F(G<A, B>7); F(G<A, B>>7);
will each be interpreted as a call to F with two arguments. The statement
x = F<A> + y;
will be interpreted as a less-than operater, greater-than operator and unary-plus operator, as if the statement
had been written x = (F < A) > (+y), instead of as a simple-name with a type-argument-list followed
by a binary-plus operator. In the statement
x = y is C<T> + z;
the tokens C<T> are interpreted as a namespace-or-type-name with a type-argument-list. end example]