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));
789 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
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 te = ((MemberName) $1).GetTypeExpression ();
3736 if (te.HasTypeArguments)
3737 Error_TypeExpected (GetLocation ($4));
3739 var lt = (Tokenizer.LocatedToken) $3;
3740 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3747 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3748 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
3749 else if (RootContext.Version < LanguageVersion.ISO_2)
3750 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
3756 qualified_alias_member
3757 : IDENTIFIER DOUBLE_COLON
3759 var lt = (Tokenizer.LocatedToken) $1;
3760 if (RootContext.Version == LanguageVersion.ISO_1)
3761 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3768 : SIZEOF open_parens_any type CLOSE_PARENS
3770 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3771 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3776 : CHECKED open_parens_any expression CLOSE_PARENS
3778 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3779 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3783 unchecked_expression
3784 : UNCHECKED open_parens_any expression CLOSE_PARENS
3786 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3787 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3791 pointer_member_access
3792 : primary_expression OP_PTR IDENTIFIER
3794 var lt = (Tokenizer.LocatedToken) $3;
3795 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3799 anonymous_method_expression
3800 : DELEGATE opt_anonymous_method_signature
3802 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3806 $$ = end_anonymous ((ToplevelBlock) $4);
3810 opt_anonymous_method_signature
3813 $$ = ParametersCompiled.Undefined;
3815 | anonymous_method_signature
3818 anonymous_method_signature
3821 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3823 opt_formal_parameter_list CLOSE_PARENS
3825 valid_param_mod = 0;
3830 default_value_expression
3831 : DEFAULT open_parens_any type CLOSE_PARENS
3833 if (RootContext.Version < LanguageVersion.ISO_2)
3834 Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3836 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3837 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3842 : primary_expression
3843 | BANG prefixed_unary_expression
3845 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3847 | TILDE prefixed_unary_expression
3849 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3855 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3857 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3858 lbag.AddLocation ($$, GetLocation ($3));
3860 | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
3862 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3863 lbag.AddLocation ($$, GetLocation ($3));
3868 // The idea to split this out is from Rhys' grammar
3869 // to solve the problem with casts.
3871 prefixed_unary_expression
3873 | PLUS prefixed_unary_expression
3875 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3877 | MINUS prefixed_unary_expression
3879 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3881 | OP_INC prefixed_unary_expression
3883 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3885 | OP_DEC prefixed_unary_expression
3887 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3889 | STAR prefixed_unary_expression
3891 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3893 | BITWISE_AND prefixed_unary_expression
3895 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3899 multiplicative_expression
3900 : prefixed_unary_expression
3901 | multiplicative_expression STAR prefixed_unary_expression
3903 $$ = new Binary (Binary.Operator.Multiply,
3904 (Expression) $1, (Expression) $3, GetLocation ($2));
3906 | multiplicative_expression DIV prefixed_unary_expression
3908 $$ = new Binary (Binary.Operator.Division,
3909 (Expression) $1, (Expression) $3, GetLocation ($2));
3911 | multiplicative_expression PERCENT prefixed_unary_expression
3913 $$ = new Binary (Binary.Operator.Modulus,
3914 (Expression) $1, (Expression) $3, GetLocation ($2));
3919 : multiplicative_expression
3920 | additive_expression PLUS multiplicative_expression
3922 $$ = new Binary (Binary.Operator.Addition,
3923 (Expression) $1, (Expression) $3, GetLocation ($2));
3925 | additive_expression MINUS multiplicative_expression
3927 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3929 | parenthesized_expression MINUS multiplicative_expression
3931 // Shift/Reduce conflict
3932 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3934 | additive_expression AS type
3936 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3938 | additive_expression IS type
3940 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3945 : additive_expression
3946 | shift_expression OP_SHIFT_LEFT additive_expression
3948 $$ = new Binary (Binary.Operator.LeftShift,
3949 (Expression) $1, (Expression) $3, GetLocation ($2));
3951 | shift_expression OP_SHIFT_RIGHT additive_expression
3953 $$ = new Binary (Binary.Operator.RightShift,
3954 (Expression) $1, (Expression) $3, GetLocation ($2));
3958 relational_expression
3960 | relational_expression OP_LT shift_expression
3962 $$ = new Binary (Binary.Operator.LessThan,
3963 (Expression) $1, (Expression) $3, GetLocation ($2));
3965 | relational_expression OP_GT shift_expression
3967 $$ = new Binary (Binary.Operator.GreaterThan,
3968 (Expression) $1, (Expression) $3, GetLocation ($2));
3970 | relational_expression OP_LE shift_expression
3972 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3973 (Expression) $1, (Expression) $3, GetLocation ($2));
3975 | relational_expression OP_GE shift_expression
3977 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3978 (Expression) $1, (Expression) $3, GetLocation ($2));
3983 : relational_expression
3984 | equality_expression OP_EQ relational_expression
3986 $$ = new Binary (Binary.Operator.Equality,
3987 (Expression) $1, (Expression) $3, GetLocation ($2));
3989 | equality_expression OP_NE relational_expression
3991 $$ = new Binary (Binary.Operator.Inequality,
3992 (Expression) $1, (Expression) $3, GetLocation ($2));
3997 : equality_expression
3998 | and_expression BITWISE_AND equality_expression
4000 $$ = new Binary (Binary.Operator.BitwiseAnd,
4001 (Expression) $1, (Expression) $3, GetLocation ($2));
4005 exclusive_or_expression
4007 | exclusive_or_expression CARRET and_expression
4009 $$ = new Binary (Binary.Operator.ExclusiveOr,
4010 (Expression) $1, (Expression) $3, GetLocation ($2));
4014 inclusive_or_expression
4015 : exclusive_or_expression
4016 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4018 $$ = new Binary (Binary.Operator.BitwiseOr,
4019 (Expression) $1, (Expression) $3, GetLocation ($2));
4023 conditional_and_expression
4024 : inclusive_or_expression
4025 | conditional_and_expression OP_AND inclusive_or_expression
4027 $$ = new Binary (Binary.Operator.LogicalAnd,
4028 (Expression) $1, (Expression) $3, GetLocation ($2));
4032 conditional_or_expression
4033 : conditional_and_expression
4034 | conditional_or_expression OP_OR conditional_and_expression
4036 $$ = new Binary (Binary.Operator.LogicalOr,
4037 (Expression) $1, (Expression) $3, GetLocation ($2));
4041 null_coalescing_expression
4042 : conditional_or_expression
4043 | conditional_or_expression OP_COALESCING null_coalescing_expression
4045 if (RootContext.Version < LanguageVersion.ISO_2)
4046 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4048 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
4052 conditional_expression
4053 : null_coalescing_expression
4054 | null_coalescing_expression INTERR expression COLON expression
4056 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4057 lbag.AddLocation ($$, GetLocation ($4));
4061 assignment_expression
4062 : prefixed_unary_expression ASSIGN expression
4064 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
4066 | prefixed_unary_expression OP_MULT_ASSIGN expression
4068 $$ = new CompoundAssign (
4069 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
4071 | prefixed_unary_expression OP_DIV_ASSIGN expression
4073 $$ = new CompoundAssign (
4074 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
4076 | prefixed_unary_expression OP_MOD_ASSIGN expression
4078 $$ = new CompoundAssign (
4079 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4081 | prefixed_unary_expression OP_ADD_ASSIGN expression
4083 $$ = new CompoundAssign (
4084 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4086 | prefixed_unary_expression OP_SUB_ASSIGN expression
4088 $$ = new CompoundAssign (
4089 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4091 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4093 $$ = new CompoundAssign (
4094 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4096 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4098 $$ = new CompoundAssign (
4099 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4101 | prefixed_unary_expression OP_AND_ASSIGN expression
4103 $$ = new CompoundAssign (
4104 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4106 | prefixed_unary_expression OP_OR_ASSIGN expression
4108 $$ = new CompoundAssign (
4109 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4111 | prefixed_unary_expression OP_XOR_ASSIGN expression
4113 $$ = new CompoundAssign (
4114 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4118 lambda_parameter_list
4121 var pars = new List<Parameter> (4);
4122 pars.Add ((Parameter) $1);
4126 | lambda_parameter_list COMMA lambda_parameter
4128 var pars = (List<Parameter>) $1;
4129 Parameter p = (Parameter)$3;
4130 if (pars[0].GetType () != p.GetType ()) {
4131 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4140 : parameter_modifier parameter_type IDENTIFIER
4142 var lt = (Tokenizer.LocatedToken) $3;
4144 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4146 | parameter_type IDENTIFIER
4148 var lt = (Tokenizer.LocatedToken) $2;
4150 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4154 var lt = (Tokenizer.LocatedToken) $1;
4155 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4159 opt_lambda_parameter_list
4160 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4161 | lambda_parameter_list {
4162 var pars_list = (List<Parameter>) $1;
4163 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
4167 lambda_expression_body
4169 start_block (lexer.Location);
4173 Block b = end_block (lexer.Location);
4174 b.AddStatement (new ContextualReturn ((Expression) $2));
4185 var lt = (Tokenizer.LocatedToken) $1;
4186 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4187 start_anonymous (true, new ParametersCompiled (compiler, p), GetLocation ($1));
4189 lambda_expression_body
4191 $$ = end_anonymous ((ToplevelBlock) $4);
4192 lbag.AddLocation ($$, GetLocation ($2));
4194 | OPEN_PARENS_LAMBDA
4196 if (RootContext.Version <= LanguageVersion.ISO_2)
4197 Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4199 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4201 opt_lambda_parameter_list CLOSE_PARENS ARROW
4203 valid_param_mod = 0;
4204 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4206 lambda_expression_body
4208 $$ = end_anonymous ((ToplevelBlock) $7);
4209 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
4214 : assignment_expression
4215 | non_assignment_expression
4218 non_assignment_expression
4219 : conditional_expression
4231 $$ = new BooleanExpression ((Expression) $1);
4244 lexer.ConstraintsParsing = true;
4246 type_declaration_name
4248 MemberName name = MakeName ((MemberName) $6);
4249 push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
4252 opt_type_parameter_constraints_clauses
4254 lexer.ConstraintsParsing = false;
4256 current_class.SetParameterInfo ((List<Constraints>) $9);
4257 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4259 if (RootContext.Documentation != null) {
4260 current_container.DocComment = Lexer.consume_doc_comment ();
4261 Lexer.doc_state = XmlCommentState.Allowed;
4264 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4266 --lexer.parsing_declaration;
4267 if (RootContext.Documentation != null)
4268 Lexer.doc_state = XmlCommentState.Allowed;
4272 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4273 $$ = pop_current_class ();
4281 { $$ = $1; } // location
4287 mod_locations = null;
4295 | modifiers modifier
4297 var m1 = (Modifiers) $1;
4298 var m2 = (Modifiers) $2;
4300 if ((m1 & m2) != 0) {
4301 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4302 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4303 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4304 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4305 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4306 "More than one protection modifier specified");
4317 StoreModifierLocation ($$, GetLocation ($1));
4319 if (current_container == RootContext.ToplevelTypes)
4320 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4324 $$ = Modifiers.PUBLIC;
4325 StoreModifierLocation ($$, GetLocation ($1));
4329 $$ = Modifiers.PROTECTED;
4330 StoreModifierLocation ($$, GetLocation ($1));
4334 $$ = Modifiers.INTERNAL;
4335 StoreModifierLocation ($$, GetLocation ($1));
4339 $$ = Modifiers.PRIVATE;
4340 StoreModifierLocation ($$, GetLocation ($1));
4344 $$ = Modifiers.ABSTRACT;
4345 StoreModifierLocation ($$, GetLocation ($1));
4349 $$ = Modifiers.SEALED;
4350 StoreModifierLocation ($$, GetLocation ($1));
4354 $$ = Modifiers.STATIC;
4355 StoreModifierLocation ($$, GetLocation ($1));
4359 $$ = Modifiers.READONLY;
4360 StoreModifierLocation ($$, GetLocation ($1));
4364 $$ = Modifiers.VIRTUAL;
4365 StoreModifierLocation ($$, GetLocation ($1));
4369 $$ = Modifiers.OVERRIDE;
4370 StoreModifierLocation ($$, GetLocation ($1));
4374 $$ = Modifiers.EXTERN;
4375 StoreModifierLocation ($$, GetLocation ($1));
4379 $$ = Modifiers.VOLATILE;
4380 StoreModifierLocation ($$, GetLocation ($1));
4384 $$ = Modifiers.UNSAFE;
4385 StoreModifierLocation ($$, GetLocation ($1));
4386 if (!RootContext.Unsafe)
4387 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4395 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4399 opt_type_parameter_constraints_clauses
4400 : /* empty */ { $$ = null; }
4401 | type_parameter_constraints_clauses
4407 type_parameter_constraints_clauses
4408 : type_parameter_constraints_clause
4410 var constraints = new List<Constraints> (1);
4411 constraints.Add ((Constraints) $1);
4414 | type_parameter_constraints_clauses type_parameter_constraints_clause
4416 var constraints = (List<Constraints>) $1;
4417 Constraints new_constraint = (Constraints)$2;
4419 foreach (Constraints c in constraints) {
4420 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4421 Report.Error (409, new_constraint.Location,
4422 "A constraint clause has already been specified for type parameter `{0}'",
4423 new_constraint.TypeParameter.Value);
4427 constraints.Add (new_constraint);
4432 type_parameter_constraints_clause
4433 : WHERE IDENTIFIER COLON type_parameter_constraints
4435 var lt = (Tokenizer.LocatedToken) $2;
4436 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4440 type_parameter_constraints
4441 : type_parameter_constraint
4443 var constraints = new List<FullNamedExpression> (1);
4444 constraints.Add ((FullNamedExpression) $1);
4447 | type_parameter_constraints COMMA type_parameter_constraint
4449 var constraints = (List<FullNamedExpression>) $1;
4450 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4451 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4452 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4455 prev = $3 as SpecialContraintExpr;
4457 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4458 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4460 prev = constraints [0] as SpecialContraintExpr;
4461 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4462 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4467 constraints.Add ((FullNamedExpression) $3);
4472 type_parameter_constraint
4475 if ($1 is ComposedCast)
4476 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4480 | NEW OPEN_PARENS CLOSE_PARENS
4482 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4483 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4487 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4491 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4495 opt_type_parameter_variance
4500 | type_parameter_variance
4502 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4503 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4504 else if (RootContext.Version <= LanguageVersion.V_3)
4505 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4511 type_parameter_variance
4514 $$ = Variance.Covariant;
4518 $$ = Variance.Contravariant;
4527 // A block is "contained" on the following places:
4529 // property_declaration as part of the accessor body (get/set)
4530 // operator_declaration
4531 // constructor_declaration
4532 // destructor_declaration
4533 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4538 ++lexer.parsing_block;
4539 start_block (GetLocation ($1));
4541 opt_statement_list block_end
4550 --lexer.parsing_block;
4551 $$ = end_block (GetLocation ($1));
4553 | COMPLETE_COMPLETION
4555 --lexer.parsing_block;
4556 $$ = end_block (lexer.Location);
4564 ++lexer.parsing_block;
4565 current_block.StartLocation = GetLocation ($1);
4567 opt_statement_list CLOSE_BRACE
4569 --lexer.parsing_block;
4570 $$ = end_block (GetLocation ($4));
4581 | statement_list statement
4585 : declaration_statement
4587 if ($1 != null && (Block) $1 != current_block){
4588 current_block.AddStatement ((Statement) $1);
4589 current_block = (Block) $1;
4592 | valid_declaration_statement
4594 current_block.AddStatement ((Statement) $1);
4600 // The interactive_statement and its derivatives are only
4601 // used to provide a special version of `expression_statement'
4602 // that has a side effect of assigning the expression to
4605 interactive_statement_list
4606 : interactive_statement
4607 | interactive_statement_list interactive_statement
4610 interactive_statement
4611 : declaration_statement
4613 if ($1 != null && (Block) $1 != current_block){
4614 current_block.AddStatement ((Statement) $1);
4615 current_block = (Block) $1;
4618 | interactive_valid_declaration_statement
4620 current_block.AddStatement ((Statement) $1);
4625 valid_declaration_statement
4628 | expression_statement
4629 | selection_statement
4630 | iteration_statement
4634 | unchecked_statement
4641 interactive_valid_declaration_statement
4644 | interactive_expression_statement
4645 | selection_statement
4646 | iteration_statement
4650 | unchecked_statement
4658 : valid_declaration_statement
4659 | declaration_statement
4661 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4666 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4674 $$ = new EmptyStatement (GetLocation ($1));
4681 var lt = (Tokenizer.LocatedToken) $1;
4682 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4684 if (current_block.AddLabel (labeled))
4685 current_block.AddStatement (labeled);
4690 declaration_statement
4691 : local_variable_declaration SEMICOLON
4694 var de = (Tuple<FullNamedExpression, List<object>>) $1;
4695 $$ = declare_local_variables (de.Item1, de.Item2, de.Item1.Location);
4699 | local_constant_declaration SEMICOLON
4702 var de = (Tuple<FullNamedExpression, List<object>>) $1;
4704 $$ = declare_local_constants (de.Item1, de.Item2);
4710 * The following is from Rhys' grammar:
4711 * > Types in local variable declarations must be recognized as
4712 * > expressions to prevent reduce/reduce errors in the grammar.
4713 * > The expressions are converted into types during semantic analysis.
4716 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4718 // Ok, the above "primary_expression" is there to get rid of
4719 // both reduce/reduce and shift/reduces in the grammar, it should
4720 // really just be "type_name". If you use type_name, a reduce/reduce
4721 // creeps up. If you use namespace_or_type_name (which is all we need
4722 // really) two shift/reduces appear.
4725 // So the super-trick is that primary_expression
4726 // can only be either a SimpleName or a MemberAccess.
4727 // The MemberAccess case arises when you have a fully qualified type-name like :
4729 // SimpleName is when you have
4732 Expression expr = (Expression) $1;
4734 SimpleName sn = expr as SimpleName;
4735 if (sn != null && sn.Name == "var")
4736 $$ = new VarExpr (sn.Location);
4739 } else if (expr is ATypeNameExpression) {
4740 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4742 Error_ExpectingTypeName (expr);
4746 | builtin_types opt_rank_specifier_or_nullable
4751 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4753 | VOID opt_rank_specifier
4755 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4756 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4760 local_variable_pointer_type
4761 : primary_expression_no_array_creation STAR
4763 ATypeNameExpression expr = $1 as ATypeNameExpression;
4766 $$ = new ComposedCast (expr, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4768 Error_ExpectingTypeName ((Expression)$1);
4772 | builtin_types STAR
4774 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4778 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4780 | local_variable_pointer_type STAR
4782 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4788 | local_variable_pointer_type opt_rank_specifier
4794 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4801 local_variable_declaration
4802 : local_variable_type local_variable_declarators
4805 VarExpr ve = $1 as VarExpr;
4807 if (!((VariableDeclaration) ((List<object>)$2) [0]).HasInitializer)
4808 ve.VariableInitializersCount = 0;
4810 ve.VariableInitializersCount = ((List<object>)$2).Count;
4813 $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $1, (List<object>) $2);
4819 local_constant_declaration
4820 : CONST variable_type local_constant_declarators
4823 $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $2, (List<object>) $3);
4829 local_constant_declarators
4830 : local_constant_declarator
4832 variables_bucket.Clear ();
4834 variables_bucket.Add ($1);
4835 $$ = variables_bucket;
4837 | local_constant_declarators COMMA local_constant_declarator
4840 var constants = (List<object>) $1;
4846 local_constant_declarator
4847 : IDENTIFIER ASSIGN constant_initializer_expr
4849 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
4853 Report.Error (145, GetLocation ($1), "A const field requires a value to be provided");
4858 expression_statement
4859 : statement_expression SEMICOLON
4862 lbag.AddStatement ($$, GetLocation ($2));
4864 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4867 interactive_expression_statement
4868 : interactive_statement_expression SEMICOLON { $$ = $1; }
4869 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4873 // We have to do the wrapping here and not in the case above,
4874 // because statement_expression is used for example in for_statement
4876 statement_expression
4879 ExpressionStatement s = $1 as ExpressionStatement;
4881 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4882 s = EmptyExpressionStatement.Instance;
4885 $$ = new StatementExpression (s);
4889 Error_SyntaxError (yyToken);
4894 interactive_statement_expression
4897 Expression expr = (Expression) $1;
4898 ExpressionStatement s;
4900 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4901 $$ = new StatementExpression (s);
4905 Error_SyntaxError (yyToken);
4906 $$ = new EmptyStatement (GetLocation ($1));
4916 : IF open_parens_any boolean_expression CLOSE_PARENS
4919 if ($5 is EmptyStatement)
4920 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4922 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4923 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4925 | IF open_parens_any boolean_expression CLOSE_PARENS
4926 embedded_statement ELSE embedded_statement
4928 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4929 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4931 if ($5 is EmptyStatement)
4932 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4933 if ($7 is EmptyStatement)
4934 Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
4939 : SWITCH open_parens_any
4941 if (switch_stack == null)
4942 switch_stack = new Stack<Block> (2);
4943 switch_stack.Push (current_block);
4945 expression CLOSE_PARENS
4946 OPEN_BRACE opt_switch_sections CLOSE_BRACE
4948 $$ = new Switch ((Expression) $4, (List<SwitchSection>) $7, GetLocation ($1));
4949 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6), GetLocation ($8));
4951 current_block = (Block) switch_stack.Pop ();
4958 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4959 $$ = new List<SwitchSection> ();
4967 var sections = new List<SwitchSection> (4);
4969 sections.Add ((SwitchSection) $1);
4972 | switch_sections switch_section
4974 var sections = (List<SwitchSection>) $1;
4976 sections.Add ((SwitchSection) $2);
4984 current_block = current_block.CreateSwitchBlock (lexer.Location);
4988 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block.Explicit);
4995 var labels = new List<SwitchLabel> (4);
4997 labels.Add ((SwitchLabel) $1);
5000 | switch_labels switch_label
5002 var labels = (List<SwitchLabel>) ($1);
5003 labels.Add ((SwitchLabel) $2);
5010 : CASE constant_expression COLON
5012 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5013 lbag.AddLocation ($$, GetLocation ($3));
5017 $$ = new SwitchLabel (null, GetLocation ($1));
5029 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5031 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5032 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5037 : DO embedded_statement
5038 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5040 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5041 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5046 : FOR open_parens_any opt_for_initializer SEMICOLON
5048 Location l = lexer.Location;
5050 Block assign_block = current_block;
5052 if ($3 is Tuple<FullNamedExpression, List<object>>){
5053 var de = (Tuple<FullNamedExpression, List<object>>) $3;
5055 var type = de.Item1;
5057 foreach (VariableDeclaration decl in de.Item2){
5061 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5065 Expression expr = decl.GetInitializer (type);
5067 LocalVariableReference var;
5068 var = new LocalVariableReference (assign_block, decl.identifier, l);
5071 Assign a = new SimpleAssign (var, expr, decl.Location);
5073 assign_block.AddStatement (new StatementExpression (a));
5077 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
5078 // This can be referred to as $5 below.
5084 opt_for_condition SEMICOLON
5085 opt_for_iterator CLOSE_PARENS
5088 For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, GetLocation ($1));
5089 current_block.AddStatement (f);
5091 lbag.AddStatement (f, GetLocation ($2), GetLocation ($4), GetLocation ($7), GetLocation ($9));
5093 $$ = end_block (lexer.Location);
5098 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5103 : local_variable_declaration
5104 | statement_expression_list
5108 : /* empty */ { $$ = null; }
5109 | boolean_expression
5113 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5118 : statement_expression_list
5121 statement_expression_list
5122 : statement_expression
5123 | statement_expression_list COMMA statement_expression
5125 var sl = $1 as StatementList;
5127 sl = new StatementList ((Statement) $1, (Statement) $3);
5129 sl.Add ((Statement) $3);
5131 lbag.AddStatement (sl, GetLocation ($2));
5137 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5139 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5142 | FOREACH open_parens_any type IDENTIFIER IN
5143 expression CLOSE_PARENS
5145 start_block (lexer.Location);
5146 Block foreach_block = current_block;
5148 var lt = (Tokenizer.LocatedToken) $4;
5149 Location l = lt.Location;
5150 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
5152 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
5154 // Get a writable reference to this read-only variable.
5156 // Note that the $$ here refers to the value of _this_ code block,
5157 // not the value of the LHS non-terminal. This can be referred to as $8 below.
5158 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
5166 Foreach f = new Foreach ((Expression) $3, (LocalVariableReference) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5167 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5169 current_block.AddStatement (f);
5172 $$ = end_block (lexer.Location);
5178 | continue_statement
5188 $$ = new Break (GetLocation ($1));
5189 lbag.AddStatement ($$, GetLocation ($2));
5194 : CONTINUE SEMICOLON
5196 $$ = new Continue (GetLocation ($1));
5197 lbag.AddStatement ($$, GetLocation ($2));
5202 : GOTO IDENTIFIER SEMICOLON
5204 var lt = (Tokenizer.LocatedToken) $2;
5205 $$ = new Goto (lt.Value, lt.Location);
5206 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5208 | GOTO CASE constant_expression SEMICOLON
5210 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5211 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5213 | GOTO DEFAULT SEMICOLON
5215 $$ = new GotoDefault (GetLocation ($1));
5216 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5221 : RETURN opt_expression SEMICOLON
5223 $$ = new Return ((Expression) $2, GetLocation ($1));
5224 lbag.AddStatement ($$, GetLocation ($3));
5229 : THROW opt_expression SEMICOLON
5231 $$ = new Throw ((Expression) $2, GetLocation ($1));
5232 lbag.AddStatement ($$, GetLocation ($3));
5237 : IDENTIFIER RETURN opt_expression SEMICOLON
5239 var lt = (Tokenizer.LocatedToken) $1;
5240 string s = lt.Value;
5242 Report.Error (1003, lt.Location, "; expected");
5243 } else if ($3 == null) {
5244 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5245 } else if (RootContext.Version == LanguageVersion.ISO_1){
5246 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5249 current_block.Toplevel.IsIterator = true;
5250 $$ = new Yield ((Expression) $3, lt.Location);
5251 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5253 | IDENTIFIER BREAK SEMICOLON
5255 var lt = (Tokenizer.LocatedToken) $1;
5256 string s = lt.Value;
5258 Report.Error (1003, lt.Location, "; expected");
5259 } else if (RootContext.Version == LanguageVersion.ISO_1){
5260 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5263 current_block.Toplevel.IsIterator = true;
5264 $$ = new YieldBreak (lt.Location);
5265 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5275 : TRY block catch_clauses
5277 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5279 | TRY block FINALLY block
5281 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5282 lbag.AddStatement ($$, GetLocation ($3));
5284 | TRY block catch_clauses FINALLY block
5286 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5287 lbag.AddStatement ($$, GetLocation ($4));
5291 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5299 var l = new List<Catch> (2);
5304 | catch_clauses catch_clause
5306 var l = (List<Catch>) $1;
5308 Catch c = (Catch) $2;
5309 if (l [0].IsGeneral) {
5310 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5323 : /* empty */ { $$ = null; }
5328 : CATCH opt_catch_args
5331 var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
5335 List<object> one = new List<object> (1);
5337 one.Add (new VariableDeclaration (lt, null));
5339 start_block (lexer.Location);
5340 current_block = declare_local_variables (cc.Item1, one, lt.Location);
5344 Expression type = null;
5346 Block var_block = null;
5349 var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
5355 var_block = end_block (lexer.Location);
5359 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5360 lbag.AddLocation ($$, GetLocation ($1));
5361 lbag.AppendTo ($$, lbag.GetLocations ($2));
5366 : /* empty */ { $$ = null; }
5371 : open_parens_any type opt_identifier CLOSE_PARENS
5373 $$ = new Tuple<FullNamedExpression, Tokenizer.LocatedToken> ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3);
5374 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4));
5376 | open_parens_any CLOSE_PARENS
5378 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5386 $$ = new Checked ((Block) $2, GetLocation ($1));
5393 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5400 if (!RootContext.Unsafe)
5401 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5403 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5408 : FIXED open_parens_any
5409 type_and_void fixed_pointer_declarators
5412 start_block (lexer.Location);
5416 Expression type = (Expression) $3;
5417 var list = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $4;
5418 Fixed f = new Fixed (type,
5419 list.ConvertAll (i => {
5420 var v = new KeyValuePair<LocalInfo, Expression> (current_block.AddVariable (type, i.Key.Value, i.Key.Location), i.Value);
5421 if (v.Key != null) {
5422 v.Key.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5423 v.Key.Pinned = true;
5426 }), (Statement) $7, GetLocation ($1));
5428 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5));
5430 current_block.AddStatement (f);
5432 $$ = end_block (lexer.Location);
5436 fixed_pointer_declarators
5437 : fixed_pointer_declarator {
5438 var declarators = new List<KeyValuePair<Tokenizer.LocatedToken, Expression>> (2);
5440 declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$1);
5443 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5445 var declarators = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $1;
5447 declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$3);
5452 fixed_pointer_declarator
5453 : IDENTIFIER ASSIGN expression
5455 var lt = (Tokenizer.LocatedToken) $1;
5456 $$ = new KeyValuePair<Tokenizer.LocatedToken, Expression> (lt, (Expression) $3);
5460 Report.Error (210, ((Tokenizer.LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5466 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5468 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5469 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5474 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5476 start_block (lexer.Location);
5477 Block assign_block = current_block;
5479 var de = (Tuple<FullNamedExpression, List<object>>) $3;
5480 Location l = GetLocation ($1);
5482 var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
5484 lbag.AddStatement (assign_block, GetLocation ($1), GetLocation ($2), GetLocation ($4));
5486 foreach (VariableDeclaration decl in de.Item2) {
5487 LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location);
5490 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5492 Expression expr = decl.GetInitializer (de.Item1);
5494 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5497 LocalVariableReference var;
5499 // Get a writable reference to this read-only variable.
5500 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5502 // This is so that it is not a warning on using variables
5505 vars.Push (new Tuple<LocalVariableReference, Expression> (var, expr));
5507 // Assign a = new SimpleAssign (var, expr, decl.Location);
5508 // assign_block.AddStatement (new StatementExpression (a));
5511 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5512 // It can be referred to as $5 below.
5517 Statement stmt = (Statement) $6;
5518 var vars = (Stack<Tuple<LocalVariableReference, Expression>>) $5;
5519 Location l = GetLocation ($1);
5521 while (vars.Count > 0) {
5522 var de = vars.Pop ();
5523 stmt = new Using (de.Item1, de.Item2, stmt, l);
5525 current_block.AddStatement (stmt);
5526 $$ = end_block (lexer.Location);
5528 | USING open_parens_any expression CLOSE_PARENS
5530 start_block (lexer.Location);
5534 UsingTemporary usingTemporary = new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1));
5535 lbag.AddStatement (usingTemporary, GetLocation ($2), GetLocation ($4));
5536 current_block.AddStatement (usingTemporary);
5537 $$ = end_block (lexer.Location);
5545 : first_from_clause query_body
5547 lexer.query_parsing = false;
5549 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5551 from.Tail.Next = (Linq.AQueryClause)$2;
5554 current_block.SetEndLocation (lexer.Location);
5555 current_block = current_block.Parent;
5557 | nested_from_clause query_body
5559 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5561 from.Tail.Next = (Linq.AQueryClause)$2;
5564 current_block.SetEndLocation (lexer.Location);
5565 current_block = current_block.Parent;
5568 // Bubble up COMPLETE_COMPLETION productions
5569 | first_from_clause COMPLETE_COMPLETION {
5570 lexer.query_parsing = false;
5573 current_block.SetEndLocation (lexer.Location);
5574 current_block = current_block.Parent;
5576 | nested_from_clause COMPLETE_COMPLETION {
5578 current_block.SetEndLocation (lexer.Location);
5579 current_block = current_block.Parent;
5584 : FROM_FIRST IDENTIFIER IN expression
5586 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5588 var lt = (Tokenizer.LocatedToken) $2;
5589 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
5591 | FROM_FIRST type IDENTIFIER IN expression
5593 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5595 var lt = (Tokenizer.LocatedToken) $3;
5596 $$ = new Linq.QueryExpression (
5597 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5598 IdentifierType = (FullNamedExpression)$2
5605 : FROM IDENTIFIER IN expression
5607 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5609 var lt = (Tokenizer.LocatedToken) $2;
5610 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
5612 | FROM type IDENTIFIER IN expression
5614 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5616 var lt = (Tokenizer.LocatedToken) $3;
5617 $$ = new Linq.QueryExpression (
5618 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5619 IdentifierType = (FullNamedExpression)$2
5626 : FROM IDENTIFIER IN
5628 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5632 var lt = (Tokenizer.LocatedToken) $2;
5633 var sn = new SimpleMemberName (lt.Value, lt.Location);
5634 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5636 current_block.SetEndLocation (lexer.Location);
5637 current_block = current_block.Parent;
5639 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5641 | FROM type IDENTIFIER IN
5643 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5647 var lt = (Tokenizer.LocatedToken) $3;
5648 var sn = new SimpleMemberName (lt.Value, lt.Location);
5650 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5651 IdentifierType = (FullNamedExpression)$2
5654 current_block.SetEndLocation (lexer.Location);
5655 current_block = current_block.Parent;
5657 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5662 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5664 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5667 head.Next = (Linq.AQueryClause)$3;
5670 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5671 clause.Tail.Next = head;
5677 | opt_query_body_clauses COMPLETE_COMPLETION
5680 select_or_group_clause
5683 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5687 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5689 current_block.SetEndLocation (lexer.Location);
5690 current_block = current_block.Parent;
5694 if (linq_clause_blocks == null)
5695 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5697 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5698 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5702 current_block.SetEndLocation (lexer.Location);
5703 current_block = current_block.Parent;
5705 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5709 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5711 current_block.SetEndLocation (lexer.Location);
5712 current_block = current_block.Parent;
5716 opt_query_body_clauses
5718 | query_body_clauses
5723 | query_body_clauses query_body_clause
5725 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5739 : LET IDENTIFIER ASSIGN
5741 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5745 var lt = (Tokenizer.LocatedToken) $2;
5746 var sn = new SimpleMemberName (lt.Value, lt.Location);
5747 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5749 current_block.SetEndLocation (lexer.Location);
5750 current_block = current_block.Parent;
5752 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5759 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5763 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
5765 current_block.SetEndLocation (lexer.Location);
5766 current_block = current_block.Parent;
5771 : JOIN IDENTIFIER IN
5773 if (linq_clause_blocks == null)
5774 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5776 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5777 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5781 current_block.SetEndLocation (lexer.Location);
5782 current_block = current_block.Parent;
5784 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5785 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5789 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5790 current_block.SetEndLocation (lexer.Location);
5791 current_block = current_block.Parent;
5793 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5795 expression opt_join_into
5797 var lt = (Tokenizer.LocatedToken) $2;
5798 var sn = new SimpleMemberName (lt.Value, lt.Location);
5799 SimpleMemberName sn2 = null;
5801 var outer_selector = linq_clause_blocks.Pop ();
5802 var block = linq_clause_blocks.Pop ();
5805 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5807 var lt2 = (Tokenizer.LocatedToken) $12;
5808 sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
5809 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block,
5810 sn2, GetLocation ($1));
5813 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5814 current_block.SetEndLocation (lexer.Location);
5815 current_block = current_block.Parent;
5817 ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
5819 | JOIN type IDENTIFIER IN
5821 if (linq_clause_blocks == null)
5822 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5824 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5825 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5829 current_block.SetEndLocation (lexer.Location);
5830 current_block = current_block.Parent;
5832 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5833 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5837 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5838 current_block.SetEndLocation (lexer.Location);
5839 current_block = current_block.Parent;
5841 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5843 expression opt_join_into
5845 var lt = (Tokenizer.LocatedToken) $3;
5846 var sn = new SimpleMemberName (lt.Value, lt.Location);
5847 SimpleMemberName sn2 = null;
5848 var outer_selector = linq_clause_blocks.Pop ();
5849 var block = linq_clause_blocks.Pop ();
5852 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5853 IdentifierType = (FullNamedExpression)$2
5856 var lt2 = (Tokenizer.LocatedToken) $13;
5857 sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
5858 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, sn2, GetLocation ($1)) {
5859 IdentifierType = (FullNamedExpression)$2
5863 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5864 current_block.SetEndLocation (lexer.Location);
5865 current_block = current_block.Parent;
5867 ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
5882 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5886 current_block.SetEndLocation (lexer.Location);
5887 current_block = current_block.Parent;
5897 current_block.SetEndLocation (lexer.Location);
5898 current_block = current_block.Parent;
5900 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5904 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5911 | orderings_then_by COMMA
5913 current_block.SetEndLocation (lexer.Location);
5914 current_block = current_block.Parent;
5916 current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
5920 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5928 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5930 | expression ASCENDING
5932 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5934 | expression DESCENDING
5936 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5943 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5945 | expression ASCENDING
5947 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5949 | expression DESCENDING
5951 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5956 opt_query_continuation
5960 // query continuation block is not linked with query block but with block
5961 // before. This means each query can use same range variable names for
5962 // different identifiers.
5964 current_block.SetEndLocation (GetLocation ($1));
5965 current_block = current_block.Parent;
5967 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5969 if (linq_clause_blocks == null)
5970 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5972 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5976 var current_block = linq_clause_blocks.Pop ();
5977 var lt = (Tokenizer.LocatedToken) $2;
5978 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5979 next = (Linq.AQueryClause)$4
5985 // Support for using the compiler as an interactive parser
5987 // The INTERACTIVE_PARSER token is first sent to parse our
5988 // productions; If the result is a Statement, the parsing
5989 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5990 // to setup the blocks in advance.
5992 // This setup is here so that in the future we can add
5993 // support for other constructs (type parsing, namespaces, etc)
5994 // that do not require a block to be setup in advance
5998 : EVAL_STATEMENT_PARSER EOF
5999 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
6000 | EVAL_STATEMENT_PARSER {
6001 Evaluator.LoadAliases (current_namespace);
6003 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
6004 Modifiers.PUBLIC, null), null);
6006 var baseclass_list = new List<FullNamedExpression> ();
6007 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
6008 current_container.AddBasesForPart (current_class, baseclass_list);
6010 // (ref object retval)
6011 Parameter [] mpar = new Parameter [1];
6012 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6014 ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
6015 current_local_parameters = pars;
6016 Method method = new Method (
6019 new TypeExpression (TypeManager.void_type, Location.Null),
6020 Modifiers.PUBLIC | Modifiers.STATIC,
6021 new MemberName ("Host"),
6023 null /* attributes */);
6025 oob_stack.Push (method);
6026 ++lexer.parsing_block;
6027 start_block (lexer.Location);
6029 interactive_statement_list opt_COMPLETE_COMPLETION
6031 --lexer.parsing_block;
6032 Method method = (Method) oob_stack.Pop ();
6034 method.Block = (ToplevelBlock) end_block(lexer.Location);
6035 current_container.AddMethod (method);
6037 --lexer.parsing_declaration;
6038 InteractiveResult = pop_current_class ();
6039 current_local_parameters = null;
6041 | EVAL_COMPILATION_UNIT_PARSER {
6042 Evaluator.LoadAliases (current_namespace);
6044 interactive_compilation_unit
6047 interactive_compilation_unit
6048 : outer_declarations
6049 | outer_declarations global_attributes
6054 opt_COMPLETE_COMPLETION
6056 | COMPLETE_COMPLETION
6059 close_brace_or_complete_completion
6061 | COMPLETE_COMPLETION
6066 // A class used to pass around variable declarations and constants
6068 class VariableDeclaration {
6069 public string identifier;
6070 Expression initializer;
6071 public Location Location;
6073 public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
6075 this.identifier = lt.Value;
6076 this.initializer = initializer;
6077 this.Location = lt.Location;
6080 public Expression GetInitializer (FullNamedExpression type)
6082 if (initializer is ArrayInitializer)
6083 return new ArrayCreation (type, (ArrayInitializer)initializer);
6088 public bool HasInitializer {
6089 get { return initializer != null; }
6095 // A class used to hold info about an operator declarator
6097 struct OperatorDeclaration {
6098 public readonly Operator.OpType optype;
6099 public readonly FullNamedExpression ret_type;
6100 public readonly Location location;
6102 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6105 this.ret_type = ret_type;
6106 this.location = location;
6110 void Error_ExpectingTypeName (Expression expr)
6112 if (expr is Invocation){
6113 Report.Error (1002, expr.Location, "Expecting `;'");
6115 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
6119 void Error_ParameterModifierNotValid (string modifier, Location loc)
6121 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6125 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6127 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6128 Parameter.GetModifierSignature (mod));
6131 void Error_TypeExpected (Location loc)
6133 Report.Error (1031, loc, "Type expected");
6136 void Error_UnsafeCodeNotAllowed (Location loc)
6138 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6141 void Error_NamedArgumentExpected (NamedArgument a)
6143 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6146 void push_current_class (TypeContainer tc, object partial_token)
6148 if (RootContext.EvalMode){
6149 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
6150 undo.AddTypeContainer (current_container, tc);
6153 if (partial_token != null)
6154 current_container = current_container.AddPartial (tc);
6156 current_container = current_container.AddTypeContainer (tc);
6158 ++lexer.parsing_declaration;
6162 DeclSpace pop_current_class ()
6164 DeclSpace retval = current_class;
6166 current_class = current_class.Parent;
6167 current_container = current_class.PartialContainer;
6173 // Given the @class_name name, it creates a fully qualified name
6174 // based on the containing declaration space
6177 MakeName (MemberName class_name)
6179 Namespace ns = current_namespace.NS;
6181 if (current_container == RootContext.ToplevelTypes) {
6182 if (ns.Name.Length != 0)
6183 return new MemberName (ns.MemberName, class_name);
6187 return new MemberName (current_container.MemberName, class_name);
6191 [System.Diagnostics.Conditional ("FULL_AST")]
6192 void StoreModifierLocation (object token, Location loc)
6197 if (mod_locations == null)
6198 mod_locations = new List<Tuple<Modifiers, Location>> ();
6200 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6203 Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
6205 Block implicit_block;
6208 // If we are doing interactive editing, we want variable declarations
6209 // that are in the top block to be added instead to the class as
6212 if (RootContext.StatementMode){
6215 for (Block b = current_block; b != null; b = b.Parent){
6216 if (b is ExplicitBlock && !(b is ToplevelBlock)){
6217 // There has been an explicit block, we cant add to the class
6224 // We can use "current_block" since we know there are no explicit blocks
6226 foreach (VariableDeclaration decl in variable_declarators){
6227 // We can not use the super-handy f.Initializer, because
6228 // multiple lines would force code to be executed out of sync
6229 var init = decl.GetInitializer (type);
6231 string id = "$" + decl.identifier;
6232 LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
6234 // Avoid warning about this variable not being used.
6237 LocalVariableReference var;
6238 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
6239 Assign assign = new SimpleAssign (var, init, decl.Location);
6240 current_block.AddStatement (new StatementExpression (assign));
6241 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
6242 current_block.AddStatement (new StatementExpression (assign));
6244 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
6245 new MemberName (decl.identifier, loc), null);
6246 current_container.AddField (f);
6248 // Register the field to be visible later as a global variable
6249 Evaluator.QueueField (f);
6253 return current_block;
6258 // We use the `Used' property to check whether statements
6259 // have been added to the current block. If so, we need
6260 // to create another block to contain the new declaration
6261 // otherwise, as an optimization, we use the same block to
6262 // add the declaration.
6264 // FIXME: A further optimization is to check if the statements
6265 // that were added were added as part of the initialization
6266 // below. In which case, no other statements have been executed
6267 // and we might be able to reduce the number of blocks for
6268 // situations like this:
6270 // int j = 1; int k = j + 1;
6272 if (current_block.Used)
6273 implicit_block = new Block (current_block, loc, lexer.Location);
6275 implicit_block = current_block;
6277 foreach (VariableDeclaration decl in variable_declarators){
6279 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6280 if (decl.HasInitializer){
6283 var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
6285 assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
6287 implicit_block.AddStatement (new StatementExpression (assign));
6292 return implicit_block;
6295 Block declare_local_constants (FullNamedExpression type, List<object> declarators)
6297 Block implicit_block;
6299 if (current_block.Used)
6300 implicit_block = new Block (current_block);
6302 implicit_block = current_block;
6304 foreach (VariableDeclaration decl in declarators){
6305 implicit_block.AddConstant (type, decl.identifier, decl.GetInitializer (type), decl.Location);
6308 return implicit_block;
6311 string CheckAttributeTarget (string a, Location l)
6314 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6318 Report.Warning (658, 1, l,
6319 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6320 return string.Empty;
6323 static bool IsUnaryOperator (Operator.OpType op)
6327 case Operator.OpType.LogicalNot:
6328 case Operator.OpType.OnesComplement:
6329 case Operator.OpType.Increment:
6330 case Operator.OpType.Decrement:
6331 case Operator.OpType.True:
6332 case Operator.OpType.False:
6333 case Operator.OpType.UnaryPlus:
6334 case Operator.OpType.UnaryNegation:
6340 void syntax_error (Location l, string msg)
6342 Report.Error (1003, l, "Syntax error, " + msg);
6347 public Tokenizer Lexer {
6353 static CSharpParser ()
6355 oob_stack = new Stack<object> ();
6358 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
6360 if (RootContext.EvalMode)
6364 this.compiler = ctx;
6365 current_namespace = new NamespaceEntry (null, file, null);
6366 current_class = current_namespace.SlaveDeclSpace;
6367 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6369 lexer = new Tokenizer (reader, file, ctx);
6371 use_global_stacks = true;
6374 public void parse ()
6376 eof_token = Token.EOF;
6377 Tokenizer.LocatedToken.Initialize ();
6380 if (yacc_verbose_flag > 1)
6381 yyparse (lexer, new yydebug.yyDebugSimple ());
6385 Tokenizer tokenizer = lexer as Tokenizer;
6386 tokenizer.cleanup ();
6387 } catch (Exception e){
6388 if (e is yyParser.yyUnexpectedEof)
6389 UnexpectedEOF = true;
6391 if (e is yyParser.yyException)
6392 Report.Error (-25, lexer.Location, "Parsing error");
6393 else if (yacc_verbose_flag > 0)
6394 throw; // Used by compiler-tester to test internal errors
6396 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6399 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6400 throw new InternalErrorException ("who set it?");
6403 void CheckToken (int error, int yyToken, string msg, Location loc)
6405 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6406 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6408 Report.Error (error, loc, msg);
6411 void CheckIdentifierToken (int yyToken, Location loc)
6413 CheckToken (1041, yyToken, "Identifier expected", loc);
6416 string ConsumeStoredComment ()
6418 string s = tmpComment;
6420 Lexer.doc_state = XmlCommentState.Allowed;
6424 Location GetLocation (object obj)
6426 if (obj is Tokenizer.LocatedToken)
6427 return ((Tokenizer.LocatedToken) obj).Location;
6428 if (obj is MemberName)
6429 return ((MemberName) obj).Location;
6431 if (obj is Expression)
6432 return ((Expression) obj).Location;
6434 return lexer.Location;
6438 get { return compiler.Report; }
6441 public LocationsBag LocationsBag {
6450 void start_block (Location loc)
6452 if (current_block == null || parsing_anonymous_method) {
6453 current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, loc);
6454 parsing_anonymous_method = false;
6456 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6461 end_block (Location loc)
6463 Block retval = current_block.Explicit;
6464 retval.SetEndLocation (loc);
6465 current_block = retval.Parent;
6470 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6472 if (RootContext.Version == LanguageVersion.ISO_1){
6473 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6476 oob_stack.Push (current_anonymous_method);
6477 oob_stack.Push (current_local_parameters);
6479 current_local_parameters = parameters;
6481 current_anonymous_method = lambda
6482 ? new LambdaExpression (loc)
6483 : new AnonymousMethodExpression (loc);
6485 // Force the next block to be created as a ToplevelBlock
6486 parsing_anonymous_method = true;
6490 * Completes the anonymous method processing, if lambda_expr is null, this
6491 * means that we have a Statement instead of an Expression embedded
6493 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6495 AnonymousMethodExpression retval;
6497 current_anonymous_method.Block = anon_block;
6498 retval = current_anonymous_method;
6500 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6501 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6506 public NamespaceEntry CurrentNamespace {
6508 return current_namespace;
6513 void Error_SyntaxError (int token)
6515 Error_SyntaxError (0, token, "Unexpected symbol");
6518 void Error_SyntaxError (int error_code, int token, string msg)
6520 string symbol = GetSymbolName (token);
6521 string expecting = GetExpecting ();
6523 if (error_code == 0) {
6524 if (expecting == "`)'")
6530 if (string.IsNullOrEmpty (expecting))
6531 Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
6533 Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6536 string GetExpecting ()
6538 int [] tokens = yyExpectingTokens (yyExpectingState);
6539 var names = new List<string> (tokens.Length);
6540 bool has_type = false;
6541 bool has_identifier = false;
6542 for (int i = 0; i < tokens.Length; i++){
6543 int token = tokens [i];
6544 has_identifier |= token == Token.IDENTIFIER;
6546 string name = GetTokenName (token);
6547 if (name == "<internal>")
6550 has_type |= name == "type";
6551 if (names.Contains (name))
6558 // Too many tokens to enumerate
6560 if (names.Count > 8)
6563 if (has_type && has_identifier)
6564 names.Remove ("identifier");
6566 if (names.Count == 1)
6567 return "`" + GetTokenName (tokens [0]) + "'";
6569 StringBuilder sb = new StringBuilder ();
6571 int count = names.Count;
6572 for (int i = 0; i < count; i++){
6573 bool last = i + 1 == count;
6577 sb.Append (names [i]);
6578 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6580 return sb.ToString ();
6584 string GetSymbolName (int token)
6588 return ((Constant)lexer.Value).GetValue ().ToString ();
6589 case Token.IDENTIFIER:
6590 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6632 case Token.BITWISE_AND:
6634 case Token.BITWISE_OR:
6648 case Token.OP_SHIFT_LEFT:
6650 case Token.OP_SHIFT_RIGHT:
6670 case Token.OP_COALESCING:
6672 case Token.OP_MULT_ASSIGN:
6674 case Token.OP_DIV_ASSIGN:
6676 case Token.OP_MOD_ASSIGN:
6678 case Token.OP_ADD_ASSIGN:
6680 case Token.OP_SUB_ASSIGN:
6682 case Token.OP_SHIFT_LEFT_ASSIGN:
6684 case Token.OP_SHIFT_RIGHT_ASSIGN:
6686 case Token.OP_AND_ASSIGN:
6688 case Token.OP_XOR_ASSIGN:
6690 case Token.OP_OR_ASSIGN:
6694 return GetTokenName (token);
6697 static string GetTokenName (int token)
6700 case Token.ABSTRACT:
6720 case Token.CONTINUE:
6724 case Token.DELEGATE:
6734 case Token.EXPLICIT:
6752 case Token.IMPLICIT:
6756 case Token.INTERFACE:
6758 case Token.INTERNAL:
6764 case Token.NAMESPACE:
6770 case Token.OPERATOR:
6774 case Token.OVERRIDE:
6780 case Token.PROTECTED:
6784 case Token.READONLY:
6796 case Token.STACKALLOC:
6797 return "stackalloc";
6814 case Token.UNCHECKED:
6822 case Token.VOLATILE:
6835 case Token.FROM_FIRST:
6853 case Token.ASCENDING:
6855 case Token.DESCENDING:
6856 return "descending";
6863 case Token.OPEN_BRACE:
6865 case Token.CLOSE_BRACE:
6867 case Token.OPEN_BRACKET:
6868 case Token.OPEN_BRACKET_EXPR:
6870 case Token.CLOSE_BRACKET:
6872 case Token.OPEN_PARENS_CAST:
6873 case Token.OPEN_PARENS_LAMBDA:
6874 case Token.OPEN_PARENS:
6876 case Token.CLOSE_PARENS:
6882 case Token.DEFAULT_COLON:
6886 case Token.SEMICOLON:
6897 case Token.BITWISE_AND:
6898 case Token.BITWISE_OR:
6905 case Token.OP_SHIFT_LEFT:
6906 case Token.OP_SHIFT_RIGHT:
6914 case Token.OP_COALESCING:
6915 case Token.OP_MULT_ASSIGN:
6916 case Token.OP_DIV_ASSIGN:
6917 case Token.OP_MOD_ASSIGN:
6918 case Token.OP_ADD_ASSIGN:
6919 case Token.OP_SUB_ASSIGN:
6920 case Token.OP_SHIFT_LEFT_ASSIGN:
6921 case Token.OP_SHIFT_RIGHT_ASSIGN:
6922 case Token.OP_AND_ASSIGN:
6923 case Token.OP_XOR_ASSIGN:
6924 case Token.OP_OR_ASSIGN:
6925 return "<operator>";
6947 case Token.OP_GENERICS_LT:
6948 case Token.GENERIC_DIMENSION:
6950 case Token.OP_GENERICS_GT:
6953 case Token.INTERR_NULLABLE:
6955 case Token.DOUBLE_COLON:
6959 case Token.IDENTIFIER:
6960 return "identifier";
6962 // All of these are internal.
6965 case Token.FIRST_KEYWORD:
6967 case Token.EVAL_COMPILATION_UNIT_PARSER:
6968 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6969 case Token.EVAL_STATEMENT_PARSER:
6970 case Token.LAST_KEYWORD:
6971 case Token.GENERATE_COMPLETION:
6972 case Token.COMPLETE_COMPLETION:
6973 return "<internal>";
6975 // A bit more robust.
6977 return yyNames [token];