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 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
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:
23 using System.Collections.Generic;
30 public class CSharpParser
33 enum ParameterModifierType
40 DefaultValue = 1 << 6,
42 All = Ref | Out | This | Params | Arglist | DefaultValue
45 static readonly object ModifierNone = 0;
47 NamespaceEntry current_namespace;
48 TypeContainer current_container;
49 DeclSpace current_class;
50 PropertyBase current_property;
51 EventProperty current_event;
52 EventField current_event_field;
53 FieldBase current_field;
56 /// Current block is used to add statements as we find
61 Delegate current_delegate;
63 AnonymousMethodExpression current_anonymous_method;
66 /// This is used by the unary_expression code to resolve
67 /// a name against a parameter.
70 // FIXME: This is very ugly and it's very hard to reset it correctly
71 // on all places, especially when some parameters are autogenerated.
72 ParametersCompiled current_local_parameters;
74 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 static Stack<object> oob_stack;
84 Stack<Block> switch_stack;
87 /// Controls the verbosity of the errors produced by the parser
89 static public int yacc_verbose_flag;
92 /// Used by the interactive shell, flags whether EOF was reached
93 /// and an error was produced
95 public bool UnexpectedEOF;
100 CompilationUnit file;
103 /// Temporary Xml documentation cache.
104 /// For enum types, we need one more temporary store.
107 string enumTypeComment;
109 /// Current attribute target
110 string current_attr_target;
112 /// assembly and module attribute definitions are enabled
113 bool global_attrs_enabled = true;
115 ParameterModifierType valid_param_mod;
117 bool default_parameter_used;
119 /// When using the interactive parser, this holds the
120 /// resulting expression
121 public object InteractiveResult;
124 // Keeps track of global data changes to undo on parser error
128 Stack<Linq.QueryBlock> linq_clause_blocks;
130 // A counter to create new class names in interactive mode
131 static int class_count;
133 CompilerContext compiler;
136 // Instead of allocating carrier array everytime we
137 // share the bucket for very common constructs which can never
140 static List<Parameter> parameters_bucket = new List<Parameter> (6);
141 static List<object> variables_bucket = new List<object> (6);
144 // Full AST support members
147 List<Tuple<Modifiers, Location>> mod_locations;
151 %token NONE /* This token is never returned by our lexer */
152 %token ERROR // This is used not by the parser, but by the tokenizer.
156 *These are the C# keywords
255 %token INTERR_NULLABLE
258 /* Generics <,> tokens */
259 %token OP_GENERICS_LT
260 %token OP_GENERICS_LT_DECL
261 %token OP_GENERICS_GT
263 /* C# keywords which are not really keywords */
269 /* C# single character operators/punctuation. */
297 /* C# multi-character operators. */
302 %token OP_SHIFT_RIGHT
309 %token OP_MULT_ASSIGN
314 %token OP_SHIFT_LEFT_ASSIGN
315 %token OP_SHIFT_RIGHT_ASSIGN
325 %token OPEN_PARENS_LAMBDA
326 %token OPEN_PARENS_CAST
327 %token GENERIC_DIMENSION
329 %token OPEN_BRACKET_EXPR
331 // Make the parser go into eval mode parsing (statements and compilation units).
332 %token EVAL_STATEMENT_PARSER
333 %token EVAL_COMPILATION_UNIT_PARSER
334 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
337 // This token is generated to trigger the completion engine at this point
339 %token GENERATE_COMPLETION
342 // This token is return repeatedly after the first GENERATE_COMPLETION
343 // token is produced and before the final EOF
345 %token COMPLETE_COMPLETION
347 /* Add precedence rules to solve dangling else s/r conflict */
351 /* Define the operator tokens and their precedences */
359 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
361 %left STAR DIV PERCENT
362 %right BANG CARRET UMINUS
363 %nonassoc OP_INC OP_DEC
365 %left OPEN_BRACKET OPEN_BRACE
368 %start compilation_unit
372 : outer_declarations opt_EOF
373 | outer_declarations global_attributes opt_EOF
374 | global_attributes opt_EOF
375 | opt_EOF /* allow empty files */
376 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
382 Lexer.check_incorrect_doc_comment ();
386 Lexer.check_incorrect_doc_comment ();
392 | outer_declarations outer_declaration
396 : extern_alias_directive
398 | namespace_member_declaration
401 extern_alias_directives
402 : extern_alias_directive
403 | extern_alias_directives extern_alias_directive
406 extern_alias_directive
407 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
409 var lt = (Tokenizer.LocatedToken) $2;
412 syntax_error (lt.Location, "`alias' expected");
413 } else if (RootContext.Version == LanguageVersion.ISO_1) {
414 Report.FeatureIsNotAvailable (lt.Location, "external alias");
416 lt = (Tokenizer.LocatedToken) $3;
417 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
422 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
428 | using_directives using_directive
432 : using_alias_directive
434 if (RootContext.Documentation != null)
435 Lexer.doc_state = XmlCommentState.Allowed;
437 | using_namespace_directive
439 if (RootContext.Documentation != null)
440 Lexer.doc_state = XmlCommentState.Allowed;
444 using_alias_directive
445 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
447 var lt = (Tokenizer.LocatedToken) $2;
448 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
451 CheckIdentifierToken (yyToken, GetLocation ($2));
456 using_namespace_directive
457 : USING namespace_name SEMICOLON
459 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
464 // Strictly speaking, namespaces don't have attributes but
465 // we parse global attributes along with namespace declarations and then
468 namespace_declaration
469 : opt_attributes NAMESPACE qualified_identifier
471 MemberName name = (MemberName) $3;
474 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
477 current_namespace = new NamespaceEntry (
478 current_namespace, file, name.GetName ());
479 current_class = current_namespace.SlaveDeclSpace;
480 current_container = current_class.PartialContainer;
482 namespace_body opt_semicolon
484 current_namespace = current_namespace.Parent;
485 current_class = current_namespace.SlaveDeclSpace;
486 current_container = current_class.PartialContainer;
493 var lt = (Tokenizer.LocatedToken) $1;
494 $$ = new MemberName (lt.Value, lt.Location);
496 | qualified_identifier DOT IDENTIFIER
498 var lt = (Tokenizer.LocatedToken) $3;
499 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
503 syntax_error (lexer.Location, "`.' expected");
504 $$ = new MemberName ("<invalid>", lexer.Location);
519 : namespace_or_type_name
521 MemberName name = (MemberName) $1;
523 if (name.TypeArguments != null)
524 syntax_error (lexer.Location, "namespace name expected");
533 if (RootContext.Documentation != null)
534 Lexer.doc_state = XmlCommentState.Allowed;
540 : opt_extern_alias_directives
542 opt_namespace_member_declarations
546 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
549 | opt_extern_alias_directives
551 opt_namespace_member_declarations
554 Report.Error (1513, lexer.Location, "Expected `}'");
563 opt_extern_alias_directives
565 | extern_alias_directives
568 opt_namespace_member_declarations
570 | namespace_member_declarations
573 namespace_member_declarations
574 : namespace_member_declaration
575 | namespace_member_declarations namespace_member_declaration
578 namespace_member_declaration
582 DeclSpace ds = (DeclSpace)$1;
584 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
585 Report.Error (1527, ds.Location,
586 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
589 current_namespace.DeclarationFound = true;
591 | namespace_declaration {
592 current_namespace.DeclarationFound = true;
595 | field_declaration {
596 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
598 | method_declaration {
599 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
606 | interface_declaration
608 | delegate_declaration
610 // Enable this when we have handled all errors, because this acts as a generic fallback
613 // Console.WriteLine ("Token=" + yyToken);
614 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
626 Attributes attrs = (Attributes)$1;
627 if (global_attrs_enabled) {
628 CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
630 foreach (Attribute a in attrs.Attrs) {
631 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
642 global_attrs_enabled = false;
647 global_attrs_enabled = false;
656 if (current_attr_target != String.Empty) {
657 var sect = (List<Attribute>) $1;
659 if (global_attrs_enabled) {
660 if (current_attr_target == "module") {
661 current_container.Module.Compiled.AddAttributes (sect);
663 } else if (current_attr_target != null && current_attr_target.Length > 0) {
664 CodeGen.Assembly.AddAttributes (sect, current_namespace);
667 $$ = new Attributes (sect);
670 if (RootContext.Documentation != null) {
671 Lexer.check_incorrect_doc_comment ();
673 XmlCommentState.Allowed;
677 $$ = new Attributes (sect);
682 current_attr_target = null;
684 | attribute_sections attribute_section
686 if (current_attr_target != String.Empty) {
687 Attributes attrs = $1 as Attributes;
688 var sect = (List<Attribute>) $2;
690 if (global_attrs_enabled) {
691 if (current_attr_target == "module") {
692 current_container.Module.Compiled.AddAttributes (sect);
694 } else if (current_attr_target == "assembly") {
695 CodeGen.Assembly.AddAttributes (sect, current_namespace);
699 attrs = new Attributes (sect);
701 attrs.AddAttributes (sect);
705 attrs = new Attributes (sect);
707 attrs.AddAttributes (sect);
713 current_attr_target = null;
718 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
722 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
728 attribute_target_specifier
729 : attribute_target COLON
731 current_attr_target = (string)$1;
739 var lt = (Tokenizer.LocatedToken) $1;
740 $$ = CheckAttributeTarget (lt.Value, lt.Location);
742 | EVENT { $$ = "event"; }
743 | RETURN { $$ = "return"; }
746 string name = GetTokenName (yyToken);
747 $$ = CheckAttributeTarget (name, GetLocation ($1));
754 $$ = new List<Attribute> (4) { (Attribute) $1 };
756 | attribute_list COMMA attribute
758 var attrs = (List<Attribute>) $1;
759 attrs.Add ((Attribute) $3);
768 ++lexer.parsing_block;
770 opt_attribute_arguments
772 --lexer.parsing_block;
773 MemberName mname = (MemberName) $1;
774 if (mname.IsGeneric) {
775 Report.Error (404, lexer.Location,
776 "'<' unexpected: attributes cannot be generic");
779 Arguments [] arguments = (Arguments []) $3;
780 ATypeNameExpression expr = mname.GetTypeExpression ();
782 if (current_attr_target == String.Empty)
784 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
785 // FIXME: supply "nameEscaped" parameter here.
786 $$ = new GlobalAttribute (current_namespace, current_attr_target,
787 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
789 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
794 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
797 opt_attribute_arguments
798 : /* empty */ { $$ = null; }
799 | OPEN_PARENS attribute_arguments CLOSE_PARENS
807 : /* empty */ { $$ = null; }
808 | positional_or_named_argument
810 Arguments a = new Arguments (4);
811 a.Add ((Argument) $1);
812 $$ = new Arguments [] { a, null };
814 | named_attribute_argument
816 Arguments a = new Arguments (4);
817 a.Add ((Argument) $1);
818 $$ = new Arguments [] { null, a };
820 | attribute_arguments COMMA positional_or_named_argument
822 Arguments[] o = (Arguments[]) $1;
824 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
825 o [0] = new Arguments (4);
828 Arguments args = ((Arguments) o [0]);
829 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
830 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
832 args.Add ((Argument) $3);
834 | attribute_arguments COMMA named_attribute_argument
836 Arguments[] o = (Arguments[]) $1;
838 o [1] = new Arguments (4);
841 ((Arguments) o [1]).Add ((Argument) $3);
845 positional_or_named_argument
848 $$ = new Argument ((Expression) $1);
853 named_attribute_argument
856 ++lexer.parsing_block;
860 --lexer.parsing_block;
861 var lt = (Tokenizer.LocatedToken) $1;
862 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
867 : IDENTIFIER COLON opt_named_modifier expression
869 if (RootContext.Version <= LanguageVersion.V_3)
870 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
872 // Avoid boxing in common case (no modifier)
873 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
875 var lt = (Tokenizer.LocatedToken) $1;
876 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
881 : /* empty */ { $$ = null; }
884 $$ = Argument.AType.Ref;
888 $$ = Argument.AType.Out;
892 opt_class_member_declarations
894 | class_member_declarations
897 class_member_declarations
898 : class_member_declaration
899 | class_member_declarations
900 class_member_declaration
903 class_member_declaration
904 : constant_declaration // done
905 | field_declaration // done
906 | method_declaration // done
907 | property_declaration // done
908 | event_declaration // done
909 | indexer_declaration // done
910 | operator_declaration // done
911 | constructor_declaration // done
912 | destructor_declaration // done
916 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
917 GetSymbolName (yyToken));
919 lexer.parsing_generic_declaration = false;
929 lexer.ConstraintsParsing = true;
931 type_declaration_name
933 MemberName name = MakeName ((MemberName) $6);
934 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
937 opt_type_parameter_constraints_clauses
939 lexer.ConstraintsParsing = false;
941 current_class.SetParameterInfo ((List<Constraints>) $9);
943 if (RootContext.Documentation != null)
944 current_container.DocComment = Lexer.consume_doc_comment ();
946 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
950 --lexer.parsing_declaration;
951 if (RootContext.Documentation != null)
952 Lexer.doc_state = XmlCommentState.Allowed;
956 lbag.AppendToMember (current_class, GetLocation ($13));
957 $$ = pop_current_class ();
959 | opt_attributes opt_modifiers opt_partial STRUCT error {
960 CheckIdentifierToken (yyToken, GetLocation ($5));
967 if (RootContext.Documentation != null)
968 Lexer.doc_state = XmlCommentState.Allowed;
970 opt_struct_member_declarations CLOSE_BRACE
972 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
976 opt_struct_member_declarations
978 | struct_member_declarations
981 struct_member_declarations
982 : struct_member_declaration
983 | struct_member_declarations struct_member_declaration
986 struct_member_declaration
987 : constant_declaration
990 | property_declaration
992 | indexer_declaration
993 | operator_declaration
994 | constructor_declaration
998 * This is only included so we can flag error 575:
999 * destructors only allowed on class types
1001 | destructor_declaration
1004 constant_declaration
1007 CONST type IDENTIFIER
1009 var lt = (Tokenizer.LocatedToken) $5;
1010 var mod = (Modifiers) $2;
1011 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1012 current_container.AddConstant ((Const) current_field);
1014 if ((mod & Modifiers.STATIC) != 0) {
1015 Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1020 constant_initializer opt_constant_declarators SEMICOLON
1022 if (RootContext.Documentation != null) {
1023 current_field.DocComment = Lexer.consume_doc_comment ();
1024 Lexer.doc_state = XmlCommentState.Allowed;
1027 current_field.Initializer = (ConstInitializer) $7;
1028 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1029 current_field = null;
1033 opt_constant_declarators
1035 | constant_declarators
1038 constant_declarators
1039 : constant_declarator
1041 current_field.AddDeclarator ((FieldDeclarator) $1);
1043 | constant_declarators constant_declarator
1045 current_field.AddDeclarator ((FieldDeclarator) $2);
1050 : COMMA IDENTIFIER constant_initializer
1052 var lt = (Tokenizer.LocatedToken) $2;
1053 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1054 lbag.AddLocation ($$, GetLocation ($1));
1058 constant_initializer
1061 ++lexer.parsing_block;
1063 constant_initializer_expr
1065 --lexer.parsing_block;
1066 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1070 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
1075 constant_initializer_expr
1076 : constant_expression
1083 member_type IDENTIFIER
1085 lexer.parsing_generic_declaration = false;
1087 FullNamedExpression type = (FullNamedExpression) $3;
1088 if (type.Type == TypeManager.void_type)
1089 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1091 var lt = (Tokenizer.LocatedToken) $4;
1092 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1093 current_container.AddField (current_field);
1096 opt_field_initializer
1097 opt_field_declarators
1100 if (RootContext.Documentation != null) {
1101 current_field.DocComment = Lexer.consume_doc_comment ();
1102 Lexer.doc_state = XmlCommentState.Allowed;
1105 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1107 current_field = null;
1111 FIXED simple_type IDENTIFIER
1113 if (RootContext.Version < LanguageVersion.ISO_2)
1114 Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1116 var lt = (Tokenizer.LocatedToken) $5;
1117 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1118 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1120 current_container.AddField (current_field);
1122 fixed_field_size opt_fixed_field_declarators SEMICOLON
1124 if (RootContext.Documentation != null) {
1125 current_field.DocComment = Lexer.consume_doc_comment ();
1126 Lexer.doc_state = XmlCommentState.Allowed;
1129 current_field.Initializer = (ConstInitializer) $7;
1130 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1132 current_field = null;
1136 FIXED simple_type error
1139 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1143 opt_field_initializer
1147 ++lexer.parsing_block;
1149 variable_initializer
1151 --lexer.parsing_block;
1152 current_field.Initializer = (Expression) $3;
1156 opt_field_declarators
1164 current_field.AddDeclarator ((FieldDeclarator) $1);
1166 | field_declarators field_declarator
1168 current_field.AddDeclarator ((FieldDeclarator) $2);
1175 var lt = (Tokenizer.LocatedToken) $2;
1176 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1177 lbag.AddLocation ($$, GetLocation ($1));
1179 | COMMA IDENTIFIER ASSIGN
1181 ++lexer.parsing_block;
1183 variable_initializer
1185 --lexer.parsing_block;
1186 var lt = (Tokenizer.LocatedToken) $2;
1187 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1188 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1192 opt_fixed_field_declarators
1194 | fixed_field_declarators
1197 fixed_field_declarators
1198 : fixed_field_declarator
1200 current_field.AddDeclarator ((FieldDeclarator) $1);
1202 | fixed_field_declarators fixed_field_declarator
1204 current_field.AddDeclarator ((FieldDeclarator) $2);
1208 fixed_field_declarator
1209 : COMMA IDENTIFIER fixed_field_size
1211 var lt = (Tokenizer.LocatedToken) $2;
1212 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1213 lbag.AddLocation ($$, GetLocation ($1));
1220 ++lexer.parsing_block;
1222 expression CLOSE_BRACKET
1224 --lexer.parsing_block;
1225 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1226 lbag.AddLocation ($$, GetLocation ($4));
1228 | OPEN_BRACKET error
1230 Report.Error (443, lexer.Location, "Value or constant expected");
1236 local_variable_declarators
1237 : local_variable_declarator
1239 variables_bucket.Clear ();
1241 variables_bucket.Add ($1);
1242 $$ = variables_bucket;
1244 | local_variable_declarators COMMA local_variable_declarator
1246 var decls = (List<object>) $1;
1248 lbag.AppendTo ($3, GetLocation ($2));
1253 local_variable_declarator
1254 : IDENTIFIER ASSIGN local_variable_initializer
1256 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
1257 lbag.AddLocation ($$, GetLocation ($2));
1261 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null);
1263 | IDENTIFIER variable_bad_array
1269 local_variable_initializer
1272 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
1274 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
1275 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
1279 $$ = new ArglistAccess (GetLocation ($1));
1281 | STACKALLOC simple_type
1283 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
1284 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
1289 : OPEN_BRACKET_EXPR opt_expression CLOSE_BRACKET
1291 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1292 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1296 variable_initializer
1303 if (RootContext.Documentation != null)
1304 Lexer.doc_state = XmlCommentState.NotAllowed;
1308 Method method = (Method) $1;
1309 method.Block = (ToplevelBlock) $3;
1310 current_container.AddMethod (method);
1312 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1313 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1316 current_local_parameters = null;
1318 if (RootContext.Documentation != null)
1319 Lexer.doc_state = XmlCommentState.Allowed;
1327 method_declaration_name OPEN_PARENS
1329 valid_param_mod = ParameterModifierType.All;
1331 opt_formal_parameter_list CLOSE_PARENS
1333 lexer.ConstraintsParsing = true;
1335 opt_type_parameter_constraints_clauses
1337 lexer.ConstraintsParsing = false;
1338 valid_param_mod = 0;
1339 MemberName name = (MemberName) $4;
1340 current_local_parameters = (ParametersCompiled) $7;
1342 GenericMethod generic = null;
1343 if (name.TypeArguments != null) {
1344 generic = new GenericMethod (current_namespace, current_class, name,
1345 (FullNamedExpression) $3, current_local_parameters);
1347 generic.SetParameterInfo ((List<Constraints>) $10);
1348 } else if ($10 != null) {
1349 Report.Error (80, GetLocation ($10),
1350 "Constraints are not allowed on non-generic declarations");
1353 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1354 name, current_local_parameters, (Attributes) $1);
1356 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1357 Report.Error (460, method.Location,
1358 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1359 method.GetSignatureForError ());
1362 if (RootContext.Documentation != null)
1363 method.DocComment = Lexer.consume_doc_comment ();
1365 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1371 VOID method_declaration_name
1374 valid_param_mod = ParameterModifierType.All;
1376 opt_formal_parameter_list CLOSE_PARENS
1378 lexer.ConstraintsParsing = true;
1380 opt_type_parameter_constraints_clauses
1382 lexer.ConstraintsParsing = false;
1383 valid_param_mod = 0;
1385 MemberName name = (MemberName) $5;
1386 current_local_parameters = (ParametersCompiled) $8;
1388 if ($10 != null && name.TypeArguments == null)
1389 Report.Error (80, lexer.Location,
1390 "Constraints are not allowed on non-generic declarations");
1393 GenericMethod generic = null;
1394 if (name.TypeArguments != null) {
1395 generic = new GenericMethod (current_namespace, current_class, name,
1396 new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1397 current_local_parameters);
1399 generic.SetParameterInfo ((List<Constraints>) $11);
1402 var modifiers = (Modifiers) $2;
1405 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1406 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1408 if ((modifiers & invalid_partial_mod) != 0) {
1409 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1410 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1411 modifiers &= ~invalid_partial_mod;
1414 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1415 Report.Error (751, name.Location, "A partial method must be declared within a " +
1416 "partial class or partial struct");
1419 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1421 method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1422 modifiers, name, current_local_parameters, (Attributes) $1);
1424 if (RootContext.Documentation != null)
1425 method.DocComment = Lexer.consume_doc_comment ();
1427 // TODO: lbag, push void
1428 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1429 lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
1435 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1437 MemberName name = (MemberName) $5;
1438 Report.Error (1585, name.Location,
1439 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1441 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1442 0, name, (ParametersCompiled) $7, (Attributes) $1);
1444 current_local_parameters = (ParametersCompiled) $7;
1446 if (RootContext.Documentation != null)
1447 method.DocComment = Lexer.consume_doc_comment ();
1455 | SEMICOLON { $$ = null; }
1458 opt_formal_parameter_list
1459 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1460 | formal_parameter_list
1463 formal_parameter_list
1466 var pars_list = (List<Parameter>) $1;
1467 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
1469 | fixed_parameters COMMA parameter_array
1471 var pars_list = (List<Parameter>) $1;
1472 pars_list.Add ((Parameter) $3);
1474 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
1476 | fixed_parameters COMMA arglist_modifier
1478 var pars_list = (List<Parameter>) $1;
1479 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1480 $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
1482 | parameter_array COMMA error
1485 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1487 $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
1489 | fixed_parameters COMMA parameter_array COMMA error
1492 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1494 var pars_list = (List<Parameter>) $1;
1495 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1497 $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
1499 | arglist_modifier COMMA error
1501 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1503 $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1505 | fixed_parameters COMMA ARGLIST COMMA error
1507 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1509 var pars_list = (List<Parameter>) $1;
1510 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1512 $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
1516 $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
1520 $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1527 parameters_bucket.Clear ();
1528 Parameter p = (Parameter) $1;
1529 parameters_bucket.Add (p);
1531 default_parameter_used = p.HasDefaultValue;
1532 $$ = parameters_bucket;
1534 | fixed_parameters COMMA fixed_parameter
1536 var pars = (List<Parameter>) $1;
1537 Parameter p = (Parameter) $3;
1539 if (p.HasExtensionMethodModifier)
1540 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1541 else if (!p.HasDefaultValue && default_parameter_used)
1542 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1544 default_parameter_used |= p.HasDefaultValue;
1547 lbag.AddLocation (p, GetLocation ($2));
1556 opt_parameter_modifier
1560 var lt = (Tokenizer.LocatedToken) $4;
1561 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1564 opt_parameter_modifier
1566 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1568 var lt = (Tokenizer.LocatedToken) $4;
1569 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1570 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1573 opt_parameter_modifier
1577 Location l = GetLocation ($4);
1578 CheckIdentifierToken (yyToken, l);
1579 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1582 opt_parameter_modifier
1587 ++lexer.parsing_block;
1591 --lexer.parsing_block;
1592 if (RootContext.Version <= LanguageVersion.V_3) {
1593 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1596 Parameter.Modifier mod = (Parameter.Modifier) $2;
1597 if (mod != Parameter.Modifier.NONE) {
1599 case Parameter.Modifier.REF:
1600 case Parameter.Modifier.OUT:
1601 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1602 Parameter.GetModifierSignature (mod));
1605 case Parameter.Modifier.This:
1606 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1607 Parameter.GetModifierSignature (mod));
1610 throw new NotImplementedException (mod.ToString ());
1613 mod = Parameter.Modifier.NONE;
1616 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1617 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1619 var lt = (Tokenizer.LocatedToken) $4;
1620 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1621 lbag.AddLocation ($$, GetLocation ($5));
1624 ((Parameter) $$).DefaultValue = (Expression) $7;
1628 opt_parameter_modifier
1629 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1630 | parameter_modifiers
1634 : parameter_modifier
1638 | parameter_modifiers parameter_modifier
1640 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1641 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1642 if (((Parameter.Modifier)$1 & p2) == p2) {
1643 Error_DuplicateParameterModifier (lexer.Location, p2);
1645 switch (mod & ~Parameter.Modifier.This) {
1646 case Parameter.Modifier.REF:
1647 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1649 case Parameter.Modifier.OUT:
1650 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1653 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1664 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1665 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1667 $$ = Parameter.Modifier.REF;
1671 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1672 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1674 $$ = Parameter.Modifier.OUT;
1678 if ((valid_param_mod & ParameterModifierType.This) == 0)
1679 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1681 if (RootContext.Version <= LanguageVersion.ISO_2)
1682 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1684 $$ = Parameter.Modifier.This;
1689 : opt_attributes params_modifier type IDENTIFIER
1691 var lt = (Tokenizer.LocatedToken) $4;
1692 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1694 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1696 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1698 var lt = (Tokenizer.LocatedToken) $4;
1699 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1701 | opt_attributes params_modifier type error
1703 CheckIdentifierToken (yyToken, GetLocation ($4));
1711 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1712 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1714 | PARAMS parameter_modifier
1716 Parameter.Modifier mod = (Parameter.Modifier)$2;
1717 if ((mod & Parameter.Modifier.This) != 0) {
1718 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1720 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1723 | PARAMS params_modifier
1725 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1732 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1733 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1737 property_declaration
1741 member_declaration_name
1743 if (RootContext.Documentation != null)
1744 tmpComment = Lexer.consume_doc_comment ();
1748 current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
1749 (MemberName) $4, (Attributes) $1);
1751 if (current_property.TypeExpression.Type == TypeManager.void_type)
1752 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1754 current_container.AddProperty ((Property)current_property);
1755 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1757 lexer.PropertyParsing = true;
1759 accessor_declarations
1761 lexer.PropertyParsing = false;
1763 if (RootContext.Documentation != null)
1764 current_property.DocComment = ConsumeStoredComment ();
1768 lbag.AppendToMember (current_property, GetLocation ($10));
1769 current_property = null;
1775 : opt_attributes opt_modifiers
1776 member_type indexer_declaration_name OPEN_BRACKET
1778 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1780 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1782 valid_param_mod = 0;
1784 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
1785 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1787 current_property = indexer;
1789 current_container.AddIndexer (indexer);
1790 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1792 if (indexer.TypeExpression.Type == TypeManager.void_type)
1793 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1795 if (indexer.Parameters.IsEmpty) {
1796 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1799 if (RootContext.Documentation != null) {
1800 tmpComment = Lexer.consume_doc_comment ();
1801 Lexer.doc_state = XmlCommentState.Allowed;
1804 lexer.PropertyParsing = true;
1806 accessor_declarations
1808 lexer.PropertyParsing = false;
1812 if (RootContext.Documentation != null)
1813 current_property.DocComment = ConsumeStoredComment ();
1815 lbag.AppendToMember (current_property, GetLocation ($12));
1816 current_property = null;
1821 accessor_declarations
1822 : get_accessor_declaration
1823 | get_accessor_declaration accessor_declarations
1824 | set_accessor_declaration
1825 | set_accessor_declaration accessor_declarations
1828 if (yyToken == Token.CLOSE_BRACE) {
1829 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1831 if (yyToken == Token.SEMICOLON)
1832 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1834 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1839 get_accessor_declaration
1840 : opt_attributes opt_modifiers GET
1842 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1843 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1846 if (current_property.Get != null) {
1847 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1850 if (current_property is Indexer) {
1851 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1852 (Attributes) $1, GetLocation ($3));
1854 current_property.Get = new Property.GetMethod (current_property,
1855 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1858 current_local_parameters = current_property.Get.ParameterInfo;
1859 lbag.AddMember (current_property.Get, mod_locations);
1860 lexer.PropertyParsing = false;
1865 current_property.Get.Block = (ToplevelBlock) $5;
1867 if (current_container.Kind == MemberKind.Interface) {
1868 Report.Error (531, current_property.Get.Block.StartLocation,
1869 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1873 current_local_parameters = null;
1874 lexer.PropertyParsing = true;
1876 if (RootContext.Documentation != null)
1877 if (Lexer.doc_state == XmlCommentState.Error)
1878 Lexer.doc_state = XmlCommentState.NotAllowed;
1882 set_accessor_declaration
1883 : opt_attributes opt_modifiers SET
1885 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1886 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1889 if (current_property.Set != null) {
1890 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1893 if (current_property is Indexer) {
1894 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1895 ParametersCompiled.MergeGenerated (compiler,
1896 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1897 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1899 (Attributes) $1, GetLocation ($3));
1901 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1902 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1903 (Attributes) $1, GetLocation ($3));
1906 current_local_parameters = current_property.Set.ParameterInfo;
1907 lbag.AddMember (current_property.Set, mod_locations);
1908 lexer.PropertyParsing = false;
1913 current_property.Set.Block = (ToplevelBlock) $5;
1915 if (current_container.Kind == MemberKind.Interface) {
1916 Report.Error (531, current_property.Set.Block.StartLocation,
1917 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1921 current_local_parameters = null;
1922 lexer.PropertyParsing = true;
1924 if (RootContext.Documentation != null
1925 && Lexer.doc_state == XmlCommentState.Error)
1926 Lexer.doc_state = XmlCommentState.NotAllowed;
1939 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1944 interface_declaration
1950 lexer.ConstraintsParsing = true;
1952 type_declaration_name
1954 MemberName name = MakeName ((MemberName) $6);
1955 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1956 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1959 opt_type_parameter_constraints_clauses
1961 lexer.ConstraintsParsing = false;
1963 current_class.SetParameterInfo ((List<Constraints>) $9);
1965 if (RootContext.Documentation != null) {
1966 current_container.DocComment = Lexer.consume_doc_comment ();
1967 Lexer.doc_state = XmlCommentState.Allowed;
1970 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1972 --lexer.parsing_declaration;
1973 if (RootContext.Documentation != null)
1974 Lexer.doc_state = XmlCommentState.Allowed;
1978 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1979 $$ = pop_current_class ();
1981 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1982 CheckIdentifierToken (yyToken, GetLocation ($5));
1986 opt_interface_member_declarations
1988 | interface_member_declarations
1991 interface_member_declarations
1992 : interface_member_declaration
1993 | interface_member_declarations interface_member_declaration
1996 interface_member_declaration
1997 : constant_declaration
1999 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2003 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2005 | method_declaration
2006 | property_declaration
2008 | indexer_declaration
2009 | operator_declaration
2011 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2013 | constructor_declaration
2015 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2019 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2023 operator_declaration
2024 : opt_attributes opt_modifiers operator_declarator
2032 OperatorDeclaration decl = (OperatorDeclaration) $3;
2033 Operator op = new Operator (
2034 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
2035 current_local_parameters,
2036 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2038 if (RootContext.Documentation != null) {
2039 op.DocComment = tmpComment;
2040 Lexer.doc_state = XmlCommentState.Allowed;
2043 // Note again, checking is done in semantic analysis
2044 current_container.AddOperator (op);
2046 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2047 current_local_parameters = null;
2053 | SEMICOLON { $$ = null; }
2057 : type_expression_or_array
2060 Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2061 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2066 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2068 valid_param_mod = ParameterModifierType.DefaultValue;
2070 opt_formal_parameter_list CLOSE_PARENS
2072 valid_param_mod = 0;
2074 Location loc = GetLocation ($2);
2075 Operator.OpType op = (Operator.OpType) $3;
2076 current_local_parameters = (ParametersCompiled)$6;
2078 int p_count = current_local_parameters.Count;
2080 if (op == Operator.OpType.Addition)
2081 op = Operator.OpType.UnaryPlus;
2082 else if (op == Operator.OpType.Subtraction)
2083 op = Operator.OpType.UnaryNegation;
2086 if (IsUnaryOperator (op)) {
2088 Report.Error (1020, loc, "Overloadable binary operator expected");
2089 } else if (p_count != 1) {
2090 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2091 Operator.GetName (op));
2095 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2096 Operator.GetName (op));
2097 } else if (p_count != 2) {
2098 Report.Error (1019, loc, "Overloadable unary operator expected");
2102 if (RootContext.Documentation != null) {
2103 tmpComment = Lexer.consume_doc_comment ();
2104 Lexer.doc_state = XmlCommentState.NotAllowed;
2107 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2108 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2110 | conversion_operator_declarator
2113 overloadable_operator
2115 : BANG { $$ = Operator.OpType.LogicalNot; }
2116 | TILDE { $$ = Operator.OpType.OnesComplement; }
2117 | OP_INC { $$ = Operator.OpType.Increment; }
2118 | OP_DEC { $$ = Operator.OpType.Decrement; }
2119 | TRUE { $$ = Operator.OpType.True; }
2120 | FALSE { $$ = Operator.OpType.False; }
2121 // Unary and binary:
2122 | PLUS { $$ = Operator.OpType.Addition; }
2123 | MINUS { $$ = Operator.OpType.Subtraction; }
2125 | STAR { $$ = Operator.OpType.Multiply; }
2126 | DIV { $$ = Operator.OpType.Division; }
2127 | PERCENT { $$ = Operator.OpType.Modulus; }
2128 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2129 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2130 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2131 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2132 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2133 | OP_EQ { $$ = Operator.OpType.Equality; }
2134 | OP_NE { $$ = Operator.OpType.Inequality; }
2135 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2136 | OP_LT { $$ = Operator.OpType.LessThan; }
2137 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2138 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2141 conversion_operator_declarator
2142 : IMPLICIT OPERATOR type OPEN_PARENS
2144 valid_param_mod = ParameterModifierType.DefaultValue;
2146 opt_formal_parameter_list CLOSE_PARENS
2148 valid_param_mod = 0;
2150 Location loc = GetLocation ($2);
2151 current_local_parameters = (ParametersCompiled)$6;
2153 if (RootContext.Documentation != null) {
2154 tmpComment = Lexer.consume_doc_comment ();
2155 Lexer.doc_state = XmlCommentState.NotAllowed;
2158 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2159 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2161 | EXPLICIT OPERATOR type OPEN_PARENS
2163 valid_param_mod = ParameterModifierType.DefaultValue;
2165 opt_formal_parameter_list CLOSE_PARENS
2167 valid_param_mod = 0;
2169 Location loc = GetLocation ($2);
2170 current_local_parameters = (ParametersCompiled)$6;
2172 if (RootContext.Documentation != null) {
2173 tmpComment = Lexer.consume_doc_comment ();
2174 Lexer.doc_state = XmlCommentState.NotAllowed;
2177 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2178 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2182 Error_SyntaxError (yyToken);
2183 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2184 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2188 Error_SyntaxError (yyToken);
2189 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2190 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2194 constructor_declaration
2195 : constructor_declarator
2198 Constructor c = (Constructor) $1;
2199 c.Block = (ToplevelBlock) $2;
2201 if (RootContext.Documentation != null)
2202 c.DocComment = ConsumeStoredComment ();
2204 current_container.AddConstructor (c);
2206 current_local_parameters = null;
2207 if (RootContext.Documentation != null)
2208 Lexer.doc_state = XmlCommentState.Allowed;
2212 constructor_declarator
2217 if (RootContext.Documentation != null) {
2218 tmpComment = Lexer.consume_doc_comment ();
2219 Lexer.doc_state = XmlCommentState.Allowed;
2222 valid_param_mod = ParameterModifierType.All;
2224 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2226 valid_param_mod = 0;
2227 current_local_parameters = (ParametersCompiled) $6;
2230 // start block here, so possible anonymous methods inside
2231 // constructor initializer can get correct parent block
2233 start_block (lexer.Location);
2235 opt_constructor_initializer
2237 var lt = (Tokenizer.LocatedToken) $3;
2238 var mods = (Modifiers) $2;
2239 ConstructorInitializer ci = (ConstructorInitializer) $9;
2241 Constructor c = new Constructor (current_class, lt.Value, mods,
2242 (Attributes) $1, current_local_parameters, ci, lt.Location);
2244 if (lt.Value != current_container.MemberName.Name) {
2245 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2246 } else if ((mods & Modifiers.STATIC) != 0) {
2247 if ((mods & Modifiers.AccessibilityMask) != 0){
2248 Report.Error (515, c.Location,
2249 "`{0}': static constructor cannot have an access modifier",
2250 c.GetSignatureForError ());
2253 Report.Error (514, c.Location,
2254 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2255 c.GetSignatureForError ());
2260 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2267 | SEMICOLON { current_block = null; $$ = null; }
2270 opt_constructor_initializer
2272 | constructor_initializer
2275 constructor_initializer
2276 : COLON BASE OPEN_PARENS
2278 ++lexer.parsing_block;
2280 opt_argument_list CLOSE_PARENS
2282 --lexer.parsing_block;
2283 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2284 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2286 | COLON THIS OPEN_PARENS
2288 ++lexer.parsing_block;
2290 opt_argument_list CLOSE_PARENS
2292 --lexer.parsing_block;
2293 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2294 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2297 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2302 destructor_declaration
2303 : opt_attributes opt_modifiers TILDE
2305 if (RootContext.Documentation != null) {
2306 tmpComment = Lexer.consume_doc_comment ();
2307 Lexer.doc_state = XmlCommentState.NotAllowed;
2310 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2312 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2314 var lt = (Tokenizer.LocatedToken) $5;
2315 if (lt.Value != current_container.MemberName.Name){
2316 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2317 } else if (current_container.Kind != MemberKind.Class){
2318 Report.Error (575, lt.Location, "Only class types can contain destructor");
2321 Destructor d = new Destructor (current_class, (Modifiers) $2,
2322 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2323 if (RootContext.Documentation != null)
2324 d.DocComment = ConsumeStoredComment ();
2326 d.Block = (ToplevelBlock) $8;
2327 current_container.AddMethod (d);
2328 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2330 current_local_parameters = null;
2337 EVENT type member_declaration_name
2339 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2340 current_container.AddEvent (current_event_field);
2342 if (current_event_field.MemberName.Left != null) {
2343 Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2344 current_event_field.GetSignatureForError ());
2347 $$ = current_event_field;
2349 opt_event_initializer
2350 opt_event_declarators
2353 if (RootContext.Documentation != null) {
2354 current_event_field.DocComment = Lexer.consume_doc_comment ();
2355 Lexer.doc_state = XmlCommentState.Allowed;
2358 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2359 current_event_field = null;
2363 EVENT type member_declaration_name
2366 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2367 current_container.AddEvent (current_event);
2368 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2370 lexer.EventParsing = true;
2372 event_accessor_declarations
2374 if (current_container.Kind == MemberKind.Interface)
2375 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2377 lexer.EventParsing = false;
2381 if (RootContext.Documentation != null) {
2382 current_event.DocComment = Lexer.consume_doc_comment ();
2383 Lexer.doc_state = XmlCommentState.Allowed;
2386 lbag.AppendToMember (current_event, GetLocation ($9));
2387 current_event = null;
2388 current_local_parameters = null;
2392 opt_event_initializer
2396 ++lexer.parsing_block;
2398 event_variable_initializer
2400 --lexer.parsing_block;
2401 current_event_field.Initializer = (Expression) $3;
2405 opt_event_declarators
2413 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2415 | event_declarators event_declarator
2417 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2424 var lt = (Tokenizer.LocatedToken) $2;
2425 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2426 lbag.AddLocation ($$, GetLocation ($1));
2428 | COMMA IDENTIFIER ASSIGN
2430 ++lexer.parsing_block;
2432 event_variable_initializer
2434 --lexer.parsing_block;
2435 var lt = (Tokenizer.LocatedToken) $2;
2436 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2437 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2441 event_variable_initializer
2443 if (current_container.Kind == MemberKind.Interface) {
2444 Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2445 current_event_field.GetSignatureForError ());
2448 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2449 Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2450 current_event_field.GetSignatureForError ());
2453 variable_initializer
2459 event_accessor_declarations
2460 : add_accessor_declaration remove_accessor_declaration
2461 | remove_accessor_declaration add_accessor_declaration
2462 | add_accessor_declaration
2464 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2465 current_event.GetSignatureForError ());
2467 | remove_accessor_declaration
2469 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2470 current_event.GetSignatureForError ());
2474 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2479 add_accessor_declaration
2480 : opt_attributes opt_modifiers ADD
2482 if ($2 != ModifierNone) {
2483 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2486 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2487 current_local_parameters = current_event.Add.ParameterInfo;
2489 lbag.AddMember (current_event.Add, mod_locations);
2490 lexer.EventParsing = false;
2492 event_accessor_block
2494 lexer.EventParsing = true;
2496 current_event.Add.Block = (ToplevelBlock) $5;
2498 if (current_container.Kind == MemberKind.Interface) {
2499 Report.Error (531, current_event.Add.Block.StartLocation,
2500 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2503 current_local_parameters = null;
2507 remove_accessor_declaration
2508 : opt_attributes opt_modifiers REMOVE
2510 if ($2 != ModifierNone) {
2511 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2514 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2515 current_local_parameters = current_event.Remove.ParameterInfo;
2517 lbag.AddMember (current_event.Remove, mod_locations);
2518 lexer.EventParsing = false;
2520 event_accessor_block
2522 lexer.EventParsing = true;
2524 current_event.Remove.Block = (ToplevelBlock) $5;
2526 if (current_container.Kind == MemberKind.Interface) {
2527 Report.Error (531, current_event.Remove.Block.StartLocation,
2528 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2531 current_local_parameters = null;
2535 event_accessor_block
2538 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2547 ENUM type_declaration_name
2550 if (RootContext.Documentation != null)
2551 enumTypeComment = Lexer.consume_doc_comment ();
2555 if (RootContext.Documentation != null)
2556 Lexer.doc_state = XmlCommentState.Allowed;
2558 MemberName name = (MemberName) $4;
2559 if (name.IsGeneric) {
2560 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2563 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2565 opt_enum_member_declarations
2567 // here will be evaluated after CLOSE_BLACE is consumed.
2568 if (RootContext.Documentation != null)
2569 Lexer.doc_state = XmlCommentState.Allowed;
2571 CLOSE_BRACE opt_semicolon
2573 if (RootContext.Documentation != null)
2574 current_class.DocComment = enumTypeComment;
2576 --lexer.parsing_declaration;
2578 // if (RootContext.Documentation != null)
2579 // em.DocComment = ev.DocComment;
2581 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2582 $$ = pop_current_class ();
2590 var te = $2 as TypeExpression;
2592 (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
2593 te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
2594 te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
2595 te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
2596 Enum.Error_1008 (GetLocation ($2), Report);
2604 Error_TypeExpected (GetLocation ($1));
2609 opt_enum_member_declarations
2611 | enum_member_declarations
2612 | enum_member_declarations COMMA
2614 lbag.AddLocation ($1, GetLocation ($2));
2618 enum_member_declarations
2619 : enum_member_declaration
2620 | enum_member_declarations COMMA enum_member_declaration
2622 lbag.AddLocation ($1, GetLocation ($2));
2627 enum_member_declaration
2628 : opt_attributes IDENTIFIER
2630 var lt = (Tokenizer.LocatedToken) $2;
2631 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2632 ((Enum) current_class).AddEnumMember (em);
2634 if (RootContext.Documentation != null) {
2635 em.DocComment = Lexer.consume_doc_comment ();
2636 Lexer.doc_state = XmlCommentState.Allowed;
2641 | opt_attributes IDENTIFIER
2643 ++lexer.parsing_block;
2644 if (RootContext.Documentation != null) {
2645 tmpComment = Lexer.consume_doc_comment ();
2646 Lexer.doc_state = XmlCommentState.NotAllowed;
2649 ASSIGN constant_expression
2651 --lexer.parsing_block;
2653 var lt = (Tokenizer.LocatedToken) $2;
2654 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2655 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2656 ((Enum) current_class).AddEnumMember (em);
2658 if (RootContext.Documentation != null)
2659 em.DocComment = ConsumeStoredComment ();
2665 delegate_declaration
2669 member_type type_declaration_name
2672 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2674 opt_formal_parameter_list CLOSE_PARENS
2676 valid_param_mod = 0;
2678 MemberName name = MakeName ((MemberName) $5);
2679 ParametersCompiled p = (ParametersCompiled) $8;
2681 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2682 (Modifiers) $2, name, p, (Attributes) $1);
2684 if (RootContext.Documentation != null) {
2685 del.DocComment = Lexer.consume_doc_comment ();
2686 Lexer.doc_state = XmlCommentState.Allowed;
2689 current_container.AddDelegate (del);
2690 current_delegate = del;
2691 lexer.ConstraintsParsing = true;
2693 opt_type_parameter_constraints_clauses
2695 lexer.ConstraintsParsing = false;
2699 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2700 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2702 $$ = current_delegate;
2704 current_delegate = null;
2715 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2716 Report.FeatureIsNotSupported (GetLocation ($1), "nullable types");
2717 else if (RootContext.Version < LanguageVersion.ISO_2)
2718 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2720 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2724 namespace_or_type_name
2726 | qualified_alias_member IDENTIFIER opt_type_argument_list
2728 var lt1 = (Tokenizer.LocatedToken) $1;
2729 var lt2 = (Tokenizer.LocatedToken) $2;
2731 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2737 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2739 var lt = (Tokenizer.LocatedToken) $3;
2740 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2741 lbag.AddLocation ($$, GetLocation ($2));
2746 : IDENTIFIER opt_type_argument_list
2748 var lt = (Tokenizer.LocatedToken) $1;
2749 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2754 // Generics arguments (any type, without attributes)
2756 opt_type_argument_list
2757 : /* empty */ { $$ = null; }
2758 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2760 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2761 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2762 else if (RootContext.Version < LanguageVersion.ISO_2)
2763 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2767 | OP_GENERICS_LT error
2769 Error_TypeExpected (lexer.Location);
2770 $$ = new TypeArguments ();
2777 TypeArguments type_args = new TypeArguments ();
2778 type_args.Add ((FullNamedExpression) $1);
2781 | type_arguments COMMA type
2783 TypeArguments type_args = (TypeArguments) $1;
2784 type_args.Add ((FullNamedExpression) $3);
2790 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2792 type_declaration_name
2795 lexer.parsing_generic_declaration = true;
2797 opt_type_parameter_list
2799 lexer.parsing_generic_declaration = false;
2800 var lt = (Tokenizer.LocatedToken) $1;
2801 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2805 member_declaration_name
2806 : method_declaration_name
2808 MemberName mn = (MemberName)$1;
2809 if (mn.TypeArguments != null)
2810 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2811 mn.GetSignatureForError ()));
2815 method_declaration_name
2816 : type_declaration_name
2817 | explicit_interface IDENTIFIER opt_type_parameter_list
2819 lexer.parsing_generic_declaration = false;
2820 var lt = (Tokenizer.LocatedToken) $2;
2821 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2825 indexer_declaration_name
2828 lexer.parsing_generic_declaration = false;
2829 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2831 | explicit_interface THIS
2833 lexer.parsing_generic_declaration = false;
2834 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2839 : IDENTIFIER opt_type_argument_list DOT
2841 var lt = (Tokenizer.LocatedToken) $1;
2842 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2843 lbag.AddLocation ($$, GetLocation ($3));
2845 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2847 var lt1 = (Tokenizer.LocatedToken) $1;
2848 var lt2 = (Tokenizer.LocatedToken) $2;
2850 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2851 lbag.AddLocation ($$, GetLocation ($4));
2853 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2855 var lt = (Tokenizer.LocatedToken) $2;
2856 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2857 lbag.AddLocation ($$, GetLocation ($4));
2861 opt_type_parameter_list
2862 : /* empty */ { $$ = null; }
2863 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2865 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2866 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2867 else if (RootContext.Version < LanguageVersion.ISO_2)
2868 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2871 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2878 TypeArguments type_args = new TypeArguments ();
2879 type_args.Add ((FullNamedExpression)$1);
2882 | type_parameters COMMA type_parameter
2884 TypeArguments type_args = (TypeArguments) $1;
2885 type_args.Add ((FullNamedExpression)$3);
2887 lbag.AddLocation ($3, GetLocation ($3));
2892 : opt_attributes opt_type_parameter_variance IDENTIFIER
2894 var lt = (Tokenizer.LocatedToken)$3;
2895 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2899 if (GetTokenName (yyToken) == "type")
2900 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2902 Error_SyntaxError (yyToken);
2904 $$ = new TypeParameterName ("", null, lexer.Location);
2909 // All types where void is allowed
2912 : type_expression_or_array
2915 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2922 lexer.parsing_generic_declaration = true;
2927 // A type which does not allow `void' to be used
2930 : type_expression_or_array
2933 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2934 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2942 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2943 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2948 : type_expression_or_array
2951 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2952 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2956 type_expression_or_array
2958 | type_expression rank_specifiers
2960 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2965 : namespace_or_type_name opt_nullable
2967 MemberName name = (MemberName) $1;
2970 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2972 if (name.Left == null && name.Name == "var")
2973 $$ = new VarExpr (name.Location);
2975 $$ = name.GetTypeExpression ();
2978 | builtin_types opt_nullable
2981 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2983 | type_expression STAR
2986 // Note that here only unmanaged types are allowed but we
2987 // can't perform checks during this phase - we do it during
2988 // semantic analysis.
2990 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
2994 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
3001 var types = new List<FullNamedExpression> (2);
3002 types.Add ((FullNamedExpression) $1);
3005 | type_list COMMA base_type_name
3007 var types = (List<FullNamedExpression>) $1;
3008 types.Add ((FullNamedExpression) $3);
3016 if ($1 is ComposedCast) {
3017 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3023 Error_TypeExpected (lexer.Location);
3029 * replaces all the productions for isolating the various
3030 * simple types, but we need this to reuse it easily in variable_type
3033 : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
3034 | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
3035 | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
3036 | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
3037 | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
3038 | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
3043 : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
3044 | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
3045 | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
3046 | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
3047 | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
3048 | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
3049 | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
3050 | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
3051 | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
3055 // Expressions, section 7.5
3060 : primary_expression_no_array_creation
3061 | array_creation_expression
3064 primary_expression_no_array_creation
3066 | IDENTIFIER opt_type_argument_list
3068 var lt = (Tokenizer.LocatedToken) $1;
3069 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3071 | IDENTIFIER GENERATE_COMPLETION {
3072 var lt = (Tokenizer.LocatedToken) $1;
3073 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3075 | parenthesized_expression
3076 | default_value_expression
3078 | invocation_expression
3082 | post_increment_expression
3083 | post_decrement_expression
3084 | object_or_delegate_creation_expression
3085 | anonymous_type_expression
3088 | checked_expression
3089 | unchecked_expression
3090 | pointer_member_access
3091 | anonymous_method_expression
3097 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3101 : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
3102 | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
3107 // Here is the trick, tokenizer may think that parens is a special but
3108 // parser is interested in open parens only, so we merge them.
3109 // Consider: if (a)foo ();
3117 // Use this production to accept closing parenthesis or
3118 // performing completion
3122 | COMPLETE_COMPLETION
3126 parenthesized_expression
3127 : OPEN_PARENS expression CLOSE_PARENS
3129 $$ = new ParenthesizedExpression ((Expression) $2);
3130 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3132 | OPEN_PARENS expression COMPLETE_COMPLETION
3134 $$ = new ParenthesizedExpression ((Expression) $2);
3139 : primary_expression DOT IDENTIFIER opt_type_argument_list
3141 var lt = (Tokenizer.LocatedToken) $3;
3142 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3143 lbag.AddLocation ($$, GetLocation ($2));
3145 | builtin_types DOT IDENTIFIER opt_type_argument_list
3147 var lt = (Tokenizer.LocatedToken) $3;
3148 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3149 lbag.AddLocation ($$, GetLocation ($2));
3151 | BASE DOT IDENTIFIER opt_type_argument_list
3153 var lt = (Tokenizer.LocatedToken) $3;
3154 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3155 lbag.AddLocation ($$, GetLocation ($2));
3157 | qualified_alias_member IDENTIFIER opt_type_argument_list
3159 var lt1 = (Tokenizer.LocatedToken) $1;
3160 var lt2 = (Tokenizer.LocatedToken) $2;
3162 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3164 | primary_expression DOT GENERATE_COMPLETION {
3165 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3167 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3168 var lt = (Tokenizer.LocatedToken) $3;
3169 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3171 | builtin_types DOT GENERATE_COMPLETION
3173 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3175 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3176 var lt = (Tokenizer.LocatedToken) $3;
3177 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3181 invocation_expression
3182 : primary_expression open_parens_any opt_argument_list close_parens
3184 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3185 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3189 opt_object_or_collection_initializer
3190 : /* empty */ { $$ = null; }
3191 | object_or_collection_initializer
3194 object_or_collection_initializer
3195 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3198 $$ = CollectionOrObjectInitializers.Empty;
3201 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3202 lbag.AddLocation ($$, GetLocation ($3));
3205 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3207 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3208 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3212 opt_member_initializer_list
3213 : /* empty */ { $$ = null; }
3214 | member_initializer_list
3220 member_initializer_list
3221 : member_initializer
3223 var a = new List<Expression> ();
3224 a.Add ((Expression) $1);
3227 | member_initializer_list COMMA member_initializer
3229 var a = (List<Expression>)$1;
3230 a.Add ((Expression) $3);
3233 | member_initializer_list error {
3234 Error_SyntaxError (yyToken);
3240 : IDENTIFIER ASSIGN initializer_value
3242 var lt = (Tokenizer.LocatedToken) $1;
3243 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3244 lbag.AddLocation ($$, GetLocation ($2));
3246 | GENERATE_COMPLETION
3248 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3250 | non_assignment_expression opt_COMPLETE_COMPLETION {
3251 CompletionSimpleName csn = $1 as CompletionSimpleName;
3253 $$ = new CollectionElementInitializer ((Expression)$1);
3255 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3257 | OPEN_BRACE expression_list CLOSE_BRACE
3262 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3264 | OPEN_BRACE CLOSE_BRACE
3266 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3273 | object_or_collection_initializer
3277 : /* empty */ { $$ = null; }
3282 : argument_or_named_argument
3284 Arguments list = new Arguments (4);
3285 list.Add ((Argument) $1);
3288 | argument_list COMMA argument
3290 Arguments list = (Arguments) $1;
3291 if (list [list.Count - 1] is NamedArgument)
3292 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3294 list.Add ((Argument) $3);
3297 | argument_list COMMA named_argument
3299 Arguments list = (Arguments) $1;
3300 NamedArgument a = (NamedArgument) $3;
3301 for (int i = 0; i < list.Count; ++i) {
3302 NamedArgument na = list [i] as NamedArgument;
3303 if (na != null && na.Name == a.Name)
3304 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3311 | argument_list COMMA
3313 Report.Error (839, GetLocation ($2), "An argument is missing");
3318 Report.Error (839, GetLocation ($1), "An argument is missing");
3326 $$ = new Argument ((Expression) $1);
3328 | non_simple_argument
3331 argument_or_named_argument
3337 : REF variable_reference
3339 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3340 lbag.AddLocation ($$, GetLocation ($1));
3342 | OUT variable_reference
3344 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3345 lbag.AddLocation ($$, GetLocation ($1));
3347 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3349 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3350 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3352 | ARGLIST OPEN_PARENS CLOSE_PARENS
3354 $$ = new Argument (new Arglist (GetLocation ($1)));
3355 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3359 $$ = new Argument (new ArglistAccess (GetLocation ($1)));
3368 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3370 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3371 lbag.AddLocation ($$, GetLocation ($4));
3378 var list = new List<Expression> (4);
3379 list.Add ((Expression) $1);
3382 | expression_list COMMA expression
3384 var list = (List<Expression>) $1;
3385 list.Add ((Expression) $3);
3388 | expression_list error {
3389 Error_SyntaxError (yyToken);
3394 expression_list_arguments
3395 : expression_list_argument
3397 Arguments args = new Arguments (4);
3398 args.Add ((Argument) $1);
3401 | expression_list_arguments COMMA expression_list_argument
3403 Arguments args = (Arguments) $1;
3404 args.Add ((Argument) $3);
3409 expression_list_argument
3412 $$ = new Argument ((Expression) $1);
3420 $$ = new This (GetLocation ($1));
3425 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3427 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3428 lbag.AddLocation ($$, GetLocation ($4));
3430 | BASE OPEN_BRACKET error
3432 Error_SyntaxError (yyToken);
3433 $$ = new ElementAccess (null, null, GetLocation ($2));
3437 post_increment_expression
3438 : primary_expression OP_INC
3440 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3444 post_decrement_expression
3445 : primary_expression OP_DEC
3447 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3451 object_or_delegate_creation_expression
3452 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3455 if (RootContext.Version <= LanguageVersion.ISO_2)
3456 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3458 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3460 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3463 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3465 | NEW new_expr_type object_or_collection_initializer
3467 if (RootContext.Version <= LanguageVersion.ISO_2)
3468 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3470 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3474 array_creation_expression
3475 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3477 opt_array_initializer
3479 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3480 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3481 Next = (ComposedTypeSpecifier) $6
3482 }, (ArrayInitializer) $7, GetLocation ($1));
3483 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3485 | NEW new_expr_type rank_specifiers opt_array_initializer
3488 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3490 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3492 | NEW rank_specifiers array_initializer
3494 if (RootContext.Version <= LanguageVersion.ISO_2)
3495 Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3497 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3499 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3501 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3502 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3504 | NEW new_expr_type error
3506 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3507 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3513 ++lexer.parsing_type;
3517 --lexer.parsing_type;
3522 anonymous_type_expression
3523 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3525 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3526 Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types");
3527 else if (RootContext.Version <= LanguageVersion.ISO_2)
3528 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3530 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3532 // TODO: lbag comma location
3533 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3537 anonymous_type_parameters_opt_comma
3538 : anonymous_type_parameters_opt
3539 | anonymous_type_parameters COMMA
3542 anonymous_type_parameters_opt
3544 | anonymous_type_parameters
3547 anonymous_type_parameters
3548 : anonymous_type_parameter
3550 var a = new List<AnonymousTypeParameter> (4);
3551 a.Add ((AnonymousTypeParameter) $1);
3554 | anonymous_type_parameters COMMA anonymous_type_parameter
3556 var a = (List<AnonymousTypeParameter>) $1;
3557 a.Add ((AnonymousTypeParameter) $3);
3562 anonymous_type_parameter
3563 : IDENTIFIER ASSIGN variable_initializer
3565 var lt = (Tokenizer.LocatedToken)$1;
3566 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3567 lbag.AddLocation ($$, GetLocation ($2));
3571 var lt = (Tokenizer.LocatedToken)$1;
3572 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3573 lt.Value, lt.Location);
3577 MemberAccess ma = (MemberAccess) $1;
3578 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3582 Report.Error (746, lexer.Location,
3583 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3596 opt_rank_specifier_or_nullable
3598 | opt_nullable rank_specifiers
3601 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3611 | rank_specifier rank_specifiers
3613 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3619 : OPEN_BRACKET CLOSE_BRACKET
3621 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3623 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3625 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3634 | dim_separators COMMA
3636 $$ = ((int) $1) + 1;
3640 opt_array_initializer
3652 : OPEN_BRACE CLOSE_BRACE
3654 $$ = new ArrayInitializer (0, GetLocation ($1));
3655 lbag.AddLocation ($$, GetLocation ($2));
3657 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3659 $$ = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3660 lbag.AddLocation ($$, GetLocation ($3));
3664 variable_initializer_list
3665 : variable_initializer
3667 var list = new List<Expression> (4);
3668 list.Add ((Expression) $1);
3671 | variable_initializer_list COMMA variable_initializer
3673 var list = (List<Expression>) $1;
3674 list.Add ((Expression) $3);
3679 Error_SyntaxError (yyToken);
3680 $$ = new List<Expression> ();
3687 lexer.TypeOfParsing = true;
3689 open_parens_any typeof_type_expression CLOSE_PARENS
3691 lexer.TypeOfParsing = false;
3692 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3693 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3697 typeof_type_expression
3702 Error_TypeExpected (lexer.Location);
3708 : IDENTIFIER generic_dimension
3710 var lt = (Tokenizer.LocatedToken) $1;
3712 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3714 | qualified_alias_member IDENTIFIER generic_dimension
3716 var lt1 = (Tokenizer.LocatedToken) $1;
3717 var lt2 = (Tokenizer.LocatedToken) $2;
3719 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3721 | unbound_type_name DOT IDENTIFIER
3723 var lt = (Tokenizer.LocatedToken) $3;
3725 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3727 | unbound_type_name DOT IDENTIFIER generic_dimension
3729 var lt = (Tokenizer.LocatedToken) $3;
3731 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3733 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3735 var lt = (Tokenizer.LocatedToken) $3;
3736 MemberName name = (MemberName) $1;
3738 $$ = new MemberAccess (name.GetTypeExpression (), lt.Value, (int) $4, lt.Location);
3745 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3746 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
3747 else if (RootContext.Version < LanguageVersion.ISO_2)
3748 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
3754 qualified_alias_member
3755 : IDENTIFIER DOUBLE_COLON
3757 var lt = (Tokenizer.LocatedToken) $1;
3758 if (RootContext.Version == LanguageVersion.ISO_1)
3759 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3766 : SIZEOF open_parens_any type CLOSE_PARENS
3768 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3769 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3774 : CHECKED open_parens_any expression CLOSE_PARENS
3776 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3777 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3781 unchecked_expression
3782 : UNCHECKED open_parens_any expression CLOSE_PARENS
3784 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3785 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3789 pointer_member_access
3790 : primary_expression OP_PTR IDENTIFIER
3792 var lt = (Tokenizer.LocatedToken) $3;
3793 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3797 anonymous_method_expression
3798 : DELEGATE opt_anonymous_method_signature
3800 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3804 $$ = end_anonymous ((ToplevelBlock) $4);
3808 opt_anonymous_method_signature
3811 $$ = ParametersCompiled.Undefined;
3813 | anonymous_method_signature
3816 anonymous_method_signature
3819 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3821 opt_formal_parameter_list CLOSE_PARENS
3823 valid_param_mod = 0;
3828 default_value_expression
3829 : DEFAULT open_parens_any type CLOSE_PARENS
3831 if (RootContext.Version < LanguageVersion.ISO_2)
3832 Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3834 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3835 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3840 : primary_expression
3841 | BANG prefixed_unary_expression
3843 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3845 | TILDE prefixed_unary_expression
3847 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3853 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3855 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3856 lbag.AddLocation ($$, GetLocation ($3));
3858 | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
3860 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3861 lbag.AddLocation ($$, GetLocation ($3));
3866 // The idea to split this out is from Rhys' grammar
3867 // to solve the problem with casts.
3869 prefixed_unary_expression
3871 | PLUS prefixed_unary_expression
3873 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3875 | MINUS prefixed_unary_expression
3877 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3879 | OP_INC prefixed_unary_expression
3881 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3883 | OP_DEC prefixed_unary_expression
3885 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3887 | STAR prefixed_unary_expression
3889 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3891 | BITWISE_AND prefixed_unary_expression
3893 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3897 multiplicative_expression
3898 : prefixed_unary_expression
3899 | multiplicative_expression STAR prefixed_unary_expression
3901 $$ = new Binary (Binary.Operator.Multiply,
3902 (Expression) $1, (Expression) $3, GetLocation ($2));
3904 | multiplicative_expression DIV prefixed_unary_expression
3906 $$ = new Binary (Binary.Operator.Division,
3907 (Expression) $1, (Expression) $3, GetLocation ($2));
3909 | multiplicative_expression PERCENT prefixed_unary_expression
3911 $$ = new Binary (Binary.Operator.Modulus,
3912 (Expression) $1, (Expression) $3, GetLocation ($2));
3917 : multiplicative_expression
3918 | additive_expression PLUS multiplicative_expression
3920 $$ = new Binary (Binary.Operator.Addition,
3921 (Expression) $1, (Expression) $3, GetLocation ($2));
3923 | additive_expression MINUS multiplicative_expression
3925 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3927 | parenthesized_expression MINUS multiplicative_expression
3929 // Shift/Reduce conflict
3930 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3932 | additive_expression AS type
3934 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3936 | additive_expression IS type
3938 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3943 : additive_expression
3944 | shift_expression OP_SHIFT_LEFT additive_expression
3946 $$ = new Binary (Binary.Operator.LeftShift,
3947 (Expression) $1, (Expression) $3, GetLocation ($2));
3949 | shift_expression OP_SHIFT_RIGHT additive_expression
3951 $$ = new Binary (Binary.Operator.RightShift,
3952 (Expression) $1, (Expression) $3, GetLocation ($2));
3956 relational_expression
3958 | relational_expression OP_LT shift_expression
3960 $$ = new Binary (Binary.Operator.LessThan,
3961 (Expression) $1, (Expression) $3, GetLocation ($2));
3963 | relational_expression OP_GT shift_expression
3965 $$ = new Binary (Binary.Operator.GreaterThan,
3966 (Expression) $1, (Expression) $3, GetLocation ($2));
3968 | relational_expression OP_LE shift_expression
3970 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3971 (Expression) $1, (Expression) $3, GetLocation ($2));
3973 | relational_expression OP_GE shift_expression
3975 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3976 (Expression) $1, (Expression) $3, GetLocation ($2));
3981 : relational_expression
3982 | equality_expression OP_EQ relational_expression
3984 $$ = new Binary (Binary.Operator.Equality,
3985 (Expression) $1, (Expression) $3, GetLocation ($2));
3987 | equality_expression OP_NE relational_expression
3989 $$ = new Binary (Binary.Operator.Inequality,
3990 (Expression) $1, (Expression) $3, GetLocation ($2));
3995 : equality_expression
3996 | and_expression BITWISE_AND equality_expression
3998 $$ = new Binary (Binary.Operator.BitwiseAnd,
3999 (Expression) $1, (Expression) $3, GetLocation ($2));
4003 exclusive_or_expression
4005 | exclusive_or_expression CARRET and_expression
4007 $$ = new Binary (Binary.Operator.ExclusiveOr,
4008 (Expression) $1, (Expression) $3, GetLocation ($2));
4012 inclusive_or_expression
4013 : exclusive_or_expression
4014 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4016 $$ = new Binary (Binary.Operator.BitwiseOr,
4017 (Expression) $1, (Expression) $3, GetLocation ($2));
4021 conditional_and_expression
4022 : inclusive_or_expression
4023 | conditional_and_expression OP_AND inclusive_or_expression
4025 $$ = new Binary (Binary.Operator.LogicalAnd,
4026 (Expression) $1, (Expression) $3, GetLocation ($2));
4030 conditional_or_expression
4031 : conditional_and_expression
4032 | conditional_or_expression OP_OR conditional_and_expression
4034 $$ = new Binary (Binary.Operator.LogicalOr,
4035 (Expression) $1, (Expression) $3, GetLocation ($2));
4039 null_coalescing_expression
4040 : conditional_or_expression
4041 | conditional_or_expression OP_COALESCING null_coalescing_expression
4043 if (RootContext.Version < LanguageVersion.ISO_2)
4044 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4046 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
4050 conditional_expression
4051 : null_coalescing_expression
4052 | null_coalescing_expression INTERR expression COLON expression
4054 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4055 lbag.AddLocation ($$, GetLocation ($4));
4059 assignment_expression
4060 : prefixed_unary_expression ASSIGN expression
4062 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
4064 | prefixed_unary_expression OP_MULT_ASSIGN expression
4066 $$ = new CompoundAssign (
4067 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
4069 | prefixed_unary_expression OP_DIV_ASSIGN expression
4071 $$ = new CompoundAssign (
4072 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
4074 | prefixed_unary_expression OP_MOD_ASSIGN expression
4076 $$ = new CompoundAssign (
4077 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4079 | prefixed_unary_expression OP_ADD_ASSIGN expression
4081 $$ = new CompoundAssign (
4082 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4084 | prefixed_unary_expression OP_SUB_ASSIGN expression
4086 $$ = new CompoundAssign (
4087 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4089 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4091 $$ = new CompoundAssign (
4092 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4094 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4096 $$ = new CompoundAssign (
4097 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4099 | prefixed_unary_expression OP_AND_ASSIGN expression
4101 $$ = new CompoundAssign (
4102 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4104 | prefixed_unary_expression OP_OR_ASSIGN expression
4106 $$ = new CompoundAssign (
4107 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4109 | prefixed_unary_expression OP_XOR_ASSIGN expression
4111 $$ = new CompoundAssign (
4112 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4116 lambda_parameter_list
4119 var pars = new List<Parameter> (4);
4120 pars.Add ((Parameter) $1);
4124 | lambda_parameter_list COMMA lambda_parameter
4126 var pars = (List<Parameter>) $1;
4127 Parameter p = (Parameter)$3;
4128 if (pars[0].GetType () != p.GetType ()) {
4129 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4138 : parameter_modifier parameter_type IDENTIFIER
4140 var lt = (Tokenizer.LocatedToken) $3;
4142 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4144 | parameter_type IDENTIFIER
4146 var lt = (Tokenizer.LocatedToken) $2;
4148 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4152 var lt = (Tokenizer.LocatedToken) $1;
4153 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4157 opt_lambda_parameter_list
4158 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4159 | lambda_parameter_list {
4160 var pars_list = (List<Parameter>) $1;
4161 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
4165 lambda_expression_body
4167 start_block (lexer.Location);
4171 Block b = end_block (lexer.Location);
4172 b.AddStatement (new ContextualReturn ((Expression) $2));
4183 var lt = (Tokenizer.LocatedToken) $1;
4184 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4185 start_anonymous (true, new ParametersCompiled (compiler, p), GetLocation ($1));
4187 lambda_expression_body
4189 $$ = end_anonymous ((ToplevelBlock) $4);
4190 lbag.AddLocation ($$, GetLocation ($2));
4192 | OPEN_PARENS_LAMBDA
4194 if (RootContext.Version <= LanguageVersion.ISO_2)
4195 Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4197 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4199 opt_lambda_parameter_list CLOSE_PARENS ARROW
4201 valid_param_mod = 0;
4202 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4204 lambda_expression_body
4206 $$ = end_anonymous ((ToplevelBlock) $7);
4207 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
4212 : assignment_expression
4213 | non_assignment_expression
4216 non_assignment_expression
4217 : conditional_expression
4229 $$ = new BooleanExpression ((Expression) $1);
4242 lexer.ConstraintsParsing = true;
4244 type_declaration_name
4246 MemberName name = MakeName ((MemberName) $6);
4247 push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
4250 opt_type_parameter_constraints_clauses
4252 lexer.ConstraintsParsing = false;
4254 current_class.SetParameterInfo ((List<Constraints>) $9);
4255 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4257 if (RootContext.Documentation != null) {
4258 current_container.DocComment = Lexer.consume_doc_comment ();
4259 Lexer.doc_state = XmlCommentState.Allowed;
4262 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4264 --lexer.parsing_declaration;
4265 if (RootContext.Documentation != null)
4266 Lexer.doc_state = XmlCommentState.Allowed;
4270 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4271 $$ = pop_current_class ();
4279 { $$ = $1; } // location
4285 mod_locations = null;
4293 | modifiers modifier
4295 var m1 = (Modifiers) $1;
4296 var m2 = (Modifiers) $2;
4298 if ((m1 & m2) != 0) {
4299 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4300 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4301 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4302 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4303 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4304 "More than one protection modifier specified");
4315 StoreModifierLocation ($$, GetLocation ($1));
4317 if (current_container == RootContext.ToplevelTypes)
4318 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4322 $$ = Modifiers.PUBLIC;
4323 StoreModifierLocation ($$, GetLocation ($1));
4327 $$ = Modifiers.PROTECTED;
4328 StoreModifierLocation ($$, GetLocation ($1));
4332 $$ = Modifiers.INTERNAL;
4333 StoreModifierLocation ($$, GetLocation ($1));
4337 $$ = Modifiers.PRIVATE;
4338 StoreModifierLocation ($$, GetLocation ($1));
4342 $$ = Modifiers.ABSTRACT;
4343 StoreModifierLocation ($$, GetLocation ($1));
4347 $$ = Modifiers.SEALED;
4348 StoreModifierLocation ($$, GetLocation ($1));
4352 $$ = Modifiers.STATIC;
4353 StoreModifierLocation ($$, GetLocation ($1));
4357 $$ = Modifiers.READONLY;
4358 StoreModifierLocation ($$, GetLocation ($1));
4362 $$ = Modifiers.VIRTUAL;
4363 StoreModifierLocation ($$, GetLocation ($1));
4367 $$ = Modifiers.OVERRIDE;
4368 StoreModifierLocation ($$, GetLocation ($1));
4372 $$ = Modifiers.EXTERN;
4373 StoreModifierLocation ($$, GetLocation ($1));
4377 $$ = Modifiers.VOLATILE;
4378 StoreModifierLocation ($$, GetLocation ($1));
4382 $$ = Modifiers.UNSAFE;
4383 StoreModifierLocation ($$, GetLocation ($1));
4384 if (!RootContext.Unsafe)
4385 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4393 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4397 opt_type_parameter_constraints_clauses
4398 : /* empty */ { $$ = null; }
4399 | type_parameter_constraints_clauses
4405 type_parameter_constraints_clauses
4406 : type_parameter_constraints_clause
4408 var constraints = new List<Constraints> (1);
4409 constraints.Add ((Constraints) $1);
4412 | type_parameter_constraints_clauses type_parameter_constraints_clause
4414 var constraints = (List<Constraints>) $1;
4415 Constraints new_constraint = (Constraints)$2;
4417 foreach (Constraints c in constraints) {
4418 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4419 Report.Error (409, new_constraint.Location,
4420 "A constraint clause has already been specified for type parameter `{0}'",
4421 new_constraint.TypeParameter.Value);
4425 constraints.Add (new_constraint);
4430 type_parameter_constraints_clause
4431 : WHERE IDENTIFIER COLON type_parameter_constraints
4433 var lt = (Tokenizer.LocatedToken) $2;
4434 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4438 type_parameter_constraints
4439 : type_parameter_constraint
4441 var constraints = new List<FullNamedExpression> (1);
4442 constraints.Add ((FullNamedExpression) $1);
4445 | type_parameter_constraints COMMA type_parameter_constraint
4447 var constraints = (List<FullNamedExpression>) $1;
4448 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4449 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4450 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4453 prev = $3 as SpecialContraintExpr;
4455 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4456 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4458 prev = constraints [0] as SpecialContraintExpr;
4459 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4460 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4465 constraints.Add ((FullNamedExpression) $3);
4470 type_parameter_constraint
4473 if ($1 is ComposedCast)
4474 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4478 | NEW OPEN_PARENS CLOSE_PARENS
4480 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4481 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4485 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4489 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4493 opt_type_parameter_variance
4498 | type_parameter_variance
4500 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4501 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4502 else if (RootContext.Version <= LanguageVersion.V_3)
4503 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4509 type_parameter_variance
4512 $$ = Variance.Covariant;
4516 $$ = Variance.Contravariant;
4525 // A block is "contained" on the following places:
4527 // property_declaration as part of the accessor body (get/set)
4528 // operator_declaration
4529 // constructor_declaration
4530 // destructor_declaration
4531 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4536 ++lexer.parsing_block;
4537 start_block (GetLocation ($1));
4539 opt_statement_list block_end
4548 --lexer.parsing_block;
4549 $$ = end_block (GetLocation ($1));
4551 | COMPLETE_COMPLETION
4553 --lexer.parsing_block;
4554 $$ = end_block (lexer.Location);
4562 ++lexer.parsing_block;
4563 current_block.StartLocation = GetLocation ($1);
4565 opt_statement_list CLOSE_BRACE
4567 --lexer.parsing_block;
4568 $$ = end_block (GetLocation ($4));
4579 | statement_list statement
4583 : declaration_statement
4585 if ($1 != null && (Block) $1 != current_block){
4586 current_block.AddStatement ((Statement) $1);
4587 current_block = (Block) $1;
4590 | valid_declaration_statement
4592 current_block.AddStatement ((Statement) $1);
4598 // The interactive_statement and its derivatives are only
4599 // used to provide a special version of `expression_statement'
4600 // that has a side effect of assigning the expression to
4603 interactive_statement_list
4604 : interactive_statement
4605 | interactive_statement_list interactive_statement
4608 interactive_statement
4609 : declaration_statement
4611 if ($1 != null && (Block) $1 != current_block){
4612 current_block.AddStatement ((Statement) $1);
4613 current_block = (Block) $1;
4616 | interactive_valid_declaration_statement
4618 current_block.AddStatement ((Statement) $1);
4623 valid_declaration_statement
4626 | expression_statement
4627 | selection_statement
4628 | iteration_statement
4632 | unchecked_statement
4639 interactive_valid_declaration_statement
4642 | interactive_expression_statement
4643 | selection_statement
4644 | iteration_statement
4648 | unchecked_statement
4656 : valid_declaration_statement
4657 | declaration_statement
4659 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4664 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4672 $$ = new EmptyStatement (GetLocation ($1));
4679 var lt = (Tokenizer.LocatedToken) $1;
4680 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4682 if (current_block.AddLabel (labeled))
4683 current_block.AddStatement (labeled);
4688 declaration_statement
4689 : local_variable_declaration SEMICOLON
4692 var de = (Tuple<FullNamedExpression, List<object>>) $1;
4693 $$ = declare_local_variables (de.Item1, de.Item2, de.Item1.Location);
4697 | local_constant_declaration SEMICOLON
4700 var de = (Tuple<FullNamedExpression, List<object>>) $1;
4702 $$ = declare_local_constants (de.Item1, de.Item2);
4708 * The following is from Rhys' grammar:
4709 * > Types in local variable declarations must be recognized as
4710 * > expressions to prevent reduce/reduce errors in the grammar.
4711 * > The expressions are converted into types during semantic analysis.
4714 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4716 // Ok, the above "primary_expression" is there to get rid of
4717 // both reduce/reduce and shift/reduces in the grammar, it should
4718 // really just be "type_name". If you use type_name, a reduce/reduce
4719 // creeps up. If you use namespace_or_type_name (which is all we need
4720 // really) two shift/reduces appear.
4723 // So the super-trick is that primary_expression
4724 // can only be either a SimpleName or a MemberAccess.
4725 // The MemberAccess case arises when you have a fully qualified type-name like :
4727 // SimpleName is when you have
4730 Expression expr = (Expression) $1;
4732 SimpleName sn = expr as SimpleName;
4733 if (sn != null && sn.Name == "var")
4734 $$ = new VarExpr (sn.Location);
4737 } else if (expr is ATypeNameExpression) {
4738 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4740 Error_ExpectingTypeName (expr);
4744 | builtin_types opt_rank_specifier_or_nullable
4749 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4751 | VOID opt_rank_specifier
4753 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4754 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4758 local_variable_pointer_type
4759 : primary_expression_no_array_creation STAR
4761 ATypeNameExpression expr = $1 as ATypeNameExpression;
4764 $$ = new ComposedCast (expr, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4766 Error_ExpectingTypeName ((Expression)$1);
4770 | builtin_types STAR
4772 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4776 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4778 | local_variable_pointer_type STAR
4780 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4786 | local_variable_pointer_type opt_rank_specifier
4792 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4799 local_variable_declaration
4800 : local_variable_type local_variable_declarators
4803 VarExpr ve = $1 as VarExpr;
4805 if (!((VariableDeclaration) ((List<object>)$2) [0]).HasInitializer)
4806 ve.VariableInitializersCount = 0;
4808 ve.VariableInitializersCount = ((List<object>)$2).Count;
4811 $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $1, (List<object>) $2);
4817 local_constant_declaration
4818 : CONST variable_type local_constant_declarators
4821 $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $2, (List<object>) $3);
4827 local_constant_declarators
4828 : local_constant_declarator
4830 variables_bucket.Clear ();
4832 variables_bucket.Add ($1);
4833 $$ = variables_bucket;
4835 | local_constant_declarators COMMA local_constant_declarator
4838 var constants = (List<object>) $1;
4844 local_constant_declarator
4845 : IDENTIFIER ASSIGN constant_initializer_expr
4847 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
4851 Report.Error (145, GetLocation ($1), "A const field requires a value to be provided");
4856 expression_statement
4857 : statement_expression SEMICOLON
4860 lbag.AddStatement ($$, GetLocation ($2));
4862 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4865 interactive_expression_statement
4866 : interactive_statement_expression SEMICOLON { $$ = $1; }
4867 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4871 // We have to do the wrapping here and not in the case above,
4872 // because statement_expression is used for example in for_statement
4874 statement_expression
4877 ExpressionStatement s = $1 as ExpressionStatement;
4879 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4880 s = EmptyExpressionStatement.Instance;
4883 $$ = new StatementExpression (s);
4887 Error_SyntaxError (yyToken);
4892 interactive_statement_expression
4895 Expression expr = (Expression) $1;
4896 ExpressionStatement s;
4898 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4899 $$ = new StatementExpression (s);
4903 Error_SyntaxError (yyToken);
4904 $$ = new EmptyStatement (GetLocation ($1));
4914 : IF open_parens_any boolean_expression CLOSE_PARENS
4917 if ($5 is EmptyStatement)
4918 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4920 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4921 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4923 | IF open_parens_any boolean_expression CLOSE_PARENS
4924 embedded_statement ELSE embedded_statement
4926 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4927 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4929 if ($5 is EmptyStatement)
4930 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4931 if ($7 is EmptyStatement)
4932 Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
4937 : SWITCH open_parens_any
4939 if (switch_stack == null)
4940 switch_stack = new Stack<Block> (2);
4941 switch_stack.Push (current_block);
4943 expression CLOSE_PARENS
4944 OPEN_BRACE opt_switch_sections CLOSE_BRACE
4946 $$ = new Switch ((Expression) $4, (List<SwitchSection>) $7, GetLocation ($1));
4947 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6), GetLocation ($8));
4949 current_block = (Block) switch_stack.Pop ();
4956 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4957 $$ = new List<SwitchSection> ();
4965 var sections = new List<SwitchSection> (4);
4967 sections.Add ((SwitchSection) $1);
4970 | switch_sections switch_section
4972 var sections = (List<SwitchSection>) $1;
4974 sections.Add ((SwitchSection) $2);
4982 current_block = current_block.CreateSwitchBlock (lexer.Location);
4986 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block.Explicit);
4993 var labels = new List<SwitchLabel> (4);
4995 labels.Add ((SwitchLabel) $1);
4998 | switch_labels switch_label
5000 var labels = (List<SwitchLabel>) ($1);
5001 labels.Add ((SwitchLabel) $2);
5008 : CASE constant_expression COLON
5010 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5011 lbag.AddLocation ($$, GetLocation ($3));
5015 $$ = new SwitchLabel (null, GetLocation ($1));
5027 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5029 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5030 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5035 : DO embedded_statement
5036 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5038 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5039 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5044 : FOR open_parens_any opt_for_initializer SEMICOLON
5046 Location l = lexer.Location;
5048 Block assign_block = current_block;
5050 if ($3 is Tuple<FullNamedExpression, List<object>>){
5051 var de = (Tuple<FullNamedExpression, List<object>>) $3;
5053 var type = de.Item1;
5055 foreach (VariableDeclaration decl in de.Item2){
5059 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5063 Expression expr = decl.GetInitializer (type);
5065 LocalVariableReference var;
5066 var = new LocalVariableReference (assign_block, decl.identifier, l);
5069 Assign a = new SimpleAssign (var, expr, decl.Location);
5071 assign_block.AddStatement (new StatementExpression (a));
5075 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
5076 // This can be referred to as $5 below.
5082 opt_for_condition SEMICOLON
5083 opt_for_iterator CLOSE_PARENS
5086 For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, GetLocation ($1));
5087 current_block.AddStatement (f);
5089 lbag.AddStatement (f, GetLocation ($2), GetLocation ($4), GetLocation ($7), GetLocation ($9));
5091 $$ = end_block (lexer.Location);
5096 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5101 : local_variable_declaration
5102 | statement_expression_list
5106 : /* empty */ { $$ = null; }
5107 | boolean_expression
5111 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5116 : statement_expression_list
5119 statement_expression_list
5120 : statement_expression
5121 | statement_expression_list COMMA statement_expression
5123 var sl = $1 as StatementList;
5125 sl = new StatementList ((Statement) $1, (Statement) $3);
5127 sl.Add ((Statement) $3);
5129 lbag.AddStatement (sl, GetLocation ($2));
5135 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5137 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5140 | FOREACH open_parens_any type IDENTIFIER IN
5141 expression CLOSE_PARENS
5143 start_block (lexer.Location);
5144 Block foreach_block = current_block;
5146 var lt = (Tokenizer.LocatedToken) $4;
5147 Location l = lt.Location;
5148 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
5150 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
5152 // Get a writable reference to this read-only variable.
5154 // Note that the $$ here refers to the value of _this_ code block,
5155 // not the value of the LHS non-terminal. This can be referred to as $8 below.
5156 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
5164 Foreach f = new Foreach ((Expression) $3, (LocalVariableReference) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5165 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5167 current_block.AddStatement (f);
5170 $$ = end_block (lexer.Location);
5176 | continue_statement
5186 $$ = new Break (GetLocation ($1));
5187 lbag.AddStatement ($$, GetLocation ($2));
5192 : CONTINUE SEMICOLON
5194 $$ = new Continue (GetLocation ($1));
5195 lbag.AddStatement ($$, GetLocation ($2));
5200 : GOTO IDENTIFIER SEMICOLON
5202 var lt = (Tokenizer.LocatedToken) $2;
5203 $$ = new Goto (lt.Value, lt.Location);
5204 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5206 | GOTO CASE constant_expression SEMICOLON
5208 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5209 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5211 | GOTO DEFAULT SEMICOLON
5213 $$ = new GotoDefault (GetLocation ($1));
5214 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5219 : RETURN opt_expression SEMICOLON
5221 $$ = new Return ((Expression) $2, GetLocation ($1));
5222 lbag.AddStatement ($$, GetLocation ($3));
5227 : THROW opt_expression SEMICOLON
5229 $$ = new Throw ((Expression) $2, GetLocation ($1));
5230 lbag.AddStatement ($$, GetLocation ($3));
5235 : IDENTIFIER RETURN opt_expression SEMICOLON
5237 var lt = (Tokenizer.LocatedToken) $1;
5238 string s = lt.Value;
5240 Report.Error (1003, lt.Location, "; expected");
5241 } else if ($3 == null) {
5242 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5243 } else if (RootContext.Version == LanguageVersion.ISO_1){
5244 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5247 current_block.Toplevel.IsIterator = true;
5248 $$ = new Yield ((Expression) $3, lt.Location);
5249 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5251 | IDENTIFIER BREAK SEMICOLON
5253 var lt = (Tokenizer.LocatedToken) $1;
5254 string s = lt.Value;
5256 Report.Error (1003, lt.Location, "; expected");
5257 } else if (RootContext.Version == LanguageVersion.ISO_1){
5258 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5261 current_block.Toplevel.IsIterator = true;
5262 $$ = new YieldBreak (lt.Location);
5263 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5273 : TRY block catch_clauses
5275 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5277 | TRY block FINALLY block
5279 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5280 lbag.AddStatement ($$, GetLocation ($3));
5282 | TRY block catch_clauses FINALLY block
5284 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5285 lbag.AddStatement ($$, GetLocation ($4));
5289 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5297 var l = new List<Catch> (2);
5302 | catch_clauses catch_clause
5304 var l = (List<Catch>) $1;
5306 Catch c = (Catch) $2;
5307 if (l [0].IsGeneral) {
5308 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5321 : /* empty */ { $$ = null; }
5326 : CATCH opt_catch_args
5329 var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
5333 List<object> one = new List<object> (1);
5335 one.Add (new VariableDeclaration (lt, null));
5337 start_block (lexer.Location);
5338 current_block = declare_local_variables (cc.Item1, one, lt.Location);
5342 Expression type = null;
5344 Block var_block = null;
5347 var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
5353 var_block = end_block (lexer.Location);
5357 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5358 lbag.AddLocation ($$, GetLocation ($1));
5359 lbag.AppendTo ($$, lbag.GetLocations ($2));
5364 : /* empty */ { $$ = null; }
5369 : open_parens_any type opt_identifier CLOSE_PARENS
5371 $$ = new Tuple<FullNamedExpression, Tokenizer.LocatedToken> ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3);
5372 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4));
5374 | open_parens_any CLOSE_PARENS
5376 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5384 $$ = new Checked ((Block) $2, GetLocation ($1));
5391 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5398 if (!RootContext.Unsafe)
5399 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5401 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5406 : FIXED open_parens_any
5407 type_and_void fixed_pointer_declarators
5410 start_block (lexer.Location);
5414 Expression type = (Expression) $3;
5415 var list = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $4;
5416 Fixed f = new Fixed (type,
5417 list.ConvertAll (i => {
5418 var v = new KeyValuePair<LocalInfo, Expression> (current_block.AddVariable (type, i.Key.Value, i.Key.Location), i.Value);
5419 if (v.Key != null) {
5420 v.Key.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5421 v.Key.Pinned = true;
5424 }), (Statement) $7, GetLocation ($1));
5426 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5));
5428 current_block.AddStatement (f);
5430 $$ = end_block (lexer.Location);
5434 fixed_pointer_declarators
5435 : fixed_pointer_declarator {
5436 var declarators = new List<KeyValuePair<Tokenizer.LocatedToken, Expression>> (2);
5438 declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$1);
5441 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5443 var declarators = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $1;
5445 declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$3);
5450 fixed_pointer_declarator
5451 : IDENTIFIER ASSIGN expression
5453 var lt = (Tokenizer.LocatedToken) $1;
5454 $$ = new KeyValuePair<Tokenizer.LocatedToken, Expression> (lt, (Expression) $3);
5458 Report.Error (210, ((Tokenizer.LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5464 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5466 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5467 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5472 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5474 start_block (lexer.Location);
5475 Block assign_block = current_block;
5477 var de = (Tuple<FullNamedExpression, List<object>>) $3;
5478 Location l = GetLocation ($1);
5480 var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
5482 lbag.AddStatement (assign_block, GetLocation ($1), GetLocation ($2), GetLocation ($4));
5484 foreach (VariableDeclaration decl in de.Item2) {
5485 LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location);
5488 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5490 Expression expr = decl.GetInitializer (de.Item1);
5492 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5495 LocalVariableReference var;
5497 // Get a writable reference to this read-only variable.
5498 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5500 // This is so that it is not a warning on using variables
5503 vars.Push (new Tuple<LocalVariableReference, Expression> (var, expr));
5505 // Assign a = new SimpleAssign (var, expr, decl.Location);
5506 // assign_block.AddStatement (new StatementExpression (a));
5509 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5510 // It can be referred to as $5 below.
5515 Statement stmt = (Statement) $6;
5516 var vars = (Stack<Tuple<LocalVariableReference, Expression>>) $5;
5517 Location l = GetLocation ($1);
5519 while (vars.Count > 0) {
5520 var de = vars.Pop ();
5521 stmt = new Using (de.Item1, de.Item2, stmt, l);
5523 current_block.AddStatement (stmt);
5524 $$ = end_block (lexer.Location);
5526 | USING open_parens_any expression CLOSE_PARENS
5528 start_block (lexer.Location);
5532 UsingTemporary usingTemporary = new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1));
5533 lbag.AddStatement (usingTemporary, GetLocation ($2), GetLocation ($4));
5534 current_block.AddStatement (usingTemporary);
5535 $$ = end_block (lexer.Location);
5543 : first_from_clause query_body
5545 lexer.query_parsing = false;
5547 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5549 from.Tail.Next = (Linq.AQueryClause)$2;
5552 current_block.SetEndLocation (lexer.Location);
5553 current_block = current_block.Parent;
5555 | nested_from_clause query_body
5557 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5559 from.Tail.Next = (Linq.AQueryClause)$2;
5562 current_block.SetEndLocation (lexer.Location);
5563 current_block = current_block.Parent;
5566 // Bubble up COMPLETE_COMPLETION productions
5567 | first_from_clause COMPLETE_COMPLETION {
5568 lexer.query_parsing = false;
5571 current_block.SetEndLocation (lexer.Location);
5572 current_block = current_block.Parent;
5574 | nested_from_clause COMPLETE_COMPLETION {
5576 current_block.SetEndLocation (lexer.Location);
5577 current_block = current_block.Parent;
5582 : FROM_FIRST IDENTIFIER IN expression
5584 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5586 var lt = (Tokenizer.LocatedToken) $2;
5587 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
5589 | FROM_FIRST type IDENTIFIER IN expression
5591 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5593 var lt = (Tokenizer.LocatedToken) $3;
5594 $$ = new Linq.QueryExpression (
5595 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5596 IdentifierType = (FullNamedExpression)$2
5603 : FROM IDENTIFIER IN expression
5605 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5607 var lt = (Tokenizer.LocatedToken) $2;
5608 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
5610 | FROM type IDENTIFIER IN expression
5612 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5614 var lt = (Tokenizer.LocatedToken) $3;
5615 $$ = new Linq.QueryExpression (
5616 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5617 IdentifierType = (FullNamedExpression)$2
5624 : FROM IDENTIFIER IN
5626 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5630 var lt = (Tokenizer.LocatedToken) $2;
5631 var sn = new SimpleMemberName (lt.Value, lt.Location);
5632 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5634 current_block.SetEndLocation (lexer.Location);
5635 current_block = current_block.Parent;
5637 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5639 | FROM type IDENTIFIER IN
5641 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5645 var lt = (Tokenizer.LocatedToken) $3;
5646 var sn = new SimpleMemberName (lt.Value, lt.Location);
5648 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5649 IdentifierType = (FullNamedExpression)$2
5652 current_block.SetEndLocation (lexer.Location);
5653 current_block = current_block.Parent;
5655 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5660 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5662 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5665 head.Next = (Linq.AQueryClause)$3;
5668 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5669 clause.Tail.Next = head;
5675 | opt_query_body_clauses COMPLETE_COMPLETION
5678 select_or_group_clause
5681 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5685 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5687 current_block.SetEndLocation (lexer.Location);
5688 current_block = current_block.Parent;
5692 if (linq_clause_blocks == null)
5693 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5695 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5696 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5700 current_block.SetEndLocation (lexer.Location);
5701 current_block = current_block.Parent;
5703 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5707 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5709 current_block.SetEndLocation (lexer.Location);
5710 current_block = current_block.Parent;
5714 opt_query_body_clauses
5716 | query_body_clauses
5721 | query_body_clauses query_body_clause
5723 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5737 : LET IDENTIFIER ASSIGN
5739 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5743 var lt = (Tokenizer.LocatedToken) $2;
5744 var sn = new SimpleMemberName (lt.Value, lt.Location);
5745 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5747 current_block.SetEndLocation (lexer.Location);
5748 current_block = current_block.Parent;
5750 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5757 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5761 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
5763 current_block.SetEndLocation (lexer.Location);
5764 current_block = current_block.Parent;
5769 : JOIN IDENTIFIER IN
5771 if (linq_clause_blocks == null)
5772 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5774 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5775 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5779 current_block.SetEndLocation (lexer.Location);
5780 current_block = current_block.Parent;
5782 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5783 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5787 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5788 current_block.SetEndLocation (lexer.Location);
5789 current_block = current_block.Parent;
5791 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5793 expression opt_join_into
5795 var lt = (Tokenizer.LocatedToken) $2;
5796 var sn = new SimpleMemberName (lt.Value, lt.Location);
5797 SimpleMemberName sn2 = null;
5799 var outer_selector = linq_clause_blocks.Pop ();
5800 var block = linq_clause_blocks.Pop ();
5803 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5805 var lt2 = (Tokenizer.LocatedToken) $12;
5806 sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
5807 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block,
5808 sn2, GetLocation ($1));
5811 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5812 current_block.SetEndLocation (lexer.Location);
5813 current_block = current_block.Parent;
5815 ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
5817 | JOIN type IDENTIFIER IN
5819 if (linq_clause_blocks == null)
5820 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5822 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5823 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5827 current_block.SetEndLocation (lexer.Location);
5828 current_block = current_block.Parent;
5830 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5831 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5835 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5836 current_block.SetEndLocation (lexer.Location);
5837 current_block = current_block.Parent;
5839 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5841 expression opt_join_into
5843 var lt = (Tokenizer.LocatedToken) $3;
5844 var sn = new SimpleMemberName (lt.Value, lt.Location);
5845 SimpleMemberName sn2 = null;
5846 var outer_selector = linq_clause_blocks.Pop ();
5847 var block = linq_clause_blocks.Pop ();
5850 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5851 IdentifierType = (FullNamedExpression)$2
5854 var lt2 = (Tokenizer.LocatedToken) $13;
5855 sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
5856 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, sn2, GetLocation ($1)) {
5857 IdentifierType = (FullNamedExpression)$2
5861 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5862 current_block.SetEndLocation (lexer.Location);
5863 current_block = current_block.Parent;
5865 ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
5880 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5884 current_block.SetEndLocation (lexer.Location);
5885 current_block = current_block.Parent;
5895 current_block.SetEndLocation (lexer.Location);
5896 current_block = current_block.Parent;
5898 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5902 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5909 | orderings_then_by COMMA
5911 current_block.SetEndLocation (lexer.Location);
5912 current_block = current_block.Parent;
5914 current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
5918 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5926 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5928 | expression ASCENDING
5930 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5932 | expression DESCENDING
5934 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5941 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5943 | expression ASCENDING
5945 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5947 | expression DESCENDING
5949 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5954 opt_query_continuation
5958 // query continuation block is not linked with query block but with block
5959 // before. This means each query can use same range variable names for
5960 // different identifiers.
5962 current_block.SetEndLocation (GetLocation ($1));
5963 current_block = current_block.Parent;
5965 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5967 if (linq_clause_blocks == null)
5968 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5970 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5974 var current_block = linq_clause_blocks.Pop ();
5975 var lt = (Tokenizer.LocatedToken) $2;
5976 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5977 next = (Linq.AQueryClause)$4
5983 // Support for using the compiler as an interactive parser
5985 // The INTERACTIVE_PARSER token is first sent to parse our
5986 // productions; If the result is a Statement, the parsing
5987 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5988 // to setup the blocks in advance.
5990 // This setup is here so that in the future we can add
5991 // support for other constructs (type parsing, namespaces, etc)
5992 // that do not require a block to be setup in advance
5996 : EVAL_STATEMENT_PARSER EOF
5997 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5998 | EVAL_STATEMENT_PARSER {
5999 Evaluator.LoadAliases (current_namespace);
6001 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
6002 Modifiers.PUBLIC, null), null);
6004 var baseclass_list = new List<FullNamedExpression> ();
6005 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
6006 current_container.AddBasesForPart (current_class, baseclass_list);
6008 // (ref object retval)
6009 Parameter [] mpar = new Parameter [1];
6010 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6012 ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
6013 current_local_parameters = pars;
6014 Method method = new Method (
6017 new TypeExpression (TypeManager.void_type, Location.Null),
6018 Modifiers.PUBLIC | Modifiers.STATIC,
6019 new MemberName ("Host"),
6021 null /* attributes */);
6023 oob_stack.Push (method);
6024 ++lexer.parsing_block;
6025 start_block (lexer.Location);
6027 interactive_statement_list opt_COMPLETE_COMPLETION
6029 --lexer.parsing_block;
6030 Method method = (Method) oob_stack.Pop ();
6032 method.Block = (ToplevelBlock) end_block(lexer.Location);
6033 current_container.AddMethod (method);
6035 --lexer.parsing_declaration;
6036 InteractiveResult = pop_current_class ();
6037 current_local_parameters = null;
6039 | EVAL_COMPILATION_UNIT_PARSER {
6040 Evaluator.LoadAliases (current_namespace);
6042 interactive_compilation_unit
6045 interactive_compilation_unit
6046 : outer_declarations
6047 | outer_declarations global_attributes
6052 opt_COMPLETE_COMPLETION
6054 | COMPLETE_COMPLETION
6057 close_brace_or_complete_completion
6059 | COMPLETE_COMPLETION
6064 // A class used to pass around variable declarations and constants
6066 class VariableDeclaration {
6067 public string identifier;
6068 Expression initializer;
6069 public Location Location;
6071 public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
6073 this.identifier = lt.Value;
6074 this.initializer = initializer;
6075 this.Location = lt.Location;
6078 public Expression GetInitializer (FullNamedExpression type)
6080 if (initializer is ArrayInitializer)
6081 return new ArrayCreation (type, (ArrayInitializer)initializer);
6086 public bool HasInitializer {
6087 get { return initializer != null; }
6093 // A class used to hold info about an operator declarator
6095 struct OperatorDeclaration {
6096 public readonly Operator.OpType optype;
6097 public readonly FullNamedExpression ret_type;
6098 public readonly Location location;
6100 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6103 this.ret_type = ret_type;
6104 this.location = location;
6108 void Error_ExpectingTypeName (Expression expr)
6110 if (expr is Invocation){
6111 Report.Error (1002, expr.Location, "Expecting `;'");
6113 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
6117 void Error_ParameterModifierNotValid (string modifier, Location loc)
6119 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6123 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6125 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6126 Parameter.GetModifierSignature (mod));
6129 void Error_TypeExpected (Location loc)
6131 Report.Error (1031, loc, "Type expected");
6134 void Error_UnsafeCodeNotAllowed (Location loc)
6136 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6139 void Error_NamedArgumentExpected (NamedArgument a)
6141 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6144 void push_current_class (TypeContainer tc, object partial_token)
6146 if (RootContext.EvalMode){
6147 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
6148 undo.AddTypeContainer (current_container, tc);
6151 if (partial_token != null)
6152 current_container = current_container.AddPartial (tc);
6154 current_container = current_container.AddTypeContainer (tc);
6156 ++lexer.parsing_declaration;
6160 DeclSpace pop_current_class ()
6162 DeclSpace retval = current_class;
6164 current_class = current_class.Parent;
6165 current_container = current_class.PartialContainer;
6171 // Given the @class_name name, it creates a fully qualified name
6172 // based on the containing declaration space
6175 MakeName (MemberName class_name)
6177 Namespace ns = current_namespace.NS;
6179 if (current_container == RootContext.ToplevelTypes) {
6180 if (ns.Name.Length != 0)
6181 return new MemberName (ns.MemberName, class_name);
6185 return new MemberName (current_container.MemberName, class_name);
6189 [System.Diagnostics.Conditional ("FULL_AST")]
6190 void StoreModifierLocation (object token, Location loc)
6195 if (mod_locations == null)
6196 mod_locations = new List<Tuple<Modifiers, Location>> ();
6198 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6201 Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
6203 Block implicit_block;
6206 // If we are doing interactive editing, we want variable declarations
6207 // that are in the top block to be added instead to the class as
6210 if (RootContext.StatementMode){
6213 for (Block b = current_block; b != null; b = b.Parent){
6214 if (b is ExplicitBlock && !(b is ToplevelBlock)){
6215 // There has been an explicit block, we cant add to the class
6222 // We can use "current_block" since we know there are no explicit blocks
6224 foreach (VariableDeclaration decl in variable_declarators){
6225 // We can not use the super-handy f.Initializer, because
6226 // multiple lines would force code to be executed out of sync
6227 var init = decl.GetInitializer (type);
6229 string id = "$" + decl.identifier;
6230 LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
6232 // Avoid warning about this variable not being used.
6235 LocalVariableReference var;
6236 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
6237 Assign assign = new SimpleAssign (var, init, decl.Location);
6238 current_block.AddStatement (new StatementExpression (assign));
6239 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
6240 current_block.AddStatement (new StatementExpression (assign));
6242 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
6243 new MemberName (decl.identifier, loc), null);
6244 current_container.AddField (f);
6246 // Register the field to be visible later as a global variable
6247 Evaluator.QueueField (f);
6251 return current_block;
6256 // We use the `Used' property to check whether statements
6257 // have been added to the current block. If so, we need
6258 // to create another block to contain the new declaration
6259 // otherwise, as an optimization, we use the same block to
6260 // add the declaration.
6262 // FIXME: A further optimization is to check if the statements
6263 // that were added were added as part of the initialization
6264 // below. In which case, no other statements have been executed
6265 // and we might be able to reduce the number of blocks for
6266 // situations like this:
6268 // int j = 1; int k = j + 1;
6270 if (current_block.Used)
6271 implicit_block = new Block (current_block, loc, lexer.Location);
6273 implicit_block = current_block;
6275 foreach (VariableDeclaration decl in variable_declarators){
6277 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6278 if (decl.HasInitializer){
6281 var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
6283 assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
6285 implicit_block.AddStatement (new StatementExpression (assign));
6290 return implicit_block;
6293 Block declare_local_constants (FullNamedExpression type, List<object> declarators)
6295 Block implicit_block;
6297 if (current_block.Used)
6298 implicit_block = new Block (current_block);
6300 implicit_block = current_block;
6302 foreach (VariableDeclaration decl in declarators){
6303 implicit_block.AddConstant (type, decl.identifier, decl.GetInitializer (type), decl.Location);
6306 return implicit_block;
6309 string CheckAttributeTarget (string a, Location l)
6312 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6316 Report.Warning (658, 1, l,
6317 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6318 return string.Empty;
6321 static bool IsUnaryOperator (Operator.OpType op)
6325 case Operator.OpType.LogicalNot:
6326 case Operator.OpType.OnesComplement:
6327 case Operator.OpType.Increment:
6328 case Operator.OpType.Decrement:
6329 case Operator.OpType.True:
6330 case Operator.OpType.False:
6331 case Operator.OpType.UnaryPlus:
6332 case Operator.OpType.UnaryNegation:
6338 void syntax_error (Location l, string msg)
6340 Report.Error (1003, l, "Syntax error, " + msg);
6345 public Tokenizer Lexer {
6351 static CSharpParser ()
6353 oob_stack = new Stack<object> ();
6356 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
6358 if (RootContext.EvalMode)
6362 this.compiler = ctx;
6363 current_namespace = new NamespaceEntry (null, file, null);
6364 current_class = current_namespace.SlaveDeclSpace;
6365 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6367 lexer = new Tokenizer (reader, file, ctx);
6369 use_global_stacks = true;
6372 public void parse ()
6374 eof_token = Token.EOF;
6375 Tokenizer.LocatedToken.Initialize ();
6378 if (yacc_verbose_flag > 1)
6379 yyparse (lexer, new yydebug.yyDebugSimple ());
6383 Tokenizer tokenizer = lexer as Tokenizer;
6384 tokenizer.cleanup ();
6385 } catch (Exception e){
6386 if (e is yyParser.yyUnexpectedEof)
6387 UnexpectedEOF = true;
6389 if (e is yyParser.yyException)
6390 Report.Error (-25, lexer.Location, "Parsing error");
6391 else if (yacc_verbose_flag > 0)
6392 throw; // Used by compiler-tester to test internal errors
6394 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6397 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6398 throw new InternalErrorException ("who set it?");
6401 void CheckToken (int error, int yyToken, string msg, Location loc)
6403 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6404 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6406 Report.Error (error, loc, msg);
6409 void CheckIdentifierToken (int yyToken, Location loc)
6411 CheckToken (1041, yyToken, "Identifier expected", loc);
6414 string ConsumeStoredComment ()
6416 string s = tmpComment;
6418 Lexer.doc_state = XmlCommentState.Allowed;
6422 Location GetLocation (object obj)
6424 if (obj is Tokenizer.LocatedToken)
6425 return ((Tokenizer.LocatedToken) obj).Location;
6426 if (obj is MemberName)
6427 return ((MemberName) obj).Location;
6429 if (obj is Expression)
6430 return ((Expression) obj).Location;
6432 return lexer.Location;
6436 get { return compiler.Report; }
6439 public LocationsBag LocationsBag {
6448 void start_block (Location loc)
6450 if (current_block == null || parsing_anonymous_method) {
6451 current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, loc);
6452 parsing_anonymous_method = false;
6454 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6459 end_block (Location loc)
6461 Block retval = current_block.Explicit;
6462 retval.SetEndLocation (loc);
6463 current_block = retval.Parent;
6468 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6470 if (RootContext.Version == LanguageVersion.ISO_1){
6471 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6474 oob_stack.Push (current_anonymous_method);
6475 oob_stack.Push (current_local_parameters);
6477 current_local_parameters = parameters;
6479 current_anonymous_method = lambda
6480 ? new LambdaExpression (loc)
6481 : new AnonymousMethodExpression (loc);
6483 // Force the next block to be created as a ToplevelBlock
6484 parsing_anonymous_method = true;
6488 * Completes the anonymous method processing, if lambda_expr is null, this
6489 * means that we have a Statement instead of an Expression embedded
6491 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6493 AnonymousMethodExpression retval;
6495 current_anonymous_method.Block = anon_block;
6496 retval = current_anonymous_method;
6498 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6499 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6504 public NamespaceEntry CurrentNamespace {
6506 return current_namespace;
6511 void Error_SyntaxError (int token)
6513 Error_SyntaxError (0, token, "Unexpected symbol");
6516 void Error_SyntaxError (int error_code, int token, string msg)
6518 string symbol = GetSymbolName (token);
6519 string expecting = GetExpecting ();
6521 if (error_code == 0) {
6522 if (expecting == "`)'")
6528 if (string.IsNullOrEmpty (expecting))
6529 Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
6531 Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6534 string GetExpecting ()
6536 int [] tokens = yyExpectingTokens (yyExpectingState);
6537 var names = new List<string> (tokens.Length);
6538 bool has_type = false;
6539 bool has_identifier = false;
6540 for (int i = 0; i < tokens.Length; i++){
6541 int token = tokens [i];
6542 has_identifier |= token == Token.IDENTIFIER;
6544 string name = GetTokenName (token);
6545 if (name == "<internal>")
6548 has_type |= name == "type";
6549 if (names.Contains (name))
6556 // Too many tokens to enumerate
6558 if (names.Count > 8)
6561 if (has_type && has_identifier)
6562 names.Remove ("identifier");
6564 if (names.Count == 1)
6565 return "`" + GetTokenName (tokens [0]) + "'";
6567 StringBuilder sb = new StringBuilder ();
6569 int count = names.Count;
6570 for (int i = 0; i < count; i++){
6571 bool last = i + 1 == count;
6575 sb.Append (names [i]);
6576 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6578 return sb.ToString ();
6582 string GetSymbolName (int token)
6586 return ((Constant)lexer.Value).GetValue ().ToString ();
6587 case Token.IDENTIFIER:
6588 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6630 case Token.BITWISE_AND:
6632 case Token.BITWISE_OR:
6646 case Token.OP_SHIFT_LEFT:
6648 case Token.OP_SHIFT_RIGHT:
6668 case Token.OP_COALESCING:
6670 case Token.OP_MULT_ASSIGN:
6672 case Token.OP_DIV_ASSIGN:
6674 case Token.OP_MOD_ASSIGN:
6676 case Token.OP_ADD_ASSIGN:
6678 case Token.OP_SUB_ASSIGN:
6680 case Token.OP_SHIFT_LEFT_ASSIGN:
6682 case Token.OP_SHIFT_RIGHT_ASSIGN:
6684 case Token.OP_AND_ASSIGN:
6686 case Token.OP_XOR_ASSIGN:
6688 case Token.OP_OR_ASSIGN:
6692 return GetTokenName (token);
6695 static string GetTokenName (int token)
6698 case Token.ABSTRACT:
6718 case Token.CONTINUE:
6722 case Token.DELEGATE:
6732 case Token.EXPLICIT:
6750 case Token.IMPLICIT:
6754 case Token.INTERFACE:
6756 case Token.INTERNAL:
6762 case Token.NAMESPACE:
6768 case Token.OPERATOR:
6772 case Token.OVERRIDE:
6778 case Token.PROTECTED:
6782 case Token.READONLY:
6794 case Token.STACKALLOC:
6795 return "stackalloc";
6812 case Token.UNCHECKED:
6820 case Token.VOLATILE:
6833 case Token.FROM_FIRST:
6851 case Token.ASCENDING:
6853 case Token.DESCENDING:
6854 return "descending";
6861 case Token.OPEN_BRACE:
6863 case Token.CLOSE_BRACE:
6865 case Token.OPEN_BRACKET:
6866 case Token.OPEN_BRACKET_EXPR:
6868 case Token.CLOSE_BRACKET:
6870 case Token.OPEN_PARENS_CAST:
6871 case Token.OPEN_PARENS_LAMBDA:
6872 case Token.OPEN_PARENS:
6874 case Token.CLOSE_PARENS:
6880 case Token.DEFAULT_COLON:
6884 case Token.SEMICOLON:
6895 case Token.BITWISE_AND:
6896 case Token.BITWISE_OR:
6903 case Token.OP_SHIFT_LEFT:
6904 case Token.OP_SHIFT_RIGHT:
6912 case Token.OP_COALESCING:
6913 case Token.OP_MULT_ASSIGN:
6914 case Token.OP_DIV_ASSIGN:
6915 case Token.OP_MOD_ASSIGN:
6916 case Token.OP_ADD_ASSIGN:
6917 case Token.OP_SUB_ASSIGN:
6918 case Token.OP_SHIFT_LEFT_ASSIGN:
6919 case Token.OP_SHIFT_RIGHT_ASSIGN:
6920 case Token.OP_AND_ASSIGN:
6921 case Token.OP_XOR_ASSIGN:
6922 case Token.OP_OR_ASSIGN:
6923 return "<operator>";
6945 case Token.OP_GENERICS_LT:
6946 case Token.GENERIC_DIMENSION:
6948 case Token.OP_GENERICS_GT:
6951 case Token.INTERR_NULLABLE:
6953 case Token.DOUBLE_COLON:
6957 case Token.IDENTIFIER:
6958 return "identifier";
6960 // All of these are internal.
6963 case Token.FIRST_KEYWORD:
6965 case Token.EVAL_COMPILATION_UNIT_PARSER:
6966 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6967 case Token.EVAL_STATEMENT_PARSER:
6968 case Token.LAST_KEYWORD:
6969 case Token.GENERATE_COMPLETION:
6970 case Token.COMPLETE_COMPLETION:
6971 return "<internal>";
6973 // A bit more robust.
6975 return yyNames [token];