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
243 %token INTERR_NULLABLE
246 /* Generics <,> tokens */
247 %token OP_GENERICS_LT
248 %token OP_GENERICS_LT_DECL
249 %token OP_GENERICS_GT
251 /* C# keywords which are not really keywords */
257 /* C# single character operators/punctuation. */
285 /* C# multi-character operators. */
290 %token OP_SHIFT_RIGHT
297 %token OP_MULT_ASSIGN
302 %token OP_SHIFT_LEFT_ASSIGN
303 %token OP_SHIFT_RIGHT_ASSIGN
311 %token LITERAL_INTEGER
313 %token LITERAL_DOUBLE
314 %token LITERAL_DECIMAL
315 %token LITERAL_CHARACTER
316 %token LITERAL_STRING
319 %token OPEN_PARENS_LAMBDA
320 %token OPEN_PARENS_CAST
321 %token GENERIC_DIMENSION
324 // Make the parser go into eval mode parsing (statements and compilation units).
325 %token EVAL_STATEMENT_PARSER
326 %token EVAL_COMPILATION_UNIT_PARSER
327 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
329 /* Add precedence rules to solve dangling else s/r conflict */
333 /* Define the operator tokens and their precedences */
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
350 %start compilation_unit
354 : outer_declarations opt_EOF
355 | outer_declarations global_attributes opt_EOF
356 | global_attributes opt_EOF
357 | opt_EOF /* allow empty files */
358 | interactive_parsing opt_EOF
364 Lexer.check_incorrect_doc_comment ();
368 Lexer.check_incorrect_doc_comment ();
374 | outer_declarations outer_declaration
378 : extern_alias_directive
380 | namespace_member_declaration
383 extern_alias_directives
384 : extern_alias_directive
385 | extern_alias_directives extern_alias_directive
388 extern_alias_directive
389 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
391 LocatedToken lt = (LocatedToken) $2;
394 syntax_error (lt.Location, "`alias' expected");
395 } else if (RootContext.Version == LanguageVersion.ISO_1) {
396 Report.FeatureIsNotAvailable (lt.Location, "external alias");
398 lt = (LocatedToken) $3;
399 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
404 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
410 | using_directives using_directive
414 : using_alias_directive
416 if (RootContext.Documentation != null)
417 Lexer.doc_state = XmlCommentState.Allowed;
419 | using_namespace_directive
421 if (RootContext.Documentation != null)
422 Lexer.doc_state = XmlCommentState.Allowed;
426 using_alias_directive
427 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
429 LocatedToken lt = (LocatedToken) $2;
430 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
433 CheckIdentifierToken (yyToken, GetLocation ($2));
438 using_namespace_directive
439 : USING namespace_name SEMICOLON
441 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
446 // Strictly speaking, namespaces don't have attributes but
447 // we parse global attributes along with namespace declarations and then
450 namespace_declaration
451 : opt_attributes NAMESPACE qualified_identifier
453 MemberName name = (MemberName) $3;
456 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
459 current_namespace = new NamespaceEntry (
460 current_namespace, file, name.GetName ());
461 current_class = current_namespace.SlaveDeclSpace;
462 current_container = current_class.PartialContainer;
464 namespace_body opt_semicolon
466 current_namespace = current_namespace.Parent;
467 current_class = current_namespace.SlaveDeclSpace;
468 current_container = current_class.PartialContainer;
475 LocatedToken lt = (LocatedToken) $1;
476 $$ = new MemberName (lt.Value, lt.Location);
478 | qualified_identifier DOT IDENTIFIER
480 LocatedToken lt = (LocatedToken) $3;
481 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
485 syntax_error (lexer.Location, "`.' expected");
500 : namespace_or_type_name
502 MemberName name = (MemberName) $1;
504 if (name.TypeArguments != null)
505 syntax_error (lexer.Location, "namespace name expected");
514 if (RootContext.Documentation != null)
515 Lexer.doc_state = XmlCommentState.Allowed;
521 : opt_extern_alias_directives
523 opt_namespace_member_declarations
527 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
530 | opt_extern_alias_directives
532 opt_namespace_member_declarations
535 Report.Error (1513, lexer.Location, "Expected `}'");
544 opt_extern_alias_directives
546 | extern_alias_directives
549 opt_namespace_member_declarations
551 | namespace_member_declarations
554 namespace_member_declarations
555 : namespace_member_declaration
556 | namespace_member_declarations namespace_member_declaration
559 namespace_member_declaration
563 DeclSpace ds = (DeclSpace)$1;
565 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
566 Report.Error (1527, ds.Location,
567 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
570 current_namespace.DeclarationFound = true;
572 | namespace_declaration {
573 current_namespace.DeclarationFound = true;
576 | field_declaration {
577 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
579 | method_declaration {
580 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
587 | interface_declaration
589 | delegate_declaration
591 // Enable this when we have handled all errors, because this acts as a generic fallback
594 // Console.WriteLine ("Token=" + yyToken);
595 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
607 Attributes attrs = (Attributes)$1;
608 if (global_attrs_enabled) {
609 CodeGen.Assembly.AddAttributes (attrs.Attrs);
611 foreach (Attribute a in attrs.Attrs) {
612 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
623 global_attrs_enabled = false;
628 global_attrs_enabled = false;
637 if (current_attr_target != String.Empty) {
638 ArrayList sect = (ArrayList) $1;
640 if (global_attrs_enabled) {
641 if (current_attr_target == "module") {
642 CodeGen.Module.AddAttributes (sect);
644 } else if (current_attr_target != null && current_attr_target.Length > 0) {
645 CodeGen.Assembly.AddAttributes (sect);
648 $$ = new Attributes (sect);
651 if (RootContext.Documentation != null) {
652 Lexer.check_incorrect_doc_comment ();
654 XmlCommentState.Allowed;
658 $$ = new Attributes (sect);
663 current_attr_target = null;
665 | attribute_sections attribute_section
667 if (current_attr_target != String.Empty) {
668 Attributes attrs = $1 as Attributes;
669 ArrayList sect = (ArrayList) $2;
671 if (global_attrs_enabled) {
672 if (current_attr_target == "module") {
673 CodeGen.Module.AddAttributes (sect);
675 } else if (current_attr_target == "assembly") {
676 CodeGen.Assembly.AddAttributes (sect);
680 attrs = new Attributes (sect);
682 attrs.AddAttributes (sect);
686 attrs = new Attributes (sect);
688 attrs.AddAttributes (sect);
694 current_attr_target = null;
699 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
703 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
709 attribute_target_specifier
710 : attribute_target COLON
712 current_attr_target = (string)$1;
720 LocatedToken lt = (LocatedToken) $1;
721 $$ = CheckAttributeTarget (lt.Value, lt.Location);
723 | EVENT { $$ = "event"; }
724 | RETURN { $$ = "return"; }
727 string name = GetTokenName (yyToken);
728 $$ = CheckAttributeTarget (name, GetLocation ($1));
735 ArrayList attrs = new ArrayList (4);
741 | attribute_list COMMA attribute
743 ArrayList attrs = (ArrayList) $1;
753 ++lexer.parsing_block;
755 opt_attribute_arguments
757 --lexer.parsing_block;
758 MemberName mname = (MemberName) $1;
759 if (mname.IsGeneric) {
760 Report.Error (404, lexer.Location,
761 "'<' unexpected: attributes cannot be generic");
764 object [] arguments = (object []) $3;
765 MemberName left = mname.Left;
766 string identifier = mname.Name;
768 Expression left_expr = left == null ? null : left.GetTypeExpression ();
770 if (current_attr_target == String.Empty)
772 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
773 // FIXME: supply "nameEscaped" parameter here.
774 $$ = new GlobalAttribute (current_namespace, current_attr_target,
775 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
777 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
782 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
785 opt_attribute_arguments
786 : /* empty */ { $$ = null; }
787 | OPEN_PARENS attribute_arguments CLOSE_PARENS
795 : opt_positional_argument_list
800 $$ = new object [] { $1, null };
803 | positional_argument_list COMMA named_argument_list
805 $$ = new object[] { $1, $3 };
807 | named_argument_list
809 $$ = new object [] { null, $1 };
814 opt_positional_argument_list
815 : /* empty */ { $$ = null; }
816 | positional_argument_list
819 positional_argument_list
822 ArrayList args = new ArrayList (4);
823 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
827 | positional_argument_list COMMA expression
829 ArrayList args = (ArrayList) $1;
830 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
839 ArrayList args = new ArrayList (4);
844 | named_argument_list COMMA named_argument
846 ArrayList args = (ArrayList) $1;
851 | named_argument_list COMMA expression
853 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
859 : IDENTIFIER ASSIGN expression
861 // FIXME: keep location
862 $$ = new DictionaryEntry (
863 ((LocatedToken) $1).Value,
864 new Argument ((Expression) $3, Argument.AType.Expression));
870 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
873 opt_class_member_declarations
875 | class_member_declarations
878 class_member_declarations
879 : class_member_declaration
880 | class_member_declarations
881 class_member_declaration
884 class_member_declaration
885 : constant_declaration // done
886 | field_declaration // done
887 | method_declaration // done
888 | property_declaration // done
889 | event_declaration // done
890 | indexer_declaration // done
891 | operator_declaration // done
892 | constructor_declaration // done
893 | destructor_declaration // done
897 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
898 GetSymbolName (yyToken));
909 lexer.ConstraintsParsing = true;
911 type_declaration_name
913 MemberName name = MakeName ((MemberName) $6);
914 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
917 opt_type_parameter_constraints_clauses
919 lexer.ConstraintsParsing = false;
921 current_class.SetParameterInfo ((ArrayList) $9);
923 if (RootContext.Documentation != null)
924 current_container.DocComment = Lexer.consume_doc_comment ();
928 --lexer.parsing_declaration;
929 if (RootContext.Documentation != null)
930 Lexer.doc_state = XmlCommentState.Allowed;
934 $$ = pop_current_class ();
936 | opt_attributes opt_modifiers opt_partial STRUCT error {
937 CheckIdentifierToken (yyToken, GetLocation ($5));
944 if (RootContext.Documentation != null)
945 Lexer.doc_state = XmlCommentState.Allowed;
947 opt_struct_member_declarations CLOSE_BRACE
950 opt_struct_member_declarations
952 | struct_member_declarations
955 struct_member_declarations
956 : struct_member_declaration
957 | struct_member_declarations struct_member_declaration
960 struct_member_declaration
961 : constant_declaration
964 | property_declaration
966 | indexer_declaration
967 | operator_declaration
968 | constructor_declaration
972 * This is only included so we can flag error 575:
973 * destructors only allowed on class types
975 | destructor_declaration
986 int modflags = (int) $2;
987 foreach (VariableDeclaration constant in (ArrayList) $5){
988 Location l = constant.Location;
989 if ((modflags & Modifiers.STATIC) != 0) {
990 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
994 Const c = new Const (
995 current_class, (FullNamedExpression) $4, (string) constant.identifier,
996 (Expression) constant.expression_or_array_initializer, modflags,
999 if (RootContext.Documentation != null) {
1000 c.DocComment = Lexer.consume_doc_comment ();
1001 Lexer.doc_state = XmlCommentState.Allowed;
1003 current_container.AddConstant (c);
1008 constant_declarators
1009 : constant_declarator
1011 ArrayList constants = new ArrayList (4);
1016 | constant_declarators COMMA constant_declarator
1019 ArrayList constants = (ArrayList) $1;
1028 ++lexer.parsing_block;
1030 constant_initializer
1032 --lexer.parsing_block;
1033 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1037 // A const field requires a value to be provided
1038 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1043 constant_initializer
1044 : constant_expression
1052 variable_declarators
1055 FullNamedExpression type = (FullNamedExpression) $3;
1056 if (type == TypeManager.system_void_expr)
1057 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1061 current_array_type = null;
1063 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1064 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1066 field.Initializer = var.expression_or_array_initializer;
1068 if (RootContext.Documentation != null) {
1069 field.DocComment = Lexer.consume_doc_comment ();
1070 Lexer.doc_state = XmlCommentState.Allowed;
1072 current_container.AddField (field);
1073 $$ = field; // FIXME: might be better if it points to the top item
1080 fixed_variable_declarators
1083 FullNamedExpression type = (FullNamedExpression) $4;
1087 current_array_type = null;
1089 foreach (VariableDeclaration var in (ArrayList) $5) {
1090 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1091 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1093 if (RootContext.Documentation != null) {
1094 field.DocComment = Lexer.consume_doc_comment ();
1095 Lexer.doc_state = XmlCommentState.Allowed;
1097 current_container.AddField (field);
1098 $$ = field; // FIXME: might be better if it points to the top item
1107 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1111 fixed_variable_declarators
1112 : fixed_variable_declarator
1114 ArrayList decl = new ArrayList (2);
1118 | fixed_variable_declarators COMMA fixed_variable_declarator
1120 ArrayList decls = (ArrayList) $1;
1126 fixed_variable_declarator
1127 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1129 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1131 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1133 Report.Error (443, lexer.Location, "Value or constant expected");
1134 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1139 local_variable_declarators
1140 : local_variable_declarator
1142 ArrayList decl = new ArrayList (4);
1147 | local_variable_declarators COMMA local_variable_declarator
1149 ArrayList decls = (ArrayList) $1;
1155 local_variable_declarator
1156 : IDENTIFIER ASSIGN local_variable_initializer
1158 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1162 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1164 | IDENTIFIER variable_bad_array
1170 local_variable_initializer
1173 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1175 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1179 $$ = new ArglistAccess ((Location) $1);
1181 | STACKALLOC simple_type
1183 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1184 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1188 variable_declarators
1189 : variable_declarator
1191 ArrayList decl = new ArrayList (4);
1196 | variable_declarators COMMA variable_declarator
1198 ArrayList decls = (ArrayList) $1;
1205 : member_declaration_name ASSIGN
1207 ++lexer.parsing_block;
1208 lexer.parsing_generic_declaration = false;
1210 variable_initializer
1212 --lexer.parsing_block;
1213 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1215 | member_declaration_name
1217 lexer.parsing_generic_declaration = false;
1218 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1220 | member_declaration_name variable_bad_array
1222 lexer.parsing_generic_declaration = false;
1228 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1230 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1231 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1235 variable_initializer
1242 if (RootContext.Documentation != null)
1243 Lexer.doc_state = XmlCommentState.NotAllowed;
1247 Method method = (Method) $1;
1248 method.Block = (ToplevelBlock) $3;
1249 current_container.AddMethod (method);
1251 if (current_container.Kind == Kind.Interface && method.Block != null) {
1252 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1255 current_generic_method = null;
1256 current_local_parameters = null;
1258 if (RootContext.Documentation != null)
1259 Lexer.doc_state = XmlCommentState.Allowed;
1267 method_declaration_name OPEN_PARENS
1269 arglist_allowed = true;
1271 opt_formal_parameter_list CLOSE_PARENS
1273 lexer.ConstraintsParsing = true;
1275 opt_type_parameter_constraints_clauses
1277 lexer.ConstraintsParsing = false;
1278 arglist_allowed = false;
1279 MemberName name = (MemberName) $4;
1280 current_local_parameters = (Parameters) $7;
1282 if ($10 != null && name.TypeArguments == null)
1283 Report.Error (80, lexer.Location,
1284 "Constraints are not allowed on non-generic declarations");
1288 GenericMethod generic = null;
1289 if (name.TypeArguments != null) {
1290 generic = new GenericMethod (current_namespace, current_class, name,
1291 (FullNamedExpression) $3, current_local_parameters);
1293 generic.SetParameterInfo ((ArrayList) $10);
1296 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1297 name, current_local_parameters, (Attributes) $1);
1299 current_generic_method = generic;
1301 if (RootContext.Documentation != null)
1302 method.DocComment = Lexer.consume_doc_comment ();
1309 VOID method_declaration_name
1310 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1312 lexer.ConstraintsParsing = true;
1314 opt_type_parameter_constraints_clauses
1316 lexer.ConstraintsParsing = false;
1318 MemberName name = (MemberName) $5;
1319 current_local_parameters = (Parameters) $7;
1321 if ($9 != null && name.TypeArguments == null)
1322 Report.Error (80, lexer.Location,
1323 "Constraints are not allowed on non-generic declarations");
1326 GenericMethod generic = null;
1327 if (name.TypeArguments != null) {
1328 generic = new GenericMethod (current_namespace, current_class, name,
1329 TypeManager.system_void_expr, current_local_parameters);
1331 generic.SetParameterInfo ((ArrayList) $10);
1334 int modifiers = (int) $2;
1337 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1338 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1340 if ((modifiers & invalid_partial_mod) != 0) {
1341 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1342 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1343 modifiers &= ~invalid_partial_mod;
1346 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1347 Report.Error (751, name.Location, "A partial method must be declared within a " +
1348 "partial class or partial struct");
1351 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1353 method = new Method (current_class, generic, TypeManager.system_void_expr,
1354 modifiers, name, current_local_parameters, (Attributes) $1);
1356 current_generic_method = generic;
1358 if (RootContext.Documentation != null)
1359 method.DocComment = Lexer.consume_doc_comment ();
1366 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1368 MemberName name = (MemberName) $5;
1369 Report.Error (1585, name.Location,
1370 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1372 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1373 0, name, (Parameters) $7, (Attributes) $1);
1375 current_local_parameters = (Parameters) $7;
1377 if (RootContext.Documentation != null)
1378 method.DocComment = Lexer.consume_doc_comment ();
1386 | SEMICOLON { $$ = null; }
1389 opt_formal_parameter_list
1390 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1391 | formal_parameter_list
1394 opt_parameter_list_no_mod
1395 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1398 parameter_modifiers_not_allowed = true;
1400 formal_parameter_list
1402 parameter_modifiers_not_allowed = false;
1407 formal_parameter_list
1410 ArrayList pars_list = (ArrayList) $1;
1412 Parameter [] pars = new Parameter [pars_list.Count];
1413 pars_list.CopyTo (pars);
1415 $$ = new Parameters (pars);
1417 | fixed_parameters COMMA parameter_array
1419 ArrayList pars_list = (ArrayList) $1;
1422 Parameter [] pars = new Parameter [pars_list.Count];
1423 pars_list.CopyTo (pars);
1425 $$ = new Parameters (pars);
1427 | fixed_parameters COMMA arglist_modifier
1429 ArrayList pars_list = (ArrayList) $1;
1430 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1432 Parameter [] pars = new Parameter [pars_list.Count];
1433 pars_list.CopyTo (pars);
1435 $$ = new Parameters (pars, true);
1437 | parameter_array COMMA error
1440 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1443 | fixed_parameters COMMA parameter_array COMMA error
1446 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1449 | arglist_modifier COMMA error
1451 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1454 | fixed_parameters COMMA ARGLIST COMMA error
1456 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1461 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1465 $$ = new Parameters (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1472 ArrayList pars = new ArrayList (4);
1477 | fixed_parameters COMMA fixed_parameter
1479 ArrayList pars = (ArrayList) $1;
1480 Parameter p = (Parameter)$3;
1482 if (p.HasExtensionMethodModifier)
1483 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1492 opt_parameter_modifier
1496 LocatedToken lt = (LocatedToken) $4;
1497 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1500 opt_parameter_modifier
1502 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1504 LocatedToken lt = (LocatedToken) $4;
1505 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1509 opt_parameter_modifier
1512 Report.Error (1001, GetLocation ($3), "Identifier expected");
1513 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
1516 opt_parameter_modifier
1519 CheckIdentifierToken (yyToken, GetLocation ($4));
1523 opt_parameter_modifier
1529 LocatedToken lt = (LocatedToken) $4;
1530 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1535 opt_parameter_modifier
1536 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1537 | parameter_modifiers
1541 : parameter_modifier
1545 | parameter_modifiers parameter_modifier
1547 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1548 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1549 if (((Parameter.Modifier)$1 & p2) == p2) {
1550 Error_DuplicateParameterModifier (lexer.Location, p2);
1552 switch (mod & ~Parameter.Modifier.This) {
1553 case Parameter.Modifier.REF:
1554 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1556 case Parameter.Modifier.OUT:
1557 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1560 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1571 if (parameter_modifiers_not_allowed)
1572 Error_ParameterModifierNotValid ("ref", (Location)$1);
1574 $$ = Parameter.Modifier.REF;
1578 if (parameter_modifiers_not_allowed)
1579 Error_ParameterModifierNotValid ("out", (Location)$1);
1581 $$ = Parameter.Modifier.OUT;
1585 if (parameter_modifiers_not_allowed)
1586 Error_ParameterModifierNotValid ("this", (Location)$1);
1588 if (RootContext.Version <= LanguageVersion.ISO_2)
1589 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1591 $$ = Parameter.Modifier.This;
1596 : opt_attributes params_modifier type IDENTIFIER
1598 LocatedToken lt = (LocatedToken) $4;
1599 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1601 | opt_attributes params_modifier type error {
1602 CheckIdentifierToken (yyToken, GetLocation ($4));
1610 if (params_modifiers_not_allowed)
1611 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1613 | PARAMS parameter_modifier
1615 Parameter.Modifier mod = (Parameter.Modifier)$2;
1616 if ((mod & Parameter.Modifier.This) != 0) {
1617 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1619 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1622 | PARAMS params_modifier
1624 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1631 if (!arglist_allowed)
1632 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1636 property_declaration
1640 member_declaration_name
1642 if (RootContext.Documentation != null)
1643 tmpComment = Lexer.consume_doc_comment ();
1647 implicit_value_parameter_type = (FullNamedExpression) $3;
1648 lexer.PropertyParsing = true;
1650 accessor_declarations
1652 lexer.PropertyParsing = false;
1653 has_get = has_set = false;
1658 Accessors accessors = (Accessors) $8;
1659 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1660 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1661 bool order = accessors != null ? accessors.declared_in_reverse : false;
1663 MemberName name = (MemberName) $4;
1664 FullNamedExpression ptype = (FullNamedExpression) $3;
1666 prop = new Property (current_class, ptype, (int) $2,
1667 name, (Attributes) $1, get_block, set_block, order, current_block);
1669 if (ptype == TypeManager.system_void_expr)
1670 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1672 if (accessors == null)
1673 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1675 if (current_container.Kind == Kind.Interface) {
1676 if (prop.Get.Block != null)
1677 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1679 if (prop.Set.Block != null)
1680 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1683 current_container.AddProperty (prop);
1684 implicit_value_parameter_type = null;
1686 if (RootContext.Documentation != null)
1687 prop.DocComment = ConsumeStoredComment ();
1692 accessor_declarations
1693 : get_accessor_declaration
1695 $$ = new Accessors ((Accessor) $1, null);
1697 | get_accessor_declaration accessor_declarations
1699 Accessors accessors = (Accessors) $2;
1700 accessors.get_or_add = (Accessor) $1;
1703 | set_accessor_declaration
1705 $$ = new Accessors (null, (Accessor) $1);
1707 | set_accessor_declaration accessor_declarations
1709 Accessors accessors = (Accessors) $2;
1710 accessors.set_or_remove = (Accessor) $1;
1711 accessors.declared_in_reverse = true;
1716 if (yyToken == Token.CLOSE_BRACE) {
1719 if (yyToken == Token.SEMICOLON)
1720 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1722 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1724 $$ = new Accessors (null, null);
1729 get_accessor_declaration
1730 : opt_attributes opt_modifiers GET
1732 // If this is not the case, then current_local_parameters has already
1733 // been set in indexer_declaration
1734 if (parsing_indexer == false)
1735 current_local_parameters = Parameters.EmptyReadOnlyParameters;
1737 current_local_parameters = indexer_parameters;
1738 lexer.PropertyParsing = false;
1743 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1746 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1748 current_local_parameters = null;
1749 lexer.PropertyParsing = true;
1751 if (RootContext.Documentation != null)
1752 if (Lexer.doc_state == XmlCommentState.Error)
1753 Lexer.doc_state = XmlCommentState.NotAllowed;
1759 set_accessor_declaration
1760 : opt_attributes opt_modifiers SET
1762 Parameter implicit_value_parameter = new Parameter (
1763 implicit_value_parameter_type, "value",
1764 Parameter.Modifier.NONE, null, (Location) $3);
1766 if (!parsing_indexer) {
1767 current_local_parameters = new Parameters (new Parameter [] { implicit_value_parameter });
1769 current_local_parameters = Parameters.MergeGenerated (
1770 indexer_parameters, true, implicit_value_parameter, null);
1773 lexer.PropertyParsing = false;
1778 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1781 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1783 current_local_parameters = null;
1784 lexer.PropertyParsing = true;
1786 if (RootContext.Documentation != null
1787 && Lexer.doc_state == XmlCommentState.Error)
1788 Lexer.doc_state = XmlCommentState.NotAllowed;
1802 Error_SyntaxError (1043, yyToken);
1807 interface_declaration
1813 lexer.ConstraintsParsing = true;
1815 type_declaration_name
1817 MemberName name = MakeName ((MemberName) $6);
1818 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1821 opt_type_parameter_constraints_clauses
1823 lexer.ConstraintsParsing = false;
1825 current_class.SetParameterInfo ((ArrayList) $9);
1827 if (RootContext.Documentation != null) {
1828 current_container.DocComment = Lexer.consume_doc_comment ();
1829 Lexer.doc_state = XmlCommentState.Allowed;
1834 --lexer.parsing_declaration;
1835 if (RootContext.Documentation != null)
1836 Lexer.doc_state = XmlCommentState.Allowed;
1840 $$ = pop_current_class ();
1842 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1843 CheckIdentifierToken (yyToken, GetLocation ($5));
1849 opt_interface_member_declarations
1853 opt_interface_member_declarations
1855 | interface_member_declarations
1858 interface_member_declarations
1859 : interface_member_declaration
1860 | interface_member_declarations interface_member_declaration
1863 interface_member_declaration
1864 : constant_declaration
1866 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1870 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1872 | method_declaration
1873 | property_declaration
1875 | indexer_declaration
1876 | operator_declaration
1878 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1880 | constructor_declaration
1882 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1886 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1890 operator_declaration
1891 : opt_attributes opt_modifiers operator_declarator
1899 OperatorDeclaration decl = (OperatorDeclaration) $3;
1900 Operator op = new Operator (
1901 current_class, decl.optype, decl.ret_type, (int) $2,
1902 current_local_parameters,
1903 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1905 if (RootContext.Documentation != null) {
1906 op.DocComment = tmpComment;
1907 Lexer.doc_state = XmlCommentState.Allowed;
1910 // Note again, checking is done in semantic analysis
1911 current_container.AddOperator (op);
1913 current_local_parameters = null;
1919 | SEMICOLON { $$ = null; }
1923 : type_expression_or_array
1926 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1927 $$ = TypeManager.system_void_expr;
1932 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1934 params_modifiers_not_allowed = true;
1936 opt_parameter_list_no_mod CLOSE_PARENS
1938 params_modifiers_not_allowed = false;
1940 Location loc = (Location) $2;
1941 Operator.OpType op = (Operator.OpType) $3;
1942 current_local_parameters = (Parameters)$6;
1944 int p_count = current_local_parameters.Count;
1946 if (op == Operator.OpType.Addition)
1947 op = Operator.OpType.UnaryPlus;
1948 else if (op == Operator.OpType.Subtraction)
1949 op = Operator.OpType.UnaryNegation;
1952 if (IsUnaryOperator (op)) {
1954 Report.Error (1020, loc, "Overloadable binary operator expected");
1955 } else if (p_count != 1) {
1956 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1957 Operator.GetName (op));
1961 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1962 Operator.GetName (op));
1963 } else if (p_count != 2) {
1964 Report.Error (1019, loc, "Overloadable unary operator expected");
1968 if (RootContext.Documentation != null) {
1969 tmpComment = Lexer.consume_doc_comment ();
1970 Lexer.doc_state = XmlCommentState.NotAllowed;
1973 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
1975 | conversion_operator_declarator
1978 overloadable_operator
1980 : BANG { $$ = Operator.OpType.LogicalNot; }
1981 | TILDE { $$ = Operator.OpType.OnesComplement; }
1982 | OP_INC { $$ = Operator.OpType.Increment; }
1983 | OP_DEC { $$ = Operator.OpType.Decrement; }
1984 | TRUE { $$ = Operator.OpType.True; }
1985 | FALSE { $$ = Operator.OpType.False; }
1986 // Unary and binary:
1987 | PLUS { $$ = Operator.OpType.Addition; }
1988 | MINUS { $$ = Operator.OpType.Subtraction; }
1990 | STAR { $$ = Operator.OpType.Multiply; }
1991 | DIV { $$ = Operator.OpType.Division; }
1992 | PERCENT { $$ = Operator.OpType.Modulus; }
1993 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1994 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1995 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1996 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1997 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1998 | OP_EQ { $$ = Operator.OpType.Equality; }
1999 | OP_NE { $$ = Operator.OpType.Inequality; }
2000 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2001 | OP_LT { $$ = Operator.OpType.LessThan; }
2002 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2003 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2006 conversion_operator_declarator
2007 : IMPLICIT OPERATOR type OPEN_PARENS
2009 params_modifiers_not_allowed = true;
2011 opt_parameter_list_no_mod CLOSE_PARENS
2013 params_modifiers_not_allowed = false;
2015 Location loc = (Location) $2;
2016 current_local_parameters = (Parameters)$6;
2018 if (RootContext.Documentation != null) {
2019 tmpComment = Lexer.consume_doc_comment ();
2020 Lexer.doc_state = XmlCommentState.NotAllowed;
2023 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2025 | EXPLICIT OPERATOR type OPEN_PARENS
2027 params_modifiers_not_allowed = true;
2029 opt_parameter_list_no_mod CLOSE_PARENS
2031 params_modifiers_not_allowed = false;
2033 Location loc = (Location) $2;
2034 current_local_parameters = (Parameters)$6;
2036 if (RootContext.Documentation != null) {
2037 tmpComment = Lexer.consume_doc_comment ();
2038 Lexer.doc_state = XmlCommentState.NotAllowed;
2041 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2045 Error_SyntaxError (yyToken);
2046 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2050 Error_SyntaxError (yyToken);
2051 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2055 constructor_declaration
2056 : constructor_declarator
2059 Constructor c = (Constructor) $1;
2060 c.Block = (ToplevelBlock) $2;
2062 if (RootContext.Documentation != null)
2063 c.DocComment = ConsumeStoredComment ();
2065 current_container.AddConstructor (c);
2067 current_local_parameters = null;
2068 if (RootContext.Documentation != null)
2069 Lexer.doc_state = XmlCommentState.Allowed;
2073 constructor_declarator
2078 if (RootContext.Documentation != null) {
2079 tmpComment = Lexer.consume_doc_comment ();
2080 Lexer.doc_state = XmlCommentState.Allowed;
2083 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2085 current_local_parameters = (Parameters) $6;
2088 // start block here, so possible anonymous methods inside
2089 // constructor initializer can get correct parent block
2091 start_block (lexer.Location);
2093 opt_constructor_initializer
2095 LocatedToken lt = (LocatedToken) $3;
2096 int mods = (int) $2;
2097 ConstructorInitializer ci = (ConstructorInitializer) $9;
2099 Constructor c = new Constructor (current_class, lt.Value, mods,
2100 (Attributes) $1, current_local_parameters, ci, lt.Location);
2102 if (lt.Value != current_container.MemberName.Name) {
2103 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2104 } else if ((mods & Modifiers.STATIC) != 0) {
2105 if ((mods & Modifiers.Accessibility) != 0){
2106 Report.Error (515, c.Location,
2107 "`{0}': static constructor cannot have an access modifier",
2108 c.GetSignatureForError ());
2111 Report.Error (514, c.Location,
2112 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2113 c.GetSignatureForError ());
2124 | SEMICOLON { current_block = null; $$ = null; }
2127 opt_constructor_initializer
2129 | constructor_initializer
2132 constructor_initializer
2133 : COLON BASE OPEN_PARENS
2135 ++lexer.parsing_block;
2137 opt_argument_list CLOSE_PARENS
2139 --lexer.parsing_block;
2140 $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
2142 | COLON THIS OPEN_PARENS
2144 ++lexer.parsing_block;
2146 opt_argument_list CLOSE_PARENS
2148 --lexer.parsing_block;
2149 $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
2152 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2157 destructor_declaration
2158 : opt_attributes opt_modifiers TILDE
2160 if (RootContext.Documentation != null) {
2161 tmpComment = Lexer.consume_doc_comment ();
2162 Lexer.doc_state = XmlCommentState.NotAllowed;
2165 current_local_parameters = Parameters.EmptyReadOnlyParameters;
2167 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2169 LocatedToken lt = (LocatedToken) $5;
2170 if (lt.Value != current_container.MemberName.Name){
2171 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2172 } else if (current_container.Kind != Kind.Class){
2173 Report.Error (575, lt.Location, "Only class types can contain destructor");
2175 Method d = new Destructor (
2176 current_class, TypeManager.system_void_expr, (int) $2, "Finalize",
2177 Parameters.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2178 if (RootContext.Documentation != null)
2179 d.DocComment = ConsumeStoredComment ();
2181 d.Block = (ToplevelBlock) $8;
2182 current_container.AddMethod (d);
2185 current_local_parameters = null;
2192 EVENT type variable_declarators SEMICOLON
2194 current_array_type = null;
2195 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2197 EventField e = new EventField (
2198 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2200 if (var.expression_or_array_initializer != null) {
2201 if (current_container.Kind == Kind.Interface) {
2202 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2205 e.Initializer = var.expression_or_array_initializer;
2208 if (var.MemberName.Left != null) {
2209 Report.Error (71, e.Location,
2210 "`{0}': An explicit interface implementation of an event must use property syntax",
2211 e.GetSignatureForError ());
2214 current_container.AddEvent (e);
2216 if (RootContext.Documentation != null) {
2217 e.DocComment = Lexer.consume_doc_comment ();
2218 Lexer.doc_state = XmlCommentState.Allowed;
2224 EVENT type member_declaration_name
2227 implicit_value_parameter_type = (FullNamedExpression) $4;
2228 current_local_parameters = new Parameters (
2229 new Parameter (implicit_value_parameter_type, "value",
2230 Parameter.Modifier.NONE, null, GetLocation ($3)));
2232 lexer.EventParsing = true;
2234 event_accessor_declarations
2236 lexer.EventParsing = false;
2240 MemberName name = (MemberName) $5;
2242 if (current_container.Kind == Kind.Interface) {
2243 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2247 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2248 current_container.Name, name.GetSignatureForError ());
2251 Accessors accessors = (Accessors) $8;
2253 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2254 // CS0073 is already reported, so no CS0065 here.
2257 Event e = new EventProperty (
2258 current_class, (FullNamedExpression) $4, (int) $2, name,
2259 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2260 if (RootContext.Documentation != null) {
2261 e.DocComment = Lexer.consume_doc_comment ();
2262 Lexer.doc_state = XmlCommentState.Allowed;
2265 current_container.AddEvent (e);
2266 implicit_value_parameter_type = null;
2269 current_local_parameters = null;
2271 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2273 MemberName mn = (MemberName) $5;
2274 if (mn.Left != null)
2275 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2277 if (RootContext.Documentation != null)
2278 Lexer.doc_state = XmlCommentState.Allowed;
2280 Error_SyntaxError (yyToken);
2285 event_accessor_declarations
2286 : add_accessor_declaration remove_accessor_declaration
2288 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2290 | remove_accessor_declaration add_accessor_declaration
2292 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2293 accessors.declared_in_reverse = true;
2296 | add_accessor_declaration { $$ = null; }
2297 | remove_accessor_declaration { $$ = null; }
2300 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2306 add_accessor_declaration
2307 : opt_attributes ADD
2309 lexer.EventParsing = false;
2313 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2314 lexer.EventParsing = true;
2317 | opt_attributes ADD error {
2318 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2321 | opt_attributes modifiers ADD {
2322 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2327 remove_accessor_declaration
2328 : opt_attributes REMOVE
2330 lexer.EventParsing = false;
2334 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2335 lexer.EventParsing = true;
2337 | opt_attributes REMOVE error {
2338 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2341 | opt_attributes modifiers REMOVE {
2342 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2348 : opt_attributes opt_modifiers
2349 member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2352 implicit_value_parameter_type = (FullNamedExpression) $3;
2353 indexer_parameters = (Parameters) $6;
2355 if (indexer_parameters.IsEmpty)
2356 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2358 if (RootContext.Documentation != null) {
2359 tmpComment = Lexer.consume_doc_comment ();
2360 Lexer.doc_state = XmlCommentState.Allowed;
2363 lexer.PropertyParsing = true;
2364 parsing_indexer = true;
2367 accessor_declarations
2369 lexer.PropertyParsing = false;
2370 has_get = has_set = false;
2371 parsing_indexer = false;
2375 Accessors accessors = (Accessors) $10;
2376 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2377 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2378 bool order = accessors != null ? accessors.declared_in_reverse : false;
2380 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2381 (MemberName)$4, (int) $2, (Parameters) $6, (Attributes) $1,
2382 get_block, set_block, order);
2384 if ($3 == TypeManager.system_void_expr)
2385 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2387 if (accessors == null)
2388 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2390 if (current_container.Kind == Kind.Interface) {
2391 if (indexer.Get.Block != null)
2392 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2394 if (indexer.Set.Block != null)
2395 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2398 if (RootContext.Documentation != null)
2399 indexer.DocComment = ConsumeStoredComment ();
2401 current_container.AddIndexer (indexer);
2403 current_local_parameters = null;
2404 implicit_value_parameter_type = null;
2405 indexer_parameters = null;
2412 ENUM type_declaration_name
2414 if (RootContext.Documentation != null)
2415 enumTypeComment = Lexer.consume_doc_comment ();
2420 MemberName name = (MemberName) $4;
2421 if (name.IsGeneric) {
2422 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2425 name = MakeName (name);
2426 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2427 name, (Attributes) $1);
2429 if (RootContext.Documentation != null)
2430 e.DocComment = enumTypeComment;
2433 EnumMember em = null;
2434 foreach (VariableDeclaration ev in (ArrayList) $7) {
2435 em = new EnumMember (
2436 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2437 ev.OptAttributes, ev.Location);
2439 // if (RootContext.Documentation != null)
2440 em.DocComment = ev.DocComment;
2442 e.AddEnumMember (em);
2444 if (RootContext.EvalMode)
2445 undo.AddTypeContainer (current_container, e);
2447 current_container.AddTypeContainer (e);
2455 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2458 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2459 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2460 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2461 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2462 Enum.Error_1008 (GetLocation ($2));
2468 Error_TypeExpected (lexer.Location);
2475 if (RootContext.Documentation != null)
2476 Lexer.doc_state = XmlCommentState.Allowed;
2478 opt_enum_member_declarations
2480 // here will be evaluated after CLOSE_BLACE is consumed.
2481 if (RootContext.Documentation != null)
2482 Lexer.doc_state = XmlCommentState.Allowed;
2490 opt_enum_member_declarations
2491 : /* empty */ { $$ = new ArrayList (4); }
2492 | enum_member_declarations opt_comma { $$ = $1; }
2495 enum_member_declarations
2496 : enum_member_declaration
2498 ArrayList l = new ArrayList (4);
2503 | enum_member_declarations COMMA enum_member_declaration
2505 ArrayList l = (ArrayList) $1;
2513 enum_member_declaration
2514 : opt_attributes IDENTIFIER
2516 VariableDeclaration vd = new VariableDeclaration (
2517 (LocatedToken) $2, null, (Attributes) $1);
2519 if (RootContext.Documentation != null) {
2520 vd.DocComment = Lexer.consume_doc_comment ();
2521 Lexer.doc_state = XmlCommentState.Allowed;
2526 | opt_attributes IDENTIFIER
2528 ++lexer.parsing_block;
2529 if (RootContext.Documentation != null) {
2530 tmpComment = Lexer.consume_doc_comment ();
2531 Lexer.doc_state = XmlCommentState.NotAllowed;
2534 ASSIGN constant_expression
2536 --lexer.parsing_block;
2537 VariableDeclaration vd = new VariableDeclaration (
2538 (LocatedToken) $2, $5, (Attributes) $1);
2540 if (RootContext.Documentation != null)
2541 vd.DocComment = ConsumeStoredComment ();
2547 delegate_declaration
2551 member_type type_declaration_name
2552 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2554 MemberName name = MakeName ((MemberName) $5);
2555 Parameters p = (Parameters) $7;
2557 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2558 (int) $2, name, p, (Attributes) $1);
2560 if (RootContext.Documentation != null) {
2561 del.DocComment = Lexer.consume_doc_comment ();
2562 Lexer.doc_state = XmlCommentState.Allowed;
2565 current_container.AddDelegate (del);
2566 current_delegate = del;
2567 lexer.ConstraintsParsing = true;
2569 opt_type_parameter_constraints_clauses
2571 lexer.ConstraintsParsing = false;
2575 current_delegate.SetParameterInfo ((ArrayList) $10);
2576 $$ = current_delegate;
2578 current_delegate = null;
2589 if (RootContext.Version < LanguageVersion.ISO_2)
2590 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2596 namespace_or_type_name
2598 | qualified_alias_member IDENTIFIER opt_type_argument_list
2600 LocatedToken lt1 = (LocatedToken) $1;
2601 LocatedToken lt2 = (LocatedToken) $2;
2603 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2609 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2611 LocatedToken lt = (LocatedToken) $3;
2612 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2617 : IDENTIFIER opt_type_argument_list
2619 LocatedToken lt = (LocatedToken) $1;
2620 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2625 // Generics arguments (any type, without attributes)
2627 opt_type_argument_list
2628 : /* empty */ { $$ = null; }
2629 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2631 if (RootContext.Version < LanguageVersion.ISO_2)
2632 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2636 | OP_GENERICS_LT error
2638 Error_TypeExpected (lexer.Location);
2639 $$ = new TypeArguments ();
2646 TypeArguments type_args = new TypeArguments ();
2647 type_args.Add ((FullNamedExpression) $1);
2650 | type_arguments COMMA type
2652 TypeArguments type_args = (TypeArguments) $1;
2653 type_args.Add ((FullNamedExpression) $3);
2659 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2661 type_declaration_name
2664 lexer.parsing_generic_declaration = true;
2666 opt_type_parameter_list
2668 lexer.parsing_generic_declaration = false;
2669 LocatedToken lt = (LocatedToken) $1;
2670 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2674 member_declaration_name
2675 : method_declaration_name
2677 MemberName mn = (MemberName)$1;
2678 if (mn.TypeArguments != null)
2679 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2680 mn.GetSignatureForError ()));
2684 method_declaration_name
2685 : type_declaration_name
2686 | explicit_interface IDENTIFIER opt_type_parameter_list
2688 lexer.parsing_generic_declaration = false;
2689 LocatedToken lt = (LocatedToken) $2;
2690 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2694 indexer_declaration_name
2697 lexer.parsing_generic_declaration = false;
2698 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2700 | explicit_interface THIS
2702 lexer.parsing_generic_declaration = false;
2703 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2708 : IDENTIFIER opt_type_argument_list DOT
2710 LocatedToken lt = (LocatedToken) $1;
2711 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2713 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2715 LocatedToken lt1 = (LocatedToken) $1;
2716 LocatedToken lt2 = (LocatedToken) $2;
2718 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2720 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2722 LocatedToken lt = (LocatedToken) $2;
2723 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2727 opt_type_parameter_list
2728 : /* empty */ { $$ = null; }
2729 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2731 if (RootContext.Version < LanguageVersion.ISO_2)
2732 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2741 TypeArguments type_args = new TypeArguments ();
2742 type_args.Add ((FullNamedExpression)$1);
2745 | type_parameters COMMA type_parameter
2747 TypeArguments type_args = (TypeArguments) $1;
2748 type_args.Add ((FullNamedExpression)$3);
2754 : opt_attributes IDENTIFIER
2756 LocatedToken lt = (LocatedToken)$2;
2757 $$ = new TypeParameterName (lt.Value, (Attributes)$1, lt.Location);
2761 if (GetTokenName (yyToken) == "type")
2762 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2764 Error_SyntaxError (yyToken);
2766 $$ = new TypeParameterName ("", null, lexer.Location);
2771 // All types where void is allowed
2774 : type_expression_or_array
2777 $$ = TypeManager.system_void_expr;
2784 lexer.parsing_generic_declaration = true;
2789 // A type which does not allow `void' to be used
2792 : type_expression_or_array
2795 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2796 $$ = TypeManager.system_void_expr;
2804 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2805 $$ = TypeManager.system_void_expr;
2809 type_expression_or_array
2811 | type_expression rank_specifiers
2813 string rank_specifiers = (string) $2;
2814 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2819 : namespace_or_type_name opt_nullable
2821 MemberName name = (MemberName) $1;
2824 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2826 if (name.Left == null && name.Name == "var" &&
2827 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
2828 $$ = current_array_type = new VarExpr (name.Location);
2830 $$ = name.GetTypeExpression ();
2833 | builtin_types opt_nullable
2836 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2838 | type_expression STAR
2841 // Note that here only unmanaged types are allowed but we
2842 // can't perform checks during this phase - we do it during
2843 // semantic analysis.
2845 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2849 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2856 ArrayList types = new ArrayList (2);
2860 | type_list COMMA base_type_name
2862 ArrayList types = (ArrayList) $1;
2871 if ($1 is ComposedCast)
2872 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2877 Error_TypeExpected (lexer.Location);
2882 * replaces all the productions for isolating the various
2883 * simple types, but we need this to reuse it easily in variable_type
2886 : OBJECT { $$ = TypeManager.system_object_expr; }
2887 | STRING { $$ = TypeManager.system_string_expr; }
2888 | BOOL { $$ = TypeManager.system_boolean_expr; }
2889 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2890 | FLOAT { $$ = TypeManager.system_single_expr; }
2891 | DOUBLE { $$ = TypeManager.system_double_expr; }
2896 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2897 | BYTE { $$ = TypeManager.system_byte_expr; }
2898 | SHORT { $$ = TypeManager.system_int16_expr; }
2899 | USHORT { $$ = TypeManager.system_uint16_expr; }
2900 | INT { $$ = TypeManager.system_int32_expr; }
2901 | UINT { $$ = TypeManager.system_uint32_expr; }
2902 | LONG { $$ = TypeManager.system_int64_expr; }
2903 | ULONG { $$ = TypeManager.system_uint64_expr; }
2904 | CHAR { $$ = TypeManager.system_char_expr; }
2911 $$ = TypeManager.system_void_expr;
2916 // Expressions, section 7.5
2921 : primary_expression_no_array_creation
2922 | array_creation_expression
2925 primary_expression_no_array_creation
2927 | IDENTIFIER opt_type_argument_list
2929 LocatedToken lt = (LocatedToken) $1;
2930 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2932 | parenthesized_expression
2933 | default_value_expression
2935 | invocation_expression
2939 | post_increment_expression
2940 | post_decrement_expression
2941 | object_or_delegate_creation_expression
2942 | anonymous_type_expression
2945 | checked_expression
2946 | unchecked_expression
2947 | pointer_member_access
2948 | anonymous_method_expression
2955 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2956 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2957 | NULL { $$ = new NullLiteral (lexer.Location); }
2961 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2962 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2963 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2968 object v = lexer.Value;
2971 $$ = new IntLiteral ((int) v, lexer.Location);
2972 } else if (v is uint)
2973 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2975 $$ = new LongLiteral ((Int64) v, lexer.Location);
2976 else if (v is ulong)
2977 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2979 Console.WriteLine ("OOPS. Unexpected result from scanner");
2984 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2985 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2990 // Here is the trick, tokenizer may think that parens is a special but
2991 // parser is interested in open parens only, so we merge them.
2992 // Consider: if (a)foo ();
2997 | OPEN_PARENS_LAMBDA
3000 parenthesized_expression
3001 : OPEN_PARENS expression CLOSE_PARENS
3003 $$ = new ParenthesizedExpression ((Expression) $2);
3008 : primary_expression DOT IDENTIFIER opt_type_argument_list
3010 LocatedToken lt = (LocatedToken) $3;
3011 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3013 | predefined_type DOT IDENTIFIER opt_type_argument_list
3015 LocatedToken lt = (LocatedToken) $3;
3016 // TODO: Location is wrong as some predefined types doesn't hold a location
3017 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3019 | qualified_alias_member IDENTIFIER opt_type_argument_list
3021 LocatedToken lt1 = (LocatedToken) $1;
3022 LocatedToken lt2 = (LocatedToken) $2;
3024 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3028 invocation_expression
3029 : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3031 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3035 opt_object_or_collection_initializer
3036 : /* empty */ { $$ = null; }
3037 | object_or_collection_initializer
3040 object_or_collection_initializer
3041 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3044 $$ = CollectionOrObjectInitializers.Empty;
3046 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3048 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3050 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3054 opt_member_initializer_list
3055 : /* empty */ { $$ = null; }
3056 | member_initializer_list
3062 member_initializer_list
3063 : member_initializer
3065 ArrayList a = new ArrayList ();
3069 | member_initializer_list COMMA member_initializer
3071 ArrayList a = (ArrayList)$1;
3078 : IDENTIFIER ASSIGN initializer_value
3080 LocatedToken lt = $1 as LocatedToken;
3081 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3083 | non_assignment_expression
3085 $$ = new CollectionElementInitializer ((Expression)$1);
3087 | OPEN_BRACE expression_list CLOSE_BRACE
3089 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3091 | OPEN_BRACE CLOSE_BRACE
3093 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3099 | object_or_collection_initializer
3103 : /* empty */ { $$ = null; }
3110 ArrayList list = new ArrayList (4);
3114 | argument_list COMMA argument
3116 ArrayList list = (ArrayList) $1;
3120 | argument_list COMMA
3122 Report.Error (839, GetLocation ($2), "An argument is missing");
3127 Report.Error (839, GetLocation ($1), "An argument is missing");
3135 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3137 | non_simple_argument
3144 : REF variable_reference
3146 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3148 | OUT variable_reference
3150 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3152 | ARGLIST open_parens_any argument_list CLOSE_PARENS
3154 ArrayList list = (ArrayList) $3;
3155 Argument[] args = new Argument [list.Count];
3156 list.CopyTo (args, 0);
3158 Expression expr = new Arglist (args, (Location) $1);
3159 $$ = new Argument (expr, Argument.AType.Expression);
3161 | ARGLIST open_parens_any CLOSE_PARENS
3163 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3167 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3172 : expression { note ("section 5.4"); $$ = $1; }
3176 : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
3178 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3180 | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3182 // LAMESPEC: Not allowed according to specification
3183 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3185 | primary_expression_no_array_creation rank_specifiers
3187 // So the super-trick is that primary_expression
3188 // can only be either a SimpleName or a MemberAccess.
3189 // The MemberAccess case arises when you have a fully qualified type-name like :
3191 // SimpleName is when you have
3194 Expression expr = (Expression) $1;
3195 if (expr is ComposedCast){
3196 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3197 } else if (expr is ATypeNameExpression){
3199 // So we extract the string corresponding to the SimpleName
3202 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3204 Error_ExpectingTypeName (expr);
3205 $$ = TypeManager.system_object_expr;
3208 current_array_type = (FullNamedExpression)$$;
3215 ArrayList list = new ArrayList (4);
3219 | expression_list COMMA expression
3221 ArrayList list = (ArrayList) $1;
3230 $$ = new This (current_block, (Location) $1);
3235 : BASE DOT IDENTIFIER opt_type_argument_list
3237 LocatedToken lt = (LocatedToken) $3;
3238 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3240 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3242 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3245 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3250 post_increment_expression
3251 : primary_expression OP_INC
3253 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3257 post_decrement_expression
3258 : primary_expression OP_DEC
3260 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3264 object_or_delegate_creation_expression
3265 : NEW simple_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3268 if (RootContext.Version <= LanguageVersion.ISO_2)
3269 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3271 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3274 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3276 | NEW simple_type object_or_collection_initializer
3278 if (RootContext.Version <= LanguageVersion.ISO_2)
3279 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3281 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3286 array_creation_expression
3287 : NEW simple_type OPEN_BRACKET expression_list CLOSE_BRACKET
3288 opt_rank_specifier // shift/reduce on OPEN_BRACE
3289 opt_array_initializer
3291 $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3293 | NEW simple_type rank_specifiers opt_array_initializer
3296 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3298 $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3300 | NEW rank_specifiers array_initializer
3302 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3304 | NEW simple_type error
3306 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3311 anonymous_type_expression
3312 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3314 if (RootContext.Version <= LanguageVersion.ISO_2)
3315 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3317 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3321 anonymous_type_parameters_opt_comma
3322 : anonymous_type_parameters_opt
3323 | anonymous_type_parameters COMMA
3326 anonymous_type_parameters_opt
3328 | anonymous_type_parameters
3331 anonymous_type_parameters
3332 : anonymous_type_parameter
3334 ArrayList a = new ArrayList (4);
3338 | anonymous_type_parameters COMMA anonymous_type_parameter
3340 ArrayList a = (ArrayList) $1;
3346 anonymous_type_parameter
3347 : IDENTIFIER ASSIGN variable_initializer
3349 LocatedToken lt = (LocatedToken)$1;
3350 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3354 LocatedToken lt = (LocatedToken)$1;
3355 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3356 lt.Value, lt.Location);
3358 | BASE DOT IDENTIFIER opt_type_argument_list
3360 LocatedToken lt = (LocatedToken) $3;
3361 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3362 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3366 MemberAccess ma = (MemberAccess) $1;
3367 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3371 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3372 "Anonymous type members must be a member assignment, simple name or member access expression");
3387 opt_rank_specifier_or_nullable
3395 | opt_nullable rank_specifiers
3398 $$ = "?" + (string) $2;
3406 | rank_specifier rank_specifiers
3408 $$ = (string) $2 + (string) $1;
3413 : OPEN_BRACKET CLOSE_BRACKET
3417 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3419 $$ = "[" + (string) $2 + "]";
3421 | OPEN_BRACKET error CLOSE_BRACKET
3423 ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
3433 | dim_separators COMMA
3435 $$ = (string) $1 + ",";
3439 opt_array_initializer
3451 : OPEN_BRACE CLOSE_BRACE
3453 ArrayList list = new ArrayList (4);
3456 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3458 $$ = (ArrayList) $2;
3462 variable_initializer_list
3463 : variable_initializer
3465 ArrayList list = new ArrayList (4);
3469 | variable_initializer_list COMMA variable_initializer
3471 ArrayList list = (ArrayList) $1;
3477 Error_SyntaxError (yyToken);
3478 $$ = new ArrayList ();
3485 pushed_current_array_type = current_array_type;
3486 lexer.TypeOfParsing = true;
3488 open_parens_any typeof_type_expression CLOSE_PARENS
3490 lexer.TypeOfParsing = false;
3491 Expression type = (Expression)$4;
3492 if (type == TypeManager.system_void_expr)
3493 $$ = new TypeOfVoid ((Location) $1);
3495 $$ = new TypeOf (type, (Location) $1);
3496 current_array_type = pushed_current_array_type;
3500 typeof_type_expression
3505 Error_TypeExpected (lexer.Location);
3511 : IDENTIFIER generic_dimension
3513 LocatedToken lt = (LocatedToken) $1;
3515 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3517 | qualified_alias_member IDENTIFIER generic_dimension
3519 LocatedToken lt1 = (LocatedToken) $1;
3520 LocatedToken lt2 = (LocatedToken) $2;
3522 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3524 | unbound_type_name DOT IDENTIFIER
3526 LocatedToken lt = (LocatedToken) $3;
3528 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3530 | unbound_type_name DOT IDENTIFIER generic_dimension
3532 LocatedToken lt = (LocatedToken) $3;
3534 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3536 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3538 LocatedToken lt = (LocatedToken) $3;
3539 MemberName name = (MemberName) $1;
3541 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3548 if (RootContext.Version < LanguageVersion.ISO_2)
3549 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3555 qualified_alias_member
3556 : IDENTIFIER DOUBLE_COLON
3558 LocatedToken lt = (LocatedToken) $1;
3559 if (RootContext.Version == LanguageVersion.ISO_1)
3560 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3567 : SIZEOF open_parens_any type CLOSE_PARENS {
3568 $$ = new SizeOf ((Expression) $3, (Location) $1);
3573 : CHECKED open_parens_any expression CLOSE_PARENS
3575 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3579 unchecked_expression
3580 : UNCHECKED open_parens_any expression CLOSE_PARENS
3582 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3586 pointer_member_access
3587 : primary_expression OP_PTR IDENTIFIER
3590 LocatedToken lt = (LocatedToken) $3;
3592 deref = new Indirection ((Expression) $1, lt.Location);
3593 $$ = new MemberAccess (deref, lt.Value);
3597 anonymous_method_expression
3598 : DELEGATE opt_anonymous_method_signature
3600 start_anonymous (false, (Parameters) $2, (Location) $1);
3604 $$ = end_anonymous ((ToplevelBlock) $4);
3608 opt_anonymous_method_signature
3611 $$ = Parameters.Undefined;
3613 | anonymous_method_signature
3616 anonymous_method_signature
3619 params_modifiers_not_allowed = true;
3621 opt_formal_parameter_list CLOSE_PARENS
3623 params_modifiers_not_allowed = false;
3628 default_value_expression
3629 : DEFAULT open_parens_any type CLOSE_PARENS
3631 if (RootContext.Version < LanguageVersion.ISO_2)
3632 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3634 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3639 : primary_expression
3640 | BANG prefixed_unary_expression
3642 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3644 | TILDE prefixed_unary_expression
3646 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3652 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3654 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3656 | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3658 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3663 // The idea to split this out is from Rhys' grammar
3664 // to solve the problem with casts.
3666 prefixed_unary_expression
3668 | PLUS prefixed_unary_expression
3670 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3672 | MINUS prefixed_unary_expression
3674 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3676 | OP_INC prefixed_unary_expression
3678 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3680 | OP_DEC prefixed_unary_expression
3682 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3684 | STAR prefixed_unary_expression
3686 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3688 | BITWISE_AND prefixed_unary_expression
3690 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3694 multiplicative_expression
3695 : prefixed_unary_expression
3696 | multiplicative_expression STAR prefixed_unary_expression
3698 $$ = new Binary (Binary.Operator.Multiply,
3699 (Expression) $1, (Expression) $3);
3701 | multiplicative_expression DIV prefixed_unary_expression
3703 $$ = new Binary (Binary.Operator.Division,
3704 (Expression) $1, (Expression) $3);
3706 | multiplicative_expression PERCENT prefixed_unary_expression
3708 $$ = new Binary (Binary.Operator.Modulus,
3709 (Expression) $1, (Expression) $3);
3714 : multiplicative_expression
3715 | additive_expression PLUS multiplicative_expression
3717 $$ = new Binary (Binary.Operator.Addition,
3718 (Expression) $1, (Expression) $3);
3720 | additive_expression MINUS multiplicative_expression
3722 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3724 | parenthesized_expression MINUS multiplicative_expression
3726 // Shift/Reduce conflict
3727 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3729 | additive_expression AS type
3731 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3733 | additive_expression IS type
3735 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3740 : additive_expression
3741 | shift_expression OP_SHIFT_LEFT additive_expression
3743 $$ = new Binary (Binary.Operator.LeftShift,
3744 (Expression) $1, (Expression) $3);
3746 | shift_expression OP_SHIFT_RIGHT additive_expression
3748 $$ = new Binary (Binary.Operator.RightShift,
3749 (Expression) $1, (Expression) $3);
3753 relational_expression
3755 | relational_expression OP_LT shift_expression
3757 $$ = new Binary (Binary.Operator.LessThan,
3758 (Expression) $1, (Expression) $3);
3760 | relational_expression OP_GT shift_expression
3762 $$ = new Binary (Binary.Operator.GreaterThan,
3763 (Expression) $1, (Expression) $3);
3765 | relational_expression OP_LE shift_expression
3767 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3768 (Expression) $1, (Expression) $3);
3770 | relational_expression OP_GE shift_expression
3772 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3773 (Expression) $1, (Expression) $3);
3778 : relational_expression
3779 | equality_expression OP_EQ relational_expression
3781 $$ = new Binary (Binary.Operator.Equality,
3782 (Expression) $1, (Expression) $3);
3784 | equality_expression OP_NE relational_expression
3786 $$ = new Binary (Binary.Operator.Inequality,
3787 (Expression) $1, (Expression) $3);
3792 : equality_expression
3793 | and_expression BITWISE_AND equality_expression
3795 $$ = new Binary (Binary.Operator.BitwiseAnd,
3796 (Expression) $1, (Expression) $3);
3800 exclusive_or_expression
3802 | exclusive_or_expression CARRET and_expression
3804 $$ = new Binary (Binary.Operator.ExclusiveOr,
3805 (Expression) $1, (Expression) $3);
3809 inclusive_or_expression
3810 : exclusive_or_expression
3811 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3813 $$ = new Binary (Binary.Operator.BitwiseOr,
3814 (Expression) $1, (Expression) $3);
3818 conditional_and_expression
3819 : inclusive_or_expression
3820 | conditional_and_expression OP_AND inclusive_or_expression
3822 $$ = new Binary (Binary.Operator.LogicalAnd,
3823 (Expression) $1, (Expression) $3);
3827 conditional_or_expression
3828 : conditional_and_expression
3829 | conditional_or_expression OP_OR conditional_and_expression
3831 $$ = new Binary (Binary.Operator.LogicalOr,
3832 (Expression) $1, (Expression) $3);
3836 null_coalescing_expression
3837 : conditional_or_expression
3838 | conditional_or_expression OP_COALESCING null_coalescing_expression
3840 if (RootContext.Version < LanguageVersion.ISO_2)
3841 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3843 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3847 conditional_expression
3848 : null_coalescing_expression
3849 | null_coalescing_expression INTERR expression COLON expression
3851 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3855 assignment_expression
3856 : prefixed_unary_expression ASSIGN expression
3858 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3860 | prefixed_unary_expression OP_MULT_ASSIGN expression
3862 $$ = new CompoundAssign (
3863 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3865 | prefixed_unary_expression OP_DIV_ASSIGN expression
3867 $$ = new CompoundAssign (
3868 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3870 | prefixed_unary_expression OP_MOD_ASSIGN expression
3872 $$ = new CompoundAssign (
3873 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3875 | prefixed_unary_expression OP_ADD_ASSIGN expression
3877 $$ = new CompoundAssign (
3878 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3880 | prefixed_unary_expression OP_SUB_ASSIGN expression
3882 $$ = new CompoundAssign (
3883 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3885 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3887 $$ = new CompoundAssign (
3888 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3890 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3892 $$ = new CompoundAssign (
3893 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3895 | prefixed_unary_expression OP_AND_ASSIGN expression
3897 $$ = new CompoundAssign (
3898 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3900 | prefixed_unary_expression OP_OR_ASSIGN expression
3902 $$ = new CompoundAssign (
3903 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3905 | prefixed_unary_expression OP_XOR_ASSIGN expression
3907 $$ = new CompoundAssign (
3908 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3912 lambda_parameter_list
3915 ArrayList pars = new ArrayList (4);
3920 | lambda_parameter_list COMMA lambda_parameter
3922 ArrayList pars = (ArrayList) $1;
3923 Parameter p = (Parameter)$3;
3924 if (pars[0].GetType () != p.GetType ()) {
3925 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
3934 : parameter_modifier type IDENTIFIER
3936 LocatedToken lt = (LocatedToken) $3;
3938 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3942 LocatedToken lt = (LocatedToken) $2;
3944 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
3948 LocatedToken lt = (LocatedToken) $1;
3949 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
3953 opt_lambda_parameter_list
3954 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
3955 | lambda_parameter_list {
3956 ArrayList pars_list = (ArrayList) $1;
3957 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
3961 lambda_expression_body
3963 start_block (lexer.Location);
3967 Block b = end_block (lexer.Location);
3968 b.AddStatement (new ContextualReturn ((Expression) $2));
3979 LocatedToken lt = (LocatedToken) $1;
3980 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
3981 start_anonymous (true, new Parameters (p), GetLocation ($1));
3983 lambda_expression_body
3985 $$ = end_anonymous ((ToplevelBlock) $4);
3987 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
3989 start_anonymous (true, (Parameters) $2, GetLocation ($1));
3991 lambda_expression_body
3993 $$ = end_anonymous ((ToplevelBlock) $6);
3998 : assignment_expression
3999 | non_assignment_expression
4002 non_assignment_expression
4003 : conditional_expression
4025 lexer.ConstraintsParsing = true;
4027 type_declaration_name
4029 MemberName name = MakeName ((MemberName) $6);
4030 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4033 opt_type_parameter_constraints_clauses
4035 lexer.ConstraintsParsing = false;
4037 current_class.SetParameterInfo ((ArrayList) $9);
4039 if (RootContext.Documentation != null) {
4040 current_container.DocComment = Lexer.consume_doc_comment ();
4041 Lexer.doc_state = XmlCommentState.Allowed;
4046 --lexer.parsing_declaration;
4047 if (RootContext.Documentation != null)
4048 Lexer.doc_state = XmlCommentState.Allowed;
4052 $$ = pop_current_class ();
4060 { $$ = $1; } // location
4064 : /* empty */ { $$ = (int) 0; }
4070 | modifiers modifier
4075 if ((m1 & m2) != 0) {
4076 Location l = lexer.Location;
4077 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4079 $$ = (int) (m1 | m2);
4087 if (current_container == RootContext.ToplevelTypes)
4088 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4090 | PUBLIC { $$ = Modifiers.PUBLIC; }
4091 | PROTECTED { $$ = Modifiers.PROTECTED; }
4092 | INTERNAL { $$ = Modifiers.INTERNAL; }
4093 | PRIVATE { $$ = Modifiers.PRIVATE; }
4094 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4095 | SEALED { $$ = Modifiers.SEALED; }
4096 | STATIC { $$ = Modifiers.STATIC; }
4097 | READONLY { $$ = Modifiers.READONLY; }
4098 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4099 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4100 | EXTERN { $$ = Modifiers.EXTERN; }
4101 | VOLATILE { $$ = Modifiers.VOLATILE; }
4102 | UNSAFE { $$ = Modifiers.UNSAFE; }
4111 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4114 opt_type_parameter_constraints_clauses
4115 : /* empty */ { $$ = null; }
4116 | type_parameter_constraints_clauses
4120 type_parameter_constraints_clauses
4121 : type_parameter_constraints_clause {
4122 ArrayList constraints = new ArrayList (1);
4123 constraints.Add ($1);
4126 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4127 ArrayList constraints = (ArrayList) $1;
4128 Constraints new_constraint = (Constraints)$2;
4130 foreach (Constraints c in constraints) {
4131 if (new_constraint.TypeParameter == c.TypeParameter) {
4132 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4133 new_constraint.TypeParameter);
4137 constraints.Add (new_constraint);
4142 type_parameter_constraints_clause
4143 : WHERE IDENTIFIER COLON type_parameter_constraints {
4144 LocatedToken lt = (LocatedToken) $2;
4145 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4149 type_parameter_constraints
4150 : type_parameter_constraint {
4151 ArrayList constraints = new ArrayList (1);
4152 constraints.Add ($1);
4155 | type_parameter_constraints COMMA type_parameter_constraint {
4156 ArrayList constraints = (ArrayList) $1;
4158 constraints.Add ($3);
4163 type_parameter_constraint
4165 | NEW OPEN_PARENS CLOSE_PARENS {
4166 $$ = SpecialConstraint.Constructor;
4169 $$ = SpecialConstraint.ReferenceType;
4172 $$ = SpecialConstraint.ValueType;
4181 // A block is "contained" on the following places:
4183 // property_declaration as part of the accessor body (get/set)
4184 // operator_declaration
4185 // constructor_declaration
4186 // destructor_declaration
4187 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4192 ++lexer.parsing_block;
4193 start_block ((Location) $1);
4195 opt_statement_list CLOSE_BRACE
4197 --lexer.parsing_block;
4198 $$ = end_block ((Location) $4);
4205 ++lexer.parsing_block;
4206 current_block.StartLocation = GetLocation ($1);
4208 opt_statement_list CLOSE_BRACE
4210 --lexer.parsing_block;
4211 $$ = end_block ((Location) $4);
4222 | statement_list statement
4226 : declaration_statement
4228 if ($1 != null && (Block) $1 != current_block){
4229 current_block.AddStatement ((Statement) $1);
4230 current_block = (Block) $1;
4233 | valid_declaration_statement
4235 current_block.AddStatement ((Statement) $1);
4241 // The interactive_statement and its derivatives are only
4242 // used to provide a special version of `expression_statement'
4243 // that has a side effect of assigning the expression to
4246 interactive_statement_list
4247 : interactive_statement
4248 | interactive_statement_list interactive_statement
4251 interactive_statement
4252 : declaration_statement
4254 if ($1 != null && (Block) $1 != current_block){
4255 current_block.AddStatement ((Statement) $1);
4256 current_block = (Block) $1;
4259 | interactive_valid_declaration_statement
4261 current_block.AddStatement ((Statement) $1);
4266 valid_declaration_statement
4269 | expression_statement
4270 | selection_statement
4271 | iteration_statement
4275 | unchecked_statement
4282 interactive_valid_declaration_statement
4285 | interactive_expression_statement
4286 | selection_statement
4287 | iteration_statement
4291 | unchecked_statement
4299 : valid_declaration_statement
4300 | declaration_statement
4302 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4307 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4315 $$ = EmptyStatement.Value;
4322 LocatedToken lt = (LocatedToken) $1;
4323 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4325 if (current_block.AddLabel (labeled))
4326 current_block.AddStatement (labeled);
4331 declaration_statement
4332 : local_variable_declaration SEMICOLON
4334 current_array_type = null;
4336 DictionaryEntry de = (DictionaryEntry) $1;
4337 Expression e = (Expression) de.Key;
4339 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4343 | local_constant_declaration SEMICOLON
4345 current_array_type = null;
4347 DictionaryEntry de = (DictionaryEntry) $1;
4349 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4355 * The following is from Rhys' grammar:
4356 * > Types in local variable declarations must be recognized as
4357 * > expressions to prevent reduce/reduce errors in the grammar.
4358 * > The expressions are converted into types during semantic analysis.
4361 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4363 // FIXME: Do something smart here regarding the composition of the type.
4365 // Ok, the above "primary_expression" is there to get rid of
4366 // both reduce/reduce and shift/reduces in the grammar, it should
4367 // really just be "type_name". If you use type_name, a reduce/reduce
4368 // creeps up. If you use namespace_or_type_name (which is all we need
4369 // really) two shift/reduces appear.
4372 // So the super-trick is that primary_expression
4373 // can only be either a SimpleName or a MemberAccess.
4374 // The MemberAccess case arises when you have a fully qualified type-name like :
4376 // SimpleName is when you have
4379 Expression expr = (Expression) $1;
4380 string rank_or_nullable = (string) $2;
4382 if (expr is ComposedCast){
4383 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4384 } else if (expr is ATypeNameExpression){
4386 // So we extract the string corresponding to the SimpleName
4389 if (rank_or_nullable.Length == 0) {
4390 SimpleName sn = expr as SimpleName;
4391 if (sn != null && sn.Name == "var" &&
4392 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
4393 $$ = current_array_type = new VarExpr (sn.Location);
4397 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4400 Error_ExpectingTypeName (expr);
4401 $$ = TypeManager.system_object_expr;
4404 | builtin_types opt_rank_specifier_or_nullable
4406 if ((string) $2 == "")
4409 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4411 | VOID opt_rank_specifier
4413 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4414 $$ = TypeManager.system_void_expr;
4418 local_variable_pointer_type
4419 : primary_expression_no_array_creation STAR
4421 ATypeNameExpression expr = $1 as ATypeNameExpression;
4424 $$ = new ComposedCast (expr, "*");
4426 Error_ExpectingTypeName ((Expression)$1);
4430 | builtin_types STAR
4432 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4436 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4438 | local_variable_pointer_type STAR
4440 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4446 | local_variable_pointer_type opt_rank_specifier
4449 string rank = (string)$2;
4454 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4461 local_variable_declaration
4462 : local_variable_type local_variable_declarators
4465 VarExpr ve = $1 as VarExpr;
4467 ve.VariableInitializer = (ArrayList)$2;
4469 $$ = new DictionaryEntry ($1, $2);
4475 local_constant_declaration
4476 : CONST variable_type constant_declarators
4479 $$ = new DictionaryEntry ($2, $3);
4485 expression_statement
4486 : statement_expression SEMICOLON { $$ = $1; }
4489 interactive_expression_statement
4490 : interactive_statement_expression SEMICOLON { $$ = $1; }
4494 // We have to do the wrapping here and not in the case above,
4495 // because statement_expression is used for example in for_statement
4497 statement_expression
4500 ExpressionStatement s = $1 as ExpressionStatement;
4502 ((Expression) $1).Error_InvalidExpressionStatement ();
4503 s = EmptyExpressionStatement.Instance;
4506 $$ = new StatementExpression (s);
4510 Error_SyntaxError (yyToken);
4515 interactive_statement_expression
4518 Expression expr = (Expression) $1;
4519 ExpressionStatement s;
4521 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4522 $$ = new StatementExpression (s);
4526 Error_SyntaxError (yyToken);
4537 : IF open_parens_any boolean_expression CLOSE_PARENS
4540 Location l = (Location) $1;
4542 $$ = new If ((Expression) $3, (Statement) $5, l);
4544 // FIXME: location for warning should be loc property of $5.
4545 if ($5 == EmptyStatement.Value)
4546 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4549 | IF open_parens_any boolean_expression CLOSE_PARENS
4550 embedded_statement ELSE embedded_statement
4552 Location l = (Location) $1;
4554 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4556 // FIXME: location for warning should be loc property of $5 and $7.
4557 if ($5 == EmptyStatement.Value)
4558 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4559 if ($7 == EmptyStatement.Value)
4560 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4565 : SWITCH open_parens_any
4567 if (switch_stack == null)
4568 switch_stack = new Stack (2);
4569 switch_stack.Push (current_block);
4571 expression CLOSE_PARENS
4574 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4575 current_block = (Block) switch_stack.Pop ();
4591 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4592 $$ = new ArrayList ();
4600 ArrayList sections = new ArrayList (4);
4605 | switch_sections switch_section
4607 ArrayList sections = (ArrayList) $1;
4617 current_block = current_block.CreateSwitchBlock (lexer.Location);
4621 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4628 ArrayList labels = new ArrayList (4);
4633 | switch_labels switch_label
4635 ArrayList labels = (ArrayList) ($1);
4643 : CASE constant_expression COLON
4645 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4649 $$ = new SwitchLabel (null, (Location) $1);
4661 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4663 Location l = (Location) $1;
4664 $$ = new While ((Expression) $3, (Statement) $5, l);
4669 : DO embedded_statement
4670 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4672 Location l = (Location) $1;
4674 $$ = new Do ((Statement) $2, (Expression) $5, l);
4679 : FOR open_parens_any opt_for_initializer SEMICOLON
4681 Location l = lexer.Location;
4683 Block assign_block = current_block;
4685 if ($3 is DictionaryEntry){
4686 DictionaryEntry de = (DictionaryEntry) $3;
4688 Expression type = (Expression) de.Key;
4689 ArrayList var_declarators = (ArrayList) de.Value;
4691 foreach (VariableDeclaration decl in var_declarators){
4695 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4699 Expression expr = decl.expression_or_array_initializer;
4701 LocalVariableReference var;
4702 var = new LocalVariableReference (assign_block, decl.identifier, l);
4705 Assign a = new SimpleAssign (var, expr, decl.Location);
4707 assign_block.AddStatement (new StatementExpression (a));
4711 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4712 // This can be referred to as $5 below.
4718 opt_for_condition SEMICOLON
4719 opt_for_iterator CLOSE_PARENS
4722 Location l = (Location) $1;
4724 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4726 current_block.AddStatement (f);
4728 $$ = end_block (lexer.Location);
4733 : /* empty */ { $$ = EmptyStatement.Value; }
4738 : local_variable_declaration
4739 | statement_expression_list
4743 : /* empty */ { $$ = null; }
4744 | boolean_expression
4748 : /* empty */ { $$ = EmptyStatement.Value; }
4753 : statement_expression_list
4756 statement_expression_list
4757 : statement_expression
4759 // CHANGE: was `null'
4760 Statement s = (Statement) $1;
4761 Block b = new Block (current_block, s.loc, lexer.Location);
4766 | statement_expression_list COMMA statement_expression
4768 Block b = (Block) $1;
4770 b.AddStatement ((Statement) $3);
4776 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4778 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4781 | FOREACH open_parens_any type IDENTIFIER IN
4782 expression CLOSE_PARENS
4784 start_block (lexer.Location);
4785 Block foreach_block = current_block;
4787 LocatedToken lt = (LocatedToken) $4;
4788 Location l = lt.Location;
4789 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4791 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4793 // Get a writable reference to this read-only variable.
4795 // Note that the $$ here refers to the value of _this_ code block,
4796 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4797 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4804 LocalVariableReference v = (LocalVariableReference) $8;
4805 Location l = (Location) $1;
4808 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4809 current_block.AddStatement (f);
4812 $$ = end_block (lexer.Location);
4818 | continue_statement
4828 $$ = new Break ((Location) $1);
4833 : CONTINUE SEMICOLON
4835 $$ = new Continue ((Location) $1);
4840 : GOTO IDENTIFIER SEMICOLON
4842 LocatedToken lt = (LocatedToken) $2;
4843 $$ = new Goto (lt.Value, lt.Location);
4845 | GOTO CASE constant_expression SEMICOLON
4847 $$ = new GotoCase ((Expression) $3, (Location) $1);
4849 | GOTO DEFAULT SEMICOLON
4851 $$ = new GotoDefault ((Location) $1);
4856 : RETURN opt_expression SEMICOLON
4858 $$ = new Return ((Expression) $2, (Location) $1);
4863 : THROW opt_expression SEMICOLON
4865 $$ = new Throw ((Expression) $2, (Location) $1);
4870 : IDENTIFIER RETURN expression SEMICOLON
4872 LocatedToken lt = (LocatedToken) $1;
4873 string s = lt.Value;
4875 Report.Error (1003, lt.Location, "; expected");
4878 if (RootContext.Version == LanguageVersion.ISO_1){
4879 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4882 current_block.Toplevel.IsIterator = true;
4883 $$ = new Yield ((Expression) $3, lt.Location);
4885 | IDENTIFIER RETURN SEMICOLON
4887 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4890 | IDENTIFIER BREAK SEMICOLON
4892 LocatedToken lt = (LocatedToken) $1;
4893 string s = lt.Value;
4895 Report.Error (1003, lt.Location, "; expected");
4898 if (RootContext.Version == LanguageVersion.ISO_1){
4899 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4903 current_block.Toplevel.IsIterator = true;
4904 $$ = new YieldBreak (lt.Location);
4914 : TRY block catch_clauses
4916 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
4918 | TRY block FINALLY block
4920 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
4922 | TRY block catch_clauses FINALLY block
4924 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
4928 Report.Error (1524, (Location) $1, "Expected catch or finally");
4936 ArrayList l = new ArrayList (4);
4941 | catch_clauses catch_clause
4943 ArrayList l = (ArrayList) $1;
4951 : /* empty */ { $$ = null; }
4956 : CATCH opt_catch_args
4958 Expression type = null;
4961 DictionaryEntry cc = (DictionaryEntry) $2;
4962 type = (Expression) cc.Key;
4963 LocatedToken lt = (LocatedToken) cc.Value;
4966 ArrayList one = new ArrayList (4);
4968 one.Add (new VariableDeclaration (lt, null));
4970 start_block (lexer.Location);
4971 current_block = declare_local_variables (type, one, lt.Location);
4975 Expression type = null;
4977 Block var_block = null;
4980 DictionaryEntry cc = (DictionaryEntry) $2;
4981 type = (Expression) cc.Key;
4982 LocatedToken lt = (LocatedToken) cc.Value;
4986 var_block = end_block (lexer.Location);
4990 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
4995 : /* empty */ { $$ = null; }
5000 : open_parens_any type opt_identifier CLOSE_PARENS
5002 $$ = new DictionaryEntry ($2, $3);
5004 | open_parens_any CLOSE_PARENS
5006 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5013 $$ = new Checked ((Block) $2);
5020 $$ = new Unchecked ((Block) $2);
5027 RootContext.CheckUnsafeOption ((Location) $1);
5029 $$ = new Unsafe ((Block) $3);
5034 : FIXED open_parens_any
5035 type_and_void fixed_pointer_declarators
5038 ArrayList list = (ArrayList) $4;
5039 Expression type = (Expression) $3;
5040 Location l = (Location) $1;
5041 int top = list.Count;
5043 start_block (lexer.Location);
5045 for (int i = 0; i < top; i++){
5046 Pair p = (Pair) list [i];
5049 v = current_block.AddVariable (type, (string) p.First, l);
5053 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5061 Location l = (Location) $1;
5063 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5065 current_block.AddStatement (f);
5067 $$ = end_block (lexer.Location);
5071 fixed_pointer_declarators
5072 : fixed_pointer_declarator {
5073 ArrayList declarators = new ArrayList (4);
5075 declarators.Add ($1);
5078 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5080 ArrayList declarators = (ArrayList) $1;
5082 declarators.Add ($3);
5087 fixed_pointer_declarator
5088 : IDENTIFIER ASSIGN expression
5090 LocatedToken lt = (LocatedToken) $1;
5091 // FIXME: keep location
5092 $$ = new Pair (lt.Value, $3);
5096 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5102 : LOCK open_parens_any expression CLOSE_PARENS
5108 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5113 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5115 start_block (lexer.Location);
5116 Block assign_block = current_block;
5118 DictionaryEntry de = (DictionaryEntry) $3;
5119 Location l = (Location) $1;
5121 Expression type = (Expression) de.Key;
5122 ArrayList var_declarators = (ArrayList) de.Value;
5124 Stack vars = new Stack ();
5126 foreach (VariableDeclaration decl in var_declarators) {
5127 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5130 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5132 Expression expr = decl.expression_or_array_initializer;
5134 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5137 LocalVariableReference var;
5139 // Get a writable reference to this read-only variable.
5140 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5142 // This is so that it is not a warning on using variables
5145 vars.Push (new DictionaryEntry (var, expr));
5147 // Assign a = new SimpleAssign (var, expr, decl.Location);
5148 // assign_block.AddStatement (new StatementExpression (a));
5151 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5152 // It can be referred to as $5 below.
5157 Statement stmt = (Statement) $6;
5158 Stack vars = (Stack) $5;
5159 Location l = (Location) $1;
5161 while (vars.Count > 0) {
5162 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5163 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5165 current_block.AddStatement (stmt);
5166 $$ = end_block (lexer.Location);
5168 | USING open_parens_any expression CLOSE_PARENS
5170 start_block (lexer.Location);
5174 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5175 $$ = end_block (lexer.Location);
5185 ++lexer.query_parsing;
5189 if (--lexer.query_parsing == 1)
5190 lexer.query_parsing = 0;
5192 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5194 from.Tail.Next = (Linq.AQueryClause)$3;
5197 current_block.SetEndLocation (lexer.Location);
5198 current_block = current_block.Parent;
5203 : FROM IDENTIFIER IN expression
5205 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5206 LocatedToken lt = (LocatedToken) $2;
5208 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
5209 $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
5211 | FROM type IDENTIFIER IN expression
5213 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5214 LocatedToken lt = (LocatedToken) $3;
5216 FullNamedExpression type = (FullNamedExpression)$2;
5217 current_block.AddVariable (type, lt.Value, lt.Location);
5218 $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
5223 : FROM IDENTIFIER IN expression
5225 LocatedToken lt = (LocatedToken) $2;
5227 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5228 lt.Value, lt.Location);
5230 $$ = new Linq.SelectMany (lt, (Expression)$4);
5232 | FROM type IDENTIFIER IN expression
5234 LocatedToken lt = (LocatedToken) $3;
5236 FullNamedExpression type = (FullNamedExpression)$2;
5237 current_block.AddVariable (type, lt.Value, lt.Location);
5238 $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (FullNamedExpression)$5));
5243 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5245 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5248 head.Next = (Linq.AQueryClause)$3;
5251 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5252 clause.Tail.Next = head;
5260 select_or_group_clause
5263 $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
5265 | GROUP expression BY expression
5267 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5271 opt_query_body_clauses
5273 | query_body_clauses
5278 | query_body_clauses query_body_clause
5280 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5294 : LET IDENTIFIER ASSIGN expression
5296 LocatedToken lt = (LocatedToken) $2;
5297 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5298 lt.Value, lt.Location);
5299 $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
5304 : WHERE boolean_expression
5306 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5311 : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5313 Location loc = GetLocation ($1);
5314 LocatedToken lt = (LocatedToken) $2;
5315 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5316 lt.Value, lt.Location);
5319 $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
5320 (Expression)$8, loc);
5322 LocatedToken lt_into = (LocatedToken) $9;
5323 $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
5324 (Expression)$8, lt_into, loc);
5327 | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5329 Location loc = GetLocation ($1);
5330 LocatedToken lt = (LocatedToken) $3;
5331 current_block.AddVariable ((FullNamedExpression)$2, lt.Value, lt.Location);
5333 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$5);
5335 $$ = new Linq.Join (lt, cast, (Expression)$7,
5336 (Expression)$9, loc);
5338 LocatedToken lt_into = (LocatedToken) $10;
5339 $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
5340 (Expression)$9, lt_into, loc);
5362 | order_by COMMA orderings_then_by
5364 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5374 | orderings_then_by COMMA then_by
5376 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5384 $$ = new Linq.OrderByAscending ((Expression)$1);
5386 | expression ASCENDING
5388 $$ = new Linq.OrderByAscending ((Expression)$1);
5390 | expression DESCENDING
5392 $$ = new Linq.OrderByDescending ((Expression)$1);
5399 $$ = new Linq.ThenByAscending ((Expression)$1);
5401 | expression ASCENDING
5403 $$ = new Linq.ThenByAscending ((Expression)$1);
5405 | expression DESCENDING
5407 $$ = new Linq.ThenByDescending ((Expression)$1);
5412 opt_query_continuation
5416 // query continuation block is not linked with query block but with block
5417 // before. This means each query can use same range variable names for
5418 // different identifiers.
5420 current_block.SetEndLocation (GetLocation ($1));
5421 current_block = current_block.Parent;
5422 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5424 LocatedToken lt = (LocatedToken) $2;
5425 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5426 lt.Value, lt.Location);
5430 $$ = new Linq.QueryExpression ((LocatedToken) $2,
5431 (Linq.AQueryClause)$4);
5436 // Support for using the compiler as an interactive parser
5438 // The INTERACTIVE_PARSER token is first sent to parse our
5439 // productions; If the result is a Statement, the parsing
5440 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5441 // to setup the blocks in advance.
5443 // This setup is here so that in the future we can add
5444 // support for other constructs (type parsing, namespaces, etc)
5445 // that do not require a block to be setup in advance
5449 : EVAL_STATEMENT_PARSER EOF
5450 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5451 | EVAL_STATEMENT_PARSER {
5452 Evaluator.LoadAliases (current_namespace);
5454 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5455 Modifiers.PUBLIC, null), null);
5457 ArrayList baseclass_list = new ArrayList ();
5458 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5459 current_container.AddBasesForPart (current_class, baseclass_list);
5461 // (ref object retval)
5462 Parameter [] mpar = new Parameter [1];
5463 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5465 Parameters pars = new Parameters (mpar);
5466 current_local_parameters = pars;
5467 Method method = new Method (
5470 TypeManager.system_void_expr,
5471 Modifiers.PUBLIC | Modifiers.STATIC,
5472 new MemberName ("Host"),
5474 null /* attributes */);
5476 oob_stack.Push (method);
5477 ++lexer.parsing_block;
5478 start_block (lexer.Location);
5480 interactive_statement_list
5482 --lexer.parsing_block;
5483 Method method = (Method) oob_stack.Pop ();
5485 method.Block = (ToplevelBlock) end_block(lexer.Location);
5486 current_container.AddMethod (method);
5488 --lexer.parsing_declaration;
5489 InteractiveResult = pop_current_class ();
5490 current_local_parameters = null;
5492 | EVAL_COMPILATION_UNIT_PARSER {
5493 Evaluator.LoadAliases (current_namespace);
5495 interactive_compilation_unit
5498 interactive_compilation_unit
5499 : outer_declarations
5500 | outer_declarations global_attributes
5507 // A class used to pass around variable declarations and constants
5509 public class VariableDeclaration {
5510 public string identifier;
5511 public Expression expression_or_array_initializer;
5512 public Location Location;
5513 public Attributes OptAttributes;
5514 public string DocComment;
5516 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5518 this.identifier = lt.Value;
5519 if (eoai is ArrayList) {
5520 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5522 this.expression_or_array_initializer = (Expression)eoai;
5524 this.Location = lt.Location;
5525 this.OptAttributes = opt_attrs;
5528 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5533 class VariableMemberDeclaration
5535 public readonly MemberName MemberName;
5536 public Expression expression_or_array_initializer;
5538 public VariableMemberDeclaration (MemberName mn, object initializer)
5542 if (initializer is ArrayList) {
5543 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5545 this.expression_or_array_initializer = (Expression)initializer;
5552 // A class used to hold info about an operator declarator
5554 struct OperatorDeclaration {
5555 public readonly Operator.OpType optype;
5556 public readonly FullNamedExpression ret_type;
5557 public readonly Location location;
5559 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5562 this.ret_type = ret_type;
5563 this.location = location;
5567 void Error_ExpectingTypeName (Expression expr)
5569 if (expr is Invocation){
5570 Report.Error (1002, expr.Location, "Expecting `;'");
5572 expr.Error_InvalidExpressionStatement ();
5576 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5578 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5582 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5584 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5585 Parameter.GetModifierSignature (mod));
5588 static void Error_TypeExpected (Location loc)
5590 Report.Error (1031, loc, "Type expected");
5593 void push_current_class (TypeContainer tc, object partial_token)
5595 if (RootContext.EvalMode){
5596 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5597 undo.AddTypeContainer (current_container, tc);
5600 if (partial_token != null)
5601 current_container = current_container.AddPartial (tc);
5603 current_container = current_container.AddTypeContainer (tc);
5605 ++lexer.parsing_declaration;
5609 DeclSpace pop_current_class ()
5611 DeclSpace retval = current_class;
5613 current_class = current_class.Parent;
5614 current_container = current_class.PartialContainer;
5620 // Given the @class_name name, it creates a fully qualified name
5621 // based on the containing declaration space
5624 MakeName (MemberName class_name)
5626 Namespace ns = current_namespace.NS;
5628 if (current_container == RootContext.ToplevelTypes) {
5629 if (ns.Name.Length != 0)
5630 return new MemberName (ns.MemberName, class_name);
5634 return new MemberName (current_container.MemberName, class_name);
5638 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5640 Block implicit_block;
5641 ArrayList inits = null;
5644 // If we are doing interactive editing, we want variable declarations
5645 // that are in the top block to be added instead to the class as
5648 if (RootContext.StatementMode){
5651 for (Block b = current_block; b != null; b = b.Parent){
5652 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5653 // There has been an explicit block, we cant add to the class
5660 // We can use "current_block" since we know there are no explicit blocks
5662 foreach (VariableDeclaration decl in variable_declarators){
5663 // We can not use the super-handy f.Initializer, because
5664 // multiple lines would force code to be executed out of sync
5665 if (decl.expression_or_array_initializer != null){
5666 string id = "$" + decl.identifier;
5667 current_block.AddVariable (type, id, decl.Location);
5669 LocalVariableReference var;
5670 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5671 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5672 current_block.AddStatement (new StatementExpression (assign));
5673 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5674 current_block.AddStatement (new StatementExpression (assign));
5676 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
5677 new MemberName (decl.identifier, loc), null);
5678 current_container.AddField (f);
5680 // Register the field to be visible later as a global variable
5681 Evaluator.QueueField (f);
5685 return current_block;
5690 // We use the `Used' property to check whether statements
5691 // have been added to the current block. If so, we need
5692 // to create another block to contain the new declaration
5693 // otherwise, as an optimization, we use the same block to
5694 // add the declaration.
5696 // FIXME: A further optimization is to check if the statements
5697 // that were added were added as part of the initialization
5698 // below. In which case, no other statements have been executed
5699 // and we might be able to reduce the number of blocks for
5700 // situations like this:
5702 // int j = 1; int k = j + 1;
5704 if (current_block.Used)
5705 implicit_block = new Block (current_block, loc, lexer.Location);
5707 implicit_block = current_block;
5709 foreach (VariableDeclaration decl in variable_declarators){
5711 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5712 if (decl.expression_or_array_initializer != null){
5714 inits = new ArrayList (4);
5721 return implicit_block;
5723 foreach (VariableDeclaration decl in inits){
5725 Expression expr = decl.expression_or_array_initializer;
5727 LocalVariableReference var;
5728 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5730 assign = new SimpleAssign (var, expr, decl.Location);
5732 implicit_block.AddStatement (new StatementExpression (assign));
5735 return implicit_block;
5738 Block declare_local_constants (Expression type, ArrayList declarators)
5740 Block implicit_block;
5742 if (current_block.Used)
5743 implicit_block = new Block (current_block);
5745 implicit_block = current_block;
5747 foreach (VariableDeclaration decl in declarators){
5748 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5751 return implicit_block;
5754 string CheckAttributeTarget (string a, Location l)
5757 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5761 Report.Warning (658, 1, l,
5762 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5763 return string.Empty;
5766 static bool IsUnaryOperator (Operator.OpType op)
5770 case Operator.OpType.LogicalNot:
5771 case Operator.OpType.OnesComplement:
5772 case Operator.OpType.Increment:
5773 case Operator.OpType.Decrement:
5774 case Operator.OpType.True:
5775 case Operator.OpType.False:
5776 case Operator.OpType.UnaryPlus:
5777 case Operator.OpType.UnaryNegation:
5783 void syntax_error (Location l, string msg)
5785 Report.Error (1003, l, "Syntax error, " + msg);
5788 void note (string s)
5790 // Used to put annotations
5795 public Tokenizer Lexer {
5801 static CSharpParser ()
5803 oob_stack = new Stack ();
5806 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
5808 if (RootContext.EvalMode)
5812 current_namespace = new NamespaceEntry (null, file, null);
5813 current_class = current_namespace.SlaveDeclSpace;
5814 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5816 lexer = new Tokenizer (reader, file);
5819 public void parse ()
5821 eof_token = Token.EOF;
5824 if (yacc_verbose_flag > 1)
5825 yyparse (lexer, new yydebug.yyDebugSimple ());
5828 } catch (Exception e){
5829 if (e is yyParser.yyUnexpectedEof)
5830 UnexpectedEOF = true;
5831 else if (yacc_verbose_flag > 0)
5832 Console.WriteLine (e);
5833 if (e is yyParser.yyException)
5834 Report.Error (-25, lexer.Location, "Parsing error");
5836 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
5838 Tokenizer tokenizer = lexer as Tokenizer;
5839 tokenizer.cleanup ();
5841 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5842 throw new InternalErrorException ("who set it?");
5845 static void CheckToken (int error, int yyToken, string msg, Location loc)
5847 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5848 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
5850 Report.Error (error, loc, msg);
5853 void CheckIdentifierToken (int yyToken, Location loc)
5855 CheckToken (1041, yyToken, "Identifier expected", loc);
5858 string ConsumeStoredComment ()
5860 string s = tmpComment;
5862 Lexer.doc_state = XmlCommentState.Allowed;
5866 Location GetLocation (object obj)
5868 if (obj is MemberCore)
5869 return ((MemberCore) obj).Location;
5870 if (obj is MemberName)
5871 return ((MemberName) obj).Location;
5872 if (obj is LocatedToken)
5873 return ((LocatedToken) obj).Location;
5874 if (obj is Location)
5875 return (Location) obj;
5876 return lexer.Location;
5879 void start_block (Location loc)
5881 if (current_block == null || parsing_anonymous_method) {
5882 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
5883 parsing_anonymous_method = false;
5885 current_block = new ExplicitBlock (current_block, loc, Location.Null);
5890 end_block (Location loc)
5892 Block retval = current_block.Explicit;
5893 retval.SetEndLocation (loc);
5894 current_block = retval.Parent;
5899 start_anonymous (bool lambda, Parameters parameters, Location loc)
5901 if (RootContext.Version == LanguageVersion.ISO_1){
5902 Report.FeatureIsNotAvailable (loc, "anonymous methods");
5905 oob_stack.Push (current_anonymous_method);
5906 oob_stack.Push (current_local_parameters);
5908 current_local_parameters = parameters;
5910 current_anonymous_method = lambda
5911 ? new LambdaExpression (loc)
5912 : new AnonymousMethodExpression (loc);
5914 // Force the next block to be created as a ToplevelBlock
5915 parsing_anonymous_method = true;
5919 * Completes the anonymous method processing, if lambda_expr is null, this
5920 * means that we have a Statement instead of an Expression embedded
5922 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
5924 AnonymousMethodExpression retval;
5926 current_anonymous_method.Block = anon_block;
5927 retval = current_anonymous_method;
5929 current_local_parameters = (Parameters) oob_stack.Pop ();
5930 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
5935 public NamespaceEntry CurrentNamespace {
5937 return current_namespace;
5942 void Error_SyntaxError (int token)
5944 Error_SyntaxError (0, token);
5947 void Error_SyntaxError (int error_code, int token)
5949 string symbol = GetSymbolName (token);
5950 string expecting = GetExpecting ();
5952 if (error_code == 0) {
5953 if (expecting == "`)'")
5959 if (expecting != null)
5960 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
5963 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
5966 string GetExpecting ()
5968 int [] tokens = yyExpectingTokens (yyExpectingState);
5969 ArrayList names = new ArrayList (tokens.Length);
5970 bool has_type = false;
5971 bool has_identifier = false;
5972 for (int i = 0; i < tokens.Length; i++){
5973 int token = tokens [i];
5974 has_identifier |= token == Token.IDENTIFIER;
5976 string name = GetTokenName (token);
5977 if (name == "<internal>")
5980 has_type |= name == "type";
5981 if (names.Contains (name))
5988 // Too many tokens to enumerate
5990 if (names.Count > 8)
5993 if (has_type && has_identifier)
5994 names.Remove ("identifier");
5996 if (names.Count == 1)
5997 return "`" + GetTokenName (tokens [0]) + "'";
5999 StringBuilder sb = new StringBuilder ();
6001 int count = names.Count;
6002 for (int i = 0; i < count; i++){
6003 bool last = i + 1 == count;
6007 sb.Append (names [i]);
6008 sb.Append (last ? "'" : "', ");
6010 return sb.ToString ();
6014 string GetSymbolName (int token)
6017 case Token.LITERAL_FLOAT:
6018 case Token.LITERAL_INTEGER:
6019 case Token.LITERAL_DOUBLE:
6020 case Token.LITERAL_DECIMAL:
6021 case Token.LITERAL_CHARACTER:
6022 case Token.LITERAL_STRING:
6023 return lexer.Value.ToString ();
6024 case Token.IDENTIFIER:
6025 return ((LocatedToken)lexer.Value).Value;
6067 case Token.BITWISE_AND:
6069 case Token.BITWISE_OR:
6083 case Token.OP_SHIFT_LEFT:
6085 case Token.OP_SHIFT_RIGHT:
6105 case Token.OP_COALESCING:
6107 case Token.OP_MULT_ASSIGN:
6109 case Token.OP_DIV_ASSIGN:
6111 case Token.OP_MOD_ASSIGN:
6113 case Token.OP_ADD_ASSIGN:
6115 case Token.OP_SUB_ASSIGN:
6117 case Token.OP_SHIFT_LEFT_ASSIGN:
6119 case Token.OP_SHIFT_RIGHT_ASSIGN:
6121 case Token.OP_AND_ASSIGN:
6123 case Token.OP_XOR_ASSIGN:
6125 case Token.OP_OR_ASSIGN:
6129 return GetTokenName (token);
6132 static string GetTokenName (int token)
6135 case Token.ABSTRACT:
6155 case Token.CONTINUE:
6159 case Token.DELEGATE:
6169 case Token.EXPLICIT:
6187 case Token.IMPLICIT:
6191 case Token.INTERFACE:
6193 case Token.INTERNAL:
6199 case Token.NAMESPACE:
6205 case Token.OPERATOR:
6209 case Token.OVERRIDE:
6215 case Token.PROTECTED:
6219 case Token.READONLY:
6231 case Token.STACKALLOC:
6232 return "stackalloc";
6249 case Token.UNCHECKED:
6257 case Token.VOLATILE:
6287 case Token.ASCENDING:
6289 case Token.DESCENDING:
6290 return "descending";
6297 case Token.OPEN_BRACE:
6299 case Token.CLOSE_BRACE:
6301 case Token.OPEN_BRACKET:
6303 case Token.CLOSE_BRACKET:
6305 case Token.OPEN_PARENS_CAST:
6306 case Token.OPEN_PARENS_LAMBDA:
6307 case Token.OPEN_PARENS:
6309 case Token.CLOSE_PARENS:
6315 case Token.DEFAULT_COLON:
6319 case Token.SEMICOLON:
6330 case Token.BITWISE_AND:
6331 case Token.BITWISE_OR:
6338 case Token.OP_SHIFT_LEFT:
6339 case Token.OP_SHIFT_RIGHT:
6347 case Token.OP_COALESCING:
6348 case Token.OP_MULT_ASSIGN:
6349 case Token.OP_DIV_ASSIGN:
6350 case Token.OP_MOD_ASSIGN:
6351 case Token.OP_ADD_ASSIGN:
6352 case Token.OP_SUB_ASSIGN:
6353 case Token.OP_SHIFT_LEFT_ASSIGN:
6354 case Token.OP_SHIFT_RIGHT_ASSIGN:
6355 case Token.OP_AND_ASSIGN:
6356 case Token.OP_XOR_ASSIGN:
6357 case Token.OP_OR_ASSIGN:
6358 return "<operator>";
6380 case Token.OP_GENERICS_LT:
6381 case Token.GENERIC_DIMENSION:
6383 case Token.OP_GENERICS_GT:
6386 case Token.INTERR_NULLABLE:
6388 case Token.DOUBLE_COLON:
6390 case Token.LITERAL_FLOAT:
6391 case Token.LITERAL_INTEGER:
6392 case Token.LITERAL_DOUBLE:
6393 case Token.LITERAL_DECIMAL:
6394 case Token.LITERAL_CHARACTER:
6395 case Token.LITERAL_STRING:
6397 case Token.IDENTIFIER:
6398 return "identifier";
6400 // All of these are internal.
6403 case Token.FIRST_KEYWORD:
6405 case Token.EVAL_COMPILATION_UNIT_PARSER:
6406 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6407 case Token.EVAL_STATEMENT_PARSER:
6408 case Token.LAST_KEYWORD:
6409 return "<internal>";
6411 // A bit more robust.
6413 return yyNames [token];