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
232 %token QUERY_FIRST_TOKEN
245 %token QUERY_LAST_TOKEN
246 %token INTERR_NULLABLE
248 /* C# keywords which are not really keywords */
254 /* C# single character operators/punctuation. */
272 %token OP_GENERICS_LT
273 %token OP_GENERICS_LT_DECL
275 %token OP_GENERICS_GT
284 /* C# multi-character operators. */
289 %token OP_SHIFT_RIGHT
296 %token OP_MULT_ASSIGN
301 %token OP_SHIFT_LEFT_ASSIGN
302 %token OP_SHIFT_RIGHT_ASSIGN
310 %token LITERAL_INTEGER
312 %token LITERAL_DOUBLE
313 %token LITERAL_DECIMAL
314 %token LITERAL_CHARACTER
315 %token LITERAL_STRING
318 %token OPEN_PARENS_LAMBDA
319 %token CLOSE_PARENS_CAST
320 %token CLOSE_PARENS_NO_CAST
321 %token CLOSE_PARENS_OPEN_PARENS
322 %token CLOSE_PARENS_MINUS
323 %token DEFAULT_OPEN_PARENS
324 %token GENERIC_DIMENSION
327 // Make the parser go into eval mode parsing (statements and compilation units).
328 %token EVAL_STATEMENT_PARSER
329 %token EVAL_COMPILATION_UNIT_PARSER
330 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
332 /* Add precedence rules to solve dangling else s/r conflict */
341 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
343 %left STAR DIV PERCENT
344 %right BANG CARRET UMINUS
345 %nonassoc OP_INC OP_DEC
347 %left OPEN_BRACKET OPEN_BRACE
351 %start compilation_unit
355 : outer_declarations opt_EOF
356 | outer_declarations global_attributes opt_EOF
357 | global_attributes opt_EOF
358 | opt_EOF /* allow empty files */
359 | interactive_parsing opt_EOF
365 Lexer.check_incorrect_doc_comment ();
369 Lexer.check_incorrect_doc_comment ();
375 | outer_declarations outer_declaration
379 : extern_alias_directive
381 | namespace_member_declaration
384 extern_alias_directives
385 : extern_alias_directive
386 | extern_alias_directives extern_alias_directive
389 extern_alias_directive
390 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
392 LocatedToken lt = (LocatedToken) $2;
395 Report.Error (1003, lt.Location, "'alias' expected");
396 } else if (RootContext.Version == LanguageVersion.ISO_1) {
397 Report.FeatureIsNotAvailable (lt.Location, "external alias");
399 lt = (LocatedToken) $3;
400 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
407 | using_directives using_directive
411 : using_alias_directive
413 if (RootContext.Documentation != null)
414 Lexer.doc_state = XmlCommentState.Allowed;
416 | using_namespace_directive
418 if (RootContext.Documentation != null)
419 Lexer.doc_state = XmlCommentState.Allowed;
423 using_alias_directive
424 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
426 LocatedToken lt = (LocatedToken) $2;
427 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
430 CheckIdentifierToken (yyToken, GetLocation ($2));
435 using_namespace_directive
436 : USING namespace_name SEMICOLON
438 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
443 // Strictly speaking, namespaces don't have attributes but
444 // we parse global attributes along with namespace declarations and then
447 namespace_declaration
448 : opt_attributes NAMESPACE qualified_identifier
450 MemberName name = (MemberName) $3;
453 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
456 current_namespace = new NamespaceEntry (
457 current_namespace, file, name.GetName ());
458 current_class = current_namespace.SlaveDeclSpace;
459 current_container = current_class.PartialContainer;
461 namespace_body opt_semicolon
463 current_namespace = current_namespace.Parent;
464 current_class = current_namespace.SlaveDeclSpace;
465 current_container = current_class.PartialContainer;
472 LocatedToken lt = (LocatedToken) $1;
473 $$ = new MemberName (lt.Value, lt.Location);
475 | qualified_identifier DOT IDENTIFIER
477 LocatedToken lt = (LocatedToken) $3;
478 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
482 syntax_error (lexer.Location, "`.' expected");
497 : namespace_or_type_name
499 MemberName name = (MemberName) $1;
501 if (name.TypeArguments != null)
502 syntax_error (lexer.Location, "namespace name expected");
511 if (RootContext.Documentation != null)
512 Lexer.doc_state = XmlCommentState.Allowed;
518 : opt_extern_alias_directives
520 opt_namespace_member_declarations
524 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
527 | opt_extern_alias_directives
529 opt_namespace_member_declarations
532 Report.Error (1513, lexer.Location, "} expected");
541 opt_extern_alias_directives
543 | extern_alias_directives
546 opt_namespace_member_declarations
548 | namespace_member_declarations
551 namespace_member_declarations
552 : namespace_member_declaration
553 | namespace_member_declarations namespace_member_declaration
556 namespace_member_declaration
560 DeclSpace ds = (DeclSpace)$1;
562 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
563 Report.Error (1527, ds.Location,
564 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
567 current_namespace.DeclarationFound = true;
569 | namespace_declaration {
570 current_namespace.DeclarationFound = true;
573 | field_declaration {
574 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
576 | method_declaration {
577 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
584 | interface_declaration
586 | delegate_declaration
588 // Enable this when we have handled all errors, because this acts as a generic fallback
591 // Console.WriteLine ("Token=" + yyToken);
592 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
604 Attributes attrs = (Attributes)$1;
605 if (global_attrs_enabled) {
606 CodeGen.Assembly.AddAttributes (attrs.Attrs);
608 foreach (Attribute a in attrs.Attrs) {
609 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
620 global_attrs_enabled = false;
625 global_attrs_enabled = false;
634 if (current_attr_target != String.Empty) {
635 ArrayList sect = (ArrayList) $1;
637 if (global_attrs_enabled) {
638 if (current_attr_target == "module") {
639 CodeGen.Module.AddAttributes (sect);
641 } else if (current_attr_target != null && current_attr_target.Length > 0) {
642 CodeGen.Assembly.AddAttributes (sect);
645 $$ = new Attributes (sect);
648 if (RootContext.Documentation != null) {
649 Lexer.check_incorrect_doc_comment ();
651 XmlCommentState.Allowed;
655 $$ = new Attributes (sect);
660 current_attr_target = null;
662 | attribute_sections attribute_section
664 if (current_attr_target != String.Empty) {
665 Attributes attrs = $1 as Attributes;
666 ArrayList sect = (ArrayList) $2;
668 if (global_attrs_enabled) {
669 if (current_attr_target == "module") {
670 CodeGen.Module.AddAttributes (sect);
672 } else if (current_attr_target == "assembly") {
673 CodeGen.Assembly.AddAttributes (sect);
677 attrs = new Attributes (sect);
679 attrs.AddAttributes (sect);
683 attrs = new Attributes (sect);
685 attrs.AddAttributes (sect);
691 current_attr_target = null;
696 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
700 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
706 attribute_target_specifier
707 : attribute_target COLON
709 current_attr_target = (string)$1;
717 LocatedToken lt = (LocatedToken) $1;
718 $$ = CheckAttributeTarget (lt.Value, lt.Location);
720 | EVENT { $$ = "event"; }
721 | RETURN { $$ = "return"; }
724 string name = GetTokenName (yyToken);
725 $$ = CheckAttributeTarget (name, GetLocation ($1));
732 ArrayList attrs = new ArrayList (4);
738 | attribute_list COMMA attribute
740 ArrayList attrs = (ArrayList) $1;
750 ++lexer.parsing_block;
752 opt_attribute_arguments
754 --lexer.parsing_block;
755 MemberName mname = (MemberName) $1;
756 if (mname.IsGeneric) {
757 Report.Error (404, lexer.Location,
758 "'<' unexpected: attributes cannot be generic");
761 object [] arguments = (object []) $3;
762 MemberName left = mname.Left;
763 string identifier = mname.Name;
765 Expression left_expr = left == null ? null : left.GetTypeExpression ();
767 if (current_attr_target == String.Empty)
769 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
770 // FIXME: supply "nameEscaped" parameter here.
771 $$ = new GlobalAttribute (current_namespace, current_attr_target,
772 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
774 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
779 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
782 opt_attribute_arguments
783 : /* empty */ { $$ = null; }
784 | OPEN_PARENS attribute_arguments CLOSE_PARENS
792 : opt_positional_argument_list
797 $$ = new object [] { $1, null };
800 | positional_argument_list COMMA named_argument_list
802 $$ = new object[] { $1, $3 };
804 | named_argument_list
806 $$ = new object [] { null, $1 };
811 opt_positional_argument_list
812 : /* empty */ { $$ = null; }
813 | positional_argument_list
816 positional_argument_list
819 ArrayList args = new ArrayList (4);
820 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
824 | positional_argument_list COMMA expression
826 ArrayList args = (ArrayList) $1;
827 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
836 ArrayList args = new ArrayList (4);
841 | named_argument_list COMMA named_argument
843 ArrayList args = (ArrayList) $1;
848 | named_argument_list COMMA expression
850 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
856 : IDENTIFIER ASSIGN expression
858 // FIXME: keep location
859 $$ = new DictionaryEntry (
860 ((LocatedToken) $1).Value,
861 new Argument ((Expression) $3, Argument.AType.Expression));
867 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
870 opt_class_member_declarations
872 | class_member_declarations
875 class_member_declarations
876 : class_member_declaration
877 | class_member_declarations
878 class_member_declaration
881 class_member_declaration
882 : constant_declaration // done
883 | field_declaration // done
884 | method_declaration // done
885 | property_declaration // done
886 | event_declaration // done
887 | indexer_declaration // done
888 | operator_declaration // done
889 | constructor_declaration // done
890 | destructor_declaration // done
900 lexer.ConstraintsParsing = true;
902 type_declaration_name
904 MemberName name = MakeName ((MemberName) $6);
905 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
908 opt_type_parameter_constraints_clauses
910 lexer.ConstraintsParsing = false;
912 current_class.SetParameterInfo ((ArrayList) $9);
914 if (RootContext.Documentation != null)
915 current_container.DocComment = Lexer.consume_doc_comment ();
919 if (RootContext.Documentation != null)
920 Lexer.doc_state = XmlCommentState.Allowed;
924 $$ = pop_current_class ();
926 | opt_attributes opt_modifiers opt_partial STRUCT error {
927 CheckIdentifierToken (yyToken, GetLocation ($5));
934 if (RootContext.Documentation != null)
935 Lexer.doc_state = XmlCommentState.Allowed;
937 opt_struct_member_declarations CLOSE_BRACE
940 opt_struct_member_declarations
942 | struct_member_declarations
945 struct_member_declarations
946 : struct_member_declaration
947 | struct_member_declarations struct_member_declaration
950 struct_member_declaration
951 : constant_declaration
954 | property_declaration
956 | indexer_declaration
957 | operator_declaration
958 | constructor_declaration
962 * This is only included so we can flag error 575:
963 * destructors only allowed on class types
965 | destructor_declaration
976 int modflags = (int) $2;
977 foreach (VariableDeclaration constant in (ArrayList) $5){
978 Location l = constant.Location;
979 if ((modflags & Modifiers.STATIC) != 0) {
980 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
984 Const c = new Const (
985 current_class, (FullNamedExpression) $4, (string) constant.identifier,
986 (Expression) constant.expression_or_array_initializer, modflags,
989 if (RootContext.Documentation != null) {
990 c.DocComment = Lexer.consume_doc_comment ();
991 Lexer.doc_state = XmlCommentState.Allowed;
993 current_container.AddConstant (c);
999 : constant_declarator
1001 ArrayList constants = new ArrayList (4);
1006 | constant_declarators COMMA constant_declarator
1009 ArrayList constants = (ArrayList) $1;
1018 ++lexer.parsing_block;
1020 constant_initializer
1022 --lexer.parsing_block;
1023 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1027 // A const field requires a value to be provided
1028 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1033 constant_initializer
1034 : constant_expression
1042 variable_declarators
1045 FullNamedExpression type = (FullNamedExpression) $3;
1046 if (type == TypeManager.system_void_expr)
1047 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1051 current_array_type = null;
1053 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1054 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1056 field.Initializer = var.expression_or_array_initializer;
1058 if (RootContext.Documentation != null) {
1059 field.DocComment = Lexer.consume_doc_comment ();
1060 Lexer.doc_state = XmlCommentState.Allowed;
1062 current_container.AddField (field);
1063 $$ = field; // FIXME: might be better if it points to the top item
1070 fixed_variable_declarators
1073 FullNamedExpression type = (FullNamedExpression) $4;
1077 current_array_type = null;
1079 foreach (VariableDeclaration var in (ArrayList) $5) {
1080 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1081 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1083 if (RootContext.Documentation != null) {
1084 field.DocComment = Lexer.consume_doc_comment ();
1085 Lexer.doc_state = XmlCommentState.Allowed;
1087 current_container.AddField (field);
1088 $$ = field; // FIXME: might be better if it points to the top item
1097 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1101 fixed_variable_declarators
1102 : fixed_variable_declarator
1104 ArrayList decl = new ArrayList (2);
1108 | fixed_variable_declarators COMMA fixed_variable_declarator
1110 ArrayList decls = (ArrayList) $1;
1116 fixed_variable_declarator
1117 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1119 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1121 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1123 Report.Error (443, lexer.Location, "Value or constant expected");
1124 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1129 local_variable_declarators
1130 : local_variable_declarator
1132 ArrayList decl = new ArrayList (4);
1137 | local_variable_declarators COMMA local_variable_declarator
1139 ArrayList decls = (ArrayList) $1;
1145 local_variable_declarator
1146 : IDENTIFIER ASSIGN local_variable_initializer
1148 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1152 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1154 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1156 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1157 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1162 local_variable_initializer
1165 | STACKALLOC type_expression OPEN_BRACKET expression CLOSE_BRACKET
1167 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1171 $$ = new ArglistAccess ((Location) $1);
1175 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1181 variable_declarators
1182 : variable_declarator
1184 ArrayList decl = new ArrayList (4);
1189 | variable_declarators COMMA variable_declarator
1191 ArrayList decls = (ArrayList) $1;
1198 : member_declaration_name ASSIGN
1200 ++lexer.parsing_block;
1201 lexer.parsing_generic_declaration = false;
1203 variable_initializer
1205 --lexer.parsing_block;
1206 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1208 | member_declaration_name
1210 lexer.parsing_generic_declaration = false;
1211 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1213 | member_declaration_name OPEN_BRACKET opt_expression CLOSE_BRACKET
1215 lexer.parsing_generic_declaration = false;
1216 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1217 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1222 variable_initializer
1229 if (RootContext.Documentation != null)
1230 Lexer.doc_state = XmlCommentState.NotAllowed;
1234 Method method = (Method) $1;
1235 method.Block = (ToplevelBlock) $3;
1236 current_container.AddMethod (method);
1238 if (current_container.Kind == Kind.Interface && method.Block != null) {
1239 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1242 current_generic_method = null;
1243 current_local_parameters = null;
1245 if (RootContext.Documentation != null)
1246 Lexer.doc_state = XmlCommentState.Allowed;
1254 method_declaration_name OPEN_PARENS
1256 arglist_allowed = true;
1258 opt_formal_parameter_list CLOSE_PARENS
1260 lexer.ConstraintsParsing = true;
1262 opt_type_parameter_constraints_clauses
1264 lexer.ConstraintsParsing = false;
1265 arglist_allowed = false;
1266 MemberName name = (MemberName) $4;
1267 current_local_parameters = (Parameters) $7;
1269 if ($10 != null && name.TypeArguments == null)
1270 Report.Error (80, lexer.Location,
1271 "Constraints are not allowed on non-generic declarations");
1275 GenericMethod generic = null;
1276 if (name.TypeArguments != null) {
1277 generic = new GenericMethod (current_namespace, current_class, name,
1278 (FullNamedExpression) $3, current_local_parameters);
1280 generic.SetParameterInfo ((ArrayList) $10);
1283 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1284 name, current_local_parameters, (Attributes) $1);
1286 current_generic_method = generic;
1288 if (RootContext.Documentation != null)
1289 method.DocComment = Lexer.consume_doc_comment ();
1296 VOID method_declaration_name
1297 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1299 lexer.ConstraintsParsing = true;
1301 opt_type_parameter_constraints_clauses
1303 lexer.ConstraintsParsing = false;
1305 MemberName name = (MemberName) $5;
1306 current_local_parameters = (Parameters) $7;
1308 if ($9 != null && name.TypeArguments == null)
1309 Report.Error (80, lexer.Location,
1310 "Constraints are not allowed on non-generic declarations");
1313 GenericMethod generic = null;
1314 if (name.TypeArguments != null) {
1315 generic = new GenericMethod (current_namespace, current_class, name,
1316 TypeManager.system_void_expr, current_local_parameters);
1318 generic.SetParameterInfo ((ArrayList) $10);
1321 int modifiers = (int) $2;
1324 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1325 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1327 if ((modifiers & invalid_partial_mod) != 0) {
1328 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1329 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1330 modifiers &= ~invalid_partial_mod;
1333 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1334 Report.Error (751, name.Location, "A partial method must be declared within a " +
1335 "partial class or partial struct");
1338 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1340 method = new Method (current_class, generic, TypeManager.system_void_expr,
1341 modifiers, name, current_local_parameters, (Attributes) $1);
1343 current_generic_method = generic;
1345 if (RootContext.Documentation != null)
1346 method.DocComment = Lexer.consume_doc_comment ();
1353 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1355 MemberName name = (MemberName) $5;
1356 Report.Error (1585, name.Location,
1357 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1359 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1360 0, name, (Parameters) $7, (Attributes) $1);
1362 current_local_parameters = (Parameters) $7;
1364 if (RootContext.Documentation != null)
1365 method.DocComment = Lexer.consume_doc_comment ();
1373 | SEMICOLON { $$ = null; }
1376 opt_formal_parameter_list
1377 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1378 | formal_parameter_list
1381 opt_parameter_list_no_mod
1382 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1385 parameter_modifiers_not_allowed = true;
1387 formal_parameter_list
1389 parameter_modifiers_not_allowed = false;
1394 formal_parameter_list
1397 ArrayList pars_list = (ArrayList) $1;
1399 Parameter [] pars = new Parameter [pars_list.Count];
1400 pars_list.CopyTo (pars);
1402 $$ = new Parameters (pars);
1404 | fixed_parameters COMMA parameter_array
1406 ArrayList pars_list = (ArrayList) $1;
1409 Parameter [] pars = new Parameter [pars_list.Count];
1410 pars_list.CopyTo (pars);
1412 $$ = new Parameters (pars);
1414 | fixed_parameters COMMA arglist_modifier
1416 ArrayList pars_list = (ArrayList) $1;
1417 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1419 Parameter [] pars = new Parameter [pars_list.Count];
1420 pars_list.CopyTo (pars);
1422 $$ = new Parameters (pars, true);
1424 | parameter_array COMMA error
1427 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1430 | fixed_parameters COMMA parameter_array COMMA error
1433 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1436 | arglist_modifier COMMA error
1438 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1441 | fixed_parameters COMMA ARGLIST COMMA error
1443 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1448 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1452 $$ = new Parameters (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1459 ArrayList pars = new ArrayList (4);
1464 | fixed_parameters COMMA fixed_parameter
1466 ArrayList pars = (ArrayList) $1;
1467 Parameter p = (Parameter)$3;
1469 if (p.HasExtensionMethodModifier)
1470 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1479 opt_parameter_modifier
1483 LocatedToken lt = (LocatedToken) $4;
1484 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1487 opt_parameter_modifier
1489 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1491 LocatedToken lt = (LocatedToken) $4;
1492 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1496 opt_parameter_modifier
1499 Report.Error (1001, GetLocation ($3), "Identifier expected");
1503 opt_parameter_modifier
1506 CheckIdentifierToken (yyToken, GetLocation ($4));
1510 opt_parameter_modifier
1516 LocatedToken lt = (LocatedToken) $4;
1517 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1522 opt_parameter_modifier
1523 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1524 | parameter_modifiers
1528 : parameter_modifier
1532 | parameter_modifiers parameter_modifier
1534 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1535 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1536 if (((Parameter.Modifier)$1 & p2) == p2) {
1537 Error_DuplicateParameterModifier (lexer.Location, p2);
1539 switch (mod & ~Parameter.Modifier.This) {
1540 case Parameter.Modifier.REF:
1541 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1543 case Parameter.Modifier.OUT:
1544 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1547 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1558 if (parameter_modifiers_not_allowed)
1559 Error_ParameterModifierNotValid ("ref", (Location)$1);
1561 $$ = Parameter.Modifier.REF;
1565 if (parameter_modifiers_not_allowed)
1566 Error_ParameterModifierNotValid ("out", (Location)$1);
1568 $$ = Parameter.Modifier.OUT;
1572 if (parameter_modifiers_not_allowed)
1573 Error_ParameterModifierNotValid ("this", (Location)$1);
1575 if (RootContext.Version <= LanguageVersion.ISO_2)
1576 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1578 $$ = Parameter.Modifier.This;
1583 : opt_attributes params_modifier type IDENTIFIER
1585 LocatedToken lt = (LocatedToken) $4;
1586 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1588 | opt_attributes params_modifier type error {
1589 CheckIdentifierToken (yyToken, GetLocation ($4));
1597 if (params_modifiers_not_allowed)
1598 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1600 | PARAMS parameter_modifier
1602 Parameter.Modifier mod = (Parameter.Modifier)$2;
1603 if ((mod & Parameter.Modifier.This) != 0) {
1604 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1606 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1609 | PARAMS params_modifier
1611 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1618 if (!arglist_allowed)
1619 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1623 property_declaration
1627 member_declaration_name
1629 if (RootContext.Documentation != null)
1630 tmpComment = Lexer.consume_doc_comment ();
1634 implicit_value_parameter_type = (FullNamedExpression) $3;
1635 lexer.PropertyParsing = true;
1637 accessor_declarations
1639 lexer.PropertyParsing = false;
1640 has_get = has_set = false;
1645 Accessors accessors = (Accessors) $8;
1646 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1647 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1648 bool order = accessors != null ? accessors.declared_in_reverse : false;
1650 MemberName name = (MemberName) $4;
1651 FullNamedExpression ptype = (FullNamedExpression) $3;
1653 prop = new Property (current_class, ptype, (int) $2,
1654 name, (Attributes) $1, get_block, set_block, order, current_block);
1656 if (ptype == TypeManager.system_void_expr)
1657 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1659 if (accessors == null)
1660 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1662 if (current_container.Kind == Kind.Interface) {
1663 if (prop.Get.Block != null)
1664 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1666 if (prop.Set.Block != null)
1667 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1670 current_container.AddProperty (prop);
1671 implicit_value_parameter_type = null;
1673 if (RootContext.Documentation != null)
1674 prop.DocComment = ConsumeStoredComment ();
1679 accessor_declarations
1680 : get_accessor_declaration
1682 $$ = new Accessors ((Accessor) $1, null);
1684 | get_accessor_declaration accessor_declarations
1686 Accessors accessors = (Accessors) $2;
1687 accessors.get_or_add = (Accessor) $1;
1690 | set_accessor_declaration
1692 $$ = new Accessors (null, (Accessor) $1);
1694 | set_accessor_declaration accessor_declarations
1696 Accessors accessors = (Accessors) $2;
1697 accessors.set_or_remove = (Accessor) $1;
1698 accessors.declared_in_reverse = true;
1703 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1708 get_accessor_declaration
1709 : opt_attributes opt_modifiers GET
1711 // If this is not the case, then current_local_parameters has already
1712 // been set in indexer_declaration
1713 if (parsing_indexer == false)
1714 current_local_parameters = null;
1716 current_local_parameters = indexer_parameters;
1717 lexer.PropertyParsing = false;
1722 Report.Error (1007, (Location) $3, "Property accessor already defined");
1725 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1727 current_local_parameters = null;
1728 lexer.PropertyParsing = true;
1730 if (RootContext.Documentation != null)
1731 if (Lexer.doc_state == XmlCommentState.Error)
1732 Lexer.doc_state = XmlCommentState.NotAllowed;
1738 set_accessor_declaration
1739 : opt_attributes opt_modifiers SET
1741 Parameter implicit_value_parameter = new Parameter (
1742 implicit_value_parameter_type, "value",
1743 Parameter.Modifier.NONE, null, (Location) $3);
1745 if (!parsing_indexer) {
1746 current_local_parameters = new Parameters (new Parameter [] { implicit_value_parameter });
1748 current_local_parameters = Parameters.MergeGenerated (
1749 indexer_parameters, true, implicit_value_parameter, null);
1752 lexer.PropertyParsing = false;
1757 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1760 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1762 current_local_parameters = null;
1763 lexer.PropertyParsing = true;
1765 if (RootContext.Documentation != null
1766 && Lexer.doc_state == XmlCommentState.Error)
1767 Lexer.doc_state = XmlCommentState.NotAllowed;
1775 | SEMICOLON { $$ = null; }
1778 interface_declaration
1784 lexer.ConstraintsParsing = true;
1786 type_declaration_name
1788 MemberName name = MakeName ((MemberName) $6);
1789 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1792 opt_type_parameter_constraints_clauses
1794 lexer.ConstraintsParsing = false;
1796 current_class.SetParameterInfo ((ArrayList) $9);
1798 if (RootContext.Documentation != null) {
1799 current_container.DocComment = Lexer.consume_doc_comment ();
1800 Lexer.doc_state = XmlCommentState.Allowed;
1805 if (RootContext.Documentation != null)
1806 Lexer.doc_state = XmlCommentState.Allowed;
1810 $$ = pop_current_class ();
1812 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1813 CheckIdentifierToken (yyToken, GetLocation ($5));
1819 opt_interface_member_declarations
1823 opt_interface_member_declarations
1825 | interface_member_declarations
1828 interface_member_declarations
1829 : interface_member_declaration
1830 | interface_member_declarations interface_member_declaration
1833 interface_member_declaration
1834 : constant_declaration
1836 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1840 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1842 | method_declaration
1843 | property_declaration
1845 | indexer_declaration
1846 | operator_declaration
1848 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1850 | constructor_declaration
1852 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1856 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1860 operator_declaration
1861 : opt_attributes opt_modifiers operator_declarator
1869 OperatorDeclaration decl = (OperatorDeclaration) $3;
1870 Operator op = new Operator (
1871 current_class, decl.optype, decl.ret_type, (int) $2,
1872 current_local_parameters,
1873 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1875 if (RootContext.Documentation != null) {
1876 op.DocComment = tmpComment;
1877 Lexer.doc_state = XmlCommentState.Allowed;
1880 // Note again, checking is done in semantic analysis
1881 current_container.AddOperator (op);
1883 current_local_parameters = null;
1889 | SEMICOLON { $$ = null; }
1893 : type_expression_or_array
1896 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1897 $$ = TypeManager.system_void_expr;
1902 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1904 params_modifiers_not_allowed = true;
1906 opt_parameter_list_no_mod CLOSE_PARENS
1908 params_modifiers_not_allowed = false;
1910 Location loc = (Location) $2;
1911 Operator.OpType op = (Operator.OpType) $3;
1912 current_local_parameters = (Parameters)$6;
1914 int p_count = current_local_parameters.Count;
1916 if (op == Operator.OpType.Addition)
1917 op = Operator.OpType.UnaryPlus;
1918 else if (op == Operator.OpType.Subtraction)
1919 op = Operator.OpType.UnaryNegation;
1922 if (IsUnaryOperator (op)) {
1924 Report.Error (1020, loc, "Overloadable binary operator expected");
1925 } else if (p_count != 1) {
1926 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1927 Operator.GetName (op));
1931 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1932 Operator.GetName (op));
1933 } else if (p_count != 2) {
1934 Report.Error (1019, loc, "Overloadable unary operator expected");
1938 if (RootContext.Documentation != null) {
1939 tmpComment = Lexer.consume_doc_comment ();
1940 Lexer.doc_state = XmlCommentState.NotAllowed;
1943 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
1945 | conversion_operator_declarator
1948 overloadable_operator
1950 : BANG { $$ = Operator.OpType.LogicalNot; }
1951 | TILDE { $$ = Operator.OpType.OnesComplement; }
1952 | OP_INC { $$ = Operator.OpType.Increment; }
1953 | OP_DEC { $$ = Operator.OpType.Decrement; }
1954 | TRUE { $$ = Operator.OpType.True; }
1955 | FALSE { $$ = Operator.OpType.False; }
1956 // Unary and binary:
1957 | PLUS { $$ = Operator.OpType.Addition; }
1958 | MINUS { $$ = Operator.OpType.Subtraction; }
1960 | STAR { $$ = Operator.OpType.Multiply; }
1961 | DIV { $$ = Operator.OpType.Division; }
1962 | PERCENT { $$ = Operator.OpType.Modulus; }
1963 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1964 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
1965 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
1966 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
1967 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
1968 | OP_EQ { $$ = Operator.OpType.Equality; }
1969 | OP_NE { $$ = Operator.OpType.Inequality; }
1970 | OP_GT { $$ = Operator.OpType.GreaterThan; }
1971 | OP_LT { $$ = Operator.OpType.LessThan; }
1972 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
1973 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
1976 conversion_operator_declarator
1977 : IMPLICIT OPERATOR type OPEN_PARENS
1979 params_modifiers_not_allowed = true;
1981 opt_parameter_list_no_mod CLOSE_PARENS
1983 params_modifiers_not_allowed = false;
1985 Location loc = (Location) $2;
1986 current_local_parameters = (Parameters)$6;
1988 if (RootContext.Documentation != null) {
1989 tmpComment = Lexer.consume_doc_comment ();
1990 Lexer.doc_state = XmlCommentState.NotAllowed;
1993 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
1995 | EXPLICIT OPERATOR type OPEN_PARENS
1997 params_modifiers_not_allowed = true;
1999 opt_parameter_list_no_mod CLOSE_PARENS
2001 params_modifiers_not_allowed = false;
2003 Location loc = (Location) $2;
2004 current_local_parameters = (Parameters)$6;
2006 if (RootContext.Documentation != null) {
2007 tmpComment = Lexer.consume_doc_comment ();
2008 Lexer.doc_state = XmlCommentState.NotAllowed;
2011 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2015 syntax_error ((Location) $1, "'operator' expected");
2019 syntax_error ((Location) $1, "'operator' expected");
2023 constructor_declaration
2024 : constructor_declarator
2027 Constructor c = (Constructor) $1;
2028 c.Block = (ToplevelBlock) $2;
2030 if (RootContext.Documentation != null)
2031 c.DocComment = ConsumeStoredComment ();
2033 current_container.AddConstructor (c);
2035 current_local_parameters = null;
2036 if (RootContext.Documentation != null)
2037 Lexer.doc_state = XmlCommentState.Allowed;
2041 constructor_declarator
2046 if (RootContext.Documentation != null) {
2047 tmpComment = Lexer.consume_doc_comment ();
2048 Lexer.doc_state = XmlCommentState.Allowed;
2051 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2053 current_local_parameters = (Parameters) $6;
2056 // start block here, so possible anonymous methods inside
2057 // constructor initializer can get correct parent block
2059 start_block (lexer.Location);
2061 opt_constructor_initializer
2063 LocatedToken lt = (LocatedToken) $3;
2064 int mods = (int) $2;
2065 ConstructorInitializer ci = (ConstructorInitializer) $9;
2067 Constructor c = new Constructor (current_class, lt.Value, mods,
2068 (Attributes) $1, current_local_parameters, ci, lt.Location);
2070 if (lt.Value != current_container.MemberName.Name) {
2071 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2072 } else if ((mods & Modifiers.STATIC) != 0) {
2073 if ((mods & Modifiers.Accessibility) != 0){
2074 Report.Error (515, c.Location,
2075 "`{0}': static constructor cannot have an access modifier",
2076 c.GetSignatureForError ());
2079 Report.Error (514, c.Location,
2080 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2081 c.GetSignatureForError ());
2092 | SEMICOLON { current_block = null; $$ = null; }
2095 opt_constructor_initializer
2097 | constructor_initializer
2100 constructor_initializer
2101 : COLON BASE OPEN_PARENS
2103 ++lexer.parsing_block;
2105 opt_argument_list CLOSE_PARENS
2107 --lexer.parsing_block;
2108 $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
2110 | COLON THIS OPEN_PARENS
2112 ++lexer.parsing_block;
2114 opt_argument_list CLOSE_PARENS
2116 --lexer.parsing_block;
2117 $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
2120 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2125 destructor_declaration
2126 : opt_attributes opt_modifiers TILDE
2128 if (RootContext.Documentation != null) {
2129 tmpComment = Lexer.consume_doc_comment ();
2130 Lexer.doc_state = XmlCommentState.NotAllowed;
2133 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2135 LocatedToken lt = (LocatedToken) $5;
2136 if (lt.Value != current_container.MemberName.Name){
2137 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2138 } else if (current_container.Kind != Kind.Class){
2139 Report.Error (575, lt.Location, "Only class types can contain destructor");
2141 Method d = new Destructor (
2142 current_class, TypeManager.system_void_expr, (int) $2, "Finalize",
2143 Parameters.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2144 if (RootContext.Documentation != null)
2145 d.DocComment = ConsumeStoredComment ();
2147 d.Block = (ToplevelBlock) $8;
2148 current_container.AddMethod (d);
2156 EVENT type variable_declarators SEMICOLON
2158 current_array_type = null;
2159 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2161 EventField e = new EventField (
2162 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2164 if (var.expression_or_array_initializer != null) {
2165 if (current_container.Kind == Kind.Interface) {
2166 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2169 e.Initializer = var.expression_or_array_initializer;
2172 if (var.MemberName.Left != null) {
2173 Report.Error (71, e.Location,
2174 "`{0}': An explicit interface implementation of an event must use property syntax",
2175 e.GetSignatureForError ());
2178 current_container.AddEvent (e);
2180 if (RootContext.Documentation != null) {
2181 e.DocComment = Lexer.consume_doc_comment ();
2182 Lexer.doc_state = XmlCommentState.Allowed;
2188 EVENT type member_declaration_name
2191 implicit_value_parameter_type = (FullNamedExpression) $4;
2192 current_local_parameters = new Parameters (
2193 new Parameter (implicit_value_parameter_type, "value",
2194 Parameter.Modifier.NONE, null, GetLocation ($3)));
2196 lexer.EventParsing = true;
2198 event_accessor_declarations
2200 lexer.EventParsing = false;
2204 MemberName name = (MemberName) $5;
2206 if (current_container.Kind == Kind.Interface) {
2207 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2211 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2212 current_container.Name, name.GetSignatureForError ());
2215 Accessors accessors = (Accessors) $8;
2217 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2218 // CS0073 is already reported, so no CS0065 here.
2221 Event e = new EventProperty (
2222 current_class, (FullNamedExpression) $4, (int) $2, name,
2223 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2224 if (RootContext.Documentation != null) {
2225 e.DocComment = Lexer.consume_doc_comment ();
2226 Lexer.doc_state = XmlCommentState.Allowed;
2229 current_container.AddEvent (e);
2230 implicit_value_parameter_type = null;
2233 current_local_parameters = null;
2235 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2237 MemberName mn = (MemberName) $5;
2238 if (mn.Left != null)
2239 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2241 if (RootContext.Documentation != null)
2242 Lexer.doc_state = XmlCommentState.Allowed;
2244 Report.Error (1002, GetLocation ($6), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
2249 event_accessor_declarations
2250 : add_accessor_declaration remove_accessor_declaration
2252 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2254 | remove_accessor_declaration add_accessor_declaration
2256 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2257 accessors.declared_in_reverse = true;
2260 | add_accessor_declaration { $$ = null; }
2261 | remove_accessor_declaration { $$ = null; }
2264 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2270 add_accessor_declaration
2271 : opt_attributes ADD
2273 lexer.EventParsing = false;
2277 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2278 lexer.EventParsing = true;
2281 | opt_attributes ADD error {
2282 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2285 | opt_attributes modifiers ADD {
2286 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2291 remove_accessor_declaration
2292 : opt_attributes REMOVE
2294 lexer.EventParsing = false;
2298 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2299 lexer.EventParsing = true;
2301 | opt_attributes REMOVE error {
2302 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2305 | opt_attributes modifiers REMOVE {
2306 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2312 : opt_attributes opt_modifiers
2313 member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2316 implicit_value_parameter_type = (FullNamedExpression) $3;
2317 indexer_parameters = (Parameters) $6;
2319 if (indexer_parameters.IsEmpty)
2320 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2322 if (RootContext.Documentation != null) {
2323 tmpComment = Lexer.consume_doc_comment ();
2324 Lexer.doc_state = XmlCommentState.Allowed;
2327 lexer.PropertyParsing = true;
2328 parsing_indexer = true;
2331 accessor_declarations
2333 lexer.PropertyParsing = false;
2334 has_get = has_set = false;
2335 parsing_indexer = false;
2339 Accessors accessors = (Accessors) $10;
2340 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2341 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2342 bool order = accessors != null ? accessors.declared_in_reverse : false;
2344 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2345 (MemberName)$4, (int) $2, (Parameters) $6, (Attributes) $1,
2346 get_block, set_block, order);
2348 if ($3 == TypeManager.system_void_expr)
2349 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2351 if (accessors == null)
2352 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2354 if (current_container.Kind == Kind.Interface) {
2355 if (indexer.Get.Block != null)
2356 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2358 if (indexer.Set.Block != null)
2359 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2362 if (RootContext.Documentation != null)
2363 indexer.DocComment = ConsumeStoredComment ();
2365 current_container.AddIndexer (indexer);
2367 current_local_parameters = null;
2368 implicit_value_parameter_type = null;
2369 indexer_parameters = null;
2376 ENUM type_declaration_name
2378 if (RootContext.Documentation != null)
2379 enumTypeComment = Lexer.consume_doc_comment ();
2384 MemberName name = (MemberName) $4;
2385 if (name.IsGeneric) {
2386 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2389 name = MakeName (name);
2390 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2391 name, (Attributes) $1);
2393 if (RootContext.Documentation != null)
2394 e.DocComment = enumTypeComment;
2397 EnumMember em = null;
2398 foreach (VariableDeclaration ev in (ArrayList) $7) {
2399 em = new EnumMember (
2400 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2401 ev.OptAttributes, ev.Location);
2403 // if (RootContext.Documentation != null)
2404 em.DocComment = ev.DocComment;
2406 e.AddEnumMember (em);
2408 if (RootContext.EvalMode)
2409 undo.AddTypeContainer (current_container, e);
2411 current_container.AddTypeContainer (e);
2419 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2422 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2423 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2424 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2425 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2426 Enum.Error_1008 (GetLocation ($2));
2432 Error_TypeExpected (lexer.Location);
2439 if (RootContext.Documentation != null)
2440 Lexer.doc_state = XmlCommentState.Allowed;
2442 opt_enum_member_declarations
2444 // here will be evaluated after CLOSE_BLACE is consumed.
2445 if (RootContext.Documentation != null)
2446 Lexer.doc_state = XmlCommentState.Allowed;
2454 opt_enum_member_declarations
2455 : /* empty */ { $$ = new ArrayList (4); }
2456 | enum_member_declarations opt_comma { $$ = $1; }
2459 enum_member_declarations
2460 : enum_member_declaration
2462 ArrayList l = new ArrayList (4);
2467 | enum_member_declarations COMMA enum_member_declaration
2469 ArrayList l = (ArrayList) $1;
2477 enum_member_declaration
2478 : opt_attributes IDENTIFIER
2480 VariableDeclaration vd = new VariableDeclaration (
2481 (LocatedToken) $2, null, (Attributes) $1);
2483 if (RootContext.Documentation != null) {
2484 vd.DocComment = Lexer.consume_doc_comment ();
2485 Lexer.doc_state = XmlCommentState.Allowed;
2490 | opt_attributes IDENTIFIER
2492 if (RootContext.Documentation != null) {
2493 tmpComment = Lexer.consume_doc_comment ();
2494 Lexer.doc_state = XmlCommentState.NotAllowed;
2497 ASSIGN constant_expression
2499 VariableDeclaration vd = new VariableDeclaration (
2500 (LocatedToken) $2, $5, (Attributes) $1);
2502 if (RootContext.Documentation != null)
2503 vd.DocComment = ConsumeStoredComment ();
2509 delegate_declaration
2513 member_type type_declaration_name
2514 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2516 MemberName name = MakeName ((MemberName) $5);
2517 Parameters p = (Parameters) $7;
2519 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2520 (int) $2, name, p, (Attributes) $1);
2522 if (RootContext.Documentation != null) {
2523 del.DocComment = Lexer.consume_doc_comment ();
2524 Lexer.doc_state = XmlCommentState.Allowed;
2527 current_container.AddDelegate (del);
2528 current_delegate = del;
2529 lexer.ConstraintsParsing = true;
2531 opt_type_parameter_constraints_clauses
2533 lexer.ConstraintsParsing = false;
2537 current_delegate.SetParameterInfo ((ArrayList) $10);
2538 $$ = current_delegate;
2540 current_delegate = null;
2551 if (RootContext.Version < LanguageVersion.ISO_2)
2552 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2558 namespace_or_type_name
2560 | qualified_alias_member IDENTIFIER opt_type_argument_list
2562 LocatedToken lt1 = (LocatedToken) $1;
2563 LocatedToken lt2 = (LocatedToken) $2;
2565 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2571 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2573 LocatedToken lt = (LocatedToken) $3;
2574 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2579 : IDENTIFIER opt_type_argument_list
2581 LocatedToken lt = (LocatedToken) $1;
2582 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2587 // Generics arguments (any type, without attributes)
2589 opt_type_argument_list
2590 : /* empty */ { $$ = null; }
2591 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2593 if (RootContext.Version < LanguageVersion.ISO_2)
2594 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2598 | OP_GENERICS_LT error
2600 Error_TypeExpected (lexer.Location);
2601 $$ = new TypeParameterName ("", null, lexer.Location);
2608 TypeArguments type_args = new TypeArguments (lexer.Location);
2609 type_args.Add ((Expression) $1);
2612 | type_arguments COMMA type
2614 TypeArguments type_args = (TypeArguments) $1;
2615 type_args.Add ((Expression) $3);
2621 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2623 type_declaration_name
2626 lexer.parsing_generic_declaration = true;
2628 opt_type_parameter_list
2630 lexer.parsing_generic_declaration = false;
2631 LocatedToken lt = (LocatedToken) $1;
2632 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2636 member_declaration_name
2637 : method_declaration_name
2639 MemberName mn = (MemberName)$1;
2640 if (mn.TypeArguments != null)
2641 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2642 mn.GetSignatureForError ()));
2646 method_declaration_name
2647 : type_declaration_name
2648 | explicit_interface IDENTIFIER opt_type_parameter_list
2650 lexer.parsing_generic_declaration = false;
2651 LocatedToken lt = (LocatedToken) $2;
2652 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2656 indexer_declaration_name
2659 lexer.parsing_generic_declaration = false;
2660 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2662 | explicit_interface THIS
2664 lexer.parsing_generic_declaration = false;
2665 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2670 : IDENTIFIER opt_type_argument_list DOT
2672 LocatedToken lt = (LocatedToken) $1;
2673 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2675 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2677 LocatedToken lt1 = (LocatedToken) $1;
2678 LocatedToken lt2 = (LocatedToken) $2;
2680 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2682 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2684 LocatedToken lt = (LocatedToken) $2;
2685 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2689 opt_type_parameter_list
2690 : /* empty */ { $$ = null; }
2691 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2693 if (RootContext.Version < LanguageVersion.ISO_2)
2694 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2703 TypeArguments type_args = new TypeArguments (lexer.Location);
2704 type_args.Add ((Expression)$1);
2707 | type_parameters COMMA type_parameter
2709 TypeArguments type_args = (TypeArguments) $1;
2710 type_args.Add ((Expression)$3);
2716 : opt_attributes IDENTIFIER
2718 LocatedToken lt = (LocatedToken)$2;
2719 $$ = new TypeParameterName (lt.Value, (Attributes)$1, lt.Location);
2723 if (GetTokenName (yyToken) == "<type>")
2724 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2726 Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
2728 $$ = new TypeParameterName ("", null, lexer.Location);
2733 // All types where void is allowed
2736 : type_expression_or_array
2739 $$ = TypeManager.system_void_expr;
2746 lexer.parsing_generic_declaration = true;
2751 // A type which does not allow `void' to be used
2754 : type_expression_or_array
2757 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2758 $$ = TypeManager.system_void_expr;
2762 type_expression_or_array
2768 : namespace_or_type_name opt_nullable
2770 MemberName name = (MemberName) $1;
2773 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2775 if (name.Left == null && name.Name == "var" &&
2776 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
2777 $$ = current_array_type = new VarExpr (name.Location);
2779 $$ = name.GetTypeExpression ();
2782 | builtin_types opt_nullable
2785 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2787 | type_expression STAR
2790 // Note that here only unmanaged types are allowed but we
2791 // can't perform checks during this phase - we do it during
2792 // semantic analysis.
2794 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2798 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2803 : builtin_types opt_nullable
2806 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2810 $$ = TypeManager.system_void_expr;
2812 | non_expression_type rank_specifiers
2814 Location loc = GetLocation ($1);
2816 loc = lexer.Location;
2817 $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, loc);
2819 | non_expression_type STAR
2821 Location loc = GetLocation ($1);
2823 loc = lexer.Location;
2824 $$ = new ComposedCast ((FullNamedExpression) $1, "*", loc);
2827 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2828 // through this different path
2830 | multiplicative_expression STAR
2832 FullNamedExpression e = $1 as FullNamedExpression;
2834 $$ = new ComposedCast (e, "*");
2836 Error_TypeExpected (GetLocation ($1));
2843 ArrayList types = new ArrayList (2);
2847 | type_list COMMA base_type_name
2849 ArrayList types = (ArrayList) $1;
2858 if ($1 is ComposedCast)
2859 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2864 Error_TypeExpected (lexer.Location);
2869 * replaces all the productions for isolating the various
2870 * simple types, but we need this to reuse it easily in local_variable_type
2873 : OBJECT { $$ = TypeManager.system_object_expr; }
2874 | STRING { $$ = TypeManager.system_string_expr; }
2875 | BOOL { $$ = TypeManager.system_boolean_expr; }
2876 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2877 | FLOAT { $$ = TypeManager.system_single_expr; }
2878 | DOUBLE { $$ = TypeManager.system_double_expr; }
2883 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2884 | BYTE { $$ = TypeManager.system_byte_expr; }
2885 | SHORT { $$ = TypeManager.system_int16_expr; }
2886 | USHORT { $$ = TypeManager.system_uint16_expr; }
2887 | INT { $$ = TypeManager.system_int32_expr; }
2888 | UINT { $$ = TypeManager.system_uint32_expr; }
2889 | LONG { $$ = TypeManager.system_int64_expr; }
2890 | ULONG { $$ = TypeManager.system_uint64_expr; }
2891 | CHAR { $$ = TypeManager.system_char_expr; }
2895 : type_expression rank_specifiers
2897 string rank_specifiers = (string) $2;
2898 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2906 $$ = TypeManager.system_void_expr;
2911 // Expressions, section 7.5
2916 : primary_expression_no_array_creation
2917 | array_creation_expression
2920 primary_expression_no_array_creation
2922 | IDENTIFIER opt_type_argument_list
2924 LocatedToken lt = (LocatedToken) $1;
2925 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2927 | parenthesized_expression
2928 | default_value_expression
2930 | invocation_expression
2934 | post_increment_expression
2935 | post_decrement_expression
2936 | object_or_delegate_creation_expression
2937 | anonymous_type_expression
2940 | checked_expression
2941 | unchecked_expression
2942 | pointer_member_access
2943 | anonymous_method_expression
2950 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2951 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2952 | NULL { $$ = new NullLiteral (lexer.Location); }
2956 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2957 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2958 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2963 object v = lexer.Value;
2966 $$ = new IntLiteral ((int) v, lexer.Location);
2967 } else if (v is uint)
2968 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2970 $$ = new LongLiteral ((Int64) v, lexer.Location);
2971 else if (v is ulong)
2972 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2974 Console.WriteLine ("OOPS. Unexpected result from scanner");
2979 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2980 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2983 parenthesized_expression_0
2984 : OPEN_PARENS expression CLOSE_PARENS
2987 lexer.Deambiguate_CloseParens ($$);
2988 // After this, the next token returned is one of
2989 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
2990 // or CLOSE_PARENS_MINUS.
2992 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
2995 parenthesized_expression
2996 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3000 | parenthesized_expression_0 CLOSE_PARENS
3004 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3006 // If a parenthesized expression is followed by a minus, we need to wrap
3007 // the expression inside a ParenthesizedExpression for the CS0075 check
3008 // in Binary.DoResolve().
3009 $$ = new ParenthesizedExpression ((Expression) $1);
3014 : primary_expression DOT IDENTIFIER opt_type_argument_list
3016 LocatedToken lt = (LocatedToken) $3;
3017 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3019 | predefined_type DOT IDENTIFIER opt_type_argument_list
3021 LocatedToken lt = (LocatedToken) $3;
3022 // TODO: Location is wrong as some predefined types doesn't hold a location
3023 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3025 | qualified_alias_member IDENTIFIER opt_type_argument_list
3027 LocatedToken lt1 = (LocatedToken) $1;
3028 LocatedToken lt2 = (LocatedToken) $2;
3030 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3034 invocation_expression
3035 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3038 Report.Error (1, (Location) $2, "Parse error");
3040 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3042 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3044 $$ = new Invocation ((Expression) $1, new ArrayList ());
3046 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3048 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3050 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3052 ArrayList args = new ArrayList (1);
3054 $$ = new Invocation ((Expression) $1, args);
3056 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3058 ArrayList args = ((ArrayList) $4);
3060 $$ = new Invocation ((Expression) $1, args);
3064 opt_object_or_collection_initializer
3065 : /* empty */ { $$ = null; }
3066 | object_or_collection_initializer
3069 object_or_collection_initializer
3070 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3073 $$ = CollectionOrObjectInitializers.Empty;
3075 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3077 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3079 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3083 opt_member_initializer_list
3084 : /* empty */ { $$ = null; }
3085 | member_initializer_list
3091 member_initializer_list
3092 : member_initializer
3094 ArrayList a = new ArrayList ();
3098 | member_initializer_list COMMA member_initializer
3100 ArrayList a = (ArrayList)$1;
3107 : IDENTIFIER ASSIGN initializer_value
3109 LocatedToken lt = $1 as LocatedToken;
3110 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3112 | non_assignment_expression
3114 $$ = new CollectionElementInitializer ((Expression)$1);
3116 | OPEN_BRACE expression_list CLOSE_BRACE
3118 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3120 | OPEN_BRACE CLOSE_BRACE
3122 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3128 | object_or_collection_initializer
3132 : /* empty */ { $$ = null; }
3139 ArrayList list = new ArrayList (4);
3143 | argument_list COMMA argument
3145 ArrayList list = (ArrayList) $1;
3149 | argument_list COMMA
3151 Report.Error (839, GetLocation ($2), "An argument is missing");
3156 Report.Error (839, GetLocation ($1), "An argument is missing");
3164 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3166 | non_simple_argument
3173 : REF variable_reference
3175 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3177 | OUT variable_reference
3179 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3181 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3183 ArrayList list = (ArrayList) $3;
3184 Argument[] args = new Argument [list.Count];
3185 list.CopyTo (args, 0);
3187 Expression expr = new Arglist (args, (Location) $1);
3188 $$ = new Argument (expr, Argument.AType.Expression);
3190 | ARGLIST OPEN_PARENS CLOSE_PARENS
3192 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3196 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3201 : expression { note ("section 5.4"); $$ = $1; }
3205 : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
3207 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3209 | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3211 // LAMESPEC: Not allowed according to specification
3212 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3214 | primary_expression_no_array_creation rank_specifiers
3216 // So the super-trick is that primary_expression
3217 // can only be either a SimpleName or a MemberAccess.
3218 // The MemberAccess case arises when you have a fully qualified type-name like :
3220 // SimpleName is when you have
3223 Expression expr = (Expression) $1;
3224 if (expr is ComposedCast){
3225 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3226 } else if (expr is ATypeNameExpression){
3228 // So we extract the string corresponding to the SimpleName
3231 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3233 Error_ExpectingTypeName (expr);
3234 $$ = TypeManager.system_object_expr;
3237 current_array_type = (FullNamedExpression)$$;
3244 ArrayList list = new ArrayList (4);
3248 | expression_list COMMA expression
3250 ArrayList list = (ArrayList) $1;
3259 $$ = new This (current_block, (Location) $1);
3264 : BASE DOT IDENTIFIER opt_type_argument_list
3266 LocatedToken lt = (LocatedToken) $3;
3267 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3269 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3271 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3274 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3279 post_increment_expression
3280 : primary_expression OP_INC
3282 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3283 (Expression) $1, (Location) $2);
3287 post_decrement_expression
3288 : primary_expression OP_DEC
3290 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3291 (Expression) $1, (Location) $2);
3295 object_or_delegate_creation_expression
3296 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3299 if (RootContext.Version <= LanguageVersion.ISO_2)
3300 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3302 $$ = new NewInitialize ((Expression) $2, (ArrayList) $4, (CollectionOrObjectInitializers) $6, (Location) $1);
3305 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3307 | NEW type object_or_collection_initializer
3309 if (RootContext.Version <= LanguageVersion.ISO_2)
3310 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3312 $$ = new NewInitialize ((Expression) $2, null, (CollectionOrObjectInitializers) $3, (Location) $1);
3316 array_creation_expression
3317 : NEW type_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3319 opt_array_initializer
3321 $$ = new ArrayCreation ((FullNamedExpression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3323 | NEW type_expression rank_specifiers array_initializer
3325 $$ = new ArrayCreation ((FullNamedExpression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3327 | NEW rank_specifiers array_initializer
3329 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, (Location) $1);
3333 Report.Error (1031, (Location) $1, "Type expected");
3336 | NEW type_expression error
3338 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3343 anonymous_type_expression
3344 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3346 if (RootContext.Version <= LanguageVersion.ISO_2)
3347 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3349 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3353 anonymous_type_parameters_opt_comma
3354 : anonymous_type_parameters_opt
3355 | anonymous_type_parameters COMMA
3358 anonymous_type_parameters_opt
3360 | anonymous_type_parameters
3363 anonymous_type_parameters
3364 : anonymous_type_parameter
3366 ArrayList a = new ArrayList (4);
3370 | anonymous_type_parameters COMMA anonymous_type_parameter
3372 ArrayList a = (ArrayList) $1;
3378 anonymous_type_parameter
3379 : IDENTIFIER ASSIGN variable_initializer
3381 LocatedToken lt = (LocatedToken)$1;
3382 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3386 LocatedToken lt = (LocatedToken)$1;
3387 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3388 lt.Value, lt.Location);
3390 | BASE DOT IDENTIFIER opt_type_argument_list
3392 LocatedToken lt = (LocatedToken) $3;
3393 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3394 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3398 MemberAccess ma = (MemberAccess) $1;
3399 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3403 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3404 "Anonymous type members must be a member assignment, simple name or member access expression");
3419 opt_rank_specifier_or_nullable
3427 | opt_nullable rank_specifiers
3430 $$ = "?" + (string) $2;
3437 : rank_specifier opt_rank_specifier
3439 $$ = (string) $2 + (string) $1;
3444 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3446 $$ = "[" + (string) $2 + "]";
3466 | dim_separators COMMA
3468 $$ = (string) $1 + ",";
3472 opt_array_initializer
3484 : OPEN_BRACE CLOSE_BRACE
3486 ArrayList list = new ArrayList (4);
3489 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3491 $$ = (ArrayList) $2;
3495 variable_initializer_list
3496 : variable_initializer
3498 ArrayList list = new ArrayList (4);
3502 | variable_initializer_list COMMA variable_initializer
3504 ArrayList list = (ArrayList) $1;
3513 pushed_current_array_type = current_array_type;
3514 lexer.TypeOfParsing = true;
3516 OPEN_PARENS typeof_type_expression CLOSE_PARENS
3518 lexer.TypeOfParsing = false;
3519 Expression type = (Expression)$4;
3520 if (type == TypeManager.system_void_expr)
3521 $$ = new TypeOfVoid ((Location) $1);
3523 $$ = new TypeOf (type, (Location) $1);
3524 current_array_type = pushed_current_array_type;
3528 typeof_type_expression
3535 $$ = new UnboundTypeExpression ((MemberName)$1, lexer.Location);
3539 Error_TypeExpected (lexer.Location);
3545 : IDENTIFIER generic_dimension
3547 LocatedToken lt = (LocatedToken) $1;
3548 TypeArguments ta = (TypeArguments)$2;
3550 $$ = new MemberName (lt.Value, ta, lt.Location);
3552 | qualified_alias_member IDENTIFIER generic_dimension
3554 LocatedToken lt1 = (LocatedToken) $1;
3555 LocatedToken lt2 = (LocatedToken) $2;
3556 TypeArguments ta = (TypeArguments)$3;
3558 $$ = new MemberName (new MemberName (lt1.Value, lt1.Location), lt2.Value, ta, lt2.Location);
3560 | unbound_type_name DOT IDENTIFIER generic_dimension
3562 LocatedToken lt = (LocatedToken) $3;
3563 TypeArguments ta = (TypeArguments)$4;
3565 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3567 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3569 LocatedToken lt = (LocatedToken) $3;
3570 TypeArguments ta = (TypeArguments)$4;
3572 $$ = new MemberName ((MemberName)$1, lt.Value, ta, lt.Location);
3579 if (RootContext.Version < LanguageVersion.ISO_2)
3580 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3582 $$ = new TypeArguments ((int)$1, lexer.Location);
3586 qualified_alias_member
3587 : IDENTIFIER DOUBLE_COLON
3589 LocatedToken lt = (LocatedToken) $1;
3590 if (RootContext.Version == LanguageVersion.ISO_1)
3591 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3598 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3599 $$ = new SizeOf ((Expression) $3, (Location) $1);
3604 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3606 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3610 unchecked_expression
3611 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3613 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3617 pointer_member_access
3618 : primary_expression OP_PTR IDENTIFIER
3621 LocatedToken lt = (LocatedToken) $3;
3623 deref = new Indirection ((Expression) $1, lt.Location);
3624 $$ = new MemberAccess (deref, lt.Value);
3628 anonymous_method_expression
3629 : DELEGATE opt_anonymous_method_signature
3631 start_anonymous (false, (Parameters) $2, (Location) $1);
3635 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3639 opt_anonymous_method_signature
3640 : /* empty */ { $$ = null; }
3641 | anonymous_method_signature
3644 anonymous_method_signature
3647 params_modifiers_not_allowed = true;
3649 opt_formal_parameter_list CLOSE_PARENS
3651 params_modifiers_not_allowed = false;
3656 default_value_expression
3657 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3659 if (RootContext.Version < LanguageVersion.ISO_2)
3660 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3662 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3667 : primary_expression
3668 | BANG prefixed_unary_expression
3670 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3672 | TILDE prefixed_unary_expression
3674 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3680 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3682 $$ = new Cast ((Expression) $1, (Expression) $3);
3684 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3686 $$ = new Cast ((Expression) $1, (Expression) $3);
3688 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3690 $$ = new Cast ((Expression) $1, (Expression) $3);
3696 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3698 if ($2 == TypeManager.system_void_expr)
3699 Expression.Error_VoidInvalidInTheContext (GetLocation ($2));
3701 // TODO: wrong location
3702 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3707 // The idea to split this out is from Rhys' grammar
3708 // to solve the problem with casts.
3710 prefixed_unary_expression
3712 | PLUS prefixed_unary_expression
3714 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3716 | MINUS prefixed_unary_expression
3718 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3720 | OP_INC prefixed_unary_expression
3722 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3723 (Expression) $2, (Location) $1);
3725 | OP_DEC prefixed_unary_expression
3727 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3728 (Expression) $2, (Location) $1);
3730 | STAR prefixed_unary_expression
3732 $$ = new Indirection ((Expression) $2, (Location) $1);
3734 | BITWISE_AND prefixed_unary_expression
3736 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3740 multiplicative_expression
3741 : prefixed_unary_expression
3742 | multiplicative_expression STAR prefixed_unary_expression
3744 $$ = new Binary (Binary.Operator.Multiply,
3745 (Expression) $1, (Expression) $3);
3747 | multiplicative_expression DIV prefixed_unary_expression
3749 $$ = new Binary (Binary.Operator.Division,
3750 (Expression) $1, (Expression) $3);
3752 | multiplicative_expression PERCENT prefixed_unary_expression
3754 $$ = new Binary (Binary.Operator.Modulus,
3755 (Expression) $1, (Expression) $3);
3760 : multiplicative_expression
3761 | additive_expression PLUS multiplicative_expression
3763 $$ = new Binary (Binary.Operator.Addition,
3764 (Expression) $1, (Expression) $3);
3766 | additive_expression MINUS multiplicative_expression
3768 $$ = new Binary (Binary.Operator.Subtraction,
3769 (Expression) $1, (Expression) $3);
3771 | additive_expression AS type
3773 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3775 | additive_expression IS type
3777 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3782 : additive_expression
3783 | shift_expression OP_SHIFT_LEFT additive_expression
3785 $$ = new Binary (Binary.Operator.LeftShift,
3786 (Expression) $1, (Expression) $3);
3788 | shift_expression OP_SHIFT_RIGHT additive_expression
3790 $$ = new Binary (Binary.Operator.RightShift,
3791 (Expression) $1, (Expression) $3);
3795 relational_expression
3797 | relational_expression OP_LT shift_expression
3799 $$ = new Binary (Binary.Operator.LessThan,
3800 (Expression) $1, (Expression) $3);
3802 | relational_expression OP_GT shift_expression
3804 $$ = new Binary (Binary.Operator.GreaterThan,
3805 (Expression) $1, (Expression) $3);
3807 | relational_expression OP_LE shift_expression
3809 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3810 (Expression) $1, (Expression) $3);
3812 | relational_expression OP_GE shift_expression
3814 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3815 (Expression) $1, (Expression) $3);
3820 : relational_expression
3821 | equality_expression OP_EQ relational_expression
3823 $$ = new Binary (Binary.Operator.Equality,
3824 (Expression) $1, (Expression) $3);
3826 | equality_expression OP_NE relational_expression
3828 $$ = new Binary (Binary.Operator.Inequality,
3829 (Expression) $1, (Expression) $3);
3834 : equality_expression
3835 | and_expression BITWISE_AND equality_expression
3837 $$ = new Binary (Binary.Operator.BitwiseAnd,
3838 (Expression) $1, (Expression) $3);
3842 exclusive_or_expression
3844 | exclusive_or_expression CARRET and_expression
3846 $$ = new Binary (Binary.Operator.ExclusiveOr,
3847 (Expression) $1, (Expression) $3);
3851 inclusive_or_expression
3852 : exclusive_or_expression
3853 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3855 $$ = new Binary (Binary.Operator.BitwiseOr,
3856 (Expression) $1, (Expression) $3);
3860 conditional_and_expression
3861 : inclusive_or_expression
3862 | conditional_and_expression OP_AND inclusive_or_expression
3864 $$ = new Binary (Binary.Operator.LogicalAnd,
3865 (Expression) $1, (Expression) $3);
3869 conditional_or_expression
3870 : conditional_and_expression
3871 | conditional_or_expression OP_OR conditional_and_expression
3873 $$ = new Binary (Binary.Operator.LogicalOr,
3874 (Expression) $1, (Expression) $3);
3878 conditional_expression
3879 : conditional_or_expression
3880 | conditional_or_expression INTERR expression COLON expression
3882 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3884 | conditional_or_expression OP_COALESCING expression
3886 if (RootContext.Version < LanguageVersion.ISO_2)
3887 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3889 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3891 | primary_expression INTERR_NULLABLE opt_rank_specifier
3894 // TODO: Is this the best place to handle `= (foo?)a;' ?
3896 if (RootContext.Version < LanguageVersion.ISO_2)
3897 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
3899 $$ = new ComposedCast ((FullNamedExpression) $1, "?" + (string)$3, lexer.Location);
3903 assignment_expression
3904 : prefixed_unary_expression ASSIGN expression
3906 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3908 | prefixed_unary_expression OP_MULT_ASSIGN expression
3910 $$ = new CompoundAssign (
3911 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3913 | prefixed_unary_expression OP_DIV_ASSIGN expression
3915 $$ = new CompoundAssign (
3916 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3918 | prefixed_unary_expression OP_MOD_ASSIGN expression
3920 $$ = new CompoundAssign (
3921 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3923 | prefixed_unary_expression OP_ADD_ASSIGN expression
3925 $$ = new CompoundAssign (
3926 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3928 | prefixed_unary_expression OP_SUB_ASSIGN expression
3930 $$ = new CompoundAssign (
3931 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3933 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3935 $$ = new CompoundAssign (
3936 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3938 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3940 $$ = new CompoundAssign (
3941 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3943 | prefixed_unary_expression OP_AND_ASSIGN expression
3945 $$ = new CompoundAssign (
3946 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3948 | prefixed_unary_expression OP_OR_ASSIGN expression
3950 $$ = new CompoundAssign (
3951 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3953 | prefixed_unary_expression OP_XOR_ASSIGN expression
3955 $$ = new CompoundAssign (
3956 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3960 lambda_parameter_list
3963 ArrayList pars = new ArrayList (4);
3968 | lambda_parameter_list COMMA lambda_parameter
3970 ArrayList pars = (ArrayList) $1;
3971 Parameter p = (Parameter)$3;
3972 if (pars[0].GetType () != p.GetType ()) {
3973 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
3982 : parameter_modifier type IDENTIFIER
3984 LocatedToken lt = (LocatedToken) $3;
3986 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3990 LocatedToken lt = (LocatedToken) $2;
3992 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
3996 LocatedToken lt = (LocatedToken) $1;
3997 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4001 opt_lambda_parameter_list
4002 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
4003 | lambda_parameter_list {
4004 ArrayList pars_list = (ArrayList) $1;
4005 $$ = new Parameters ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4009 lambda_expression_body
4011 start_block (lexer.Location);
4015 Block b = end_block (lexer.Location);
4016 b.AddStatement (new ContextualReturn ((Expression) $2));
4027 LocatedToken lt = (LocatedToken) $1;
4028 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4029 start_anonymous (true, new Parameters (p), (Location) $2);
4031 lambda_expression_body
4033 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4035 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4037 start_anonymous (true, (Parameters) $2, (Location) $4);
4039 lambda_expression_body
4041 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4046 : assignment_expression
4047 | non_assignment_expression
4050 non_assignment_expression
4051 : conditional_expression
4073 lexer.ConstraintsParsing = true;
4075 type_declaration_name
4077 MemberName name = MakeName ((MemberName) $6);
4078 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4081 opt_type_parameter_constraints_clauses
4083 lexer.ConstraintsParsing = false;
4085 current_class.SetParameterInfo ((ArrayList) $9);
4087 if (RootContext.Documentation != null) {
4088 current_container.DocComment = Lexer.consume_doc_comment ();
4089 Lexer.doc_state = XmlCommentState.Allowed;
4094 if (RootContext.Documentation != null)
4095 Lexer.doc_state = XmlCommentState.Allowed;
4099 $$ = pop_current_class ();
4107 { $$ = $1; } // location
4111 : /* empty */ { $$ = (int) 0; }
4117 | modifiers modifier
4122 if ((m1 & m2) != 0) {
4123 Location l = lexer.Location;
4124 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4126 $$ = (int) (m1 | m2);
4134 if (current_container == RootContext.ToplevelTypes)
4135 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4137 | PUBLIC { $$ = Modifiers.PUBLIC; }
4138 | PROTECTED { $$ = Modifiers.PROTECTED; }
4139 | INTERNAL { $$ = Modifiers.INTERNAL; }
4140 | PRIVATE { $$ = Modifiers.PRIVATE; }
4141 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4142 | SEALED { $$ = Modifiers.SEALED; }
4143 | STATIC { $$ = Modifiers.STATIC; }
4144 | READONLY { $$ = Modifiers.READONLY; }
4145 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4146 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4147 | EXTERN { $$ = Modifiers.EXTERN; }
4148 | VOLATILE { $$ = Modifiers.VOLATILE; }
4149 | UNSAFE { $$ = Modifiers.UNSAFE; }
4158 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4161 opt_type_parameter_constraints_clauses
4162 : /* empty */ { $$ = null; }
4163 | type_parameter_constraints_clauses
4167 type_parameter_constraints_clauses
4168 : type_parameter_constraints_clause {
4169 ArrayList constraints = new ArrayList (1);
4170 constraints.Add ($1);
4173 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4174 ArrayList constraints = (ArrayList) $1;
4175 Constraints new_constraint = (Constraints)$2;
4177 foreach (Constraints c in constraints) {
4178 if (new_constraint.TypeParameter == c.TypeParameter) {
4179 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4180 new_constraint.TypeParameter);
4184 constraints.Add (new_constraint);
4189 type_parameter_constraints_clause
4190 : WHERE IDENTIFIER COLON type_parameter_constraints {
4191 LocatedToken lt = (LocatedToken) $2;
4192 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4196 type_parameter_constraints
4197 : type_parameter_constraint {
4198 ArrayList constraints = new ArrayList (1);
4199 constraints.Add ($1);
4202 | type_parameter_constraints COMMA type_parameter_constraint {
4203 ArrayList constraints = (ArrayList) $1;
4205 constraints.Add ($3);
4210 type_parameter_constraint
4212 | NEW OPEN_PARENS CLOSE_PARENS {
4213 $$ = SpecialConstraint.Constructor;
4216 $$ = SpecialConstraint.ReferenceType;
4219 $$ = SpecialConstraint.ValueType;
4228 // A block is "contained" on the following places:
4230 // property_declaration as part of the accessor body (get/set)
4231 // operator_declaration
4232 // constructor_declaration
4233 // destructor_declaration
4234 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4239 ++lexer.parsing_block;
4240 start_block ((Location) $1);
4242 opt_statement_list CLOSE_BRACE
4244 --lexer.parsing_block;
4245 $$ = end_block ((Location) $4);
4252 ++lexer.parsing_block;
4253 current_block.StartLocation = GetLocation ($1);
4255 opt_statement_list CLOSE_BRACE
4257 --lexer.parsing_block;
4258 $$ = end_block ((Location) $4);
4269 | statement_list statement
4273 : declaration_statement
4275 if ($1 != null && (Block) $1 != current_block){
4276 current_block.AddStatement ((Statement) $1);
4277 current_block = (Block) $1;
4280 | valid_declaration_statement
4282 current_block.AddStatement ((Statement) $1);
4288 // The interactive_statement and its derivatives are only
4289 // used to provide a special version of `expression_statement'
4290 // that has a side effect of assigning the expression to
4293 interactive_statement_list
4294 : interactive_statement
4295 | interactive_statement_list interactive_statement
4298 interactive_statement
4299 : declaration_statement
4301 if ($1 != null && (Block) $1 != current_block){
4302 current_block.AddStatement ((Statement) $1);
4303 current_block = (Block) $1;
4306 | interactive_valid_declaration_statement
4308 current_block.AddStatement ((Statement) $1);
4313 valid_declaration_statement
4316 | expression_statement
4317 | selection_statement
4318 | iteration_statement
4322 | unchecked_statement
4329 interactive_valid_declaration_statement
4332 | interactive_expression_statement
4333 | selection_statement
4334 | iteration_statement
4338 | unchecked_statement
4346 : valid_declaration_statement
4347 | declaration_statement
4349 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4354 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4362 $$ = EmptyStatement.Value;
4369 LocatedToken lt = (LocatedToken) $1;
4370 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4372 if (current_block.AddLabel (labeled))
4373 current_block.AddStatement (labeled);
4378 declaration_statement
4379 : local_variable_declaration SEMICOLON
4381 current_array_type = null;
4383 DictionaryEntry de = (DictionaryEntry) $1;
4384 Expression e = (Expression) de.Key;
4386 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4390 | local_constant_declaration SEMICOLON
4392 current_array_type = null;
4394 DictionaryEntry de = (DictionaryEntry) $1;
4396 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4402 * The following is from Rhys' grammar:
4403 * > Types in local variable declarations must be recognized as
4404 * > expressions to prevent reduce/reduce errors in the grammar.
4405 * > The expressions are converted into types during semantic analysis.
4408 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4410 // FIXME: Do something smart here regarding the composition of the type.
4412 // Ok, the above "primary_expression" is there to get rid of
4413 // both reduce/reduce and shift/reduces in the grammar, it should
4414 // really just be "type_name". If you use type_name, a reduce/reduce
4415 // creeps up. If you use namespace_or_type_name (which is all we need
4416 // really) two shift/reduces appear.
4419 // So the super-trick is that primary_expression
4420 // can only be either a SimpleName or a MemberAccess.
4421 // The MemberAccess case arises when you have a fully qualified type-name like :
4423 // SimpleName is when you have
4426 Expression expr = (Expression) $1;
4427 string rank_or_nullable = (string) $2;
4429 if (expr is ComposedCast){
4430 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4431 } else if (expr is ATypeNameExpression){
4433 // So we extract the string corresponding to the SimpleName
4436 if (rank_or_nullable.Length == 0) {
4437 SimpleName sn = expr as SimpleName;
4438 if (sn != null && sn.Name == "var" &&
4439 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
4440 $$ = current_array_type = new VarExpr (sn.Location);
4444 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4447 Error_ExpectingTypeName (expr);
4448 $$ = TypeManager.system_object_expr;
4451 | builtin_types opt_rank_specifier_or_nullable
4453 if ((string) $2 == "")
4456 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4458 | VOID opt_rank_specifier
4460 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4461 $$ = TypeManager.system_void_expr;
4465 local_variable_pointer_type
4466 : primary_expression_no_array_creation STAR
4468 ATypeNameExpression expr = $1 as ATypeNameExpression;
4471 $$ = new ComposedCast (expr, "*");
4473 Error_ExpectingTypeName ((Expression)$1);
4477 | builtin_types STAR
4479 $$ = new ComposedCast ((FullNamedExpression) $1, "*", lexer.Location);
4483 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4485 | local_variable_pointer_type STAR
4487 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4491 local_variable_declaration
4492 : local_variable_type local_variable_declarators
4495 VarExpr ve = $1 as VarExpr;
4497 ve.VariableInitializer = (ArrayList)$2;
4499 $$ = new DictionaryEntry ($1, $2);
4503 | local_variable_pointer_type opt_rank_specifier local_variable_declarators
4508 if ((string) $2 == "")
4509 t = (Expression) $1;
4511 t = new ComposedCast ((FullNamedExpression) $1, (string) $2);
4512 $$ = new DictionaryEntry (t, $3);
4518 local_constant_declaration
4519 : CONST local_variable_type constant_declarators
4522 $$ = new DictionaryEntry ($2, $3);
4528 expression_statement
4529 : statement_expression SEMICOLON { $$ = $1; }
4532 interactive_expression_statement
4533 : interactive_statement_expression SEMICOLON { $$ = $1; }
4537 // We have to do the wrapping here and not in the case above,
4538 // because statement_expression is used for example in for_statement
4540 statement_expression
4543 Expression expr = (Expression) $1;
4544 ExpressionStatement s;
4546 s = expr as ExpressionStatement;
4549 expr.Error_InvalidExpressionStatement ();
4552 $$ = new StatementExpression (s);
4557 Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
4562 interactive_statement_expression
4565 Expression expr = (Expression) $1;
4566 ExpressionStatement s;
4568 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4569 $$ = new StatementExpression (s);
4573 Report.Error (1002, GetLocation ($1), "Expecting {0}, got {1}", GetExpecting (), GetTokenName (yyToken));
4584 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4587 Location l = (Location) $1;
4589 $$ = new If ((Expression) $3, (Statement) $5, l);
4591 // FIXME: location for warning should be loc property of $5.
4592 if ($5 == EmptyStatement.Value)
4593 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4596 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4597 embedded_statement ELSE embedded_statement
4599 Location l = (Location) $1;
4601 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4603 // FIXME: location for warning should be loc property of $5 and $7.
4604 if ($5 == EmptyStatement.Value)
4605 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4606 if ($7 == EmptyStatement.Value)
4607 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4612 : SWITCH OPEN_PARENS
4614 if (switch_stack == null)
4615 switch_stack = new Stack (2);
4616 switch_stack.Push (current_block);
4618 expression CLOSE_PARENS
4621 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4622 current_block = (Block) switch_stack.Pop ();
4638 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4639 $$ = new ArrayList ();
4647 ArrayList sections = new ArrayList (4);
4652 | switch_sections switch_section
4654 ArrayList sections = (ArrayList) $1;
4664 current_block = current_block.CreateSwitchBlock (lexer.Location);
4668 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4675 ArrayList labels = new ArrayList (4);
4680 | switch_labels switch_label
4682 ArrayList labels = (ArrayList) ($1);
4690 : CASE constant_expression COLON
4692 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4696 $$ = new SwitchLabel (null, (Location) $1);
4708 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4710 Location l = (Location) $1;
4711 $$ = new While ((Expression) $3, (Statement) $5, l);
4716 : DO embedded_statement
4717 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4719 Location l = (Location) $1;
4721 $$ = new Do ((Statement) $2, (Expression) $5, l);
4727 opt_for_initializer SEMICOLON
4729 Location l = lexer.Location;
4731 Block assign_block = current_block;
4733 if ($3 is DictionaryEntry){
4734 DictionaryEntry de = (DictionaryEntry) $3;
4736 Expression type = (Expression) de.Key;
4737 ArrayList var_declarators = (ArrayList) de.Value;
4739 foreach (VariableDeclaration decl in var_declarators){
4743 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4747 Expression expr = decl.expression_or_array_initializer;
4749 LocalVariableReference var;
4750 var = new LocalVariableReference (assign_block, decl.identifier, l);
4753 Assign a = new SimpleAssign (var, expr, decl.Location);
4755 assign_block.AddStatement (new StatementExpression (a));
4759 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4760 // This can be referred to as $5 below.
4766 opt_for_condition SEMICOLON
4767 opt_for_iterator CLOSE_PARENS
4770 Location l = (Location) $1;
4772 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4774 current_block.AddStatement (f);
4776 $$ = end_block (lexer.Location);
4781 : /* empty */ { $$ = EmptyStatement.Value; }
4786 : local_variable_declaration
4787 | statement_expression_list
4791 : /* empty */ { $$ = null; }
4792 | boolean_expression
4796 : /* empty */ { $$ = EmptyStatement.Value; }
4801 : statement_expression_list
4804 statement_expression_list
4805 : statement_expression
4807 // CHANGE: was `null'
4808 Statement s = (Statement) $1;
4809 Block b = new Block (current_block, s.loc, lexer.Location);
4814 | statement_expression_list COMMA statement_expression
4816 Block b = (Block) $1;
4818 b.AddStatement ((Statement) $3);
4824 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4826 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4829 | FOREACH OPEN_PARENS type IDENTIFIER IN
4830 expression CLOSE_PARENS
4832 start_block (lexer.Location);
4833 Block foreach_block = current_block;
4835 LocatedToken lt = (LocatedToken) $4;
4836 Location l = lt.Location;
4837 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4839 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4841 // Get a writable reference to this read-only variable.
4843 // Note that the $$ here refers to the value of _this_ code block,
4844 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4845 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4852 LocalVariableReference v = (LocalVariableReference) $8;
4853 Location l = (Location) $1;
4856 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4857 current_block.AddStatement (f);
4860 $$ = end_block (lexer.Location);
4866 | continue_statement
4876 $$ = new Break ((Location) $1);
4881 : CONTINUE SEMICOLON
4883 $$ = new Continue ((Location) $1);
4888 : GOTO IDENTIFIER SEMICOLON
4890 LocatedToken lt = (LocatedToken) $2;
4891 $$ = new Goto (lt.Value, lt.Location);
4893 | GOTO CASE constant_expression SEMICOLON
4895 $$ = new GotoCase ((Expression) $3, (Location) $1);
4897 | GOTO DEFAULT SEMICOLON
4899 $$ = new GotoDefault ((Location) $1);
4904 : RETURN opt_expression SEMICOLON
4906 $$ = new Return ((Expression) $2, (Location) $1);
4911 : THROW opt_expression SEMICOLON
4913 $$ = new Throw ((Expression) $2, (Location) $1);
4918 : IDENTIFIER RETURN expression SEMICOLON
4920 LocatedToken lt = (LocatedToken) $1;
4921 string s = lt.Value;
4923 Report.Error (1003, lt.Location, "; expected");
4926 if (RootContext.Version == LanguageVersion.ISO_1){
4927 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4930 current_block.Toplevel.IsIterator = true;
4931 $$ = new Yield ((Expression) $3, lt.Location);
4933 | IDENTIFIER RETURN SEMICOLON
4935 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4938 | IDENTIFIER BREAK SEMICOLON
4940 LocatedToken lt = (LocatedToken) $1;
4941 string s = lt.Value;
4943 Report.Error (1003, lt.Location, "; expected");
4946 if (RootContext.Version == LanguageVersion.ISO_1){
4947 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4951 current_block.Toplevel.IsIterator = true;
4952 $$ = new YieldBreak (lt.Location);
4962 : TRY block catch_clauses
4964 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
4966 | TRY block FINALLY block
4968 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
4970 | TRY block catch_clauses FINALLY block
4972 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
4976 Report.Error (1524, (Location) $1, "Expected catch or finally");
4984 ArrayList l = new ArrayList (4);
4989 | catch_clauses catch_clause
4991 ArrayList l = (ArrayList) $1;
4999 : /* empty */ { $$ = null; }
5004 : CATCH opt_catch_args
5006 Expression type = null;
5009 DictionaryEntry cc = (DictionaryEntry) $2;
5010 type = (Expression) cc.Key;
5011 LocatedToken lt = (LocatedToken) cc.Value;
5014 ArrayList one = new ArrayList (4);
5016 one.Add (new VariableDeclaration (lt, null));
5018 start_block (lexer.Location);
5019 current_block = declare_local_variables (type, one, lt.Location);
5023 Expression type = null;
5025 Block var_block = null;
5028 DictionaryEntry cc = (DictionaryEntry) $2;
5029 type = (Expression) cc.Key;
5030 LocatedToken lt = (LocatedToken) cc.Value;
5034 var_block = end_block (lexer.Location);
5038 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5043 : /* empty */ { $$ = null; }
5048 : OPEN_PARENS type opt_identifier CLOSE_PARENS
5050 $$ = new DictionaryEntry ($2, $3);
5052 | OPEN_PARENS CLOSE_PARENS
5054 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5061 $$ = new Checked ((Block) $2);
5068 $$ = new Unchecked ((Block) $2);
5075 RootContext.CheckUnsafeOption ((Location) $1);
5077 $$ = new Unsafe ((Block) $3);
5083 type_and_void fixed_pointer_declarators
5086 ArrayList list = (ArrayList) $4;
5087 Expression type = (Expression) $3;
5088 Location l = (Location) $1;
5089 int top = list.Count;
5091 start_block (lexer.Location);
5093 for (int i = 0; i < top; i++){
5094 Pair p = (Pair) list [i];
5097 v = current_block.AddVariable (type, (string) p.First, l);
5101 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5109 Location l = (Location) $1;
5111 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5113 current_block.AddStatement (f);
5115 $$ = end_block (lexer.Location);
5119 fixed_pointer_declarators
5120 : fixed_pointer_declarator {
5121 ArrayList declarators = new ArrayList (4);
5123 declarators.Add ($1);
5126 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5128 ArrayList declarators = (ArrayList) $1;
5130 declarators.Add ($3);
5135 fixed_pointer_declarator
5136 : IDENTIFIER ASSIGN expression
5138 LocatedToken lt = (LocatedToken) $1;
5139 // FIXME: keep location
5140 $$ = new Pair (lt.Value, $3);
5144 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5150 : LOCK OPEN_PARENS expression CLOSE_PARENS
5156 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5161 : USING OPEN_PARENS local_variable_declaration CLOSE_PARENS
5163 start_block (lexer.Location);
5164 Block assign_block = current_block;
5166 DictionaryEntry de = (DictionaryEntry) $3;
5167 Location l = (Location) $1;
5169 Expression type = (Expression) de.Key;
5170 ArrayList var_declarators = (ArrayList) de.Value;
5172 Stack vars = new Stack ();
5174 foreach (VariableDeclaration decl in var_declarators) {
5175 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5178 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5180 Expression expr = decl.expression_or_array_initializer;
5182 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5185 LocalVariableReference var;
5187 // Get a writable reference to this read-only variable.
5188 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5190 // This is so that it is not a warning on using variables
5193 vars.Push (new DictionaryEntry (var, expr));
5195 // Assign a = new SimpleAssign (var, expr, decl.Location);
5196 // assign_block.AddStatement (new StatementExpression (a));
5199 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5200 // It can be referred to as $5 below.
5205 Statement stmt = (Statement) $6;
5206 Stack vars = (Stack) $5;
5207 Location l = (Location) $1;
5209 while (vars.Count > 0) {
5210 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5211 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5213 current_block.AddStatement (stmt);
5214 $$ = end_block (lexer.Location);
5216 | USING OPEN_PARENS expression CLOSE_PARENS
5218 start_block (lexer.Location);
5222 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5223 $$ = end_block (lexer.Location);
5233 ++lexer.query_parsing;
5237 if (--lexer.query_parsing == 1)
5238 lexer.query_parsing = 0;
5240 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5242 from.Tail.Next = (Linq.AQueryClause)$3;
5245 current_block.SetEndLocation (lexer.Location);
5246 current_block = current_block.Parent;
5251 : FROM IDENTIFIER IN expression
5253 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5254 LocatedToken lt = (LocatedToken) $2;
5256 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance, lt.Value, lt.Location);
5257 $$ = new Linq.QueryExpression (lt, new Linq.QueryStartClause ((Expression)$4));
5259 | FROM type IDENTIFIER IN expression
5261 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5262 LocatedToken lt = (LocatedToken) $3;
5264 Expression type = (Expression)$2;
5265 current_block.AddVariable (type, lt.Value, lt.Location);
5266 $$ = new Linq.QueryExpression (lt, new Linq.Cast (type, (Expression)$5));
5271 : FROM IDENTIFIER IN expression
5273 LocatedToken lt = (LocatedToken) $2;
5275 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5276 lt.Value, lt.Location);
5278 $$ = new Linq.SelectMany (lt, (Expression)$4);
5280 | FROM type IDENTIFIER IN expression
5282 LocatedToken lt = (LocatedToken) $3;
5284 Expression type = (Expression)$2;
5285 current_block.AddVariable (type, lt.Value, lt.Location);
5286 $$ = new Linq.SelectMany (lt, new Linq.Cast (type, (Expression)$5));
5291 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5293 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5296 head.Next = (Linq.AQueryClause)$3;
5299 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5300 clause.Tail.Next = head;
5308 select_or_group_clause
5311 $$ = new Linq.Select ((Expression)$2, GetLocation ($1));
5313 | GROUP expression BY expression
5315 $$ = new Linq.GroupBy ((Expression)$2, (Expression)$4, GetLocation ($1));
5319 opt_query_body_clauses
5321 | query_body_clauses
5326 | query_body_clauses query_body_clause
5328 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5342 : LET IDENTIFIER ASSIGN expression
5344 LocatedToken lt = (LocatedToken) $2;
5345 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5346 lt.Value, lt.Location);
5347 $$ = new Linq.Let (lt, (Expression)$4, GetLocation ($1));
5352 : WHERE boolean_expression
5354 $$ = new Linq.Where ((Expression)$2, GetLocation ($1));
5359 : JOIN IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5361 Location loc = GetLocation ($1);
5362 LocatedToken lt = (LocatedToken) $2;
5363 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5364 lt.Value, lt.Location);
5367 $$ = new Linq.Join (lt, (Expression)$4, (Expression)$6,
5368 (Expression)$8, loc);
5370 LocatedToken lt_into = (LocatedToken) $9;
5371 $$ = new Linq.GroupJoin (lt, (Expression)$4, (Expression)$6,
5372 (Expression)$8, lt_into, loc);
5375 | JOIN type IDENTIFIER IN expression ON expression EQUALS expression opt_join_into
5377 Location loc = GetLocation ($1);
5378 LocatedToken lt = (LocatedToken) $3;
5379 current_block.AddVariable ((Expression)$2, lt.Value, lt.Location);
5381 Linq.Cast cast = new Linq.Cast ((Expression)$2, (Expression)$5);
5383 $$ = new Linq.Join (lt, cast, (Expression)$7,
5384 (Expression)$9, loc);
5386 LocatedToken lt_into = (LocatedToken) $10;
5387 $$ = new Linq.GroupJoin (lt, cast, (Expression)$7,
5388 (Expression)$9, lt_into, loc);
5410 | order_by COMMA orderings_then_by
5412 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$3;
5422 | orderings_then_by COMMA then_by
5424 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5432 $$ = new Linq.OrderByAscending ((Expression)$1);
5434 | expression ASCENDING
5436 $$ = new Linq.OrderByAscending ((Expression)$1);
5438 | expression DESCENDING
5440 $$ = new Linq.OrderByDescending ((Expression)$1);
5447 $$ = new Linq.ThenByAscending ((Expression)$1);
5449 | expression ASCENDING
5451 $$ = new Linq.ThenByAscending ((Expression)$1);
5453 | expression DESCENDING
5455 $$ = new Linq.ThenByDescending ((Expression)$1);
5460 opt_query_continuation
5464 // query continuation block is not linked with query block but with block
5465 // before. This means each query can use same range variable names for
5466 // different identifiers.
5468 current_block.SetEndLocation (GetLocation ($1));
5469 current_block = current_block.Parent;
5470 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5472 LocatedToken lt = (LocatedToken) $2;
5473 current_block.AddVariable (Linq.ImplicitQueryParameter.ImplicitType.Instance,
5474 lt.Value, lt.Location);
5478 $$ = new Linq.QueryExpression ((LocatedToken) $2,
5479 (Linq.AQueryClause)$4);
5484 // Support for using the compiler as an interactive parser
5486 // The INTERACTIVE_PARSER token is first sent to parse our
5487 // productions; If the result is a Statement, the parsing
5488 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5489 // to setup the blocks in advance.
5491 // This setup is here so that in the future we can add
5492 // support for other constructs (type parsing, namespaces, etc)
5493 // that do not require a block to be setup in advance
5497 : EVAL_STATEMENT_PARSER EOF
5498 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5499 | EVAL_STATEMENT_PARSER {
5500 Evaluator.LoadAliases (current_namespace);
5502 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5503 Modifiers.PUBLIC, null), null);
5505 ArrayList baseclass_list = new ArrayList ();
5506 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5507 current_container.AddBasesForPart (current_class, baseclass_list);
5509 // (ref object retval)
5510 Parameter [] mpar = new Parameter [1];
5511 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5513 Parameters pars = new Parameters (mpar);
5514 current_local_parameters = pars;
5515 Method method = new Method (
5518 TypeManager.system_void_expr,
5519 Modifiers.PUBLIC | Modifiers.STATIC,
5520 new MemberName ("Host"),
5522 null /* attributes */);
5524 oob_stack.Push (method);
5525 ++lexer.parsing_block;
5526 start_block (lexer.Location);
5528 interactive_statement_list
5530 --lexer.parsing_block;
5531 Method method = (Method) oob_stack.Pop ();
5533 method.Block = (ToplevelBlock) end_block(lexer.Location);
5534 current_container.AddMethod (method);
5536 InteractiveResult = pop_current_class ();
5537 current_local_parameters = null;
5539 | EVAL_COMPILATION_UNIT_PARSER {
5540 Evaluator.LoadAliases (current_namespace);
5542 interactive_compilation_unit
5545 interactive_compilation_unit
5546 : outer_declarations
5547 | outer_declarations global_attributes
5554 // A class used to pass around variable declarations and constants
5556 public class VariableDeclaration {
5557 public string identifier;
5558 public Expression expression_or_array_initializer;
5559 public Location Location;
5560 public Attributes OptAttributes;
5561 public string DocComment;
5563 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5565 this.identifier = lt.Value;
5566 if (eoai is ArrayList) {
5567 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5569 this.expression_or_array_initializer = (Expression)eoai;
5571 this.Location = lt.Location;
5572 this.OptAttributes = opt_attrs;
5575 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5580 class VariableMemberDeclaration
5582 public readonly MemberName MemberName;
5583 public Expression expression_or_array_initializer;
5585 public VariableMemberDeclaration (MemberName mn, object initializer)
5589 if (initializer is ArrayList) {
5590 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5592 this.expression_or_array_initializer = (Expression)initializer;
5599 // A class used to hold info about an operator declarator
5601 struct OperatorDeclaration {
5602 public readonly Operator.OpType optype;
5603 public readonly FullNamedExpression ret_type;
5604 public readonly Location location;
5606 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5609 this.ret_type = ret_type;
5610 this.location = location;
5614 void Error_ExpectingTypeName (Expression expr)
5616 if (expr is Invocation){
5617 Report.Error (1002, expr.Location, "Expecting `;'");
5619 expr.Error_InvalidExpressionStatement ();
5623 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5625 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5629 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5631 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5632 Parameter.GetModifierSignature (mod));
5635 static void Error_TypeExpected (Location loc)
5637 Report.Error (1031, loc, "Type expected");
5640 void push_current_class (TypeContainer tc, object partial_token)
5642 if (RootContext.EvalMode){
5643 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5644 undo.AddTypeContainer (current_container, tc);
5647 if (partial_token != null)
5648 current_container = current_container.AddPartial (tc);
5650 current_container = current_container.AddTypeContainer (tc);
5656 DeclSpace pop_current_class ()
5658 DeclSpace retval = current_class;
5660 current_class = current_class.Parent;
5661 current_container = current_class.PartialContainer;
5667 // Given the @class_name name, it creates a fully qualified name
5668 // based on the containing declaration space
5671 MakeName (MemberName class_name)
5673 Namespace ns = current_namespace.NS;
5675 if (current_container == RootContext.ToplevelTypes) {
5676 if (ns.Name.Length != 0)
5677 return new MemberName (ns.MemberName, class_name);
5681 return new MemberName (current_container.MemberName, class_name);
5685 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5687 Block implicit_block;
5688 ArrayList inits = null;
5691 // If we are doing interactive editing, we want variable declarations
5692 // that are in the top block to be added instead to the class as
5695 if (RootContext.StatementMode){
5698 for (Block b = current_block; b != null; b = b.Parent){
5699 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5700 // There has been an explicit block, we cant add to the class
5707 // We can use "current_block" since we know there are no explicit blocks
5709 foreach (VariableDeclaration decl in variable_declarators){
5710 // We can not use the super-handy f.Initializer, because
5711 // multiple lines would force code to be executed out of sync
5712 if (decl.expression_or_array_initializer != null){
5713 string id = "$" + decl.identifier;
5714 current_block.AddVariable (type, id, decl.Location);
5716 LocalVariableReference var;
5717 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5718 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5719 current_block.AddStatement (new StatementExpression (assign));
5720 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5721 current_block.AddStatement (new StatementExpression (assign));
5723 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
5724 new MemberName (decl.identifier, loc), null);
5725 current_container.AddField (f);
5727 // Register the field to be visible later as a global variable
5728 Evaluator.QueueField (f);
5732 return current_block;
5737 // We use the `Used' property to check whether statements
5738 // have been added to the current block. If so, we need
5739 // to create another block to contain the new declaration
5740 // otherwise, as an optimization, we use the same block to
5741 // add the declaration.
5743 // FIXME: A further optimization is to check if the statements
5744 // that were added were added as part of the initialization
5745 // below. In which case, no other statements have been executed
5746 // and we might be able to reduce the number of blocks for
5747 // situations like this:
5749 // int j = 1; int k = j + 1;
5751 if (current_block.Used)
5752 implicit_block = new Block (current_block, loc, lexer.Location);
5754 implicit_block = current_block;
5756 foreach (VariableDeclaration decl in variable_declarators){
5758 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5759 if (decl.expression_or_array_initializer != null){
5761 inits = new ArrayList (4);
5768 return implicit_block;
5770 foreach (VariableDeclaration decl in inits){
5772 Expression expr = decl.expression_or_array_initializer;
5774 LocalVariableReference var;
5775 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5777 assign = new SimpleAssign (var, expr, decl.Location);
5779 implicit_block.AddStatement (new StatementExpression (assign));
5782 return implicit_block;
5785 Block declare_local_constants (Expression type, ArrayList declarators)
5787 Block implicit_block;
5789 if (current_block.Used)
5790 implicit_block = new Block (current_block);
5792 implicit_block = current_block;
5794 foreach (VariableDeclaration decl in declarators){
5795 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5798 return implicit_block;
5801 string CheckAttributeTarget (string a, Location l)
5804 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5808 Report.Warning (658, 1, l,
5809 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5810 return string.Empty;
5813 static bool IsUnaryOperator (Operator.OpType op)
5817 case Operator.OpType.LogicalNot:
5818 case Operator.OpType.OnesComplement:
5819 case Operator.OpType.Increment:
5820 case Operator.OpType.Decrement:
5821 case Operator.OpType.True:
5822 case Operator.OpType.False:
5823 case Operator.OpType.UnaryPlus:
5824 case Operator.OpType.UnaryNegation:
5830 void syntax_error (Location l, string msg)
5832 Report.Error (1003, l, "Syntax error, " + msg);
5835 void note (string s)
5837 // Used to put annotations
5842 public Tokenizer Lexer {
5848 static CSharpParser ()
5850 oob_stack = new Stack ();
5853 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
5855 if (RootContext.EvalMode)
5859 current_namespace = new NamespaceEntry (null, file, null);
5860 current_class = current_namespace.SlaveDeclSpace;
5861 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5863 lexer = new Tokenizer (reader, file);
5866 public void parse ()
5868 eof_token = Token.EOF;
5871 if (yacc_verbose_flag > 1)
5872 yyparse (lexer, new yydebug.yyDebugSimple ());
5875 } catch (Exception e){
5876 if (e is yyParser.yyUnexpectedEof)
5877 UnexpectedEOF = true;
5878 else if (yacc_verbose_flag > 0)
5879 Console.WriteLine (e);
5880 if (e is yyParser.yyException)
5881 Report.Error (-25, lexer.Location, "Parsing error");
5883 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
5885 Tokenizer tokenizer = lexer as Tokenizer;
5886 tokenizer.cleanup ();
5888 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5889 throw new InternalErrorException ("who set it?");
5892 static void CheckToken (int error, int yyToken, string msg, Location loc)
5894 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5895 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
5897 Report.Error (error, loc, msg);
5900 void CheckIdentifierToken (int yyToken, Location loc)
5902 CheckToken (1041, yyToken, "Identifier expected", loc);
5905 string ConsumeStoredComment ()
5907 string s = tmpComment;
5909 Lexer.doc_state = XmlCommentState.Allowed;
5913 Location GetLocation (object obj)
5915 if (obj is MemberCore)
5916 return ((MemberCore) obj).Location;
5917 if (obj is MemberName)
5918 return ((MemberName) obj).Location;
5919 if (obj is LocatedToken)
5920 return ((LocatedToken) obj).Location;
5921 if (obj is Location)
5922 return (Location) obj;
5923 return lexer.Location;
5926 void start_block (Location loc)
5928 if (current_block == null || parsing_anonymous_method) {
5929 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
5930 parsing_anonymous_method = false;
5932 current_block = new ExplicitBlock (current_block, loc, Location.Null);
5937 end_block (Location loc)
5939 Block retval = current_block.Explicit;
5940 retval.SetEndLocation (loc);
5941 current_block = retval.Parent;
5946 start_anonymous (bool lambda, Parameters parameters, Location loc)
5948 oob_stack.Push (current_anonymous_method);
5949 oob_stack.Push (current_local_parameters);
5951 current_local_parameters = parameters;
5953 current_anonymous_method = lambda
5954 ? new LambdaExpression (parameters, loc)
5955 : new AnonymousMethodExpression (parameters, loc);
5957 // Force the next block to be created as a ToplevelBlock
5958 parsing_anonymous_method = true;
5962 * Completes the anonymous method processing, if lambda_expr is null, this
5963 * means that we have a Statement instead of an Expression embedded
5965 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
5967 AnonymousMethodExpression retval;
5969 if (RootContext.Version == LanguageVersion.ISO_1){
5970 Report.FeatureIsNotAvailable (loc, "anonymous methods");
5973 current_anonymous_method.Block = anon_block;
5974 retval = current_anonymous_method;
5977 current_local_parameters = (Parameters) oob_stack.Pop ();
5978 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
5983 public NamespaceEntry CurrentNamespace {
5985 return current_namespace;
5989 public string GetExpecting ()
5991 int [] tokens = yyExpectingTokens (yyExpectingState);
5992 if (tokens.Length == 1)
5993 return "`" + GetTokenName (tokens [0]) + "'";
5995 StringBuilder sb = new StringBuilder ();
5996 ArrayList names = new ArrayList ();
5997 for (int i = 0; i < tokens.Length; i++){
5998 string name = GetTokenName (tokens [i]);
5999 if (name == "<internal>")
6001 if (names.Contains (name))
6008 int count = names.Count;
6009 for (int i = 0; i < count; i++){
6010 bool last = i + 1 == count;
6014 sb.Append (names [i]);
6015 sb.Append (last ? "'" : "', ");
6017 return sb.ToString ();
6020 static public string GetTokenName (int token)
6023 case Token.ABSTRACT:
6029 case Token.ASSEMBLY:
6045 case Token.CONTINUE:
6049 case Token.DELEGATE:
6059 case Token.EXPLICIT:
6077 case Token.IMPLICIT:
6081 case Token.INTERFACE:
6083 case Token.INTERNAL:
6089 case Token.NAMESPACE:
6097 case Token.OPERATOR:
6101 case Token.OVERRIDE:
6107 case Token.PROTECTED:
6111 case Token.READONLY:
6123 case Token.STACKALLOC:
6124 return "stackalloc";
6141 case Token.UNCHECKED:
6149 case Token.VOLATILE:
6179 case Token.ASCENDING:
6181 case Token.DESCENDING:
6182 return "descending";
6189 case Token.OPEN_BRACE:
6191 case Token.CLOSE_BRACE:
6193 case Token.OPEN_BRACKET:
6195 case Token.CLOSE_BRACKET:
6197 case Token.DEFAULT_OPEN_PARENS:
6198 case Token.OPEN_PARENS_LAMBDA:
6199 case Token.OPEN_PARENS:
6201 case Token.CLOSE_PARENS_CAST:
6202 case Token.CLOSE_PARENS_NO_CAST:
6203 case Token.CLOSE_PARENS_OPEN_PARENS:
6204 case Token.CLOSE_PARENS_MINUS:
6205 case Token.CLOSE_PARENS:
6211 case Token.DEFAULT_COLON:
6215 case Token.SEMICOLON:
6226 case Token.BITWISE_AND:
6227 case Token.BITWISE_OR:
6234 case Token.OP_SHIFT_LEFT:
6235 case Token.OP_SHIFT_RIGHT:
6243 case Token.OP_COALESCING:
6244 return "<operator>";
6246 case Token.OP_MULT_ASSIGN:
6247 case Token.OP_DIV_ASSIGN:
6248 case Token.OP_MOD_ASSIGN:
6249 case Token.OP_ADD_ASSIGN:
6250 case Token.OP_SUB_ASSIGN:
6251 case Token.OP_SHIFT_LEFT_ASSIGN:
6252 case Token.OP_SHIFT_RIGHT_ASSIGN:
6253 case Token.OP_AND_ASSIGN:
6254 case Token.OP_XOR_ASSIGN:
6255 case Token.OP_OR_ASSIGN:
6256 return "<operator>";
6277 case Token.OP_GENERICS_LT:
6278 case Token.GENERIC_DIMENSION:
6280 case Token.OP_GENERICS_GT:
6283 case Token.INTERR_NULLABLE:
6285 case Token.DOUBLE_COLON:
6287 case Token.LITERAL_FLOAT:
6288 case Token.LITERAL_INTEGER:
6289 case Token.LITERAL_DOUBLE:
6290 case Token.LITERAL_DECIMAL:
6291 case Token.LITERAL_CHARACTER:
6292 case Token.LITERAL_STRING:
6294 case Token.IDENTIFIER:
6295 return "identifier";
6297 // All of these are internal.
6300 case Token.FIRST_KEYWORD:
6302 case Token.EVAL_COMPILATION_UNIT_PARSER:
6303 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6304 case Token.EVAL_STATEMENT_PARSER:
6306 case Token.QUERY_LAST_TOKEN:
6307 case Token.QUERY_FIRST_TOKEN:
6308 case Token.LAST_KEYWORD:
6309 return "<internal>";
6311 // A bit more robust.
6313 return yyNames [token];