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.
30 using System.Collections;
35 public class CSharpParser {
36 NamespaceEntry current_namespace;
37 TypeContainer current_container;
38 DeclSpace current_class;
41 /// Current block is used to add statements as we find
46 Delegate current_delegate;
48 GenericMethod current_generic_method;
49 AnonymousMethodExpression current_anonymous_method;
52 /// This is used by the unary_expression code to resolve
53 /// a name against a parameter.
56 // FIXME: This is very ugly and it's very hard to reset it correctly
57 // on all places, especially when some parameters are autogenerated.
58 Parameters current_local_parameters;
61 /// Using during property parsing to describe the implicit
62 /// value parameter that is passed to the "set" and "get"accesor
63 /// methods (properties and indexers).
65 FullNamedExpression implicit_value_parameter_type;
66 Parameters indexer_parameters;
69 /// Hack to help create non-typed array initializer
71 public static FullNamedExpression current_array_type;
72 FullNamedExpression pushed_current_array_type;
75 /// Used to determine if we are parsing the get/set pair
76 /// of an indexer or a property
80 bool parsing_anonymous_method;
83 /// An out-of-band stack.
85 static Stack oob_stack;
93 /// Controls the verbosity of the errors produced by the parser
95 static public int yacc_verbose_flag;
98 /// Used by the interactive shell, flags whether EOF was reached
99 /// and an error was produced
101 public bool UnexpectedEOF;
104 /// The current file.
106 CompilationUnit file;
109 /// Temporary Xml documentation cache.
110 /// For enum types, we need one more temporary store.
113 string enumTypeComment;
115 /// Current attribute target
116 string current_attr_target;
118 /// assembly and module attribute definitions are enabled
119 bool global_attrs_enabled = true;
120 bool has_get, has_set;
121 bool parameter_modifiers_not_allowed;
122 bool params_modifiers_not_allowed;
123 bool arglist_allowed;
126 /// When using the interactive parser, this holds the
127 /// resulting expression
128 public object InteractiveResult;
131 // Keeps track of global data changes to undo on parser error
135 // A counter to create new class names in interactive mode
136 static int class_count;
140 %token NONE /* This token is never returned by our lexer */
141 %token ERROR // This is used not by the parser, but by the tokenizer.
145 *These are the C# keywords
231 %token QUERY_FIRST_TOKEN
244 %token QUERY_LAST_TOKEN
245 %token INTERR_NULLABLE
247 /* C# keywords which are not really keywords */
253 /* C# single character operators/punctuation. */
271 %token OP_GENERICS_LT
272 %token OP_GENERICS_LT_DECL
274 %token OP_GENERICS_GT
284 /* C# multi-character operators. */
289 %token OP_SHIFT_RIGHT
296 %token OP_MULT_ASSIGN
301 %token OP_SHIFT_LEFT_ASSIGN
302 %token OP_SHIFT_RIGHT_ASSIGN
310 %token LITERAL_INTEGER
312 %token LITERAL_DOUBLE
313 %token LITERAL_DECIMAL
314 %token LITERAL_CHARACTER
315 %token LITERAL_STRING
318 %token OPEN_PARENS_LAMBDA
319 %token CLOSE_PARENS_CAST
320 %token CLOSE_PARENS_NO_CAST
321 %token CLOSE_PARENS_OPEN_PARENS
322 %token CLOSE_PARENS_MINUS
323 %token DEFAULT_OPEN_PARENS
324 %token GENERIC_DIMENSION
327 // Make the parser go into eval mode parsing (statements and compilation units).
328 %token EVAL_STATEMENT_PARSER
329 %token EVAL_COMPILATION_UNIT_PARSER
330 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
332 /* Add precedence rules to solve dangling else s/r conflict */
341 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
343 %left STAR DIV PERCENT
344 %right BANG CARRET UMINUS
345 %nonassoc OP_INC OP_DEC
347 %left OPEN_BRACKET OPEN_BRACE
351 %start compilation_unit
355 : outer_declarations opt_EOF
356 | outer_declarations global_attributes opt_EOF
357 | global_attributes opt_EOF
358 | opt_EOF /* allow empty files */
359 | interactive_parsing opt_EOF
365 Lexer.check_incorrect_doc_comment ();
369 Lexer.check_incorrect_doc_comment ();
375 | outer_declarations outer_declaration
379 : extern_alias_directive
381 | namespace_member_declaration
384 extern_alias_directives
385 : extern_alias_directive
386 | extern_alias_directives extern_alias_directive
389 extern_alias_directive
390 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
392 LocatedToken lt = (LocatedToken) $2;
395 syntax_error (lt.Location, "`alias' expected");
396 } else if (RootContext.Version == LanguageVersion.ISO_1) {
397 Report.FeatureIsNotAvailable (lt.Location, "external alias");
399 lt = (LocatedToken) $3;
400 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
405 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
411 | using_directives using_directive
415 : using_alias_directive
417 if (RootContext.Documentation != null)
418 Lexer.doc_state = XmlCommentState.Allowed;
420 | using_namespace_directive
422 if (RootContext.Documentation != null)
423 Lexer.doc_state = XmlCommentState.Allowed;
427 using_alias_directive
428 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
430 LocatedToken lt = (LocatedToken) $2;
431 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
434 CheckIdentifierToken (yyToken, GetLocation ($2));
439 using_namespace_directive
440 : USING namespace_name SEMICOLON
442 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
447 // Strictly speaking, namespaces don't have attributes but
448 // we parse global attributes along with namespace declarations and then
451 namespace_declaration
452 : opt_attributes NAMESPACE qualified_identifier
454 MemberName name = (MemberName) $3;
457 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
460 current_namespace = new NamespaceEntry (
461 current_namespace, file, name.GetName ());
462 current_class = current_namespace.SlaveDeclSpace;
463 current_container = current_class.PartialContainer;
465 namespace_body opt_semicolon
467 current_namespace = current_namespace.Parent;
468 current_class = current_namespace.SlaveDeclSpace;
469 current_container = current_class.PartialContainer;
476 LocatedToken lt = (LocatedToken) $1;
477 $$ = new MemberName (lt.Value, lt.Location);
479 | qualified_identifier DOT IDENTIFIER
481 LocatedToken lt = (LocatedToken) $3;
482 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
486 syntax_error (lexer.Location, "`.' expected");
501 : namespace_or_type_name
503 MemberName name = (MemberName) $1;
505 if (name.TypeArguments != null)
506 syntax_error (lexer.Location, "namespace name expected");
515 if (RootContext.Documentation != null)
516 Lexer.doc_state = XmlCommentState.Allowed;
522 : opt_extern_alias_directives
524 opt_namespace_member_declarations
528 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
531 | opt_extern_alias_directives
533 opt_namespace_member_declarations
536 Report.Error (1513, lexer.Location, "Expected `}'");
545 opt_extern_alias_directives
547 | extern_alias_directives
550 opt_namespace_member_declarations
552 | namespace_member_declarations
555 namespace_member_declarations
556 : namespace_member_declaration
557 | namespace_member_declarations namespace_member_declaration
560 namespace_member_declaration
564 DeclSpace ds = (DeclSpace)$1;
566 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
567 Report.Error (1527, ds.Location,
568 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
571 current_namespace.DeclarationFound = true;
573 | namespace_declaration {
574 current_namespace.DeclarationFound = true;
577 | field_declaration {
578 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
580 | method_declaration {
581 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
588 | interface_declaration
590 | delegate_declaration
592 // Enable this when we have handled all errors, because this acts as a generic fallback
595 // Console.WriteLine ("Token=" + yyToken);
596 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
608 Attributes attrs = (Attributes)$1;
609 if (global_attrs_enabled) {
610 CodeGen.Assembly.AddAttributes (attrs.Attrs);
612 foreach (Attribute a in attrs.Attrs) {
613 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
624 global_attrs_enabled = false;
629 global_attrs_enabled = false;
638 if (current_attr_target != String.Empty) {
639 ArrayList sect = (ArrayList) $1;
641 if (global_attrs_enabled) {
642 if (current_attr_target == "module") {
643 CodeGen.Module.AddAttributes (sect);
645 } else if (current_attr_target != null && current_attr_target.Length > 0) {
646 CodeGen.Assembly.AddAttributes (sect);
649 $$ = new Attributes (sect);
652 if (RootContext.Documentation != null) {
653 Lexer.check_incorrect_doc_comment ();
655 XmlCommentState.Allowed;
659 $$ = new Attributes (sect);
664 current_attr_target = null;
666 | attribute_sections attribute_section
668 if (current_attr_target != String.Empty) {
669 Attributes attrs = $1 as Attributes;
670 ArrayList sect = (ArrayList) $2;
672 if (global_attrs_enabled) {
673 if (current_attr_target == "module") {
674 CodeGen.Module.AddAttributes (sect);
676 } else if (current_attr_target == "assembly") {
677 CodeGen.Assembly.AddAttributes (sect);
681 attrs = new Attributes (sect);
683 attrs.AddAttributes (sect);
687 attrs = new Attributes (sect);
689 attrs.AddAttributes (sect);
695 current_attr_target = null;
700 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
704 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
710 attribute_target_specifier
711 : attribute_target COLON
713 current_attr_target = (string)$1;
721 LocatedToken lt = (LocatedToken) $1;
722 $$ = CheckAttributeTarget (lt.Value, lt.Location);
724 | EVENT { $$ = "event"; }
725 | RETURN { $$ = "return"; }
728 string name = GetTokenName (yyToken);
729 $$ = CheckAttributeTarget (name, GetLocation ($1));
736 ArrayList attrs = new ArrayList (4);
742 | attribute_list COMMA attribute
744 ArrayList attrs = (ArrayList) $1;
754 ++lexer.parsing_block;
756 opt_attribute_arguments
758 --lexer.parsing_block;
759 MemberName mname = (MemberName) $1;
760 if (mname.IsGeneric) {
761 Report.Error (404, lexer.Location,
762 "'<' unexpected: attributes cannot be generic");
765 object [] arguments = (object []) $3;
766 MemberName left = mname.Left;
767 string identifier = mname.Name;
769 Expression left_expr = left == null ? null : left.GetTypeExpression ();
771 if (current_attr_target == String.Empty)
773 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
774 // FIXME: supply "nameEscaped" parameter here.
775 $$ = new GlobalAttribute (current_namespace, current_attr_target,
776 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
778 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
783 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
786 opt_attribute_arguments
787 : /* empty */ { $$ = null; }
788 | OPEN_PARENS attribute_arguments CLOSE_PARENS
796 : opt_positional_argument_list
801 $$ = new object [] { $1, null };
804 | positional_argument_list COMMA named_argument_list
806 $$ = new object[] { $1, $3 };
808 | named_argument_list
810 $$ = new object [] { null, $1 };
815 opt_positional_argument_list
816 : /* empty */ { $$ = null; }
817 | positional_argument_list
820 positional_argument_list
823 ArrayList args = new ArrayList (4);
824 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
828 | positional_argument_list COMMA expression
830 ArrayList args = (ArrayList) $1;
831 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
840 ArrayList args = new ArrayList (4);
845 | named_argument_list COMMA named_argument
847 ArrayList args = (ArrayList) $1;
852 | named_argument_list COMMA expression
854 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
860 : IDENTIFIER ASSIGN expression
862 // FIXME: keep location
863 $$ = new DictionaryEntry (
864 ((LocatedToken) $1).Value,
865 new Argument ((Expression) $3, Argument.AType.Expression));
871 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
874 opt_class_member_declarations
876 | class_member_declarations
879 class_member_declarations
880 : class_member_declaration
881 | class_member_declarations
882 class_member_declaration
885 class_member_declaration
886 : constant_declaration // done
887 | field_declaration // done
888 | method_declaration // done
889 | property_declaration // done
890 | event_declaration // done
891 | indexer_declaration // done
892 | operator_declaration // done
893 | constructor_declaration // done
894 | destructor_declaration // done
898 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
899 GetSymbolName (yyToken));
910 lexer.ConstraintsParsing = true;
912 type_declaration_name
914 MemberName name = MakeName ((MemberName) $6);
915 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
918 opt_type_parameter_constraints_clauses
920 lexer.ConstraintsParsing = false;
922 current_class.SetParameterInfo ((ArrayList) $9);
924 if (RootContext.Documentation != null)
925 current_container.DocComment = Lexer.consume_doc_comment ();
929 --lexer.parsing_declaration;
930 if (RootContext.Documentation != null)
931 Lexer.doc_state = XmlCommentState.Allowed;
935 $$ = pop_current_class ();
937 | opt_attributes opt_modifiers opt_partial STRUCT error {
938 CheckIdentifierToken (yyToken, GetLocation ($5));
945 if (RootContext.Documentation != null)
946 Lexer.doc_state = XmlCommentState.Allowed;
948 opt_struct_member_declarations CLOSE_BRACE
951 opt_struct_member_declarations
953 | struct_member_declarations
956 struct_member_declarations
957 : struct_member_declaration
958 | struct_member_declarations struct_member_declaration
961 struct_member_declaration
962 : constant_declaration
965 | property_declaration
967 | indexer_declaration
968 | operator_declaration
969 | constructor_declaration
973 * This is only included so we can flag error 575:
974 * destructors only allowed on class types
976 | destructor_declaration
987 int modflags = (int) $2;
988 foreach (VariableDeclaration constant in (ArrayList) $5){
989 Location l = constant.Location;
990 if ((modflags & Modifiers.STATIC) != 0) {
991 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
995 Const c = new Const (
996 current_class, (FullNamedExpression) $4, (string) constant.identifier,
997 (Expression) constant.expression_or_array_initializer, modflags,
1000 if (RootContext.Documentation != null) {
1001 c.DocComment = Lexer.consume_doc_comment ();
1002 Lexer.doc_state = XmlCommentState.Allowed;
1004 current_container.AddConstant (c);
1009 constant_declarators
1010 : constant_declarator
1012 ArrayList constants = new ArrayList (4);
1017 | constant_declarators COMMA constant_declarator
1020 ArrayList constants = (ArrayList) $1;
1029 ++lexer.parsing_block;
1031 constant_initializer
1033 --lexer.parsing_block;
1034 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1038 // A const field requires a value to be provided
1039 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1044 constant_initializer
1045 : constant_expression
1053 variable_declarators
1056 FullNamedExpression type = (FullNamedExpression) $3;
1057 if (type == TypeManager.system_void_expr)
1058 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1062 current_array_type = null;
1064 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1065 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1067 field.Initializer = var.expression_or_array_initializer;
1069 if (RootContext.Documentation != null) {
1070 field.DocComment = Lexer.consume_doc_comment ();
1071 Lexer.doc_state = XmlCommentState.Allowed;
1073 current_container.AddField (field);
1074 $$ = field; // FIXME: might be better if it points to the top item
1081 fixed_variable_declarators
1084 FullNamedExpression type = (FullNamedExpression) $4;
1088 current_array_type = null;
1090 foreach (VariableDeclaration var in (ArrayList) $5) {
1091 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1092 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1094 if (RootContext.Documentation != null) {
1095 field.DocComment = Lexer.consume_doc_comment ();
1096 Lexer.doc_state = XmlCommentState.Allowed;
1098 current_container.AddField (field);
1099 $$ = field; // FIXME: might be better if it points to the top item
1108 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1112 fixed_variable_declarators
1113 : fixed_variable_declarator
1115 ArrayList decl = new ArrayList (2);
1119 | fixed_variable_declarators COMMA fixed_variable_declarator
1121 ArrayList decls = (ArrayList) $1;
1127 fixed_variable_declarator
1128 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1130 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1132 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1134 Report.Error (443, lexer.Location, "Value or constant expected");
1135 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1140 local_variable_declarators
1141 : local_variable_declarator
1143 ArrayList decl = new ArrayList (4);
1148 | local_variable_declarators COMMA local_variable_declarator
1150 ArrayList decls = (ArrayList) $1;
1156 local_variable_declarator
1157 : IDENTIFIER ASSIGN local_variable_initializer
1159 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1163 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1165 | IDENTIFIER variable_bad_array
1171 local_variable_initializer
1174 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1176 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1180 $$ = new ArglistAccess ((Location) $1);
1182 | STACKALLOC simple_type
1184 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1185 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1189 variable_declarators
1190 : variable_declarator
1192 ArrayList decl = new ArrayList (4);
1197 | variable_declarators COMMA variable_declarator
1199 ArrayList decls = (ArrayList) $1;
1206 : member_declaration_name ASSIGN
1208 ++lexer.parsing_block;
1209 lexer.parsing_generic_declaration = false;
1211 variable_initializer
1213 --lexer.parsing_block;
1214 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1216 | member_declaration_name
1218 lexer.parsing_generic_declaration = false;
1219 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1221 | member_declaration_name variable_bad_array
1223 lexer.parsing_generic_declaration = false;
1229 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1231 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1232 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1236 variable_initializer
1243 if (RootContext.Documentation != null)
1244 Lexer.doc_state = XmlCommentState.NotAllowed;
1248 Method method = (Method) $1;
1249 method.Block = (ToplevelBlock) $3;
1250 current_container.AddMethod (method);
1252 if (current_container.Kind == Kind.Interface && method.Block != null) {
1253 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1256 current_generic_method = null;
1257 current_local_parameters = null;
1259 if (RootContext.Documentation != null)
1260 Lexer.doc_state = XmlCommentState.Allowed;
1268 method_declaration_name OPEN_PARENS
1270 arglist_allowed = true;
1272 opt_formal_parameter_list CLOSE_PARENS
1274 lexer.ConstraintsParsing = true;
1276 opt_type_parameter_constraints_clauses
1278 lexer.ConstraintsParsing = false;
1279 arglist_allowed = false;
1280 MemberName name = (MemberName) $4;
1281 current_local_parameters = (Parameters) $7;
1283 if ($10 != null && name.TypeArguments == null)
1284 Report.Error (80, lexer.Location,
1285 "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 (FullNamedExpression) $3, current_local_parameters);
1294 generic.SetParameterInfo ((ArrayList) $10);
1297 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1298 name, current_local_parameters, (Attributes) $1);
1300 current_generic_method = generic;
1302 if (RootContext.Documentation != null)
1303 method.DocComment = Lexer.consume_doc_comment ();
1310 VOID method_declaration_name
1311 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1313 lexer.ConstraintsParsing = true;
1315 opt_type_parameter_constraints_clauses
1317 lexer.ConstraintsParsing = false;
1319 MemberName name = (MemberName) $5;
1320 current_local_parameters = (Parameters) $7;
1322 if ($9 != null && name.TypeArguments == null)
1323 Report.Error (80, lexer.Location,
1324 "Constraints are not allowed on non-generic declarations");
1327 GenericMethod generic = null;
1328 if (name.TypeArguments != null) {
1329 generic = new GenericMethod (current_namespace, current_class, name,
1330 TypeManager.system_void_expr, current_local_parameters);
1332 generic.SetParameterInfo ((ArrayList) $10);
1335 int modifiers = (int) $2;
1338 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1339 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1341 if ((modifiers & invalid_partial_mod) != 0) {
1342 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1343 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1344 modifiers &= ~invalid_partial_mod;
1347 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1348 Report.Error (751, name.Location, "A partial method must be declared within a " +
1349 "partial class or partial struct");
1352 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1354 method = new Method (current_class, generic, TypeManager.system_void_expr,
1355 modifiers, name, current_local_parameters, (Attributes) $1);
1357 current_generic_method = generic;
1359 if (RootContext.Documentation != null)
1360 method.DocComment = Lexer.consume_doc_comment ();
1367 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1369 MemberName name = (MemberName) $5;
1370 Report.Error (1585, name.Location,
1371 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1373 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1374 0, name, (Parameters) $7, (Attributes) $1);
1376 current_local_parameters = (Parameters) $7;
1378 if (RootContext.Documentation != null)
1379 method.DocComment = Lexer.consume_doc_comment ();
1387 | SEMICOLON { $$ = null; }
1390 opt_formal_parameter_list
1391 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1392 | formal_parameter_list
1395 opt_parameter_list_no_mod
1396 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1399 parameter_modifiers_not_allowed = true;
1401 formal_parameter_list
1403 parameter_modifiers_not_allowed = false;
1408 formal_parameter_list
1411 ArrayList pars_list = (ArrayList) $1;
1413 Parameter [] pars = new Parameter [pars_list.Count];
1414 pars_list.CopyTo (pars);
1416 $$ = new Parameters (pars);
1418 | fixed_parameters COMMA parameter_array
1420 ArrayList pars_list = (ArrayList) $1;
1423 Parameter [] pars = new Parameter [pars_list.Count];
1424 pars_list.CopyTo (pars);
1426 $$ = new Parameters (pars);
1428 | fixed_parameters COMMA arglist_modifier
1430 ArrayList pars_list = (ArrayList) $1;
1431 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1433 Parameter [] pars = new Parameter [pars_list.Count];
1434 pars_list.CopyTo (pars);
1436 $$ = new Parameters (pars, true);
1438 | parameter_array COMMA error
1441 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1444 | fixed_parameters COMMA parameter_array COMMA error
1447 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1450 | arglist_modifier COMMA error
1452 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1455 | fixed_parameters COMMA ARGLIST COMMA error
1457 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1462 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1466 $$ = new Parameters (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1473 ArrayList pars = new ArrayList (4);
1478 | fixed_parameters COMMA fixed_parameter
1480 ArrayList pars = (ArrayList) $1;
1481 Parameter p = (Parameter)$3;
1483 if (p.HasExtensionMethodModifier)
1484 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1493 opt_parameter_modifier
1497 LocatedToken lt = (LocatedToken) $4;
1498 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1501 opt_parameter_modifier
1503 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1505 LocatedToken lt = (LocatedToken) $4;
1506 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1510 opt_parameter_modifier
1513 Report.Error (1001, GetLocation ($3), "Identifier expected");
1514 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
1517 opt_parameter_modifier
1520 CheckIdentifierToken (yyToken, GetLocation ($4));
1524 opt_parameter_modifier
1530 LocatedToken lt = (LocatedToken) $4;
1531 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1536 opt_parameter_modifier
1537 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1538 | parameter_modifiers
1542 : parameter_modifier
1546 | parameter_modifiers parameter_modifier
1548 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1549 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1550 if (((Parameter.Modifier)$1 & p2) == p2) {
1551 Error_DuplicateParameterModifier (lexer.Location, p2);
1553 switch (mod & ~Parameter.Modifier.This) {
1554 case Parameter.Modifier.REF:
1555 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1557 case Parameter.Modifier.OUT:
1558 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1561 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1572 if (parameter_modifiers_not_allowed)
1573 Error_ParameterModifierNotValid ("ref", (Location)$1);
1575 $$ = Parameter.Modifier.REF;
1579 if (parameter_modifiers_not_allowed)
1580 Error_ParameterModifierNotValid ("out", (Location)$1);
1582 $$ = Parameter.Modifier.OUT;
1586 if (parameter_modifiers_not_allowed)
1587 Error_ParameterModifierNotValid ("this", (Location)$1);
1589 if (RootContext.Version <= LanguageVersion.ISO_2)
1590 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1592 $$ = Parameter.Modifier.This;
1597 : opt_attributes params_modifier type IDENTIFIER
1599 LocatedToken lt = (LocatedToken) $4;
1600 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1602 | opt_attributes params_modifier type error {
1603 CheckIdentifierToken (yyToken, GetLocation ($4));
1611 if (params_modifiers_not_allowed)
1612 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1614 | PARAMS parameter_modifier
1616 Parameter.Modifier mod = (Parameter.Modifier)$2;
1617 if ((mod & Parameter.Modifier.This) != 0) {
1618 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1620 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1623 | PARAMS params_modifier
1625 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1632 if (!arglist_allowed)
1633 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1637 property_declaration
1641 member_declaration_name
1643 if (RootContext.Documentation != null)
1644 tmpComment = Lexer.consume_doc_comment ();
1648 implicit_value_parameter_type = (FullNamedExpression) $3;
1649 lexer.PropertyParsing = true;
1651 accessor_declarations
1653 lexer.PropertyParsing = false;
1654 has_get = has_set = false;
1659 Accessors accessors = (Accessors) $8;
1660 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1661 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1662 bool order = accessors != null ? accessors.declared_in_reverse : false;
1664 MemberName name = (MemberName) $4;
1665 FullNamedExpression ptype = (FullNamedExpression) $3;
1667 prop = new Property (current_class, ptype, (int) $2,
1668 name, (Attributes) $1, get_block, set_block, order, current_block);
1670 if (ptype == TypeManager.system_void_expr)
1671 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1673 if (accessors == null)
1674 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1676 if (current_container.Kind == Kind.Interface) {
1677 if (prop.Get.Block != null)
1678 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1680 if (prop.Set.Block != null)
1681 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1684 current_container.AddProperty (prop);
1685 implicit_value_parameter_type = null;
1687 if (RootContext.Documentation != null)
1688 prop.DocComment = ConsumeStoredComment ();
1693 accessor_declarations
1694 : get_accessor_declaration
1696 $$ = new Accessors ((Accessor) $1, null);
1698 | get_accessor_declaration accessor_declarations
1700 Accessors accessors = (Accessors) $2;
1701 accessors.get_or_add = (Accessor) $1;
1704 | set_accessor_declaration
1706 $$ = new Accessors (null, (Accessor) $1);
1708 | set_accessor_declaration accessor_declarations
1710 Accessors accessors = (Accessors) $2;
1711 accessors.set_or_remove = (Accessor) $1;
1712 accessors.declared_in_reverse = true;
1717 if (yyToken == Token.CLOSE_BRACE) {
1720 if (yyToken == Token.SEMICOLON)
1721 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1723 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1725 $$ = new Accessors (null, null);
1730 get_accessor_declaration
1731 : opt_attributes opt_modifiers GET
1733 // If this is not the case, then current_local_parameters has already
1734 // been set in indexer_declaration
1735 if (parsing_indexer == false)
1736 current_local_parameters = null;
1738 current_local_parameters = indexer_parameters;
1739 lexer.PropertyParsing = false;
1744 Report.Error (1007, (Location) $3, "Property accessor already defined");
1747 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1749 current_local_parameters = null;
1750 lexer.PropertyParsing = true;
1752 if (RootContext.Documentation != null)
1753 if (Lexer.doc_state == XmlCommentState.Error)
1754 Lexer.doc_state = XmlCommentState.NotAllowed;
1760 set_accessor_declaration
1761 : opt_attributes opt_modifiers SET
1763 Parameter implicit_value_parameter = new Parameter (
1764 implicit_value_parameter_type, "value",
1765 Parameter.Modifier.NONE, null, (Location) $3);
1767 if (!parsing_indexer) {
1768 current_local_parameters = new Parameters (new Parameter [] { implicit_value_parameter });
1770 current_local_parameters = Parameters.MergeGenerated (
1771 indexer_parameters, true, implicit_value_parameter, null);
1774 lexer.PropertyParsing = false;
1779 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1782 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1784 current_local_parameters = null;
1785 lexer.PropertyParsing = true;
1787 if (RootContext.Documentation != null
1788 && Lexer.doc_state == XmlCommentState.Error)
1789 Lexer.doc_state = XmlCommentState.NotAllowed;
1803 Error_SyntaxError (1043, yyToken);
1808 interface_declaration
1814 lexer.ConstraintsParsing = true;
1816 type_declaration_name
1818 MemberName name = MakeName ((MemberName) $6);
1819 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1822 opt_type_parameter_constraints_clauses
1824 lexer.ConstraintsParsing = false;
1826 current_class.SetParameterInfo ((ArrayList) $9);
1828 if (RootContext.Documentation != null) {
1829 current_container.DocComment = Lexer.consume_doc_comment ();
1830 Lexer.doc_state = XmlCommentState.Allowed;
1835 --lexer.parsing_declaration;
1836 if (RootContext.Documentation != null)
1837 Lexer.doc_state = XmlCommentState.Allowed;
1841 $$ = pop_current_class ();
1843 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1844 CheckIdentifierToken (yyToken, GetLocation ($5));
1850 opt_interface_member_declarations
1854 opt_interface_member_declarations
1856 | interface_member_declarations
1859 interface_member_declarations
1860 : interface_member_declaration
1861 | interface_member_declarations interface_member_declaration
1864 interface_member_declaration
1865 : constant_declaration
1867 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1871 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1873 | method_declaration
1874 | property_declaration
1876 | indexer_declaration
1877 | operator_declaration
1879 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1881 | constructor_declaration
1883 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1887 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1891 operator_declaration
1892 : opt_attributes opt_modifiers operator_declarator
1900 OperatorDeclaration decl = (OperatorDeclaration) $3;
1901 Operator op = new Operator (
1902 current_class, decl.optype, decl.ret_type, (int) $2,
1903 current_local_parameters,
1904 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1906 if (RootContext.Documentation != null) {
1907 op.DocComment = tmpComment;
1908 Lexer.doc_state = XmlCommentState.Allowed;
1911 // Note again, checking is done in semantic analysis
1912 current_container.AddOperator (op);
1914 current_local_parameters = null;
1920 | SEMICOLON { $$ = null; }
1924 : type_expression_or_array
1927 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1928 $$ = TypeManager.system_void_expr;
1933 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1935 params_modifiers_not_allowed = true;
1937 opt_parameter_list_no_mod CLOSE_PARENS
1939 params_modifiers_not_allowed = false;
1941 Location loc = (Location) $2;
1942 Operator.OpType op = (Operator.OpType) $3;
1943 current_local_parameters = (Parameters)$6;
1945 int p_count = current_local_parameters.Count;
1947 if (op == Operator.OpType.Addition)
1948 op = Operator.OpType.UnaryPlus;
1949 else if (op == Operator.OpType.Subtraction)
1950 op = Operator.OpType.UnaryNegation;
1953 if (IsUnaryOperator (op)) {
1955 Report.Error (1020, loc, "Overloadable binary operator expected");
1956 } else if (p_count != 1) {
1957 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1958 Operator.GetName (op));
1962 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1963 Operator.GetName (op));
1964 } else if (p_count != 2) {
1965 Report.Error (1019, loc, "Overloadable unary operator expected");
1969 if (RootContext.Documentation != null) {
1970 tmpComment = Lexer.consume_doc_comment ();
1971 Lexer.doc_state = XmlCommentState.NotAllowed;
1974 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
1976 | conversion_operator_declarator
1979 overloadable_operator
1981 : BANG { $$ = Operator.OpType.LogicalNot; }
1982 | TILDE { $$ = Operator.OpType.OnesComplement; }
1983 | OP_INC { $$ = Operator.OpType.Increment; }
1984 | OP_DEC { $$ = Operator.OpType.Decrement; }
1985 | TRUE { $$ = Operator.OpType.True; }
1986 | FALSE { $$ = Operator.OpType.False; }
1987 // Unary and binary:
1988 | PLUS { $$ = Operator.OpType.Addition; }
1989 | MINUS { $$ = Operator.OpType.Subtraction; }
1991 | STAR { $$ = Operator.OpType.Multiply; }
1992 | DIV { $$ = Operator.OpType.Division; }
1993 | PERCENT { $$ = Operator.OpType.Modulus; }
1994 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1995 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1996 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1997 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1998 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1999 | OP_EQ { $$ = Operator.OpType.Equality; }
2000 | OP_NE { $$ = Operator.OpType.Inequality; }
2001 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2002 | OP_LT { $$ = Operator.OpType.LessThan; }
2003 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2004 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2007 conversion_operator_declarator
2008 : IMPLICIT OPERATOR type OPEN_PARENS
2010 params_modifiers_not_allowed = true;
2012 opt_parameter_list_no_mod CLOSE_PARENS
2014 params_modifiers_not_allowed = false;
2016 Location loc = (Location) $2;
2017 current_local_parameters = (Parameters)$6;
2019 if (RootContext.Documentation != null) {
2020 tmpComment = Lexer.consume_doc_comment ();
2021 Lexer.doc_state = XmlCommentState.NotAllowed;
2024 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2026 | EXPLICIT OPERATOR type OPEN_PARENS
2028 params_modifiers_not_allowed = true;
2030 opt_parameter_list_no_mod CLOSE_PARENS
2032 params_modifiers_not_allowed = false;
2034 Location loc = (Location) $2;
2035 current_local_parameters = (Parameters)$6;
2037 if (RootContext.Documentation != null) {
2038 tmpComment = Lexer.consume_doc_comment ();
2039 Lexer.doc_state = XmlCommentState.NotAllowed;
2042 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2046 syntax_error ((Location) $1, "'operator' expected");
2050 syntax_error ((Location) $1, "'operator' expected");
2054 constructor_declaration
2055 : constructor_declarator
2058 Constructor c = (Constructor) $1;
2059 c.Block = (ToplevelBlock) $2;
2061 if (RootContext.Documentation != null)
2062 c.DocComment = ConsumeStoredComment ();
2064 current_container.AddConstructor (c);
2066 current_local_parameters = null;
2067 if (RootContext.Documentation != null)
2068 Lexer.doc_state = XmlCommentState.Allowed;
2072 constructor_declarator
2077 if (RootContext.Documentation != null) {
2078 tmpComment = Lexer.consume_doc_comment ();
2079 Lexer.doc_state = XmlCommentState.Allowed;
2082 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2084 current_local_parameters = (Parameters) $6;
2087 // start block here, so possible anonymous methods inside
2088 // constructor initializer can get correct parent block
2090 start_block (lexer.Location);
2092 opt_constructor_initializer
2094 LocatedToken lt = (LocatedToken) $3;
2095 int mods = (int) $2;
2096 ConstructorInitializer ci = (ConstructorInitializer) $9;
2098 Constructor c = new Constructor (current_class, lt.Value, mods,
2099 (Attributes) $1, current_local_parameters, ci, lt.Location);
2101 if (lt.Value != current_container.MemberName.Name) {
2102 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2103 } else if ((mods & Modifiers.STATIC) != 0) {
2104 if ((mods & Modifiers.Accessibility) != 0){
2105 Report.Error (515, c.Location,
2106 "`{0}': static constructor cannot have an access modifier",
2107 c.GetSignatureForError ());
2110 Report.Error (514, c.Location,
2111 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2112 c.GetSignatureForError ());
2123 | SEMICOLON { current_block = null; $$ = null; }
2126 opt_constructor_initializer
2128 | constructor_initializer
2131 constructor_initializer
2132 : COLON BASE OPEN_PARENS
2134 ++lexer.parsing_block;
2136 opt_argument_list CLOSE_PARENS
2138 --lexer.parsing_block;
2139 $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
2141 | COLON THIS OPEN_PARENS
2143 ++lexer.parsing_block;
2145 opt_argument_list CLOSE_PARENS
2147 --lexer.parsing_block;
2148 $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
2151 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2156 destructor_declaration
2157 : opt_attributes opt_modifiers TILDE
2159 if (RootContext.Documentation != null) {
2160 tmpComment = Lexer.consume_doc_comment ();
2161 Lexer.doc_state = XmlCommentState.NotAllowed;
2164 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2166 LocatedToken lt = (LocatedToken) $5;
2167 if (lt.Value != current_container.MemberName.Name){
2168 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2169 } else if (current_container.Kind != Kind.Class){
2170 Report.Error (575, lt.Location, "Only class types can contain destructor");
2172 Method d = new Destructor (
2173 current_class, TypeManager.system_void_expr, (int) $2, "Finalize",
2174 Parameters.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2175 if (RootContext.Documentation != null)
2176 d.DocComment = ConsumeStoredComment ();
2178 d.Block = (ToplevelBlock) $8;
2179 current_container.AddMethod (d);
2187 EVENT type variable_declarators SEMICOLON
2189 current_array_type = null;
2190 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2192 EventField e = new EventField (
2193 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2195 if (var.expression_or_array_initializer != null) {
2196 if (current_container.Kind == Kind.Interface) {
2197 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2200 e.Initializer = var.expression_or_array_initializer;
2203 if (var.MemberName.Left != null) {
2204 Report.Error (71, e.Location,
2205 "`{0}': An explicit interface implementation of an event must use property syntax",
2206 e.GetSignatureForError ());
2209 current_container.AddEvent (e);
2211 if (RootContext.Documentation != null) {
2212 e.DocComment = Lexer.consume_doc_comment ();
2213 Lexer.doc_state = XmlCommentState.Allowed;
2219 EVENT type member_declaration_name
2222 implicit_value_parameter_type = (FullNamedExpression) $4;
2223 current_local_parameters = new Parameters (
2224 new Parameter (implicit_value_parameter_type, "value",
2225 Parameter.Modifier.NONE, null, GetLocation ($3)));
2227 lexer.EventParsing = true;
2229 event_accessor_declarations
2231 lexer.EventParsing = false;
2235 MemberName name = (MemberName) $5;
2237 if (current_container.Kind == Kind.Interface) {
2238 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2242 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2243 current_container.Name, name.GetSignatureForError ());
2246 Accessors accessors = (Accessors) $8;
2248 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2249 // CS0073 is already reported, so no CS0065 here.
2252 Event e = new EventProperty (
2253 current_class, (FullNamedExpression) $4, (int) $2, name,
2254 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2255 if (RootContext.Documentation != null) {
2256 e.DocComment = Lexer.consume_doc_comment ();
2257 Lexer.doc_state = XmlCommentState.Allowed;
2260 current_container.AddEvent (e);
2261 implicit_value_parameter_type = null;
2264 current_local_parameters = null;
2266 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2268 MemberName mn = (MemberName) $5;
2269 if (mn.Left != null)
2270 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2272 if (RootContext.Documentation != null)
2273 Lexer.doc_state = XmlCommentState.Allowed;
2275 Error_SyntaxError (yyToken);
2280 event_accessor_declarations
2281 : add_accessor_declaration remove_accessor_declaration
2283 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2285 | remove_accessor_declaration add_accessor_declaration
2287 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2288 accessors.declared_in_reverse = true;
2291 | add_accessor_declaration { $$ = null; }
2292 | remove_accessor_declaration { $$ = null; }
2295 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2301 add_accessor_declaration
2302 : opt_attributes ADD
2304 lexer.EventParsing = false;
2308 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2309 lexer.EventParsing = true;
2312 | opt_attributes ADD error {
2313 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2316 | opt_attributes modifiers ADD {
2317 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2322 remove_accessor_declaration
2323 : opt_attributes REMOVE
2325 lexer.EventParsing = false;
2329 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2330 lexer.EventParsing = true;
2332 | opt_attributes REMOVE error {
2333 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2336 | opt_attributes modifiers REMOVE {
2337 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2343 : opt_attributes opt_modifiers
2344 member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2347 implicit_value_parameter_type = (FullNamedExpression) $3;
2348 indexer_parameters = (Parameters) $6;
2350 if (indexer_parameters.IsEmpty)
2351 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2353 if (RootContext.Documentation != null) {
2354 tmpComment = Lexer.consume_doc_comment ();
2355 Lexer.doc_state = XmlCommentState.Allowed;
2358 lexer.PropertyParsing = true;
2359 parsing_indexer = true;
2362 accessor_declarations
2364 lexer.PropertyParsing = false;
2365 has_get = has_set = false;
2366 parsing_indexer = false;
2370 Accessors accessors = (Accessors) $10;
2371 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2372 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2373 bool order = accessors != null ? accessors.declared_in_reverse : false;
2375 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2376 (MemberName)$4, (int) $2, (Parameters) $6, (Attributes) $1,
2377 get_block, set_block, order);
2379 if ($3 == TypeManager.system_void_expr)
2380 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2382 if (accessors == null)
2383 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2385 if (current_container.Kind == Kind.Interface) {
2386 if (indexer.Get.Block != null)
2387 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2389 if (indexer.Set.Block != null)
2390 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2393 if (RootContext.Documentation != null)
2394 indexer.DocComment = ConsumeStoredComment ();
2396 current_container.AddIndexer (indexer);
2398 current_local_parameters = null;
2399 implicit_value_parameter_type = null;
2400 indexer_parameters = null;
2407 ENUM type_declaration_name
2409 if (RootContext.Documentation != null)
2410 enumTypeComment = Lexer.consume_doc_comment ();
2415 MemberName name = (MemberName) $4;
2416 if (name.IsGeneric) {
2417 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2420 name = MakeName (name);
2421 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2422 name, (Attributes) $1);
2424 if (RootContext.Documentation != null)
2425 e.DocComment = enumTypeComment;
2428 EnumMember em = null;
2429 foreach (VariableDeclaration ev in (ArrayList) $7) {
2430 em = new EnumMember (
2431 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2432 ev.OptAttributes, ev.Location);
2434 // if (RootContext.Documentation != null)
2435 em.DocComment = ev.DocComment;
2437 e.AddEnumMember (em);
2439 if (RootContext.EvalMode)
2440 undo.AddTypeContainer (current_container, e);
2442 current_container.AddTypeContainer (e);
2450 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2453 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2454 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2455 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2456 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2457 Enum.Error_1008 (GetLocation ($2));
2463 Error_TypeExpected (lexer.Location);
2470 if (RootContext.Documentation != null)
2471 Lexer.doc_state = XmlCommentState.Allowed;
2473 opt_enum_member_declarations
2475 // here will be evaluated after CLOSE_BLACE is consumed.
2476 if (RootContext.Documentation != null)
2477 Lexer.doc_state = XmlCommentState.Allowed;
2485 opt_enum_member_declarations
2486 : /* empty */ { $$ = new ArrayList (4); }
2487 | enum_member_declarations opt_comma { $$ = $1; }
2490 enum_member_declarations
2491 : enum_member_declaration
2493 ArrayList l = new ArrayList (4);
2498 | enum_member_declarations COMMA enum_member_declaration
2500 ArrayList l = (ArrayList) $1;
2508 enum_member_declaration
2509 : opt_attributes IDENTIFIER
2511 VariableDeclaration vd = new VariableDeclaration (
2512 (LocatedToken) $2, null, (Attributes) $1);
2514 if (RootContext.Documentation != null) {
2515 vd.DocComment = Lexer.consume_doc_comment ();
2516 Lexer.doc_state = XmlCommentState.Allowed;
2521 | opt_attributes IDENTIFIER
2523 if (RootContext.Documentation != null) {
2524 tmpComment = Lexer.consume_doc_comment ();
2525 Lexer.doc_state = XmlCommentState.NotAllowed;
2528 ASSIGN constant_expression
2530 VariableDeclaration vd = new VariableDeclaration (
2531 (LocatedToken) $2, $5, (Attributes) $1);
2533 if (RootContext.Documentation != null)
2534 vd.DocComment = ConsumeStoredComment ();
2540 delegate_declaration
2544 member_type type_declaration_name
2545 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2547 MemberName name = MakeName ((MemberName) $5);
2548 Parameters p = (Parameters) $7;
2550 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2551 (int) $2, name, p, (Attributes) $1);
2553 if (RootContext.Documentation != null) {
2554 del.DocComment = Lexer.consume_doc_comment ();
2555 Lexer.doc_state = XmlCommentState.Allowed;
2558 current_container.AddDelegate (del);
2559 current_delegate = del;
2560 lexer.ConstraintsParsing = true;
2562 opt_type_parameter_constraints_clauses
2564 lexer.ConstraintsParsing = false;
2568 current_delegate.SetParameterInfo ((ArrayList) $10);
2569 $$ = current_delegate;
2571 current_delegate = null;
2582 if (RootContext.Version < LanguageVersion.ISO_2)
2583 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2589 namespace_or_type_name
2591 | qualified_alias_member IDENTIFIER opt_type_argument_list
2593 LocatedToken lt1 = (LocatedToken) $1;
2594 LocatedToken lt2 = (LocatedToken) $2;
2596 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2602 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2604 LocatedToken lt = (LocatedToken) $3;
2605 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2610 : IDENTIFIER opt_type_argument_list
2612 LocatedToken lt = (LocatedToken) $1;
2613 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2618 // Generics arguments (any type, without attributes)
2620 opt_type_argument_list
2621 : /* empty */ { $$ = null; }
2622 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2624 if (RootContext.Version < LanguageVersion.ISO_2)
2625 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2629 | OP_GENERICS_LT error
2631 Error_TypeExpected (lexer.Location);
2632 $$ = new TypeArguments (lexer.Location);
2639 TypeArguments type_args = new TypeArguments (lexer.Location);
2640 type_args.Add ((Expression) $1);
2643 | type_arguments COMMA type
2645 TypeArguments type_args = (TypeArguments) $1;
2646 type_args.Add ((Expression) $3);
2652 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2654 type_declaration_name
2657 lexer.parsing_generic_declaration = true;
2659 opt_type_parameter_list
2661 lexer.parsing_generic_declaration = false;
2662 LocatedToken lt = (LocatedToken) $1;
2663 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2667 member_declaration_name
2668 : method_declaration_name
2670 MemberName mn = (MemberName)$1;
2671 if (mn.TypeArguments != null)
2672 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2673 mn.GetSignatureForError ()));
2677 method_declaration_name
2678 : type_declaration_name
2679 | explicit_interface IDENTIFIER opt_type_parameter_list
2681 lexer.parsing_generic_declaration = false;
2682 LocatedToken lt = (LocatedToken) $2;
2683 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2687 indexer_declaration_name
2690 lexer.parsing_generic_declaration = false;
2691 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2693 | explicit_interface THIS
2695 lexer.parsing_generic_declaration = false;
2696 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2701 : IDENTIFIER opt_type_argument_list DOT
2703 LocatedToken lt = (LocatedToken) $1;
2704 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2706 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2708 LocatedToken lt1 = (LocatedToken) $1;
2709 LocatedToken lt2 = (LocatedToken) $2;
2711 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2713 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2715 LocatedToken lt = (LocatedToken) $2;
2716 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2720 opt_type_parameter_list
2721 : /* empty */ { $$ = null; }
2722 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2724 if (RootContext.Version < LanguageVersion.ISO_2)
2725 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2734 TypeArguments type_args = new TypeArguments (lexer.Location);
2735 type_args.Add ((Expression)$1);
2738 | type_parameters COMMA type_parameter
2740 TypeArguments type_args = (TypeArguments) $1;
2741 type_args.Add ((Expression)$3);
2747 : opt_attributes IDENTIFIER
2749 LocatedToken lt = (LocatedToken)$2;
2750 $$ = new TypeParameterName (lt.Value, (Attributes)$1, lt.Location);
2754 if (GetTokenName (yyToken) == "type")
2755 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2757 Error_SyntaxError (yyToken);
2759 $$ = new TypeParameterName ("", null, lexer.Location);
2764 // All types where void is allowed
2767 : type_expression_or_array
2770 $$ = TypeManager.system_void_expr;
2777 lexer.parsing_generic_declaration = true;
2782 // A type which does not allow `void' to be used
2785 : type_expression_or_array
2788 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2789 $$ = TypeManager.system_void_expr;
2797 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2798 $$ = TypeManager.system_void_expr;
2802 type_expression_or_array
2804 | type_expression rank_specifiers
2806 string rank_specifiers = (string) $2;
2807 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2812 : namespace_or_type_name opt_nullable
2814 MemberName name = (MemberName) $1;
2817 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2819 if (name.Left == null && name.Name == "var" &&
2820 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
2821 $$ = current_array_type = new VarExpr (name.Location);
2823 $$ = name.GetTypeExpression ();
2826 | builtin_types opt_nullable
2829 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2831 | type_expression STAR
2834 // Note that here only unmanaged types are allowed but we
2835 // can't perform checks during this phase - we do it during
2836 // semantic analysis.
2838 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2842 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2847 : builtin_types opt_nullable
2850 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2854 $$ = TypeManager.system_void_expr;
2856 | non_expression_type rank_specifiers
2858 Location loc = GetLocation ($1);
2860 loc = lexer.Location;
2861 $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
2863 | non_expression_type STAR
2865 Location loc = GetLocation ($1);
2867 loc = lexer.Location;
2868 $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
2871 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2872 // through this different path
2874 | multiplicative_expression STAR
2876 FullNamedExpression e = $1 as FullNamedExpression;
2878 $$ = new ComposedCast (e, "*");
2880 Error_TypeExpected (GetLocation ($1));
2887 ArrayList types = new ArrayList (2);
2891 | type_list COMMA base_type_name
2893 ArrayList types = (ArrayList) $1;
2902 if ($1 is ComposedCast)
2903 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2908 Error_TypeExpected (lexer.Location);
2913 * replaces all the productions for isolating the various
2914 * simple types, but we need this to reuse it easily in local_variable_type
2917 : OBJECT { $$ = TypeManager.system_object_expr; }
2918 | STRING { $$ = TypeManager.system_string_expr; }
2919 | BOOL { $$ = TypeManager.system_boolean_expr; }
2920 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2921 | FLOAT { $$ = TypeManager.system_single_expr; }
2922 | DOUBLE { $$ = TypeManager.system_double_expr; }
2927 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2928 | BYTE { $$ = TypeManager.system_byte_expr; }
2929 | SHORT { $$ = TypeManager.system_int16_expr; }
2930 | USHORT { $$ = TypeManager.system_uint16_expr; }
2931 | INT { $$ = TypeManager.system_int32_expr; }
2932 | UINT { $$ = TypeManager.system_uint32_expr; }
2933 | LONG { $$ = TypeManager.system_int64_expr; }
2934 | ULONG { $$ = TypeManager.system_uint64_expr; }
2935 | CHAR { $$ = TypeManager.system_char_expr; }
2942 $$ = TypeManager.system_void_expr;
2947 // Expressions, section 7.5
2952 : primary_expression_no_array_creation
2953 | array_creation_expression
2956 primary_expression_no_array_creation
2958 | IDENTIFIER opt_type_argument_list
2960 LocatedToken lt = (LocatedToken) $1;
2961 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2963 | parenthesized_expression
2964 | default_value_expression
2966 | invocation_expression
2970 | post_increment_expression
2971 | post_decrement_expression
2972 | object_or_delegate_creation_expression
2973 | anonymous_type_expression
2976 | checked_expression
2977 | unchecked_expression
2978 | pointer_member_access
2979 | anonymous_method_expression
2986 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2987 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2988 | NULL { $$ = new NullLiteral (lexer.Location); }
2992 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2993 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2994 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2999 object v = lexer.Value;
3002 $$ = new IntLiteral ((int) v, lexer.Location);
3003 } else if (v is uint)
3004 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3006 $$ = new LongLiteral ((Int64) v, lexer.Location);
3007 else if (v is ulong)
3008 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3010 Console.WriteLine ("OOPS. Unexpected result from scanner");
3015 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3016 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3019 parenthesized_expression_0
3020 : OPEN_PARENS expression CLOSE_PARENS
3023 lexer.Deambiguate_CloseParens ($$);
3024 // After this, the next token returned is one of
3025 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3026 // or CLOSE_PARENS_MINUS.
3028 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3031 parenthesized_expression
3032 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3036 | parenthesized_expression_0 CLOSE_PARENS
3040 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3042 // If a parenthesized expression is followed by a minus, we need to wrap
3043 // the expression inside a ParenthesizedExpression for the CS0075 check
3044 // in Binary.DoResolve().
3045 $$ = new ParenthesizedExpression ((Expression) $1);
3050 : primary_expression DOT IDENTIFIER opt_type_argument_list
3052 LocatedToken lt = (LocatedToken) $3;
3053 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3055 | predefined_type DOT IDENTIFIER opt_type_argument_list
3057 LocatedToken lt = (LocatedToken) $3;
3058 // TODO: Location is wrong as some predefined types doesn't hold a location
3059 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3061 | qualified_alias_member IDENTIFIER opt_type_argument_list
3063 LocatedToken lt1 = (LocatedToken) $1;
3064 LocatedToken lt2 = (LocatedToken) $2;
3066 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3070 invocation_expression
3071 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3073 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3075 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3077 $$ = new Invocation ((Expression) $1, new ArrayList ());
3079 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3081 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3083 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3085 ArrayList args = new ArrayList (1);
3087 $$ = new Invocation ((Expression) $1, args);
3089 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3091 ArrayList args = ((ArrayList) $4);
3093 $$ = new Invocation ((Expression) $1, args);
3097 opt_object_or_collection_initializer
3098 : /* empty */ { $$ = null; }
3099 | object_or_collection_initializer
3102 object_or_collection_initializer
3103 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3106 $$ = CollectionOrObjectInitializers.Empty;
3108 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3110 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3112 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3116 opt_member_initializer_list
3117 : /* empty */ { $$ = null; }
3118 | member_initializer_list
3124 member_initializer_list
3125 : member_initializer
3127 ArrayList a = new ArrayList ();
3131 | member_initializer_list COMMA member_initializer
3133 ArrayList a = (ArrayList)$1;
3140 : IDENTIFIER ASSIGN initializer_value
3142 LocatedToken lt = $1 as LocatedToken;
3143 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3145 | non_assignment_expression
3147 $$ = new CollectionElementInitializer ((Expression)$1);
3149 | OPEN_BRACE expression_list CLOSE_BRACE
3151 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3153 | OPEN_BRACE CLOSE_BRACE
3155 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3161 | object_or_collection_initializer
3165 : /* empty */ { $$ = null; }
3172 ArrayList list = new ArrayList (4);
3176 | argument_list COMMA argument
3178 ArrayList list = (ArrayList) $1;
3182 | argument_list COMMA
3184 Report.Error (839, GetLocation ($2), "An argument is missing");
3189 Report.Error (839, GetLocation ($1), "An argument is missing");
3197 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3199 | non_simple_argument
3206 : REF variable_reference
3208 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3210 | OUT variable_reference
3212 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3214 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3216 ArrayList list = (ArrayList) $3;
3217 Argument[] args = new Argument [list.Count];
3218 list.CopyTo (args, 0);
3220 Expression expr = new Arglist (args, (Location) $1);
3221 $$ = new Argument (expr, Argument.AType.Expression);
3223 | ARGLIST OPEN_PARENS CLOSE_PARENS
3225 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3229 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3234 : expression { note ("section 5.4"); $$ = $1; }
3238 : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
3240 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3242 | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3244 // LAMESPEC: Not allowed according to specification
3245 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3247 | primary_expression_no_array_creation rank_specifiers
3249 // So the super-trick is that primary_expression
3250 // can only be either a SimpleName or a MemberAccess.
3251 // The MemberAccess case arises when you have a fully qualified type-name like :
3253 // SimpleName is when you have
3256 Expression expr = (Expression) $1;
3257 if (expr is ComposedCast){
3258 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3259 } else if (expr is ATypeNameExpression){
3261 // So we extract the string corresponding to the SimpleName
3264 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3266 Error_ExpectingTypeName (expr);
3267 $$ = TypeManager.system_object_expr;
3270 current_array_type = (FullNamedExpression)$$;
3277 ArrayList list = new ArrayList (4);
3281 | expression_list COMMA expression
3283 ArrayList list = (ArrayList) $1;
3292 $$ = new This (current_block, (Location) $1);
3297 : BASE DOT IDENTIFIER opt_type_argument_list
3299 LocatedToken lt = (LocatedToken) $3;
3300 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3302 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3304 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3307 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3312 post_increment_expression
3313 : primary_expression OP_INC
3315 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3316 (Expression) $1, (Location) $2);
3320 post_decrement_expression
3321 : primary_expression OP_DEC
3323 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3324 (Expression) $1, (Location) $2);
3328 object_or_delegate_creation_expression
3329 : NEW simple_type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3332 if (RootContext.Version <= LanguageVersion.ISO_2)
3333 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3335 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3338 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3340 | NEW simple_type object_or_collection_initializer
3342 if (RootContext.Version <= LanguageVersion.ISO_2)
3343 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3345 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3350 array_creation_expression
3351 : NEW simple_type OPEN_BRACKET expression_list CLOSE_BRACKET
3352 opt_rank_specifier // shift/reduce on OPEN_BRACE
3353 opt_array_initializer
3355 $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3357 | NEW simple_type rank_specifiers opt_array_initializer
3360 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3362 $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3364 | NEW rank_specifiers array_initializer
3366 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3368 | NEW simple_type error
3370 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3375 anonymous_type_expression
3376 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3378 if (RootContext.Version <= LanguageVersion.ISO_2)
3379 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3381 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3385 anonymous_type_parameters_opt_comma
3386 : anonymous_type_parameters_opt
3387 | anonymous_type_parameters COMMA
3390 anonymous_type_parameters_opt
3392 | anonymous_type_parameters
3395 anonymous_type_parameters
3396 : anonymous_type_parameter
3398 ArrayList a = new ArrayList (4);
3402 | anonymous_type_parameters COMMA anonymous_type_parameter
3404 ArrayList a = (ArrayList) $1;
3410 anonymous_type_parameter
3411 : IDENTIFIER ASSIGN variable_initializer
3413 LocatedToken lt = (LocatedToken)$1;
3414 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3418 LocatedToken lt = (LocatedToken)$1;
3419 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3420 lt.Value, lt.Location);
3422 | BASE DOT IDENTIFIER opt_type_argument_list
3424 LocatedToken lt = (LocatedToken) $3;
3425 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3426 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3430 MemberAccess ma = (MemberAccess) $1;
3431 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3435 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3436 "Anonymous type members must be a member assignment, simple name or member access expression");
3451 opt_rank_specifier_or_nullable
3459 | opt_nullable rank_specifiers
3462 $$ = "?" + (string) $2;
3470 | rank_specifier rank_specifiers
3472 $$ = (string) $2 + (string) $1;
3477 : OPEN_BRACKET CLOSE_BRACKET
3481 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3483 $$ = "[" + (string) $2 + "]";
3485 | OPEN_BRACKET error CLOSE_BRACKET
3487 ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
3497 | dim_separators COMMA
3499 $$ = (string) $1 + ",";
3503 opt_array_initializer
3515 : OPEN_BRACE CLOSE_BRACE
3517 ArrayList list = new ArrayList (4);
3520 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3522 $$ = (ArrayList) $2;
3526 variable_initializer_list
3527 : variable_initializer
3529 ArrayList list = new ArrayList (4);
3533 | variable_initializer_list COMMA variable_initializer
3535 ArrayList list = (ArrayList) $1;
3541 Error_SyntaxError (yyToken);
3542 $$ = new ArrayList ();
3549 pushed_current_array_type = current_array_type;
3550 lexer.TypeOfParsing = true;
3552 OPEN_PARENS typeof_type_expression CLOSE_PARENS
3554 lexer.TypeOfParsing = false;
3555 Expression type = (Expression)$4;
3556 if (type == TypeManager.system_void_expr)
3557 $$ = new TypeOfVoid ((Location) $1);
3559 $$ = new TypeOf (type, (Location) $1);
3560 current_array_type = pushed_current_array_type;
3564 typeof_type_expression
3571 $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
3575 Error_TypeExpected (lexer.Location);
3581 : IDENTIFIER generic_dimension
3583 LocatedToken lt = (LocatedToken) $1;
3584 TypeArguments ta = (TypeArguments)$2;
3586 $$ = new MemberName (lt.Value, ta, lt.Location);
3588 | qualified_alias_member IDENTIFIER generic_dimension
3590 LocatedToken lt1 = (LocatedToken) $1;
3591 LocatedToken lt2 = (LocatedToken) $2;
3592 TypeArguments ta = (TypeArguments)$3;
3594 $$ = new MemberName (new MemberName (lt1.Value, lt1.Location), lt2.Value, ta, lt2.Location);
3596 | unbound_type_name DOT IDENTIFIER generic_dimension
3598 LocatedToken lt = (LocatedToken) $3;
3599 TypeArguments ta = (TypeArguments)$4;
3601 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3603 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3605 LocatedToken lt = (LocatedToken) $3;
3606 TypeArguments ta = (TypeArguments)$4;
3608 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3615 if (RootContext.Version < LanguageVersion.ISO_2)
3616 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3618 $$ = new TypeArguments ((int)$1, lexer.Location);
3622 qualified_alias_member
3623 : IDENTIFIER DOUBLE_COLON
3625 LocatedToken lt = (LocatedToken) $1;
3626 if (RootContext.Version == LanguageVersion.ISO_1)
3627 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3634 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3635 $$ = new SizeOf ((Expression) $3, (Location) $1);
3640 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3642 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3646 unchecked_expression
3647 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3649 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3653 pointer_member_access
3654 : primary_expression OP_PTR IDENTIFIER
3657 LocatedToken lt = (LocatedToken) $3;
3659 deref = new Indirection ((Expression) $1, lt.Location);
3660 $$ = new MemberAccess (deref, lt.Value);
3664 anonymous_method_expression
3665 : DELEGATE opt_anonymous_method_signature
3667 start_anonymous (false, (Parameters) $2, (Location) $1);
3671 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3675 opt_anonymous_method_signature
3676 : /* empty */ { $$ = null; }
3677 | anonymous_method_signature
3680 anonymous_method_signature
3683 params_modifiers_not_allowed = true;
3685 opt_formal_parameter_list CLOSE_PARENS
3687 params_modifiers_not_allowed = false;
3692 default_value_expression
3693 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3695 if (RootContext.Version < LanguageVersion.ISO_2)
3696 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3698 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3703 : primary_expression
3704 | BANG prefixed_unary_expression
3706 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3708 | TILDE prefixed_unary_expression
3710 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3716 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3718 $$ = new Cast ((Expression) $1, (Expression) $3);
3720 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3722 $$ = new Cast ((Expression) $1, (Expression) $3);
3724 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3726 $$ = new Cast ((Expression) $1, (Expression) $3);
3732 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3734 if ($2 == TypeManager.system_void_expr)
3735 Expression.Error_VoidInvalidInTheContext (GetLocation ($2));
3737 // TODO: wrong location
3738 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3743 // The idea to split this out is from Rhys' grammar
3744 // to solve the problem with casts.
3746 prefixed_unary_expression
3748 | PLUS prefixed_unary_expression
3750 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3752 | MINUS prefixed_unary_expression
3754 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3756 | OP_INC prefixed_unary_expression
3758 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3759 (Expression) $2, (Location) $1);
3761 | OP_DEC prefixed_unary_expression
3763 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3764 (Expression) $2, (Location) $1);
3766 | STAR prefixed_unary_expression
3768 $$ = new Indirection ((Expression) $2, (Location) $1);
3770 | BITWISE_AND prefixed_unary_expression
3772 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3776 multiplicative_expression
3777 : prefixed_unary_expression
3778 | multiplicative_expression STAR prefixed_unary_expression
3780 $$ = new Binary (Binary.Operator.Multiply,
3781 (Expression) $1, (Expression) $3);
3783 | multiplicative_expression DIV prefixed_unary_expression
3785 $$ = new Binary (Binary.Operator.Division,
3786 (Expression) $1, (Expression) $3);
3788 | multiplicative_expression PERCENT prefixed_unary_expression
3790 $$ = new Binary (Binary.Operator.Modulus,
3791 (Expression) $1, (Expression) $3);
3796 : multiplicative_expression
3797 | additive_expression PLUS multiplicative_expression
3799 $$ = new Binary (Binary.Operator.Addition,
3800 (Expression) $1, (Expression) $3);
3802 | additive_expression MINUS multiplicative_expression
3804 $$ = new Binary (Binary.Operator.Subtraction,
3805 (Expression) $1, (Expression) $3);
3807 | additive_expression AS type
3809 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3811 | additive_expression IS type
3813 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3818 : additive_expression
3819 | shift_expression OP_SHIFT_LEFT additive_expression
3821 $$ = new Binary (Binary.Operator.LeftShift,
3822 (Expression) $1, (Expression) $3);
3824 | shift_expression OP_SHIFT_RIGHT additive_expression
3826 $$ = new Binary (Binary.Operator.RightShift,
3827 (Expression) $1, (Expression) $3);
3831 relational_expression
3833 | relational_expression OP_LT shift_expression
3835 $$ = new Binary (Binary.Operator.LessThan,
3836 (Expression) $1, (Expression) $3);
3838 | relational_expression OP_GT shift_expression
3840 $$ = new Binary (Binary.Operator.GreaterThan,
3841 (Expression) $1, (Expression) $3);
3843 | relational_expression OP_LE shift_expression
3845 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3846 (Expression) $1, (Expression) $3);
3848 | relational_expression OP_GE shift_expression
3850 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3851 (Expression) $1, (Expression) $3);
3856 : relational_expression
3857 | equality_expression OP_EQ relational_expression
3859 $$ = new Binary (Binary.Operator.Equality,
3860 (Expression) $1, (Expression) $3);
3862 | equality_expression OP_NE relational_expression
3864 $$ = new Binary (Binary.Operator.Inequality,
3865 (Expression) $1, (Expression) $3);
3870 : equality_expression
3871 | and_expression BITWISE_AND equality_expression
3873 $$ = new Binary (Binary.Operator.BitwiseAnd,
3874 (Expression) $1, (Expression) $3);
3878 exclusive_or_expression
3880 | exclusive_or_expression CARRET and_expression
3882 $$ = new Binary (Binary.Operator.ExclusiveOr,
3883 (Expression) $1, (Expression) $3);
3887 inclusive_or_expression
3888 : exclusive_or_expression
3889 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3891 $$ = new Binary (Binary.Operator.BitwiseOr,
3892 (Expression) $1, (Expression) $3);
3896 conditional_and_expression
3897 : inclusive_or_expression
3898 | conditional_and_expression OP_AND inclusive_or_expression
3900 $$ = new Binary (Binary.Operator.LogicalAnd,
3901 (Expression) $1, (Expression) $3);
3905 conditional_or_expression
3906 : conditional_and_expression
3907 | conditional_or_expression OP_OR conditional_and_expression
3909 $$ = new Binary (Binary.Operator.LogicalOr,
3910 (Expression) $1, (Expression) $3);
3914 conditional_expression
3915 : conditional_or_expression
3916 | conditional_or_expression INTERR expression COLON expression
3918 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3920 | conditional_or_expression OP_COALESCING expression
3922 if (RootContext.Version < LanguageVersion.ISO_2)
3923 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3925 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3927 | primary_expression INTERR_NULLABLE opt_rank_specifier
3930 // TODO: Is this the best place to handle `= (foo?)a;' ?
3932 if (RootContext.Version < LanguageVersion.ISO_2)
3933 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
3935 $$ = new ComposedCast ((FullNamedExpression) $1, "?" + (string)$3, lexer.Location);
3939 assignment_expression
3940 : prefixed_unary_expression ASSIGN expression
3942 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3944 | prefixed_unary_expression OP_MULT_ASSIGN expression
3946 $$ = new CompoundAssign (
3947 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3949 | prefixed_unary_expression OP_DIV_ASSIGN expression
3951 $$ = new CompoundAssign (
3952 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3954 | prefixed_unary_expression OP_MOD_ASSIGN expression
3956 $$ = new CompoundAssign (
3957 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3959 | prefixed_unary_expression OP_ADD_ASSIGN expression
3961 $$ = new CompoundAssign (
3962 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3964 | prefixed_unary_expression OP_SUB_ASSIGN expression
3966 $$ = new CompoundAssign (
3967 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3969 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3971 $$ = new CompoundAssign (
3972 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3974 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3976 $$ = new CompoundAssign (
3977 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3979 | prefixed_unary_expression OP_AND_ASSIGN expression
3981 $$ = new CompoundAssign (
3982 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3984 | prefixed_unary_expression OP_OR_ASSIGN expression
3986 $$ = new CompoundAssign (
3987 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3989 | prefixed_unary_expression OP_XOR_ASSIGN expression
3991 $$ = new CompoundAssign (
3992 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3996 lambda_parameter_list
3999 ArrayList pars = new ArrayList (4);
4004 | lambda_parameter_list COMMA lambda_parameter
4006 ArrayList pars = (ArrayList) $1;
4007 Parameter p = (Parameter)$3;
4008 if (pars[0].GetType () != p.GetType ()) {
4009 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4018 : parameter_modifier type IDENTIFIER
4020 LocatedToken lt = (LocatedToken) $3;
4022 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4026 LocatedToken lt = (LocatedToken) $2;
4028 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4032 LocatedToken lt = (LocatedToken) $1;
4033 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4037 opt_lambda_parameter_list
4038 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
4039 | lambda_parameter_list {
4040 ArrayList pars_list = (ArrayList) $1;
4041 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4045 lambda_expression_body
4047 start_block (lexer.Location);
4051 Block b = end_block (lexer.Location);
4052 b.AddStatement (new ContextualReturn ((Expression) $2));
4063 LocatedToken lt = (LocatedToken) $1;
4064 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4065 start_anonymous (true, new Parameters (p), (Location) $2);
4067 lambda_expression_body
4069 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4071 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4073 start_anonymous (true, (Parameters) $2, (Location) $4);
4075 lambda_expression_body
4077 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4082 : assignment_expression
4083 | non_assignment_expression
4086 non_assignment_expression
4087 : conditional_expression
4109 lexer.ConstraintsParsing = true;
4111 type_declaration_name
4113 MemberName name = MakeName ((MemberName) $6);
4114 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4117 opt_type_parameter_constraints_clauses
4119 lexer.ConstraintsParsing = false;
4121 current_class.SetParameterInfo ((ArrayList) $9);
4123 if (RootContext.Documentation != null) {
4124 current_container.DocComment = Lexer.consume_doc_comment ();
4125 Lexer.doc_state = XmlCommentState.Allowed;
4130 --lexer.parsing_declaration;
4131 if (RootContext.Documentation != null)
4132 Lexer.doc_state = XmlCommentState.Allowed;
4136 $$ = pop_current_class ();
4144 { $$ = $1; } // location
4148 : /* empty */ { $$ = (int) 0; }
4154 | modifiers modifier
4159 if ((m1 & m2) != 0) {
4160 Location l = lexer.Location;
4161 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4163 $$ = (int) (m1 | m2);
4171 if (current_container == RootContext.ToplevelTypes)
4172 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4174 | PUBLIC { $$ = Modifiers.PUBLIC; }
4175 | PROTECTED { $$ = Modifiers.PROTECTED; }
4176 | INTERNAL { $$ = Modifiers.INTERNAL; }
4177 | PRIVATE { $$ = Modifiers.PRIVATE; }
4178 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4179 | SEALED { $$ = Modifiers.SEALED; }
4180 | STATIC { $$ = Modifiers.STATIC; }
4181 | READONLY { $$ = Modifiers.READONLY; }
4182 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4183 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4184 | EXTERN { $$ = Modifiers.EXTERN; }
4185 | VOLATILE { $$ = Modifiers.VOLATILE; }
4186 | UNSAFE { $$ = Modifiers.UNSAFE; }
4195 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4198 opt_type_parameter_constraints_clauses
4199 : /* empty */ { $$ = null; }
4200 | type_parameter_constraints_clauses
4204 type_parameter_constraints_clauses
4205 : type_parameter_constraints_clause {
4206 ArrayList constraints = new ArrayList (1);
4207 constraints.Add ($1);
4210 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4211 ArrayList constraints = (ArrayList) $1;
4212 Constraints new_constraint = (Constraints)$2;
4214 foreach (Constraints c in constraints) {
4215 if (new_constraint.TypeParameter == c.TypeParameter) {
4216 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4217 new_constraint.TypeParameter);
4221 constraints.Add (new_constraint);
4226 type_parameter_constraints_clause
4227 : WHERE IDENTIFIER COLON type_parameter_constraints {
4228 LocatedToken lt = (LocatedToken) $2;
4229 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4233 type_parameter_constraints
4234 : type_parameter_constraint {
4235 ArrayList constraints = new ArrayList (1);
4236 constraints.Add ($1);
4239 | type_parameter_constraints COMMA type_parameter_constraint {
4240 ArrayList constraints = (ArrayList) $1;
4242 constraints.Add ($3);
4247 type_parameter_constraint
4249 | NEW OPEN_PARENS CLOSE_PARENS {
4250 $$ = SpecialConstraint.Constructor;
4253 $$ = SpecialConstraint.ReferenceType;
4256 $$ = SpecialConstraint.ValueType;
4265 // A block is "contained" on the following places:
4267 // property_declaration as part of the accessor body (get/set)
4268 // operator_declaration
4269 // constructor_declaration
4270 // destructor_declaration
4271 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4276 ++lexer.parsing_block;
4277 start_block ((Location) $1);
4279 opt_statement_list CLOSE_BRACE
4281 --lexer.parsing_block;
4282 $$ = end_block ((Location) $4);
4289 ++lexer.parsing_block;
4290 current_block.StartLocation = GetLocation ($1);
4292 opt_statement_list CLOSE_BRACE
4294 --lexer.parsing_block;
4295 $$ = end_block ((Location) $4);
4306 | statement_list statement
4310 : declaration_statement
4312 if ($1 != null && (Block) $1 != current_block){
4313 current_block.AddStatement ((Statement) $1);
4314 current_block = (Block) $1;
4317 | valid_declaration_statement
4319 current_block.AddStatement ((Statement) $1);
4325 // The interactive_statement and its derivatives are only
4326 // used to provide a special version of `expression_statement'
4327 // that has a side effect of assigning the expression to
4330 interactive_statement_list
4331 : interactive_statement
4332 | interactive_statement_list interactive_statement
4335 interactive_statement
4336 : declaration_statement
4338 if ($1 != null && (Block) $1 != current_block){
4339 current_block.AddStatement ((Statement) $1);
4340 current_block = (Block) $1;
4343 | interactive_valid_declaration_statement
4345 current_block.AddStatement ((Statement) $1);
4350 valid_declaration_statement
4353 | expression_statement
4354 | selection_statement
4355 | iteration_statement
4359 | unchecked_statement
4366 interactive_valid_declaration_statement
4369 | interactive_expression_statement
4370 | selection_statement
4371 | iteration_statement
4375 | unchecked_statement
4383 : valid_declaration_statement
4384 | declaration_statement
4386 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4391 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4399 $$ = EmptyStatement.Value;
4406 LocatedToken lt = (LocatedToken) $1;
4407 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4409 if (current_block.AddLabel (labeled))
4410 current_block.AddStatement (labeled);
4415 declaration_statement
4416 : local_variable_declaration SEMICOLON
4418 current_array_type = null;
4420 DictionaryEntry de = (DictionaryEntry) $1;
4421 Expression e = (Expression) de.Key;
4423 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4427 | local_constant_declaration SEMICOLON
4429 current_array_type = null;
4431 DictionaryEntry de = (DictionaryEntry) $1;
4433 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4439 * The following is from Rhys' grammar:
4440 * > Types in local variable declarations must be recognized as
4441 * > expressions to prevent reduce/reduce errors in the grammar.
4442 * > The expressions are converted into types during semantic analysis.
4445 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4447 // FIXME: Do something smart here regarding the composition of the type.
4449 // Ok, the above "primary_expression" is there to get rid of
4450 // both reduce/reduce and shift/reduces in the grammar, it should
4451 // really just be "type_name". If you use type_name, a reduce/reduce
4452 // creeps up. If you use namespace_or_type_name (which is all we need
4453 // really) two shift/reduces appear.
4456 // So the super-trick is that primary_expression
4457 // can only be either a SimpleName or a MemberAccess.
4458 // The MemberAccess case arises when you have a fully qualified type-name like :
4460 // SimpleName is when you have
4463 Expression expr = (Expression) $1;
4464 string rank_or_nullable = (string) $2;
4466 if (expr is ComposedCast){
4467 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4468 } else if (expr is ATypeNameExpression){
4470 // So we extract the string corresponding to the SimpleName
4473 if (rank_or_nullable.Length == 0) {
4474 SimpleName sn = expr as SimpleName;
4475 if (sn != null && sn.Name == "var" &&
4476 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
4477 $$ = current_array_type = new VarExpr (sn.Location);
4481 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4484 Error_ExpectingTypeName (expr);
4485 $$ = TypeManager.system_object_expr;
4488 | builtin_types opt_rank_specifier_or_nullable
4490 if ((string) $2 == "")
4493 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4495 | VOID opt_rank_specifier
4497 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4498 $$ = TypeManager.system_void_expr;
4502 local_variable_pointer_type
4503 : primary_expression_no_array_creation STAR
4505 ATypeNameExpression expr = $1 as ATypeNameExpression;
4508 $$ = new ComposedCast (expr, "*");
4510 Error_ExpectingTypeName ((Expression)$1);
4514 | builtin_types STAR
4516 $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
4520 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4522 | local_variable_pointer_type STAR
4524 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4528 local_variable_declaration
4529 : local_variable_type local_variable_declarators
4532 VarExpr ve = $1 as VarExpr;
4534 ve.VariableInitializer = (ArrayList)$2;
4536 $$ = new DictionaryEntry ($1, $2);
4540 | local_variable_pointer_type opt_rank_specifier local_variable_declarators
4545 if ((string) $2 == "")
4546 t = (Expression) $1;
4548 t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
4549 $$ = new DictionaryEntry (t, $3);
4555 local_constant_declaration
4556 : CONST local_variable_type constant_declarators
4559 $$ = new DictionaryEntry ($2, $3);
4565 expression_statement
4566 : statement_expression SEMICOLON { $$ = $1; }
4569 interactive_expression_statement
4570 : interactive_statement_expression SEMICOLON { $$ = $1; }
4574 // We have to do the wrapping here and not in the case above,
4575 // because statement_expression is used for example in for_statement
4577 statement_expression
4580 Expression expr = (Expression) $1;
4581 ExpressionStatement s;
4583 s = expr as ExpressionStatement;
4586 expr.Error_InvalidExpressionStatement ();
4589 $$ = new StatementExpression (s);
4594 Error_SyntaxError (yyToken);
4599 interactive_statement_expression
4602 Expression expr = (Expression) $1;
4603 ExpressionStatement s;
4605 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4606 $$ = new StatementExpression (s);
4610 Error_SyntaxError (yyToken);
4621 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4624 Location l = (Location) $1;
4626 $$ = new If ((Expression) $3, (Statement) $5, l);
4628 // FIXME: location for warning should be loc property of $5.
4629 if ($5 == EmptyStatement.Value)
4630 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4633 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4634 embedded_statement ELSE embedded_statement
4636 Location l = (Location) $1;
4638 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4640 // FIXME: location for warning should be loc property of $5 and $7.
4641 if ($5 == EmptyStatement.Value)
4642 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4643 if ($7 == EmptyStatement.Value)
4644 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4649 : SWITCH OPEN_PARENS
4651 if (switch_stack == null)
4652 switch_stack = new Stack (2);
4653 switch_stack.Push (current_block);
4655 expression CLOSE_PARENS
4658 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4659 current_block = (Block) switch_stack.Pop ();
4675 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4676 $$ = new ArrayList ();
4684 ArrayList sections = new ArrayList (4);
4689 | switch_sections switch_section
4691 ArrayList sections = (ArrayList) $1;
4701 current_block = current_block.CreateSwitchBlock (lexer.Location);
4705 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4712 ArrayList labels = new ArrayList (4);
4717 | switch_labels switch_label
4719 ArrayList labels = (ArrayList) ($1);
4727 : CASE constant_expression COLON
4729 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4733 $$ = new SwitchLabel (null, (Location) $1);
4745 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4747 Location l = (Location) $1;
4748 $$ = new While ((Expression) $3, (Statement) $5, l);
4753 : DO embedded_statement
4754 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4756 Location l = (Location) $1;
4758 $$ = new Do ((Statement) $2, (Expression) $5, l);
4764 opt_for_initializer SEMICOLON
4766 Location l = lexer.Location;
4768 Block assign_block = current_block;
4770 if ($3 is DictionaryEntry){
4771 DictionaryEntry de = (DictionaryEntry) $3;
4773 Expression type = (Expression) de.Key;
4774 ArrayList var_declarators = (ArrayList) de.Value;
4776 foreach (VariableDeclaration decl in var_declarators){
4780 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4784 Expression expr = decl.expression_or_array_initializer;
4786 LocalVariableReference var;
4787 var = new LocalVariableReference (assign_block, decl.identifier, l);
4790 Assign a = new SimpleAssign (var, expr, decl.Location);
4792 assign_block.AddStatement (new StatementExpression (a));
4796 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4797 // This can be referred to as $5 below.
4803 opt_for_condition SEMICOLON
4804 opt_for_iterator CLOSE_PARENS
4807 Location l = (Location) $1;
4809 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4811 current_block.AddStatement (f);
4813 $$ = end_block (lexer.Location);
4818 : /* empty */ { $$ = EmptyStatement.Value; }
4823 : local_variable_declaration
4824 | statement_expression_list
4828 : /* empty */ { $$ = null; }
4829 | boolean_expression
4833 : /* empty */ { $$ = EmptyStatement.Value; }
4838 : statement_expression_list
4841 statement_expression_list
4842 : statement_expression
4844 // CHANGE: was `null'
4845 Statement s = (Statement) $1;
4846 Block b = new Block (current_block, s.loc, lexer.Location);
4851 | statement_expression_list COMMA statement_expression
4853 Block b = (Block) $1;
4855 b.AddStatement ((Statement) $3);
4861 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4863 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4866 | FOREACH OPEN_PARENS type IDENTIFIER IN
4867 expression CLOSE_PARENS
4869 start_block (lexer.Location);
4870 Block foreach_block = current_block;
4872 LocatedToken lt = (LocatedToken) $4;
4873 Location l = lt.Location;
4874 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4876 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4878 // Get a writable reference to this read-only variable.
4880 // Note that the $$ here refers to the value of _this_ code block,
4881 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4882 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4889 LocalVariableReference v = (LocalVariableReference) $8;
4890 Location l = (Location) $1;
4893 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4894 current_block.AddStatement (f);
4897 $$ = end_block (lexer.Location);
4903 | continue_statement
4913 $$ = new Break ((Location) $1);
4918 : CONTINUE SEMICOLON
4920 $$ = new Continue ((Location) $1);
4925 : GOTO IDENTIFIER SEMICOLON
4927 LocatedToken lt = (LocatedToken) $2;
4928 $$ = new Goto (lt.Value, lt.Location);
4930 | GOTO CASE constant_expression SEMICOLON
4932 $$ = new GotoCase ((Expression) $3, (Location) $1);
4934 | GOTO DEFAULT SEMICOLON
4936 $$ = new GotoDefault ((Location) $1);
4941 : RETURN opt_expression SEMICOLON
4943 $$ = new Return ((Expression) $2, (Location) $1);
4948 : THROW opt_expression SEMICOLON
4950 $$ = new Throw ((Expression) $2, (Location) $1);
4955 : IDENTIFIER RETURN expression SEMICOLON
4957 LocatedToken lt = (LocatedToken) $1;
4958 string s = lt.Value;
4960 Report.Error (1003, lt.Location, "; expected");
4963 if (RootContext.Version == LanguageVersion.ISO_1){
4964 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4967 current_block.Toplevel.IsIterator = true;
4968 $$ = new Yield ((Expression) $3, lt.Location);
4970 | IDENTIFIER RETURN SEMICOLON
4972 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4975 | IDENTIFIER BREAK SEMICOLON
4977 LocatedToken lt = (LocatedToken) $1;
4978 string s = lt.Value;
4980 Report.Error (1003, lt.Location, "; expected");
4983 if (RootContext.Version == LanguageVersion.ISO_1){
4984 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4988 current_block.Toplevel.IsIterator = true;
4989 $$ = new YieldBreak (lt.Location);
4999 : TRY block catch_clauses
5001 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
5003 | TRY block FINALLY block
5005 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
5007 | TRY block catch_clauses FINALLY block
5009 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
5013 Report.Error (1524, (Location) $1, "Expected catch or finally");
5021 ArrayList l = new ArrayList (4);
5026 | catch_clauses catch_clause
5028 ArrayList l = (ArrayList) $1;
5036 : /* empty */ { $$ = null; }
5041 : CATCH opt_catch_args
5043 Expression type = null;
5046 DictionaryEntry cc = (DictionaryEntry) $2;
5047 type = (Expression) cc.Key;
5048 LocatedToken lt = (LocatedToken) cc.Value;
5051 ArrayList one = new ArrayList (4);
5053 one.Add (new VariableDeclaration (lt, null));
5055 start_block (lexer.Location);
5056 current_block = declare_local_variables (type, one, lt.Location);
5060 Expression type = null;
5062 Block var_block = null;
5065 DictionaryEntry cc = (DictionaryEntry) $2;
5066 type = (Expression) cc.Key;
5067 LocatedToken lt = (LocatedToken) cc.Value;
5071 var_block = end_block (lexer.Location);
5075 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5080 : /* empty */ { $$ = null; }
5085 : OPEN_PARENS type opt_identifier CLOSE_PARENS
5087 $$ = new DictionaryEntry ($2, $3);
5089 | OPEN_PARENS CLOSE_PARENS
5091 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5098 $$ = new Checked ((Block) $2);
5105 $$ = new Unchecked ((Block) $2);
5112 RootContext.CheckUnsafeOption ((Location) $1);
5114 $$ = new Unsafe ((Block) $3);
5120 type_and_void fixed_pointer_declarators
5123 ArrayList list = (ArrayList) $4;
5124 Expression type = (Expression) $3;
5125 Location l = (Location) $1;
5126 int top = list.Count;
5128 start_block (lexer.Location);
5130 for (int i = 0; i < top; i++){
5131 Pair p = (Pair) list [i];
5134 v = current_block.AddVariable (type, (string) p.First, l);
5138 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5146 Location l = (Location) $1;
5148 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5150 current_block.AddStatement (f);
5152 $$ = end_block (lexer.Location);
5156 fixed_pointer_declarators
5157 : fixed_pointer_declarator {
5158 ArrayList declarators = new ArrayList (4);
5160 declarators.Add ($1);
5163 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5165 ArrayList declarators = (ArrayList) $1;
5167 declarators.Add ($3);
5172 fixed_pointer_declarator
5173 : IDENTIFIER ASSIGN expression
5175 LocatedToken lt = (LocatedToken) $1;
5176 // FIXME: keep location
5177 $$ = new Pair (lt.Value, $3);
5181 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5187 : LOCK OPEN_PARENS expression CLOSE_PARENS
5193 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5198 : USING OPEN_PARENS local_variable_declaration CLOSE_PARENS
5200 start_block (lexer.Location);
5201 Block assign_block = current_block;
5203 DictionaryEntry de = (DictionaryEntry) $3;
5204 Location l = (Location) $1;
5206 Expression type = (Expression) de.Key;
5207 ArrayList var_declarators = (ArrayList) de.Value;
5209 Stack vars = new Stack ();
5211 foreach (VariableDeclaration decl in var_declarators) {
5212 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5215 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5217 Expression expr = decl.expression_or_array_initializer;
5219 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5222 LocalVariableReference var;
5224 // Get a writable reference to this read-only variable.
5225 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5227 // This is so that it is not a warning on using variables
5230 vars.Push (new DictionaryEntry (var, expr));
5232 // Assign a = new SimpleAssign (var, expr, decl.Location);
5233 // assign_block.AddStatement (new StatementExpression (a));
5236 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5237 // It can be referred to as $5 below.
5242 Statement stmt = (Statement) $6;
5243 Stack vars = (Stack) $5;
5244 Location l = (Location) $1;
5246 while (vars.Count > 0) {
5247 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5248 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5250 current_block.AddStatement (stmt);
5251 $$ = end_block (lexer.Location);
5253 | USING OPEN_PARENS expression CLOSE_PARENS
5255 start_block (lexer.Location);
5259 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5260 $$ = end_block (lexer.Location);
5270 ++lexer.query_parsing;
5274 if (--lexer.query_parsing == 1)
5275 lexer.query_parsing = 0;
5277 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5279 from.Tail.Next = (Linq.AQueryClause)$3;
5282 current_block.SetEndLocation (lexer.Location);
5283 current_block = current_block.Parent;
5288 : FROM IDENTIFIER IN expression
5290 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5291 LocatedToken lt = (LocatedToken) $2;
5293 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
5294 $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
5296 | FROM type IDENTIFIER IN expression
5298 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5299 LocatedToken lt = (LocatedToken) $3;
5301 Expression type = (Expression)$2;
5302 current_block.AddVariable (type, lt.Value, lt.Location);
5303 $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
5308 : FROM IDENTIFIER IN expression
5310 LocatedToken lt = (LocatedToken) $2;
5312 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5313 lt.Value, lt.Location);
5315 $$ = new Linq.SelectMany (lt, (Expression)$4);
5317 | FROM type IDENTIFIER IN expression
5319 LocatedToken lt = (LocatedToken) $3;
5321 Expression type = (Expression)$2;
5322 current_block.AddVariable (type, lt.Value, lt.Location);
5323 $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
5328 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5330 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5333 head.Next = (Linq.AQueryClause)$3;
5336 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5337 clause.Tail.Next = head;
5345 select_or_group_clause
5348 $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
5350 | GROUP expression BY expression
5352 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5356 opt_query_body_clauses
5358 | query_body_clauses
5363 | query_body_clauses query_body_clause
5365 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5379 : LET IDENTIFIER ASSIGN expression
5381 LocatedToken lt = (LocatedToken) $2;
5382 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5383 lt.Value, lt.Location);
5384 $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
5389 : WHERE boolean_expression
5391 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5396 : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5398 Location loc = GetLocation ($1);
5399 LocatedToken lt = (LocatedToken) $2;
5400 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5401 lt.Value, lt.Location);
5404 $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
5405 (Expression)$8, loc);
5407 LocatedToken lt_into = (LocatedToken) $9;
5408 $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
5409 (Expression)$8, lt_into, loc);
5412 | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5414 Location loc = GetLocation ($1);
5415 LocatedToken lt = (LocatedToken) $3;
5416 current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
5418 Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
5420 $$ = new Linq.Join (lt, cast, (Expression)$7,
5421 (Expression)$9, loc);
5423 LocatedToken lt_into = (LocatedToken) $10;
5424 $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
5425 (Expression)$9, lt_into, loc);
5447 | order_by COMMA orderings_then_by
5449 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5459 | orderings_then_by COMMA then_by
5461 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5469 $$ = new Linq.OrderByAscending ((Expression)$1);
5471 | expression ASCENDING
5473 $$ = new Linq.OrderByAscending ((Expression)$1);
5475 | expression DESCENDING
5477 $$ = new Linq.OrderByDescending ((Expression)$1);
5484 $$ = new Linq.ThenByAscending ((Expression)$1);
5486 | expression ASCENDING
5488 $$ = new Linq.ThenByAscending ((Expression)$1);
5490 | expression DESCENDING
5492 $$ = new Linq.ThenByDescending ((Expression)$1);
5497 opt_query_continuation
5501 // query continuation block is not linked with query block but with block
5502 // before. This means each query can use same range variable names for
5503 // different identifiers.
5505 current_block.SetEndLocation (GetLocation ($1));
5506 current_block = current_block.Parent;
5507 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5509 LocatedToken lt = (LocatedToken) $2;
5510 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5511 lt.Value, lt.Location);
5515 $$ = new Linq.QueryExpression ((LocatedToken) $2,
5516 (Linq.AQueryClause)$4);
5521 // Support for using the compiler as an interactive parser
5523 // The INTERACTIVE_PARSER token is first sent to parse our
5524 // productions; If the result is a Statement, the parsing
5525 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5526 // to setup the blocks in advance.
5528 // This setup is here so that in the future we can add
5529 // support for other constructs (type parsing, namespaces, etc)
5530 // that do not require a block to be setup in advance
5534 : EVAL_STATEMENT_PARSER EOF
5535 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5536 | EVAL_STATEMENT_PARSER {
5537 Evaluator.LoadAliases (current_namespace);
5539 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5540 Modifiers.PUBLIC, null), null);
5542 ArrayList baseclass_list = new ArrayList ();
5543 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5544 current_container.AddBasesForPart (current_class, baseclass_list);
5546 // (ref object retval)
5547 Parameter [] mpar = new Parameter [1];
5548 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5550 Parameters pars = new Parameters (mpar);
5551 current_local_parameters = pars;
5552 Method method = new Method (
5555 TypeManager.system_void_expr,
5556 Modifiers.PUBLIC | Modifiers.STATIC,
5557 new MemberName ("Host"),
5559 null /* attributes */);
5561 oob_stack.Push (method);
5562 ++lexer.parsing_block;
5563 start_block (lexer.Location);
5565 interactive_statement_list
5567 --lexer.parsing_block;
5568 Method method = (Method) oob_stack.Pop ();
5570 method.Block = (ToplevelBlock) end_block(lexer.Location);
5571 current_container.AddMethod (method);
5573 --lexer.parsing_declaration;
5574 InteractiveResult = pop_current_class ();
5575 current_local_parameters = null;
5577 | EVAL_COMPILATION_UNIT_PARSER {
5578 Evaluator.LoadAliases (current_namespace);
5580 interactive_compilation_unit
5583 interactive_compilation_unit
5584 : outer_declarations
5585 | outer_declarations global_attributes
5592 // A class used to pass around variable declarations and constants
5594 public class VariableDeclaration {
5595 public string identifier;
5596 public Expression expression_or_array_initializer;
5597 public Location Location;
5598 public Attributes OptAttributes;
5599 public string DocComment;
5601 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5603 this.identifier = lt.Value;
5604 if (eoai is ArrayList) {
5605 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5607 this.expression_or_array_initializer = (Expression)eoai;
5609 this.Location = lt.Location;
5610 this.OptAttributes = opt_attrs;
5613 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5618 class VariableMemberDeclaration
5620 public readonly MemberName MemberName;
5621 public Expression expression_or_array_initializer;
5623 public VariableMemberDeclaration (MemberName mn, object initializer)
5627 if (initializer is ArrayList) {
5628 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5630 this.expression_or_array_initializer = (Expression)initializer;
5637 // A class used to hold info about an operator declarator
5639 struct OperatorDeclaration {
5640 public readonly Operator.OpType optype;
5641 public readonly FullNamedExpression ret_type;
5642 public readonly Location location;
5644 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5647 this.ret_type = ret_type;
5648 this.location = location;
5652 void Error_ExpectingTypeName (Expression expr)
5654 if (expr is Invocation){
5655 Report.Error (1002, expr.Location, "Expecting `;'");
5657 expr.Error_InvalidExpressionStatement ();
5661 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5663 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5667 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5669 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5670 Parameter.GetModifierSignature (mod));
5673 static void Error_TypeExpected (Location loc)
5675 Report.Error (1031, loc, "Type expected");
5678 void push_current_class (TypeContainer tc, object partial_token)
5680 if (RootContext.EvalMode){
5681 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5682 undo.AddTypeContainer (current_container, tc);
5685 if (partial_token != null)
5686 current_container = current_container.AddPartial (tc);
5688 current_container = current_container.AddTypeContainer (tc);
5690 ++lexer.parsing_declaration;
5694 DeclSpace pop_current_class ()
5696 DeclSpace retval = current_class;
5698 current_class = current_class.Parent;
5699 current_container = current_class.PartialContainer;
5705 // Given the @class_name name, it creates a fully qualified name
5706 // based on the containing declaration space
5709 MakeName (MemberName class_name)
5711 Namespace ns = current_namespace.NS;
5713 if (current_container == RootContext.ToplevelTypes) {
5714 if (ns.Name.Length != 0)
5715 return new MemberName (ns.MemberName, class_name);
5719 return new MemberName (current_container.MemberName, class_name);
5723 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5725 Block implicit_block;
5726 ArrayList inits = null;
5729 // If we are doing interactive editing, we want variable declarations
5730 // that are in the top block to be added instead to the class as
5733 if (RootContext.StatementMode){
5736 for (Block b = current_block; b != null; b = b.Parent){
5737 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5738 // There has been an explicit block, we cant add to the class
5745 // We can use "current_block" since we know there are no explicit blocks
5747 foreach (VariableDeclaration decl in variable_declarators){
5748 // We can not use the super-handy f.Initializer, because
5749 // multiple lines would force code to be executed out of sync
5750 if (decl.expression_or_array_initializer != null){
5751 string id = "$" + decl.identifier;
5752 current_block.AddVariable (type, id, decl.Location);
5754 LocalVariableReference var;
5755 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5756 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5757 current_block.AddStatement (new StatementExpression (assign));
5758 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5759 current_block.AddStatement (new StatementExpression (assign));
5761 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
5762 new MemberName (decl.identifier, loc), null);
5763 current_container.AddField (f);
5765 // Register the field to be visible later as a global variable
5766 Evaluator.QueueField (f);
5770 return current_block;
5775 // We use the `Used' property to check whether statements
5776 // have been added to the current block. If so, we need
5777 // to create another block to contain the new declaration
5778 // otherwise, as an optimization, we use the same block to
5779 // add the declaration.
5781 // FIXME: A further optimization is to check if the statements
5782 // that were added were added as part of the initialization
5783 // below. In which case, no other statements have been executed
5784 // and we might be able to reduce the number of blocks for
5785 // situations like this:
5787 // int j = 1; int k = j + 1;
5789 if (current_block.Used)
5790 implicit_block = new Block (current_block, loc, lexer.Location);
5792 implicit_block = current_block;
5794 foreach (VariableDeclaration decl in variable_declarators){
5796 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5797 if (decl.expression_or_array_initializer != null){
5799 inits = new ArrayList (4);
5806 return implicit_block;
5808 foreach (VariableDeclaration decl in inits){
5810 Expression expr = decl.expression_or_array_initializer;
5812 LocalVariableReference var;
5813 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5815 assign = new SimpleAssign (var, expr, decl.Location);
5817 implicit_block.AddStatement (new StatementExpression (assign));
5820 return implicit_block;
5823 Block declare_local_constants (Expression type, ArrayList declarators)
5825 Block implicit_block;
5827 if (current_block.Used)
5828 implicit_block = new Block (current_block);
5830 implicit_block = current_block;
5832 foreach (VariableDeclaration decl in declarators){
5833 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5836 return implicit_block;
5839 string CheckAttributeTarget (string a, Location l)
5842 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5846 Report.Warning (658, 1, l,
5847 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5848 return string.Empty;
5851 static bool IsUnaryOperator (Operator.OpType op)
5855 case Operator.OpType.LogicalNot:
5856 case Operator.OpType.OnesComplement:
5857 case Operator.OpType.Increment:
5858 case Operator.OpType.Decrement:
5859 case Operator.OpType.True:
5860 case Operator.OpType.False:
5861 case Operator.OpType.UnaryPlus:
5862 case Operator.OpType.UnaryNegation:
5868 void syntax_error (Location l, string msg)
5870 Report.Error (1003, l, "Syntax error, " + msg);
5873 void note (string s)
5875 // Used to put annotations
5880 public Tokenizer Lexer {
5886 static CSharpParser ()
5888 oob_stack = new Stack ();
5891 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
5893 if (RootContext.EvalMode)
5897 current_namespace = new NamespaceEntry (null, file, null);
5898 current_class = current_namespace.SlaveDeclSpace;
5899 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5901 lexer = new Tokenizer (reader, file);
5904 public void parse ()
5906 eof_token = Token.EOF;
5909 if (yacc_verbose_flag > 1)
5910 yyparse (lexer, new yydebug.yyDebugSimple ());
5913 } catch (Exception e){
5914 if (e is yyParser.yyUnexpectedEof)
5915 UnexpectedEOF = true;
5916 else if (yacc_verbose_flag > 0)
5917 Console.WriteLine (e);
5918 if (e is yyParser.yyException)
5919 Report.Error (-25, lexer.Location, "Parsing error");
5921 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
5923 Tokenizer tokenizer = lexer as Tokenizer;
5924 tokenizer.cleanup ();
5926 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5927 throw new InternalErrorException ("who set it?");
5930 static void CheckToken (int error, int yyToken, string msg, Location loc)
5932 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5933 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
5935 Report.Error (error, loc, msg);
5938 void CheckIdentifierToken (int yyToken, Location loc)
5940 CheckToken (1041, yyToken, "Identifier expected", loc);
5943 string ConsumeStoredComment ()
5945 string s = tmpComment;
5947 Lexer.doc_state = XmlCommentState.Allowed;
5951 Location GetLocation (object obj)
5953 if (obj is MemberCore)
5954 return ((MemberCore) obj).Location;
5955 if (obj is MemberName)
5956 return ((MemberName) obj).Location;
5957 if (obj is LocatedToken)
5958 return ((LocatedToken) obj).Location;
5959 if (obj is Location)
5960 return (Location) obj;
5961 return lexer.Location;
5964 void start_block (Location loc)
5966 if (current_block == null || parsing_anonymous_method) {
5967 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
5968 parsing_anonymous_method = false;
5970 current_block = new ExplicitBlock (current_block, loc, Location.Null);
5975 end_block (Location loc)
5977 Block retval = current_block.Explicit;
5978 retval.SetEndLocation (loc);
5979 current_block = retval.Parent;
5984 start_anonymous (bool lambda, Parameters parameters, Location loc)
5986 oob_stack.Push (current_anonymous_method);
5987 oob_stack.Push (current_local_parameters);
5989 current_local_parameters = parameters;
5991 current_anonymous_method = lambda
5992 ? new LambdaExpression (parameters, loc)
5993 : new AnonymousMethodExpression (parameters, loc);
5995 // Force the next block to be created as a ToplevelBlock
5996 parsing_anonymous_method = true;
6000 * Completes the anonymous method processing, if lambda_expr is null, this
6001 * means that we have a Statement instead of an Expression embedded
6003 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
6005 AnonymousMethodExpression retval;
6007 if (RootContext.Version == LanguageVersion.ISO_1){
6008 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6011 current_anonymous_method.Block = anon_block;
6012 retval = current_anonymous_method;
6015 current_local_parameters = (Parameters) oob_stack.Pop ();
6016 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6021 public NamespaceEntry CurrentNamespace {
6023 return current_namespace;
6028 void Error_SyntaxError (int token)
6030 Error_SyntaxError (1525, token);
6033 void Error_SyntaxError (int error_code, int token)
6035 string symbol = GetSymbolName (token);
6036 string expecting = GetExpecting ();
6037 if (expecting != null)
6038 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
6041 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
6044 string GetExpecting ()
6046 int [] tokens = yyExpectingTokens (yyExpectingState);
6047 if (tokens.Length == 1)
6048 return "`" + GetTokenName (tokens [0]) + "'";
6050 ArrayList names = new ArrayList ();
6051 bool has_type = false;
6052 bool has_identifier = false;
6053 for (int i = 0; i < tokens.Length; i++){
6054 int token = tokens [i];
6055 has_identifier |= token == Token.IDENTIFIER;
6057 string name = GetTokenName (token);
6058 if (name == "<internal>")
6061 has_type |= name == "type";
6062 if (names.Contains (name))
6069 // Too many tokens to enumerate
6071 if (names.Count > 8)
6074 if (has_type && has_identifier)
6075 names.Remove ("identifier");
6077 StringBuilder sb = new StringBuilder ();
6079 int count = names.Count;
6080 for (int i = 0; i < count; i++){
6081 bool last = i + 1 == count;
6085 sb.Append (names [i]);
6086 sb.Append (last ? "'" : "', ");
6088 return sb.ToString ();
6092 string GetSymbolName (int token)
6095 case Token.LITERAL_FLOAT:
6096 case Token.LITERAL_INTEGER:
6097 case Token.LITERAL_DOUBLE:
6098 case Token.LITERAL_DECIMAL:
6099 case Token.LITERAL_CHARACTER:
6100 case Token.LITERAL_STRING:
6101 return lexer.Value.ToString ();
6102 case Token.IDENTIFIER:
6103 return ((LocatedToken)lexer.Value).Value;
6139 return GetTokenName (token);
6142 static string GetTokenName (int token)
6145 case Token.ABSTRACT:
6165 case Token.CONTINUE:
6169 case Token.DELEGATE:
6179 case Token.EXPLICIT:
6197 case Token.IMPLICIT:
6201 case Token.INTERFACE:
6203 case Token.INTERNAL:
6209 case Token.NAMESPACE:
6215 case Token.OPERATOR:
6219 case Token.OVERRIDE:
6225 case Token.PROTECTED:
6229 case Token.READONLY:
6241 case Token.STACKALLOC:
6242 return "stackalloc";
6259 case Token.UNCHECKED:
6267 case Token.VOLATILE:
6297 case Token.ASCENDING:
6299 case Token.DESCENDING:
6300 return "descending";
6307 case Token.OPEN_BRACE:
6309 case Token.CLOSE_BRACE:
6311 case Token.OPEN_BRACKET:
6313 case Token.CLOSE_BRACKET:
6315 case Token.DEFAULT_OPEN_PARENS:
6316 case Token.OPEN_PARENS_LAMBDA:
6317 case Token.OPEN_PARENS:
6319 case Token.CLOSE_PARENS_CAST:
6320 case Token.CLOSE_PARENS_NO_CAST:
6321 case Token.CLOSE_PARENS_OPEN_PARENS:
6322 case Token.CLOSE_PARENS_MINUS:
6323 case Token.CLOSE_PARENS:
6329 case Token.DEFAULT_COLON:
6333 case Token.SEMICOLON:
6344 case Token.BITWISE_AND:
6345 case Token.BITWISE_OR:
6352 case Token.OP_SHIFT_LEFT:
6353 case Token.OP_SHIFT_RIGHT:
6361 case Token.OP_COALESCING:
6362 return "<operator>";
6364 case Token.OP_MULT_ASSIGN:
6365 case Token.OP_DIV_ASSIGN:
6366 case Token.OP_MOD_ASSIGN:
6367 case Token.OP_ADD_ASSIGN:
6368 case Token.OP_SUB_ASSIGN:
6369 case Token.OP_SHIFT_LEFT_ASSIGN:
6370 case Token.OP_SHIFT_RIGHT_ASSIGN:
6371 case Token.OP_AND_ASSIGN:
6372 case Token.OP_XOR_ASSIGN:
6373 case Token.OP_OR_ASSIGN:
6374 return "<operator>";
6396 case Token.OP_GENERICS_LT:
6397 case Token.GENERIC_DIMENSION:
6399 case Token.OP_GENERICS_GT:
6402 case Token.INTERR_NULLABLE:
6404 case Token.DOUBLE_COLON:
6406 case Token.LITERAL_FLOAT:
6407 case Token.LITERAL_INTEGER:
6408 case Token.LITERAL_DOUBLE:
6409 case Token.LITERAL_DECIMAL:
6410 case Token.LITERAL_CHARACTER:
6411 case Token.LITERAL_STRING:
6413 case Token.IDENTIFIER:
6414 return "identifier";
6416 // All of these are internal.
6419 case Token.FIRST_KEYWORD:
6421 case Token.EVAL_COMPILATION_UNIT_PARSER:
6422 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6423 case Token.EVAL_STATEMENT_PARSER:
6425 case Token.QUERY_LAST_TOKEN:
6426 case Token.QUERY_FIRST_TOKEN:
6427 case Token.LAST_KEYWORD:
6428 return "<internal>";
6430 // A bit more robust.
6432 return yyNames [token];