3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Licensed under the terms of the GNU GPL
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004 Novell, Inc
15 // (1) Figure out why error productions dont work. `type-declaration' is a
16 // great spot to put an `error' because you can reproduce it with this input:
19 // Possible optimization:
20 // Run memory profiler with parsing only, and consider dropping
21 // arraylists where not needed. Some pieces can use linked lists.
29 using System.Collections;
34 public class CSharpParser {
35 NamespaceEntry current_namespace;
36 TypeContainer current_container;
37 DeclSpace current_class;
39 IAnonymousHost anonymous_host;
42 /// Current block is used to add statements as we find
47 Delegate current_delegate;
49 GenericMethod current_generic_method;
50 AnonymousMethodExpression current_anonymous_method;
53 /// This is used by the unary_expression code to resolve
54 /// a name against a parameter.
56 Parameters current_local_parameters;
59 /// Using during property parsing to describe the implicit
60 /// value parameter that is passed to the "set" and "get"accesor
61 /// methods (properties and indexers).
63 Expression implicit_value_parameter_type;
64 Parameters indexer_parameters;
67 /// Hack to help create non-typed array initializer
69 public static Expression current_array_type;
70 Expression pushed_current_array_type;
73 /// Used to determine if we are parsing the get/set pair
74 /// of an indexer or a property
78 bool parsing_anonymous_method;
81 /// An out-of-band stack.
83 static Stack oob_stack;
90 static public int yacc_verbose_flag;
92 // Name of the file we are parsing
101 /// Temporary Xml documentation cache.
102 /// For enum types, we need one more temporary store.
105 string enumTypeComment;
107 /// Current attribute target
108 string current_attr_target;
110 /// assembly and module attribute definitions are enabled
111 bool global_attrs_enabled = true;
112 bool has_get, has_set;
113 bool parameter_modifiers_not_allowed;
114 bool params_modifiers_not_allowed;
115 bool arglist_allowed;
120 %token NONE /* This token is never returned by our lexer */
121 %token ERROR // This is used not by the parser, but by the tokenizer.
125 *These are the C# keywords
212 %token QUERY_FIRST_TOKEN
225 %token QUERY_LAST_TOKEN
227 /* C# keywords which are not really keywords */
233 /* C# single character operators/punctuation. */
234 %token OPEN_BRACE "{"
235 %token CLOSE_BRACE "}"
236 %token OPEN_BRACKET "["
237 %token CLOSE_BRACKET "]"
238 %token OPEN_PARENS "("
239 %token CLOSE_PARENS ")"
251 %token OP_GENERICS_LT "<"
253 %token OP_GENERICS_GT ">"
254 %token BITWISE_AND "&"
255 %token BITWISE_OR "|"
262 /* C# multi-character operators. */
263 %token DOUBLE_COLON "::"
266 %token OP_SHIFT_LEFT "<<"
267 %token OP_SHIFT_RIGHT ">>"
274 %token OP_MULT_ASSIGN "*="
275 %token OP_DIV_ASSIGN "/="
276 %token OP_MOD_ASSIGN "%="
277 %token OP_ADD_ASSIGN "+="
278 %token OP_SUB_ASSIGN "-="
279 %token OP_SHIFT_LEFT_ASSIGN "<<="
280 %token OP_SHIFT_RIGHT_ASSIGN ">>="
281 %token OP_AND_ASSIGN "&="
282 %token OP_XOR_ASSIGN "^="
283 %token OP_OR_ASSIGN "|="
285 %token OP_COALESCING "??"
288 %token LITERAL_INTEGER "int literal"
289 %token LITERAL_FLOAT "float literal"
290 %token LITERAL_DOUBLE "double literal"
291 %token LITERAL_DECIMAL "decimal literal"
292 %token LITERAL_CHARACTER "character literal"
293 %token LITERAL_STRING "string literal"
296 %token OPEN_PARENS_LAMBDA
297 %token CLOSE_PARENS_CAST
298 %token CLOSE_PARENS_NO_CAST
299 %token CLOSE_PARENS_OPEN_PARENS
300 %token CLOSE_PARENS_MINUS
301 %token DEFAULT_OPEN_PARENS
302 %token GENERIC_DIMENSION
305 /* Add precedence rules to solve dangling else s/r conflict */
314 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
316 %left STAR DIV PERCENT
317 %right BANG CARRET UMINUS
318 %nonassoc OP_INC OP_DEC
320 %left OPEN_BRACKET OPEN_BRACE
324 %start compilation_unit
328 : outer_declarations opt_EOF
329 | outer_declarations global_attributes opt_EOF
330 | global_attributes opt_EOF
331 | opt_EOF /* allow empty files */
337 Lexer.check_incorrect_doc_comment ();
341 Lexer.check_incorrect_doc_comment ();
347 | outer_declarations outer_declaration
351 : extern_alias_directive
353 | namespace_member_declaration
356 extern_alias_directives
357 : extern_alias_directive
358 | extern_alias_directives extern_alias_directive;
360 extern_alias_directive
361 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
363 LocatedToken lt = (LocatedToken) $2;
366 Report.Error (1003, lt.Location, "'alias' expected");
367 } else if (RootContext.Version == LanguageVersion.ISO_1) {
368 Report.FeatureIsNotAvailable (lt.Location, "external alias");
370 lt = (LocatedToken) $3;
371 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
378 | using_directives using_directive
382 : using_alias_directive
384 if (RootContext.Documentation != null)
385 Lexer.doc_state = XmlCommentState.Allowed;
387 | using_namespace_directive
389 if (RootContext.Documentation != null)
390 Lexer.doc_state = XmlCommentState.Allowed;
394 using_alias_directive
395 : USING IDENTIFIER ASSIGN
396 namespace_or_type_name SEMICOLON
398 LocatedToken lt = (LocatedToken) $2;
399 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
402 CheckIdentifierToken (yyToken, GetLocation ($2));
406 using_namespace_directive
407 : USING namespace_name SEMICOLON
409 current_namespace.Using ((MemberName) $2, (Location) $1);
414 // Strictly speaking, namespaces don't have attributes but
415 // we parse global attributes along with namespace declarations and then
418 namespace_declaration
419 : opt_attributes NAMESPACE namespace_or_type_name
421 MemberName name = (MemberName) $3;
424 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
427 if (name.TypeArguments != null)
428 syntax_error (lexer.Location, "namespace name expected");
430 current_namespace = new NamespaceEntry (
431 current_namespace, file, name.GetName ());
432 current_class = current_namespace.SlaveDeclSpace;
433 current_container = current_class.PartialContainer;
435 namespace_body opt_semicolon
437 current_namespace = current_namespace.Parent;
438 current_class = current_namespace.SlaveDeclSpace;
439 current_container = current_class.PartialContainer;
454 : namespace_or_type_name {
455 MemberName name = (MemberName) $1;
457 if (name.TypeArguments != null)
458 syntax_error (lexer.Location, "namespace name expected");
467 if (RootContext.Documentation != null)
468 Lexer.doc_state = XmlCommentState.Allowed;
474 : opt_extern_alias_directives
476 opt_namespace_member_declarations
480 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
483 | opt_extern_alias_directives
485 opt_namespace_member_declarations
488 Report.Error (1513, lexer.Location, "} expected");
497 opt_extern_alias_directives
499 | extern_alias_directives
502 opt_namespace_member_declarations
504 | namespace_member_declarations
507 namespace_member_declarations
508 : namespace_member_declaration
509 | namespace_member_declarations namespace_member_declaration
512 namespace_member_declaration
516 DeclSpace ds = (DeclSpace)$1;
518 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
519 Report.Error (1527, ds.Location,
520 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
523 current_namespace.DeclarationFound = true;
525 | namespace_declaration {
526 current_namespace.DeclarationFound = true;
529 | field_declaration {
530 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
532 | method_declaration {
533 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
540 | interface_declaration
542 | delegate_declaration
544 // Enable this when we have handled all errors, because this acts as a generic fallback
547 // Console.WriteLine ("Token=" + yyToken);
548 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
560 Attributes attrs = (Attributes)$1;
561 if (global_attrs_enabled) {
562 CodeGen.Assembly.AddAttributes (attrs.Attrs);
564 foreach (Attribute a in attrs.Attrs) {
565 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
576 global_attrs_enabled = false;
581 global_attrs_enabled = false;
590 if (current_attr_target != String.Empty) {
591 ArrayList sect = (ArrayList) $1;
593 if (global_attrs_enabled) {
594 if (current_attr_target == "module") {
595 CodeGen.Module.AddAttributes (sect);
597 } else if (current_attr_target != null && current_attr_target.Length > 0) {
598 CodeGen.Assembly.AddAttributes (sect);
601 $$ = new Attributes (sect);
604 if (RootContext.Documentation != null) {
605 Lexer.check_incorrect_doc_comment ();
607 XmlCommentState.Allowed;
611 $$ = new Attributes (sect);
616 current_attr_target = null;
618 | attribute_sections attribute_section
620 if (current_attr_target != String.Empty) {
621 Attributes attrs = $1 as Attributes;
622 ArrayList sect = (ArrayList) $2;
624 if (global_attrs_enabled) {
625 if (current_attr_target == "module") {
626 CodeGen.Module.AddAttributes (sect);
628 } else if (current_attr_target == "assembly") {
629 CodeGen.Assembly.AddAttributes (sect);
633 attrs = new Attributes (sect);
635 attrs.AddAttributes (sect);
639 attrs = new Attributes (sect);
641 attrs.AddAttributes (sect);
647 current_attr_target = null;
652 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
656 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
662 attribute_target_specifier
663 : attribute_target COLON
665 current_attr_target = (string)$1;
673 LocatedToken lt = (LocatedToken) $1;
674 $$ = CheckAttributeTarget (lt.Value, lt.Location);
676 | EVENT { $$ = "event"; }
677 | RETURN { $$ = "return"; }
680 string name = yyNames [yyToken].ToLower ();
681 $$ = CheckAttributeTarget (name, GetLocation ($1));
688 ArrayList attrs = new ArrayList (4);
694 | attribute_list COMMA attribute
696 ArrayList attrs = (ArrayList) $1;
704 : attribute_name opt_attribute_arguments
706 MemberName mname = (MemberName) $1;
707 if (mname.IsGeneric) {
708 Report.Error (404, lexer.Location,
709 "'<' unexpected: attributes cannot be generic");
712 object [] arguments = (object []) $2;
713 MemberName left = mname.Left;
714 string identifier = mname.Name;
716 Expression left_expr = left == null ? null : left.GetTypeExpression ();
718 if (current_attr_target == String.Empty)
720 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
721 // FIXME: supply "nameEscaped" parameter here.
722 $$ = new GlobalAttribute (current_namespace, current_attr_target,
723 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
725 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
730 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
733 opt_attribute_arguments
734 : /* empty */ { $$ = null; }
735 | OPEN_PARENS attribute_arguments CLOSE_PARENS
743 : opt_positional_argument_list
748 $$ = new object [] { $1, null };
751 | positional_argument_list COMMA named_argument_list
753 $$ = new object[] { $1, $3 };
755 | named_argument_list
757 $$ = new object [] { null, $1 };
762 opt_positional_argument_list
763 : /* empty */ { $$ = null; }
764 | positional_argument_list
767 positional_argument_list
770 ArrayList args = new ArrayList (4);
771 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
775 | positional_argument_list COMMA expression
777 ArrayList args = (ArrayList) $1;
778 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
787 ArrayList args = new ArrayList (4);
792 | named_argument_list COMMA named_argument
794 ArrayList args = (ArrayList) $1;
799 | named_argument_list COMMA expression
801 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
807 : IDENTIFIER ASSIGN expression
809 // FIXME: keep location
810 $$ = new DictionaryEntry (
811 ((LocatedToken) $1).Value,
812 new Argument ((Expression) $3, Argument.AType.Expression));
818 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
821 opt_class_member_declarations
823 | class_member_declarations
826 class_member_declarations
827 : class_member_declaration
828 | class_member_declarations
829 class_member_declaration
832 class_member_declaration
833 : constant_declaration // done
834 | field_declaration // done
835 | method_declaration // done
836 | property_declaration // done
837 | event_declaration // done
838 | indexer_declaration // done
839 | operator_declaration // done
840 | constructor_declaration // done
841 | destructor_declaration // done
851 lexer.ConstraintsParsing = true;
855 MemberName name = MakeName ((MemberName) $6);
856 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
859 opt_type_parameter_constraints_clauses
861 lexer.ConstraintsParsing = false;
863 current_class.SetParameterInfo ((ArrayList) $9);
865 if (RootContext.Documentation != null)
866 current_container.DocComment = Lexer.consume_doc_comment ();
870 if (RootContext.Documentation != null)
871 Lexer.doc_state = XmlCommentState.Allowed;
875 $$ = pop_current_class ();
877 | opt_attributes opt_modifiers opt_partial STRUCT error {
878 CheckIdentifierToken (yyToken, GetLocation ($5));
885 if (RootContext.Documentation != null)
886 Lexer.doc_state = XmlCommentState.Allowed;
888 opt_struct_member_declarations CLOSE_BRACE
891 opt_struct_member_declarations
893 | struct_member_declarations
896 struct_member_declarations
897 : struct_member_declaration
898 | struct_member_declarations struct_member_declaration
901 struct_member_declaration
902 : constant_declaration
905 | property_declaration
907 | indexer_declaration
908 | operator_declaration
909 | constructor_declaration
913 * This is only included so we can flag error 575:
914 * destructors only allowed on class types
916 | destructor_declaration
927 int modflags = (int) $2;
928 foreach (VariableDeclaration constant in (ArrayList) $5){
929 Location l = constant.Location;
930 if ((modflags & Modifiers.STATIC) != 0) {
931 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
935 Const c = new Const (
936 current_class, (Expression) $4, (string) constant.identifier,
937 (Expression) constant.expression_or_array_initializer, modflags,
940 if (RootContext.Documentation != null) {
941 c.DocComment = Lexer.consume_doc_comment ();
942 Lexer.doc_state = XmlCommentState.Allowed;
944 current_container.AddConstant (c);
950 : constant_declarator
952 ArrayList constants = new ArrayList (4);
957 | constant_declarators COMMA constant_declarator
960 ArrayList constants = (ArrayList) $1;
967 : IDENTIFIER ASSIGN constant_expression
969 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
973 // A const field requires a value to be provided
974 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
986 Expression type = (Expression) $3;
989 current_array_type = null;
991 foreach (VariableDeclaration var in (ArrayList) $4){
992 Field field = new Field (current_class, type, mod, var.identifier,
993 (Attributes) $1, var.Location);
995 field.Initializer = var.expression_or_array_initializer;
997 if (RootContext.Documentation != null) {
998 field.DocComment = Lexer.consume_doc_comment ();
999 Lexer.doc_state = XmlCommentState.Allowed;
1001 current_container.AddField (field);
1002 $$ = field; // FIXME: might be better if it points to the top item
1009 fixed_variable_declarators
1012 Expression type = (Expression) $4;
1015 current_array_type = null;
1017 foreach (VariableDeclaration var in (ArrayList) $5) {
1018 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1019 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1021 if (RootContext.Documentation != null) {
1022 field.DocComment = Lexer.consume_doc_comment ();
1023 Lexer.doc_state = XmlCommentState.Allowed;
1025 current_container.AddField (field);
1026 $$ = field; // FIXME: might be better if it points to the top item
1035 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1040 variable_declarators
1042 current_array_type = null;
1043 Report.Error (670, (Location) $3, "Fields cannot have void type");
1047 fixed_variable_declarators
1048 : fixed_variable_declarator
1050 ArrayList decl = new ArrayList (2);
1054 | fixed_variable_declarators COMMA fixed_variable_declarator
1056 ArrayList decls = (ArrayList) $1;
1062 fixed_variable_declarator
1063 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1065 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1067 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1069 Report.Error (443, lexer.Location, "Value or constant expected");
1070 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1074 variable_declarators
1075 : variable_declarator
1077 ArrayList decl = new ArrayList (4);
1082 | variable_declarators COMMA variable_declarator
1084 ArrayList decls = (ArrayList) $1;
1091 : IDENTIFIER ASSIGN variable_initializer
1093 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1097 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1099 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1101 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1102 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1107 variable_initializer
1116 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1118 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1122 $$ = new ArglistAccess ((Location) $1);
1126 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1133 anonymous_host = (IAnonymousHost) $1;
1134 if (RootContext.Documentation != null)
1135 Lexer.doc_state = XmlCommentState.NotAllowed;
1139 Method method = (Method) $1;
1140 method.Block = (ToplevelBlock) $3;
1141 current_container.AddMethod (method);
1143 anonymous_host = null;
1144 current_generic_method = null;
1145 current_local_parameters = null;
1147 if (RootContext.Documentation != null)
1148 Lexer.doc_state = XmlCommentState.Allowed;
1161 Report.Error (1585, lexer.Location,
1162 "Member modifier `{0}' must precede the member type and name",
1163 Modifiers.Name (i));
1172 // This rule is used to handle the cases where OPEN_PARENS_LAMBDA
1173 // is returned (type followed by an identifier), these are the
1174 // declarations (methods, overloads, constructors, etc) and a handful
1175 // of expressions ("using", "fixed") or "catch".
1179 | OPEN_PARENS_LAMBDA
1188 arglist_allowed = true;
1190 opt_formal_parameter_list CLOSE_PARENS
1192 lexer.ConstraintsParsing = true;
1194 opt_type_parameter_constraints_clauses
1196 lexer.ConstraintsParsing = false;
1197 arglist_allowed = false;
1198 MemberName name = (MemberName) $4;
1199 current_local_parameters = (Parameters) $7;
1201 if ($10 != null && name.TypeArguments == null)
1202 Report.Error (80, lexer.Location,
1203 "Constraints are not allowed on non-generic declarations");
1207 GenericMethod generic = null;
1208 if (name.TypeArguments != null) {
1209 generic = new GenericMethod (current_namespace, current_class, name,
1210 (Expression) $3, current_local_parameters);
1212 generic.SetParameterInfo ((ArrayList) $10);
1215 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1216 name, current_local_parameters, (Attributes) $1);
1218 anonymous_host = method;
1219 current_generic_method = generic;
1221 if (RootContext.Documentation != null)
1222 method.DocComment = Lexer.consume_doc_comment ();
1231 arglist_allowed = true;
1233 opt_formal_parameter_list CLOSE_PARENS
1235 lexer.ConstraintsParsing = true;
1237 opt_type_parameter_constraints_clauses
1239 lexer.ConstraintsParsing = false;
1240 arglist_allowed = false;
1242 MemberName name = (MemberName) $4;
1243 current_local_parameters = (Parameters) $7;
1245 if ($10 != null && name.TypeArguments == null)
1246 Report.Error (80, lexer.Location,
1247 "Constraints are not allowed on non-generic declarations");
1250 GenericMethod generic = null;
1251 if (name.TypeArguments != null) {
1252 generic = new GenericMethod (current_namespace, current_class, name,
1253 TypeManager.system_void_expr, current_local_parameters);
1255 generic.SetParameterInfo ((ArrayList) $10);
1258 method = new Method (current_class, generic, TypeManager.system_void_expr,
1259 (int) $2, false, name, current_local_parameters, (Attributes) $1);
1261 anonymous_host = method;
1262 current_generic_method = generic;
1264 if (RootContext.Documentation != null)
1265 method.DocComment = Lexer.consume_doc_comment ();
1273 open_parens opt_formal_parameter_list CLOSE_PARENS
1275 lexer.ConstraintsParsing = true;
1277 opt_type_parameter_constraints_clauses
1279 lexer.ConstraintsParsing = false;
1281 MemberName name = (MemberName) $5;
1282 current_local_parameters = (Parameters) $7;
1284 if ($9 != null && name.TypeArguments == null)
1285 Report.Error (80, lexer.Location,
1286 "Constraints are not allowed on non-generic declarations");
1289 GenericMethod generic = null;
1290 if (name.TypeArguments != null) {
1291 generic = new GenericMethod (current_namespace, current_class, name,
1292 TypeManager.system_void_expr, current_local_parameters);
1294 generic.SetParameterInfo ((ArrayList) $10);
1297 int modifiers = (int) $2;
1300 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1301 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1303 if ((modifiers & invalid_partial_mod) != 0) {
1304 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1305 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1306 modifiers &= ~invalid_partial_mod;
1309 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1310 Report.Error (751, name.Location, "A partial method must be declared within a " +
1311 "partial class or partial struct");
1314 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1316 method = new Method (current_class, generic, TypeManager.system_void_expr,
1317 modifiers, false, name, current_local_parameters, (Attributes) $1);
1319 anonymous_host = method;
1320 current_generic_method = generic;
1322 if (RootContext.Documentation != null)
1323 method.DocComment = Lexer.consume_doc_comment ();
1330 modifiers member_name open_parens opt_formal_parameter_list CLOSE_PARENS
1332 MemberName name = (MemberName) $5;
1333 Report.Error (1585, name.Location,
1334 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1336 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1337 0, false, name, (Parameters) $7, (Attributes) $1);
1339 current_local_parameters = (Parameters) $7;
1341 if (RootContext.Documentation != null)
1342 method.DocComment = Lexer.consume_doc_comment ();
1350 | SEMICOLON { $$ = null; }
1353 opt_formal_parameter_list
1354 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1355 | formal_parameter_list
1358 opt_parameter_list_no_mod
1359 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1362 parameter_modifiers_not_allowed = true;
1364 formal_parameter_list
1366 parameter_modifiers_not_allowed = false;
1371 formal_parameter_list
1374 ArrayList pars_list = (ArrayList) $1;
1376 Parameter [] pars = new Parameter [pars_list.Count];
1377 pars_list.CopyTo (pars);
1379 $$ = new Parameters (pars);
1381 | fixed_parameters COMMA parameter_array
1383 ArrayList pars_list = (ArrayList) $1;
1386 Parameter [] pars = new Parameter [pars_list.Count];
1387 pars_list.CopyTo (pars);
1389 $$ = new Parameters (pars);
1391 | fixed_parameters COMMA arglist_modifier
1393 ArrayList pars_list = (ArrayList) $1;
1394 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1396 Parameter [] pars = new Parameter [pars_list.Count];
1397 pars_list.CopyTo (pars);
1399 $$ = new Parameters (pars, true);
1401 | parameter_array COMMA error
1404 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1407 | fixed_parameters COMMA parameter_array COMMA error
1410 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1413 | arglist_modifier COMMA error
1415 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1418 | fixed_parameters COMMA ARGLIST COMMA error
1420 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1425 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1429 $$ = new Parameters (new Parameter[0], true);
1436 ArrayList pars = new ArrayList (4);
1441 | fixed_parameters COMMA fixed_parameter
1443 ArrayList pars = (ArrayList) $1;
1444 Parameter p = (Parameter)$3;
1446 if ((p.modFlags & Parameter.Modifier.This) != 0)
1447 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1456 opt_parameter_modifier
1460 LocatedToken lt = (LocatedToken) $4;
1461 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1464 opt_parameter_modifier
1466 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1468 LocatedToken lt = (LocatedToken) $4;
1469 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1473 opt_parameter_modifier
1476 Report.Error (1001, GetLocation ($3), "Identifier expected");
1480 opt_parameter_modifier
1483 CheckIdentifierToken (yyToken, GetLocation ($4));
1487 opt_parameter_modifier
1493 LocatedToken lt = (LocatedToken) $4;
1494 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1499 opt_parameter_modifier
1500 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1501 | parameter_modifiers
1505 : parameter_modifier
1509 | parameter_modifiers parameter_modifier
1511 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1512 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1513 if (((Parameter.Modifier)$1 & p2) == p2) {
1514 Error_DuplicateParameterModifier (lexer.Location, p2);
1516 switch (mod & ~Parameter.Modifier.This) {
1517 case Parameter.Modifier.REF:
1518 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1520 case Parameter.Modifier.OUT:
1521 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1524 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1535 if (parameter_modifiers_not_allowed)
1536 Error_ParameterModifierNotValid ("ref", (Location)$1);
1538 $$ = Parameter.Modifier.REF;
1542 if (parameter_modifiers_not_allowed)
1543 Error_ParameterModifierNotValid ("out", (Location)$1);
1545 $$ = Parameter.Modifier.OUT;
1549 if (parameter_modifiers_not_allowed)
1550 Error_ParameterModifierNotValid ("this", (Location)$1);
1552 if (RootContext.Version <= LanguageVersion.ISO_2)
1553 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1555 $$ = Parameter.Modifier.This;
1560 : opt_attributes params_modifier type IDENTIFIER
1562 LocatedToken lt = (LocatedToken) $4;
1563 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1565 | opt_attributes params_modifier type error {
1566 CheckIdentifierToken (yyToken, GetLocation ($4));
1574 if (params_modifiers_not_allowed)
1575 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1577 | PARAMS parameter_modifier
1579 Parameter.Modifier mod = (Parameter.Modifier)$2;
1580 if ((mod & Parameter.Modifier.This) != 0) {
1581 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1583 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1586 | PARAMS params_modifier
1588 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1595 if (!arglist_allowed)
1596 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1600 property_declaration
1604 namespace_or_type_name
1606 if (RootContext.Documentation != null)
1607 tmpComment = Lexer.consume_doc_comment ();
1611 implicit_value_parameter_type = (Expression) $3;
1613 lexer.PropertyParsing = true;
1615 accessor_declarations
1617 lexer.PropertyParsing = false;
1618 has_get = has_set = false;
1626 Accessors accessors = (Accessors) $8;
1627 Accessor get_block = accessors.get_or_add;
1628 Accessor set_block = accessors.set_or_remove;
1630 MemberName name = (MemberName) $4;
1632 if (name.TypeArguments != null)
1633 syntax_error (lexer.Location, "a property can't have type arguments");
1635 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1636 name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse, current_block);
1638 current_container.AddProperty (prop);
1639 implicit_value_parameter_type = null;
1641 if (RootContext.Documentation != null)
1642 prop.DocComment = ConsumeStoredComment ();
1647 accessor_declarations
1648 : get_accessor_declaration
1650 $$ = new Accessors ((Accessor) $1, null);
1652 | get_accessor_declaration accessor_declarations
1654 Accessors accessors = (Accessors) $2;
1655 accessors.get_or_add = (Accessor) $1;
1658 | set_accessor_declaration
1660 $$ = new Accessors (null, (Accessor) $1);
1662 | set_accessor_declaration accessor_declarations
1664 Accessors accessors = (Accessors) $2;
1665 accessors.set_or_remove = (Accessor) $1;
1666 accessors.declared_in_reverse = true;
1671 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1676 get_accessor_declaration
1677 : opt_attributes opt_modifiers GET
1679 // If this is not the case, then current_local_parameters has already
1680 // been set in indexer_declaration
1681 if (parsing_indexer == false)
1682 current_local_parameters = null;
1684 current_local_parameters = indexer_parameters;
1685 lexer.PropertyParsing = false;
1687 anonymous_host = SimpleAnonymousHost.GetSimple ();
1692 Report.Error (1007, (Location) $3, "Property accessor already defined");
1695 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1697 current_local_parameters = null;
1698 lexer.PropertyParsing = true;
1700 SimpleAnonymousHost.Simple.Propagate (accessor);
1701 anonymous_host = null;
1703 if (RootContext.Documentation != null)
1704 if (Lexer.doc_state == XmlCommentState.Error)
1705 Lexer.doc_state = XmlCommentState.NotAllowed;
1711 set_accessor_declaration
1712 : opt_attributes opt_modifiers SET
1715 Parameter implicit_value_parameter = new Parameter (
1716 implicit_value_parameter_type, "value",
1717 Parameter.Modifier.NONE, null, (Location) $3);
1719 if (parsing_indexer == false) {
1720 args = new Parameter [1];
1721 args [0] = implicit_value_parameter;
1722 current_local_parameters = new Parameters (args);
1724 Parameter [] fpars = indexer_parameters.FixedParameters;
1727 int count = fpars.Length;
1729 args = new Parameter [count + 1];
1730 fpars.CopyTo (args, 0);
1731 args [count] = implicit_value_parameter;
1734 current_local_parameters = new Parameters (
1738 lexer.PropertyParsing = false;
1740 anonymous_host = SimpleAnonymousHost.GetSimple ();
1745 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1748 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1750 current_local_parameters = null;
1751 lexer.PropertyParsing = true;
1753 SimpleAnonymousHost.Simple.Propagate (accessor);
1754 anonymous_host = null;
1756 if (RootContext.Documentation != null
1757 && Lexer.doc_state == XmlCommentState.Error)
1758 Lexer.doc_state = XmlCommentState.NotAllowed;
1766 | SEMICOLON { $$ = null; }
1769 interface_declaration
1775 lexer.ConstraintsParsing = true;
1779 MemberName name = MakeName ((MemberName) $6);
1780 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1783 opt_type_parameter_constraints_clauses
1785 lexer.ConstraintsParsing = false;
1787 current_class.SetParameterInfo ((ArrayList) $9);
1789 if (RootContext.Documentation != null) {
1790 current_container.DocComment = Lexer.consume_doc_comment ();
1791 Lexer.doc_state = XmlCommentState.Allowed;
1796 if (RootContext.Documentation != null)
1797 Lexer.doc_state = XmlCommentState.Allowed;
1801 $$ = pop_current_class ();
1803 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1804 CheckIdentifierToken (yyToken, GetLocation ($5));
1810 opt_interface_member_declarations
1814 opt_interface_member_declarations
1816 | interface_member_declarations
1819 interface_member_declarations
1820 : interface_member_declaration
1821 | interface_member_declarations interface_member_declaration
1824 interface_member_declaration
1825 : interface_method_declaration
1830 Method m = (Method) $1;
1832 if (m.IsExplicitImpl)
1833 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1834 m.GetSignatureForError ());
1836 current_container.AddMethod (m);
1838 if (RootContext.Documentation != null)
1839 Lexer.doc_state = XmlCommentState.Allowed;
1841 | interface_property_declaration
1846 Property p = (Property) $1;
1848 if (p.IsExplicitImpl)
1849 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1850 p.GetSignatureForError ());
1852 current_container.AddProperty (p);
1854 if (RootContext.Documentation != null)
1855 Lexer.doc_state = XmlCommentState.Allowed;
1857 | interface_event_declaration
1860 Event e = (Event) $1;
1862 if (e.IsExplicitImpl)
1863 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1864 e.GetSignatureForError ());
1866 current_container.AddEvent (e);
1869 if (RootContext.Documentation != null)
1870 Lexer.doc_state = XmlCommentState.Allowed;
1872 | interface_indexer_declaration
1877 Indexer i = (Indexer) $1;
1879 if (i.IsExplicitImpl)
1880 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1881 i.GetSignatureForError ());
1883 current_container.AddIndexer (i);
1885 if (RootContext.Documentation != null)
1886 Lexer.doc_state = XmlCommentState.Allowed;
1888 | delegate_declaration
1891 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1892 ((MemberCore)$1).GetSignatureForError ());
1898 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1899 ((MemberCore)$1).GetSignatureForError ());
1902 | struct_declaration
1905 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1906 ((MemberCore)$1).GetSignatureForError ());
1912 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1913 ((MemberCore)$1).GetSignatureForError ());
1916 | interface_declaration
1919 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1920 ((MemberCore)$1).GetSignatureForError ());
1923 | constant_declaration
1925 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1933 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1938 interface_method_declaration_body
1941 Report.Error (531, (Location)$1,
1942 "`{0}.{1}{2}': interface members cannot have a definition",
1943 current_class.GetSignatureForError (),
1944 ((MemberName) $-0).GetSignatureForError (),
1945 ((Parameters)$-4).GetSignatureForError ());
1947 lexer.ConstraintsParsing = false;
1949 opt_statement_list CLOSE_BRACE
1956 interface_method_declaration
1957 : opt_attributes opt_new type namespace_or_type_name
1958 open_parens opt_formal_parameter_list CLOSE_PARENS
1960 lexer.ConstraintsParsing = true;
1962 opt_type_parameter_constraints_clauses
1964 // Refer to the name as $-1 in interface_method_declaration_body
1967 interface_method_declaration_body
1969 lexer.ConstraintsParsing = false;
1971 MemberName name = (MemberName) $4;
1973 if ($9 != null && name.TypeArguments == null)
1974 Report.Error (80, lexer.Location,
1975 "Constraints are not allowed on non-generic declarations");
1977 GenericMethod generic = null;
1978 if (name.TypeArguments != null) {
1979 generic = new GenericMethod (current_namespace, current_class, name,
1980 (Expression) $3, (Parameters) $6);
1982 generic.SetParameterInfo ((ArrayList) $9);
1985 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1986 (Parameters) $6, (Attributes) $1);
1987 if (RootContext.Documentation != null)
1988 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1990 | opt_attributes opt_new VOID namespace_or_type_name
1991 open_parens opt_formal_parameter_list CLOSE_PARENS
1993 lexer.ConstraintsParsing = true;
1995 opt_type_parameter_constraints_clauses
1999 interface_method_declaration_body
2001 lexer.ConstraintsParsing = false;
2003 MemberName name = (MemberName) $4;
2005 if ($9 != null && name.TypeArguments == null)
2006 Report.Error (80, lexer.Location,
2007 "Constraints are not allowed on non-generic declarations");
2009 GenericMethod generic = null;
2010 if (name.TypeArguments != null) {
2011 generic = new GenericMethod (current_namespace, current_class, name,
2012 TypeManager.system_void_expr, (Parameters) $6);
2014 generic.SetParameterInfo ((ArrayList) $9);
2017 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
2018 true, name, (Parameters) $6, (Attributes) $1);
2019 if (RootContext.Documentation != null)
2020 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
2024 interface_property_declaration
2030 lexer.PropertyParsing = true;
2031 implicit_value_parameter_type = (Expression)$3;
2033 accessor_declarations
2035 has_get = has_set = false;
2036 lexer.PropertyParsing = false;
2037 implicit_value_parameter_type = null;
2041 LocatedToken lt = (LocatedToken) $4;
2042 MemberName name = new MemberName (lt.Value, lt.Location);
2044 if ($3 == TypeManager.system_void_expr) {
2045 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
2051 p = new Property (current_class, (Expression) $3, (int) $2, true,
2052 name, (Attributes) $1,
2055 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
2059 Accessors accessor = (Accessors) $7;
2060 p = new Property (current_class, (Expression) $3, (int) $2, true,
2061 name, (Attributes) $1,
2062 accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
2064 if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
2065 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
2070 if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
2071 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
2076 if (RootContext.Documentation != null)
2077 p.DocComment = Lexer.consume_doc_comment ();
2084 CheckIdentifierToken (yyToken, GetLocation ($4));
2090 interface_event_declaration
2091 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
2093 LocatedToken lt = (LocatedToken) $5;
2094 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
2095 new MemberName (lt.Value, lt.Location),
2097 if (RootContext.Documentation != null)
2098 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
2100 | opt_attributes opt_new EVENT type error {
2101 CheckIdentifierToken (yyToken, GetLocation ($5));
2104 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
2105 LocatedToken lt = (LocatedToken) $5;
2106 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
2109 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
2111 implicit_value_parameter_type = (Expression) $4;
2112 lexer.EventParsing = true;
2114 event_accessor_declarations
2116 lexer.EventParsing = false;
2117 implicit_value_parameter_type = null;
2120 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2125 interface_indexer_declaration
2126 : opt_attributes opt_new type THIS
2127 OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2130 lexer.PropertyParsing = true;
2131 implicit_value_parameter_type = (Expression)$3;
2133 accessor_declarations
2135 has_get = has_set = false;
2136 lexer.PropertyParsing = false;
2137 implicit_value_parameter_type = null;
2143 i = new Indexer (current_class, (Expression) $3,
2144 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2145 (int) $2, true, (Parameters) $6, (Attributes) $1,
2148 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
2152 Accessors accessors = (Accessors) $10;
2153 i = new Indexer (current_class, (Expression) $3,
2154 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2155 (int) $2, true, (Parameters) $6, (Attributes) $1,
2156 accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
2158 if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
2159 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
2164 if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
2165 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
2170 if (RootContext.Documentation != null)
2171 i.DocComment = ConsumeStoredComment ();
2177 operator_declaration
2178 : opt_attributes opt_modifiers operator_declarator
2180 anonymous_host = SimpleAnonymousHost.GetSimple ();
2187 OperatorDeclaration decl = (OperatorDeclaration) $3;
2188 Operator op = new Operator (
2189 current_class, decl.optype, decl.ret_type, (int) $2,
2190 current_local_parameters,
2191 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2193 if (RootContext.Documentation != null) {
2194 op.DocComment = tmpComment;
2195 Lexer.doc_state = XmlCommentState.Allowed;
2198 SimpleAnonymousHost.Simple.Propagate (op);
2199 anonymous_host = null;
2201 // Note again, checking is done in semantic analysis
2202 current_container.AddOperator (op);
2204 current_local_parameters = null;
2210 | SEMICOLON { $$ = null; }
2214 : type OPERATOR overloadable_operator open_parens
2216 params_modifiers_not_allowed = true;
2218 opt_parameter_list_no_mod CLOSE_PARENS
2220 params_modifiers_not_allowed = false;
2222 Location loc = (Location) $2;
2223 Operator.OpType op = (Operator.OpType) $3;
2224 current_local_parameters = (Parameters)$6;
2226 int p_count = current_local_parameters.Count;
2228 if (op == Operator.OpType.Addition)
2229 op = Operator.OpType.UnaryPlus;
2230 else if (op == Operator.OpType.Subtraction)
2231 op = Operator.OpType.UnaryNegation;
2234 if (IsUnaryOperator (op)) {
2236 Report.Error (1020, loc, "Overloadable binary operator expected");
2237 } else if (p_count != 1) {
2238 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2239 Operator.GetName (op));
2243 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2244 Operator.GetName (op));
2245 } else if (p_count != 2) {
2246 Report.Error (1019, loc, "Overloadable unary operator expected");
2250 if (RootContext.Documentation != null) {
2251 tmpComment = Lexer.consume_doc_comment ();
2252 Lexer.doc_state = XmlCommentState.NotAllowed;
2255 $$ = new OperatorDeclaration (op, (Expression) $1, loc);
2257 | conversion_operator_declarator
2260 overloadable_operator
2262 : BANG { $$ = Operator.OpType.LogicalNot; }
2263 | TILDE { $$ = Operator.OpType.OnesComplement; }
2264 | OP_INC { $$ = Operator.OpType.Increment; }
2265 | OP_DEC { $$ = Operator.OpType.Decrement; }
2266 | TRUE { $$ = Operator.OpType.True; }
2267 | FALSE { $$ = Operator.OpType.False; }
2268 // Unary and binary:
2269 | PLUS { $$ = Operator.OpType.Addition; }
2270 | MINUS { $$ = Operator.OpType.Subtraction; }
2272 | STAR { $$ = Operator.OpType.Multiply; }
2273 | DIV { $$ = Operator.OpType.Division; }
2274 | PERCENT { $$ = Operator.OpType.Modulus; }
2275 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2276 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2277 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2278 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2279 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2280 | OP_EQ { $$ = Operator.OpType.Equality; }
2281 | OP_NE { $$ = Operator.OpType.Inequality; }
2282 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2283 | OP_LT { $$ = Operator.OpType.LessThan; }
2284 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2285 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2288 conversion_operator_declarator
2289 : IMPLICIT OPERATOR type open_parens
2291 params_modifiers_not_allowed = true;
2293 opt_parameter_list_no_mod CLOSE_PARENS
2295 params_modifiers_not_allowed = false;
2297 Location loc = (Location) $2;
2298 current_local_parameters = (Parameters)$6;
2300 if (RootContext.Documentation != null) {
2301 tmpComment = Lexer.consume_doc_comment ();
2302 Lexer.doc_state = XmlCommentState.NotAllowed;
2305 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, loc);
2307 | EXPLICIT OPERATOR type open_parens
2309 params_modifiers_not_allowed = true;
2311 opt_parameter_list_no_mod CLOSE_PARENS
2313 params_modifiers_not_allowed = false;
2315 Location loc = (Location) $2;
2316 current_local_parameters = (Parameters)$6;
2318 if (RootContext.Documentation != null) {
2319 tmpComment = Lexer.consume_doc_comment ();
2320 Lexer.doc_state = XmlCommentState.NotAllowed;
2323 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, loc);
2327 syntax_error ((Location) $1, "'operator' expected");
2331 syntax_error ((Location) $1, "'operator' expected");
2335 constructor_declaration
2338 constructor_declarator
2341 Constructor c = (Constructor) $3;
2342 c.Block = (ToplevelBlock) $4;
2343 c.OptAttributes = (Attributes) $1;
2344 int yield_method = c.ModFlags & Modifiers.METHOD_YIELDS;
2345 c.ModFlags = (int) $2;
2347 if (RootContext.Documentation != null)
2348 c.DocComment = ConsumeStoredComment ();
2350 if (c.Name == current_container.Basename){
2351 if ((c.ModFlags & Modifiers.STATIC) != 0){
2352 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2353 Report.Error (515, c.Location,
2354 "`{0}': access modifiers are not allowed on static constructors",
2355 c.GetSignatureForError ());
2358 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2360 if (c.Initializer != null){
2361 Report.Error (514, c.Location,
2362 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2363 c.GetSignatureForError ());
2366 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2369 // We let another layer check the validity of the constructor.
2370 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2373 c.ModFlags |= yield_method;
2374 current_container.AddConstructor (c);
2376 current_local_parameters = null;
2377 if (RootContext.Documentation != null)
2378 Lexer.doc_state = XmlCommentState.Allowed;
2382 constructor_declarator
2383 : constructor_header
2387 | constructor_header constructor_initializer
2389 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2397 if (RootContext.Documentation != null) {
2398 tmpComment = Lexer.consume_doc_comment ();
2399 Lexer.doc_state = XmlCommentState.Allowed;
2402 open_parens opt_formal_parameter_list CLOSE_PARENS
2404 LocatedToken lt = (LocatedToken) $1;
2405 current_local_parameters = (Parameters) $4;
2406 current_block = new ToplevelBlock (null, current_local_parameters, null, lt.Location);
2408 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2411 anonymous_host = (IAnonymousHost) $$;
2417 | SEMICOLON { current_block = null; $$ = null; }
2420 constructor_initializer
2421 : COLON BASE open_parens opt_argument_list CLOSE_PARENS
2423 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2425 | COLON THIS open_parens opt_argument_list CLOSE_PARENS
2427 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2430 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2436 : /* EMPTY */ { $$ = 0; }
2437 | UNSAFE { $$ = Modifiers.UNSAFE; }
2438 | EXTERN { $$ = Modifiers.EXTERN; }
2441 destructor_declaration
2442 : opt_attributes opt_finalizer TILDE
2444 if (RootContext.Documentation != null) {
2445 tmpComment = Lexer.consume_doc_comment ();
2446 Lexer.doc_state = XmlCommentState.NotAllowed;
2449 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2451 LocatedToken lt = (LocatedToken) $5;
2452 if (lt.Value != current_container.MemberName.Name){
2453 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2454 } else if (current_container.Kind != Kind.Class){
2455 Report.Error (575, lt.Location, "Only class types can contain destructor");
2457 Location l = lt.Location;
2460 if (!RootContext.StdLib && current_container.Name == "System.Object")
2461 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2463 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2465 Method d = new Destructor (
2466 current_class, TypeManager.system_void_expr, m, "Finalize",
2467 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2468 if (RootContext.Documentation != null)
2469 d.DocComment = ConsumeStoredComment ();
2471 d.Block = (ToplevelBlock) $8;
2472 current_container.AddMethod (d);
2480 EVENT type variable_declarators SEMICOLON
2482 current_array_type = null;
2483 foreach (VariableDeclaration var in (ArrayList) $5) {
2485 MemberName name = new MemberName (var.identifier,
2488 EventField e = new EventField (
2489 current_class, (Expression) $4, (int) $2, false, name,
2492 e.Initializer = var.expression_or_array_initializer;
2494 current_container.AddEvent (e);
2496 if (RootContext.Documentation != null) {
2497 e.DocComment = Lexer.consume_doc_comment ();
2498 Lexer.doc_state = XmlCommentState.Allowed;
2504 EVENT type namespace_or_type_name
2507 implicit_value_parameter_type = (Expression) $4;
2508 lexer.EventParsing = true;
2510 event_accessor_declarations
2512 lexer.EventParsing = false;
2516 MemberName name = (MemberName) $5;
2519 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2520 current_container.Name, name.GetSignatureForError ());
2523 Accessors accessors = (Accessors) $8;
2525 if (name.TypeArguments != null)
2526 syntax_error (lexer.Location, "an event can't have type arguments");
2528 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2529 // CS0073 is already reported, so no CS0065 here.
2532 Event e = new EventProperty (
2533 current_class, (Expression) $4, (int) $2, false, name,
2534 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2535 if (RootContext.Documentation != null) {
2536 e.DocComment = Lexer.consume_doc_comment ();
2537 Lexer.doc_state = XmlCommentState.Allowed;
2540 current_container.AddEvent (e);
2541 implicit_value_parameter_type = null;
2545 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2546 MemberName mn = (MemberName) $5;
2548 if (mn.Left != null)
2549 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2551 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2553 if (RootContext.Documentation != null)
2554 Lexer.doc_state = XmlCommentState.Allowed;
2558 event_accessor_declarations
2559 : add_accessor_declaration remove_accessor_declaration
2561 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2563 | remove_accessor_declaration add_accessor_declaration
2565 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2566 accessors.declared_in_reverse = true;
2569 | add_accessor_declaration { $$ = null; }
2570 | remove_accessor_declaration { $$ = null; }
2573 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2579 add_accessor_declaration
2580 : opt_attributes ADD
2582 Parameter [] args = new Parameter [1];
2583 Parameter implicit_value_parameter = new Parameter (
2584 implicit_value_parameter_type, "value",
2585 Parameter.Modifier.NONE, null, (Location) $2);
2587 args [0] = implicit_value_parameter;
2589 current_local_parameters = new Parameters (args);
2590 lexer.EventParsing = false;
2592 anonymous_host = SimpleAnonymousHost.GetSimple ();
2596 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2597 lexer.EventParsing = true;
2599 current_local_parameters = null;
2600 SimpleAnonymousHost.Simple.Propagate (accessor);
2601 anonymous_host = null;
2605 | opt_attributes ADD error {
2606 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2609 | opt_attributes modifiers ADD {
2610 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2615 remove_accessor_declaration
2616 : opt_attributes REMOVE
2618 Parameter [] args = new Parameter [1];
2619 Parameter implicit_value_parameter = new Parameter (
2620 implicit_value_parameter_type, "value",
2621 Parameter.Modifier.NONE, null, (Location) $2);
2623 args [0] = implicit_value_parameter;
2625 current_local_parameters = new Parameters (args);
2626 lexer.EventParsing = false;
2630 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2631 lexer.EventParsing = true;
2633 | opt_attributes REMOVE error {
2634 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2637 | opt_attributes modifiers REMOVE {
2638 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2644 : opt_attributes opt_modifiers indexer_declarator
2647 IndexerDeclaration decl = (IndexerDeclaration) $3;
2649 implicit_value_parameter_type = decl.type;
2651 lexer.PropertyParsing = true;
2652 parsing_indexer = true;
2654 indexer_parameters = decl.param_list;
2655 anonymous_host = SimpleAnonymousHost.GetSimple ();
2657 accessor_declarations
2659 lexer.PropertyParsing = false;
2660 has_get = has_set = false;
2661 parsing_indexer = false;
2668 // The signature is computed from the signature of the indexer. Look
2669 // at section 3.6 on the spec
2671 IndexerDeclaration decl = (IndexerDeclaration) $3;
2672 Location loc = decl.location;
2673 Accessors accessors = (Accessors) $6;
2674 Accessor get_block = accessors.get_or_add;
2675 Accessor set_block = accessors.set_or_remove;
2678 if (decl.interface_type != null)
2679 name = new MemberName (decl.interface_type, TypeContainer.DefaultIndexerName, loc);
2681 name = new MemberName (TypeContainer.DefaultIndexerName, loc);
2683 indexer = new Indexer (current_class, decl.type, name,
2684 (int) $2, false, decl.param_list, (Attributes) $1,
2685 get_block, set_block, accessors.declared_in_reverse);
2687 if (RootContext.Documentation != null)
2688 indexer.DocComment = ConsumeStoredComment ();
2690 current_container.AddIndexer (indexer);
2692 current_local_parameters = null;
2693 implicit_value_parameter_type = null;
2694 indexer_parameters = null;
2699 : type THIS OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2701 Parameters pars = (Parameters) $4;
2703 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2705 if (RootContext.Documentation != null) {
2706 tmpComment = Lexer.consume_doc_comment ();
2707 Lexer.doc_state = XmlCommentState.Allowed;
2710 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2712 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2714 Parameters pars = (Parameters) $6;
2716 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2719 MemberName name = (MemberName) $2;
2720 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2722 if (RootContext.Documentation != null) {
2723 tmpComment = Lexer.consume_doc_comment ();
2724 Lexer.doc_state = XmlCommentState.Allowed;
2734 if (RootContext.Documentation != null)
2735 enumTypeComment = Lexer.consume_doc_comment ();
2740 LocatedToken lt = (LocatedToken) $4;
2741 Location enum_location = lt.Location;
2743 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2744 Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
2745 name, (Attributes) $1);
2747 if (RootContext.Documentation != null)
2748 e.DocComment = enumTypeComment;
2751 EnumMember em = null;
2752 foreach (VariableDeclaration ev in (ArrayList) $7) {
2753 em = new EnumMember (
2754 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2755 ev.OptAttributes, ev.Location);
2757 // if (RootContext.Documentation != null)
2758 em.DocComment = ev.DocComment;
2760 e.AddEnumMember (em);
2763 current_container.AddTypeContainer (e);
2770 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2771 | COLON type { $$ = $2; }
2777 if (RootContext.Documentation != null)
2778 Lexer.doc_state = XmlCommentState.Allowed;
2780 opt_enum_member_declarations
2782 // here will be evaluated after CLOSE_BLACE is consumed.
2783 if (RootContext.Documentation != null)
2784 Lexer.doc_state = XmlCommentState.Allowed;
2792 opt_enum_member_declarations
2793 : /* empty */ { $$ = new ArrayList (4); }
2794 | enum_member_declarations opt_comma { $$ = $1; }
2797 enum_member_declarations
2798 : enum_member_declaration
2800 ArrayList l = new ArrayList (4);
2805 | enum_member_declarations COMMA enum_member_declaration
2807 ArrayList l = (ArrayList) $1;
2815 enum_member_declaration
2816 : opt_attributes IDENTIFIER
2818 VariableDeclaration vd = new VariableDeclaration (
2819 (LocatedToken) $2, null, (Attributes) $1);
2821 if (RootContext.Documentation != null) {
2822 vd.DocComment = Lexer.consume_doc_comment ();
2823 Lexer.doc_state = XmlCommentState.Allowed;
2828 | opt_attributes IDENTIFIER
2830 if (RootContext.Documentation != null) {
2831 tmpComment = Lexer.consume_doc_comment ();
2832 Lexer.doc_state = XmlCommentState.NotAllowed;
2837 VariableDeclaration vd = new VariableDeclaration (
2838 (LocatedToken) $2, $5, (Attributes) $1);
2840 if (RootContext.Documentation != null)
2841 vd.DocComment = ConsumeStoredComment ();
2847 delegate_declaration
2852 open_parens opt_formal_parameter_list CLOSE_PARENS
2854 MemberName name = MakeName ((MemberName) $5);
2855 Parameters p = (Parameters) $7;
2857 Delegate del = new Delegate (current_namespace, current_class, (Expression) $4,
2858 (int) $2, name, p, (Attributes) $1);
2860 if (RootContext.Documentation != null) {
2861 del.DocComment = Lexer.consume_doc_comment ();
2862 Lexer.doc_state = XmlCommentState.Allowed;
2865 current_container.AddDelegate (del);
2866 current_delegate = del;
2867 lexer.ConstraintsParsing = true;
2869 opt_type_parameter_constraints_clauses
2871 lexer.ConstraintsParsing = false;
2875 current_delegate.SetParameterInfo ((ArrayList) $10);
2876 $$ = current_delegate;
2878 current_delegate = null;
2885 lexer.CheckNullable (false);
2890 // FIXME: A hack with parsing conditional operator as nullable type
2891 //if (RootContext.Version < LanguageVersion.ISO_2)
2892 // Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2894 lexer.CheckNullable (true);
2899 namespace_or_type_name
2900 : IDENTIFIER opt_type_argument_list
2902 LocatedToken lt = (LocatedToken) $1;
2903 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2905 | IDENTIFIER DOUBLE_COLON IDENTIFIER opt_type_argument_list {
2906 LocatedToken lt1 = (LocatedToken) $1;
2907 LocatedToken lt2 = (LocatedToken) $3;
2908 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $4, lt2.Location);
2910 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2911 LocatedToken lt = (LocatedToken) $3;
2912 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2917 : IDENTIFIER opt_type_parameter_list
2919 LocatedToken lt = (LocatedToken) $1;
2920 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2922 | namespace_or_type_name DOT IDENTIFIER opt_type_parameter_list
2924 LocatedToken lt = (LocatedToken) $3;
2925 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2930 : IDENTIFIER opt_type_parameter_list
2932 LocatedToken lt = (LocatedToken) $1;
2933 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2938 // Generics arguments (any type, without attributes)
2941 opt_type_argument_list
2942 : /* empty */ { $$ = null; }
2943 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2945 if (RootContext.Version < LanguageVersion.ISO_2)
2946 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2953 // Generics parameters (identifiers only, with attributes), used in type, method declarations
2956 opt_type_parameter_list
2957 : /* empty */ { $$ = null; }
2958 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2960 if (RootContext.Version < LanguageVersion.ISO_2)
2961 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2970 TypeArguments type_args = new TypeArguments (lexer.Location);
2971 type_args.Add ((Expression) $1);
2974 | type_arguments COMMA type_argument
2976 TypeArguments type_args = (TypeArguments) $1;
2977 type_args.Add ((Expression) $3);
2987 | attribute_sections type
2989 SimpleName sn = $2 as SimpleName;
2991 Error_TypeExpected (GetLocation ($2));
2993 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2999 * Before you think of adding a return_type, notice that we have been
3000 * using two rules in the places where it matters (one rule using type
3001 * and another identical one that uses VOID as the return type). This
3002 * gets rid of a shift/reduce couple
3005 : namespace_or_type_name opt_nullable
3007 MemberName name = (MemberName) $1;
3010 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
3012 if (RootContext.Version > LanguageVersion.ISO_2 && name.Name == "var")
3013 $$ = new VarExpr (name.Location);
3015 $$ = name.GetTypeExpression ();
3018 | builtin_types opt_nullable
3021 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3031 // Note that here only unmanaged types are allowed but we
3032 // can't perform checks during this phase - we do it during
3033 // semantic analysis.
3035 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
3039 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
3044 : builtin_types opt_nullable
3047 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3049 | non_expression_type rank_specifier
3051 Location loc = GetLocation ($1);
3053 loc = lexer.Location;
3054 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
3056 | non_expression_type STAR
3058 Location loc = GetLocation ($1);
3060 loc = lexer.Location;
3061 $$ = new ComposedCast ((Expression) $1, "*", loc);
3063 | expression rank_specifiers
3065 $$ = new ComposedCast ((Expression) $1, (string) $2);
3069 $$ = new ComposedCast ((Expression) $1, "*");
3073 // We need this because the parser will happily go and reduce IDENTIFIER STAR
3074 // through this different path
3076 | multiplicative_expression STAR
3078 $$ = new ComposedCast ((Expression) $1, "*");
3085 ArrayList types = new ArrayList (4);
3090 | type_list COMMA type
3092 ArrayList types = (ArrayList) $1;
3100 * replaces all the productions for isolating the various
3101 * simple types, but we need this to reuse it easily in local_variable_type
3104 : OBJECT { $$ = TypeManager.system_object_expr; }
3105 | STRING { $$ = TypeManager.system_string_expr; }
3106 | BOOL { $$ = TypeManager.system_boolean_expr; }
3107 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
3108 | FLOAT { $$ = TypeManager.system_single_expr; }
3109 | DOUBLE { $$ = TypeManager.system_double_expr; }
3114 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
3115 | BYTE { $$ = TypeManager.system_byte_expr; }
3116 | SHORT { $$ = TypeManager.system_int16_expr; }
3117 | USHORT { $$ = TypeManager.system_uint16_expr; }
3118 | INT { $$ = TypeManager.system_int32_expr; }
3119 | UINT { $$ = TypeManager.system_uint32_expr; }
3120 | LONG { $$ = TypeManager.system_int64_expr; }
3121 | ULONG { $$ = TypeManager.system_uint64_expr; }
3122 | CHAR { $$ = TypeManager.system_char_expr; }
3123 | VOID { $$ = TypeManager.system_void_expr; }
3127 : type rank_specifiers opt_nullable
3129 string rank_specifiers = (string) $2;
3131 rank_specifiers += "?";
3133 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
3138 // Expressions, section 7.5
3147 MemberName mn = (MemberName) $1;
3148 $$ = mn.GetTypeExpression ();
3150 | IDENTIFIER DOUBLE_COLON IDENTIFIER
3152 LocatedToken lt1 = (LocatedToken) $1;
3153 LocatedToken lt2 = (LocatedToken) $3;
3154 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
3156 | parenthesized_expression
3157 | default_value_expression
3159 | invocation_expression
3163 | post_increment_expression
3164 | post_decrement_expression
3168 | checked_expression
3169 | unchecked_expression
3170 | pointer_member_access
3171 | anonymous_method_expression
3178 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3179 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3180 | NULL { $$ = new NullLiteral (lexer.Location); }
3184 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3185 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3186 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3191 object v = lexer.Value;
3194 $$ = new IntLiteral ((int) v, lexer.Location);
3195 } else if (v is uint)
3196 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3198 $$ = new LongLiteral ((Int64) v, lexer.Location);
3199 else if (v is ulong)
3200 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3202 Console.WriteLine ("OOPS. Unexpected result from scanner");
3207 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3208 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3211 parenthesized_expression_0
3212 : OPEN_PARENS expression CLOSE_PARENS
3215 lexer.Deambiguate_CloseParens ($$);
3216 // After this, the next token returned is one of
3217 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3218 // or CLOSE_PARENS_MINUS.
3220 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3223 parenthesized_expression
3224 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3228 | parenthesized_expression_0 CLOSE_PARENS
3232 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3234 // If a parenthesized expression is followed by a minus, we need to wrap
3235 // the expression inside a ParenthesizedExpression for the CS0075 check
3236 // in Binary.DoResolve().
3237 $$ = new ParenthesizedExpression ((Expression) $1);
3242 : primary_expression DOT IDENTIFIER opt_type_argument_list
3244 LocatedToken lt = (LocatedToken) $3;
3245 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3247 | predefined_type DOT IDENTIFIER opt_type_argument_list
3249 LocatedToken lt = (LocatedToken) $3;
3250 // TODO: Location is wrong as some predefined types doesn't hold a location
3251 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3259 invocation_expression
3260 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3263 Report.Error (1, (Location) $2, "Parse error");
3265 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3267 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3269 $$ = new Invocation ((Expression) $1, new ArrayList ());
3271 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3273 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3275 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3277 ArrayList args = new ArrayList (1);
3279 $$ = new Invocation ((Expression) $1, args);
3281 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3283 ArrayList args = ((ArrayList) $4);
3285 $$ = new Invocation ((Expression) $1, args);
3289 opt_object_or_collection_initializer
3290 : /* empty */ { $$ = null; }
3291 | object_or_collection_initializer
3294 object_or_collection_initializer
3295 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3298 $$ = CollectionOrObjectInitializers.Empty;
3300 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3302 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3304 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3308 opt_member_initializer_list
3309 : /* empty */ { $$ = null; }
3310 | member_initializer_list
3316 member_initializer_list
3317 : member_initializer
3319 ArrayList a = new ArrayList ();
3323 | member_initializer_list COMMA member_initializer
3325 ArrayList a = (ArrayList)$1;
3332 : IDENTIFIER ASSIGN initializer_value
3334 LocatedToken lt = $1 as LocatedToken;
3335 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3337 | non_assignment_expression
3339 $$ = new CollectionElementInitializer ((Expression)$1);
3341 | OPEN_BRACE expression_list CLOSE_BRACE
3343 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3345 | OPEN_BRACE CLOSE_BRACE
3347 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3353 | object_or_collection_initializer
3357 : /* empty */ { $$ = null; }
3364 ArrayList list = new ArrayList (4);
3368 | argument_list COMMA argument
3370 ArrayList list = (ArrayList) $1;
3374 | argument_list error {
3375 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3383 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3385 | non_simple_argument
3392 : REF variable_reference
3394 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3396 | OUT variable_reference
3398 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3400 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3402 ArrayList list = (ArrayList) $3;
3403 Argument[] args = new Argument [list.Count];
3404 list.CopyTo (args, 0);
3406 Expression expr = new Arglist (args, (Location) $1);
3407 $$ = new Argument (expr, Argument.AType.Expression);
3409 | ARGLIST OPEN_PARENS CLOSE_PARENS
3411 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3415 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3420 : expression { note ("section 5.4"); $$ = $1; }
3424 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3426 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3428 | primary_expression rank_specifiers
3430 // So the super-trick is that primary_expression
3431 // can only be either a SimpleName or a MemberAccess.
3432 // The MemberAccess case arises when you have a fully qualified type-name like :
3434 // SimpleName is when you have
3437 Expression expr = (Expression) $1;
3438 if (expr is ComposedCast){
3439 $$ = new ComposedCast (expr, (string) $2);
3440 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3441 Error_ExpectingTypeName (expr);
3442 $$ = TypeManager.system_object_expr;
3445 // So we extract the string corresponding to the SimpleName
3448 $$ = new ComposedCast (expr, (string) $2);
3450 current_array_type = (Expression)$$;
3457 ArrayList list = new ArrayList (4);
3461 | expression_list COMMA expression
3463 ArrayList list = (ArrayList) $1;
3472 $$ = new This (current_block, (Location) $1);
3477 : BASE DOT IDENTIFIER opt_type_argument_list
3479 LocatedToken lt = (LocatedToken) $3;
3480 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3482 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3484 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3487 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3492 post_increment_expression
3493 : primary_expression OP_INC
3495 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3496 (Expression) $1, (Location) $2);
3500 post_decrement_expression
3501 : primary_expression OP_DEC
3503 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3504 (Expression) $1, (Location) $2);
3509 : object_or_delegate_creation_expression
3510 | array_creation_expression
3511 | anonymous_type_expression
3514 object_or_delegate_creation_expression
3515 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3518 if (RootContext.Version <= LanguageVersion.ISO_2)
3519 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3521 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3524 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3526 | NEW type object_or_collection_initializer
3528 if (RootContext.Version <= LanguageVersion.ISO_2)
3529 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3531 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3535 array_creation_expression
3536 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3538 opt_array_initializer
3540 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3542 | NEW type rank_specifiers array_initializer
3544 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3546 | NEW rank_specifiers array_initializer
3548 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3552 Report.Error (1031, (Location) $1, "Type expected");
3557 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3562 anonymous_type_expression
3563 : NEW OPEN_BRACE anonymous_type_parameters CLOSE_BRACE
3565 if (RootContext.Version <= LanguageVersion.ISO_2)
3566 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3568 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3572 anonymous_type_parameters
3574 | anonymous_type_parameter
3576 ArrayList a = new ArrayList (4);
3580 | anonymous_type_parameters COMMA anonymous_type_parameter
3582 ArrayList a = (ArrayList) $1;
3588 anonymous_type_parameter
3589 : IDENTIFIER ASSIGN variable_initializer
3591 LocatedToken lt = (LocatedToken)$1;
3592 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3596 LocatedToken lt = (LocatedToken)$1;
3597 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3598 lt.Value, lt.Location);
3602 MemberAccess ma = (MemberAccess) $1;
3603 $$ = new AnonymousTypeParameter (ma, ma.Identifier, ma.Location);
3607 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3608 "Anonymous type members must be a member assignment, simple name or member access expression");
3623 opt_rank_specifier_or_nullable
3632 | opt_nullable rank_specifiers
3639 | opt_nullable rank_specifiers INTERR
3642 $$ = "?" + $2 + "?";
3649 : rank_specifier opt_rank_specifier
3651 $$ = (string) $2 + (string) $1;
3656 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3658 $$ = "[" + (string) $2 + "]";
3678 | dim_separators COMMA
3680 $$ = (string) $1 + ",";
3684 opt_array_initializer
3696 : OPEN_BRACE CLOSE_BRACE
3698 ArrayList list = new ArrayList (4);
3701 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3703 $$ = (ArrayList) $2;
3707 variable_initializer_list
3708 : variable_initializer
3710 ArrayList list = new ArrayList (4);
3714 | variable_initializer_list COMMA variable_initializer
3716 ArrayList list = (ArrayList) $1;
3725 pushed_current_array_type = current_array_type;
3726 lexer.TypeOfParsing = true;
3728 OPEN_PARENS typeof_type_expression CLOSE_PARENS
3730 lexer.TypeOfParsing = false;
3731 Expression type = (Expression)$4;
3732 if (type == TypeManager.system_void_expr)
3733 $$ = new TypeOfVoid ((Location) $1);
3735 $$ = new TypeOf (type, (Location) $1);
3736 current_array_type = pushed_current_array_type;
3740 typeof_type_expression
3747 $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
3752 : IDENTIFIER GENERIC_DIMENSION
3754 if (RootContext.Version < LanguageVersion.ISO_1)
3755 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3757 LocatedToken lt = (LocatedToken) $1;
3758 TypeArguments ta = new TypeArguments ((int)$2, lt.Location);
3760 $$ = new MemberName (lt.Value, ta, lt.Location);
3762 | IDENTIFIER DOUBLE_COLON IDENTIFIER GENERIC_DIMENSION
3764 LocatedToken lt = (LocatedToken) $1;
3765 MemberName left = new MemberName (lt.Value, lt.Location);
3766 lt = (LocatedToken) $3;
3767 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3769 $$ = new MemberName (left, lt.Value, ta, lt.Location);
3771 | unbound_type_name DOT IDENTIFIER GENERIC_DIMENSION
3773 LocatedToken lt = (LocatedToken) $3;
3774 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3776 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3778 | namespace_or_type_name DOT IDENTIFIER GENERIC_DIMENSION
3780 LocatedToken lt = (LocatedToken) $3;
3781 TypeArguments ta = new TypeArguments ((int)$4, lt.Location);
3783 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3789 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3790 $$ = new SizeOf ((Expression) $3, (Location) $1);
3795 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3797 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3801 unchecked_expression
3802 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3804 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3808 pointer_member_access
3809 : primary_expression OP_PTR IDENTIFIER
3812 LocatedToken lt = (LocatedToken) $3;
3814 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3815 $$ = new MemberAccess (deref, lt.Value);
3819 anonymous_method_expression
3820 : DELEGATE opt_anonymous_method_signature
3822 start_anonymous (false, (Parameters) $2, (Location) $1);
3826 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3830 opt_anonymous_method_signature
3831 : /* empty */ { $$ = null; }
3832 | anonymous_method_signature
3835 anonymous_method_signature
3838 params_modifiers_not_allowed = true;
3840 opt_formal_parameter_list CLOSE_PARENS
3842 params_modifiers_not_allowed = false;
3847 default_value_expression
3848 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3850 if (RootContext.Version < LanguageVersion.ISO_2)
3851 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3853 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3858 : primary_expression
3859 | BANG prefixed_unary_expression
3861 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3863 | TILDE prefixed_unary_expression
3865 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3871 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3873 $$ = new Cast ((Expression) $1, (Expression) $3);
3875 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3877 $$ = new Cast ((Expression) $1, (Expression) $3);
3879 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3881 $$ = new Cast ((Expression) $1, (Expression) $3);
3887 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3889 // TODO: wrong location
3890 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3895 // The idea to split this out is from Rhys' grammar
3896 // to solve the problem with casts.
3898 prefixed_unary_expression
3900 | PLUS prefixed_unary_expression
3902 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3904 | MINUS prefixed_unary_expression
3906 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3908 | OP_INC prefixed_unary_expression
3910 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3911 (Expression) $2, (Location) $1);
3913 | OP_DEC prefixed_unary_expression
3915 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3916 (Expression) $2, (Location) $1);
3918 | STAR prefixed_unary_expression
3920 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3922 | BITWISE_AND prefixed_unary_expression
3924 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3928 multiplicative_expression
3929 : prefixed_unary_expression
3930 | multiplicative_expression STAR prefixed_unary_expression
3932 $$ = new Binary (Binary.Operator.Multiply,
3933 (Expression) $1, (Expression) $3);
3935 | multiplicative_expression DIV prefixed_unary_expression
3937 $$ = new Binary (Binary.Operator.Division,
3938 (Expression) $1, (Expression) $3);
3940 | multiplicative_expression PERCENT prefixed_unary_expression
3942 $$ = new Binary (Binary.Operator.Modulus,
3943 (Expression) $1, (Expression) $3);
3948 : multiplicative_expression
3949 | additive_expression PLUS multiplicative_expression
3951 $$ = new Binary (Binary.Operator.Addition,
3952 (Expression) $1, (Expression) $3);
3954 | additive_expression MINUS multiplicative_expression
3956 $$ = new Binary (Binary.Operator.Subtraction,
3957 (Expression) $1, (Expression) $3);
3962 : additive_expression
3963 | shift_expression OP_SHIFT_LEFT additive_expression
3965 $$ = new Binary (Binary.Operator.LeftShift,
3966 (Expression) $1, (Expression) $3);
3968 | shift_expression OP_SHIFT_RIGHT additive_expression
3970 $$ = new Binary (Binary.Operator.RightShift,
3971 (Expression) $1, (Expression) $3);
3982 lexer.PutbackNullable ();
3987 nullable_type_or_conditional
3990 if (((bool) $2) && ($1 is ComposedCast))
3991 $$ = ((ComposedCast) $1).RemoveNullable ();
3997 relational_expression
3999 | relational_expression OP_LT shift_expression
4001 $$ = new Binary (Binary.Operator.LessThan,
4002 (Expression) $1, (Expression) $3);
4004 | relational_expression OP_GT shift_expression
4006 $$ = new Binary (Binary.Operator.GreaterThan,
4007 (Expression) $1, (Expression) $3);
4009 | relational_expression OP_LE shift_expression
4011 $$ = new Binary (Binary.Operator.LessThanOrEqual,
4012 (Expression) $1, (Expression) $3);
4014 | relational_expression OP_GE shift_expression
4016 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
4017 (Expression) $1, (Expression) $3);
4019 | relational_expression IS
4022 } nullable_type_or_conditional
4024 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
4026 | relational_expression AS
4029 } nullable_type_or_conditional
4031 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
4036 : relational_expression
4037 | equality_expression OP_EQ relational_expression
4039 $$ = new Binary (Binary.Operator.Equality,
4040 (Expression) $1, (Expression) $3);
4042 | equality_expression OP_NE relational_expression
4044 $$ = new Binary (Binary.Operator.Inequality,
4045 (Expression) $1, (Expression) $3);
4050 : equality_expression
4051 | and_expression BITWISE_AND equality_expression
4053 $$ = new Binary (Binary.Operator.BitwiseAnd,
4054 (Expression) $1, (Expression) $3);
4058 exclusive_or_expression
4060 | exclusive_or_expression CARRET and_expression
4062 $$ = new Binary (Binary.Operator.ExclusiveOr,
4063 (Expression) $1, (Expression) $3);
4067 inclusive_or_expression
4068 : exclusive_or_expression
4069 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4071 $$ = new Binary (Binary.Operator.BitwiseOr,
4072 (Expression) $1, (Expression) $3);
4076 conditional_and_expression
4077 : inclusive_or_expression
4078 | conditional_and_expression OP_AND inclusive_or_expression
4080 $$ = new Binary (Binary.Operator.LogicalAnd,
4081 (Expression) $1, (Expression) $3);
4085 conditional_or_expression
4086 : conditional_and_expression
4087 | conditional_or_expression OP_OR conditional_and_expression
4089 $$ = new Binary (Binary.Operator.LogicalOr,
4090 (Expression) $1, (Expression) $3);
4094 conditional_expression
4095 : conditional_or_expression
4096 | conditional_or_expression INTERR expression COLON expression
4098 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
4100 | conditional_or_expression OP_COALESCING expression
4102 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
4104 // We'll be resolved into a `parenthesized_expression_0' later on.
4105 | conditional_or_expression INTERR CLOSE_PARENS
4107 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
4108 lexer.PutbackCloseParens ();
4112 assignment_expression
4113 : prefixed_unary_expression ASSIGN expression
4115 $$ = new Assign ((Expression) $1, (Expression) $3);
4117 | prefixed_unary_expression OP_MULT_ASSIGN expression
4119 $$ = new CompoundAssign (
4120 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4122 | prefixed_unary_expression OP_DIV_ASSIGN expression
4124 $$ = new CompoundAssign (
4125 Binary.Operator.Division, (Expression) $1, (Expression) $3);
4127 | prefixed_unary_expression OP_MOD_ASSIGN expression
4129 $$ = new CompoundAssign (
4130 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4132 | prefixed_unary_expression OP_ADD_ASSIGN expression
4134 $$ = new CompoundAssign (
4135 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4137 | prefixed_unary_expression OP_SUB_ASSIGN expression
4139 $$ = new CompoundAssign (
4140 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4142 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4144 $$ = new CompoundAssign (
4145 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4147 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4149 $$ = new CompoundAssign (
4150 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4152 | prefixed_unary_expression OP_AND_ASSIGN expression
4154 $$ = new CompoundAssign (
4155 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4157 | prefixed_unary_expression OP_OR_ASSIGN expression
4159 $$ = new CompoundAssign (
4160 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4162 | prefixed_unary_expression OP_XOR_ASSIGN expression
4164 $$ = new CompoundAssign (
4165 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4169 lambda_parameter_list
4172 ArrayList pars = new ArrayList (4);
4177 | lambda_parameter_list COMMA lambda_parameter
4179 ArrayList pars = (ArrayList) $1;
4180 Parameter p = (Parameter)$3;
4181 if (pars[0].GetType () != p.GetType ()) {
4182 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4191 : parameter_modifier type IDENTIFIER
4193 LocatedToken lt = (LocatedToken) $3;
4195 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4199 LocatedToken lt = (LocatedToken) $2;
4201 $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4205 LocatedToken lt = (LocatedToken) $1;
4206 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4210 opt_lambda_parameter_list
4211 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
4212 | lambda_parameter_list {
4213 ArrayList pars_list = (ArrayList) $1;
4214 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4218 lambda_expression_body
4220 start_block (lexer.Location);
4224 Block b = end_block (lexer.Location);
4225 b.AddStatement (new ContextualReturn ((Expression) $2));
4236 LocatedToken lt = (LocatedToken) $1;
4237 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4238 start_anonymous (true, new Parameters (p), (Location) $2);
4240 lambda_expression_body
4242 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4244 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4246 start_anonymous (true, (Parameters) $2, (Location) $4);
4248 lambda_expression_body
4250 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4255 : assignment_expression
4256 | non_assignment_expression
4259 non_assignment_expression
4260 : conditional_expression
4282 lexer.ConstraintsParsing = true;
4286 MemberName name = MakeName ((MemberName) $6);
4287 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4290 opt_type_parameter_constraints_clauses
4292 lexer.ConstraintsParsing = false;
4294 current_class.SetParameterInfo ((ArrayList) $9);
4296 if (RootContext.Documentation != null) {
4297 current_container.DocComment = Lexer.consume_doc_comment ();
4298 Lexer.doc_state = XmlCommentState.Allowed;
4303 if (RootContext.Documentation != null)
4304 Lexer.doc_state = XmlCommentState.Allowed;
4308 $$ = pop_current_class ();
4316 { $$ = $1; } // location
4320 : /* empty */ { $$ = (int) 0; }
4326 | modifiers modifier
4331 if ((m1 & m2) != 0) {
4332 Location l = lexer.Location;
4333 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4335 $$ = (int) (m1 | m2);
4340 : NEW { $$ = Modifiers.NEW; }
4341 | PUBLIC { $$ = Modifiers.PUBLIC; }
4342 | PROTECTED { $$ = Modifiers.PROTECTED; }
4343 | INTERNAL { $$ = Modifiers.INTERNAL; }
4344 | PRIVATE { $$ = Modifiers.PRIVATE; }
4345 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4346 | SEALED { $$ = Modifiers.SEALED; }
4347 | STATIC { $$ = Modifiers.STATIC; }
4348 | READONLY { $$ = Modifiers.READONLY; }
4349 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4350 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4351 | EXTERN { $$ = Modifiers.EXTERN; }
4352 | VOLATILE { $$ = Modifiers.VOLATILE; }
4353 | UNSAFE { $$ = Modifiers.UNSAFE; }
4362 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4365 opt_type_parameter_constraints_clauses
4366 : /* empty */ { $$ = null; }
4367 | type_parameter_constraints_clauses
4371 type_parameter_constraints_clauses
4372 : type_parameter_constraints_clause {
4373 ArrayList constraints = new ArrayList (1);
4374 constraints.Add ($1);
4377 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4378 ArrayList constraints = (ArrayList) $1;
4379 Constraints new_constraint = (Constraints)$2;
4381 foreach (Constraints c in constraints) {
4382 if (new_constraint.TypeParameter == c.TypeParameter) {
4383 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4384 new_constraint.TypeParameter);
4388 constraints.Add (new_constraint);
4393 type_parameter_constraints_clause
4394 : WHERE IDENTIFIER COLON type_parameter_constraints {
4395 LocatedToken lt = (LocatedToken) $2;
4396 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4400 type_parameter_constraints
4401 : type_parameter_constraint {
4402 ArrayList constraints = new ArrayList (1);
4403 constraints.Add ($1);
4406 | type_parameter_constraints COMMA type_parameter_constraint {
4407 ArrayList constraints = (ArrayList) $1;
4409 constraints.Add ($3);
4414 type_parameter_constraint
4416 | NEW OPEN_PARENS CLOSE_PARENS {
4417 $$ = SpecialConstraint.Constructor;
4420 $$ = SpecialConstraint.ReferenceType;
4423 $$ = SpecialConstraint.ValueType;
4432 // A block is "contained" on the following places:
4434 // property_declaration as part of the accessor body (get/set)
4435 // operator_declaration
4436 // constructor_declaration
4437 // destructor_declaration
4438 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4443 ++lexer.parsing_block;
4444 start_block ((Location) $1);
4446 opt_statement_list CLOSE_BRACE
4448 --lexer.parsing_block;
4449 $$ = end_block ((Location) $4);
4456 ++lexer.parsing_block;
4458 opt_statement_list CLOSE_BRACE
4460 --lexer.parsing_block;
4461 $$ = end_block ((Location) $4);
4472 | statement_list statement
4476 : declaration_statement
4478 if ($1 != null && (Block) $1 != current_block){
4479 current_block.AddStatement ((Statement) $1);
4480 current_block = (Block) $1;
4483 | valid_declaration_statement
4485 current_block.AddStatement ((Statement) $1);
4490 valid_declaration_statement
4493 | expression_statement
4494 | selection_statement
4495 | iteration_statement
4499 | unchecked_statement
4507 : valid_declaration_statement
4508 | declaration_statement
4510 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4515 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4523 $$ = EmptyStatement.Value;
4530 LocatedToken lt = (LocatedToken) $1;
4531 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4533 if (current_block.AddLabel (labeled))
4534 current_block.AddStatement (labeled);
4539 declaration_statement
4540 : local_variable_declaration SEMICOLON
4542 current_array_type = null;
4544 DictionaryEntry de = (DictionaryEntry) $1;
4545 Expression e = (Expression) de.Key;
4547 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4551 | local_constant_declaration SEMICOLON
4553 current_array_type = null;
4555 DictionaryEntry de = (DictionaryEntry) $1;
4557 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4563 * The following is from Rhys' grammar:
4564 * > Types in local variable declarations must be recognized as
4565 * > expressions to prevent reduce/reduce errors in the grammar.
4566 * > The expressions are converted into types during semantic analysis.
4569 : primary_expression opt_rank_specifier_or_nullable
4571 // FIXME: Do something smart here regarding the composition of the type.
4573 // Ok, the above "primary_expression" is there to get rid of
4574 // both reduce/reduce and shift/reduces in the grammar, it should
4575 // really just be "type_name". If you use type_name, a reduce/reduce
4576 // creeps up. If you use namespace_or_type_name (which is all we need
4577 // really) two shift/reduces appear.
4580 // So the super-trick is that primary_expression
4581 // can only be either a SimpleName or a MemberAccess.
4582 // The MemberAccess case arises when you have a fully qualified type-name like :
4584 // SimpleName is when you have
4587 Expression expr = (Expression) $1;
4588 SimpleName sn = expr as SimpleName;
4589 if (!(sn != null || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4590 Error_ExpectingTypeName (expr);
4594 // So we extract the string corresponding to the SimpleName
4598 if ((string) $2 == "") {
4599 if (sn != null && RootContext.Version > LanguageVersion.ISO_2 && sn.Name == "var")
4600 $$ = new VarExpr (sn.Location);
4604 $$ = new ComposedCast ((Expression) $1, (string) $2);
4607 | builtin_types opt_rank_specifier_or_nullable
4609 if ((string) $2 == "")
4612 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4616 local_variable_pointer_type
4617 : primary_expression STAR
4619 Expression expr = (Expression) $1;
4621 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4622 Error_ExpectingTypeName (expr);
4626 $$ = new ComposedCast ((Expression) $1, "*");
4628 | builtin_types STAR
4630 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4634 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4636 | local_variable_pointer_type STAR
4638 $$ = new ComposedCast ((Expression) $1, "*");
4642 local_variable_declaration
4643 : local_variable_type variable_declarators
4646 VarExpr ve = $1 as VarExpr;
4648 ve.VariableInitializer = (ArrayList)$2;
4650 $$ = new DictionaryEntry ($1, $2);
4654 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4659 if ((string) $2 == "")
4660 t = (Expression) $1;
4662 t = new ComposedCast ((Expression) $1, (string) $2);
4663 $$ = new DictionaryEntry (t, $3);
4669 local_constant_declaration
4670 : CONST local_variable_type constant_declarators
4673 $$ = new DictionaryEntry ($2, $3);
4679 expression_statement
4680 : statement_expression SEMICOLON { $$ = $1; }
4684 // We have to do the wrapping here and not in the case above,
4685 // because statement_expression is used for example in for_statement
4687 statement_expression
4690 Expression expr = (Expression) $1;
4691 ExpressionStatement s = expr as ExpressionStatement;
4693 expr.Error_InvalidExpressionStatement ();
4696 $$ = new StatementExpression (s);
4700 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4711 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4714 Location l = (Location) $1;
4716 $$ = new If ((Expression) $3, (Statement) $5, l);
4718 // FIXME: location for warning should be loc property of $5.
4719 if ($5 == EmptyStatement.Value)
4720 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4723 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4724 embedded_statement ELSE embedded_statement
4726 Location l = (Location) $1;
4728 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4730 // FIXME: location for warning should be loc property of $5 and $7.
4731 if ($5 == EmptyStatement.Value)
4732 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4733 if ($7 == EmptyStatement.Value)
4734 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4739 : SWITCH OPEN_PARENS
4741 if (switch_stack == null)
4742 switch_stack = new Stack (2);
4743 switch_stack.Push (current_block);
4745 expression CLOSE_PARENS
4748 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4749 current_block = (Block) switch_stack.Pop ();
4765 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4766 $$ = new ArrayList ();
4774 ArrayList sections = new ArrayList (4);
4779 | switch_sections switch_section
4781 ArrayList sections = (ArrayList) $1;
4791 current_block = current_block.CreateSwitchBlock (lexer.Location);
4795 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4802 ArrayList labels = new ArrayList (4);
4807 | switch_labels switch_label
4809 ArrayList labels = (ArrayList) ($1);
4817 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4818 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4821 1523, GetLocation ($1),
4822 "The keyword case or default must precede code in switch block");
4834 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4836 Location l = (Location) $1;
4837 $$ = new While ((Expression) $3, (Statement) $5, l);
4842 : DO embedded_statement
4843 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4845 Location l = (Location) $1;
4847 $$ = new Do ((Statement) $2, (Expression) $5, l);
4853 opt_for_initializer SEMICOLON
4855 Location l = lexer.Location;
4857 Block assign_block = current_block;
4859 if ($3 is DictionaryEntry){
4860 DictionaryEntry de = (DictionaryEntry) $3;
4862 Expression type = (Expression) de.Key;
4863 ArrayList var_declarators = (ArrayList) de.Value;
4865 foreach (VariableDeclaration decl in var_declarators){
4869 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4873 Expression expr = decl.expression_or_array_initializer;
4875 LocalVariableReference var;
4876 var = new LocalVariableReference (assign_block, decl.identifier, l);
4879 Assign a = new Assign (var, expr, decl.Location);
4881 assign_block.AddStatement (new StatementExpression (a));
4885 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4886 // This can be referred to as $5 below.
4892 opt_for_condition SEMICOLON
4893 opt_for_iterator CLOSE_PARENS
4896 Location l = (Location) $1;
4898 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4900 current_block.AddStatement (f);
4902 $$ = end_block (lexer.Location);
4907 : /* empty */ { $$ = EmptyStatement.Value; }
4912 : local_variable_declaration
4913 | statement_expression_list
4917 : /* empty */ { $$ = null; }
4918 | boolean_expression
4922 : /* empty */ { $$ = EmptyStatement.Value; }
4927 : statement_expression_list
4930 statement_expression_list
4931 : statement_expression
4933 // CHANGE: was `null'
4934 Statement s = (Statement) $1;
4935 Block b = new Block (current_block, s.loc, lexer.Location);
4940 | statement_expression_list COMMA statement_expression
4942 Block b = (Block) $1;
4944 b.AddStatement ((Statement) $3);
4950 : FOREACH open_parens type IN expression CLOSE_PARENS
4952 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4955 | FOREACH open_parens type IDENTIFIER IN
4956 expression CLOSE_PARENS
4958 start_block (lexer.Location);
4959 Block foreach_block = current_block;
4961 LocatedToken lt = (LocatedToken) $4;
4962 Location l = lt.Location;
4963 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4965 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4967 // Get a writable reference to this read-only variable.
4969 // Note that the $$ here refers to the value of _this_ code block,
4970 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4971 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4978 LocalVariableReference v = (LocalVariableReference) $8;
4979 Location l = (Location) $1;
4982 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4983 current_block.AddStatement (f);
4986 $$ = end_block (lexer.Location);
4992 | continue_statement
5002 $$ = new Break ((Location) $1);
5007 : CONTINUE SEMICOLON
5009 $$ = new Continue ((Location) $1);
5014 : GOTO IDENTIFIER SEMICOLON
5016 LocatedToken lt = (LocatedToken) $2;
5017 $$ = new Goto (lt.Value, lt.Location);
5019 | GOTO CASE constant_expression SEMICOLON
5021 $$ = new GotoCase ((Expression) $3, (Location) $1);
5023 | GOTO DEFAULT SEMICOLON
5025 $$ = new GotoDefault ((Location) $1);
5030 : RETURN opt_expression SEMICOLON
5032 $$ = new Return ((Expression) $2, (Location) $1);
5037 : THROW opt_expression SEMICOLON
5039 $$ = new Throw ((Expression) $2, (Location) $1);
5044 : IDENTIFIER RETURN expression SEMICOLON
5046 LocatedToken lt = (LocatedToken) $1;
5047 string s = lt.Value;
5049 Report.Error (1003, lt.Location, "; expected");
5052 if (RootContext.Version == LanguageVersion.ISO_1){
5053 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5056 if (anonymous_host == null){
5057 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5060 anonymous_host.SetYields ();
5061 $$ = new Yield ((Expression) $3, lt.Location);
5064 | IDENTIFIER RETURN SEMICOLON
5066 Report.Error (1627, (Location) $2, "Expression expected after yield return");
5069 | IDENTIFIER BREAK SEMICOLON
5071 LocatedToken lt = (LocatedToken) $1;
5072 string s = lt.Value;
5074 Report.Error (1003, lt.Location, "; expected");
5077 if (RootContext.Version == LanguageVersion.ISO_1){
5078 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5081 if (anonymous_host == null){
5082 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
5085 anonymous_host.SetYields ();
5086 $$ = new YieldBreak (lt.Location);
5097 : TRY block catch_clauses
5101 ArrayList c = (ArrayList)$3;
5102 for (int i = 0; i < c.Count; ++i) {
5103 Catch cc = (Catch) c [i];
5105 if (i != c.Count - 1)
5106 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
5113 // Now s contains the list of specific catch clauses
5114 // and g contains the general one.
5116 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
5118 | TRY block opt_catch_clauses FINALLY block
5121 ArrayList s = new ArrayList (4);
5122 ArrayList catch_list = (ArrayList) $3;
5124 if (catch_list != null){
5125 foreach (Catch cc in catch_list) {
5133 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
5137 Report.Error (1524, (Location) $1, "Expected catch or finally");
5143 : /* empty */ { $$ = null; }
5150 ArrayList l = new ArrayList (4);
5155 | catch_clauses catch_clause
5157 ArrayList l = (ArrayList) $1;
5165 : /* empty */ { $$ = null; }
5170 : CATCH opt_catch_args
5172 Expression type = null;
5175 DictionaryEntry cc = (DictionaryEntry) $2;
5176 type = (Expression) cc.Key;
5177 LocatedToken lt = (LocatedToken) cc.Value;
5180 ArrayList one = new ArrayList (4);
5182 one.Add (new VariableDeclaration (lt, null));
5184 start_block (lexer.Location);
5185 current_block = declare_local_variables (type, one, lt.Location);
5189 Expression type = null;
5191 Block var_block = null;
5194 DictionaryEntry cc = (DictionaryEntry) $2;
5195 type = (Expression) cc.Key;
5196 LocatedToken lt = (LocatedToken) cc.Value;
5200 var_block = end_block (lexer.Location);
5204 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5209 : /* empty */ { $$ = null; }
5214 : open_parens type opt_identifier CLOSE_PARENS
5216 $$ = new DictionaryEntry ($2, $3);
5224 $$ = new Checked ((Block) $2);
5231 $$ = new Unchecked ((Block) $2);
5238 RootContext.CheckUnsafeOption ((Location) $1);
5240 $$ = new Unsafe ((Block) $3);
5246 type fixed_pointer_declarators
5249 ArrayList list = (ArrayList) $4;
5250 Expression type = (Expression) $3;
5251 Location l = (Location) $1;
5252 int top = list.Count;
5254 start_block (lexer.Location);
5256 for (int i = 0; i < top; i++){
5257 Pair p = (Pair) list [i];
5260 v = current_block.AddVariable (type, (string) p.First, l);
5264 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5272 Location l = (Location) $1;
5274 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5276 current_block.AddStatement (f);
5278 $$ = end_block (lexer.Location);
5282 fixed_pointer_declarators
5283 : fixed_pointer_declarator {
5284 ArrayList declarators = new ArrayList (4);
5286 declarators.Add ($1);
5289 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5291 ArrayList declarators = (ArrayList) $1;
5293 declarators.Add ($3);
5298 fixed_pointer_declarator
5299 : IDENTIFIER ASSIGN expression
5301 LocatedToken lt = (LocatedToken) $1;
5302 // FIXME: keep location
5303 $$ = new Pair (lt.Value, $3);
5307 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5313 : LOCK OPEN_PARENS expression CLOSE_PARENS
5319 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5324 : USING open_parens resource_acquisition CLOSE_PARENS
5326 start_block (lexer.Location);
5327 Block assign_block = current_block;
5329 if ($3 is DictionaryEntry){
5330 DictionaryEntry de = (DictionaryEntry) $3;
5331 Location l = (Location) $1;
5333 Expression type = (Expression) de.Key;
5334 ArrayList var_declarators = (ArrayList) de.Value;
5336 ArrayList vars = new ArrayList (4);
5338 foreach (VariableDeclaration decl in var_declarators){
5340 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5343 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5345 Expression expr = decl.expression_or_array_initializer;
5347 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5350 LocalVariableReference var;
5352 // Get a writable reference to this read-only variable.
5353 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5355 // This is so that it is not a warning on using variables
5358 vars.Add (new DictionaryEntry (var, expr));
5360 // Assign a = new Assign (var, expr, decl.Location);
5361 // assign_block.AddStatement (new StatementExpression (a));
5364 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5365 // It can be referred to as $5 below.
5366 $$ = new DictionaryEntry (type, vars);
5373 Using u = new Using ($5, (Statement) $6, (Location) $1);
5374 current_block.AddStatement (u);
5375 $$ = end_block (lexer.Location);
5379 resource_acquisition
5380 : local_variable_declaration
5390 ++lexer.query_parsing;
5394 if (--lexer.query_parsing == 1)
5395 lexer.query_parsing = 0;
5397 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5399 from.Tail.Next = (Linq.AQueryClause)$3;
5402 current_block.SetEndLocation (lexer.Location);
5403 current_block = current_block.Parent;
5408 : FROM IDENTIFIER IN expression
5410 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5411 LocatedToken lt = (LocatedToken) $2;
5413 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
5414 $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
5416 | FROM type IDENTIFIER IN expression
5418 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5419 LocatedToken lt = (LocatedToken) $3;
5421 Expression type = (Expression)$2;
5422 current_block.AddVariable (type, lt.Value, lt.Location);
5423 $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
5428 : FROM IDENTIFIER IN expression
5430 LocatedToken lt = (LocatedToken) $2;
5432 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5433 lt.Value, lt.Location);
5435 $$ = new Linq.SelectMany (lt, (Expression)$4);
5437 | FROM type IDENTIFIER IN expression
5439 LocatedToken lt = (LocatedToken) $3;
5441 Expression type = (Expression)$2;
5442 current_block.AddVariable (type, lt.Value, lt.Location);
5443 $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
5448 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5450 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5453 head.Next = (Linq.AQueryClause)$3;
5456 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5457 clause.Tail.Next = head;
5465 select_or_group_clause
5468 $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
5470 | GROUP expression BY expression
5472 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5476 opt_query_body_clauses
5478 | query_body_clauses
5483 | query_body_clauses query_body_clause
5485 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5499 : LET IDENTIFIER ASSIGN expression
5501 LocatedToken lt = (LocatedToken) $2;
5502 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5503 lt.Value, lt.Location);
5504 $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
5509 : WHERE boolean_expression
5511 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5516 : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5518 Location loc = GetLocation ($1);
5519 LocatedToken lt = (LocatedToken) $2;
5520 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5521 lt.Value, lt.Location);
5524 $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
5525 (Expression)$8, loc);
5527 LocatedToken lt_into = (LocatedToken) $9;
5528 $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
5529 (Expression)$8, lt_into, loc);
5532 | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5534 Location loc = GetLocation ($1);
5535 LocatedToken lt = (LocatedToken) $3;
5536 current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
5538 Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
5540 $$ = new Linq.Join (lt, cast, (Expression)$7,
5541 (Expression)$9, loc);
5543 LocatedToken lt_into = (LocatedToken) $10;
5544 $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
5545 (Expression)$9, lt_into, loc);
5567 | order_by COMMA orderings_then_by
5569 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5579 | orderings_then_by COMMA then_by
5581 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5589 $$ = new Linq.OrderByAscending ((Expression)$1);
5591 | expression ASCENDING
5593 $$ = new Linq.OrderByAscending ((Expression)$1);
5595 | expression DESCENDING
5597 $$ = new Linq.OrderByDescending ((Expression)$1);
5604 $$ = new Linq.ThenByAscending ((Expression)$1);
5606 | expression ASCENDING
5608 $$ = new Linq.ThenByAscending ((Expression)$1);
5610 | expression DESCENDING
5612 $$ = new Linq.ThenByDescending ((Expression)$1);
5617 opt_query_continuation
5621 // query continuation block is not linked with query block but with block
5622 // before. This means each query can use same range variable names for
5623 // different identifiers.
5625 current_block.SetEndLocation (GetLocation ($1));
5626 current_block = current_block.Parent;
5627 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5629 LocatedToken lt = (LocatedToken) $2;
5630 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5631 lt.Value, lt.Location);
5635 $$ = new Linq.QueryExpression ((LocatedToken) $2,
5636 (Linq.AQueryClause)$4);
5643 // A class used to pass around variable declarations and constants
5645 public class VariableDeclaration {
5646 public string identifier;
5647 public Expression expression_or_array_initializer;
5648 public Location Location;
5649 public Attributes OptAttributes;
5650 public string DocComment;
5652 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5654 this.identifier = lt.Value;
5655 if (eoai is ArrayList) {
5656 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5658 this.expression_or_array_initializer = (Expression)eoai;
5660 this.Location = lt.Location;
5661 this.OptAttributes = opt_attrs;
5664 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5670 // A class used to hold info about an indexer declarator
5672 public class IndexerDeclaration {
5673 public Expression type;
5674 public MemberName interface_type;
5675 public Parameters param_list;
5676 public Location location;
5678 public IndexerDeclaration (Expression type, MemberName interface_type,
5679 Parameters param_list, Location loc)
5682 this.interface_type = interface_type;
5683 this.param_list = param_list;
5684 this.location = loc;
5689 // We use this when we do not have an object in advance that is an IAnonymousHost
5691 public class SimpleAnonymousHost : IAnonymousHost {
5692 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5695 ArrayList anonymous_methods;
5697 public static SimpleAnonymousHost GetSimple () {
5698 Simple.yields = false;
5699 Simple.anonymous_methods = null;
5703 public void SetYields ()
5708 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5710 if (anonymous_methods == null)
5711 anonymous_methods = new ArrayList ();
5712 anonymous_methods.Add (anonymous);
5715 public void Propagate (IAnonymousHost real_host)
5718 real_host.SetYields ();
5719 if (anonymous_methods != null) {
5720 foreach (AnonymousMethodExpression ame in anonymous_methods)
5721 real_host.AddAnonymousMethod (ame);
5727 // A class used to hold info about an operator declarator
5729 struct OperatorDeclaration {
5730 public readonly Operator.OpType optype;
5731 public readonly Expression ret_type;
5732 public readonly Location location;
5734 public OperatorDeclaration (Operator.OpType op, Expression ret_type, Location location)
5737 this.ret_type = ret_type;
5738 this.location = location;
5742 void Error_ExpectingTypeName (Expression expr)
5744 if (expr is Invocation){
5745 Report.Error (1002, expr.Location, "Expecting `;'");
5747 expr.Error_InvalidExpressionStatement ();
5751 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5753 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5757 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5759 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5760 Parameter.GetModifierSignature (mod));
5763 static void Error_TypeExpected (Location loc)
5765 Report.Error (1031, loc, "Type expected");
5768 void push_current_class (TypeContainer tc, object partial_token)
5770 if (partial_token != null)
5771 current_container = current_container.AddPartial (tc);
5773 current_container = current_container.AddTypeContainer (tc);
5777 DeclSpace pop_current_class ()
5779 DeclSpace retval = current_class;
5781 current_class = current_class.Parent;
5782 current_container = current_class.PartialContainer;
5788 // Given the @class_name name, it creates a fully qualified name
5789 // based on the containing declaration space
5792 MakeName (MemberName class_name)
5794 Namespace ns = current_namespace.NS;
5796 if (current_container.Name.Length == 0){
5797 if (ns.Name.Length != 0)
5798 return new MemberName (ns.MemberName, class_name);
5802 return new MemberName (current_container.MemberName, class_name);
5806 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5808 Block implicit_block;
5809 ArrayList inits = null;
5812 // We use the `Used' property to check whether statements
5813 // have been added to the current block. If so, we need
5814 // to create another block to contain the new declaration
5815 // otherwise, as an optimization, we use the same block to
5816 // add the declaration.
5818 // FIXME: A further optimization is to check if the statements
5819 // that were added were added as part of the initialization
5820 // below. In which case, no other statements have been executed
5821 // and we might be able to reduce the number of blocks for
5822 // situations like this:
5824 // int j = 1; int k = j + 1;
5826 if (current_block.Used)
5827 implicit_block = new Block (current_block, loc, Location.Null);
5829 implicit_block = current_block;
5831 foreach (VariableDeclaration decl in variable_declarators){
5833 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5834 if (decl.expression_or_array_initializer != null){
5836 inits = new ArrayList (4);
5843 return implicit_block;
5845 foreach (VariableDeclaration decl in inits){
5847 Expression expr = decl.expression_or_array_initializer;
5849 LocalVariableReference var;
5850 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5852 assign = new Assign (var, expr, decl.Location);
5854 implicit_block.AddStatement (new StatementExpression (assign));
5857 return implicit_block;
5860 Block declare_local_constants (Expression type, ArrayList declarators)
5862 Block implicit_block;
5864 if (current_block.Used)
5865 implicit_block = new Block (current_block);
5867 implicit_block = current_block;
5869 foreach (VariableDeclaration decl in declarators){
5870 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5873 return implicit_block;
5876 string CheckAttributeTarget (string a, Location l)
5879 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5883 Report.Warning (658, 1, l,
5884 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5885 return string.Empty;
5888 static bool IsUnaryOperator (Operator.OpType op)
5892 case Operator.OpType.LogicalNot:
5893 case Operator.OpType.OnesComplement:
5894 case Operator.OpType.Increment:
5895 case Operator.OpType.Decrement:
5896 case Operator.OpType.True:
5897 case Operator.OpType.False:
5898 case Operator.OpType.UnaryPlus:
5899 case Operator.OpType.UnaryNegation:
5905 void syntax_error (Location l, string msg)
5907 Report.Error (1003, l, "Syntax error, " + msg);
5910 void note (string s)
5912 // Used to put annotations
5917 public Tokenizer Lexer {
5923 static CSharpParser ()
5925 oob_stack = new Stack ();
5928 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5930 this.name = file.Name;
5932 current_namespace = new NamespaceEntry (null, file, null);
5933 current_class = current_namespace.SlaveDeclSpace;
5934 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5936 lexer = new Tokenizer (reader, file, defines);
5939 public void parse ()
5941 int errors = Report.Errors;
5943 if (yacc_verbose_flag > 1)
5944 yyparse (lexer, new yydebug.yyDebugSimple ());
5947 Tokenizer tokenizer = lexer as Tokenizer;
5948 tokenizer.cleanup ();
5949 } catch (Exception e){
5951 // Removed for production use, use parser verbose to get the output.
5953 // Console.WriteLine (e);
5954 if (Report.Errors == errors)
5955 Report.Error (-25, lexer.Location, "Parsing error");
5956 if (yacc_verbose_flag > 0)
5957 Console.WriteLine (e);
5960 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5961 throw new InternalErrorException ("who set it?");
5964 static void CheckToken (int error, int yyToken, string msg, Location loc)
5966 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5967 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5969 Report.Error (error, loc, msg);
5972 void CheckIdentifierToken (int yyToken, Location loc)
5974 CheckToken (1041, yyToken, "Identifier expected", loc);
5977 string ConsumeStoredComment ()
5979 string s = tmpComment;
5981 Lexer.doc_state = XmlCommentState.Allowed;
5985 Location GetLocation (object obj)
5987 if (obj is MemberCore)
5988 return ((MemberCore) obj).Location;
5989 if (obj is MemberName)
5990 return ((MemberName) obj).Location;
5991 if (obj is LocatedToken)
5992 return ((LocatedToken) obj).Location;
5993 if (obj is Location)
5994 return (Location) obj;
5995 return lexer.Location;
5998 void start_block (Location loc)
6000 if (current_block == null || parsing_anonymous_method) {
6001 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6002 parsing_anonymous_method = false;
6004 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6009 end_block (Location loc)
6011 Block retval = current_block.Explicit;
6012 retval.SetEndLocation (loc);
6013 current_block = retval.Parent;
6018 start_anonymous (bool lambda, Parameters parameters, Location loc)
6020 oob_stack.Push (current_anonymous_method);
6021 oob_stack.Push (current_local_parameters);
6023 current_local_parameters = parameters;
6025 ToplevelBlock top_current_block = current_block == null ? null : current_block.Toplevel;
6027 current_anonymous_method = lambda
6028 ? new LambdaExpression (
6029 current_anonymous_method, current_generic_method, current_container,
6030 parameters, top_current_block, loc)
6031 : new AnonymousMethodExpression (
6032 current_anonymous_method, current_generic_method, current_container,
6033 parameters, top_current_block, loc);
6035 // Force the next block to be created as a ToplevelBlock
6036 parsing_anonymous_method = true;
6040 * Completes the anonymous method processing, if lambda_expr is null, this
6041 * means that we have a Statement instead of an Expression embedded
6043 AnonymousMethodExpression
6044 end_anonymous (ToplevelBlock anon_block, Location loc)
6046 AnonymousMethodExpression retval;
6048 if (RootContext.Version == LanguageVersion.ISO_1){
6049 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6052 current_anonymous_method.Block = anon_block;
6053 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
6054 anonymous_host.AddAnonymousMethod (current_anonymous_method);
6056 retval = current_anonymous_method;
6059 current_local_parameters = (Parameters) oob_stack.Pop ();
6060 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();