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
333 /* Add precedence rules to solve dangling else s/r conflict */
337 /* Define the operator tokens and their precedences */
345 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
347 %left STAR DIV PERCENT
348 %right BANG CARRET UMINUS
349 %nonassoc OP_INC OP_DEC
351 %left OPEN_BRACKET OPEN_BRACE
354 %start compilation_unit
358 : outer_declarations opt_EOF
359 | outer_declarations global_attributes opt_EOF
360 | global_attributes opt_EOF
361 | opt_EOF /* allow empty files */
362 | interactive_parsing opt_EOF
368 Lexer.check_incorrect_doc_comment ();
372 Lexer.check_incorrect_doc_comment ();
378 | outer_declarations outer_declaration
382 : extern_alias_directive
384 | namespace_member_declaration
387 extern_alias_directives
388 : extern_alias_directive
389 | extern_alias_directives extern_alias_directive
392 extern_alias_directive
393 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
395 LocatedToken lt = (LocatedToken) $2;
398 syntax_error (lt.Location, "`alias' expected");
399 } else if (RootContext.Version == LanguageVersion.ISO_1) {
400 Report.FeatureIsNotAvailable (lt.Location, "external alias");
402 lt = (LocatedToken) $3;
403 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location);
408 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
414 | using_directives using_directive
418 : using_alias_directive
420 if (RootContext.Documentation != null)
421 Lexer.doc_state = XmlCommentState.Allowed;
423 | using_namespace_directive
425 if (RootContext.Documentation != null)
426 Lexer.doc_state = XmlCommentState.Allowed;
430 using_alias_directive
431 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
433 LocatedToken lt = (LocatedToken) $2;
434 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1);
437 CheckIdentifierToken (yyToken, GetLocation ($2));
442 using_namespace_directive
443 : USING namespace_name SEMICOLON
445 current_namespace.AddUsing ((MemberName) $2, (Location) $1);
450 // Strictly speaking, namespaces don't have attributes but
451 // we parse global attributes along with namespace declarations and then
454 namespace_declaration
455 : opt_attributes NAMESPACE qualified_identifier
457 MemberName name = (MemberName) $3;
460 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
463 current_namespace = new NamespaceEntry (
464 current_namespace, file, name.GetName ());
465 current_class = current_namespace.SlaveDeclSpace;
466 current_container = current_class.PartialContainer;
468 namespace_body opt_semicolon
470 current_namespace = current_namespace.Parent;
471 current_class = current_namespace.SlaveDeclSpace;
472 current_container = current_class.PartialContainer;
479 LocatedToken lt = (LocatedToken) $1;
480 $$ = new MemberName (lt.Value, lt.Location);
482 | qualified_identifier DOT IDENTIFIER
484 LocatedToken lt = (LocatedToken) $3;
485 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
489 syntax_error (lexer.Location, "`.' expected");
504 : namespace_or_type_name
506 MemberName name = (MemberName) $1;
508 if (name.TypeArguments != null)
509 syntax_error (lexer.Location, "namespace name expected");
518 if (RootContext.Documentation != null)
519 Lexer.doc_state = XmlCommentState.Allowed;
525 : opt_extern_alias_directives
527 opt_namespace_member_declarations
531 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
534 | opt_extern_alias_directives
536 opt_namespace_member_declarations
539 Report.Error (1513, lexer.Location, "Expected `}'");
548 opt_extern_alias_directives
550 | extern_alias_directives
553 opt_namespace_member_declarations
555 | namespace_member_declarations
558 namespace_member_declarations
559 : namespace_member_declaration
560 | namespace_member_declarations namespace_member_declaration
563 namespace_member_declaration
567 DeclSpace ds = (DeclSpace)$1;
569 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
570 Report.Error (1527, ds.Location,
571 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
574 current_namespace.DeclarationFound = true;
576 | namespace_declaration {
577 current_namespace.DeclarationFound = true;
580 | field_declaration {
581 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
583 | method_declaration {
584 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
591 | interface_declaration
593 | delegate_declaration
595 // Enable this when we have handled all errors, because this acts as a generic fallback
598 // Console.WriteLine ("Token=" + yyToken);
599 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
611 Attributes attrs = (Attributes)$1;
612 if (global_attrs_enabled) {
613 CodeGen.Assembly.AddAttributes (attrs.Attrs);
615 foreach (Attribute a in attrs.Attrs) {
616 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
627 global_attrs_enabled = false;
632 global_attrs_enabled = false;
641 if (current_attr_target != String.Empty) {
642 ArrayList sect = (ArrayList) $1;
644 if (global_attrs_enabled) {
645 if (current_attr_target == "module") {
646 CodeGen.Module.AddAttributes (sect);
648 } else if (current_attr_target != null && current_attr_target.Length > 0) {
649 CodeGen.Assembly.AddAttributes (sect);
652 $$ = new Attributes (sect);
655 if (RootContext.Documentation != null) {
656 Lexer.check_incorrect_doc_comment ();
658 XmlCommentState.Allowed;
662 $$ = new Attributes (sect);
667 current_attr_target = null;
669 | attribute_sections attribute_section
671 if (current_attr_target != String.Empty) {
672 Attributes attrs = $1 as Attributes;
673 ArrayList sect = (ArrayList) $2;
675 if (global_attrs_enabled) {
676 if (current_attr_target == "module") {
677 CodeGen.Module.AddAttributes (sect);
679 } else if (current_attr_target == "assembly") {
680 CodeGen.Assembly.AddAttributes (sect);
684 attrs = new Attributes (sect);
686 attrs.AddAttributes (sect);
690 attrs = new Attributes (sect);
692 attrs.AddAttributes (sect);
698 current_attr_target = null;
703 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
707 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
713 attribute_target_specifier
714 : attribute_target COLON
716 current_attr_target = (string)$1;
724 LocatedToken lt = (LocatedToken) $1;
725 $$ = CheckAttributeTarget (lt.Value, lt.Location);
727 | EVENT { $$ = "event"; }
728 | RETURN { $$ = "return"; }
731 string name = GetTokenName (yyToken);
732 $$ = CheckAttributeTarget (name, GetLocation ($1));
739 ArrayList attrs = new ArrayList (4);
745 | attribute_list COMMA attribute
747 ArrayList attrs = (ArrayList) $1;
757 ++lexer.parsing_block;
759 opt_attribute_arguments
761 --lexer.parsing_block;
762 MemberName mname = (MemberName) $1;
763 if (mname.IsGeneric) {
764 Report.Error (404, lexer.Location,
765 "'<' unexpected: attributes cannot be generic");
768 object [] arguments = (object []) $3;
769 MemberName left = mname.Left;
770 string identifier = mname.Name;
772 Expression left_expr = left == null ? null : left.GetTypeExpression ();
774 if (current_attr_target == String.Empty)
776 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
777 // FIXME: supply "nameEscaped" parameter here.
778 $$ = new GlobalAttribute (current_namespace, current_attr_target,
779 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
781 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
786 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
789 opt_attribute_arguments
790 : /* empty */ { $$ = null; }
791 | OPEN_PARENS attribute_arguments CLOSE_PARENS
799 : opt_positional_argument_list
804 $$ = new object [] { $1, null };
807 | positional_argument_list COMMA named_argument_list
809 $$ = new object[] { $1, $3 };
811 | named_argument_list
813 $$ = new object [] { null, $1 };
818 opt_positional_argument_list
819 : /* empty */ { $$ = null; }
820 | positional_argument_list
823 positional_argument_list
826 ArrayList args = new ArrayList (4);
827 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
831 | positional_argument_list COMMA expression
833 ArrayList args = (ArrayList) $1;
834 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
843 ArrayList args = new ArrayList (4);
848 | named_argument_list COMMA named_argument
850 ArrayList args = (ArrayList) $1;
855 | named_argument_list COMMA expression
857 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
863 : IDENTIFIER ASSIGN expression
865 // FIXME: keep location
866 $$ = new DictionaryEntry (
867 ((LocatedToken) $1).Value,
868 new Argument ((Expression) $3, Argument.AType.Expression));
874 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
877 opt_class_member_declarations
879 | class_member_declarations
882 class_member_declarations
883 : class_member_declaration
884 | class_member_declarations
885 class_member_declaration
888 class_member_declaration
889 : constant_declaration // done
890 | field_declaration // done
891 | method_declaration // done
892 | property_declaration // done
893 | event_declaration // done
894 | indexer_declaration // done
895 | operator_declaration // done
896 | constructor_declaration // done
897 | destructor_declaration // done
901 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
902 GetSymbolName (yyToken));
904 lexer.parsing_generic_declaration = false;
914 lexer.ConstraintsParsing = true;
916 type_declaration_name
918 MemberName name = MakeName ((MemberName) $6);
919 push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
922 opt_type_parameter_constraints_clauses
924 lexer.ConstraintsParsing = false;
926 current_class.SetParameterInfo ((ArrayList) $9);
928 if (RootContext.Documentation != null)
929 current_container.DocComment = Lexer.consume_doc_comment ();
933 --lexer.parsing_declaration;
934 if (RootContext.Documentation != null)
935 Lexer.doc_state = XmlCommentState.Allowed;
939 $$ = pop_current_class ();
941 | opt_attributes opt_modifiers opt_partial STRUCT error {
942 CheckIdentifierToken (yyToken, GetLocation ($5));
949 if (RootContext.Documentation != null)
950 Lexer.doc_state = XmlCommentState.Allowed;
952 opt_struct_member_declarations CLOSE_BRACE
955 opt_struct_member_declarations
957 | struct_member_declarations
960 struct_member_declarations
961 : struct_member_declaration
962 | struct_member_declarations struct_member_declaration
965 struct_member_declaration
966 : constant_declaration
969 | property_declaration
971 | indexer_declaration
972 | operator_declaration
973 | constructor_declaration
977 * This is only included so we can flag error 575:
978 * destructors only allowed on class types
980 | destructor_declaration
991 int modflags = (int) $2;
992 foreach (VariableDeclaration constant in (ArrayList) $5){
993 Location l = constant.Location;
994 if ((modflags & Modifiers.STATIC) != 0) {
995 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
999 Const c = new Const (
1000 current_class, (FullNamedExpression) $4, (string) constant.identifier,
1001 (Expression) constant.expression_or_array_initializer, modflags,
1002 (Attributes) $1, l);
1004 if (RootContext.Documentation != null) {
1005 c.DocComment = Lexer.consume_doc_comment ();
1006 Lexer.doc_state = XmlCommentState.Allowed;
1008 current_container.AddConstant (c);
1013 constant_declarators
1014 : constant_declarator
1016 ArrayList constants = new ArrayList (4);
1021 | constant_declarators COMMA constant_declarator
1024 ArrayList constants = (ArrayList) $1;
1033 ++lexer.parsing_block;
1035 constant_initializer
1037 --lexer.parsing_block;
1038 $$ = new VariableDeclaration ((LocatedToken) $1, $4);
1042 // A const field requires a value to be provided
1043 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
1048 constant_initializer
1049 : constant_expression
1057 variable_declarators
1060 FullNamedExpression type = (FullNamedExpression) $3;
1061 if (type == TypeManager.system_void_expr)
1062 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1066 current_array_type = null;
1068 foreach (VariableMemberDeclaration var in (ArrayList) $4){
1069 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1071 field.Initializer = var.expression_or_array_initializer;
1073 if (RootContext.Documentation != null) {
1074 field.DocComment = Lexer.consume_doc_comment ();
1075 Lexer.doc_state = XmlCommentState.Allowed;
1077 current_container.AddField (field);
1078 $$ = field; // FIXME: might be better if it points to the top item
1085 fixed_variable_declarators
1088 FullNamedExpression type = (FullNamedExpression) $4;
1092 current_array_type = null;
1094 foreach (VariableDeclaration var in (ArrayList) $5) {
1095 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1096 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1098 if (RootContext.Documentation != null) {
1099 field.DocComment = Lexer.consume_doc_comment ();
1100 Lexer.doc_state = XmlCommentState.Allowed;
1102 current_container.AddField (field);
1103 $$ = field; // FIXME: might be better if it points to the top item
1112 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1116 fixed_variable_declarators
1117 : fixed_variable_declarator
1119 ArrayList decl = new ArrayList (2);
1123 | fixed_variable_declarators COMMA fixed_variable_declarator
1125 ArrayList decls = (ArrayList) $1;
1131 fixed_variable_declarator
1132 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1134 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1136 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1138 Report.Error (443, lexer.Location, "Value or constant expected");
1139 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1144 local_variable_declarators
1145 : local_variable_declarator
1147 ArrayList decl = new ArrayList (4);
1152 | local_variable_declarators COMMA local_variable_declarator
1154 ArrayList decls = (ArrayList) $1;
1160 local_variable_declarator
1161 : IDENTIFIER ASSIGN local_variable_initializer
1163 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1167 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1169 | IDENTIFIER variable_bad_array
1175 local_variable_initializer
1178 | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET
1180 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1184 $$ = new ArglistAccess ((Location) $1);
1186 | STACKALLOC simple_type
1188 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1189 $$ = new StackAlloc ((Expression) $2, null, (Location) $1);
1193 variable_declarators
1194 : variable_declarator
1196 ArrayList decl = new ArrayList (4);
1201 | variable_declarators COMMA variable_declarator
1203 ArrayList decls = (ArrayList) $1;
1210 : member_declaration_name ASSIGN
1212 ++lexer.parsing_block;
1213 lexer.parsing_generic_declaration = false;
1215 variable_initializer
1217 --lexer.parsing_block;
1218 $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
1220 | member_declaration_name
1222 lexer.parsing_generic_declaration = false;
1223 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1225 | member_declaration_name variable_bad_array
1227 lexer.parsing_generic_declaration = false;
1233 : OPEN_BRACKET opt_expression CLOSE_BRACKET
1235 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1236 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1240 variable_initializer
1247 if (RootContext.Documentation != null)
1248 Lexer.doc_state = XmlCommentState.NotAllowed;
1252 Method method = (Method) $1;
1253 method.Block = (ToplevelBlock) $3;
1254 current_container.AddMethod (method);
1256 if (current_container.Kind == Kind.Interface && method.Block != null) {
1257 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1260 current_generic_method = null;
1261 current_local_parameters = null;
1263 if (RootContext.Documentation != null)
1264 Lexer.doc_state = XmlCommentState.Allowed;
1272 method_declaration_name OPEN_PARENS
1274 arglist_allowed = true;
1276 opt_formal_parameter_list CLOSE_PARENS
1278 lexer.ConstraintsParsing = true;
1280 opt_type_parameter_constraints_clauses
1282 lexer.ConstraintsParsing = false;
1283 arglist_allowed = false;
1284 MemberName name = (MemberName) $4;
1285 current_local_parameters = (ParametersCompiled) $7;
1287 if ($10 != null && name.TypeArguments == null)
1288 Report.Error (80, lexer.Location,
1289 "Constraints are not allowed on non-generic declarations");
1293 GenericMethod generic = null;
1294 if (name.TypeArguments != null) {
1295 generic = new GenericMethod (current_namespace, current_class, name,
1296 (FullNamedExpression) $3, current_local_parameters);
1298 generic.SetParameterInfo ((ArrayList) $10);
1301 method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2,
1302 name, current_local_parameters, (Attributes) $1);
1304 current_generic_method = generic;
1306 if (RootContext.Documentation != null)
1307 method.DocComment = Lexer.consume_doc_comment ();
1314 VOID method_declaration_name
1315 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1317 lexer.ConstraintsParsing = true;
1319 opt_type_parameter_constraints_clauses
1321 lexer.ConstraintsParsing = false;
1323 MemberName name = (MemberName) $5;
1324 current_local_parameters = (ParametersCompiled) $7;
1326 if ($9 != null && name.TypeArguments == null)
1327 Report.Error (80, lexer.Location,
1328 "Constraints are not allowed on non-generic declarations");
1331 GenericMethod generic = null;
1332 if (name.TypeArguments != null) {
1333 generic = new GenericMethod (current_namespace, current_class, name,
1334 TypeManager.system_void_expr, current_local_parameters);
1336 generic.SetParameterInfo ((ArrayList) $10);
1339 int modifiers = (int) $2;
1342 const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN |
1343 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1345 if ((modifiers & invalid_partial_mod) != 0) {
1346 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1347 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1348 modifiers &= ~invalid_partial_mod;
1351 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1352 Report.Error (751, name.Location, "A partial method must be declared within a " +
1353 "partial class or partial struct");
1356 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1358 method = new Method (current_class, generic, TypeManager.system_void_expr,
1359 modifiers, name, current_local_parameters, (Attributes) $1);
1361 current_generic_method = generic;
1363 if (RootContext.Documentation != null)
1364 method.DocComment = Lexer.consume_doc_comment ();
1371 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1373 MemberName name = (MemberName) $5;
1374 Report.Error (1585, name.Location,
1375 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1377 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1378 0, name, (ParametersCompiled) $7, (Attributes) $1);
1380 current_local_parameters = (ParametersCompiled) $7;
1382 if (RootContext.Documentation != null)
1383 method.DocComment = Lexer.consume_doc_comment ();
1391 | SEMICOLON { $$ = null; }
1394 opt_formal_parameter_list
1395 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1396 | formal_parameter_list
1399 opt_parameter_list_no_mod
1400 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1403 parameter_modifiers_not_allowed = true;
1405 formal_parameter_list
1407 parameter_modifiers_not_allowed = false;
1412 formal_parameter_list
1415 ArrayList pars_list = (ArrayList) $1;
1417 Parameter [] pars = new Parameter [pars_list.Count];
1418 pars_list.CopyTo (pars);
1420 $$ = new ParametersCompiled (pars);
1422 | fixed_parameters COMMA parameter_array
1424 ArrayList pars_list = (ArrayList) $1;
1427 Parameter [] pars = new Parameter [pars_list.Count];
1428 pars_list.CopyTo (pars);
1430 $$ = new ParametersCompiled (pars);
1432 | fixed_parameters COMMA arglist_modifier
1434 ArrayList pars_list = (ArrayList) $1;
1435 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1437 Parameter [] pars = new Parameter [pars_list.Count];
1438 pars_list.CopyTo (pars);
1440 $$ = new ParametersCompiled (pars, true);
1442 | parameter_array COMMA error
1445 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1448 | fixed_parameters COMMA parameter_array COMMA error
1451 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1454 | arglist_modifier COMMA error
1456 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1459 | fixed_parameters COMMA ARGLIST COMMA error
1461 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1466 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1470 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true);
1477 ArrayList pars = new ArrayList (4);
1482 | fixed_parameters COMMA fixed_parameter
1484 ArrayList pars = (ArrayList) $1;
1485 Parameter p = (Parameter)$3;
1487 if (p.HasExtensionMethodModifier)
1488 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1497 opt_parameter_modifier
1501 LocatedToken lt = (LocatedToken) $4;
1502 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1505 opt_parameter_modifier
1507 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1509 LocatedToken lt = (LocatedToken) $4;
1510 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1514 opt_parameter_modifier
1517 Report.Error (1001, GetLocation ($3), "Identifier expected");
1518 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
1521 opt_parameter_modifier
1524 CheckIdentifierToken (yyToken, GetLocation ($4));
1528 opt_parameter_modifier
1534 LocatedToken lt = (LocatedToken) $4;
1535 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1540 opt_parameter_modifier
1541 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1542 | parameter_modifiers
1546 : parameter_modifier
1550 | parameter_modifiers parameter_modifier
1552 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1553 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1554 if (((Parameter.Modifier)$1 & p2) == p2) {
1555 Error_DuplicateParameterModifier (lexer.Location, p2);
1557 switch (mod & ~Parameter.Modifier.This) {
1558 case Parameter.Modifier.REF:
1559 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1561 case Parameter.Modifier.OUT:
1562 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1565 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1576 if (parameter_modifiers_not_allowed)
1577 Error_ParameterModifierNotValid ("ref", (Location)$1);
1579 $$ = Parameter.Modifier.REF;
1583 if (parameter_modifiers_not_allowed)
1584 Error_ParameterModifierNotValid ("out", (Location)$1);
1586 $$ = Parameter.Modifier.OUT;
1590 if (parameter_modifiers_not_allowed)
1591 Error_ParameterModifierNotValid ("this", (Location)$1);
1593 if (RootContext.Version <= LanguageVersion.ISO_2)
1594 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1596 $$ = Parameter.Modifier.This;
1601 : opt_attributes params_modifier type IDENTIFIER
1603 LocatedToken lt = (LocatedToken) $4;
1604 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1606 | opt_attributes params_modifier type error {
1607 CheckIdentifierToken (yyToken, GetLocation ($4));
1615 if (params_modifiers_not_allowed)
1616 Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context");
1618 | PARAMS parameter_modifier
1620 Parameter.Modifier mod = (Parameter.Modifier)$2;
1621 if ((mod & Parameter.Modifier.This) != 0) {
1622 Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether");
1624 Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out");
1627 | PARAMS params_modifier
1629 Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS);
1636 if (!arglist_allowed)
1637 Report.Error (1669, (Location) $1, "__arglist is not valid in this context");
1641 property_declaration
1645 member_declaration_name
1647 if (RootContext.Documentation != null)
1648 tmpComment = Lexer.consume_doc_comment ();
1652 implicit_value_parameter_type = (FullNamedExpression) $3;
1653 lexer.PropertyParsing = true;
1655 accessor_declarations
1657 lexer.PropertyParsing = false;
1658 has_get = has_set = false;
1663 Accessors accessors = (Accessors) $8;
1664 Accessor get_block = accessors != null ? accessors.get_or_add : null;
1665 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
1666 bool order = accessors != null ? accessors.declared_in_reverse : false;
1668 MemberName name = (MemberName) $4;
1669 FullNamedExpression ptype = (FullNamedExpression) $3;
1671 prop = new Property (current_class, ptype, (int) $2,
1672 name, (Attributes) $1, get_block, set_block, order, current_block);
1674 if (ptype == TypeManager.system_void_expr)
1675 Report.Error (547, name.Location, "`{0}': property or indexer cannot have void type", prop.GetSignatureForError ());
1677 if (accessors == null)
1678 Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ());
1680 if (current_container.Kind == Kind.Interface) {
1681 if (prop.Get.Block != null)
1682 Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ());
1684 if (prop.Set.Block != null)
1685 Report.Error (531, prop.Location, "`{0}.set': interface members cannot have a definition", prop.GetSignatureForError ());
1688 current_container.AddProperty (prop);
1689 implicit_value_parameter_type = null;
1691 if (RootContext.Documentation != null)
1692 prop.DocComment = ConsumeStoredComment ();
1697 accessor_declarations
1698 : get_accessor_declaration
1700 $$ = new Accessors ((Accessor) $1, null);
1702 | get_accessor_declaration accessor_declarations
1704 Accessors accessors = (Accessors) $2;
1705 accessors.get_or_add = (Accessor) $1;
1708 | set_accessor_declaration
1710 $$ = new Accessors (null, (Accessor) $1);
1712 | set_accessor_declaration accessor_declarations
1714 Accessors accessors = (Accessors) $2;
1715 accessors.set_or_remove = (Accessor) $1;
1716 accessors.declared_in_reverse = true;
1721 if (yyToken == Token.CLOSE_BRACE) {
1724 if (yyToken == Token.SEMICOLON)
1725 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1727 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1729 $$ = new Accessors (null, null);
1734 get_accessor_declaration
1735 : opt_attributes opt_modifiers GET
1737 // If this is not the case, then current_local_parameters has already
1738 // been set in indexer_declaration
1739 if (parsing_indexer == false)
1740 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1742 current_local_parameters = indexer_parameters;
1743 lexer.PropertyParsing = false;
1748 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1751 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1753 current_local_parameters = null;
1754 lexer.PropertyParsing = true;
1756 if (RootContext.Documentation != null)
1757 if (Lexer.doc_state == XmlCommentState.Error)
1758 Lexer.doc_state = XmlCommentState.NotAllowed;
1764 set_accessor_declaration
1765 : opt_attributes opt_modifiers SET
1767 Parameter implicit_value_parameter = new Parameter (
1768 implicit_value_parameter_type, "value",
1769 Parameter.Modifier.NONE, null, (Location) $3);
1771 if (!parsing_indexer) {
1772 current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter });
1774 current_local_parameters = ParametersCompiled.MergeGenerated (
1775 indexer_parameters, true, implicit_value_parameter, null);
1778 lexer.PropertyParsing = false;
1783 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1786 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3);
1788 current_local_parameters = null;
1789 lexer.PropertyParsing = true;
1791 if (RootContext.Documentation != null
1792 && Lexer.doc_state == XmlCommentState.Error)
1793 Lexer.doc_state = XmlCommentState.NotAllowed;
1807 Error_SyntaxError (1043, yyToken);
1812 interface_declaration
1818 lexer.ConstraintsParsing = true;
1820 type_declaration_name
1822 MemberName name = MakeName ((MemberName) $6);
1823 push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
1826 opt_type_parameter_constraints_clauses
1828 lexer.ConstraintsParsing = false;
1830 current_class.SetParameterInfo ((ArrayList) $9);
1832 if (RootContext.Documentation != null) {
1833 current_container.DocComment = Lexer.consume_doc_comment ();
1834 Lexer.doc_state = XmlCommentState.Allowed;
1839 --lexer.parsing_declaration;
1840 if (RootContext.Documentation != null)
1841 Lexer.doc_state = XmlCommentState.Allowed;
1845 $$ = pop_current_class ();
1847 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1848 CheckIdentifierToken (yyToken, GetLocation ($5));
1854 opt_interface_member_declarations
1858 opt_interface_member_declarations
1860 | interface_member_declarations
1863 interface_member_declarations
1864 : interface_member_declaration
1865 | interface_member_declarations interface_member_declaration
1868 interface_member_declaration
1869 : constant_declaration
1871 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1875 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1877 | method_declaration
1878 | property_declaration
1880 | indexer_declaration
1881 | operator_declaration
1883 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1885 | constructor_declaration
1887 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1891 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1895 operator_declaration
1896 : opt_attributes opt_modifiers operator_declarator
1904 OperatorDeclaration decl = (OperatorDeclaration) $3;
1905 Operator op = new Operator (
1906 current_class, decl.optype, decl.ret_type, (int) $2,
1907 current_local_parameters,
1908 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1910 if (RootContext.Documentation != null) {
1911 op.DocComment = tmpComment;
1912 Lexer.doc_state = XmlCommentState.Allowed;
1915 // Note again, checking is done in semantic analysis
1916 current_container.AddOperator (op);
1918 current_local_parameters = null;
1924 | SEMICOLON { $$ = null; }
1928 : type_expression_or_array
1931 Report.Error (590, lexer.Location, "User-defined operators cannot return void");
1932 $$ = TypeManager.system_void_expr;
1937 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1939 params_modifiers_not_allowed = true;
1941 opt_parameter_list_no_mod CLOSE_PARENS
1943 params_modifiers_not_allowed = false;
1945 Location loc = (Location) $2;
1946 Operator.OpType op = (Operator.OpType) $3;
1947 current_local_parameters = (ParametersCompiled)$6;
1949 int p_count = current_local_parameters.Count;
1951 if (op == Operator.OpType.Addition)
1952 op = Operator.OpType.UnaryPlus;
1953 else if (op == Operator.OpType.Subtraction)
1954 op = Operator.OpType.UnaryNegation;
1957 if (IsUnaryOperator (op)) {
1959 Report.Error (1020, loc, "Overloadable binary operator expected");
1960 } else if (p_count != 1) {
1961 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1962 Operator.GetName (op));
1966 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1967 Operator.GetName (op));
1968 } else if (p_count != 2) {
1969 Report.Error (1019, loc, "Overloadable unary operator expected");
1973 if (RootContext.Documentation != null) {
1974 tmpComment = Lexer.consume_doc_comment ();
1975 Lexer.doc_state = XmlCommentState.NotAllowed;
1978 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
1980 | conversion_operator_declarator
1983 overloadable_operator
1985 : BANG { $$ = Operator.OpType.LogicalNot; }
1986 | TILDE { $$ = Operator.OpType.OnesComplement; }
1987 | OP_INC { $$ = Operator.OpType.Increment; }
1988 | OP_DEC { $$ = Operator.OpType.Decrement; }
1989 | TRUE { $$ = Operator.OpType.True; }
1990 | FALSE { $$ = Operator.OpType.False; }
1991 // Unary and binary:
1992 | PLUS { $$ = Operator.OpType.Addition; }
1993 | MINUS { $$ = Operator.OpType.Subtraction; }
1995 | STAR { $$ = Operator.OpType.Multiply; }
1996 | DIV { $$ = Operator.OpType.Division; }
1997 | PERCENT { $$ = Operator.OpType.Modulus; }
1998 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
1999 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2000 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2001 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2002 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2003 | OP_EQ { $$ = Operator.OpType.Equality; }
2004 | OP_NE { $$ = Operator.OpType.Inequality; }
2005 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2006 | OP_LT { $$ = Operator.OpType.LessThan; }
2007 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2008 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2011 conversion_operator_declarator
2012 : IMPLICIT OPERATOR type OPEN_PARENS
2014 params_modifiers_not_allowed = true;
2016 opt_parameter_list_no_mod CLOSE_PARENS
2018 params_modifiers_not_allowed = false;
2020 Location loc = (Location) $2;
2021 current_local_parameters = (ParametersCompiled)$6;
2023 if (RootContext.Documentation != null) {
2024 tmpComment = Lexer.consume_doc_comment ();
2025 Lexer.doc_state = XmlCommentState.NotAllowed;
2028 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2030 | EXPLICIT OPERATOR type OPEN_PARENS
2032 params_modifiers_not_allowed = true;
2034 opt_parameter_list_no_mod CLOSE_PARENS
2036 params_modifiers_not_allowed = false;
2038 Location loc = (Location) $2;
2039 current_local_parameters = (ParametersCompiled)$6;
2041 if (RootContext.Documentation != null) {
2042 tmpComment = Lexer.consume_doc_comment ();
2043 Lexer.doc_state = XmlCommentState.NotAllowed;
2046 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2050 Error_SyntaxError (yyToken);
2051 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2055 Error_SyntaxError (yyToken);
2056 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2060 constructor_declaration
2061 : constructor_declarator
2064 Constructor c = (Constructor) $1;
2065 c.Block = (ToplevelBlock) $2;
2067 if (RootContext.Documentation != null)
2068 c.DocComment = ConsumeStoredComment ();
2070 current_container.AddConstructor (c);
2072 current_local_parameters = null;
2073 if (RootContext.Documentation != null)
2074 Lexer.doc_state = XmlCommentState.Allowed;
2078 constructor_declarator
2083 if (RootContext.Documentation != null) {
2084 tmpComment = Lexer.consume_doc_comment ();
2085 Lexer.doc_state = XmlCommentState.Allowed;
2088 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2090 current_local_parameters = (ParametersCompiled) $6;
2093 // start block here, so possible anonymous methods inside
2094 // constructor initializer can get correct parent block
2096 start_block (lexer.Location);
2098 opt_constructor_initializer
2100 LocatedToken lt = (LocatedToken) $3;
2101 int mods = (int) $2;
2102 ConstructorInitializer ci = (ConstructorInitializer) $9;
2104 Constructor c = new Constructor (current_class, lt.Value, mods,
2105 (Attributes) $1, current_local_parameters, ci, lt.Location);
2107 if (lt.Value != current_container.MemberName.Name) {
2108 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2109 } else if ((mods & Modifiers.STATIC) != 0) {
2110 if ((mods & Modifiers.Accessibility) != 0){
2111 Report.Error (515, c.Location,
2112 "`{0}': static constructor cannot have an access modifier",
2113 c.GetSignatureForError ());
2116 Report.Error (514, c.Location,
2117 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2118 c.GetSignatureForError ());
2129 | SEMICOLON { current_block = null; $$ = null; }
2132 opt_constructor_initializer
2134 | constructor_initializer
2137 constructor_initializer
2138 : COLON BASE OPEN_PARENS
2140 ++lexer.parsing_block;
2142 opt_argument_list CLOSE_PARENS
2144 --lexer.parsing_block;
2145 $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2);
2147 | COLON THIS OPEN_PARENS
2149 ++lexer.parsing_block;
2151 opt_argument_list CLOSE_PARENS
2153 --lexer.parsing_block;
2154 $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2);
2157 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2162 destructor_declaration
2163 : opt_attributes opt_modifiers TILDE
2165 if (RootContext.Documentation != null) {
2166 tmpComment = Lexer.consume_doc_comment ();
2167 Lexer.doc_state = XmlCommentState.NotAllowed;
2170 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2172 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2174 LocatedToken lt = (LocatedToken) $5;
2175 if (lt.Value != current_container.MemberName.Name){
2176 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2177 } else if (current_container.Kind != Kind.Class){
2178 Report.Error (575, lt.Location, "Only class types can contain destructor");
2180 Destructor d = new Destructor (current_class, (int) $2,
2181 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2182 if (RootContext.Documentation != null)
2183 d.DocComment = ConsumeStoredComment ();
2185 d.Block = (ToplevelBlock) $8;
2186 current_container.AddMethod (d);
2189 current_local_parameters = null;
2196 EVENT type variable_declarators SEMICOLON
2198 current_array_type = null;
2199 foreach (VariableMemberDeclaration var in (ArrayList) $5) {
2201 EventField e = new EventField (
2202 current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
2204 if (var.expression_or_array_initializer != null) {
2205 if (current_container.Kind == Kind.Interface) {
2206 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2209 e.Initializer = var.expression_or_array_initializer;
2212 if (var.MemberName.Left != null) {
2213 Report.Error (71, e.Location,
2214 "`{0}': An explicit interface implementation of an event must use property syntax",
2215 e.GetSignatureForError ());
2218 current_container.AddEvent (e);
2220 if (RootContext.Documentation != null) {
2221 e.DocComment = Lexer.consume_doc_comment ();
2222 Lexer.doc_state = XmlCommentState.Allowed;
2228 EVENT type member_declaration_name
2231 implicit_value_parameter_type = (FullNamedExpression) $4;
2232 current_local_parameters = new ParametersCompiled (
2233 new Parameter (implicit_value_parameter_type, "value",
2234 Parameter.Modifier.NONE, null, GetLocation ($3)));
2236 lexer.EventParsing = true;
2238 event_accessor_declarations
2240 lexer.EventParsing = false;
2244 MemberName name = (MemberName) $5;
2246 if (current_container.Kind == Kind.Interface) {
2247 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
2251 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2252 current_container.Name, name.GetSignatureForError ());
2255 Accessors accessors = (Accessors) $8;
2257 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2258 // CS0073 is already reported, so no CS0065 here.
2261 Event e = new EventProperty (
2262 current_class, (FullNamedExpression) $4, (int) $2, name,
2263 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2264 if (RootContext.Documentation != null) {
2265 e.DocComment = Lexer.consume_doc_comment ();
2266 Lexer.doc_state = XmlCommentState.Allowed;
2269 current_container.AddEvent (e);
2270 implicit_value_parameter_type = null;
2273 current_local_parameters = null;
2275 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2277 MemberName mn = (MemberName) $5;
2278 if (mn.Left != null)
2279 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2281 if (RootContext.Documentation != null)
2282 Lexer.doc_state = XmlCommentState.Allowed;
2284 Error_SyntaxError (yyToken);
2289 event_accessor_declarations
2290 : add_accessor_declaration remove_accessor_declaration
2292 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2294 | remove_accessor_declaration add_accessor_declaration
2296 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2297 accessors.declared_in_reverse = true;
2300 | add_accessor_declaration { $$ = null; }
2301 | remove_accessor_declaration { $$ = null; }
2304 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2310 add_accessor_declaration
2311 : opt_attributes ADD
2313 lexer.EventParsing = false;
2317 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2318 lexer.EventParsing = true;
2321 | opt_attributes ADD error {
2322 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2325 | opt_attributes modifiers ADD {
2326 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2331 remove_accessor_declaration
2332 : opt_attributes REMOVE
2334 lexer.EventParsing = false;
2338 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2);
2339 lexer.EventParsing = true;
2341 | opt_attributes REMOVE error {
2342 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2345 | opt_attributes modifiers REMOVE {
2346 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2352 : opt_attributes opt_modifiers
2353 member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET
2356 implicit_value_parameter_type = (FullNamedExpression) $3;
2357 indexer_parameters = (ParametersCompiled) $6;
2359 if (indexer_parameters.IsEmpty)
2360 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2362 if (RootContext.Documentation != null) {
2363 tmpComment = Lexer.consume_doc_comment ();
2364 Lexer.doc_state = XmlCommentState.Allowed;
2367 lexer.PropertyParsing = true;
2368 parsing_indexer = true;
2371 accessor_declarations
2373 lexer.PropertyParsing = false;
2374 has_get = has_set = false;
2375 parsing_indexer = false;
2379 Accessors accessors = (Accessors) $10;
2380 Accessor get_block = accessors != null ? accessors.get_or_add : null;
2381 Accessor set_block = accessors != null ? accessors.set_or_remove : null;
2382 bool order = accessors != null ? accessors.declared_in_reverse : false;
2384 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
2385 (MemberName)$4, (int) $2, (ParametersCompiled) $6, (Attributes) $1,
2386 get_block, set_block, order);
2388 if ($3 == TypeManager.system_void_expr)
2389 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2391 if (accessors == null)
2392 Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ());
2394 if (current_container.Kind == Kind.Interface) {
2395 if (indexer.Get.Block != null)
2396 Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ());
2398 if (indexer.Set.Block != null)
2399 Report.Error (531, indexer.Location, "`{0}.set': interface members cannot have a definition", indexer.GetSignatureForError ());
2402 if (RootContext.Documentation != null)
2403 indexer.DocComment = ConsumeStoredComment ();
2405 current_container.AddIndexer (indexer);
2407 current_local_parameters = null;
2408 implicit_value_parameter_type = null;
2409 indexer_parameters = null;
2416 ENUM type_declaration_name
2418 if (RootContext.Documentation != null)
2419 enumTypeComment = Lexer.consume_doc_comment ();
2424 MemberName name = (MemberName) $4;
2425 if (name.IsGeneric) {
2426 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2429 name = MakeName (name);
2430 Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2,
2431 name, (Attributes) $1);
2433 if (RootContext.Documentation != null)
2434 e.DocComment = enumTypeComment;
2437 EnumMember em = null;
2438 foreach (VariableDeclaration ev in (ArrayList) $7) {
2439 em = new EnumMember (
2440 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2441 ev.OptAttributes, ev.Location);
2443 // if (RootContext.Documentation != null)
2444 em.DocComment = ev.DocComment;
2446 e.AddEnumMember (em);
2448 if (RootContext.EvalMode)
2449 undo.AddTypeContainer (current_container, e);
2451 current_container.AddTypeContainer (e);
2459 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2462 if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr &&
2463 $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr &&
2464 $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr &&
2465 $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr)
2466 Enum.Error_1008 (GetLocation ($2));
2472 Error_TypeExpected (lexer.Location);
2479 if (RootContext.Documentation != null)
2480 Lexer.doc_state = XmlCommentState.Allowed;
2482 opt_enum_member_declarations
2484 // here will be evaluated after CLOSE_BLACE is consumed.
2485 if (RootContext.Documentation != null)
2486 Lexer.doc_state = XmlCommentState.Allowed;
2494 opt_enum_member_declarations
2495 : /* empty */ { $$ = new ArrayList (4); }
2496 | enum_member_declarations opt_comma { $$ = $1; }
2499 enum_member_declarations
2500 : enum_member_declaration
2502 ArrayList l = new ArrayList (4);
2507 | enum_member_declarations COMMA enum_member_declaration
2509 ArrayList l = (ArrayList) $1;
2517 enum_member_declaration
2518 : opt_attributes IDENTIFIER
2520 VariableDeclaration vd = new VariableDeclaration (
2521 (LocatedToken) $2, null, (Attributes) $1);
2523 if (RootContext.Documentation != null) {
2524 vd.DocComment = Lexer.consume_doc_comment ();
2525 Lexer.doc_state = XmlCommentState.Allowed;
2530 | opt_attributes IDENTIFIER
2532 ++lexer.parsing_block;
2533 if (RootContext.Documentation != null) {
2534 tmpComment = Lexer.consume_doc_comment ();
2535 Lexer.doc_state = XmlCommentState.NotAllowed;
2538 ASSIGN constant_expression
2540 --lexer.parsing_block;
2541 VariableDeclaration vd = new VariableDeclaration (
2542 (LocatedToken) $2, $5, (Attributes) $1);
2544 if (RootContext.Documentation != null)
2545 vd.DocComment = ConsumeStoredComment ();
2551 delegate_declaration
2555 member_type type_declaration_name
2556 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2558 MemberName name = MakeName ((MemberName) $5);
2559 ParametersCompiled p = (ParametersCompiled) $7;
2561 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2562 (int) $2, name, p, (Attributes) $1);
2564 if (RootContext.Documentation != null) {
2565 del.DocComment = Lexer.consume_doc_comment ();
2566 Lexer.doc_state = XmlCommentState.Allowed;
2569 current_container.AddDelegate (del);
2570 current_delegate = del;
2571 lexer.ConstraintsParsing = true;
2573 opt_type_parameter_constraints_clauses
2575 lexer.ConstraintsParsing = false;
2579 current_delegate.SetParameterInfo ((ArrayList) $10);
2580 $$ = current_delegate;
2582 current_delegate = null;
2593 if (RootContext.Version < LanguageVersion.ISO_2)
2594 Report.FeatureIsNotAvailable (lexer.Location, "nullable types");
2600 namespace_or_type_name
2602 | qualified_alias_member IDENTIFIER opt_type_argument_list
2604 LocatedToken lt1 = (LocatedToken) $1;
2605 LocatedToken lt2 = (LocatedToken) $2;
2607 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2613 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2615 LocatedToken lt = (LocatedToken) $3;
2616 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2621 : IDENTIFIER opt_type_argument_list
2623 LocatedToken lt = (LocatedToken) $1;
2624 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2629 // Generics arguments (any type, without attributes)
2631 opt_type_argument_list
2632 : /* empty */ { $$ = null; }
2633 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2635 if (RootContext.Version < LanguageVersion.ISO_2)
2636 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2640 | OP_GENERICS_LT error
2642 Error_TypeExpected (lexer.Location);
2643 $$ = new TypeArguments ();
2650 TypeArguments type_args = new TypeArguments ();
2651 type_args.Add ((FullNamedExpression) $1);
2654 | type_arguments COMMA type
2656 TypeArguments type_args = (TypeArguments) $1;
2657 type_args.Add ((FullNamedExpression) $3);
2663 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2665 type_declaration_name
2668 lexer.parsing_generic_declaration = true;
2670 opt_type_parameter_list
2672 lexer.parsing_generic_declaration = false;
2673 LocatedToken lt = (LocatedToken) $1;
2674 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2678 member_declaration_name
2679 : method_declaration_name
2681 MemberName mn = (MemberName)$1;
2682 if (mn.TypeArguments != null)
2683 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2684 mn.GetSignatureForError ()));
2688 method_declaration_name
2689 : type_declaration_name
2690 | explicit_interface IDENTIFIER opt_type_parameter_list
2692 lexer.parsing_generic_declaration = false;
2693 LocatedToken lt = (LocatedToken) $2;
2694 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2698 indexer_declaration_name
2701 lexer.parsing_generic_declaration = false;
2702 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2704 | explicit_interface THIS
2706 lexer.parsing_generic_declaration = false;
2707 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2712 : IDENTIFIER opt_type_argument_list DOT
2714 LocatedToken lt = (LocatedToken) $1;
2715 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2717 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2719 LocatedToken lt1 = (LocatedToken) $1;
2720 LocatedToken lt2 = (LocatedToken) $2;
2722 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2724 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2726 LocatedToken lt = (LocatedToken) $2;
2727 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2731 opt_type_parameter_list
2732 : /* empty */ { $$ = null; }
2733 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2735 if (RootContext.Version < LanguageVersion.ISO_2)
2736 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2745 TypeArguments type_args = new TypeArguments ();
2746 type_args.Add ((FullNamedExpression)$1);
2749 | type_parameters COMMA type_parameter
2751 TypeArguments type_args = (TypeArguments) $1;
2752 type_args.Add ((FullNamedExpression)$3);
2758 : opt_attributes opt_type_parameter_variance IDENTIFIER
2760 LocatedToken lt = (LocatedToken)$3;
2761 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance)$2, lt.Location);
2765 if (GetTokenName (yyToken) == "type")
2766 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2768 Error_SyntaxError (yyToken);
2770 $$ = new TypeParameterName ("", null, lexer.Location);
2775 // All types where void is allowed
2778 : type_expression_or_array
2781 $$ = TypeManager.system_void_expr;
2788 lexer.parsing_generic_declaration = true;
2793 // A type which does not allow `void' to be used
2796 : type_expression_or_array
2799 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2800 $$ = TypeManager.system_void_expr;
2808 Expression.Error_VoidInvalidInTheContext (lexer.Location);
2809 $$ = TypeManager.system_void_expr;
2813 type_expression_or_array
2815 | type_expression rank_specifiers
2817 string rank_specifiers = (string) $2;
2818 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
2823 : namespace_or_type_name opt_nullable
2825 MemberName name = (MemberName) $1;
2828 $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
2830 if (name.Left == null && name.Name == "var" &&
2831 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
2832 $$ = current_array_type = new VarExpr (name.Location);
2834 $$ = name.GetTypeExpression ();
2837 | builtin_types opt_nullable
2840 $$ = new ComposedCast ((FullNamedExpression) $1, "?", lexer.Location);
2842 | type_expression STAR
2845 // Note that here only unmanaged types are allowed but we
2846 // can't perform checks during this phase - we do it during
2847 // semantic analysis.
2849 $$ = new ComposedCast ((FullNamedExpression) $1, "*", Lexer.Location);
2853 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2860 ArrayList types = new ArrayList (2);
2864 | type_list COMMA base_type_name
2866 ArrayList types = (ArrayList) $1;
2875 if ($1 is ComposedCast)
2876 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2881 Error_TypeExpected (lexer.Location);
2886 * replaces all the productions for isolating the various
2887 * simple types, but we need this to reuse it easily in variable_type
2890 : OBJECT { $$ = TypeManager.system_object_expr; }
2891 | STRING { $$ = TypeManager.system_string_expr; }
2892 | BOOL { $$ = TypeManager.system_boolean_expr; }
2893 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2894 | FLOAT { $$ = TypeManager.system_single_expr; }
2895 | DOUBLE { $$ = TypeManager.system_double_expr; }
2900 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2901 | BYTE { $$ = TypeManager.system_byte_expr; }
2902 | SHORT { $$ = TypeManager.system_int16_expr; }
2903 | USHORT { $$ = TypeManager.system_uint16_expr; }
2904 | INT { $$ = TypeManager.system_int32_expr; }
2905 | UINT { $$ = TypeManager.system_uint32_expr; }
2906 | LONG { $$ = TypeManager.system_int64_expr; }
2907 | ULONG { $$ = TypeManager.system_uint64_expr; }
2908 | CHAR { $$ = TypeManager.system_char_expr; }
2915 $$ = TypeManager.system_void_expr;
2920 // Expressions, section 7.5
2925 : primary_expression_no_array_creation
2926 | array_creation_expression
2929 primary_expression_no_array_creation
2931 | IDENTIFIER opt_type_argument_list
2933 LocatedToken lt = (LocatedToken) $1;
2934 $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location);
2936 | parenthesized_expression
2937 | default_value_expression
2939 | invocation_expression
2943 | post_increment_expression
2944 | post_decrement_expression
2945 | object_or_delegate_creation_expression
2946 | anonymous_type_expression
2949 | checked_expression
2950 | unchecked_expression
2951 | pointer_member_access
2952 | anonymous_method_expression
2959 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2960 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2961 | NULL { $$ = new NullLiteral (lexer.Location); }
2965 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2966 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2967 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2972 object v = lexer.Value;
2975 $$ = new IntLiteral ((int) v, lexer.Location);
2976 } else if (v is uint)
2977 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2979 $$ = new LongLiteral ((Int64) v, lexer.Location);
2980 else if (v is ulong)
2981 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2983 Console.WriteLine ("OOPS. Unexpected result from scanner");
2988 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2989 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2994 // Here is the trick, tokenizer may think that parens is a special but
2995 // parser is interested in open parens only, so we merge them.
2996 // Consider: if (a)foo ();
3001 | OPEN_PARENS_LAMBDA
3004 parenthesized_expression
3005 : OPEN_PARENS expression CLOSE_PARENS
3007 $$ = new ParenthesizedExpression ((Expression) $2);
3012 : primary_expression DOT IDENTIFIER opt_type_argument_list
3014 LocatedToken lt = (LocatedToken) $3;
3015 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3017 | predefined_type DOT IDENTIFIER opt_type_argument_list
3019 LocatedToken lt = (LocatedToken) $3;
3020 // TODO: Location is wrong as some predefined types doesn't hold a location
3021 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3023 | qualified_alias_member IDENTIFIER opt_type_argument_list
3025 LocatedToken lt1 = (LocatedToken) $1;
3026 LocatedToken lt2 = (LocatedToken) $2;
3028 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3032 invocation_expression
3033 : primary_expression open_parens_any opt_argument_list CLOSE_PARENS
3035 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3039 opt_object_or_collection_initializer
3040 : /* empty */ { $$ = null; }
3041 | object_or_collection_initializer
3044 object_or_collection_initializer
3045 : OPEN_BRACE opt_member_initializer_list CLOSE_BRACE
3048 $$ = CollectionOrObjectInitializers.Empty;
3050 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3052 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3054 $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1));
3058 opt_member_initializer_list
3059 : /* empty */ { $$ = null; }
3060 | member_initializer_list
3066 member_initializer_list
3067 : member_initializer
3069 ArrayList a = new ArrayList ();
3073 | member_initializer_list COMMA member_initializer
3075 ArrayList a = (ArrayList)$1;
3082 : IDENTIFIER ASSIGN initializer_value
3084 LocatedToken lt = $1 as LocatedToken;
3085 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3087 | non_assignment_expression
3089 $$ = new CollectionElementInitializer ((Expression)$1);
3091 | OPEN_BRACE expression_list CLOSE_BRACE
3093 $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
3095 | OPEN_BRACE CLOSE_BRACE
3097 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3103 | object_or_collection_initializer
3107 : /* empty */ { $$ = null; }
3114 ArrayList list = new ArrayList (4);
3118 | argument_list COMMA argument
3120 ArrayList list = (ArrayList) $1;
3124 | argument_list COMMA
3126 Report.Error (839, GetLocation ($2), "An argument is missing");
3131 Report.Error (839, GetLocation ($1), "An argument is missing");
3139 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3141 | non_simple_argument
3148 : REF variable_reference
3150 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3152 | OUT variable_reference
3154 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3156 | ARGLIST open_parens_any argument_list CLOSE_PARENS
3158 ArrayList list = (ArrayList) $3;
3159 Argument[] args = new Argument [list.Count];
3160 list.CopyTo (args, 0);
3162 Expression expr = new Arglist (args, (Location) $1);
3163 $$ = new Argument (expr, Argument.AType.Expression);
3165 | ARGLIST open_parens_any CLOSE_PARENS
3167 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3171 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3176 : expression { note ("section 5.4"); $$ = $1; }
3180 : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET
3182 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3184 | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3186 // LAMESPEC: Not allowed according to specification
3187 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3189 | primary_expression_no_array_creation rank_specifiers
3191 // So the super-trick is that primary_expression
3192 // can only be either a SimpleName or a MemberAccess.
3193 // The MemberAccess case arises when you have a fully qualified type-name like :
3195 // SimpleName is when you have
3198 Expression expr = (Expression) $1;
3199 if (expr is ComposedCast){
3200 $$ = new ComposedCast ((ComposedCast)expr, (string) $2);
3201 } else if (expr is ATypeNameExpression){
3203 // So we extract the string corresponding to the SimpleName
3206 $$ = new ComposedCast ((ATypeNameExpression)expr, (string) $2);
3208 Error_ExpectingTypeName (expr);
3209 $$ = TypeManager.system_object_expr;
3212 current_array_type = (FullNamedExpression)$$;
3219 ArrayList list = new ArrayList (4);
3223 | expression_list COMMA expression
3225 ArrayList list = (ArrayList) $1;
3234 $$ = new This (current_block, (Location) $1);
3239 : BASE DOT IDENTIFIER opt_type_argument_list
3241 LocatedToken lt = (LocatedToken) $3;
3242 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3244 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3246 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3249 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3254 post_increment_expression
3255 : primary_expression OP_INC
3257 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1);
3261 post_decrement_expression
3262 : primary_expression OP_DEC
3264 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1);
3268 object_or_delegate_creation_expression
3269 : new_expr_start open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3272 if (RootContext.Version <= LanguageVersion.ISO_2)
3273 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3275 $$ = new NewInitialize ((Expression) $1, (ArrayList) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1));
3278 $$ = new New ((Expression) $1, (ArrayList) $3, GetLocation ($1));
3280 | new_expr_start object_or_collection_initializer
3282 if (RootContext.Version <= LanguageVersion.ISO_2)
3283 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3285 $$ = new NewInitialize ((Expression) $1, null, (CollectionOrObjectInitializers) $2, GetLocation ($1));
3289 array_creation_expression
3290 : new_expr_start OPEN_BRACKET expression_list CLOSE_BRACKET
3291 opt_rank_specifier // shift/reduce on OPEN_BRACE
3292 opt_array_initializer
3294 $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
3296 | new_expr_start rank_specifiers opt_array_initializer
3299 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3301 $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
3303 | NEW rank_specifiers array_initializer
3305 $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
3307 | new_expr_start error
3309 Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type");
3317 ++lexer.parsing_type;
3321 --lexer.parsing_type;
3326 anonymous_type_expression
3327 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3329 if (RootContext.Version <= LanguageVersion.ISO_2)
3330 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3332 $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1));
3336 anonymous_type_parameters_opt_comma
3337 : anonymous_type_parameters_opt
3338 | anonymous_type_parameters COMMA
3341 anonymous_type_parameters_opt
3343 | anonymous_type_parameters
3346 anonymous_type_parameters
3347 : anonymous_type_parameter
3349 ArrayList a = new ArrayList (4);
3353 | anonymous_type_parameters COMMA anonymous_type_parameter
3355 ArrayList a = (ArrayList) $1;
3361 anonymous_type_parameter
3362 : IDENTIFIER ASSIGN variable_initializer
3364 LocatedToken lt = (LocatedToken)$1;
3365 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3369 LocatedToken lt = (LocatedToken)$1;
3370 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3371 lt.Value, lt.Location);
3373 | BASE DOT IDENTIFIER opt_type_argument_list
3375 LocatedToken lt = (LocatedToken) $3;
3376 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3377 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3381 MemberAccess ma = (MemberAccess) $1;
3382 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3386 Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " +
3387 "Anonymous type members must be a member assignment, simple name or member access expression");
3402 opt_rank_specifier_or_nullable
3410 | opt_nullable rank_specifiers
3413 $$ = "?" + (string) $2;
3421 | rank_specifier rank_specifiers
3423 $$ = (string) $2 + (string) $1;
3428 : OPEN_BRACKET CLOSE_BRACKET
3432 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3434 $$ = "[" + (string) $2 + "]";
3436 | OPEN_BRACKET error CLOSE_BRACKET
3438 ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1));
3448 | dim_separators COMMA
3450 $$ = (string) $1 + ",";
3454 opt_array_initializer
3466 : OPEN_BRACE CLOSE_BRACE
3468 ArrayList list = new ArrayList (4);
3471 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3473 $$ = (ArrayList) $2;
3477 variable_initializer_list
3478 : variable_initializer
3480 ArrayList list = new ArrayList (4);
3484 | variable_initializer_list COMMA variable_initializer
3486 ArrayList list = (ArrayList) $1;
3492 Error_SyntaxError (yyToken);
3493 $$ = new ArrayList ();
3500 pushed_current_array_type = current_array_type;
3501 lexer.TypeOfParsing = true;
3503 open_parens_any typeof_type_expression CLOSE_PARENS
3505 lexer.TypeOfParsing = false;
3506 Expression type = (Expression)$4;
3507 if (type == TypeManager.system_void_expr)
3508 $$ = new TypeOfVoid ((Location) $1);
3510 $$ = new TypeOf (type, (Location) $1);
3511 current_array_type = pushed_current_array_type;
3515 typeof_type_expression
3520 Error_TypeExpected (lexer.Location);
3526 : IDENTIFIER generic_dimension
3528 LocatedToken lt = (LocatedToken) $1;
3530 $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location);
3532 | qualified_alias_member IDENTIFIER generic_dimension
3534 LocatedToken lt1 = (LocatedToken) $1;
3535 LocatedToken lt2 = (LocatedToken) $2;
3537 $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location);
3539 | unbound_type_name DOT IDENTIFIER
3541 LocatedToken lt = (LocatedToken) $3;
3543 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3545 | unbound_type_name DOT IDENTIFIER generic_dimension
3547 LocatedToken lt = (LocatedToken) $3;
3549 $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3551 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3553 LocatedToken lt = (LocatedToken) $3;
3554 MemberName name = (MemberName) $1;
3556 $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location);
3563 if (RootContext.Version < LanguageVersion.ISO_2)
3564 Report.FeatureIsNotAvailable (lexer.Location, "generics");
3570 qualified_alias_member
3571 : IDENTIFIER DOUBLE_COLON
3573 LocatedToken lt = (LocatedToken) $1;
3574 if (RootContext.Version == LanguageVersion.ISO_1)
3575 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3582 : SIZEOF open_parens_any type CLOSE_PARENS {
3583 $$ = new SizeOf ((Expression) $3, (Location) $1);
3588 : CHECKED open_parens_any expression CLOSE_PARENS
3590 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3594 unchecked_expression
3595 : UNCHECKED open_parens_any expression CLOSE_PARENS
3597 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3601 pointer_member_access
3602 : primary_expression OP_PTR IDENTIFIER
3605 LocatedToken lt = (LocatedToken) $3;
3607 deref = new Indirection ((Expression) $1, lt.Location);
3608 $$ = new MemberAccess (deref, lt.Value);
3612 anonymous_method_expression
3613 : DELEGATE opt_anonymous_method_signature
3615 start_anonymous (false, (ParametersCompiled) $2, (Location) $1);
3619 $$ = end_anonymous ((ToplevelBlock) $4);
3623 opt_anonymous_method_signature
3626 $$ = ParametersCompiled.Undefined;
3628 | anonymous_method_signature
3631 anonymous_method_signature
3634 params_modifiers_not_allowed = true;
3636 opt_formal_parameter_list CLOSE_PARENS
3638 params_modifiers_not_allowed = false;
3643 default_value_expression
3644 : DEFAULT open_parens_any type CLOSE_PARENS
3646 if (RootContext.Version < LanguageVersion.ISO_2)
3647 Report.FeatureIsNotAvailable (lexer.Location, "default value expression");
3649 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3654 : primary_expression
3655 | BANG prefixed_unary_expression
3657 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2);
3659 | TILDE prefixed_unary_expression
3661 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2);
3667 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3669 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3671 | OPEN_PARENS predefined_type CLOSE_PARENS prefixed_unary_expression
3673 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3678 // The idea to split this out is from Rhys' grammar
3679 // to solve the problem with casts.
3681 prefixed_unary_expression
3683 | PLUS prefixed_unary_expression
3685 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2);
3687 | MINUS prefixed_unary_expression
3689 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2);
3691 | OP_INC prefixed_unary_expression
3693 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2);
3695 | OP_DEC prefixed_unary_expression
3697 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2);
3699 | STAR prefixed_unary_expression
3701 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3703 | BITWISE_AND prefixed_unary_expression
3705 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2);
3709 multiplicative_expression
3710 : prefixed_unary_expression
3711 | multiplicative_expression STAR prefixed_unary_expression
3713 $$ = new Binary (Binary.Operator.Multiply,
3714 (Expression) $1, (Expression) $3);
3716 | multiplicative_expression DIV prefixed_unary_expression
3718 $$ = new Binary (Binary.Operator.Division,
3719 (Expression) $1, (Expression) $3);
3721 | multiplicative_expression PERCENT prefixed_unary_expression
3723 $$ = new Binary (Binary.Operator.Modulus,
3724 (Expression) $1, (Expression) $3);
3729 : multiplicative_expression
3730 | additive_expression PLUS multiplicative_expression
3732 $$ = new Binary (Binary.Operator.Addition,
3733 (Expression) $1, (Expression) $3);
3735 | additive_expression MINUS multiplicative_expression
3737 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3739 | parenthesized_expression MINUS multiplicative_expression
3741 // Shift/Reduce conflict
3742 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3744 | additive_expression AS type
3746 $$ = new As ((Expression) $1, (Expression) $3, (Location) $2);
3748 | additive_expression IS type
3750 $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2);
3755 : additive_expression
3756 | shift_expression OP_SHIFT_LEFT additive_expression
3758 $$ = new Binary (Binary.Operator.LeftShift,
3759 (Expression) $1, (Expression) $3);
3761 | shift_expression OP_SHIFT_RIGHT additive_expression
3763 $$ = new Binary (Binary.Operator.RightShift,
3764 (Expression) $1, (Expression) $3);
3768 relational_expression
3770 | relational_expression OP_LT shift_expression
3772 $$ = new Binary (Binary.Operator.LessThan,
3773 (Expression) $1, (Expression) $3);
3775 | relational_expression OP_GT shift_expression
3777 $$ = new Binary (Binary.Operator.GreaterThan,
3778 (Expression) $1, (Expression) $3);
3780 | relational_expression OP_LE shift_expression
3782 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3783 (Expression) $1, (Expression) $3);
3785 | relational_expression OP_GE shift_expression
3787 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3788 (Expression) $1, (Expression) $3);
3793 : relational_expression
3794 | equality_expression OP_EQ relational_expression
3796 $$ = new Binary (Binary.Operator.Equality,
3797 (Expression) $1, (Expression) $3);
3799 | equality_expression OP_NE relational_expression
3801 $$ = new Binary (Binary.Operator.Inequality,
3802 (Expression) $1, (Expression) $3);
3807 : equality_expression
3808 | and_expression BITWISE_AND equality_expression
3810 $$ = new Binary (Binary.Operator.BitwiseAnd,
3811 (Expression) $1, (Expression) $3);
3815 exclusive_or_expression
3817 | exclusive_or_expression CARRET and_expression
3819 $$ = new Binary (Binary.Operator.ExclusiveOr,
3820 (Expression) $1, (Expression) $3);
3824 inclusive_or_expression
3825 : exclusive_or_expression
3826 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3828 $$ = new Binary (Binary.Operator.BitwiseOr,
3829 (Expression) $1, (Expression) $3);
3833 conditional_and_expression
3834 : inclusive_or_expression
3835 | conditional_and_expression OP_AND inclusive_or_expression
3837 $$ = new Binary (Binary.Operator.LogicalAnd,
3838 (Expression) $1, (Expression) $3);
3842 conditional_or_expression
3843 : conditional_and_expression
3844 | conditional_or_expression OP_OR conditional_and_expression
3846 $$ = new Binary (Binary.Operator.LogicalOr,
3847 (Expression) $1, (Expression) $3);
3851 null_coalescing_expression
3852 : conditional_or_expression
3853 | conditional_or_expression OP_COALESCING null_coalescing_expression
3855 if (RootContext.Version < LanguageVersion.ISO_2)
3856 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3858 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location);
3862 conditional_expression
3863 : null_coalescing_expression
3864 | null_coalescing_expression INTERR expression COLON expression
3866 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3870 assignment_expression
3871 : prefixed_unary_expression ASSIGN expression
3873 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
3875 | prefixed_unary_expression OP_MULT_ASSIGN expression
3877 $$ = new CompoundAssign (
3878 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3880 | prefixed_unary_expression OP_DIV_ASSIGN expression
3882 $$ = new CompoundAssign (
3883 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3885 | prefixed_unary_expression OP_MOD_ASSIGN expression
3887 $$ = new CompoundAssign (
3888 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3890 | prefixed_unary_expression OP_ADD_ASSIGN expression
3892 $$ = new CompoundAssign (
3893 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3895 | prefixed_unary_expression OP_SUB_ASSIGN expression
3897 $$ = new CompoundAssign (
3898 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3900 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3902 $$ = new CompoundAssign (
3903 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3905 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3907 $$ = new CompoundAssign (
3908 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3910 | prefixed_unary_expression OP_AND_ASSIGN expression
3912 $$ = new CompoundAssign (
3913 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3915 | prefixed_unary_expression OP_OR_ASSIGN expression
3917 $$ = new CompoundAssign (
3918 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3920 | prefixed_unary_expression OP_XOR_ASSIGN expression
3922 $$ = new CompoundAssign (
3923 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3927 lambda_parameter_list
3930 ArrayList pars = new ArrayList (4);
3935 | lambda_parameter_list COMMA lambda_parameter
3937 ArrayList pars = (ArrayList) $1;
3938 Parameter p = (Parameter)$3;
3939 if (pars[0].GetType () != p.GetType ()) {
3940 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
3949 : parameter_modifier type IDENTIFIER
3951 LocatedToken lt = (LocatedToken) $3;
3953 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3957 LocatedToken lt = (LocatedToken) $2;
3959 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
3963 LocatedToken lt = (LocatedToken) $1;
3964 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
3968 opt_lambda_parameter_list
3969 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
3970 | lambda_parameter_list {
3971 ArrayList pars_list = (ArrayList) $1;
3972 $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter)));
3976 lambda_expression_body
3978 start_block (lexer.Location);
3982 Block b = end_block (lexer.Location);
3983 b.AddStatement (new ContextualReturn ((Expression) $2));
3994 LocatedToken lt = (LocatedToken) $1;
3995 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
3996 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
3998 lambda_expression_body
4000 $$ = end_anonymous ((ToplevelBlock) $4);
4002 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4004 start_anonymous (true, (ParametersCompiled) $2, GetLocation ($1));
4006 lambda_expression_body
4008 $$ = end_anonymous ((ToplevelBlock) $6);
4013 : assignment_expression
4014 | non_assignment_expression
4017 non_assignment_expression
4018 : conditional_expression
4040 lexer.ConstraintsParsing = true;
4042 type_declaration_name
4044 MemberName name = MakeName ((MemberName) $6);
4045 push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3);
4048 opt_type_parameter_constraints_clauses
4050 lexer.ConstraintsParsing = false;
4052 current_class.SetParameterInfo ((ArrayList) $9);
4054 if (RootContext.Documentation != null) {
4055 current_container.DocComment = Lexer.consume_doc_comment ();
4056 Lexer.doc_state = XmlCommentState.Allowed;
4061 --lexer.parsing_declaration;
4062 if (RootContext.Documentation != null)
4063 Lexer.doc_state = XmlCommentState.Allowed;
4067 $$ = pop_current_class ();
4075 { $$ = $1; } // location
4079 : /* empty */ { $$ = (int) 0; }
4085 | modifiers modifier
4090 if ((m1 & m2) != 0) {
4091 Location l = lexer.Location;
4092 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4094 $$ = (int) (m1 | m2);
4102 if (current_container == RootContext.ToplevelTypes)
4103 Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements");
4105 | PUBLIC { $$ = Modifiers.PUBLIC; }
4106 | PROTECTED { $$ = Modifiers.PROTECTED; }
4107 | INTERNAL { $$ = Modifiers.INTERNAL; }
4108 | PRIVATE { $$ = Modifiers.PRIVATE; }
4109 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4110 | SEALED { $$ = Modifiers.SEALED; }
4111 | STATIC { $$ = Modifiers.STATIC; }
4112 | READONLY { $$ = Modifiers.READONLY; }
4113 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4114 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4115 | EXTERN { $$ = Modifiers.EXTERN; }
4116 | VOLATILE { $$ = Modifiers.VOLATILE; }
4117 | UNSAFE { $$ = Modifiers.UNSAFE; }
4126 : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); }
4129 opt_type_parameter_constraints_clauses
4130 : /* empty */ { $$ = null; }
4131 | type_parameter_constraints_clauses
4135 type_parameter_constraints_clauses
4136 : type_parameter_constraints_clause {
4137 ArrayList constraints = new ArrayList (1);
4138 constraints.Add ($1);
4141 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4142 ArrayList constraints = (ArrayList) $1;
4143 Constraints new_constraint = (Constraints)$2;
4145 foreach (Constraints c in constraints) {
4146 if (new_constraint.TypeParameter == c.TypeParameter) {
4147 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4148 new_constraint.TypeParameter);
4152 constraints.Add (new_constraint);
4157 type_parameter_constraints_clause
4158 : WHERE IDENTIFIER COLON type_parameter_constraints {
4159 LocatedToken lt = (LocatedToken) $2;
4160 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4164 type_parameter_constraints
4165 : type_parameter_constraint {
4166 ArrayList constraints = new ArrayList (1);
4167 constraints.Add ($1);
4170 | type_parameter_constraints COMMA type_parameter_constraint {
4171 ArrayList constraints = (ArrayList) $1;
4173 constraints.Add ($3);
4178 type_parameter_constraint
4180 | NEW OPEN_PARENS CLOSE_PARENS {
4181 $$ = SpecialConstraint.Constructor;
4184 $$ = SpecialConstraint.ReferenceType;
4187 $$ = SpecialConstraint.ValueType;
4191 opt_type_parameter_variance
4196 | type_parameter_variance
4198 if (RootContext.Version < LanguageVersion.Future)
4199 Report.FeatureIsNotAvailable (lexer.Location, "generic variance");
4204 type_parameter_variance
4207 $$ = Variance.Covariant;
4211 $$ = Variance.Contravariant;
4220 // A block is "contained" on the following places:
4222 // property_declaration as part of the accessor body (get/set)
4223 // operator_declaration
4224 // constructor_declaration
4225 // destructor_declaration
4226 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4231 ++lexer.parsing_block;
4232 start_block ((Location) $1);
4234 opt_statement_list CLOSE_BRACE
4236 --lexer.parsing_block;
4237 $$ = end_block ((Location) $4);
4244 ++lexer.parsing_block;
4245 current_block.StartLocation = GetLocation ($1);
4247 opt_statement_list CLOSE_BRACE
4249 --lexer.parsing_block;
4250 $$ = end_block ((Location) $4);
4261 | statement_list statement
4265 : declaration_statement
4267 if ($1 != null && (Block) $1 != current_block){
4268 current_block.AddStatement ((Statement) $1);
4269 current_block = (Block) $1;
4272 | valid_declaration_statement
4274 current_block.AddStatement ((Statement) $1);
4280 // The interactive_statement and its derivatives are only
4281 // used to provide a special version of `expression_statement'
4282 // that has a side effect of assigning the expression to
4285 interactive_statement_list
4286 : interactive_statement
4287 | interactive_statement_list interactive_statement
4290 interactive_statement
4291 : declaration_statement
4293 if ($1 != null && (Block) $1 != current_block){
4294 current_block.AddStatement ((Statement) $1);
4295 current_block = (Block) $1;
4298 | interactive_valid_declaration_statement
4300 current_block.AddStatement ((Statement) $1);
4305 valid_declaration_statement
4308 | expression_statement
4309 | selection_statement
4310 | iteration_statement
4314 | unchecked_statement
4321 interactive_valid_declaration_statement
4324 | interactive_expression_statement
4325 | selection_statement
4326 | iteration_statement
4330 | unchecked_statement
4338 : valid_declaration_statement
4339 | declaration_statement
4341 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4346 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4354 $$ = EmptyStatement.Value;
4361 LocatedToken lt = (LocatedToken) $1;
4362 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4364 if (current_block.AddLabel (labeled))
4365 current_block.AddStatement (labeled);
4370 declaration_statement
4371 : local_variable_declaration SEMICOLON
4373 current_array_type = null;
4375 DictionaryEntry de = (DictionaryEntry) $1;
4376 Expression e = (Expression) de.Key;
4378 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4382 | local_constant_declaration SEMICOLON
4384 current_array_type = null;
4386 DictionaryEntry de = (DictionaryEntry) $1;
4388 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4394 * The following is from Rhys' grammar:
4395 * > Types in local variable declarations must be recognized as
4396 * > expressions to prevent reduce/reduce errors in the grammar.
4397 * > The expressions are converted into types during semantic analysis.
4400 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4402 // FIXME: Do something smart here regarding the composition of the type.
4404 // Ok, the above "primary_expression" is there to get rid of
4405 // both reduce/reduce and shift/reduces in the grammar, it should
4406 // really just be "type_name". If you use type_name, a reduce/reduce
4407 // creeps up. If you use namespace_or_type_name (which is all we need
4408 // really) two shift/reduces appear.
4411 // So the super-trick is that primary_expression
4412 // can only be either a SimpleName or a MemberAccess.
4413 // The MemberAccess case arises when you have a fully qualified type-name like :
4415 // SimpleName is when you have
4418 Expression expr = (Expression) $1;
4419 string rank_or_nullable = (string) $2;
4421 if (expr is ComposedCast){
4422 $$ = new ComposedCast ((ComposedCast)expr, rank_or_nullable);
4423 } else if (expr is ATypeNameExpression){
4425 // So we extract the string corresponding to the SimpleName
4428 if (rank_or_nullable.Length == 0) {
4429 SimpleName sn = expr as SimpleName;
4430 if (sn != null && sn.Name == "var" &&
4431 (RootContext.Version > LanguageVersion.ISO_2 || RootContext.Version == LanguageVersion.Default_MCS))
4432 $$ = current_array_type = new VarExpr (sn.Location);
4436 $$ = new ComposedCast ((ATypeNameExpression)expr, rank_or_nullable);
4439 Error_ExpectingTypeName (expr);
4440 $$ = TypeManager.system_object_expr;
4443 | builtin_types opt_rank_specifier_or_nullable
4445 if ((string) $2 == "")
4448 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
4450 | VOID opt_rank_specifier
4452 Expression.Error_VoidInvalidInTheContext (lexer.Location);
4453 $$ = TypeManager.system_void_expr;
4457 local_variable_pointer_type
4458 : primary_expression_no_array_creation STAR
4460 ATypeNameExpression expr = $1 as ATypeNameExpression;
4463 $$ = new ComposedCast (expr, "*");
4465 Error_ExpectingTypeName ((Expression)$1);
4469 | builtin_types STAR
4471 $$ = new ComposedCast ((FullNamedExpression) $1, "*", GetLocation ($1));
4475 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4477 | local_variable_pointer_type STAR
4479 $$ = new ComposedCast ((FullNamedExpression) $1, "*");
4485 | local_variable_pointer_type opt_rank_specifier
4488 string rank = (string)$2;
4493 $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
4500 local_variable_declaration
4501 : local_variable_type local_variable_declarators
4504 VarExpr ve = $1 as VarExpr;
4506 ve.VariableInitializer = (ArrayList)$2;
4508 $$ = new DictionaryEntry ($1, $2);
4514 local_constant_declaration
4515 : CONST variable_type constant_declarators
4518 $$ = new DictionaryEntry ($2, $3);
4524 expression_statement
4525 : statement_expression SEMICOLON { $$ = $1; }
4528 interactive_expression_statement
4529 : interactive_statement_expression SEMICOLON { $$ = $1; }
4533 // We have to do the wrapping here and not in the case above,
4534 // because statement_expression is used for example in for_statement
4536 statement_expression
4539 ExpressionStatement s = $1 as ExpressionStatement;
4541 ((Expression) $1).Error_InvalidExpressionStatement ();
4542 s = EmptyExpressionStatement.Instance;
4545 $$ = new StatementExpression (s);
4549 Error_SyntaxError (yyToken);
4554 interactive_statement_expression
4557 Expression expr = (Expression) $1;
4558 ExpressionStatement s;
4560 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4561 $$ = new StatementExpression (s);
4565 Error_SyntaxError (yyToken);
4576 : IF open_parens_any boolean_expression CLOSE_PARENS
4579 Location l = (Location) $1;
4581 $$ = new If ((Expression) $3, (Statement) $5, l);
4583 // FIXME: location for warning should be loc property of $5.
4584 if ($5 == EmptyStatement.Value)
4585 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4588 | IF open_parens_any boolean_expression CLOSE_PARENS
4589 embedded_statement ELSE embedded_statement
4591 Location l = (Location) $1;
4593 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4595 // FIXME: location for warning should be loc property of $5 and $7.
4596 if ($5 == EmptyStatement.Value)
4597 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4598 if ($7 == EmptyStatement.Value)
4599 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4604 : SWITCH open_parens_any
4606 if (switch_stack == null)
4607 switch_stack = new Stack (2);
4608 switch_stack.Push (current_block);
4610 expression CLOSE_PARENS
4613 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4614 current_block = (Block) switch_stack.Pop ();
4630 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4631 $$ = new ArrayList ();
4639 ArrayList sections = new ArrayList (4);
4644 | switch_sections switch_section
4646 ArrayList sections = (ArrayList) $1;
4656 current_block = current_block.CreateSwitchBlock (lexer.Location);
4660 $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit);
4667 ArrayList labels = new ArrayList (4);
4672 | switch_labels switch_label
4674 ArrayList labels = (ArrayList) ($1);
4682 : CASE constant_expression COLON
4684 $$ = new SwitchLabel ((Expression) $2, (Location) $1);
4688 $$ = new SwitchLabel (null, (Location) $1);
4700 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4702 Location l = (Location) $1;
4703 $$ = new While ((Expression) $3, (Statement) $5, l);
4708 : DO embedded_statement
4709 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4711 Location l = (Location) $1;
4713 $$ = new Do ((Statement) $2, (Expression) $5, l);
4718 : FOR open_parens_any opt_for_initializer SEMICOLON
4720 Location l = lexer.Location;
4722 Block assign_block = current_block;
4724 if ($3 is DictionaryEntry){
4725 DictionaryEntry de = (DictionaryEntry) $3;
4727 Expression type = (Expression) de.Key;
4728 ArrayList var_declarators = (ArrayList) de.Value;
4730 foreach (VariableDeclaration decl in var_declarators){
4734 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4738 Expression expr = decl.expression_or_array_initializer;
4740 LocalVariableReference var;
4741 var = new LocalVariableReference (assign_block, decl.identifier, l);
4744 Assign a = new SimpleAssign (var, expr, decl.Location);
4746 assign_block.AddStatement (new StatementExpression (a));
4750 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4751 // This can be referred to as $5 below.
4757 opt_for_condition SEMICOLON
4758 opt_for_iterator CLOSE_PARENS
4761 Location l = (Location) $1;
4763 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4765 current_block.AddStatement (f);
4767 $$ = end_block (lexer.Location);
4772 : /* empty */ { $$ = EmptyStatement.Value; }
4777 : local_variable_declaration
4778 | statement_expression_list
4782 : /* empty */ { $$ = null; }
4783 | boolean_expression
4787 : /* empty */ { $$ = EmptyStatement.Value; }
4792 : statement_expression_list
4795 statement_expression_list
4796 : statement_expression
4798 // CHANGE: was `null'
4799 Statement s = (Statement) $1;
4800 Block b = new Block (current_block, s.loc, lexer.Location);
4805 | statement_expression_list COMMA statement_expression
4807 Block b = (Block) $1;
4809 b.AddStatement ((Statement) $3);
4815 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4817 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4820 | FOREACH open_parens_any type IDENTIFIER IN
4821 expression CLOSE_PARENS
4823 start_block (lexer.Location);
4824 Block foreach_block = current_block;
4826 LocatedToken lt = (LocatedToken) $4;
4827 Location l = lt.Location;
4828 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4830 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4832 // Get a writable reference to this read-only variable.
4834 // Note that the $$ here refers to the value of _this_ code block,
4835 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4836 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4843 LocalVariableReference v = (LocalVariableReference) $8;
4844 Location l = (Location) $1;
4847 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4848 current_block.AddStatement (f);
4851 $$ = end_block (lexer.Location);
4857 | continue_statement
4867 $$ = new Break ((Location) $1);
4872 : CONTINUE SEMICOLON
4874 $$ = new Continue ((Location) $1);
4879 : GOTO IDENTIFIER SEMICOLON
4881 LocatedToken lt = (LocatedToken) $2;
4882 $$ = new Goto (lt.Value, lt.Location);
4884 | GOTO CASE constant_expression SEMICOLON
4886 $$ = new GotoCase ((Expression) $3, (Location) $1);
4888 | GOTO DEFAULT SEMICOLON
4890 $$ = new GotoDefault ((Location) $1);
4895 : RETURN opt_expression SEMICOLON
4897 $$ = new Return ((Expression) $2, (Location) $1);
4902 : THROW opt_expression SEMICOLON
4904 $$ = new Throw ((Expression) $2, (Location) $1);
4909 : IDENTIFIER RETURN expression SEMICOLON
4911 LocatedToken lt = (LocatedToken) $1;
4912 string s = lt.Value;
4914 Report.Error (1003, lt.Location, "; expected");
4917 if (RootContext.Version == LanguageVersion.ISO_1){
4918 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4921 current_block.Toplevel.IsIterator = true;
4922 $$ = new Yield ((Expression) $3, lt.Location);
4924 | IDENTIFIER RETURN SEMICOLON
4926 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4929 | IDENTIFIER BREAK SEMICOLON
4931 LocatedToken lt = (LocatedToken) $1;
4932 string s = lt.Value;
4934 Report.Error (1003, lt.Location, "; expected");
4937 if (RootContext.Version == LanguageVersion.ISO_1){
4938 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
4942 current_block.Toplevel.IsIterator = true;
4943 $$ = new YieldBreak (lt.Location);
4953 : TRY block catch_clauses
4955 $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false);
4957 | TRY block FINALLY block
4959 $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1);
4961 | TRY block catch_clauses FINALLY block
4963 $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1);
4967 Report.Error (1524, (Location) $1, "Expected catch or finally");
4975 ArrayList l = new ArrayList (4);
4980 | catch_clauses catch_clause
4982 ArrayList l = (ArrayList) $1;
4990 : /* empty */ { $$ = null; }
4995 : CATCH opt_catch_args
4997 Expression type = null;
5000 DictionaryEntry cc = (DictionaryEntry) $2;
5001 type = (Expression) cc.Key;
5002 LocatedToken lt = (LocatedToken) cc.Value;
5005 ArrayList one = new ArrayList (4);
5007 one.Add (new VariableDeclaration (lt, null));
5009 start_block (lexer.Location);
5010 current_block = declare_local_variables (type, one, lt.Location);
5014 Expression type = null;
5016 Block var_block = null;
5019 DictionaryEntry cc = (DictionaryEntry) $2;
5020 type = (Expression) cc.Key;
5021 LocatedToken lt = (LocatedToken) cc.Value;
5025 var_block = end_block (lexer.Location);
5029 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5034 : /* empty */ { $$ = null; }
5039 : open_parens_any type opt_identifier CLOSE_PARENS
5041 $$ = new DictionaryEntry ($2, $3);
5043 | open_parens_any CLOSE_PARENS
5045 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5052 $$ = new Checked ((Block) $2);
5059 $$ = new Unchecked ((Block) $2);
5066 RootContext.CheckUnsafeOption ((Location) $1);
5068 $$ = new Unsafe ((Block) $3);
5073 : FIXED open_parens_any
5074 type_and_void fixed_pointer_declarators
5077 ArrayList list = (ArrayList) $4;
5078 Expression type = (Expression) $3;
5079 Location l = (Location) $1;
5080 int top = list.Count;
5082 start_block (lexer.Location);
5084 for (int i = 0; i < top; i++){
5085 Pair p = (Pair) list [i];
5088 v = current_block.AddVariable (type, (string) p.First, l);
5092 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5100 Location l = (Location) $1;
5102 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5104 current_block.AddStatement (f);
5106 $$ = end_block (lexer.Location);
5110 fixed_pointer_declarators
5111 : fixed_pointer_declarator {
5112 ArrayList declarators = new ArrayList (4);
5114 declarators.Add ($1);
5117 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5119 ArrayList declarators = (ArrayList) $1;
5121 declarators.Add ($3);
5126 fixed_pointer_declarator
5127 : IDENTIFIER ASSIGN expression
5129 LocatedToken lt = (LocatedToken) $1;
5130 // FIXME: keep location
5131 $$ = new Pair (lt.Value, $3);
5135 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5141 : LOCK open_parens_any expression CLOSE_PARENS
5147 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5152 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5154 start_block (lexer.Location);
5155 Block assign_block = current_block;
5157 DictionaryEntry de = (DictionaryEntry) $3;
5158 Location l = (Location) $1;
5160 Expression type = (Expression) de.Key;
5161 ArrayList var_declarators = (ArrayList) de.Value;
5163 Stack vars = new Stack ();
5165 foreach (VariableDeclaration decl in var_declarators) {
5166 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5169 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5171 Expression expr = decl.expression_or_array_initializer;
5173 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5176 LocalVariableReference var;
5178 // Get a writable reference to this read-only variable.
5179 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5181 // This is so that it is not a warning on using variables
5184 vars.Push (new DictionaryEntry (var, expr));
5186 // Assign a = new SimpleAssign (var, expr, decl.Location);
5187 // assign_block.AddStatement (new StatementExpression (a));
5190 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5191 // It can be referred to as $5 below.
5196 Statement stmt = (Statement) $6;
5197 Stack vars = (Stack) $5;
5198 Location l = (Location) $1;
5200 while (vars.Count > 0) {
5201 DictionaryEntry de = (DictionaryEntry) vars.Pop ();
5202 stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
5204 current_block.AddStatement (stmt);
5205 $$ = end_block (lexer.Location);
5207 | USING open_parens_any expression CLOSE_PARENS
5209 start_block (lexer.Location);
5213 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1));
5214 $$ = end_block (lexer.Location);
5222 : first_from_clause query_body
5224 lexer.query_parsing = false;
5226 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5228 from.Tail.Next = (Linq.AQueryClause)$2;
5231 current_block.SetEndLocation (lexer.Location);
5232 current_block = current_block.Parent;
5234 | nested_from_clause query_body
5236 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5238 from.Tail.Next = (Linq.AQueryClause)$2;
5241 current_block.SetEndLocation (lexer.Location);
5242 current_block = current_block.Parent;
5247 : FROM_FIRST IDENTIFIER IN expression
5249 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5250 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5252 | FROM_FIRST type IDENTIFIER IN expression
5254 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5255 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5260 : FROM IDENTIFIER IN expression
5262 $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4));
5263 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5265 | FROM type IDENTIFIER IN expression
5267 $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5));
5268 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1));
5273 : FROM IDENTIFIER IN
5275 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5279 LocatedToken lt = (LocatedToken) $2;
5280 $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5);
5282 current_block.SetEndLocation (lexer.Location);
5283 current_block = current_block.Parent;
5285 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5287 | FROM type IDENTIFIER IN
5289 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5293 LocatedToken lt = (LocatedToken) $3;
5294 FullNamedExpression type = (FullNamedExpression)$2;
5296 $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6));
5298 current_block.SetEndLocation (lexer.Location);
5299 current_block = current_block.Parent;
5301 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5306 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5308 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5311 head.Next = (Linq.AQueryClause)$3;
5314 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5315 clause.Tail.Next = head;
5323 select_or_group_clause
5326 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5330 $$ = new Linq.Select (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5332 current_block.SetEndLocation (lexer.Location);
5333 current_block = current_block.Parent;
5337 if (linq_clause_blocks == null)
5338 linq_clause_blocks = new Stack ();
5340 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5341 linq_clause_blocks.Push (current_block);
5345 current_block.SetEndLocation (lexer.Location);
5346 current_block = current_block.Parent;
5348 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5352 $$ = new Linq.GroupBy (current_block.Toplevel, (Expression)$3, (ToplevelBlock) linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5354 current_block.SetEndLocation (lexer.Location);
5355 current_block = current_block.Parent;
5359 opt_query_body_clauses
5361 | query_body_clauses
5366 | query_body_clauses query_body_clause
5368 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5382 : LET IDENTIFIER ASSIGN
5384 current_block = new Linq.QueryBlock (current_block, GetLocation ($1));
5388 LocatedToken lt = (LocatedToken) $2;
5389 $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5);
5391 current_block.SetEndLocation (lexer.Location);
5392 current_block = current_block.Parent;
5394 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5401 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5405 $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1));
5407 current_block.SetEndLocation (lexer.Location);
5408 current_block = current_block.Parent;
5413 : JOIN IDENTIFIER IN
5415 if (linq_clause_blocks == null)
5416 linq_clause_blocks = new Stack ();
5418 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5419 linq_clause_blocks.Push (current_block);
5423 current_block.SetEndLocation (lexer.Location);
5424 current_block = current_block.Parent;
5426 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5427 linq_clause_blocks.Push (current_block);
5431 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5432 current_block.SetEndLocation (lexer.Location);
5433 current_block = current_block.Parent;
5435 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location);
5437 expression opt_join_into
5439 LocatedToken lt = (LocatedToken) $2;
5441 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5442 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5445 $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1));
5447 $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel,
5448 (LocatedToken) $12, GetLocation ($1));
5451 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5452 current_block.SetEndLocation (lexer.Location);
5453 current_block = current_block.Parent;
5456 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5458 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12);
5460 | JOIN type IDENTIFIER IN
5462 if (linq_clause_blocks == null)
5463 linq_clause_blocks = new Stack ();
5465 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5466 linq_clause_blocks.Push (current_block);
5470 current_block.SetEndLocation (lexer.Location);
5471 current_block = current_block.Parent;
5473 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5474 linq_clause_blocks.Push (current_block);
5478 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5479 current_block.SetEndLocation (lexer.Location);
5480 current_block = current_block.Parent;
5482 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location);
5484 expression opt_join_into
5486 LocatedToken lt = (LocatedToken) $3;
5487 ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop ();
5488 ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop ();
5490 Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6);
5492 $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1));
5494 $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel,
5495 (LocatedToken) $13, GetLocation ($1));
5498 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5499 current_block.SetEndLocation (lexer.Location);
5500 current_block = current_block.Parent;
5503 ((Linq.QueryBlock)current_block).AddTransparentParameter (lt);
5505 ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13);
5520 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5524 current_block.SetEndLocation (lexer.Location);
5525 current_block = current_block.Parent;
5535 current_block.SetEndLocation (lexer.Location);
5536 current_block = current_block.Parent;
5538 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5542 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5549 | orderings_then_by COMMA
5551 current_block.SetEndLocation (lexer.Location);
5552 current_block = current_block.Parent;
5554 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5558 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$3;
5566 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5568 | expression ASCENDING
5570 $$ = new Linq.OrderByAscending (current_block.Toplevel, (Expression)$1);
5572 | expression DESCENDING
5574 $$ = new Linq.OrderByDescending (current_block.Toplevel, (Expression)$1);
5581 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5583 | expression ASCENDING
5585 $$ = new Linq.ThenByAscending (current_block.Toplevel, (Expression)$1);
5587 | expression DESCENDING
5589 $$ = new Linq.ThenByDescending (current_block.Toplevel, (Expression)$1);
5594 opt_query_continuation
5598 // query continuation block is not linked with query block but with block
5599 // before. This means each query can use same range variable names for
5600 // different identifiers.
5602 current_block.SetEndLocation (GetLocation ($1));
5603 current_block = current_block.Parent;
5605 current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1));
5609 $$ = new Linq.QueryExpression (current_block, (Linq.AQueryClause)$4);
5614 // Support for using the compiler as an interactive parser
5616 // The INTERACTIVE_PARSER token is first sent to parse our
5617 // productions; If the result is a Statement, the parsing
5618 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5619 // to setup the blocks in advance.
5621 // This setup is here so that in the future we can add
5622 // support for other constructs (type parsing, namespaces, etc)
5623 // that do not require a block to be setup in advance
5627 : EVAL_STATEMENT_PARSER EOF
5628 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5629 | EVAL_STATEMENT_PARSER {
5630 Evaluator.LoadAliases (current_namespace);
5632 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5633 Modifiers.PUBLIC, null), null);
5635 ArrayList baseclass_list = new ArrayList ();
5636 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5637 current_container.AddBasesForPart (current_class, baseclass_list);
5639 // (ref object retval)
5640 Parameter [] mpar = new Parameter [1];
5641 mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null);
5643 ParametersCompiled pars = new ParametersCompiled (mpar);
5644 current_local_parameters = pars;
5645 Method method = new Method (
5648 TypeManager.system_void_expr,
5649 Modifiers.PUBLIC | Modifiers.STATIC,
5650 new MemberName ("Host"),
5652 null /* attributes */);
5654 oob_stack.Push (method);
5655 ++lexer.parsing_block;
5656 start_block (lexer.Location);
5658 interactive_statement_list
5660 --lexer.parsing_block;
5661 Method method = (Method) oob_stack.Pop ();
5663 method.Block = (ToplevelBlock) end_block(lexer.Location);
5664 current_container.AddMethod (method);
5666 --lexer.parsing_declaration;
5667 InteractiveResult = pop_current_class ();
5668 current_local_parameters = null;
5670 | EVAL_COMPILATION_UNIT_PARSER {
5671 Evaluator.LoadAliases (current_namespace);
5673 interactive_compilation_unit
5676 interactive_compilation_unit
5677 : outer_declarations
5678 | outer_declarations global_attributes
5685 // A class used to pass around variable declarations and constants
5687 public class VariableDeclaration {
5688 public string identifier;
5689 public Expression expression_or_array_initializer;
5690 public Location Location;
5691 public Attributes OptAttributes;
5692 public string DocComment;
5694 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5696 this.identifier = lt.Value;
5697 if (eoai is ArrayList) {
5698 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5700 this.expression_or_array_initializer = (Expression)eoai;
5702 this.Location = lt.Location;
5703 this.OptAttributes = opt_attrs;
5706 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5711 class VariableMemberDeclaration
5713 public readonly MemberName MemberName;
5714 public Expression expression_or_array_initializer;
5716 public VariableMemberDeclaration (MemberName mn, object initializer)
5720 if (initializer is ArrayList) {
5721 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
5723 this.expression_or_array_initializer = (Expression)initializer;
5730 // A class used to hold info about an operator declarator
5732 struct OperatorDeclaration {
5733 public readonly Operator.OpType optype;
5734 public readonly FullNamedExpression ret_type;
5735 public readonly Location location;
5737 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5740 this.ret_type = ret_type;
5741 this.location = location;
5745 void Error_ExpectingTypeName (Expression expr)
5747 if (expr is Invocation){
5748 Report.Error (1002, expr.Location, "Expecting `;'");
5750 expr.Error_InvalidExpressionStatement ();
5754 static void Error_ParameterModifierNotValid (string modifier, Location loc)
5756 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5760 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5762 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5763 Parameter.GetModifierSignature (mod));
5766 static void Error_TypeExpected (Location loc)
5768 Report.Error (1031, loc, "Type expected");
5771 void push_current_class (TypeContainer tc, object partial_token)
5773 if (RootContext.EvalMode){
5774 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5775 undo.AddTypeContainer (current_container, tc);
5778 if (partial_token != null)
5779 current_container = current_container.AddPartial (tc);
5781 current_container = current_container.AddTypeContainer (tc);
5783 ++lexer.parsing_declaration;
5787 DeclSpace pop_current_class ()
5789 DeclSpace retval = current_class;
5791 current_class = current_class.Parent;
5792 current_container = current_class.PartialContainer;
5798 // Given the @class_name name, it creates a fully qualified name
5799 // based on the containing declaration space
5802 MakeName (MemberName class_name)
5804 Namespace ns = current_namespace.NS;
5806 if (current_container == RootContext.ToplevelTypes) {
5807 if (ns.Name.Length != 0)
5808 return new MemberName (ns.MemberName, class_name);
5812 return new MemberName (current_container.MemberName, class_name);
5816 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5818 Block implicit_block;
5819 ArrayList inits = null;
5822 // If we are doing interactive editing, we want variable declarations
5823 // that are in the top block to be added instead to the class as
5826 if (RootContext.StatementMode){
5829 for (Block b = current_block; b != null; b = b.Parent){
5830 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5831 // There has been an explicit block, we cant add to the class
5838 // We can use "current_block" since we know there are no explicit blocks
5840 foreach (VariableDeclaration decl in variable_declarators){
5841 // We can not use the super-handy f.Initializer, because
5842 // multiple lines would force code to be executed out of sync
5843 if (decl.expression_or_array_initializer != null){
5844 string id = "$" + decl.identifier;
5845 current_block.AddVariable (type, id, decl.Location);
5847 LocalVariableReference var;
5848 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location);
5849 Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
5850 current_block.AddStatement (new StatementExpression (assign));
5851 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
5852 current_block.AddStatement (new StatementExpression (assign));
5854 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
5855 new MemberName (decl.identifier, loc), null);
5856 current_container.AddField (f);
5858 // Register the field to be visible later as a global variable
5859 Evaluator.QueueField (f);
5863 return current_block;
5868 // We use the `Used' property to check whether statements
5869 // have been added to the current block. If so, we need
5870 // to create another block to contain the new declaration
5871 // otherwise, as an optimization, we use the same block to
5872 // add the declaration.
5874 // FIXME: A further optimization is to check if the statements
5875 // that were added were added as part of the initialization
5876 // below. In which case, no other statements have been executed
5877 // and we might be able to reduce the number of blocks for
5878 // situations like this:
5880 // int j = 1; int k = j + 1;
5882 if (current_block.Used)
5883 implicit_block = new Block (current_block, loc, lexer.Location);
5885 implicit_block = current_block;
5887 foreach (VariableDeclaration decl in variable_declarators){
5889 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5890 if (decl.expression_or_array_initializer != null){
5892 inits = new ArrayList (4);
5899 return implicit_block;
5901 foreach (VariableDeclaration decl in inits){
5903 Expression expr = decl.expression_or_array_initializer;
5905 LocalVariableReference var;
5906 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5908 assign = new SimpleAssign (var, expr, decl.Location);
5910 implicit_block.AddStatement (new StatementExpression (assign));
5913 return implicit_block;
5916 Block declare_local_constants (Expression type, ArrayList declarators)
5918 Block implicit_block;
5920 if (current_block.Used)
5921 implicit_block = new Block (current_block);
5923 implicit_block = current_block;
5925 foreach (VariableDeclaration decl in declarators){
5926 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5929 return implicit_block;
5932 string CheckAttributeTarget (string a, Location l)
5935 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5939 Report.Warning (658, 1, l,
5940 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5941 return string.Empty;
5944 static bool IsUnaryOperator (Operator.OpType op)
5948 case Operator.OpType.LogicalNot:
5949 case Operator.OpType.OnesComplement:
5950 case Operator.OpType.Increment:
5951 case Operator.OpType.Decrement:
5952 case Operator.OpType.True:
5953 case Operator.OpType.False:
5954 case Operator.OpType.UnaryPlus:
5955 case Operator.OpType.UnaryNegation:
5961 void syntax_error (Location l, string msg)
5963 Report.Error (1003, l, "Syntax error, " + msg);
5966 void note (string s)
5968 // Used to put annotations
5973 public Tokenizer Lexer {
5979 static CSharpParser ()
5981 oob_stack = new Stack ();
5984 public CSharpParser (SeekableStreamReader reader, CompilationUnit file)
5986 if (RootContext.EvalMode)
5990 current_namespace = new NamespaceEntry (null, file, null);
5991 current_class = current_namespace.SlaveDeclSpace;
5992 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5994 lexer = new Tokenizer (reader, file);
5997 public void parse ()
5999 eof_token = Token.EOF;
6002 if (yacc_verbose_flag > 1)
6003 yyparse (lexer, new yydebug.yyDebugSimple ());
6006 } catch (Exception e){
6007 if (e is yyParser.yyUnexpectedEof)
6008 UnexpectedEOF = true;
6009 else if (yacc_verbose_flag > 0)
6010 Console.WriteLine (e);
6011 if (e is yyParser.yyException)
6012 Report.Error (-25, lexer.Location, "Parsing error");
6014 Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details");
6016 Tokenizer tokenizer = lexer as Tokenizer;
6017 tokenizer.cleanup ();
6019 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6020 throw new InternalErrorException ("who set it?");
6023 static void CheckToken (int error, int yyToken, string msg, Location loc)
6025 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6026 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6028 Report.Error (error, loc, msg);
6031 void CheckIdentifierToken (int yyToken, Location loc)
6033 CheckToken (1041, yyToken, "Identifier expected", loc);
6036 string ConsumeStoredComment ()
6038 string s = tmpComment;
6040 Lexer.doc_state = XmlCommentState.Allowed;
6044 Location GetLocation (object obj)
6046 if (obj is MemberCore)
6047 return ((MemberCore) obj).Location;
6048 if (obj is MemberName)
6049 return ((MemberName) obj).Location;
6050 if (obj is LocatedToken)
6051 return ((LocatedToken) obj).Location;
6052 if (obj is Location)
6053 return (Location) obj;
6054 return lexer.Location;
6057 void start_block (Location loc)
6059 if (current_block == null || parsing_anonymous_method) {
6060 current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc);
6061 parsing_anonymous_method = false;
6063 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6068 end_block (Location loc)
6070 Block retval = current_block.Explicit;
6071 retval.SetEndLocation (loc);
6072 current_block = retval.Parent;
6077 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6079 if (RootContext.Version == LanguageVersion.ISO_1){
6080 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6083 oob_stack.Push (current_anonymous_method);
6084 oob_stack.Push (current_local_parameters);
6086 current_local_parameters = parameters;
6088 current_anonymous_method = lambda
6089 ? new LambdaExpression (loc)
6090 : new AnonymousMethodExpression (loc);
6092 // Force the next block to be created as a ToplevelBlock
6093 parsing_anonymous_method = true;
6097 * Completes the anonymous method processing, if lambda_expr is null, this
6098 * means that we have a Statement instead of an Expression embedded
6100 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6102 AnonymousMethodExpression retval;
6104 current_anonymous_method.Block = anon_block;
6105 retval = current_anonymous_method;
6107 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6108 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6113 public NamespaceEntry CurrentNamespace {
6115 return current_namespace;
6120 void Error_SyntaxError (int token)
6122 Error_SyntaxError (0, token);
6125 void Error_SyntaxError (int error_code, int token)
6127 string symbol = GetSymbolName (token);
6128 string expecting = GetExpecting ();
6130 if (error_code == 0) {
6131 if (expecting == "`)'")
6137 if (expecting != null)
6138 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}",
6141 Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol);
6144 string GetExpecting ()
6146 int [] tokens = yyExpectingTokens (yyExpectingState);
6147 ArrayList names = new ArrayList (tokens.Length);
6148 bool has_type = false;
6149 bool has_identifier = false;
6150 for (int i = 0; i < tokens.Length; i++){
6151 int token = tokens [i];
6152 has_identifier |= token == Token.IDENTIFIER;
6154 string name = GetTokenName (token);
6155 if (name == "<internal>")
6158 has_type |= name == "type";
6159 if (names.Contains (name))
6166 // Too many tokens to enumerate
6168 if (names.Count > 8)
6171 if (has_type && has_identifier)
6172 names.Remove ("identifier");
6174 if (names.Count == 1)
6175 return "`" + GetTokenName (tokens [0]) + "'";
6177 StringBuilder sb = new StringBuilder ();
6179 int count = names.Count;
6180 for (int i = 0; i < count; i++){
6181 bool last = i + 1 == count;
6185 sb.Append (names [i]);
6186 sb.Append (last ? "'" : "', ");
6188 return sb.ToString ();
6192 string GetSymbolName (int token)
6195 case Token.LITERAL_FLOAT:
6196 case Token.LITERAL_INTEGER:
6197 case Token.LITERAL_DOUBLE:
6198 case Token.LITERAL_DECIMAL:
6199 case Token.LITERAL_CHARACTER:
6200 case Token.LITERAL_STRING:
6201 return lexer.Value.ToString ();
6202 case Token.IDENTIFIER:
6203 return ((LocatedToken)lexer.Value).Value;
6245 case Token.BITWISE_AND:
6247 case Token.BITWISE_OR:
6261 case Token.OP_SHIFT_LEFT:
6263 case Token.OP_SHIFT_RIGHT:
6283 case Token.OP_COALESCING:
6285 case Token.OP_MULT_ASSIGN:
6287 case Token.OP_DIV_ASSIGN:
6289 case Token.OP_MOD_ASSIGN:
6291 case Token.OP_ADD_ASSIGN:
6293 case Token.OP_SUB_ASSIGN:
6295 case Token.OP_SHIFT_LEFT_ASSIGN:
6297 case Token.OP_SHIFT_RIGHT_ASSIGN:
6299 case Token.OP_AND_ASSIGN:
6301 case Token.OP_XOR_ASSIGN:
6303 case Token.OP_OR_ASSIGN:
6307 return GetTokenName (token);
6310 static string GetTokenName (int token)
6313 case Token.ABSTRACT:
6333 case Token.CONTINUE:
6337 case Token.DELEGATE:
6347 case Token.EXPLICIT:
6365 case Token.IMPLICIT:
6369 case Token.INTERFACE:
6371 case Token.INTERNAL:
6377 case Token.NAMESPACE:
6383 case Token.OPERATOR:
6387 case Token.OVERRIDE:
6393 case Token.PROTECTED:
6397 case Token.READONLY:
6409 case Token.STACKALLOC:
6410 return "stackalloc";
6427 case Token.UNCHECKED:
6435 case Token.VOLATILE:
6448 case Token.FROM_FIRST:
6466 case Token.ASCENDING:
6468 case Token.DESCENDING:
6469 return "descending";
6476 case Token.OPEN_BRACE:
6478 case Token.CLOSE_BRACE:
6480 case Token.OPEN_BRACKET:
6482 case Token.CLOSE_BRACKET:
6484 case Token.OPEN_PARENS_CAST:
6485 case Token.OPEN_PARENS_LAMBDA:
6486 case Token.OPEN_PARENS:
6488 case Token.CLOSE_PARENS:
6494 case Token.DEFAULT_COLON:
6498 case Token.SEMICOLON:
6509 case Token.BITWISE_AND:
6510 case Token.BITWISE_OR:
6517 case Token.OP_SHIFT_LEFT:
6518 case Token.OP_SHIFT_RIGHT:
6526 case Token.OP_COALESCING:
6527 case Token.OP_MULT_ASSIGN:
6528 case Token.OP_DIV_ASSIGN:
6529 case Token.OP_MOD_ASSIGN:
6530 case Token.OP_ADD_ASSIGN:
6531 case Token.OP_SUB_ASSIGN:
6532 case Token.OP_SHIFT_LEFT_ASSIGN:
6533 case Token.OP_SHIFT_RIGHT_ASSIGN:
6534 case Token.OP_AND_ASSIGN:
6535 case Token.OP_XOR_ASSIGN:
6536 case Token.OP_OR_ASSIGN:
6537 return "<operator>";
6559 case Token.OP_GENERICS_LT:
6560 case Token.GENERIC_DIMENSION:
6562 case Token.OP_GENERICS_GT:
6565 case Token.INTERR_NULLABLE:
6567 case Token.DOUBLE_COLON:
6569 case Token.LITERAL_FLOAT:
6570 case Token.LITERAL_INTEGER:
6571 case Token.LITERAL_DOUBLE:
6572 case Token.LITERAL_DECIMAL:
6573 case Token.LITERAL_CHARACTER:
6574 case Token.LITERAL_STRING:
6576 case Token.IDENTIFIER:
6577 return "identifier";
6579 // All of these are internal.
6582 case Token.FIRST_KEYWORD:
6584 case Token.EVAL_COMPILATION_UNIT_PARSER:
6585 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6586 case Token.EVAL_STATEMENT_PARSER:
6587 case Token.LAST_KEYWORD:
6588 return "<internal>";
6590 // A bit more robust.
6592 return yyNames [token];