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 ParametersCompiled 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 ParametersCompiled 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 // Stack<ToplevelBlock>
136 Stack linq_clause_blocks;
138 // A counter to create new class names in interactive mode
139 static int class_count;
143 %token NONE /* This token is never returned by our lexer */
144 %token ERROR // This is used not by the parser, but by the tokenizer.
148 *These are the C# keywords
247 %token INTERR_NULLABLE
250 /* Generics <,> tokens */
251 %token OP_GENERICS_LT
252 %token OP_GENERICS_LT_DECL
253 %token OP_GENERICS_GT
255 /* C# keywords which are not really keywords */
261 /* C# single character operators/punctuation. */
289 /* C# multi-character operators. */
294 %token OP_SHIFT_RIGHT
301 %token OP_MULT_ASSIGN
306 %token OP_SHIFT_LEFT_ASSIGN
307 %token OP_SHIFT_RIGHT_ASSIGN
315 %token LITERAL_INTEGER
317 %token LITERAL_DOUBLE
318 %token LITERAL_DECIMAL
319 %token LITERAL_CHARACTER
320 %token LITERAL_STRING
323 %token OPEN_PARENS_LAMBDA
324 %token OPEN_PARENS_CAST
325 %token GENERIC_DIMENSION
328 // Make the parser go into eval mode parsing (statements and compilation units).
329 %token EVAL_STATEMENT_PARSER
330 %token EVAL_COMPILATION_UNIT_PARSER
331 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
334 // This token is generated to trigger the completion engine at this point
336 %token GENERATE_COMPLETION
339 // This token is return repeatedly after the first GENERATE_COMPLETION
340 // token is produced and before the final EOF
342 %token COMPLETE_COMPLETION
344 /* Add precedence rules to solve dangling else s/r conflict */
348 /* Define the operator tokens and their precedences */
356 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
358 %left STAR DIV PERCENT
359 %right BANG CARRET UMINUS
360 %nonassoc OP_INC OP_DEC
362 %left OPEN_BRACKET OPEN_BRACE
365 %start compilation_unit
369 : outer_declarations opt_EOF
370 | outer_declarations global_attributes opt_EOF
371 | global_attributes opt_EOF
372 | opt_EOF /* allow empty files */
373 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
379 Lexer.check_incorrect_doc_comment ();
383 Lexer.check_incorrect_doc_comment ();
389 | outer_declarations outer_declaration
393 : extern_alias_directive
395 | namespace_member_declaration
398 extern_alias_directives
399 : extern_alias_directive
400 | extern_alias_directives extern_alias_directive
403 extern_alias_directive
404 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
406 LocatedToken lt = (LocatedToken) $2;
409 syntax_error (lt.Location, "`alias' expected");
410 } else if (RootContext.Version == LanguageVersion.ISO_1) {
411 Report.FeatureIsNotAvailable (lt.Location, "external alias");
413 lt = (LocatedToken) $3;
414 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
419 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
425 | using_directives using_directive
429 : using_alias_directive
431 if (RootContext.Documentation != null)
432 Lexer.doc_state = XmlCommentState.Allowed;
434 | using_namespace_directive
436 if (RootContext.Documentation != null)
437 Lexer.doc_state = XmlCommentState.Allowed;
441 using_alias_directive
442 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
444 LocatedToken lt = (LocatedToken) $2;
445 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
448 CheckIdentifierToken (yyToken, GetLocation ($2));
453 using_namespace_directive
454 : USING namespace_name SEMICOLON
456 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
461 // Strictly speaking, namespaces don't have attributes but
462 // we parse global attributes along with namespace declarations and then
465 namespace_declaration
466 : opt_attributes NAMESPACE qualified_identifier
468 MemberName name = (MemberName) $3;
471 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
474 current_namespace = new NamespaceEntry (
475 current_namespace, file, name.GetName ());
476 current_class = current_namespace.SlaveDeclSpace;
477 current_container = current_class.PartialContainer;
479 namespace_body opt_semicolon
481 current_namespace = current_namespace.Parent;
482 current_class = current_namespace.SlaveDeclSpace;
483 current_container = current_class.PartialContainer;
490 LocatedToken lt = (LocatedToken) $1;
491 $$ = new MemberName (lt.Value, lt.Location);
493 | qualified_identifier DOT IDENTIFIER
495 LocatedToken lt = (LocatedToken) $3;
496 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
500 syntax_error (lexer.Location, "`.' expected");
515 : namespace_or_type_name
517 MemberName name = (MemberName) $1;
519 if (name.TypeArguments != null)
520 syntax_error (lexer.Location, "namespace name expected");
529 if (RootContext.Documentation != null)
530 Lexer.doc_state = XmlCommentState.Allowed;
536 : opt_extern_alias_directives
538 opt_namespace_member_declarations
542 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
545 | opt_extern_alias_directives
547 opt_namespace_member_declarations
550 Report.Error (1513, lexer.Location, "Expected `}'");
559 opt_extern_alias_directives
561 | extern_alias_directives
564 opt_namespace_member_declarations
566 | namespace_member_declarations
569 namespace_member_declarations
570 : namespace_member_declaration
571 | namespace_member_declarations namespace_member_declaration
574 namespace_member_declaration
578 DeclSpace ds = (DeclSpace)$1;
580 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
581 Report.Error (1527, ds.Location,
582 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
585 current_namespace.DeclarationFound = true;
587 | namespace_declaration {
588 current_namespace.DeclarationFound = true;
591 | field_declaration {
592 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
594 | method_declaration {
595 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
602 | interface_declaration
604 | delegate_declaration
606 // Enable this when we have handled all errors, because this acts as a generic fallback
609 // Console.WriteLine ("Token=" + yyToken);
610 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
622 Attributes attrs = (Attributes)$1;
623 if (global_attrs_enabled) {
624 CodeGen.Assembly.AddAttributes (attrs.Attrs);
626 foreach (Attribute a in attrs.Attrs) {
627 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
638 global_attrs_enabled = false;
643 global_attrs_enabled = false;
652 if (current_attr_target != String.Empty) {
653 ArrayList sect = (ArrayList) $1;
655 if (global_attrs_enabled) {
656 if (current_attr_target == "module") {
657 current_container.Module.AddAttributes (sect);
659 } else if (current_attr_target != null && current_attr_target.Length > 0) {
660 CodeGen.Assembly.AddAttributes (sect);
663 $$ = new Attributes (sect);
666 if (RootContext.Documentation != null) {
667 Lexer.check_incorrect_doc_comment ();
669 XmlCommentState.Allowed;
673 $$ = new Attributes (sect);
678 current_attr_target = null;
680 | attribute_sections attribute_section
682 if (current_attr_target != String.Empty) {
683 Attributes attrs = $1 as Attributes;
684 ArrayList sect = (ArrayList) $2;
686 if (global_attrs_enabled) {
687 if (current_attr_target == "module") {
688 current_container.Module.AddAttributes (sect);
690 } else if (current_attr_target == "assembly") {
691 CodeGen.Assembly.AddAttributes (sect);
695 attrs = new Attributes (sect);
697 attrs.AddAttributes (sect);
701 attrs = new Attributes (sect);
703 attrs.AddAttributes (sect);
709 current_attr_target = null;
714 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
718 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
724 attribute_target_specifier
725 : attribute_target COLON
727 current_attr_target = (string)$1;
735 LocatedToken lt = (LocatedToken) $1;
736 $$ = CheckAttributeTarget (lt.Value, lt.Location);
738 | EVENT { $$ = "event"; }
739 | RETURN { $$ = "return"; }
742 string name = GetTokenName (yyToken);
743 $$ = CheckAttributeTarget (name, GetLocation ($1));
750 ArrayList attrs = new ArrayList (4);
756 | attribute_list COMMA attribute
758 ArrayList attrs = (ArrayList) $1;
768 ++lexer.parsing_block;
770 opt_attribute_arguments
772 --lexer.parsing_block;
773 MemberName mname = (MemberName) $1;
774 if (mname.IsGeneric) {
775 Report.Error (404, lexer.Location,
776 "'<' unexpected: attributes cannot be generic");
779 object [] arguments = (object []) $3;
780 MemberName left = mname.Left;
781 string identifier = mname.Name;
783 Expression left_expr = left == null ? null : left.GetTypeExpression ();
785 if (current_attr_target == String.Empty)
787 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
788 // FIXME: supply "nameEscaped" parameter here.
789 $$ = new GlobalAttribute (current_namespace, current_attr_target,
790 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
792 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
797 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
800 opt_attribute_arguments
801 : /* empty */ { $$ = null; }
802 | OPEN_PARENS attribute_arguments CLOSE_PARENS
810 : opt_positional_argument_list
815 $$ = new object [] { $1, null };
818 | positional_argument_list COMMA named_argument_list
820 $$ = new object[] { $1, $3 };
822 | named_argument_list
824 $$ = new object [] { null, $1 };
829 opt_positional_argument_list
830 : /* empty */ { $$ = null; }
831 | positional_argument_list
834 positional_argument_list
837 ArrayList args = new ArrayList (4);
838 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
842 | positional_argument_list COMMA expression
844 ArrayList args = (ArrayList) $1;
845 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
854 ArrayList args = new ArrayList (4);
859 | named_argument_list COMMA named_argument
861 ArrayList args = (ArrayList) $1;
866 | named_argument_list COMMA expression
868 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
874 : IDENTIFIER ASSIGN expression
876 // FIXME: keep location
877 $$ = new DictionaryEntry (
878 ((LocatedToken) $1).Value,
879 new Argument ((Expression) $3, Argument.AType.Expression));
885 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
888 opt_class_member_declarations
890 | class_member_declarations
893 class_member_declarations
894 : class_member_declaration
895 | class_member_declarations
896 class_member_declaration
899 class_member_declaration
900 : constant_declaration // done
901 | field_declaration // done
902 | method_declaration // done
903 | property_declaration // done
904 | event_declaration // done
905 | indexer_declaration // done
906 | operator_declaration // done
907 | constructor_declaration // done
908 | destructor_declaration // done
912 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
913 GetSymbolName (yyToken));
915 lexer.parsing_generic_declaration = false;
925 lexer.ConstraintsParsing = true;
927 type_declaration_name
929 MemberName name = MakeName ((MemberName) $6);
930 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
933 opt_type_parameter_constraints_clauses
935 lexer.ConstraintsParsing = false;
937 current_class.SetParameterInfo ((ArrayList) $9);
939 if (RootContext.Documentation != null)
940 current_container.DocComment = Lexer.consume_doc_comment ();
944 --lexer.parsing_declaration;
945 if (RootContext.Documentation != null)
946 Lexer.doc_state = XmlCommentState.Allowed;
950 $$ = pop_current_class ();
952 | opt_attributes opt_modifiers opt_partial STRUCT error {
953 CheckIdentifierToken (yyToken, GetLocation ($5));
960 if (RootContext.Documentation != null)
961 Lexer.doc_state = XmlCommentState.Allowed;
963 opt_struct_member_declarations CLOSE_BRACE
966 opt_struct_member_declarations
968 | struct_member_declarations
971 struct_member_declarations
972 : struct_member_declaration
973 | struct_member_declarations struct_member_declaration
976 struct_member_declaration
977 : constant_declaration
980 | property_declaration
982 | indexer_declaration
983 | operator_declaration
984 | constructor_declaration
988 * This is only included so we can flag error 575:
989 * destructors only allowed on class types
991 | destructor_declaration
1002 int modflags = (int) $2;
1003 foreach (VariableDeclaration constant in (ArrayList) $5){
1004 Location l = constant.Location;
1005 if ((modflags & Modifiers.STATIC) != 0) {
1006 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
1010 Const c = new Const (
1011 current_class, (FullNamedExpression) $4, (string) constant.identifier,
1012 (Expression) constant.expression_or_array_initializer, modflags,
1013 (Attributes) $1, l);
1015 if (RootContext.Documentation != null) {
1016 c.DocComment = Lexer.consume_doc_comment ();
1017 Lexer.doc_state = XmlCommentState.Allowed;
1019 current_container.AddConstant (c);
1024 constant_declarators
1025 : constant_declarator
1027 ArrayList constants = new ArrayList (4);
1032 | constant_declarators COMMA constant_declarator
1035 ArrayList constants = (ArrayList) $1;
1044 ++lexer.parsing_block;
1046 constant_initializer
1048 --lexer.parsing_block;
1049 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1053 // A const field requires a value to be provided
1054 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1059 constant_initializer
1060 : constant_expression
1068 variable_declarators
1071 FullNamedExpression type = (FullNamedExpression) $3;
1072 if (type == TypeManager.system_void_expr)
1073 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1077 current_array_type = null;
1079 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1080 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1082 field.Initializer = var.expression_or_array_initializer;
1084 if (RootContext.Documentation != null) {
1085 field.DocComment = Lexer.consume_doc_comment ();
1086 Lexer.doc_state = XmlCommentState.Allowed;
1088 current_container.AddField (field);
1089 $$ = field; // FIXME: might be better if it points to the top item
1096 fixed_variable_declarators
1099 FullNamedExpression type = (FullNamedExpression) $4;
1103 current_array_type = null;
1105 foreach (VariableDeclaration var in (ArrayList) $5) {
1106 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1107 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1109 if (RootContext.Documentation != null) {
1110 field.DocComment = Lexer.consume_doc_comment ();
1111 Lexer.doc_state = XmlCommentState.Allowed;
1113 current_container.AddField (field);
1114 $$ = field; // FIXME: might be better if it points to the top item
1123 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1127 fixed_variable_declarators
1128 : fixed_variable_declarator
1130 ArrayList decl = new ArrayList (2);
1134 | fixed_variable_declarators COMMA fixed_variable_declarator
1136 ArrayList decls = (ArrayList) $1;
1142 fixed_variable_declarator
1143 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1145 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1147 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1149 Report.Error (443, lexer.Location, "Value or constant expected");
1150 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1155 local_variable_declarators
1156 : local_variable_declarator
1158 ArrayList decl = new ArrayList (4);
1163 | local_variable_declarators COMMA local_variable_declarator
1165 ArrayList decls = (ArrayList) $1;
1171 local_variable_declarator
1172 : IDENTIFIER ASSIGN local_variable_initializer
1174 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1178 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1180 | IDENTIFIER variable_bad_array
1186 local_variable_initializer
1189 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1191 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1195 $$ = new ArglistAccess ((Location) $1);
1197 | STACKALLOC simple_type
1199 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1200 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1204 variable_declarators
1205 : variable_declarator
1207 ArrayList decl = new ArrayList (4);
1212 | variable_declarators COMMA variable_declarator
1214 ArrayList decls = (ArrayList) $1;
1221 : member_declaration_name ASSIGN
1223 ++lexer.parsing_block;
1224 lexer.parsing_generic_declaration = false;
1226 variable_initializer
1228 --lexer.parsing_block;
1229 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1231 | member_declaration_name
1233 lexer.parsing_generic_declaration = false;
1234 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1236 | member_declaration_name variable_bad_array
1238 lexer.parsing_generic_declaration = false;
1244 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1246 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1247 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1251 variable_initializer
1258 if (RootContext.Documentation != null)
1259 Lexer.doc_state = XmlCommentState.NotAllowed;
1263 Method method = (Method) $1;
1264 method.Block = (ToplevelBlock) $3;
1265 current_container.AddMethod (method);
1267 if (current_container.Kind == Kind.Interface && method.Block != null) {
1268 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1271 current_generic_method = null;
1272 current_local_parameters = null;
1274 if (RootContext.Documentation != null)
1275 Lexer.doc_state = XmlCommentState.Allowed;
1283 method_declaration_name OPEN_PARENS
1285 arglist_allowed = true;
1287 opt_formal_parameter_list CLOSE_PARENS
1289 lexer.ConstraintsParsing = true;
1291 opt_type_parameter_constraints_clauses
1293 lexer.ConstraintsParsing = false;
1294 arglist_allowed = false;
1295 MemberName name = (MemberName) $4;
1296 current_local_parameters = (ParametersCompiled) $7;
1298 if ($10 != null && name.TypeArguments == null)
1299 Report.Error (80, lexer.Location,
1300 "Constraints are not allowed on non-generic declarations");
1304 GenericMethod generic = null;
1305 if (name.TypeArguments != null) {
1306 generic = new GenericMethod (current_namespace, current_class, name,
1307 (FullNamedExpression) $3, current_local_parameters);
1309 generic.SetParameterInfo ((ArrayList) $10);
1312 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1313 name, current_local_parameters, (Attributes) $1);
1315 current_generic_method = generic;
1317 if (RootContext.Documentation != null)
1318 method.DocComment = Lexer.consume_doc_comment ();
1325 VOID method_declaration_name
1326 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1328 lexer.ConstraintsParsing = true;
1330 opt_type_parameter_constraints_clauses
1332 lexer.ConstraintsParsing = false;
1334 MemberName name = (MemberName) $5;
1335 current_local_parameters = (ParametersCompiled) $7;
1337 if ($9 != null && name.TypeArguments == null)
1338 Report.Error (80, lexer.Location,
1339 "Constraints are not allowed on non-generic declarations");
1342 GenericMethod generic = null;
1343 if (name.TypeArguments != null) {
1344 generic = new GenericMethod (current_namespace, current_class, name,
1345 TypeManager.system_void_expr, current_local_parameters);
1347 generic.SetParameterInfo ((ArrayList) $10);
1350 int modifiers = (int) $2;
1353 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1354 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1356 if ((modifiers & invalid_partial_mod) != 0) {
1357 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1358 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1359 modifiers &= ~invalid_partial_mod;
1362 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1363 Report.Error (751, name.Location, "A partial method must be declared within a " +
1364 "partial class or partial struct");
1367 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1369 method = new Method (current_class, generic, TypeManager.system_void_expr,
1370 modifiers, name, current_local_parameters, (Attributes) $1);
1372 current_generic_method = generic;
1374 if (RootContext.Documentation != null)
1375 method.DocComment = Lexer.consume_doc_comment ();
1382 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1384 MemberName name = (MemberName) $5;
1385 Report.Error (1585, name.Location,
1386 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1388 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1389 0, name, (ParametersCompiled) $7, (Attributes) $1);
1391 current_local_parameters = (ParametersCompiled) $7;
1393 if (RootContext.Documentation != null)
1394 method.DocComment = Lexer.consume_doc_comment ();
1402 | SEMICOLON { $$ = null; }
1405 opt_formal_parameter_list
1406 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1407 | formal_parameter_list
1410 opt_parameter_list_no_mod
1411 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1414 parameter_modifiers_not_allowed = true;
1416 formal_parameter_list
1418 parameter_modifiers_not_allowed = false;
1423 formal_parameter_list
1426 ArrayList pars_list = (ArrayList) $1;
1428 Parameter [] pars = new Parameter [pars_list.Count];
1429 pars_list.CopyTo (pars);
1431 $$ = new ParametersCompiled (pars);
1433 | fixed_parameters COMMA parameter_array
1435 ArrayList pars_list = (ArrayList) $1;
1438 Parameter [] pars = new Parameter [pars_list.Count];
1439 pars_list.CopyTo (pars);
1441 $$ = new ParametersCompiled (pars);
1443 | fixed_parameters COMMA arglist_modifier
1445 ArrayList pars_list = (ArrayList) $1;
1446 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1448 Parameter [] pars = new Parameter [pars_list.Count];
1449 pars_list.CopyTo (pars);
1451 $$ = new ParametersCompiled (pars, true);
1453 | parameter_array COMMA error
1456 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1459 | fixed_parameters COMMA parameter_array COMMA error
1462 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1465 | arglist_modifier COMMA error
1467 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1470 | fixed_parameters COMMA ARGLIST COMMA error
1472 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1477 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1481 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1488 ArrayList pars = new ArrayList (4);
1493 | fixed_parameters COMMA fixed_parameter
1495 ArrayList pars = (ArrayList) $1;
1496 Parameter p = (Parameter)$3;
1498 if (p.HasExtensionMethodModifier)
1499 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1508 opt_parameter_modifier
1512 LocatedToken lt = (LocatedToken) $4;
1513 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1516 opt_parameter_modifier
1518 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1520 LocatedToken lt = (LocatedToken) $4;
1521 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1525 opt_parameter_modifier
1528 Report.Error (1001, GetLocation ($3), "Identifier expected");
1529 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
1532 opt_parameter_modifier
1535 CheckIdentifierToken (yyToken, GetLocation ($4));
1539 opt_parameter_modifier
1545 LocatedToken lt = (LocatedToken) $4;
1546 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1551 opt_parameter_modifier
1552 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1553 | parameter_modifiers
1557 : parameter_modifier
1561 | parameter_modifiers parameter_modifier
1563 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1564 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1565 if (((Parameter.Modifier)$1 & p2) == p2) {
1566 Error_DuplicateParameterModifier (lexer.Location, p2);
1568 switch (mod & ~Parameter.Modifier.This) {
1569 case Parameter.Modifier.REF:
1570 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1572 case Parameter.Modifier.OUT:
1573 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1576 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1587 if (parameter_modifiers_not_allowed)
1588 Error_ParameterModifierNotValid ("ref", (Location)$1);
1590 $$ = Parameter.Modifier.REF;
1594 if (parameter_modifiers_not_allowed)
1595 Error_ParameterModifierNotValid ("out", (Location)$1);
1597 $$ = Parameter.Modifier.OUT;
1601 if (parameter_modifiers_not_allowed)
1602 Error_ParameterModifierNotValid ("this", (Location)$1);
1604 if (RootContext.Version <= LanguageVersion.ISO_2)
1605 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1607 $$ = Parameter.Modifier.This;
1612 : opt_attributes params_modifier type IDENTIFIER
1614 LocatedToken lt = (LocatedToken) $4;
1615 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1617 | opt_attributes params_modifier type error {
1618 CheckIdentifierToken (yyToken, GetLocation ($4));
1626 if (params_modifiers_not_allowed)
1627 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1629 | PARAMS parameter_modifier
1631 Parameter.Modifier mod = (Parameter.Modifier)$2;
1632 if ((mod & Parameter.Modifier.This) != 0) {
1633 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1635 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1638 | PARAMS params_modifier
1640 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1647 if (!arglist_allowed)
1648 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1652 property_declaration
1656 member_declaration_name
1658 if (RootContext.Documentation != null)
1659 tmpComment = Lexer.consume_doc_comment ();
1663 implicit_value_parameter_type = (FullNamedExpression) $3;
1664 lexer.PropertyParsing = true;
1666 accessor_declarations
1668 lexer.PropertyParsing = false;
1669 has_get = has_set = false;
1674 Accessors accessors = (Accessors) $8;
1675 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1676 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1677 bool order = accessors != null ? accessors.declared_in_reverse : false;
1679 MemberName name = (MemberName) $4;
1680 FullNamedExpression ptype = (FullNamedExpression) $3;
1682 prop = new Property (current_class, ptype, (int) $2,
1683 name, (Attributes) $1, get_block, set_block, order, current_block);
1685 if (ptype == TypeManager.system_void_expr)
1686 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1688 if (accessors == null)
1689 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1691 if (current_container.Kind == Kind.Interface) {
1692 if (prop.Get.Block != null)
1693 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1695 if (prop.Set.Block != null)
1696 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1699 current_container.AddProperty (prop);
1700 implicit_value_parameter_type = null;
1702 if (RootContext.Documentation != null)
1703 prop.DocComment = ConsumeStoredComment ();
1708 accessor_declarations
1709 : get_accessor_declaration
1711 $$ = new Accessors ((Accessor) $1, null);
1713 | get_accessor_declaration accessor_declarations
1715 Accessors accessors = (Accessors) $2;
1716 accessors.get_or_add = (Accessor) $1;
1719 | set_accessor_declaration
1721 $$ = new Accessors (null, (Accessor) $1);
1723 | set_accessor_declaration accessor_declarations
1725 Accessors accessors = (Accessors) $2;
1726 accessors.set_or_remove = (Accessor) $1;
1727 accessors.declared_in_reverse = true;
1732 if (yyToken == Token.CLOSE_BRACE) {
1735 if (yyToken == Token.SEMICOLON)
1736 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1738 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1740 $$ = new Accessors (null, null);
1745 get_accessor_declaration
1746 : opt_attributes opt_modifiers GET
1748 // If this is not the case, then current_local_parameters has already
1749 // been set in indexer_declaration
1750 if (parsing_indexer == false)
1751 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1753 current_local_parameters = indexer_parameters;
1754 lexer.PropertyParsing = false;
1759 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1762 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1764 current_local_parameters = null;
1765 lexer.PropertyParsing = true;
1767 if (RootContext.Documentation != null)
1768 if (Lexer.doc_state == XmlCommentState.Error)
1769 Lexer.doc_state = XmlCommentState.NotAllowed;
1775 set_accessor_declaration
1776 : opt_attributes opt_modifiers SET
1778 Parameter implicit_value_parameter = new Parameter (
1779 implicit_value_parameter_type, "value",
1780 Parameter.Modifier.NONE, null, (Location) $3);
1782 if (!parsing_indexer) {
1783 current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter });
1785 current_local_parameters = ParametersCompiled.MergeGenerated (
1786 indexer_parameters, true, implicit_value_parameter, null);
1789 lexer.PropertyParsing = false;
1794 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1797 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1799 current_local_parameters = null;
1800 lexer.PropertyParsing = true;
1802 if (RootContext.Documentation != null
1803 && Lexer.doc_state == XmlCommentState.Error)
1804 Lexer.doc_state = XmlCommentState.NotAllowed;
1818 Error_SyntaxError (1043, yyToken);
1823 interface_declaration
1829 lexer.ConstraintsParsing = true;
1831 type_declaration_name
1833 MemberName name = MakeName ((MemberName) $6);
1834 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1837 opt_type_parameter_constraints_clauses
1839 lexer.ConstraintsParsing = false;
1841 current_class.SetParameterInfo ((ArrayList) $9);
1843 if (RootContext.Documentation != null) {
1844 current_container.DocComment = Lexer.consume_doc_comment ();
1845 Lexer.doc_state = XmlCommentState.Allowed;
1850 --lexer.parsing_declaration;
1851 if (RootContext.Documentation != null)
1852 Lexer.doc_state = XmlCommentState.Allowed;
1856 $$ = pop_current_class ();
1858 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1859 CheckIdentifierToken (yyToken, GetLocation ($5));
1865 opt_interface_member_declarations
1869 opt_interface_member_declarations
1871 | interface_member_declarations
1874 interface_member_declarations
1875 : interface_member_declaration
1876 | interface_member_declarations interface_member_declaration
1879 interface_member_declaration
1880 : constant_declaration
1882 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1886 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1888 | method_declaration
1889 | property_declaration
1891 | indexer_declaration
1892 | operator_declaration
1894 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1896 | constructor_declaration
1898 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1902 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1906 operator_declaration
1907 : opt_attributes opt_modifiers operator_declarator
1915 OperatorDeclaration decl = (OperatorDeclaration) $3;
1916 Operator op = new Operator (
1917 current_class, decl.optype, decl.ret_type, (int) $2,
1918 current_local_parameters,
1919 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1921 if (RootContext.Documentation != null) {
1922 op.DocComment = tmpComment;
1923 Lexer.doc_state = XmlCommentState.Allowed;
1926 // Note again, checking is done in semantic analysis
1927 current_container.AddOperator (op);
1929 current_local_parameters = null;
1935 | SEMICOLON { $$ = null; }
1939 : type_expression_or_array
1942 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1943 $$ = TypeManager.system_void_expr;
1948 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1950 params_modifiers_not_allowed = true;
1952 opt_parameter_list_no_mod CLOSE_PARENS
1954 params_modifiers_not_allowed = false;
1956 Location loc = (Location) $2;
1957 Operator.OpType op = (Operator.OpType) $3;
1958 current_local_parameters = (ParametersCompiled)$6;
1960 int p_count = current_local_parameters.Count;
1962 if (op == Operator.OpType.Addition)
1963 op = Operator.OpType.UnaryPlus;
1964 else if (op == Operator.OpType.Subtraction)
1965 op = Operator.OpType.UnaryNegation;
1968 if (IsUnaryOperator (op)) {
1970 Report.Error (1020, loc, "Overloadable binary operator expected");
1971 } else if (p_count != 1) {
1972 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1973 Operator.GetName (op));
1977 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1978 Operator.GetName (op));
1979 } else if (p_count != 2) {
1980 Report.Error (1019, loc, "Overloadable unary operator expected");
1984 if (RootContext.Documentation != null) {
1985 tmpComment = Lexer.consume_doc_comment ();
1986 Lexer.doc_state = XmlCommentState.NotAllowed;
1989 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
1991 | conversion_operator_declarator
1994 overloadable_operator
1996 : BANG { $$ = Operator.OpType.LogicalNot; }
1997 | TILDE { $$ = Operator.OpType.OnesComplement; }
1998 | OP_INC { $$ = Operator.OpType.Increment; }
1999 | OP_DEC { $$ = Operator.OpType.Decrement; }
2000 | TRUE { $$ = Operator.OpType.True; }
2001 | FALSE { $$ = Operator.OpType.False; }
2002 // Unary and binary:
2003 | PLUS { $$ = Operator.OpType.Addition; }
2004 | MINUS { $$ = Operator.OpType.Subtraction; }
2006 | STAR { $$ = Operator.OpType.Multiply; }
2007 | DIV { $$ = Operator.OpType.Division; }
2008 | PERCENT { $$ = Operator.OpType.Modulus; }
2009 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2010 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2011 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2012 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2013 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2014 | OP_EQ { $$ = Operator.OpType.Equality; }
2015 | OP_NE { $$ = Operator.OpType.Inequality; }
2016 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2017 | OP_LT { $$ = Operator.OpType.LessThan; }
2018 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2019 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2022 conversion_operator_declarator
2023 : IMPLICIT OPERATOR type OPEN_PARENS
2025 params_modifiers_not_allowed = true;
2027 opt_parameter_list_no_mod CLOSE_PARENS
2029 params_modifiers_not_allowed = false;
2031 Location loc = (Location) $2;
2032 current_local_parameters = (ParametersCompiled)$6;
2034 if (RootContext.Documentation != null) {
2035 tmpComment = Lexer.consume_doc_comment ();
2036 Lexer.doc_state = XmlCommentState.NotAllowed;
2039 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2041 | EXPLICIT OPERATOR type OPEN_PARENS
2043 params_modifiers_not_allowed = true;
2045 opt_parameter_list_no_mod CLOSE_PARENS
2047 params_modifiers_not_allowed = false;
2049 Location loc = (Location) $2;
2050 current_local_parameters = (ParametersCompiled)$6;
2052 if (RootContext.Documentation != null) {
2053 tmpComment = Lexer.consume_doc_comment ();
2054 Lexer.doc_state = XmlCommentState.NotAllowed;
2057 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2061 Error_SyntaxError (yyToken);
2062 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2066 Error_SyntaxError (yyToken);
2067 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2071 constructor_declaration
2072 : constructor_declarator
2075 Constructor c = (Constructor) $1;
2076 c.Block = (ToplevelBlock) $2;
2078 if (RootContext.Documentation != null)
2079 c.DocComment = ConsumeStoredComment ();
2081 current_container.AddConstructor (c);
2083 current_local_parameters = null;
2084 if (RootContext.Documentation != null)
2085 Lexer.doc_state = XmlCommentState.Allowed;
2089 constructor_declarator
2094 if (RootContext.Documentation != null) {
2095 tmpComment = Lexer.consume_doc_comment ();
2096 Lexer.doc_state = XmlCommentState.Allowed;
2099 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2101 current_local_parameters = (ParametersCompiled) $6;
2104 // start block here, so possible anonymous methods inside
2105 // constructor initializer can get correct parent block
2107 start_block (lexer.Location);
2109 opt_constructor_initializer
2111 LocatedToken lt = (LocatedToken) $3;
2112 int mods = (int) $2;
2113 ConstructorInitializer ci = (ConstructorInitializer) $9;
2115 Constructor c = new Constructor (current_class, lt.Value, mods,
2116 (Attributes) $1, current_local_parameters, ci, lt.Location);
2118 if (lt.Value != current_container.MemberName.Name) {
2119 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2120 } else if ((mods & Modifiers.STATIC) != 0) {
2121 if ((mods & Modifiers.Accessibility) != 0){
2122 Report.Error (515, c.Location,
2123 "`{0}': static constructor cannot have an access modifier",
2124 c.GetSignatureForError ());
2127 Report.Error (514, c.Location,
2128 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2129 c.GetSignatureForError ());
2140 | SEMICOLON { current_block = null; $$ = null; }
2143 opt_constructor_initializer
2145 | constructor_initializer
2148 constructor_initializer
2149 : COLON BASE OPEN_PARENS
2151 ++lexer.parsing_block;
2153 opt_argument_list CLOSE_PARENS
2155 --lexer.parsing_block;
2156 $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
2158 | COLON THIS OPEN_PARENS
2160 ++lexer.parsing_block;
2162 opt_argument_list CLOSE_PARENS
2164 --lexer.parsing_block;
2165 $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
2168 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2173 destructor_declaration
2174 : opt_attributes opt_modifiers TILDE
2176 if (RootContext.Documentation != null) {
2177 tmpComment = Lexer.consume_doc_comment ();
2178 Lexer.doc_state = XmlCommentState.NotAllowed;
2181 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2183 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2185 LocatedToken lt = (LocatedToken) $5;
2186 if (lt.Value != current_container.MemberName.Name){
2187 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2188 } else if (current_container.Kind != Kind.Class){
2189 Report.Error (575, lt.Location, "Only class types can contain destructor");
2191 Destructor d = new Destructor (current_class, (int) $2,
2192 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2193 if (RootContext.Documentation != null)
2194 d.DocComment = ConsumeStoredComment ();
2196 d.Block = (ToplevelBlock) $8;
2197 current_container.AddMethod (d);
2200 current_local_parameters = null;
2207 EVENT type variable_declarators SEMICOLON
2209 current_array_type = null;
2210 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2212 EventField e = new EventField (
2213 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2215 if (var.expression_or_array_initializer != null) {
2216 if (current_container.Kind == Kind.Interface) {
2217 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2220 e.Initializer = var.expression_or_array_initializer;
2223 if (var.MemberName.Left != null) {
2224 Report.Error (71, e.Location,
2225 "`{0}': An explicit interface implementation of an event must use property syntax",
2226 e.GetSignatureForError ());
2229 current_container.AddEvent (e);
2231 if (RootContext.Documentation != null) {
2232 e.DocComment = Lexer.consume_doc_comment ();
2233 Lexer.doc_state = XmlCommentState.Allowed;
2239 EVENT type member_declaration_name
2242 implicit_value_parameter_type = (FullNamedExpression) $4;
2243 current_local_parameters = new ParametersCompiled (
2244 new Parameter (implicit_value_parameter_type, "value",
2245 Parameter.Modifier.NONE, null, GetLocation ($3)));
2247 lexer.EventParsing = true;
2249 event_accessor_declarations
2251 lexer.EventParsing = false;
2255 MemberName name = (MemberName) $5;
2257 if (current_container.Kind == Kind.Interface) {
2258 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2262 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2263 current_container.Name, name.GetSignatureForError ());
2266 Accessors accessors = (Accessors) $8;
2268 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2269 // CS0073 is already reported, so no CS0065 here.
2272 Event e = new EventProperty (
2273 current_class, (FullNamedExpression) $4, (int) $2, name,
2274 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2275 if (RootContext.Documentation != null) {
2276 e.DocComment = Lexer.consume_doc_comment ();
2277 Lexer.doc_state = XmlCommentState.Allowed;
2280 current_container.AddEvent (e);
2281 implicit_value_parameter_type = null;
2284 current_local_parameters = null;
2286 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2288 MemberName mn = (MemberName) $5;
2289 if (mn.Left != null)
2290 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2292 if (RootContext.Documentation != null)
2293 Lexer.doc_state = XmlCommentState.Allowed;
2295 Error_SyntaxError (yyToken);
2300 event_accessor_declarations
2301 : add_accessor_declaration remove_accessor_declaration
2303 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2305 | remove_accessor_declaration add_accessor_declaration
2307 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2308 accessors.declared_in_reverse = true;
2311 | add_accessor_declaration { $$ = null; }
2312 | remove_accessor_declaration { $$ = null; }
2315 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2321 add_accessor_declaration
2322 : opt_attributes ADD
2324 lexer.EventParsing = false;
2328 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2329 lexer.EventParsing = true;
2332 | opt_attributes ADD error {
2333 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2336 | opt_attributes modifiers ADD {
2337 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2342 remove_accessor_declaration
2343 : opt_attributes REMOVE
2345 lexer.EventParsing = false;
2349 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2350 lexer.EventParsing = true;
2352 | opt_attributes REMOVE error {
2353 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2356 | opt_attributes modifiers REMOVE {
2357 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2363 : opt_attributes opt_modifiers
2364 member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2367 implicit_value_parameter_type = (FullNamedExpression) $3;
2368 indexer_parameters = (ParametersCompiled) $6;
2370 if (indexer_parameters.IsEmpty)
2371 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2373 if (RootContext.Documentation != null) {
2374 tmpComment = Lexer.consume_doc_comment ();
2375 Lexer.doc_state = XmlCommentState.Allowed;
2378 lexer.PropertyParsing = true;
2379 parsing_indexer = true;
2382 accessor_declarations
2384 lexer.PropertyParsing = false;
2385 has_get = has_set = false;
2386 parsing_indexer = false;
2390 Accessors accessors = (Accessors) $10;
2391 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2392 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2393 bool order = accessors != null ? accessors.declared_in_reverse : false;
2395 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2396 (MemberName)$4, (int) $2, (ParametersCompiled) $6, (Attributes) $1,
2397 get_block, set_block, order);
2399 if ($3 == TypeManager.system_void_expr)
2400 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2402 if (accessors == null)
2403 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2405 if (current_container.Kind == Kind.Interface) {
2406 if (indexer.Get.Block != null)
2407 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2409 if (indexer.Set.Block != null)
2410 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2413 if (RootContext.Documentation != null)
2414 indexer.DocComment = ConsumeStoredComment ();
2416 current_container.AddIndexer (indexer);
2418 current_local_parameters = null;
2419 implicit_value_parameter_type = null;
2420 indexer_parameters = null;
2427 ENUM type_declaration_name
2429 if (RootContext.Documentation != null)
2430 enumTypeComment = Lexer.consume_doc_comment ();
2435 MemberName name = (MemberName) $4;
2436 if (name.IsGeneric) {
2437 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2440 name = MakeName (name);
2441 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2442 name, (Attributes) $1);
2444 if (RootContext.Documentation != null)
2445 e.DocComment = enumTypeComment;
2448 EnumMember em = null;
2449 foreach (VariableDeclaration ev in (ArrayList) $7) {
2450 em = new EnumMember (
2451 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2452 ev.OptAttributes, ev.Location);
2454 // if (RootContext.Documentation != null)
2455 em.DocComment = ev.DocComment;
2457 e.AddEnumMember (em);
2459 if (RootContext.EvalMode)
2460 undo.AddTypeContainer (current_container, e);
2462 current_container.AddTypeContainer (e);
2470 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2473 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2474 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2475 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2476 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2477 Enum.Error_1008 (GetLocation ($2));
2483 Error_TypeExpected (lexer.Location);
2490 if (RootContext.Documentation != null)
2491 Lexer.doc_state = XmlCommentState.Allowed;
2493 opt_enum_member_declarations
2495 // here will be evaluated after CLOSE_BLACE is consumed.
2496 if (RootContext.Documentation != null)
2497 Lexer.doc_state = XmlCommentState.Allowed;
2505 opt_enum_member_declarations
2506 : /* empty */ { $$ = new ArrayList (4); }
2507 | enum_member_declarations opt_comma { $$ = $1; }
2510 enum_member_declarations
2511 : enum_member_declaration
2513 ArrayList l = new ArrayList (4);
2518 | enum_member_declarations COMMA enum_member_declaration
2520 ArrayList l = (ArrayList) $1;
2528 enum_member_declaration
2529 : opt_attributes IDENTIFIER
2531 VariableDeclaration vd = new VariableDeclaration (
2532 (LocatedToken) $2, null, (Attributes) $1);
2534 if (RootContext.Documentation != null) {
2535 vd.DocComment = Lexer.consume_doc_comment ();
2536 Lexer.doc_state = XmlCommentState.Allowed;
2541 | opt_attributes IDENTIFIER
2543 ++lexer.parsing_block;
2544 if (RootContext.Documentation != null) {
2545 tmpComment = Lexer.consume_doc_comment ();
2546 Lexer.doc_state = XmlCommentState.NotAllowed;
2549 ASSIGN constant_expression
2551 --lexer.parsing_block;
2552 VariableDeclaration vd = new VariableDeclaration (
2553 (LocatedToken) $2, $5, (Attributes) $1);
2555 if (RootContext.Documentation != null)
2556 vd.DocComment = ConsumeStoredComment ();
2562 delegate_declaration
2566 member_type type_declaration_name
2567 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2569 MemberName name = MakeName ((MemberName) $5);
2570 ParametersCompiled p = (ParametersCompiled) $7;
2572 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2573 (int) $2, name, p, (Attributes) $1);
2575 if (RootContext.Documentation != null) {
2576 del.DocComment = Lexer.consume_doc_comment ();
2577 Lexer.doc_state = XmlCommentState.Allowed;
2580 current_container.AddDelegate (del);
2581 current_delegate = del;
2582 lexer.ConstraintsParsing = true;
2584 opt_type_parameter_constraints_clauses
2586 lexer.ConstraintsParsing = false;
2590 current_delegate.SetParameterInfo ((ArrayList) $10);
2591 $$ = current_delegate;
2593 current_delegate = null;
2604 if (RootContext.Version < LanguageVersion.ISO_2)
2605 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2611 namespace_or_type_name
2613 | qualified_alias_member IDENTIFIER opt_type_argument_list
2615 LocatedToken lt1 = (LocatedToken) $1;
2616 LocatedToken lt2 = (LocatedToken) $2;
2618 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2624 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2626 LocatedToken lt = (LocatedToken) $3;
2627 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2632 : IDENTIFIER opt_type_argument_list
2634 LocatedToken lt = (LocatedToken) $1;
2635 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2640 // Generics arguments (any type, without attributes)
2642 opt_type_argument_list
2643 : /* empty */ { $$ = null; }
2644 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2646 if (RootContext.Version < LanguageVersion.ISO_2)
2647 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2651 | OP_GENERICS_LT error
2653 Error_TypeExpected (lexer.Location);
2654 $$ = new TypeArguments ();
2661 TypeArguments type_args = new TypeArguments ();
2662 type_args.Add ((FullNamedExpression) $1);
2665 | type_arguments COMMA type
2667 TypeArguments type_args = (TypeArguments) $1;
2668 type_args.Add ((FullNamedExpression) $3);
2674 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2676 type_declaration_name
2679 lexer.parsing_generic_declaration = true;
2681 opt_type_parameter_list
2683 lexer.parsing_generic_declaration = false;
2684 LocatedToken lt = (LocatedToken) $1;
2685 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2689 member_declaration_name
2690 : method_declaration_name
2692 MemberName mn = (MemberName)$1;
2693 if (mn.TypeArguments != null)
2694 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2695 mn.GetSignatureForError ()));
2699 method_declaration_name
2700 : type_declaration_name
2701 | explicit_interface IDENTIFIER opt_type_parameter_list
2703 lexer.parsing_generic_declaration = false;
2704 LocatedToken lt = (LocatedToken) $2;
2705 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2709 indexer_declaration_name
2712 lexer.parsing_generic_declaration = false;
2713 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2715 | explicit_interface THIS
2717 lexer.parsing_generic_declaration = false;
2718 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2723 : IDENTIFIER opt_type_argument_list DOT
2725 LocatedToken lt = (LocatedToken) $1;
2726 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2728 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2730 LocatedToken lt1 = (LocatedToken) $1;
2731 LocatedToken lt2 = (LocatedToken) $2;
2733 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2735 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2737 LocatedToken lt = (LocatedToken) $2;
2738 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2742 opt_type_parameter_list
2743 : /* empty */ { $$ = null; }
2744 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2746 if (RootContext.Version < LanguageVersion.ISO_2)
2747 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2756 TypeArguments type_args = new TypeArguments ();
2757 type_args.Add ((FullNamedExpression)$1);
2760 | type_parameters COMMA type_parameter
2762 TypeArguments type_args = (TypeArguments) $1;
2763 type_args.Add ((FullNamedExpression)$3);
2769 : opt_attributes opt_type_parameter_variance IDENTIFIER
2771 LocatedToken lt = (LocatedToken)$3;
2772 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2776 if (GetTokenName (yyToken) == "type")
2777 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2779 Error_SyntaxError (yyToken);
2781 $$ = new TypeParameterName ("", null, lexer.Location);
2786 // All types where void is allowed
2789 : type_expression_or_array
2792 $$ = TypeManager.system_void_expr;
2799 lexer.parsing_generic_declaration = true;
2804 // A type which does not allow `void' to be used
2807 : type_expression_or_array
2810 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2811 $$ = TypeManager.system_void_expr;
2819 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2820 $$ = TypeManager.system_void_expr;
2824 type_expression_or_array
2826 | type_expression rank_specifiers
2828 string rank_specifiers = (string) $2;
2829 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2834 : namespace_or_type_name opt_nullable
2836 MemberName name = (MemberName) $1;
2839 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2841 if (name.Left == null && name.Name == "var" &&
2842 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
2843 $$ = current_array_type = new VarExpr (name.Location);
2845 $$ = name.GetTypeExpression ();
2848 | builtin_types opt_nullable
2851 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2853 | type_expression STAR
2856 // Note that here only unmanaged types are allowed but we
2857 // can't perform checks during this phase - we do it during
2858 // semantic analysis.
2860 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2864 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2871 ArrayList types = new ArrayList (2);
2875 | type_list COMMA base_type_name
2877 ArrayList types = (ArrayList) $1;
2886 if ($1 is ComposedCast)
2887 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2892 Error_TypeExpected (lexer.Location);
2897 * replaces all the productions for isolating the various
2898 * simple types, but we need this to reuse it easily in variable_type
2901 : OBJECT { $$ = TypeManager.system_object_expr; }
2902 | STRING { $$ = TypeManager.system_string_expr; }
2903 | BOOL { $$ = TypeManager.system_boolean_expr; }
2904 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2905 | FLOAT { $$ = TypeManager.system_single_expr; }
2906 | DOUBLE { $$ = TypeManager.system_double_expr; }
2911 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2912 | BYTE { $$ = TypeManager.system_byte_expr; }
2913 | SHORT { $$ = TypeManager.system_int16_expr; }
2914 | USHORT { $$ = TypeManager.system_uint16_expr; }
2915 | INT { $$ = TypeManager.system_int32_expr; }
2916 | UINT { $$ = TypeManager.system_uint32_expr; }
2917 | LONG { $$ = TypeManager.system_int64_expr; }
2918 | ULONG { $$ = TypeManager.system_uint64_expr; }
2919 | CHAR { $$ = TypeManager.system_char_expr; }
2926 $$ = TypeManager.system_void_expr;
2931 // Expressions, section 7.5
2936 : primary_expression_no_array_creation
2937 | array_creation_expression
2940 primary_expression_no_array_creation
2942 | IDENTIFIER opt_type_argument_list
2944 LocatedToken lt = (LocatedToken) $1;
2945 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2947 | IDENTIFIER GENERATE_COMPLETION {
2948 LocatedToken lt = (LocatedToken) $1;
2949 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
2951 | parenthesized_expression
2952 | default_value_expression
2954 | invocation_expression
2958 | post_increment_expression
2959 | post_decrement_expression
2960 | object_or_delegate_creation_expression
2961 | anonymous_type_expression
2964 | checked_expression
2965 | unchecked_expression
2966 | pointer_member_access
2967 | anonymous_method_expression
2974 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2975 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2976 | NULL { $$ = new NullLiteral (lexer.Location); }
2980 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2981 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2982 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2987 object v = lexer.Value;
2990 $$ = new IntLiteral ((int) v, lexer.Location);
2991 } else if (v is uint)
2992 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2994 $$ = new LongLiteral ((Int64) v, lexer.Location);
2995 else if (v is ulong)
2996 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2998 Console.WriteLine ("OOPS. Unexpected result from scanner");
3003 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3004 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3009 // Here is the trick, tokenizer may think that parens is a special but
3010 // parser is interested in open parens only, so we merge them.
3011 // Consider: if (a)foo ();
3016 | OPEN_PARENS_LAMBDA
3019 parenthesized_expression
3020 : OPEN_PARENS expression CLOSE_PARENS
3022 $$ = new ParenthesizedExpression ((Expression) $2);
3024 | OPEN_PARENS expression COMPLETE_COMPLETION
3026 $$ = new ParenthesizedExpression ((Expression) $2);
3031 : primary_expression DOT IDENTIFIER opt_type_argument_list
3033 LocatedToken lt = (LocatedToken) $3;
3034 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3036 | predefined_type DOT IDENTIFIER opt_type_argument_list
3038 LocatedToken lt = (LocatedToken) $3;
3039 // TODO: Location is wrong as some predefined types doesn't hold a location
3040 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3042 | qualified_alias_member IDENTIFIER opt_type_argument_list
3044 LocatedToken lt1 = (LocatedToken) $1;
3045 LocatedToken lt2 = (LocatedToken) $2;
3047 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3049 | primary_expression DOT GENERATE_COMPLETION {
3050 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3052 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3053 LocatedToken lt = (LocatedToken) $3;
3054 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3056 | predefined_type DOT GENERATE_COMPLETION
3058 // TODO: Location is wrong as some predefined types doesn't hold a location
3059 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3061 | predefined_type DOT IDENTIFIER GENERATE_COMPLETION {
3062 LocatedToken lt = (LocatedToken) $3;
3063 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3067 invocation_expression
3068 : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3070 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3074 opt_object_or_collection_initializer
3075 : /* empty */ { $$ = null; }
3076 | object_or_collection_initializer
3079 object_or_collection_initializer
3080 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3083 $$ = CollectionOrObjectInitializers.Empty;
3085 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3087 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3089 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3093 opt_member_initializer_list
3094 : /* empty */ { $$ = null; }
3095 | member_initializer_list
3101 member_initializer_list
3102 : member_initializer
3104 ArrayList a = new ArrayList ();
3108 | member_initializer_list COMMA member_initializer
3110 ArrayList a = (ArrayList)$1;
3117 : IDENTIFIER ASSIGN initializer_value
3119 LocatedToken lt = $1 as LocatedToken;
3120 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3122 | GENERATE_COMPLETION
3124 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3126 | non_assignment_expression opt_COMPLETE_COMPLETION {
3127 CompletionSimpleName csn = $1 as CompletionSimpleName;
3129 $$ = new CollectionElementInitializer ((Expression)$1);
3131 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3133 | OPEN_BRACE expression_list CLOSE_BRACE
3135 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3137 | OPEN_BRACE CLOSE_BRACE
3139 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3145 | object_or_collection_initializer
3149 : /* empty */ { $$ = null; }
3156 ArrayList list = new ArrayList (4);
3160 | argument_list COMMA argument
3162 ArrayList list = (ArrayList) $1;
3166 | argument_list COMMA
3168 Report.Error (839, GetLocation ($2), "An argument is missing");
3173 Report.Error (839, GetLocation ($1), "An argument is missing");
3181 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3183 | non_simple_argument
3190 : REF variable_reference
3192 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3194 | OUT variable_reference
3196 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3198 | ARGLIST open_parens_any argument_list CLOSE_PARENS
3200 ArrayList list = (ArrayList) $3;
3201 Argument[] args = new Argument [list.Count];
3202 list.CopyTo (args, 0);
3204 Expression expr = new Arglist (args, (Location) $1);
3205 $$ = new Argument (expr, Argument.AType.Expression);
3207 | ARGLIST open_parens_any CLOSE_PARENS
3209 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3213 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3218 : expression { note ("section 5.4"); $$ = $1; }
3222 : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
3224 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3226 | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3228 // LAMESPEC: Not allowed according to specification
3229 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3231 | primary_expression_no_array_creation rank_specifiers
3233 // So the super-trick is that primary_expression
3234 // can only be either a SimpleName or a MemberAccess.
3235 // The MemberAccess case arises when you have a fully qualified type-name like :
3237 // SimpleName is when you have
3240 Expression expr = (Expression) $1;
3241 if (expr is ComposedCast){
3242 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3243 } else if (expr is ATypeNameExpression){
3245 // So we extract the string corresponding to the SimpleName
3248 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3250 Error_ExpectingTypeName (expr);
3251 $$ = TypeManager.system_object_expr;
3254 current_array_type = (FullNamedExpression)$$;
3261 ArrayList list = new ArrayList (4);
3265 | expression_list COMMA expression
3267 ArrayList list = (ArrayList) $1;
3276 $$ = new This (current_block, (Location) $1);
3281 : BASE DOT IDENTIFIER opt_type_argument_list
3283 LocatedToken lt = (LocatedToken) $3;
3284 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3286 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3288 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3291 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3296 post_increment_expression
3297 : primary_expression OP_INC
3299 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3303 post_decrement_expression
3304 : primary_expression OP_DEC
3306 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3310 object_or_delegate_creation_expression
3311 : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3314 if (RootContext.Version <= LanguageVersion.ISO_2)
3315 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3317 $$ = new NewInitialize ((Expression) $1, (ArrayList) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
3320 $$ = new New ((Expression) $1, (ArrayList) $3, GetLocation ($1));
3322 | new_expr_start object_or_collection_initializer
3324 if (RootContext.Version <= LanguageVersion.ISO_2)
3325 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3327 $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
3331 array_creation_expression
3332 : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET
3333 opt_rank_specifier // shift/reduce on OPEN_BRACE
3334 opt_array_initializer
3336 $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
3338 | new_expr_start rank_specifiers opt_array_initializer
3341 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3343 $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
3345 | NEW rank_specifiers array_initializer
3347 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
3349 | new_expr_start error
3351 Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
3359 ++lexer.parsing_type;
3363 --lexer.parsing_type;
3368 anonymous_type_expression
3369 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3371 if (RootContext.Version <= LanguageVersion.ISO_2)
3372 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3374 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3378 anonymous_type_parameters_opt_comma
3379 : anonymous_type_parameters_opt
3380 | anonymous_type_parameters COMMA
3383 anonymous_type_parameters_opt
3385 | anonymous_type_parameters
3388 anonymous_type_parameters
3389 : anonymous_type_parameter
3391 ArrayList a = new ArrayList (4);
3395 | anonymous_type_parameters COMMA anonymous_type_parameter
3397 ArrayList a = (ArrayList) $1;
3403 anonymous_type_parameter
3404 : IDENTIFIER ASSIGN variable_initializer
3406 LocatedToken lt = (LocatedToken)$1;
3407 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3411 LocatedToken lt = (LocatedToken)$1;
3412 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3413 lt.Value, lt.Location);
3415 | BASE DOT IDENTIFIER opt_type_argument_list
3417 LocatedToken lt = (LocatedToken) $3;
3418 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3419 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3423 MemberAccess ma = (MemberAccess) $1;
3424 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3428 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3429 "Anonymous type members must be a member assignment, simple name or member access expression");
3444 opt_rank_specifier_or_nullable
3452 | opt_nullable rank_specifiers
3455 $$ = "?" + (string) $2;
3463 | rank_specifier rank_specifiers
3465 $$ = (string) $2 + (string) $1;
3470 : OPEN_BRACKET CLOSE_BRACKET
3474 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3476 $$ = "[" + (string) $2 + "]";
3478 | OPEN_BRACKET error CLOSE_BRACKET
3480 ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
3490 | dim_separators COMMA
3492 $$ = (string) $1 + ",";
3496 opt_array_initializer
3508 : OPEN_BRACE CLOSE_BRACE
3510 ArrayList list = new ArrayList (4);
3513 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3515 $$ = (ArrayList) $2;
3519 variable_initializer_list
3520 : variable_initializer
3522 ArrayList list = new ArrayList (4);
3526 | variable_initializer_list COMMA variable_initializer
3528 ArrayList list = (ArrayList) $1;
3534 Error_SyntaxError (yyToken);
3535 $$ = new ArrayList ();
3542 pushed_current_array_type = current_array_type;
3543 lexer.TypeOfParsing = true;
3545 open_parens_any typeof_type_expression CLOSE_PARENS
3547 lexer.TypeOfParsing = false;
3548 Expression type = (Expression)$4;
3549 if (type == TypeManager.system_void_expr)
3550 $$ = new TypeOfVoid ((Location) $1);
3552 $$ = new TypeOf (type, (Location) $1);
3553 current_array_type = pushed_current_array_type;
3557 typeof_type_expression
3562 Error_TypeExpected (lexer.Location);
3568 : IDENTIFIER generic_dimension
3570 LocatedToken lt = (LocatedToken) $1;
3572 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3574 | qualified_alias_member IDENTIFIER generic_dimension
3576 LocatedToken lt1 = (LocatedToken) $1;
3577 LocatedToken lt2 = (LocatedToken) $2;
3579 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3581 | unbound_type_name DOT IDENTIFIER
3583 LocatedToken lt = (LocatedToken) $3;
3585 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3587 | unbound_type_name DOT IDENTIFIER generic_dimension
3589 LocatedToken lt = (LocatedToken) $3;
3591 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3593 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3595 LocatedToken lt = (LocatedToken) $3;
3596 MemberName name = (MemberName) $1;
3598 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3605 if (RootContext.Version < LanguageVersion.ISO_2)
3606 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3612 qualified_alias_member
3613 : IDENTIFIER DOUBLE_COLON
3615 LocatedToken lt = (LocatedToken) $1;
3616 if (RootContext.Version == LanguageVersion.ISO_1)
3617 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3624 : SIZEOF open_parens_any type CLOSE_PARENS {
3625 $$ = new SizeOf ((Expression) $3, (Location) $1);
3630 : CHECKED open_parens_any expression CLOSE_PARENS
3632 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3636 unchecked_expression
3637 : UNCHECKED open_parens_any expression CLOSE_PARENS
3639 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3643 pointer_member_access
3644 : primary_expression OP_PTR IDENTIFIER
3647 LocatedToken lt = (LocatedToken) $3;
3649 deref = new Indirection ((Expression) $1, lt.Location);
3650 $$ = new MemberAccess (deref, lt.Value);
3654 anonymous_method_expression
3655 : DELEGATE opt_anonymous_method_signature
3657 start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
3661 $$ = end_anonymous ((ToplevelBlock) $4);
3665 opt_anonymous_method_signature
3668 $$ = ParametersCompiled.Undefined;
3670 | anonymous_method_signature
3673 anonymous_method_signature
3676 params_modifiers_not_allowed = true;
3678 opt_formal_parameter_list CLOSE_PARENS
3680 params_modifiers_not_allowed = false;
3685 default_value_expression
3686 : DEFAULT open_parens_any type CLOSE_PARENS
3688 if (RootContext.Version < LanguageVersion.ISO_2)
3689 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3691 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3696 : primary_expression
3697 | BANG prefixed_unary_expression
3699 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3701 | TILDE prefixed_unary_expression
3703 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3709 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3711 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3713 | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3715 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3720 // The idea to split this out is from Rhys' grammar
3721 // to solve the problem with casts.
3723 prefixed_unary_expression
3725 | PLUS prefixed_unary_expression
3727 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3729 | MINUS prefixed_unary_expression
3731 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3733 | OP_INC prefixed_unary_expression
3735 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3737 | OP_DEC prefixed_unary_expression
3739 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3741 | STAR prefixed_unary_expression
3743 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3745 | BITWISE_AND prefixed_unary_expression
3747 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3751 multiplicative_expression
3752 : prefixed_unary_expression
3753 | multiplicative_expression STAR prefixed_unary_expression
3755 $$ = new Binary (Binary.Operator.Multiply,
3756 (Expression) $1, (Expression) $3);
3758 | multiplicative_expression DIV prefixed_unary_expression
3760 $$ = new Binary (Binary.Operator.Division,
3761 (Expression) $1, (Expression) $3);
3763 | multiplicative_expression PERCENT prefixed_unary_expression
3765 $$ = new Binary (Binary.Operator.Modulus,
3766 (Expression) $1, (Expression) $3);
3771 : multiplicative_expression
3772 | additive_expression PLUS multiplicative_expression
3774 $$ = new Binary (Binary.Operator.Addition,
3775 (Expression) $1, (Expression) $3);
3777 | additive_expression MINUS multiplicative_expression
3779 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3781 | parenthesized_expression MINUS multiplicative_expression
3783 // Shift/Reduce conflict
3784 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3786 | additive_expression AS type
3788 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3790 | additive_expression IS type
3792 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3797 : additive_expression
3798 | shift_expression OP_SHIFT_LEFT additive_expression
3800 $$ = new Binary (Binary.Operator.LeftShift,
3801 (Expression) $1, (Expression) $3);
3803 | shift_expression OP_SHIFT_RIGHT additive_expression
3805 $$ = new Binary (Binary.Operator.RightShift,
3806 (Expression) $1, (Expression) $3);
3810 relational_expression
3812 | relational_expression OP_LT shift_expression
3814 $$ = new Binary (Binary.Operator.LessThan,
3815 (Expression) $1, (Expression) $3);
3817 | relational_expression OP_GT shift_expression
3819 $$ = new Binary (Binary.Operator.GreaterThan,
3820 (Expression) $1, (Expression) $3);
3822 | relational_expression OP_LE shift_expression
3824 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3825 (Expression) $1, (Expression) $3);
3827 | relational_expression OP_GE shift_expression
3829 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3830 (Expression) $1, (Expression) $3);
3835 : relational_expression
3836 | equality_expression OP_EQ relational_expression
3838 $$ = new Binary (Binary.Operator.Equality,
3839 (Expression) $1, (Expression) $3);
3841 | equality_expression OP_NE relational_expression
3843 $$ = new Binary (Binary.Operator.Inequality,
3844 (Expression) $1, (Expression) $3);
3849 : equality_expression
3850 | and_expression BITWISE_AND equality_expression
3852 $$ = new Binary (Binary.Operator.BitwiseAnd,
3853 (Expression) $1, (Expression) $3);
3857 exclusive_or_expression
3859 | exclusive_or_expression CARRET and_expression
3861 $$ = new Binary (Binary.Operator.ExclusiveOr,
3862 (Expression) $1, (Expression) $3);
3866 inclusive_or_expression
3867 : exclusive_or_expression
3868 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3870 $$ = new Binary (Binary.Operator.BitwiseOr,
3871 (Expression) $1, (Expression) $3);
3875 conditional_and_expression
3876 : inclusive_or_expression
3877 | conditional_and_expression OP_AND inclusive_or_expression
3879 $$ = new Binary (Binary.Operator.LogicalAnd,
3880 (Expression) $1, (Expression) $3);
3884 conditional_or_expression
3885 : conditional_and_expression
3886 | conditional_or_expression OP_OR conditional_and_expression
3888 $$ = new Binary (Binary.Operator.LogicalOr,
3889 (Expression) $1, (Expression) $3);
3893 null_coalescing_expression
3894 : conditional_or_expression
3895 | conditional_or_expression OP_COALESCING null_coalescing_expression
3897 if (RootContext.Version < LanguageVersion.ISO_2)
3898 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3900 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3904 conditional_expression
3905 : null_coalescing_expression
3906 | null_coalescing_expression INTERR expression COLON expression
3908 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3912 assignment_expression
3913 : prefixed_unary_expression ASSIGN expression
3915 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3917 | prefixed_unary_expression OP_MULT_ASSIGN expression
3919 $$ = new CompoundAssign (
3920 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3922 | prefixed_unary_expression OP_DIV_ASSIGN expression
3924 $$ = new CompoundAssign (
3925 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3927 | prefixed_unary_expression OP_MOD_ASSIGN expression
3929 $$ = new CompoundAssign (
3930 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3932 | prefixed_unary_expression OP_ADD_ASSIGN expression
3934 $$ = new CompoundAssign (
3935 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3937 | prefixed_unary_expression OP_SUB_ASSIGN expression
3939 $$ = new CompoundAssign (
3940 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3942 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3944 $$ = new CompoundAssign (
3945 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3947 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3949 $$ = new CompoundAssign (
3950 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3952 | prefixed_unary_expression OP_AND_ASSIGN expression
3954 $$ = new CompoundAssign (
3955 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3957 | prefixed_unary_expression OP_OR_ASSIGN expression
3959 $$ = new CompoundAssign (
3960 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3962 | prefixed_unary_expression OP_XOR_ASSIGN expression
3964 $$ = new CompoundAssign (
3965 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3969 lambda_parameter_list
3972 ArrayList pars = new ArrayList (4);
3977 | lambda_parameter_list COMMA lambda_parameter
3979 ArrayList pars = (ArrayList) $1;
3980 Parameter p = (Parameter)$3;
3981 if (pars[0].GetType () != p.GetType ()) {
3982 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
3991 : parameter_modifier type IDENTIFIER
3993 LocatedToken lt = (LocatedToken) $3;
3995 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3999 LocatedToken lt = (LocatedToken) $2;
4001 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4005 LocatedToken lt = (LocatedToken) $1;
4006 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4010 opt_lambda_parameter_list
4011 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4012 | lambda_parameter_list {
4013 ArrayList pars_list = (ArrayList) $1;
4014 $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter)));
4018 lambda_expression_body
4020 start_block (lexer.Location);
4024 Block b = end_block (lexer.Location);
4025 b.AddStatement (new ContextualReturn ((Expression) $2));
4036 LocatedToken lt = (LocatedToken) $1;
4037 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4038 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4040 lambda_expression_body
4042 $$ = end_anonymous ((ToplevelBlock) $4);
4044 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4046 start_anonymous (true, (ParametersCompiled) $2, GetLocation ($1));
4048 lambda_expression_body
4050 $$ = end_anonymous ((ToplevelBlock) $6);
4055 : assignment_expression
4056 | non_assignment_expression
4059 non_assignment_expression
4060 : conditional_expression
4082 lexer.ConstraintsParsing = true;
4084 type_declaration_name
4086 MemberName name = MakeName ((MemberName) $6);
4087 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4090 opt_type_parameter_constraints_clauses
4092 lexer.ConstraintsParsing = false;
4094 current_class.SetParameterInfo ((ArrayList) $9);
4096 if (RootContext.Documentation != null) {
4097 current_container.DocComment = Lexer.consume_doc_comment ();
4098 Lexer.doc_state = XmlCommentState.Allowed;
4103 --lexer.parsing_declaration;
4104 if (RootContext.Documentation != null)
4105 Lexer.doc_state = XmlCommentState.Allowed;
4109 $$ = pop_current_class ();
4117 { $$ = $1; } // location
4121 : /* empty */ { $$ = (int) 0; }
4127 | modifiers modifier
4132 if ((m1 & m2) != 0) {
4133 Location l = lexer.Location;
4134 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4136 $$ = (int) (m1 | m2);
4144 if (current_container == RootContext.ToplevelTypes)
4145 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4147 | PUBLIC { $$ = Modifiers.PUBLIC; }
4148 | PROTECTED { $$ = Modifiers.PROTECTED; }
4149 | INTERNAL { $$ = Modifiers.INTERNAL; }
4150 | PRIVATE { $$ = Modifiers.PRIVATE; }
4151 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4152 | SEALED { $$ = Modifiers.SEALED; }
4153 | STATIC { $$ = Modifiers.STATIC; }
4154 | READONLY { $$ = Modifiers.READONLY; }
4155 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4156 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4157 | EXTERN { $$ = Modifiers.EXTERN; }
4158 | VOLATILE { $$ = Modifiers.VOLATILE; }
4159 | UNSAFE { $$ = Modifiers.UNSAFE; }
4168 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4171 opt_type_parameter_constraints_clauses
4172 : /* empty */ { $$ = null; }
4173 | type_parameter_constraints_clauses
4177 type_parameter_constraints_clauses
4178 : type_parameter_constraints_clause {
4179 ArrayList constraints = new ArrayList (1);
4180 constraints.Add ($1);
4183 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4184 ArrayList constraints = (ArrayList) $1;
4185 Constraints new_constraint = (Constraints)$2;
4187 foreach (Constraints c in constraints) {
4188 if (new_constraint.TypeParameter == c.TypeParameter) {
4189 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4190 new_constraint.TypeParameter);
4194 constraints.Add (new_constraint);
4199 type_parameter_constraints_clause
4200 : WHERE IDENTIFIER COLON type_parameter_constraints {
4201 LocatedToken lt = (LocatedToken) $2;
4202 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4206 type_parameter_constraints
4207 : type_parameter_constraint {
4208 ArrayList constraints = new ArrayList (1);
4209 constraints.Add ($1);
4212 | type_parameter_constraints COMMA type_parameter_constraint {
4213 ArrayList constraints = (ArrayList) $1;
4215 constraints.Add ($3);
4220 type_parameter_constraint
4222 | NEW OPEN_PARENS CLOSE_PARENS {
4223 $$ = SpecialConstraint.Constructor;
4226 $$ = SpecialConstraint.ReferenceType;
4229 $$ = SpecialConstraint.ValueType;
4233 opt_type_parameter_variance
4238 | type_parameter_variance
4240 if (RootContext.Version <= LanguageVersion.V_3)
4241 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4247 type_parameter_variance
4250 $$ = Variance.Covariant;
4254 $$ = Variance.Contravariant;
4263 // A block is "contained" on the following places:
4265 // property_declaration as part of the accessor body (get/set)
4266 // operator_declaration
4267 // constructor_declaration
4268 // destructor_declaration
4269 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4274 ++lexer.parsing_block;
4275 start_block ((Location) $1);
4277 opt_statement_list block_end
4286 --lexer.parsing_block;
4287 $$ = end_block ((Location) $1);
4289 | COMPLETE_COMPLETION
4291 --lexer.parsing_block;
4292 $$ = end_block (lexer.Location);
4300 ++lexer.parsing_block;
4301 current_block.StartLocation = GetLocation ($1);
4303 opt_statement_list CLOSE_BRACE
4305 --lexer.parsing_block;
4306 $$ = end_block ((Location) $4);
4317 | statement_list statement
4321 : declaration_statement
4323 if ($1 != null && (Block) $1 != current_block){
4324 current_block.AddStatement ((Statement) $1);
4325 current_block = (Block) $1;
4328 | valid_declaration_statement
4330 current_block.AddStatement ((Statement) $1);
4336 // The interactive_statement and its derivatives are only
4337 // used to provide a special version of `expression_statement'
4338 // that has a side effect of assigning the expression to
4341 interactive_statement_list
4342 : interactive_statement
4343 | interactive_statement_list interactive_statement
4346 interactive_statement
4347 : declaration_statement
4349 if ($1 != null && (Block) $1 != current_block){
4350 current_block.AddStatement ((Statement) $1);
4351 current_block = (Block) $1;
4354 | interactive_valid_declaration_statement
4356 current_block.AddStatement ((Statement) $1);
4361 valid_declaration_statement
4364 | expression_statement
4365 | selection_statement
4366 | iteration_statement
4370 | unchecked_statement
4377 interactive_valid_declaration_statement
4380 | interactive_expression_statement
4381 | selection_statement
4382 | iteration_statement
4386 | unchecked_statement
4394 : valid_declaration_statement
4395 | declaration_statement
4397 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4402 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4410 $$ = EmptyStatement.Value;
4417 LocatedToken lt = (LocatedToken) $1;
4418 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4420 if (current_block.AddLabel (labeled))
4421 current_block.AddStatement (labeled);
4426 declaration_statement
4427 : local_variable_declaration SEMICOLON
4429 current_array_type = null;
4431 DictionaryEntry de = (DictionaryEntry) $1;
4432 Expression e = (Expression) de.Key;
4434 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4438 | local_constant_declaration SEMICOLON
4440 current_array_type = null;
4442 DictionaryEntry de = (DictionaryEntry) $1;
4444 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4450 * The following is from Rhys' grammar:
4451 * > Types in local variable declarations must be recognized as
4452 * > expressions to prevent reduce/reduce errors in the grammar.
4453 * > The expressions are converted into types during semantic analysis.
4456 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4458 // FIXME: Do something smart here regarding the composition of the type.
4460 // Ok, the above "primary_expression" is there to get rid of
4461 // both reduce/reduce and shift/reduces in the grammar, it should
4462 // really just be "type_name". If you use type_name, a reduce/reduce
4463 // creeps up. If you use namespace_or_type_name (which is all we need
4464 // really) two shift/reduces appear.
4467 // So the super-trick is that primary_expression
4468 // can only be either a SimpleName or a MemberAccess.
4469 // The MemberAccess case arises when you have a fully qualified type-name like :
4471 // SimpleName is when you have
4474 Expression expr = (Expression) $1;
4475 string rank_or_nullable = (string) $2;
4477 if (expr is ComposedCast){
4478 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4479 } else if (expr is ATypeNameExpression){
4481 // So we extract the string corresponding to the SimpleName
4484 if (rank_or_nullable.Length == 0) {
4485 SimpleName sn = expr as SimpleName;
4486 if (sn != null && sn.Name == "var" &&
4487 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
4488 $$ = current_array_type = new VarExpr (sn.Location);
4492 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4495 Error_ExpectingTypeName (expr);
4496 $$ = TypeManager.system_object_expr;
4499 | builtin_types opt_rank_specifier_or_nullable
4501 if ((string) $2 == "")
4504 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4506 | VOID opt_rank_specifier
4508 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4509 $$ = TypeManager.system_void_expr;
4513 local_variable_pointer_type
4514 : primary_expression_no_array_creation STAR
4516 ATypeNameExpression expr = $1 as ATypeNameExpression;
4519 $$ = new ComposedCast (expr, "*");
4521 Error_ExpectingTypeName ((Expression)$1);
4525 | builtin_types STAR
4527 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4531 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4533 | local_variable_pointer_type STAR
4535 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4541 | local_variable_pointer_type opt_rank_specifier
4544 string rank = (string)$2;
4549 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4556 local_variable_declaration
4557 : local_variable_type local_variable_declarators
4560 VarExpr ve = $1 as VarExpr;
4562 ve.VariableInitializer = (ArrayList)$2;
4564 $$ = new DictionaryEntry ($1, $2);
4570 local_constant_declaration
4571 : CONST variable_type constant_declarators
4574 $$ = new DictionaryEntry ($2, $3);
4580 expression_statement
4581 : statement_expression SEMICOLON { $$ = $1; }
4582 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4585 interactive_expression_statement
4586 : interactive_statement_expression SEMICOLON { $$ = $1; }
4587 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4591 // We have to do the wrapping here and not in the case above,
4592 // because statement_expression is used for example in for_statement
4594 statement_expression
4597 ExpressionStatement s = $1 as ExpressionStatement;
4599 ((Expression) $1).Error_InvalidExpressionStatement ();
4600 s = EmptyExpressionStatement.Instance;
4603 $$ = new StatementExpression (s);
4607 Error_SyntaxError (yyToken);
4612 interactive_statement_expression
4615 Expression expr = (Expression) $1;
4616 ExpressionStatement s;
4618 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4619 $$ = new StatementExpression (s);
4623 Error_SyntaxError (yyToken);
4634 : IF open_parens_any boolean_expression CLOSE_PARENS
4637 Location l = (Location) $1;
4639 $$ = new If ((Expression) $3, (Statement) $5, l);
4641 // FIXME: location for warning should be loc property of $5.
4642 if ($5 == EmptyStatement.Value)
4643 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4646 | IF open_parens_any boolean_expression CLOSE_PARENS
4647 embedded_statement ELSE embedded_statement
4649 Location l = (Location) $1;
4651 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4653 // FIXME: location for warning should be loc property of $5 and $7.
4654 if ($5 == EmptyStatement.Value)
4655 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4656 if ($7 == EmptyStatement.Value)
4657 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4662 : SWITCH open_parens_any
4664 if (switch_stack == null)
4665 switch_stack = new Stack (2);
4666 switch_stack.Push (current_block);
4668 expression CLOSE_PARENS
4671 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4672 current_block = (Block) switch_stack.Pop ();
4688 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4689 $$ = new ArrayList ();
4697 ArrayList sections = new ArrayList (4);
4702 | switch_sections switch_section
4704 ArrayList sections = (ArrayList) $1;
4714 current_block = current_block.CreateSwitchBlock (lexer.Location);
4718 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4725 ArrayList labels = new ArrayList (4);
4730 | switch_labels switch_label
4732 ArrayList labels = (ArrayList) ($1);
4740 : CASE constant_expression COLON
4742 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4746 $$ = new SwitchLabel (null, (Location) $1);
4758 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4760 Location l = (Location) $1;
4761 $$ = new While ((Expression) $3, (Statement) $5, l);
4766 : DO embedded_statement
4767 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4769 Location l = (Location) $1;
4771 $$ = new Do ((Statement) $2, (Expression) $5, l);
4776 : FOR open_parens_any opt_for_initializer SEMICOLON
4778 Location l = lexer.Location;
4780 Block assign_block = current_block;
4782 if ($3 is DictionaryEntry){
4783 DictionaryEntry de = (DictionaryEntry) $3;
4785 Expression type = (Expression) de.Key;
4786 ArrayList var_declarators = (ArrayList) de.Value;
4788 foreach (VariableDeclaration decl in var_declarators){
4792 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4796 Expression expr = decl.expression_or_array_initializer;
4798 LocalVariableReference var;
4799 var = new LocalVariableReference (assign_block, decl.identifier, l);
4802 Assign a = new SimpleAssign (var, expr, decl.Location);
4804 assign_block.AddStatement (new StatementExpression (a));
4808 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4809 // This can be referred to as $5 below.
4815 opt_for_condition SEMICOLON
4816 opt_for_iterator CLOSE_PARENS
4819 Location l = (Location) $1;
4821 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4823 current_block.AddStatement (f);
4825 $$ = end_block (lexer.Location);
4830 : /* empty */ { $$ = EmptyStatement.Value; }
4835 : local_variable_declaration
4836 | statement_expression_list
4840 : /* empty */ { $$ = null; }
4841 | boolean_expression
4845 : /* empty */ { $$ = EmptyStatement.Value; }
4850 : statement_expression_list
4853 statement_expression_list
4854 : statement_expression
4856 // CHANGE: was `null'
4857 Statement s = (Statement) $1;
4858 Block b = new Block (current_block, s.loc, lexer.Location);
4863 | statement_expression_list COMMA statement_expression
4865 Block b = (Block) $1;
4867 b.AddStatement ((Statement) $3);
4873 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4875 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4878 | FOREACH open_parens_any type IDENTIFIER IN
4879 expression CLOSE_PARENS
4881 start_block (lexer.Location);
4882 Block foreach_block = current_block;
4884 LocatedToken lt = (LocatedToken) $4;
4885 Location l = lt.Location;
4886 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4888 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4890 // Get a writable reference to this read-only variable.
4892 // Note that the $$ here refers to the value of _this_ code block,
4893 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4894 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4901 LocalVariableReference v = (LocalVariableReference) $8;
4902 Location l = (Location) $1;
4905 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4906 current_block.AddStatement (f);
4909 $$ = end_block (lexer.Location);
4915 | continue_statement
4925 $$ = new Break ((Location) $1);
4930 : CONTINUE SEMICOLON
4932 $$ = new Continue ((Location) $1);
4937 : GOTO IDENTIFIER SEMICOLON
4939 LocatedToken lt = (LocatedToken) $2;
4940 $$ = new Goto (lt.Value, lt.Location);
4942 | GOTO CASE constant_expression SEMICOLON
4944 $$ = new GotoCase ((Expression) $3, (Location) $1);
4946 | GOTO DEFAULT SEMICOLON
4948 $$ = new GotoDefault ((Location) $1);
4953 : RETURN opt_expression SEMICOLON
4955 $$ = new Return ((Expression) $2, (Location) $1);
4960 : THROW opt_expression SEMICOLON
4962 $$ = new Throw ((Expression) $2, (Location) $1);
4967 : IDENTIFIER RETURN expression SEMICOLON
4969 LocatedToken lt = (LocatedToken) $1;
4970 string s = lt.Value;
4972 Report.Error (1003, lt.Location, "; expected");
4975 if (RootContext.Version == LanguageVersion.ISO_1){
4976 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4979 current_block.Toplevel.IsIterator = true;
4980 $$ = new Yield ((Expression) $3, lt.Location);
4982 | IDENTIFIER RETURN SEMICOLON
4984 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4987 | IDENTIFIER BREAK SEMICOLON
4989 LocatedToken lt = (LocatedToken) $1;
4990 string s = lt.Value;
4992 Report.Error (1003, lt.Location, "; expected");
4995 if (RootContext.Version == LanguageVersion.ISO_1){
4996 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5000 current_block.Toplevel.IsIterator = true;
5001 $$ = new YieldBreak (lt.Location);
5011 : TRY block catch_clauses
5013 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
5015 | TRY block FINALLY block
5017 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
5019 | TRY block catch_clauses FINALLY block
5021 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
5025 Report.Error (1524, (Location) $1, "Expected catch or finally");
5033 ArrayList l = new ArrayList (4);
5038 | catch_clauses catch_clause
5040 ArrayList l = (ArrayList) $1;
5048 : /* empty */ { $$ = null; }
5053 : CATCH opt_catch_args
5055 Expression type = null;
5058 DictionaryEntry cc = (DictionaryEntry) $2;
5059 type = (Expression) cc.Key;
5060 LocatedToken lt = (LocatedToken) cc.Value;
5063 ArrayList one = new ArrayList (4);
5065 one.Add (new VariableDeclaration (lt, null));
5067 start_block (lexer.Location);
5068 current_block = declare_local_variables (type, one, lt.Location);
5072 Expression type = null;
5074 Block var_block = null;
5077 DictionaryEntry cc = (DictionaryEntry) $2;
5078 type = (Expression) cc.Key;
5079 LocatedToken lt = (LocatedToken) cc.Value;
5083 var_block = end_block (lexer.Location);
5087 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5092 : /* empty */ { $$ = null; }
5097 : open_parens_any type opt_identifier CLOSE_PARENS
5099 $$ = new DictionaryEntry ($2, $3);
5101 | open_parens_any CLOSE_PARENS
5103 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5110 $$ = new Checked ((Block) $2);
5117 $$ = new Unchecked ((Block) $2);
5124 RootContext.CheckUnsafeOption ((Location) $1);
5126 $$ = new Unsafe ((Block) $3);
5131 : FIXED open_parens_any
5132 type_and_void fixed_pointer_declarators
5135 ArrayList list = (ArrayList) $4;
5136 Expression type = (Expression) $3;
5137 Location l = (Location) $1;
5138 int top = list.Count;
5140 start_block (lexer.Location);
5142 for (int i = 0; i < top; i++){
5143 Pair p = (Pair) list [i];
5146 v = current_block.AddVariable (type, (string) p.First, l);
5150 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5158 Location l = (Location) $1;
5160 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5162 current_block.AddStatement (f);
5164 $$ = end_block (lexer.Location);
5168 fixed_pointer_declarators
5169 : fixed_pointer_declarator {
5170 ArrayList declarators = new ArrayList (4);
5172 declarators.Add ($1);
5175 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5177 ArrayList declarators = (ArrayList) $1;
5179 declarators.Add ($3);
5184 fixed_pointer_declarator
5185 : IDENTIFIER ASSIGN expression
5187 LocatedToken lt = (LocatedToken) $1;
5188 // FIXME: keep location
5189 $$ = new Pair (lt.Value, $3);
5193 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5199 : LOCK open_parens_any expression CLOSE_PARENS
5205 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5210 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5212 start_block (lexer.Location);
5213 Block assign_block = current_block;
5215 DictionaryEntry de = (DictionaryEntry) $3;
5216 Location l = (Location) $1;
5218 Expression type = (Expression) de.Key;
5219 ArrayList var_declarators = (ArrayList) de.Value;
5221 Stack vars = new Stack ();
5223 foreach (VariableDeclaration decl in var_declarators) {
5224 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5227 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5229 Expression expr = decl.expression_or_array_initializer;
5231 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5234 LocalVariableReference var;
5236 // Get a writable reference to this read-only variable.
5237 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5239 // This is so that it is not a warning on using variables
5242 vars.Push (new DictionaryEntry (var, expr));
5244 // Assign a = new SimpleAssign (var, expr, decl.Location);
5245 // assign_block.AddStatement (new StatementExpression (a));
5248 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5249 // It can be referred to as $5 below.
5254 Statement stmt = (Statement) $6;
5255 Stack vars = (Stack) $5;
5256 Location l = (Location) $1;
5258 while (vars.Count > 0) {
5259 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5260 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5262 current_block.AddStatement (stmt);
5263 $$ = end_block (lexer.Location);
5265 | USING open_parens_any expression CLOSE_PARENS
5267 start_block (lexer.Location);
5271 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5272 $$ = end_block (lexer.Location);
5280 : first_from_clause query_body
5282 lexer.query_parsing = false;
5284 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5286 from.Tail.Next = (Linq.AQueryClause)$2;
5289 current_block.SetEndLocation (lexer.Location);
5290 current_block = current_block.Parent;
5292 | nested_from_clause query_body
5294 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5296 from.Tail.Next = (Linq.AQueryClause)$2;
5299 current_block.SetEndLocation (lexer.Location);
5300 current_block = current_block.Parent;
5305 : FROM_FIRST IDENTIFIER IN expression
5307 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5308 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5310 | FROM_FIRST type IDENTIFIER IN expression
5312 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5313 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5318 : FROM IDENTIFIER IN expression
5320 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5321 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5323 | FROM type IDENTIFIER IN expression
5325 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5326 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5331 : FROM IDENTIFIER IN
5333 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5337 LocatedToken lt = (LocatedToken) $2;
5338 $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
5340 current_block.SetEndLocation (lexer.Location);
5341 current_block = current_block.Parent;
5343 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5345 | FROM type IDENTIFIER IN
5347 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5351 LocatedToken lt = (LocatedToken) $3;
5352 FullNamedExpression type = (FullNamedExpression)$2;
5354 $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
5356 current_block.SetEndLocation (lexer.Location);
5357 current_block = current_block.Parent;
5359 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5364 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5366 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5369 head.Next = (Linq.AQueryClause)$3;
5372 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5373 clause.Tail.Next = head;
5381 select_or_group_clause
5384 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5388 $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5390 current_block.SetEndLocation (lexer.Location);
5391 current_block = current_block.Parent;
5395 if (linq_clause_blocks == null)
5396 linq_clause_blocks = new Stack ();
5398 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5399 linq_clause_blocks.Push (current_block);
5403 current_block.SetEndLocation (lexer.Location);
5404 current_block = current_block.Parent;
5406 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5410 $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5412 current_block.SetEndLocation (lexer.Location);
5413 current_block = current_block.Parent;
5417 opt_query_body_clauses
5419 | query_body_clauses
5424 | query_body_clauses query_body_clause
5426 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5440 : LET IDENTIFIER ASSIGN
5442 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5446 LocatedToken lt = (LocatedToken) $2;
5447 $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
5449 current_block.SetEndLocation (lexer.Location);
5450 current_block = current_block.Parent;
5452 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5459 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5463 $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5465 current_block.SetEndLocation (lexer.Location);
5466 current_block = current_block.Parent;
5471 : JOIN IDENTIFIER IN
5473 if (linq_clause_blocks == null)
5474 linq_clause_blocks = new Stack ();
5476 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5477 linq_clause_blocks.Push (current_block);
5481 current_block.SetEndLocation (lexer.Location);
5482 current_block = current_block.Parent;
5484 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5485 linq_clause_blocks.Push (current_block);
5489 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5490 current_block.SetEndLocation (lexer.Location);
5491 current_block = current_block.Parent;
5493 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location);
5495 expression opt_join_into
5497 LocatedToken lt = (LocatedToken) $2;
5499 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5500 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5503 $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
5505 $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
5506 (LocatedToken) $12, GetLocation ($1));
5509 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5510 current_block.SetEndLocation (lexer.Location);
5511 current_block = current_block.Parent;
5514 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5516 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12);
5518 | JOIN type IDENTIFIER IN
5520 if (linq_clause_blocks == null)
5521 linq_clause_blocks = new Stack ();
5523 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5524 linq_clause_blocks.Push (current_block);
5528 current_block.SetEndLocation (lexer.Location);
5529 current_block = current_block.Parent;
5531 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5532 linq_clause_blocks.Push (current_block);
5536 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5537 current_block.SetEndLocation (lexer.Location);
5538 current_block = current_block.Parent;
5540 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location);
5542 expression opt_join_into
5544 LocatedToken lt = (LocatedToken) $3;
5545 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5546 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5548 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
5550 $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
5552 $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
5553 (LocatedToken) $13, GetLocation ($1));
5556 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5557 current_block.SetEndLocation (lexer.Location);
5558 current_block = current_block.Parent;
5561 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5563 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13);
5578 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5582 current_block.SetEndLocation (lexer.Location);
5583 current_block = current_block.Parent;
5593 current_block.SetEndLocation (lexer.Location);
5594 current_block = current_block.Parent;
5596 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5600 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5607 | orderings_then_by COMMA
5609 current_block.SetEndLocation (lexer.Location);
5610 current_block = current_block.Parent;
5612 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5616 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5624 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5626 | expression ASCENDING
5628 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5630 | expression DESCENDING
5632 $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
5639 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5641 | expression ASCENDING
5643 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5645 | expression DESCENDING
5647 $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
5652 opt_query_continuation
5656 // query continuation block is not linked with query block but with block
5657 // before. This means each query can use same range variable names for
5658 // different identifiers.
5660 current_block.SetEndLocation (GetLocation ($1));
5661 current_block = current_block.Parent;
5663 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5667 $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
5672 // Support for using the compiler as an interactive parser
5674 // The INTERACTIVE_PARSER token is first sent to parse our
5675 // productions; If the result is a Statement, the parsing
5676 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5677 // to setup the blocks in advance.
5679 // This setup is here so that in the future we can add
5680 // support for other constructs (type parsing, namespaces, etc)
5681 // that do not require a block to be setup in advance
5685 : EVAL_STATEMENT_PARSER EOF
5686 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5687 | EVAL_STATEMENT_PARSER {
5688 Evaluator.LoadAliases (current_namespace);
5690 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5691 Modifiers.PUBLIC, null), null);
5693 ArrayList baseclass_list = new ArrayList ();
5694 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5695 current_container.AddBasesForPart (current_class, baseclass_list);
5697 // (ref object retval)
5698 Parameter [] mpar = new Parameter [1];
5699 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5701 ParametersCompiled pars = new ParametersCompiled (mpar);
5702 current_local_parameters = pars;
5703 Method method = new Method (
5706 TypeManager.system_void_expr,
5707 Modifiers.PUBLIC | Modifiers.STATIC,
5708 new MemberName ("Host"),
5710 null /* attributes */);
5712 oob_stack.Push (method);
5713 ++lexer.parsing_block;
5714 start_block (lexer.Location);
5716 interactive_statement_list opt_COMPLETE_COMPLETION
5718 --lexer.parsing_block;
5719 Method method = (Method) oob_stack.Pop ();
5721 method.Block = (ToplevelBlock) end_block(lexer.Location);
5722 current_container.AddMethod (method);
5724 --lexer.parsing_declaration;
5725 InteractiveResult = pop_current_class ();
5726 current_local_parameters = null;
5728 | EVAL_COMPILATION_UNIT_PARSER {
5729 Evaluator.LoadAliases (current_namespace);
5731 interactive_compilation_unit
5734 interactive_compilation_unit
5735 : outer_declarations
5736 | outer_declarations global_attributes
5741 opt_COMPLETE_COMPLETION
5743 | COMPLETE_COMPLETION
5746 close_brace_or_complete_completion
5748 | COMPLETE_COMPLETION
5753 // A class used to pass around variable declarations and constants
5755 public class VariableDeclaration {
5756 public string identifier;
5757 public Expression expression_or_array_initializer;
5758 public Location Location;
5759 public Attributes OptAttributes;
5760 public string DocComment;
5762 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5764 this.identifier = lt.Value;
5765 if (eoai is ArrayList) {
5766 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5768 this.expression_or_array_initializer = (Expression)eoai;
5770 this.Location = lt.Location;
5771 this.OptAttributes = opt_attrs;
5774 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5779 class VariableMemberDeclaration
5781 public readonly MemberName MemberName;
5782 public Expression expression_or_array_initializer;
5784 public VariableMemberDeclaration (MemberName mn, object initializer)
5788 if (initializer is ArrayList) {
5789 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5791 this.expression_or_array_initializer = (Expression)initializer;
5798 // A class used to hold info about an operator declarator
5800 struct OperatorDeclaration {
5801 public readonly Operator.OpType optype;
5802 public readonly FullNamedExpression ret_type;
5803 public readonly Location location;
5805 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5808 this.ret_type = ret_type;
5809 this.location = location;
5813 void Error_ExpectingTypeName (Expression expr)
5815 if (expr is Invocation){
5816 Report.Error (1002, expr.Location, "Expecting `;'");
5818 expr.Error_InvalidExpressionStatement ();
5822 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5824 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5828 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5830 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5831 Parameter.GetModifierSignature (mod));
5834 static void Error_TypeExpected (Location loc)
5836 Report.Error (1031, loc, "Type expected");
5839 void push_current_class (TypeContainer tc, object partial_token)
5841 if (RootContext.EvalMode){
5842 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5843 undo.AddTypeContainer (current_container, tc);
5846 if (partial_token != null)
5847 current_container = current_container.AddPartial (tc);
5849 current_container = current_container.AddTypeContainer (tc);
5851 ++lexer.parsing_declaration;
5855 DeclSpace pop_current_class ()
5857 DeclSpace retval = current_class;
5859 current_class = current_class.Parent;
5860 current_container = current_class.PartialContainer;
5866 // Given the @class_name name, it creates a fully qualified name
5867 // based on the containing declaration space
5870 MakeName (MemberName class_name)
5872 Namespace ns = current_namespace.NS;
5874 if (current_container == RootContext.ToplevelTypes) {
5875 if (ns.Name.Length != 0)
5876 return new MemberName (ns.MemberName, class_name);
5880 return new MemberName (current_container.MemberName, class_name);
5884 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5886 Block implicit_block;
5887 ArrayList inits = null;
5890 // If we are doing interactive editing, we want variable declarations
5891 // that are in the top block to be added instead to the class as
5894 if (RootContext.StatementMode){
5897 for (Block b = current_block; b != null; b = b.Parent){
5898 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5899 // There has been an explicit block, we cant add to the class
5906 // We can use "current_block" since we know there are no explicit blocks
5908 foreach (VariableDeclaration decl in variable_declarators){
5909 // We can not use the super-handy f.Initializer, because
5910 // multiple lines would force code to be executed out of sync
5911 if (decl.expression_or_array_initializer != null){
5912 string id = "$" + decl.identifier;
5913 current_block.AddVariable (type, id, decl.Location);
5915 LocalVariableReference var;
5916 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5917 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5918 current_block.AddStatement (new StatementExpression (assign));
5919 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5920 current_block.AddStatement (new StatementExpression (assign));
5922 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
5923 new MemberName (decl.identifier, loc), null);
5924 current_container.AddField (f);
5926 // Register the field to be visible later as a global variable
5927 Evaluator.QueueField (f);
5931 return current_block;
5936 // We use the `Used' property to check whether statements
5937 // have been added to the current block. If so, we need
5938 // to create another block to contain the new declaration
5939 // otherwise, as an optimization, we use the same block to
5940 // add the declaration.
5942 // FIXME: A further optimization is to check if the statements
5943 // that were added were added as part of the initialization
5944 // below. In which case, no other statements have been executed
5945 // and we might be able to reduce the number of blocks for
5946 // situations like this:
5948 // int j = 1; int k = j + 1;
5950 if (current_block.Used)
5951 implicit_block = new Block (current_block, loc, lexer.Location);
5953 implicit_block = current_block;
5955 foreach (VariableDeclaration decl in variable_declarators){
5957 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5958 if (decl.expression_or_array_initializer != null){
5960 inits = new ArrayList (4);
5967 return implicit_block;
5969 foreach (VariableDeclaration decl in inits){
5971 Expression expr = decl.expression_or_array_initializer;
5973 LocalVariableReference var;
5974 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5976 assign = new SimpleAssign (var, expr, decl.Location);
5978 implicit_block.AddStatement (new StatementExpression (assign));
5981 return implicit_block;
5984 Block declare_local_constants (Expression type, ArrayList declarators)
5986 Block implicit_block;
5988 if (current_block.Used)
5989 implicit_block = new Block (current_block);
5991 implicit_block = current_block;
5993 foreach (VariableDeclaration decl in declarators){
5994 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5997 return implicit_block;
6000 string CheckAttributeTarget (string a, Location l)
6003 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6007 Report.Warning (658, 1, l,
6008 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6009 return string.Empty;
6012 static bool IsUnaryOperator (Operator.OpType op)
6016 case Operator.OpType.LogicalNot:
6017 case Operator.OpType.OnesComplement:
6018 case Operator.OpType.Increment:
6019 case Operator.OpType.Decrement:
6020 case Operator.OpType.True:
6021 case Operator.OpType.False:
6022 case Operator.OpType.UnaryPlus:
6023 case Operator.OpType.UnaryNegation:
6029 void syntax_error (Location l, string msg)
6031 Report.Error (1003, l, "Syntax error, " + msg);
6034 void note (string s)
6036 // Used to put annotations
6041 public Tokenizer Lexer {
6047 static CSharpParser ()
6049 oob_stack = new Stack ();
6052 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
6054 if (RootContext.EvalMode)
6058 current_namespace = new NamespaceEntry (null, file, null);
6059 current_class = current_namespace.SlaveDeclSpace;
6060 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6062 lexer = new Tokenizer (reader, file);
6065 public void parse ()
6067 eof_token = Token.EOF;
6070 if (yacc_verbose_flag > 1)
6071 yyparse (lexer, new yydebug.yyDebugSimple ());
6074 } catch (Exception e){
6075 if (e is yyParser.yyUnexpectedEof)
6076 UnexpectedEOF = true;
6077 else if (yacc_verbose_flag > 0)
6078 Console.WriteLine (e);
6079 if (e is yyParser.yyException)
6080 Report.Error (-25, lexer.Location, "Parsing error");
6082 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
6084 Tokenizer tokenizer = lexer as Tokenizer;
6085 tokenizer.cleanup ();
6087 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6088 throw new InternalErrorException ("who set it?");
6091 static void CheckToken (int error, int yyToken, string msg, Location loc)
6093 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6094 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6096 Report.Error (error, loc, msg);
6099 void CheckIdentifierToken (int yyToken, Location loc)
6101 CheckToken (1041, yyToken, "Identifier expected", loc);
6104 string ConsumeStoredComment ()
6106 string s = tmpComment;
6108 Lexer.doc_state = XmlCommentState.Allowed;
6112 Location GetLocation (object obj)
6114 if (obj is MemberCore)
6115 return ((MemberCore) obj).Location;
6116 if (obj is MemberName)
6117 return ((MemberName) obj).Location;
6118 if (obj is LocatedToken)
6119 return ((LocatedToken) obj).Location;
6120 if (obj is Location)
6121 return (Location) obj;
6122 return lexer.Location;
6125 void start_block (Location loc)
6127 if (current_block == null || parsing_anonymous_method) {
6128 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6129 parsing_anonymous_method = false;
6131 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6136 end_block (Location loc)
6138 Block retval = current_block.Explicit;
6139 retval.SetEndLocation (loc);
6140 current_block = retval.Parent;
6145 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6147 if (RootContext.Version == LanguageVersion.ISO_1){
6148 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6151 oob_stack.Push (current_anonymous_method);
6152 oob_stack.Push (current_local_parameters);
6154 current_local_parameters = parameters;
6156 current_anonymous_method = lambda
6157 ? new LambdaExpression (loc)
6158 : new AnonymousMethodExpression (loc);
6160 // Force the next block to be created as a ToplevelBlock
6161 parsing_anonymous_method = true;
6165 * Completes the anonymous method processing, if lambda_expr is null, this
6166 * means that we have a Statement instead of an Expression embedded
6168 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6170 AnonymousMethodExpression retval;
6172 current_anonymous_method.Block = anon_block;
6173 retval = current_anonymous_method;
6175 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6176 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6181 public NamespaceEntry CurrentNamespace {
6183 return current_namespace;
6188 void Error_SyntaxError (int token)
6190 Error_SyntaxError (0, token);
6193 void Error_SyntaxError (int error_code, int token)
6195 string symbol = GetSymbolName (token);
6196 string expecting = GetExpecting ();
6198 if (error_code == 0) {
6199 if (expecting == "`)'")
6205 if (expecting != null)
6206 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
6209 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
6212 string GetExpecting ()
6214 int [] tokens = yyExpectingTokens (yyExpectingState);
6215 ArrayList names = new ArrayList (tokens.Length);
6216 bool has_type = false;
6217 bool has_identifier = false;
6218 for (int i = 0; i < tokens.Length; i++){
6219 int token = tokens [i];
6220 has_identifier |= token == Token.IDENTIFIER;
6222 string name = GetTokenName (token);
6223 if (name == "<internal>")
6226 has_type |= name == "type";
6227 if (names.Contains (name))
6234 // Too many tokens to enumerate
6236 if (names.Count > 8)
6239 if (has_type && has_identifier)
6240 names.Remove ("identifier");
6242 if (names.Count == 1)
6243 return "`" + GetTokenName (tokens [0]) + "'";
6245 StringBuilder sb = new StringBuilder ();
6247 int count = names.Count;
6248 for (int i = 0; i < count; i++){
6249 bool last = i + 1 == count;
6253 sb.Append (names [i]);
6254 sb.Append (last ? "'" : "', ");
6256 return sb.ToString ();
6260 string GetSymbolName (int token)
6263 case Token.LITERAL_FLOAT:
6264 case Token.LITERAL_INTEGER:
6265 case Token.LITERAL_DOUBLE:
6266 case Token.LITERAL_DECIMAL:
6267 case Token.LITERAL_CHARACTER:
6268 case Token.LITERAL_STRING:
6269 return lexer.Value.ToString ();
6270 case Token.IDENTIFIER:
6271 return ((LocatedToken)lexer.Value).Value;
6313 case Token.BITWISE_AND:
6315 case Token.BITWISE_OR:
6329 case Token.OP_SHIFT_LEFT:
6331 case Token.OP_SHIFT_RIGHT:
6351 case Token.OP_COALESCING:
6353 case Token.OP_MULT_ASSIGN:
6355 case Token.OP_DIV_ASSIGN:
6357 case Token.OP_MOD_ASSIGN:
6359 case Token.OP_ADD_ASSIGN:
6361 case Token.OP_SUB_ASSIGN:
6363 case Token.OP_SHIFT_LEFT_ASSIGN:
6365 case Token.OP_SHIFT_RIGHT_ASSIGN:
6367 case Token.OP_AND_ASSIGN:
6369 case Token.OP_XOR_ASSIGN:
6371 case Token.OP_OR_ASSIGN:
6375 return GetTokenName (token);
6378 static string GetTokenName (int token)
6381 case Token.ABSTRACT:
6401 case Token.CONTINUE:
6405 case Token.DELEGATE:
6415 case Token.EXPLICIT:
6433 case Token.IMPLICIT:
6437 case Token.INTERFACE:
6439 case Token.INTERNAL:
6445 case Token.NAMESPACE:
6451 case Token.OPERATOR:
6455 case Token.OVERRIDE:
6461 case Token.PROTECTED:
6465 case Token.READONLY:
6477 case Token.STACKALLOC:
6478 return "stackalloc";
6495 case Token.UNCHECKED:
6503 case Token.VOLATILE:
6516 case Token.FROM_FIRST:
6534 case Token.ASCENDING:
6536 case Token.DESCENDING:
6537 return "descending";
6544 case Token.OPEN_BRACE:
6546 case Token.CLOSE_BRACE:
6548 case Token.OPEN_BRACKET:
6550 case Token.CLOSE_BRACKET:
6552 case Token.OPEN_PARENS_CAST:
6553 case Token.OPEN_PARENS_LAMBDA:
6554 case Token.OPEN_PARENS:
6556 case Token.CLOSE_PARENS:
6562 case Token.DEFAULT_COLON:
6566 case Token.SEMICOLON:
6577 case Token.BITWISE_AND:
6578 case Token.BITWISE_OR:
6585 case Token.OP_SHIFT_LEFT:
6586 case Token.OP_SHIFT_RIGHT:
6594 case Token.OP_COALESCING:
6595 case Token.OP_MULT_ASSIGN:
6596 case Token.OP_DIV_ASSIGN:
6597 case Token.OP_MOD_ASSIGN:
6598 case Token.OP_ADD_ASSIGN:
6599 case Token.OP_SUB_ASSIGN:
6600 case Token.OP_SHIFT_LEFT_ASSIGN:
6601 case Token.OP_SHIFT_RIGHT_ASSIGN:
6602 case Token.OP_AND_ASSIGN:
6603 case Token.OP_XOR_ASSIGN:
6604 case Token.OP_OR_ASSIGN:
6605 return "<operator>";
6627 case Token.OP_GENERICS_LT:
6628 case Token.GENERIC_DIMENSION:
6630 case Token.OP_GENERICS_GT:
6633 case Token.INTERR_NULLABLE:
6635 case Token.DOUBLE_COLON:
6637 case Token.LITERAL_FLOAT:
6638 case Token.LITERAL_INTEGER:
6639 case Token.LITERAL_DOUBLE:
6640 case Token.LITERAL_DECIMAL:
6641 case Token.LITERAL_CHARACTER:
6642 case Token.LITERAL_STRING:
6644 case Token.IDENTIFIER:
6645 return "identifier";
6647 // All of these are internal.
6650 case Token.FIRST_KEYWORD:
6652 case Token.EVAL_COMPILATION_UNIT_PARSER:
6653 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6654 case Token.EVAL_STATEMENT_PARSER:
6655 case Token.LAST_KEYWORD:
6656 case Token.GENERATE_COMPLETION:
6657 case Token.COMPLETE_COMPLETION:
6658 return "<internal>";
6660 // A bit more robust.
6662 return yyNames [token];