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 NamespaceContainer 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 BlockVariableDeclaration current_variable;
63 Delegate current_delegate;
65 AnonymousMethodExpression current_anonymous_method;
68 /// This is used by the unary_expression code to resolve
69 /// a name against a parameter.
72 // FIXME: This is very ugly and it's very hard to reset it correctly
73 // on all places, especially when some parameters are autogenerated.
74 ParametersCompiled current_local_parameters;
76 bool parsing_anonymous_method;
79 /// An out-of-band stack.
81 static Stack<object> oob_stack;
84 /// Controls the verbosity of the errors produced by the parser
86 static public int yacc_verbose_flag;
89 /// Used by the interactive shell, flags whether EOF was reached
90 /// and an error was produced
92 public bool UnexpectedEOF;
97 readonly CompilationSourceFile file;
100 /// Temporary Xml documentation cache.
101 /// For enum types, we need one more temporary store.
104 string enumTypeComment;
106 /// Current attribute target
107 string current_attr_target;
109 ParameterModifierType valid_param_mod;
111 bool default_parameter_used;
113 /// When using the interactive parser, this holds the
114 /// resulting expression
115 public Class InteractiveResult;
118 // Keeps track of global data changes to undo on parser error
122 Stack<Linq.QueryBlock> linq_clause_blocks;
124 ModuleContainer module;
126 readonly CompilerContext compiler;
127 readonly LanguageVersion lang_version;
128 readonly bool doc_support;
129 readonly CompilerSettings settings;
130 readonly Report report;
133 // Instead of allocating carrier array everytime we
134 // share the bucket for very common constructs which can never
137 static List<Parameter> parameters_bucket = new List<Parameter> (6);
140 // Full AST support members
143 List<Tuple<Modifiers, Location>> mod_locations;
147 %token NONE /* This token is never returned by our lexer */
148 %token ERROR // This is used not by the parser, but by the tokenizer.
152 *These are the C# keywords
251 %token INTERR_NULLABLE
259 /* C# keywords which are not really keywords */
265 /* C# single character operators/punctuation. */
293 /* C# multi-character operators. */
298 %token OP_SHIFT_RIGHT
305 %token OP_MULT_ASSIGN
310 %token OP_SHIFT_LEFT_ASSIGN
311 %token OP_SHIFT_RIGHT_ASSIGN
318 /* Generics <,> tokens */
319 %token OP_GENERICS_LT
320 %token OP_GENERICS_LT_DECL
321 %token OP_GENERICS_GT
326 %token OPEN_PARENS_LAMBDA
327 %token OPEN_PARENS_CAST
328 %token GENERIC_DIMENSION
330 %token OPEN_BRACKET_EXPR
332 // Make the parser go into eval mode parsing (statements and compilation units).
333 %token EVAL_STATEMENT_PARSER
334 %token EVAL_COMPILATION_UNIT_PARSER
335 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
340 // This token is generated to trigger the completion engine at this point
342 %token GENERATE_COMPLETION
345 // This token is return repeatedly after the first GENERATE_COMPLETION
346 // token is produced and before the final EOF
348 %token COMPLETE_COMPLETION
350 /* Add precedence rules to solve dangling else s/r conflict */
354 /* Define the operator tokens and their precedences */
362 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
364 %left STAR DIV PERCENT
365 %right BANG CARRET UMINUS
366 %nonassoc OP_INC OP_DEC
368 %left OPEN_BRACKET OPEN_BRACE
371 %start compilation_unit
375 : outer_declaration opt_EOF
377 Lexer.check_incorrect_doc_comment ();
379 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
380 | documentation_parsing
384 : opt_extern_alias_directives opt_using_directives
385 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
388 Attributes attrs = (Attributes) $4;
389 report.Error (1730, attrs.Attrs [0].Location,
390 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
393 | opt_extern_alias_directives opt_using_directives attribute_sections
395 module.AddAttributes ((Attributes) $3, current_namespace);
399 if (yyToken == Token.EXTERN_ALIAS)
400 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
402 Error_SyntaxError (yyToken);
411 extern_alias_directives
412 : extern_alias_directive
413 | extern_alias_directives extern_alias_directive
416 extern_alias_directive
417 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
419 var lt = (Tokenizer.LocatedToken) $2;
422 syntax_error (lt.Location, "`alias' expected");
423 } else if (lang_version == LanguageVersion.ISO_1) {
424 FeatureIsNotAvailable (lt.Location, "external alias");
426 lt = (Tokenizer.LocatedToken) $3;
427 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, report);
432 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
438 | using_directives using_directive
442 : using_alias_directive
445 Lexer.doc_state = XmlCommentState.Allowed;
447 | using_namespace_directive
450 Lexer.doc_state = XmlCommentState.Allowed;
454 using_alias_directive
455 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
457 var lt = (Tokenizer.LocatedToken) $2;
458 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
459 report.Warning (440, 2, lt.Location,
460 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
463 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
467 Error_SyntaxError (yyToken);
472 using_namespace_directive
473 : USING namespace_name SEMICOLON
475 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
480 // Strictly speaking, namespaces don't have attributes but
481 // we parse global attributes along with namespace declarations and then
484 namespace_declaration
485 : opt_attributes NAMESPACE qualified_identifier
487 Attributes attrs = (Attributes) $1;
488 MemberName name = (MemberName) $3;
490 bool valid_global_attrs = true;
491 if ((current_namespace.DeclarationFound || current_namespace != file.NamespaceContainer)) {
492 valid_global_attrs = false;
494 foreach (var a in attrs.Attrs) {
495 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
498 valid_global_attrs = false;
503 if (!valid_global_attrs)
504 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
507 module.AddAttributes (attrs, current_namespace);
509 current_namespace = new NamespaceContainer (name, module, current_namespace, file);
510 module.AddTypesContainer (current_namespace);
511 current_class = current_namespace.SlaveDeclSpace;
512 current_container = current_class.PartialContainer;
517 Lexer.doc_state = XmlCommentState.Allowed;
519 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon
522 lbag.AddLocation (current_namespace, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
524 lbag.AddLocation (current_namespace, GetLocation ($2), GetLocation ($5), GetLocation ($10));
526 current_namespace = current_namespace.Parent;
527 current_class = current_namespace.SlaveDeclSpace;
528 current_container = current_class.PartialContainer;
535 var lt = (Tokenizer.LocatedToken) $1;
536 $$ = new MemberName (lt.Value, lt.Location);
538 | qualified_identifier DOT IDENTIFIER
540 var lt = (Tokenizer.LocatedToken) $3;
541 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
545 Error_SyntaxError (yyToken);
546 $$ = new MemberName ("<invalid>", lexer.Location);
561 : namespace_or_type_name
563 MemberName name = (MemberName) $1;
565 if (name.TypeArguments != null)
566 syntax_error (lexer.Location, "namespace name expected");
577 opt_extern_alias_directives
579 | extern_alias_directives
582 opt_namespace_or_type_declarations
584 | namespace_or_type_declarations
587 namespace_or_type_declarations
588 : namespace_or_type_declaration
589 | namespace_or_type_declarations namespace_or_type_declaration
592 namespace_or_type_declaration
596 TypeContainer ds = (TypeContainer)$1;
598 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
599 report.Error (1527, ds.Location,
600 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
603 // Here is a trick, for explicit attributes we don't know where they belong to until
604 // we parse succeeding declaration hence we parse them as normal and re-attach them
605 // when we know whether they are global (assembly:, module:) or local (type:).
606 if (ds.OptAttributes != null) {
607 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file.NamespaceContainer);
610 current_namespace.DeclarationFound = true;
612 | namespace_declaration
614 current_namespace.DeclarationFound = true;
621 | interface_declaration
623 | delegate_declaration
625 // Enable this when we have handled all errors, because this acts as a generic fallback
628 // Console.WriteLine ("Token=" + yyToken);
629 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
645 var sect = (List<Attribute>) $1;
646 $$ = new Attributes (sect);
648 | attribute_sections attribute_section
650 Attributes attrs = $1 as Attributes;
651 var sect = (List<Attribute>) $2;
653 attrs = new Attributes (sect);
655 attrs.AddAttributes (sect);
663 lexer.parsing_attribute_section = true;
665 attribute_section_cont
667 lexer.parsing_attribute_section = false;
672 attribute_section_cont
673 : attribute_target COLON
675 current_attr_target = (string) $1;
676 if (current_attr_target == "assembly" || current_attr_target == "module") {
677 Lexer.check_incorrect_doc_comment ();
680 attribute_list opt_comma CLOSE_BRACKET
682 // when attribute target is invalid
683 if (current_attr_target == string.Empty)
684 $$ = new List<Attribute> (0);
688 current_attr_target = null;
689 lexer.parsing_attribute_section = false;
691 | attribute_list opt_comma CLOSE_BRACKET
700 var lt = (Tokenizer.LocatedToken) $1;
701 $$ = CheckAttributeTarget (lt.Value, lt.Location);
703 | EVENT { $$ = "event"; }
704 | RETURN { $$ = "return"; }
707 if (yyToken == Token.IDENTIFIER) {
708 Error_SyntaxError (yyToken);
711 string name = GetTokenName (yyToken);
712 $$ = CheckAttributeTarget (name, GetLocation ($1));
720 $$ = new List<Attribute> (4) { (Attribute) $1 };
722 | attribute_list COMMA attribute
724 var attrs = (List<Attribute>) $1;
725 attrs.Add ((Attribute) $3);
734 ++lexer.parsing_block;
736 opt_attribute_arguments
738 --lexer.parsing_block;
739 MemberName mname = (MemberName) $1;
740 if (mname.IsGeneric) {
741 report.Error (404, lexer.Location,
742 "'<' unexpected: attributes cannot be generic");
745 Arguments [] arguments = (Arguments []) $3;
746 ATypeNameExpression expr = mname.GetTypeExpression ();
747 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
752 : namespace_or_type_name
755 opt_attribute_arguments
756 : /* empty */ { $$ = null; }
757 | OPEN_PARENS attribute_arguments CLOSE_PARENS
765 : /* empty */ { $$ = null; }
766 | positional_or_named_argument
768 Arguments a = new Arguments (4);
769 a.Add ((Argument) $1);
770 $$ = new Arguments [] { a, null };
772 | named_attribute_argument
774 Arguments a = new Arguments (4);
775 a.Add ((Argument) $1);
776 $$ = new Arguments [] { null, a };
778 | attribute_arguments COMMA positional_or_named_argument
780 Arguments[] o = (Arguments[]) $1;
782 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
783 o [0] = new Arguments (4);
786 Arguments args = ((Arguments) o [0]);
787 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
788 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
790 args.Add ((Argument) $3);
792 | attribute_arguments COMMA named_attribute_argument
794 Arguments[] o = (Arguments[]) $1;
796 o [1] = new Arguments (4);
799 ((Arguments) o [1]).Add ((Argument) $3);
803 positional_or_named_argument
806 $$ = new Argument ((Expression) $1);
811 named_attribute_argument
814 ++lexer.parsing_block;
818 --lexer.parsing_block;
819 var lt = (Tokenizer.LocatedToken) $1;
820 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
825 : IDENTIFIER COLON opt_named_modifier expression
827 if (lang_version <= LanguageVersion.V_3)
828 FeatureIsNotAvailable (GetLocation ($1), "named argument");
830 // Avoid boxing in common case (no modifier)
831 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
833 var lt = (Tokenizer.LocatedToken) $1;
834 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
839 : /* empty */ { $$ = null; }
842 $$ = Argument.AType.Ref;
846 $$ = Argument.AType.Out;
850 opt_class_member_declarations
852 | class_member_declarations
855 class_member_declarations
856 : class_member_declaration
857 | class_member_declarations
858 class_member_declaration
861 class_member_declaration
862 : constant_declaration
865 | property_declaration
867 | indexer_declaration
868 | operator_declaration
869 | constructor_declaration
870 | destructor_declaration
874 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
875 GetSymbolName (yyToken));
877 lexer.parsing_generic_declaration = false;
887 lexer.ConstraintsParsing = true;
889 type_declaration_name
891 MemberName name = MakeName ((MemberName) $6);
892 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
895 opt_type_parameter_constraints_clauses
897 lexer.ConstraintsParsing = false;
899 current_class.SetParameterInfo ((List<Constraints>) $9);
902 current_container.DocComment = Lexer.consume_doc_comment ();
904 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
908 --lexer.parsing_declaration;
910 Lexer.doc_state = XmlCommentState.Allowed;
914 lbag.AppendToMember (current_class, GetLocation ($13));
915 $$ = pop_current_class ();
917 | opt_attributes opt_modifiers opt_partial STRUCT error
919 Error_SyntaxError (yyToken);
927 Lexer.doc_state = XmlCommentState.Allowed;
929 opt_struct_member_declarations CLOSE_BRACE
931 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
935 opt_struct_member_declarations
937 | struct_member_declarations
940 struct_member_declarations
941 : struct_member_declaration
942 | struct_member_declarations struct_member_declaration
945 struct_member_declaration
946 : constant_declaration
949 | property_declaration
951 | indexer_declaration
952 | operator_declaration
953 | constructor_declaration
957 * This is only included so we can flag error 575:
958 * destructors only allowed on class types
960 | destructor_declaration
966 CONST type IDENTIFIER
968 var lt = (Tokenizer.LocatedToken) $5;
969 var mod = (Modifiers) $2;
970 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
971 current_container.AddConstant ((Const) current_field);
973 if ((mod & Modifiers.STATIC) != 0) {
974 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
979 constant_initializer opt_constant_declarators SEMICOLON
982 current_field.DocComment = Lexer.consume_doc_comment ();
983 Lexer.doc_state = XmlCommentState.Allowed;
986 current_field.Initializer = (ConstInitializer) $7;
987 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
988 current_field = null;
992 opt_constant_declarators
994 | constant_declarators
998 : constant_declarator
1000 current_field.AddDeclarator ((FieldDeclarator) $1);
1002 | constant_declarators constant_declarator
1004 current_field.AddDeclarator ((FieldDeclarator) $2);
1009 : COMMA IDENTIFIER constant_initializer
1011 var lt = (Tokenizer.LocatedToken) $2;
1012 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1013 lbag.AddLocation ($$, GetLocation ($1));
1017 constant_initializer
1020 ++lexer.parsing_block;
1022 constant_initializer_expr
1024 --lexer.parsing_block;
1025 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1029 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1034 constant_initializer_expr
1035 : constant_expression
1042 member_type IDENTIFIER
1044 lexer.parsing_generic_declaration = false;
1046 FullNamedExpression type = (FullNamedExpression) $3;
1047 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1048 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1050 var lt = (Tokenizer.LocatedToken) $4;
1051 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1052 current_container.AddField (current_field);
1055 opt_field_initializer
1056 opt_field_declarators
1060 current_field.DocComment = Lexer.consume_doc_comment ();
1061 Lexer.doc_state = XmlCommentState.Allowed;
1064 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1066 current_field = null;
1070 FIXED simple_type IDENTIFIER
1072 if (lang_version < LanguageVersion.ISO_2)
1073 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1075 var lt = (Tokenizer.LocatedToken) $5;
1076 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1077 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1079 current_container.AddField (current_field);
1081 fixed_field_size opt_fixed_field_declarators SEMICOLON
1084 current_field.DocComment = Lexer.consume_doc_comment ();
1085 Lexer.doc_state = XmlCommentState.Allowed;
1088 current_field.Initializer = (ConstInitializer) $7;
1089 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1091 current_field = null;
1095 FIXED simple_type error
1098 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1102 opt_field_initializer
1106 ++lexer.parsing_block;
1107 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1108 start_block (GetLocation ($1));
1110 variable_initializer
1112 --lexer.parsing_block;
1113 current_field.Initializer = (Expression) $3;
1114 end_block (lexer.Location);
1115 current_local_parameters = null;
1119 opt_field_declarators
1127 current_field.AddDeclarator ((FieldDeclarator) $1);
1129 | field_declarators field_declarator
1131 current_field.AddDeclarator ((FieldDeclarator) $2);
1138 var lt = (Tokenizer.LocatedToken) $2;
1139 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1140 lbag.AddLocation ($$, GetLocation ($1));
1142 | COMMA IDENTIFIER ASSIGN
1144 ++lexer.parsing_block;
1146 variable_initializer
1148 --lexer.parsing_block;
1149 var lt = (Tokenizer.LocatedToken) $2;
1150 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1151 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1155 opt_fixed_field_declarators
1157 | fixed_field_declarators
1160 fixed_field_declarators
1161 : fixed_field_declarator
1163 current_field.AddDeclarator ((FieldDeclarator) $1);
1165 | fixed_field_declarators fixed_field_declarator
1167 current_field.AddDeclarator ((FieldDeclarator) $2);
1171 fixed_field_declarator
1172 : COMMA IDENTIFIER fixed_field_size
1174 var lt = (Tokenizer.LocatedToken) $2;
1175 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1176 lbag.AddLocation ($$, GetLocation ($1));
1183 ++lexer.parsing_block;
1185 expression CLOSE_BRACKET
1187 --lexer.parsing_block;
1188 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1189 lbag.AddLocation ($$, GetLocation ($4));
1191 | OPEN_BRACKET error
1193 report.Error (443, lexer.Location, "Value or constant expected");
1198 variable_initializer
1203 // It has to be here for the parent to safely restore artificial block
1204 Error_SyntaxError (yyToken);
1213 Lexer.doc_state = XmlCommentState.NotAllowed;
1215 // Add it early in the case of body being eof for full aot
1216 current_container.AddMethod ((Method) $1);
1220 Method method = (Method) $1;
1221 method.Block = (ToplevelBlock) $3;
1223 if (method.Block == null) {
1224 method.ParameterInfo.CheckParameters (method);
1226 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1227 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1228 method.GetSignatureForError ());
1231 if (current_container.Kind == MemberKind.Interface) {
1232 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1233 method.GetSignatureForError ());
1237 current_local_parameters = null;
1240 Lexer.doc_state = XmlCommentState.Allowed;
1248 method_declaration_name OPEN_PARENS
1250 valid_param_mod = ParameterModifierType.All;
1252 opt_formal_parameter_list CLOSE_PARENS
1254 lexer.ConstraintsParsing = true;
1256 opt_type_parameter_constraints_clauses
1258 lexer.ConstraintsParsing = false;
1259 valid_param_mod = 0;
1260 MemberName name = (MemberName) $4;
1261 current_local_parameters = (ParametersCompiled) $7;
1263 GenericMethod generic = null;
1264 if (name.TypeArguments != null) {
1265 generic = new GenericMethod (current_namespace, current_class, name,
1266 (FullNamedExpression) $3, current_local_parameters);
1268 generic.SetParameterInfo ((List<Constraints>) $10);
1269 } else if ($10 != null) {
1270 report.Error (80, GetLocation ($10),
1271 "Constraints are not allowed on non-generic declarations");
1274 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1275 name, current_local_parameters, (Attributes) $1);
1277 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1278 report.Error (460, method.Location,
1279 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1280 method.GetSignatureForError ());
1284 method.DocComment = Lexer.consume_doc_comment ();
1286 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1294 lexer.parsing_generic_declaration = true;
1296 method_declaration_name
1299 lexer.parsing_generic_declaration = false;
1300 valid_param_mod = ParameterModifierType.All;
1302 opt_formal_parameter_list CLOSE_PARENS
1304 lexer.ConstraintsParsing = true;
1306 opt_type_parameter_constraints_clauses
1308 lexer.ConstraintsParsing = false;
1309 valid_param_mod = 0;
1311 MemberName name = (MemberName) $6;
1312 current_local_parameters = (ParametersCompiled) $9;
1314 if ($11 != null && name.TypeArguments == null)
1315 report.Error (80, lexer.Location,
1316 "Constraints are not allowed on non-generic declarations");
1319 GenericMethod generic = null;
1320 if (name.TypeArguments != null) {
1321 generic = new GenericMethod (current_namespace, current_class, name,
1322 new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1323 current_local_parameters);
1325 generic.SetParameterInfo ((List<Constraints>) $11);
1328 var modifiers = (Modifiers) $2;
1330 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1331 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1333 if ((modifiers & invalid_partial_mod) != 0) {
1334 report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1335 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1336 modifiers &= ~invalid_partial_mod;
1339 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1340 report.Error (751, name.Location, "A partial method must be declared within a " +
1341 "partial class or partial struct");
1344 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1346 method = new Method (current_class, generic, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1347 modifiers, name, current_local_parameters, (Attributes) $1);
1350 method.DocComment = Lexer.consume_doc_comment ();
1352 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1353 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1359 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1361 MemberName name = (MemberName) $5;
1362 report.Error (1585, name.Location,
1363 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1365 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1366 0, name, (ParametersCompiled) $7, (Attributes) $1);
1368 current_local_parameters = (ParametersCompiled) $7;
1371 method.DocComment = Lexer.consume_doc_comment ();
1379 | SEMICOLON { $$ = null; }
1382 opt_formal_parameter_list
1383 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1384 | formal_parameter_list
1387 formal_parameter_list
1390 var pars_list = (List<Parameter>) $1;
1391 $$ = new ParametersCompiled (pars_list.ToArray ());
1393 | fixed_parameters COMMA parameter_array
1395 var pars_list = (List<Parameter>) $1;
1396 pars_list.Add ((Parameter) $3);
1398 $$ = new ParametersCompiled (pars_list.ToArray ());
1400 | fixed_parameters COMMA arglist_modifier
1402 var pars_list = (List<Parameter>) $1;
1403 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1404 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1406 | parameter_array COMMA error
1409 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1411 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1413 | fixed_parameters COMMA parameter_array COMMA error
1416 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1418 var pars_list = (List<Parameter>) $1;
1419 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1421 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1423 | arglist_modifier COMMA error
1425 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1427 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1429 | fixed_parameters COMMA ARGLIST COMMA error
1431 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1433 var pars_list = (List<Parameter>) $1;
1434 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1436 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1440 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1444 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1448 Error_SyntaxError (yyToken);
1449 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1456 parameters_bucket.Clear ();
1457 Parameter p = (Parameter) $1;
1458 parameters_bucket.Add (p);
1460 default_parameter_used = p.HasDefaultValue;
1461 $$ = parameters_bucket;
1463 | fixed_parameters COMMA fixed_parameter
1465 var pars = (List<Parameter>) $1;
1466 Parameter p = (Parameter) $3;
1468 if (p.HasExtensionMethodModifier)
1469 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1470 else if (!p.HasDefaultValue && default_parameter_used)
1471 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1473 default_parameter_used |= p.HasDefaultValue;
1476 lbag.AddLocation (p, GetLocation ($2));
1485 opt_parameter_modifier
1489 var lt = (Tokenizer.LocatedToken) $4;
1490 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1493 opt_parameter_modifier
1495 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1497 var lt = (Tokenizer.LocatedToken) $4;
1498 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1499 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1502 opt_parameter_modifier
1506 Error_SyntaxError (yyToken);
1507 Location l = GetLocation ($4);
1508 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1511 opt_parameter_modifier
1516 ++lexer.parsing_block;
1520 --lexer.parsing_block;
1521 if (lang_version <= LanguageVersion.V_3) {
1522 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1525 Parameter.Modifier mod = (Parameter.Modifier) $2;
1526 if (mod != Parameter.Modifier.NONE) {
1528 case Parameter.Modifier.REF:
1529 case Parameter.Modifier.OUT:
1530 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1531 Parameter.GetModifierSignature (mod));
1534 case Parameter.Modifier.This:
1535 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1536 Parameter.GetModifierSignature (mod));
1539 throw new NotImplementedException (mod.ToString ());
1542 mod = Parameter.Modifier.NONE;
1545 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1546 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1548 var lt = (Tokenizer.LocatedToken) $4;
1549 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1550 lbag.AddLocation ($$, GetLocation ($5));
1553 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1557 opt_parameter_modifier
1558 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1559 | parameter_modifiers
1563 : parameter_modifier
1567 | parameter_modifiers parameter_modifier
1569 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1570 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1571 if (((Parameter.Modifier)$1 & p2) == p2) {
1572 Error_DuplicateParameterModifier (lexer.Location, p2);
1574 switch (mod & ~Parameter.Modifier.This) {
1575 case Parameter.Modifier.REF:
1576 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1578 case Parameter.Modifier.OUT:
1579 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1582 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1593 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1594 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1596 $$ = Parameter.Modifier.REF;
1600 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1601 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1603 $$ = Parameter.Modifier.OUT;
1607 if ((valid_param_mod & ParameterModifierType.This) == 0)
1608 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1610 if (lang_version <= LanguageVersion.ISO_2)
1611 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1613 $$ = Parameter.Modifier.This;
1618 : opt_attributes params_modifier type IDENTIFIER
1620 var lt = (Tokenizer.LocatedToken) $4;
1621 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1623 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1625 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1627 var lt = (Tokenizer.LocatedToken) $4;
1628 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1630 | opt_attributes params_modifier type error
1632 Error_SyntaxError (yyToken);
1640 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1641 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1643 | PARAMS parameter_modifier
1645 Parameter.Modifier mod = (Parameter.Modifier)$2;
1646 if ((mod & Parameter.Modifier.This) != 0) {
1647 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1649 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1652 | PARAMS params_modifier
1654 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1661 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1662 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1666 property_declaration
1670 member_declaration_name
1673 tmpComment = Lexer.consume_doc_comment ();
1677 var type = (FullNamedExpression) $3;
1678 current_property = new Property (current_class, type, (Modifiers) $2,
1679 (MemberName) $4, (Attributes) $1);
1681 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1682 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1684 current_container.AddProperty ((Property)current_property);
1685 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1687 lexer.PropertyParsing = true;
1689 accessor_declarations
1691 lexer.PropertyParsing = false;
1694 current_property.DocComment = ConsumeStoredComment ();
1698 lbag.AppendToMember (current_property, GetLocation ($10));
1699 current_property = null;
1705 : opt_attributes opt_modifiers
1706 member_type indexer_declaration_name OPEN_BRACKET
1708 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1710 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1712 valid_param_mod = 0;
1713 var type = (FullNamedExpression) $3;
1714 Indexer indexer = new Indexer (current_class, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1716 current_property = indexer;
1718 current_container.AddIndexer (indexer);
1719 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1721 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1722 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1724 if (indexer.ParameterInfo.IsEmpty) {
1725 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1729 tmpComment = Lexer.consume_doc_comment ();
1730 Lexer.doc_state = XmlCommentState.Allowed;
1733 lexer.PropertyParsing = true;
1735 accessor_declarations
1737 lexer.PropertyParsing = false;
1741 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1742 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1745 current_property.DocComment = ConsumeStoredComment ();
1747 lbag.AppendToMember (current_property, GetLocation ($12));
1748 current_property = null;
1753 accessor_declarations
1754 : get_accessor_declaration
1755 | get_accessor_declaration accessor_declarations
1756 | set_accessor_declaration
1757 | set_accessor_declaration accessor_declarations
1760 if (yyToken == Token.CLOSE_BRACE) {
1761 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1763 if (yyToken == Token.SEMICOLON)
1764 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1766 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1771 get_accessor_declaration
1772 : opt_attributes opt_modifiers GET
1774 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1775 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1778 if (current_property.Get != null) {
1779 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1782 if (current_property is Indexer) {
1783 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1784 (Attributes) $1, GetLocation ($3));
1786 current_property.Get = new Property.GetMethod (current_property,
1787 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1790 current_local_parameters = current_property.Get.ParameterInfo;
1791 lbag.AddMember (current_property.Get, mod_locations);
1792 lexer.PropertyParsing = false;
1797 current_property.Get.Block = (ToplevelBlock) $5;
1799 if (current_container.Kind == MemberKind.Interface) {
1800 report.Error (531, current_property.Get.Block.StartLocation,
1801 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1805 current_local_parameters = null;
1806 lexer.PropertyParsing = true;
1809 if (Lexer.doc_state == XmlCommentState.Error)
1810 Lexer.doc_state = XmlCommentState.NotAllowed;
1814 set_accessor_declaration
1815 : opt_attributes opt_modifiers SET
1817 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1818 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1821 if (current_property.Set != null) {
1822 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1825 if (current_property is Indexer) {
1826 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1827 ParametersCompiled.MergeGenerated (compiler,
1828 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1829 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1831 (Attributes) $1, GetLocation ($3));
1833 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1834 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1835 (Attributes) $1, GetLocation ($3));
1838 current_local_parameters = current_property.Set.ParameterInfo;
1839 lbag.AddMember (current_property.Set, mod_locations);
1840 lexer.PropertyParsing = false;
1845 current_property.Set.Block = (ToplevelBlock) $5;
1847 if (current_container.Kind == MemberKind.Interface) {
1848 report.Error (531, current_property.Set.Block.StartLocation,
1849 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1853 current_local_parameters = null;
1854 lexer.PropertyParsing = true;
1857 && Lexer.doc_state == XmlCommentState.Error)
1858 Lexer.doc_state = XmlCommentState.NotAllowed;
1871 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1876 interface_declaration
1882 lexer.ConstraintsParsing = true;
1884 type_declaration_name
1886 MemberName name = MakeName ((MemberName) $6);
1887 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1888 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1891 opt_type_parameter_constraints_clauses
1893 lexer.ConstraintsParsing = false;
1895 current_class.SetParameterInfo ((List<Constraints>) $9);
1898 current_container.DocComment = Lexer.consume_doc_comment ();
1899 Lexer.doc_state = XmlCommentState.Allowed;
1902 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1904 --lexer.parsing_declaration;
1906 Lexer.doc_state = XmlCommentState.Allowed;
1910 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1911 $$ = pop_current_class ();
1913 | opt_attributes opt_modifiers opt_partial INTERFACE error
1915 Error_SyntaxError (yyToken);
1919 opt_interface_member_declarations
1921 | interface_member_declarations
1924 interface_member_declarations
1925 : interface_member_declaration
1926 | interface_member_declarations interface_member_declaration
1929 interface_member_declaration
1930 : constant_declaration
1932 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1936 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1938 | method_declaration
1939 | property_declaration
1941 | indexer_declaration
1942 | operator_declaration
1944 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1946 | constructor_declaration
1948 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1952 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1956 operator_declaration
1957 : opt_attributes opt_modifiers operator_declarator
1962 OperatorDeclaration decl = (OperatorDeclaration) $3;
1964 Operator op = new Operator (
1965 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1966 current_local_parameters,
1967 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1969 if (op.Block == null)
1970 op.ParameterInfo.CheckParameters (op);
1973 op.DocComment = tmpComment;
1974 Lexer.doc_state = XmlCommentState.Allowed;
1977 // Note again, checking is done in semantic analysis
1978 current_container.AddOperator (op);
1980 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1983 current_local_parameters = null;
1989 | SEMICOLON { $$ = null; }
1993 : type_expression_or_array
1996 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1997 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2002 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2004 valid_param_mod = ParameterModifierType.DefaultValue;
2006 opt_formal_parameter_list CLOSE_PARENS
2008 valid_param_mod = 0;
2010 Location loc = GetLocation ($2);
2011 Operator.OpType op = (Operator.OpType) $3;
2012 current_local_parameters = (ParametersCompiled)$6;
2014 int p_count = current_local_parameters.Count;
2016 if (op == Operator.OpType.Addition)
2017 op = Operator.OpType.UnaryPlus;
2018 else if (op == Operator.OpType.Subtraction)
2019 op = Operator.OpType.UnaryNegation;
2022 if (IsUnaryOperator (op)) {
2024 report.Error (1020, loc, "Overloadable binary operator expected");
2025 } else if (p_count != 1) {
2026 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2027 Operator.GetName (op));
2031 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2032 Operator.GetName (op));
2033 } else if (p_count != 2) {
2034 report.Error (1019, loc, "Overloadable unary operator expected");
2039 tmpComment = Lexer.consume_doc_comment ();
2040 Lexer.doc_state = XmlCommentState.NotAllowed;
2043 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2044 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2046 | conversion_operator_declarator
2049 overloadable_operator
2051 : BANG { $$ = Operator.OpType.LogicalNot; }
2052 | TILDE { $$ = Operator.OpType.OnesComplement; }
2053 | OP_INC { $$ = Operator.OpType.Increment; }
2054 | OP_DEC { $$ = Operator.OpType.Decrement; }
2055 | TRUE { $$ = Operator.OpType.True; }
2056 | FALSE { $$ = Operator.OpType.False; }
2057 // Unary and binary:
2058 | PLUS { $$ = Operator.OpType.Addition; }
2059 | MINUS { $$ = Operator.OpType.Subtraction; }
2061 | STAR { $$ = Operator.OpType.Multiply; }
2062 | DIV { $$ = Operator.OpType.Division; }
2063 | PERCENT { $$ = Operator.OpType.Modulus; }
2064 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2065 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2066 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2067 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2068 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2069 | OP_EQ { $$ = Operator.OpType.Equality; }
2070 | OP_NE { $$ = Operator.OpType.Inequality; }
2071 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2072 | OP_LT { $$ = Operator.OpType.LessThan; }
2073 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2074 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2077 conversion_operator_declarator
2078 : IMPLICIT OPERATOR type OPEN_PARENS
2080 valid_param_mod = ParameterModifierType.DefaultValue;
2082 opt_formal_parameter_list CLOSE_PARENS
2084 valid_param_mod = 0;
2086 Location loc = GetLocation ($2);
2087 current_local_parameters = (ParametersCompiled)$6;
2090 tmpComment = Lexer.consume_doc_comment ();
2091 Lexer.doc_state = XmlCommentState.NotAllowed;
2094 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2095 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2097 | EXPLICIT OPERATOR type OPEN_PARENS
2099 valid_param_mod = ParameterModifierType.DefaultValue;
2101 opt_formal_parameter_list CLOSE_PARENS
2103 valid_param_mod = 0;
2105 Location loc = GetLocation ($2);
2106 current_local_parameters = (ParametersCompiled)$6;
2109 tmpComment = Lexer.consume_doc_comment ();
2110 Lexer.doc_state = XmlCommentState.NotAllowed;
2113 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2114 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2118 Error_SyntaxError (yyToken);
2119 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2120 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2124 Error_SyntaxError (yyToken);
2125 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2126 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2130 constructor_declaration
2131 : constructor_declarator
2134 Constructor c = (Constructor) $1;
2135 c.Block = (ToplevelBlock) $2;
2138 c.DocComment = ConsumeStoredComment ();
2140 current_container.AddConstructor (c);
2142 current_local_parameters = null;
2144 Lexer.doc_state = XmlCommentState.Allowed;
2148 constructor_declarator
2154 tmpComment = Lexer.consume_doc_comment ();
2155 Lexer.doc_state = XmlCommentState.Allowed;
2158 valid_param_mod = ParameterModifierType.All;
2160 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2162 valid_param_mod = 0;
2163 current_local_parameters = (ParametersCompiled) $6;
2166 // start block here, so possible anonymous methods inside
2167 // constructor initializer can get correct parent block
2169 start_block (lexer.Location);
2171 opt_constructor_initializer
2173 var lt = (Tokenizer.LocatedToken) $3;
2174 var mods = (Modifiers) $2;
2175 ConstructorInitializer ci = (ConstructorInitializer) $9;
2177 Constructor c = new Constructor (current_class, lt.Value, mods,
2178 (Attributes) $1, current_local_parameters, ci, lt.Location);
2180 if (lt.Value != current_container.MemberName.Name) {
2181 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2182 } else if ((mods & Modifiers.STATIC) != 0) {
2183 if ((mods & Modifiers.AccessibilityMask) != 0){
2184 report.Error (515, c.Location,
2185 "`{0}': static constructor cannot have an access modifier",
2186 c.GetSignatureForError ());
2189 report.Error (514, c.Location,
2190 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2191 c.GetSignatureForError ());
2196 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2203 | SEMICOLON { current_block = null; $$ = null; }
2206 opt_constructor_initializer
2208 | constructor_initializer
2211 constructor_initializer
2212 : COLON BASE OPEN_PARENS
2214 ++lexer.parsing_block;
2216 opt_argument_list CLOSE_PARENS
2218 --lexer.parsing_block;
2219 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2220 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2222 | COLON THIS OPEN_PARENS
2224 ++lexer.parsing_block;
2226 opt_argument_list CLOSE_PARENS
2228 --lexer.parsing_block;
2229 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2230 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2234 Error_SyntaxError (yyToken);
2239 destructor_declaration
2240 : opt_attributes opt_modifiers TILDE
2243 tmpComment = Lexer.consume_doc_comment ();
2244 Lexer.doc_state = XmlCommentState.NotAllowed;
2247 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2249 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2251 var lt = (Tokenizer.LocatedToken) $5;
2252 if (lt.Value != current_container.MemberName.Name){
2253 report.Error (574, lt.Location, "Name of destructor must match name of class");
2254 } else if (current_container.Kind != MemberKind.Class){
2255 report.Error (575, lt.Location, "Only class types can contain destructor");
2258 Destructor d = new Destructor (current_class, (Modifiers) $2,
2259 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2261 d.DocComment = ConsumeStoredComment ();
2263 d.Block = (ToplevelBlock) $8;
2264 current_container.AddMethod (d);
2265 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2267 current_local_parameters = null;
2274 EVENT type member_declaration_name
2276 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2277 current_container.AddEvent (current_event_field);
2279 if (current_event_field.MemberName.Left != null) {
2280 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2281 current_event_field.GetSignatureForError ());
2284 $$ = current_event_field;
2286 opt_event_initializer
2287 opt_event_declarators
2291 current_event_field.DocComment = Lexer.consume_doc_comment ();
2292 Lexer.doc_state = XmlCommentState.Allowed;
2295 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2296 current_event_field = null;
2300 EVENT type member_declaration_name
2303 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2304 current_container.AddEvent (current_event);
2305 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2307 lexer.EventParsing = true;
2309 event_accessor_declarations
2311 if (current_container.Kind == MemberKind.Interface)
2312 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2314 lexer.EventParsing = false;
2319 current_event.DocComment = Lexer.consume_doc_comment ();
2320 Lexer.doc_state = XmlCommentState.Allowed;
2323 lbag.AppendToMember (current_event, GetLocation ($9));
2324 current_event = null;
2325 current_local_parameters = null;
2329 opt_event_initializer
2333 ++lexer.parsing_block;
2335 event_variable_initializer
2337 --lexer.parsing_block;
2338 current_event_field.Initializer = (Expression) $3;
2342 opt_event_declarators
2350 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2352 | event_declarators event_declarator
2354 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2361 var lt = (Tokenizer.LocatedToken) $2;
2362 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2363 lbag.AddLocation ($$, GetLocation ($1));
2365 | COMMA IDENTIFIER ASSIGN
2367 ++lexer.parsing_block;
2369 event_variable_initializer
2371 --lexer.parsing_block;
2372 var lt = (Tokenizer.LocatedToken) $2;
2373 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2374 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2378 event_variable_initializer
2380 if (current_container.Kind == MemberKind.Interface) {
2381 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2382 current_event_field.GetSignatureForError ());
2385 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2386 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2387 current_event_field.GetSignatureForError ());
2390 variable_initializer
2396 event_accessor_declarations
2397 : add_accessor_declaration remove_accessor_declaration
2398 | remove_accessor_declaration add_accessor_declaration
2399 | add_accessor_declaration
2401 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2402 current_event.GetSignatureForError ());
2404 | remove_accessor_declaration
2406 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2407 current_event.GetSignatureForError ());
2411 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2416 add_accessor_declaration
2417 : opt_attributes opt_modifiers ADD
2419 if ($2 != ModifierNone) {
2420 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2423 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2424 current_local_parameters = current_event.Add.ParameterInfo;
2426 lbag.AddMember (current_event.Add, mod_locations);
2427 lexer.EventParsing = false;
2429 event_accessor_block
2431 lexer.EventParsing = true;
2433 current_event.Add.Block = (ToplevelBlock) $5;
2435 if (current_container.Kind == MemberKind.Interface) {
2436 report.Error (531, current_event.Add.Block.StartLocation,
2437 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2440 current_local_parameters = null;
2444 remove_accessor_declaration
2445 : opt_attributes opt_modifiers REMOVE
2447 if ($2 != ModifierNone) {
2448 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2451 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2452 current_local_parameters = current_event.Remove.ParameterInfo;
2454 lbag.AddMember (current_event.Remove, mod_locations);
2455 lexer.EventParsing = false;
2457 event_accessor_block
2459 lexer.EventParsing = true;
2461 current_event.Remove.Block = (ToplevelBlock) $5;
2463 if (current_container.Kind == MemberKind.Interface) {
2464 report.Error (531, current_event.Remove.Block.StartLocation,
2465 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2468 current_local_parameters = null;
2472 event_accessor_block
2475 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2484 ENUM type_declaration_name
2488 enumTypeComment = Lexer.consume_doc_comment ();
2493 Lexer.doc_state = XmlCommentState.Allowed;
2495 MemberName name = (MemberName) $4;
2496 if (name.IsGeneric) {
2497 report.Error (1675, name.Location, "Enums cannot have type parameters");
2500 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2502 opt_enum_member_declarations
2504 // here will be evaluated after CLOSE_BLACE is consumed.
2506 Lexer.doc_state = XmlCommentState.Allowed;
2508 CLOSE_BRACE opt_semicolon
2511 current_class.DocComment = enumTypeComment;
2513 --lexer.parsing_declaration;
2516 // em.DocComment = ev.DocComment;
2518 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2519 $$ = pop_current_class ();
2527 var te = $2 as TypeExpression;
2528 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2529 Enum.Error_1008 (GetLocation ($2), report);
2537 Error_TypeExpected (GetLocation ($1));
2542 opt_enum_member_declarations
2544 | enum_member_declarations
2545 | enum_member_declarations COMMA
2547 lbag.AddLocation ($1, GetLocation ($2));
2551 enum_member_declarations
2552 : enum_member_declaration
2553 | enum_member_declarations COMMA enum_member_declaration
2555 lbag.AddLocation ($1, GetLocation ($2));
2560 enum_member_declaration
2561 : opt_attributes IDENTIFIER
2563 var lt = (Tokenizer.LocatedToken) $2;
2564 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2565 ((Enum) current_class).AddEnumMember (em);
2568 em.DocComment = Lexer.consume_doc_comment ();
2569 Lexer.doc_state = XmlCommentState.Allowed;
2574 | opt_attributes IDENTIFIER
2576 ++lexer.parsing_block;
2578 tmpComment = Lexer.consume_doc_comment ();
2579 Lexer.doc_state = XmlCommentState.NotAllowed;
2582 ASSIGN constant_expression
2584 --lexer.parsing_block;
2586 var lt = (Tokenizer.LocatedToken) $2;
2587 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2588 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2589 ((Enum) current_class).AddEnumMember (em);
2592 em.DocComment = ConsumeStoredComment ();
2598 delegate_declaration
2602 member_type type_declaration_name
2605 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2607 opt_formal_parameter_list CLOSE_PARENS
2609 valid_param_mod = 0;
2611 MemberName name = MakeName ((MemberName) $5);
2612 ParametersCompiled p = (ParametersCompiled) $8;
2614 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2615 (Modifiers) $2, name, p, (Attributes) $1);
2617 p.CheckParameters (del);
2619 current_container.AddDelegate (del);
2620 current_delegate = del;
2621 lexer.ConstraintsParsing = true;
2623 opt_type_parameter_constraints_clauses
2625 lexer.ConstraintsParsing = false;
2630 current_delegate.DocComment = Lexer.consume_doc_comment ();
2631 Lexer.doc_state = XmlCommentState.Allowed;
2634 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2635 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2637 $$ = current_delegate;
2639 current_delegate = null;
2647 if (lang_version < LanguageVersion.ISO_2)
2648 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2650 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2654 namespace_or_type_name
2656 | qualified_alias_member IDENTIFIER opt_type_argument_list
2658 var lt1 = (Tokenizer.LocatedToken) $1;
2659 var lt2 = (Tokenizer.LocatedToken) $2;
2661 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2667 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2669 var lt = (Tokenizer.LocatedToken) $3;
2670 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2671 lbag.AddLocation ($$, GetLocation ($2));
2676 : IDENTIFIER opt_type_argument_list
2678 var lt = (Tokenizer.LocatedToken) $1;
2679 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2684 // Generics arguments (any type, without attributes)
2686 opt_type_argument_list
2688 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2690 if (lang_version < LanguageVersion.ISO_2)
2691 FeatureIsNotAvailable (GetLocation ($1), "generics");
2695 | OP_GENERICS_LT error
2697 Error_TypeExpected (lexer.Location);
2698 $$ = new TypeArguments ();
2705 TypeArguments type_args = new TypeArguments ();
2706 type_args.Add ((FullNamedExpression) $1);
2709 | type_arguments COMMA type
2711 TypeArguments type_args = (TypeArguments) $1;
2712 type_args.Add ((FullNamedExpression) $3);
2718 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2720 type_declaration_name
2723 lexer.parsing_generic_declaration = true;
2725 opt_type_parameter_list
2727 lexer.parsing_generic_declaration = false;
2728 var lt = (Tokenizer.LocatedToken) $1;
2729 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2733 member_declaration_name
2734 : method_declaration_name
2736 MemberName mn = (MemberName)$1;
2737 if (mn.TypeArguments != null)
2738 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2739 mn.GetSignatureForError ()));
2743 method_declaration_name
2744 : type_declaration_name
2745 | explicit_interface IDENTIFIER opt_type_parameter_list
2747 lexer.parsing_generic_declaration = false;
2748 var lt = (Tokenizer.LocatedToken) $2;
2749 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2753 indexer_declaration_name
2756 lexer.parsing_generic_declaration = false;
2757 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2759 | explicit_interface THIS
2761 lexer.parsing_generic_declaration = false;
2762 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2767 : IDENTIFIER opt_type_argument_list DOT
2769 var lt = (Tokenizer.LocatedToken) $1;
2770 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2771 lbag.AddLocation ($$, GetLocation ($3));
2773 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2775 var lt1 = (Tokenizer.LocatedToken) $1;
2776 var lt2 = (Tokenizer.LocatedToken) $2;
2778 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2779 lbag.AddLocation ($$, GetLocation ($4));
2781 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2783 var lt = (Tokenizer.LocatedToken) $2;
2784 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2785 lbag.AddLocation ($$, GetLocation ($4));
2789 opt_type_parameter_list
2791 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2793 if (lang_version < LanguageVersion.ISO_2)
2794 FeatureIsNotAvailable (GetLocation ($1), "generics");
2797 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2804 TypeArguments type_args = new TypeArguments ();
2805 type_args.Add ((FullNamedExpression)$1);
2808 | type_parameters COMMA type_parameter
2810 TypeArguments type_args = (TypeArguments) $1;
2811 type_args.Add ((FullNamedExpression)$3);
2813 lbag.AddLocation ($3, GetLocation ($3));
2818 : opt_attributes opt_type_parameter_variance IDENTIFIER
2820 var lt = (Tokenizer.LocatedToken)$3;
2821 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2825 if (GetTokenName (yyToken) == "type")
2826 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2828 Error_SyntaxError (yyToken);
2830 $$ = new TypeParameterName ("", null, lexer.Location);
2835 // All types where void is allowed
2838 : type_expression_or_array
2841 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2848 lexer.parsing_generic_declaration = true;
2853 // A type which does not allow `void' to be used
2856 : type_expression_or_array
2859 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2860 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2868 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2869 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2874 : type_expression_or_array
2877 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2878 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2882 type_expression_or_array
2884 | type_expression rank_specifiers
2886 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2891 : namespace_or_type_name opt_nullable
2893 MemberName name = (MemberName) $1;
2896 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2898 if (name.Left == null && name.Name == "var")
2899 $$ = new VarExpr (name.Location);
2901 $$ = name.GetTypeExpression ();
2904 | namespace_or_type_name pointer_stars
2906 $$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2);
2908 | builtin_types opt_nullable
2911 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2913 | builtin_types pointer_stars
2915 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2917 | VOID pointer_stars
2919 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2926 var types = new List<FullNamedExpression> (2);
2927 types.Add ((FullNamedExpression) $1);
2930 | type_list COMMA base_type_name
2932 var types = (List<FullNamedExpression>) $1;
2933 types.Add ((FullNamedExpression) $3);
2941 if ($1 is ComposedCast) {
2942 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2948 Error_TypeExpected (lexer.Location);
2954 * replaces all the productions for isolating the various
2955 * simple types, but we need this to reuse it easily in variable_type
2958 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2959 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2960 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2961 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2962 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2963 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2968 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2969 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2970 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2971 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2972 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2973 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2974 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2975 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2976 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2980 // Expressions, section 7.5
2985 : primary_expression_or_type
2987 | array_creation_expression
2988 | parenthesized_expression
2989 | default_value_expression
2990 | invocation_expression
2994 | post_increment_expression
2995 | post_decrement_expression
2996 | object_or_delegate_creation_expression
2997 | anonymous_type_expression
3000 | checked_expression
3001 | unchecked_expression
3002 | pointer_member_access
3003 | anonymous_method_expression
3004 | undocumented_expressions
3007 primary_expression_or_type
3008 : IDENTIFIER opt_type_argument_list
3010 var lt = (Tokenizer.LocatedToken) $1;
3011 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3013 | IDENTIFIER GENERATE_COMPLETION {
3014 var lt = (Tokenizer.LocatedToken) $1;
3015 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3023 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3027 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3028 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3033 // Here is the trick, tokenizer may think that parens is a special but
3034 // parser is interested in open parens only, so we merge them.
3035 // Consider: if (a)foo ();
3043 // Use this production to accept closing parenthesis or
3044 // performing completion
3048 | COMPLETE_COMPLETION
3052 parenthesized_expression
3053 : OPEN_PARENS expression CLOSE_PARENS
3055 $$ = new ParenthesizedExpression ((Expression) $2);
3056 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3058 | OPEN_PARENS expression COMPLETE_COMPLETION
3060 $$ = new ParenthesizedExpression ((Expression) $2);
3065 : primary_expression DOT IDENTIFIER opt_type_argument_list
3067 var lt = (Tokenizer.LocatedToken) $3;
3068 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3069 lbag.AddLocation ($$, GetLocation ($2));
3071 | builtin_types DOT IDENTIFIER opt_type_argument_list
3073 var lt = (Tokenizer.LocatedToken) $3;
3074 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3075 lbag.AddLocation ($$, GetLocation ($2));
3077 | BASE DOT IDENTIFIER opt_type_argument_list
3079 var lt = (Tokenizer.LocatedToken) $3;
3080 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3081 lbag.AddLocation ($$, GetLocation ($2));
3083 | qualified_alias_member IDENTIFIER opt_type_argument_list
3085 var lt1 = (Tokenizer.LocatedToken) $1;
3086 var lt2 = (Tokenizer.LocatedToken) $2;
3088 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3090 | primary_expression DOT GENERATE_COMPLETION {
3091 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3093 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3094 var lt = (Tokenizer.LocatedToken) $3;
3095 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3097 | builtin_types DOT GENERATE_COMPLETION
3099 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3101 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3102 var lt = (Tokenizer.LocatedToken) $3;
3103 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3107 invocation_expression
3108 : primary_expression open_parens_any opt_argument_list close_parens
3110 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3111 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3115 opt_object_or_collection_initializer
3116 : /* empty */ { $$ = null; }
3117 | object_or_collection_initializer
3120 object_or_collection_initializer
3121 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3124 $$ = CollectionOrObjectInitializers.Empty;
3127 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3128 lbag.AddLocation ($$, GetLocation ($3));
3131 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3133 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3134 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3138 opt_member_initializer_list
3139 : /* empty */ { $$ = null; }
3140 | member_initializer_list
3146 member_initializer_list
3147 : member_initializer
3149 var a = new List<Expression> ();
3150 a.Add ((Expression) $1);
3153 | member_initializer_list COMMA member_initializer
3155 var a = (List<Expression>)$1;
3156 a.Add ((Expression) $3);
3159 | member_initializer_list error {
3160 Error_SyntaxError (yyToken);
3166 : IDENTIFIER ASSIGN initializer_value
3168 var lt = (Tokenizer.LocatedToken) $1;
3169 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3170 lbag.AddLocation ($$, GetLocation ($2));
3172 | GENERATE_COMPLETION
3174 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3176 | non_assignment_expression opt_COMPLETE_COMPLETION {
3177 CompletionSimpleName csn = $1 as CompletionSimpleName;
3179 $$ = new CollectionElementInitializer ((Expression)$1);
3181 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3183 | OPEN_BRACE expression_list CLOSE_BRACE
3188 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3190 | OPEN_BRACE CLOSE_BRACE
3192 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3199 | object_or_collection_initializer
3203 : /* empty */ { $$ = null; }
3208 : argument_or_named_argument
3210 Arguments list = new Arguments (4);
3211 list.Add ((Argument) $1);
3214 | argument_list COMMA argument
3216 Arguments list = (Arguments) $1;
3217 if (list [list.Count - 1] is NamedArgument)
3218 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3220 list.Add ((Argument) $3);
3223 | argument_list COMMA named_argument
3225 Arguments list = (Arguments) $1;
3226 NamedArgument a = (NamedArgument) $3;
3227 for (int i = 0; i < list.Count; ++i) {
3228 NamedArgument na = list [i] as NamedArgument;
3229 if (na != null && na.Name == a.Name)
3230 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3237 | argument_list COMMA
3239 report.Error (839, GetLocation ($2), "An argument is missing");
3244 report.Error (839, GetLocation ($1), "An argument is missing");
3252 $$ = new Argument ((Expression) $1);
3254 | non_simple_argument
3257 argument_or_named_argument
3263 : REF variable_reference
3265 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3266 lbag.AddLocation ($$, GetLocation ($1));
3268 | OUT variable_reference
3270 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3271 lbag.AddLocation ($$, GetLocation ($1));
3273 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3275 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3276 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3278 | ARGLIST OPEN_PARENS CLOSE_PARENS
3280 $$ = new Argument (new Arglist (GetLocation ($1)));
3281 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3290 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3292 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3293 lbag.AddLocation ($$, GetLocation ($4));
3300 var list = new List<Expression> (4);
3301 list.Add ((Expression) $1);
3304 | expression_list COMMA expression
3306 var list = (List<Expression>) $1;
3307 list.Add ((Expression) $3);
3310 | expression_list error {
3311 Error_SyntaxError (yyToken);
3316 expression_list_arguments
3317 : expression_list_argument
3319 Arguments args = new Arguments (4);
3320 args.Add ((Argument) $1);
3323 | expression_list_arguments COMMA expression_list_argument
3325 Arguments args = (Arguments) $1;
3326 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3327 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3329 args.Add ((Argument) $3);
3334 expression_list_argument
3337 $$ = new Argument ((Expression) $1);
3345 $$ = new This (GetLocation ($1));
3350 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3352 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3353 lbag.AddLocation ($$, GetLocation ($4));
3355 | BASE OPEN_BRACKET error
3357 Error_SyntaxError (yyToken);
3358 $$ = new ElementAccess (null, null, GetLocation ($2));
3362 post_increment_expression
3363 : primary_expression OP_INC
3365 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3369 post_decrement_expression
3370 : primary_expression OP_DEC
3372 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3376 object_or_delegate_creation_expression
3377 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3380 if (lang_version <= LanguageVersion.ISO_2)
3381 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3383 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3385 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3388 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3390 | NEW new_expr_type object_or_collection_initializer
3392 if (lang_version <= LanguageVersion.ISO_2)
3393 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3395 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3399 array_creation_expression
3400 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3402 opt_array_initializer
3404 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3405 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3406 Next = (ComposedTypeSpecifier) $6
3407 }, (ArrayInitializer) $7, GetLocation ($1));
3408 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3410 | NEW new_expr_type rank_specifiers opt_array_initializer
3413 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3415 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3417 | NEW rank_specifier array_initializer
3419 if (lang_version <= LanguageVersion.ISO_2)
3420 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3422 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3424 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3426 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3427 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3429 | NEW new_expr_type error
3431 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3432 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3438 ++lexer.parsing_type;
3442 --lexer.parsing_type;
3447 anonymous_type_expression
3448 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3450 if (lang_version <= LanguageVersion.ISO_2)
3451 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3453 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3455 // TODO: lbag comma location
3456 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3460 anonymous_type_parameters_opt_comma
3461 : anonymous_type_parameters_opt
3462 | anonymous_type_parameters COMMA
3465 anonymous_type_parameters_opt
3467 | anonymous_type_parameters
3470 anonymous_type_parameters
3471 : anonymous_type_parameter
3473 var a = new List<AnonymousTypeParameter> (4);
3474 a.Add ((AnonymousTypeParameter) $1);
3477 | anonymous_type_parameters COMMA anonymous_type_parameter
3479 var a = (List<AnonymousTypeParameter>) $1;
3480 a.Add ((AnonymousTypeParameter) $3);
3485 anonymous_type_parameter
3486 : IDENTIFIER ASSIGN variable_initializer
3488 var lt = (Tokenizer.LocatedToken)$1;
3489 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3490 lbag.AddLocation ($$, GetLocation ($2));
3494 var lt = (Tokenizer.LocatedToken)$1;
3495 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3496 lt.Value, lt.Location);
3500 MemberAccess ma = (MemberAccess) $1;
3501 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3505 report.Error (746, lexer.Location,
3506 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3518 | rank_specifier rank_specifiers
3520 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3526 : OPEN_BRACKET CLOSE_BRACKET
3528 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3529 lbag.AddLocation ($$, GetLocation ($2));
3531 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3533 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3534 lbag.AddLocation ($$, GetLocation ($3));
3543 | dim_separators COMMA
3545 $$ = ((int) $1) + 1;
3549 opt_array_initializer
3561 : OPEN_BRACE CLOSE_BRACE
3563 var ai = new ArrayInitializer (0, GetLocation ($1));
3564 ai.VariableDeclaration = current_variable;
3565 lbag.AddLocation (ai, GetLocation ($2));
3568 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3570 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3571 ai.VariableDeclaration = current_variable;
3573 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3575 lbag.AddLocation (ai, GetLocation ($4));
3581 variable_initializer_list
3582 : variable_initializer
3584 var list = new List<Expression> (4);
3585 list.Add ((Expression) $1);
3588 | variable_initializer_list COMMA variable_initializer
3590 var list = (List<Expression>) $1;
3591 list.Add ((Expression) $3);
3599 lexer.TypeOfParsing = true;
3601 open_parens_any typeof_type_expression CLOSE_PARENS
3603 lexer.TypeOfParsing = false;
3604 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3605 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3609 typeof_type_expression
3614 Error_TypeExpected (lexer.Location);
3620 : IDENTIFIER generic_dimension
3622 var lt = (Tokenizer.LocatedToken) $1;
3624 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3626 | qualified_alias_member IDENTIFIER generic_dimension
3628 var lt1 = (Tokenizer.LocatedToken) $1;
3629 var lt2 = (Tokenizer.LocatedToken) $2;
3631 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3633 | unbound_type_name DOT IDENTIFIER
3635 var lt = (Tokenizer.LocatedToken) $3;
3637 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3639 | unbound_type_name DOT IDENTIFIER generic_dimension
3641 var lt = (Tokenizer.LocatedToken) $3;
3643 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3645 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3647 var te = ((MemberName) $1).GetTypeExpression ();
3648 if (te.HasTypeArguments)
3649 Error_TypeExpected (GetLocation ($4));
3651 var lt = (Tokenizer.LocatedToken) $3;
3652 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3659 if (lang_version < LanguageVersion.ISO_2)
3660 FeatureIsNotAvailable (GetLocation ($1), "generics");
3666 qualified_alias_member
3667 : IDENTIFIER DOUBLE_COLON
3669 var lt = (Tokenizer.LocatedToken) $1;
3670 if (lang_version == LanguageVersion.ISO_1)
3671 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3678 : SIZEOF open_parens_any type CLOSE_PARENS
3680 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3681 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3686 : CHECKED open_parens_any expression CLOSE_PARENS
3688 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3689 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3693 unchecked_expression
3694 : UNCHECKED open_parens_any expression CLOSE_PARENS
3696 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3697 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3701 pointer_member_access
3702 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3704 var lt = (Tokenizer.LocatedToken) $3;
3705 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3709 anonymous_method_expression
3710 : DELEGATE opt_anonymous_method_signature
3712 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3716 $$ = end_anonymous ((ParametersBlock) $4);
3718 | ASYNC DELEGATE opt_anonymous_method_signature
3720 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3724 $$ = end_anonymous ((ParametersBlock) $5);
3728 opt_anonymous_method_signature
3731 $$ = ParametersCompiled.Undefined;
3733 | anonymous_method_signature
3736 anonymous_method_signature
3739 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3741 opt_formal_parameter_list CLOSE_PARENS
3743 valid_param_mod = 0;
3748 default_value_expression
3749 : DEFAULT open_parens_any type CLOSE_PARENS
3751 if (lang_version < LanguageVersion.ISO_2)
3752 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3754 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3755 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3760 : primary_expression
3761 | BANG prefixed_unary_expression
3763 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3765 | TILDE prefixed_unary_expression
3767 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3774 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3776 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3777 lbag.AddLocation ($$, GetLocation ($3));
3782 : AWAIT unary_expression
3784 current_block.ParametersBlock.IsAsync = true;
3785 $$ = new Await ((Expression) $2, GetLocation ($1));
3790 // The idea to split this out is from Rhys' grammar
3791 // to solve the problem with casts.
3793 prefixed_unary_expression
3795 | PLUS prefixed_unary_expression
3797 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3799 | MINUS prefixed_unary_expression
3801 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3803 | OP_INC prefixed_unary_expression
3805 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3807 | OP_DEC prefixed_unary_expression
3809 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3811 | STAR prefixed_unary_expression
3813 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3815 | BITWISE_AND prefixed_unary_expression
3817 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3821 multiplicative_expression
3822 : prefixed_unary_expression
3823 | multiplicative_expression STAR prefixed_unary_expression
3825 $$ = new Binary (Binary.Operator.Multiply,
3826 (Expression) $1, (Expression) $3, GetLocation ($2));
3828 | multiplicative_expression DIV prefixed_unary_expression
3830 $$ = new Binary (Binary.Operator.Division,
3831 (Expression) $1, (Expression) $3, GetLocation ($2));
3833 | multiplicative_expression PERCENT prefixed_unary_expression
3835 $$ = new Binary (Binary.Operator.Modulus,
3836 (Expression) $1, (Expression) $3, GetLocation ($2));
3841 : multiplicative_expression
3842 | additive_expression PLUS multiplicative_expression
3844 $$ = new Binary (Binary.Operator.Addition,
3845 (Expression) $1, (Expression) $3, GetLocation ($2));
3847 | additive_expression MINUS multiplicative_expression
3849 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3851 | parenthesized_expression MINUS multiplicative_expression
3853 // Shift/Reduce conflict
3854 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3856 | additive_expression AS type
3858 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3860 | additive_expression IS type
3862 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3867 : additive_expression
3868 | shift_expression OP_SHIFT_LEFT additive_expression
3870 $$ = new Binary (Binary.Operator.LeftShift,
3871 (Expression) $1, (Expression) $3, GetLocation ($2));
3873 | shift_expression OP_SHIFT_RIGHT additive_expression
3875 $$ = new Binary (Binary.Operator.RightShift,
3876 (Expression) $1, (Expression) $3, GetLocation ($2));
3880 relational_expression
3882 | relational_expression OP_LT shift_expression
3884 $$ = new Binary (Binary.Operator.LessThan,
3885 (Expression) $1, (Expression) $3, GetLocation ($2));
3887 | relational_expression OP_GT shift_expression
3889 $$ = new Binary (Binary.Operator.GreaterThan,
3890 (Expression) $1, (Expression) $3, GetLocation ($2));
3892 | relational_expression OP_LE shift_expression
3894 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3895 (Expression) $1, (Expression) $3, GetLocation ($2));
3897 | relational_expression OP_GE shift_expression
3899 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3900 (Expression) $1, (Expression) $3, GetLocation ($2));
3905 : relational_expression
3906 | equality_expression OP_EQ relational_expression
3908 $$ = new Binary (Binary.Operator.Equality,
3909 (Expression) $1, (Expression) $3, GetLocation ($2));
3911 | equality_expression OP_NE relational_expression
3913 $$ = new Binary (Binary.Operator.Inequality,
3914 (Expression) $1, (Expression) $3, GetLocation ($2));
3919 : equality_expression
3920 | and_expression BITWISE_AND equality_expression
3922 $$ = new Binary (Binary.Operator.BitwiseAnd,
3923 (Expression) $1, (Expression) $3, GetLocation ($2));
3927 exclusive_or_expression
3929 | exclusive_or_expression CARRET and_expression
3931 $$ = new Binary (Binary.Operator.ExclusiveOr,
3932 (Expression) $1, (Expression) $3, GetLocation ($2));
3936 inclusive_or_expression
3937 : exclusive_or_expression
3938 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3940 $$ = new Binary (Binary.Operator.BitwiseOr,
3941 (Expression) $1, (Expression) $3, GetLocation ($2));
3945 conditional_and_expression
3946 : inclusive_or_expression
3947 | conditional_and_expression OP_AND inclusive_or_expression
3949 $$ = new Binary (Binary.Operator.LogicalAnd,
3950 (Expression) $1, (Expression) $3, GetLocation ($2));
3954 conditional_or_expression
3955 : conditional_and_expression
3956 | conditional_or_expression OP_OR conditional_and_expression
3958 $$ = new Binary (Binary.Operator.LogicalOr,
3959 (Expression) $1, (Expression) $3, GetLocation ($2));
3963 null_coalescing_expression
3964 : conditional_or_expression
3965 | conditional_or_expression OP_COALESCING null_coalescing_expression
3967 if (lang_version < LanguageVersion.ISO_2)
3968 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3970 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3974 conditional_expression
3975 : null_coalescing_expression
3976 | null_coalescing_expression INTERR expression COLON expression
3978 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3979 lbag.AddLocation ($$, GetLocation ($4));
3983 assignment_expression
3984 : prefixed_unary_expression ASSIGN expression
3986 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3988 | prefixed_unary_expression OP_MULT_ASSIGN expression
3990 $$ = new CompoundAssign (
3991 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3993 | prefixed_unary_expression OP_DIV_ASSIGN expression
3995 $$ = new CompoundAssign (
3996 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3998 | prefixed_unary_expression OP_MOD_ASSIGN expression
4000 $$ = new CompoundAssign (
4001 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4003 | prefixed_unary_expression OP_ADD_ASSIGN expression
4005 $$ = new CompoundAssign (
4006 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4008 | prefixed_unary_expression OP_SUB_ASSIGN expression
4010 $$ = new CompoundAssign (
4011 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4013 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4015 $$ = new CompoundAssign (
4016 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4018 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4020 $$ = new CompoundAssign (
4021 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4023 | prefixed_unary_expression OP_AND_ASSIGN expression
4025 $$ = new CompoundAssign (
4026 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4028 | prefixed_unary_expression OP_OR_ASSIGN expression
4030 $$ = new CompoundAssign (
4031 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4033 | prefixed_unary_expression OP_XOR_ASSIGN expression
4035 $$ = new CompoundAssign (
4036 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4040 lambda_parameter_list
4043 var pars = new List<Parameter> (4);
4044 pars.Add ((Parameter) $1);
4048 | lambda_parameter_list COMMA lambda_parameter
4050 var pars = (List<Parameter>) $1;
4051 Parameter p = (Parameter)$3;
4052 if (pars[0].GetType () != p.GetType ()) {
4053 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4062 : parameter_modifier parameter_type IDENTIFIER
4064 var lt = (Tokenizer.LocatedToken) $3;
4066 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4068 | parameter_type IDENTIFIER
4070 var lt = (Tokenizer.LocatedToken) $2;
4072 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4076 var lt = (Tokenizer.LocatedToken) $1;
4077 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4081 opt_lambda_parameter_list
4082 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4083 | lambda_parameter_list {
4084 var pars_list = (List<Parameter>) $1;
4085 $$ = new ParametersCompiled (pars_list.ToArray ());
4089 lambda_expression_body
4090 : lambda_expression_body_simple
4094 lambda_expression_body_simple
4096 start_block (lexer.Location);
4098 expression_or_error // Have to close block when error occurs
4100 Block b = end_block (lexer.Location);
4101 b.AddStatement (new ContextualReturn ((Expression) $2));
4110 Error_SyntaxError (yyToken);
4111 $$ = EmptyExpression.Null;
4118 var lt = (Tokenizer.LocatedToken) $1;
4119 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4120 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4122 lambda_expression_body
4124 $$ = end_anonymous ((ParametersBlock) $4);
4125 lbag.AddLocation ($$, GetLocation ($2));
4127 | ASYNC IDENTIFIER ARROW
4129 var lt = (Tokenizer.LocatedToken) $2;
4130 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4131 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4133 lambda_expression_body
4135 $$ = end_anonymous ((ParametersBlock) $5);
4136 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4138 | OPEN_PARENS_LAMBDA
4140 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4142 opt_lambda_parameter_list CLOSE_PARENS ARROW
4144 valid_param_mod = 0;
4145 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4147 lambda_expression_body
4149 $$ = end_anonymous ((ParametersBlock) $7);
4150 lbag.AddLocation ($$, GetLocation ($4), GetLocation ($5));
4152 | ASYNC OPEN_PARENS_LAMBDA
4154 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4156 opt_lambda_parameter_list CLOSE_PARENS ARROW
4158 valid_param_mod = 0;
4159 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4161 lambda_expression_body
4163 $$ = end_anonymous ((ParametersBlock) $8);
4164 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($5), GetLocation ($6));
4169 : assignment_expression
4170 | non_assignment_expression
4173 non_assignment_expression
4174 : conditional_expression
4179 $$ = new ArglistAccess (GetLocation ($1));
4183 undocumented_expressions
4184 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4186 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4187 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4189 | REFTYPE open_parens_any expression CLOSE_PARENS
4191 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4192 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4194 | MAKEREF open_parens_any expression CLOSE_PARENS
4196 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4197 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4208 $$ = new BooleanExpression ((Expression) $1);
4221 lexer.ConstraintsParsing = true;
4223 type_declaration_name
4225 MemberName name = MakeName ((MemberName) $6);
4226 Class c = new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1);
4227 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4228 FeatureIsNotAvailable (c.Location, "static classes");
4231 push_current_class (c, $3);
4234 opt_type_parameter_constraints_clauses
4236 lexer.ConstraintsParsing = false;
4238 current_class.SetParameterInfo ((List<Constraints>) $9);
4239 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4242 current_container.DocComment = Lexer.consume_doc_comment ();
4243 Lexer.doc_state = XmlCommentState.Allowed;
4246 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4248 --lexer.parsing_declaration;
4250 Lexer.doc_state = XmlCommentState.Allowed;
4254 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4255 $$ = pop_current_class ();
4263 { $$ = $1; } // location
4269 mod_locations = null;
4277 | modifiers modifier
4279 var m1 = (Modifiers) $1;
4280 var m2 = (Modifiers) $2;
4282 if ((m1 & m2) != 0) {
4283 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4284 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4285 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4286 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4287 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4288 "More than one protection modifier specified");
4299 StoreModifierLocation ($$, GetLocation ($1));
4301 if (current_container == module)
4302 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4306 $$ = Modifiers.PUBLIC;
4307 StoreModifierLocation ($$, GetLocation ($1));
4311 $$ = Modifiers.PROTECTED;
4312 StoreModifierLocation ($$, GetLocation ($1));
4316 $$ = Modifiers.INTERNAL;
4317 StoreModifierLocation ($$, GetLocation ($1));
4321 $$ = Modifiers.PRIVATE;
4322 StoreModifierLocation ($$, GetLocation ($1));
4326 $$ = Modifiers.ABSTRACT;
4327 StoreModifierLocation ($$, GetLocation ($1));
4331 $$ = Modifiers.SEALED;
4332 StoreModifierLocation ($$, GetLocation ($1));
4336 $$ = Modifiers.STATIC;
4337 StoreModifierLocation ($$, GetLocation ($1));
4341 $$ = Modifiers.READONLY;
4342 StoreModifierLocation ($$, GetLocation ($1));
4346 $$ = Modifiers.VIRTUAL;
4347 StoreModifierLocation ($$, GetLocation ($1));
4351 $$ = Modifiers.OVERRIDE;
4352 StoreModifierLocation ($$, GetLocation ($1));
4356 $$ = Modifiers.EXTERN;
4357 StoreModifierLocation ($$, GetLocation ($1));
4361 $$ = Modifiers.VOLATILE;
4362 StoreModifierLocation ($$, GetLocation ($1));
4366 $$ = Modifiers.UNSAFE;
4367 StoreModifierLocation ($$, GetLocation ($1));
4368 if (!settings.Unsafe)
4369 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4373 $$ = Modifiers.ASYNC;
4374 StoreModifierLocation ($$, GetLocation ($1));
4382 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4386 opt_type_parameter_constraints_clauses
4388 | type_parameter_constraints_clauses
4394 Error_SyntaxError (yyToken);
4399 type_parameter_constraints_clauses
4400 : type_parameter_constraints_clause
4402 var constraints = new List<Constraints> (1);
4403 constraints.Add ((Constraints) $1);
4406 | type_parameter_constraints_clauses type_parameter_constraints_clause
4408 var constraints = (List<Constraints>) $1;
4409 Constraints new_constraint = (Constraints)$2;
4411 foreach (Constraints c in constraints) {
4412 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4413 report.Error (409, new_constraint.Location,
4414 "A constraint clause has already been specified for type parameter `{0}'",
4415 new_constraint.TypeParameter.Value);
4419 constraints.Add (new_constraint);
4424 type_parameter_constraints_clause
4425 : WHERE IDENTIFIER COLON type_parameter_constraints
4427 var lt = (Tokenizer.LocatedToken) $2;
4428 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4432 type_parameter_constraints
4433 : type_parameter_constraint
4435 var constraints = new List<FullNamedExpression> (1);
4436 constraints.Add ((FullNamedExpression) $1);
4439 | type_parameter_constraints COMMA type_parameter_constraint
4441 var constraints = (List<FullNamedExpression>) $1;
4442 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4443 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4444 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4447 prev = $3 as SpecialContraintExpr;
4449 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4450 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4452 prev = constraints [0] as SpecialContraintExpr;
4453 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4454 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4459 constraints.Add ((FullNamedExpression) $3);
4464 type_parameter_constraint
4467 if ($1 is ComposedCast)
4468 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4472 | NEW OPEN_PARENS CLOSE_PARENS
4474 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4475 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4479 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4483 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4487 opt_type_parameter_variance
4492 | type_parameter_variance
4494 if (lang_version <= LanguageVersion.V_3)
4495 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4501 type_parameter_variance
4504 $$ = Variance.Covariant;
4508 $$ = Variance.Contravariant;
4517 // A block is "contained" on the following places:
4519 // property_declaration as part of the accessor body (get/set)
4520 // operator_declaration
4521 // constructor_declaration
4522 // destructor_declaration
4523 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4528 ++lexer.parsing_block;
4529 start_block (GetLocation ($1));
4531 opt_statement_list block_end
4540 --lexer.parsing_block;
4541 $$ = end_block (GetLocation ($1));
4543 | COMPLETE_COMPLETION
4545 --lexer.parsing_block;
4546 $$ = end_block (lexer.Location);
4554 ++lexer.parsing_block;
4555 current_block.StartLocation = GetLocation ($1);
4557 opt_statement_list CLOSE_BRACE
4559 --lexer.parsing_block;
4560 $$ = end_block (GetLocation ($4));
4571 | statement_list statement
4575 : block_variable_declaration
4577 current_block.AddStatement ((Statement) $1);
4579 | valid_declaration_statement
4581 current_block.AddStatement ((Statement) $1);
4586 Error_SyntaxError (yyToken);
4592 // The interactive_statement and its derivatives are only
4593 // used to provide a special version of `expression_statement'
4594 // that has a side effect of assigning the expression to
4597 interactive_statement_list
4598 : interactive_statement
4599 | interactive_statement_list interactive_statement
4602 interactive_statement
4603 : block_variable_declaration
4605 current_block.AddStatement ((Statement) $1);
4607 | interactive_valid_declaration_statement
4609 current_block.AddStatement ((Statement) $1);
4614 valid_declaration_statement
4617 | expression_statement
4618 | selection_statement
4619 | iteration_statement
4623 | unchecked_statement
4630 interactive_valid_declaration_statement
4633 | interactive_expression_statement
4634 | selection_statement
4635 | iteration_statement
4639 | unchecked_statement
4647 : valid_declaration_statement
4648 | block_variable_declaration
4650 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4655 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4660 Error_SyntaxError (yyToken);
4661 $$ = new EmptyStatement (GetLocation ($1));
4668 // Uses lexer.Location because semicolon location is not kept in quick mode
4669 $$ = new EmptyStatement (lexer.Location);
4676 var lt = (Tokenizer.LocatedToken) $1;
4677 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4679 current_block.AddLabel (labeled);
4680 current_block.AddStatement (labeled);
4686 : variable_type_simple
4687 | variable_type_simple rank_specifiers
4690 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4692 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4697 * The following is from Rhys' grammar:
4698 * > Types in local variable declarations must be recognized as
4699 * > expressions to prevent reduce/reduce errors in the grammar.
4700 * > The expressions are converted into types during semantic analysis.
4702 variable_type_simple
4703 : primary_expression_or_type opt_nullable
4705 // Ok, the above "primary_expression" is there to get rid of
4706 // both reduce/reduce and shift/reduces in the grammar, it should
4707 // really just be "type_name". If you use type_name, a reduce/reduce
4708 // creeps up. If you use namespace_or_type_name (which is all we need
4709 // really) two shift/reduces appear.
4712 // So the super-trick is that primary_expression
4713 // can only be either a SimpleName or a MemberAccess.
4714 // The MemberAccess case arises when you have a fully qualified type-name like :
4716 // SimpleName is when you have
4719 Expression expr = (Expression) $1;
4721 SimpleName sn = expr as SimpleName;
4722 if (sn != null && sn.Name == "var")
4723 $$ = new VarExpr (sn.Location);
4726 } else if (expr is ATypeNameExpression) {
4727 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4729 Error_ExpectingTypeName (expr);
4733 | primary_expression_or_type pointer_stars
4735 ATypeNameExpression expr = $1 as ATypeNameExpression;
4738 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4740 Error_ExpectingTypeName ((Expression)$1);
4744 | builtin_types opt_nullable
4749 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4751 | builtin_types pointer_stars
4753 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4755 | VOID pointer_stars
4757 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4761 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4762 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4768 | pointer_star pointer_stars
4770 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4778 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4782 block_variable_declaration
4783 : variable_type IDENTIFIER
4785 var lt = (Tokenizer.LocatedToken) $2;
4786 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4787 current_block.AddLocalName (li);
4788 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4790 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4792 $$ = current_variable;
4793 current_variable = null;
4794 lbag.AddLocation ($$, GetLocation ($6));
4796 | CONST variable_type IDENTIFIER
4798 var lt = (Tokenizer.LocatedToken) $3;
4799 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4800 current_block.AddLocalName (li);
4801 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4803 const_variable_initializer opt_const_declarators SEMICOLON
4805 $$ = current_variable;
4806 current_variable = null;
4807 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4811 opt_local_variable_initializer
4813 | ASSIGN block_variable_initializer
4815 current_variable.Initializer = (Expression) $2;
4820 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4821 report.Error (650, lexer.Location,
4822 "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type");
4824 Error_SyntaxError (yyToken);
4829 opt_variable_declarators
4831 | variable_declarators
4834 variable_declarators
4835 : variable_declarator
4836 | variable_declarators variable_declarator
4842 var lt = (Tokenizer.LocatedToken) $2;
4843 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4844 var d = new BlockVariableDeclaration.Declarator (li, null);
4845 current_variable.AddDeclarator (d);
4846 current_block.AddLocalName (li);
4847 lbag.AddLocation (d, GetLocation ($1));
4849 | COMMA IDENTIFIER ASSIGN block_variable_initializer
4851 var lt = (Tokenizer.LocatedToken) $2;
4852 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4853 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4854 current_variable.AddDeclarator (d);
4855 current_block.AddLocalName (li);
4856 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4860 const_variable_initializer
4863 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4865 | ASSIGN constant_initializer_expr
4867 current_variable.Initializer = (Expression) $2;
4871 opt_const_declarators
4878 | const_declarators const_declarator
4882 : COMMA IDENTIFIER ASSIGN constant_initializer_expr
4884 var lt = (Tokenizer.LocatedToken) $2;
4885 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4886 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4887 current_variable.AddDeclarator (d);
4888 current_block.AddLocalName (li);
4889 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4893 block_variable_initializer
4894 : variable_initializer
4895 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4897 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4898 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4900 | STACKALLOC simple_type
4902 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4903 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4907 expression_statement
4908 : statement_expression SEMICOLON
4911 lbag.AddStatement ($$, GetLocation ($2));
4913 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4916 interactive_expression_statement
4917 : interactive_statement_expression SEMICOLON { $$ = $1; }
4918 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4922 // We have to do the wrapping here and not in the case above,
4923 // because statement_expression is used for example in for_statement
4925 statement_expression
4928 ExpressionStatement s = $1 as ExpressionStatement;
4930 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4931 $$ = new StatementExpression (EmptyExpressionStatement.Instance);
4933 $$ = new StatementExpression (s);
4938 interactive_statement_expression
4941 Expression expr = (Expression) $1;
4942 ExpressionStatement s;
4944 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4945 $$ = new StatementExpression (s);
4949 Error_SyntaxError (yyToken);
4950 $$ = new EmptyStatement (GetLocation ($1));
4960 : IF open_parens_any boolean_expression CLOSE_PARENS
4963 if ($5 is EmptyStatement)
4964 Warning_EmptyStatement (GetLocation ($5));
4966 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4967 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4969 | IF open_parens_any boolean_expression CLOSE_PARENS
4970 embedded_statement ELSE embedded_statement
4972 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4973 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4975 if ($5 is EmptyStatement)
4976 Warning_EmptyStatement (GetLocation ($5));
4977 if ($7 is EmptyStatement)
4978 Warning_EmptyStatement (GetLocation ($7));
4983 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
4985 start_block (GetLocation ($5));
4987 opt_switch_sections CLOSE_BRACE
4989 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
4990 end_block (GetLocation ($8));
4991 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4998 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
4999 $$ = new List<SwitchSection> ();
5007 var sections = new List<SwitchSection> (4);
5009 sections.Add ((SwitchSection) $1);
5012 | switch_sections switch_section
5014 var sections = (List<SwitchSection>) $1;
5016 sections.Add ((SwitchSection) $2);
5021 Error_SyntaxError (yyToken);
5022 $$ = new List<SwitchSection> ();
5029 current_block = current_block.CreateSwitchBlock (lexer.Location);
5033 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5040 var labels = new List<SwitchLabel> (2);
5042 labels.Add ((SwitchLabel) $1);
5045 | switch_labels switch_label
5047 var labels = (List<SwitchLabel>) ($1);
5048 labels.Add ((SwitchLabel) $2);
5055 : CASE constant_expression COLON
5057 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5058 lbag.AddLocation ($$, GetLocation ($3));
5062 $$ = new SwitchLabel (null, GetLocation ($1));
5074 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5076 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5077 Warning_EmptyStatement (GetLocation ($5));
5079 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5080 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5085 : DO embedded_statement
5086 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5088 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5089 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5094 : FOR open_parens_any
5096 start_block (GetLocation ($2));
5097 current_block.IsCompilerGenerated = true;
5105 // Has to use be extra rule to recover started block
5107 : opt_for_initializer SEMICOLON
5108 opt_for_condition SEMICOLON
5109 opt_for_iterator CLOSE_PARENS
5112 if ($7 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5113 Warning_EmptyStatement (GetLocation ($7));
5115 For f = new For ((Statement) $1, (BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($-2));
5116 current_block.AddStatement (f);
5118 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5120 $$ = end_block (GetLocation ($2));
5124 Error_SyntaxError (yyToken);
5125 $$ = end_block (current_block.StartLocation);
5130 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5135 : variable_type IDENTIFIER
5137 var lt = (Tokenizer.LocatedToken) $2;
5138 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5139 current_block.AddLocalName (li);
5140 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5142 opt_local_variable_initializer opt_variable_declarators
5144 $$ = current_variable;
5145 current_variable = null;
5147 | statement_expression_list
5151 : /* empty */ { $$ = null; }
5152 | boolean_expression
5156 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5161 : statement_expression_list
5164 statement_expression_list
5165 : statement_expression
5166 | statement_expression_list COMMA statement_expression
5168 var sl = $1 as StatementList;
5170 sl = new StatementList ((Statement) $1, (Statement) $3);
5171 lbag.AddStatement (sl, GetLocation ($2));
5173 sl.Add ((Statement) $3);
5174 lbag.AppendTo (sl, GetLocation ($2));
5182 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5184 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5187 | FOREACH open_parens_any type IDENTIFIER IN expression CLOSE_PARENS
5189 start_block (GetLocation ($2));
5190 current_block.IsCompilerGenerated = true;
5192 var lt = (Tokenizer.LocatedToken) $4;
5193 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5194 current_block.AddLocalName (li);
5199 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5200 Warning_EmptyStatement (GetLocation ($9));
5202 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5203 current_block.AddStatement (f);
5205 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5206 $$ = end_block (GetLocation ($7));
5212 | continue_statement
5222 $$ = new Break (GetLocation ($1));
5223 lbag.AddStatement ($$, GetLocation ($2));
5228 : CONTINUE SEMICOLON
5230 $$ = new Continue (GetLocation ($1));
5231 lbag.AddStatement ($$, GetLocation ($2));
5236 : GOTO IDENTIFIER SEMICOLON
5238 var lt = (Tokenizer.LocatedToken) $2;
5239 $$ = new Goto (lt.Value, lt.Location);
5240 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5242 | GOTO CASE constant_expression SEMICOLON
5244 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5245 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5247 | GOTO DEFAULT SEMICOLON
5249 $$ = new GotoDefault (GetLocation ($1));
5250 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5255 : RETURN opt_expression SEMICOLON
5257 $$ = new Return ((Expression) $2, GetLocation ($1));
5258 lbag.AddStatement ($$, GetLocation ($3));
5263 : THROW opt_expression SEMICOLON
5265 $$ = new Throw ((Expression) $2, GetLocation ($1));
5266 lbag.AddStatement ($$, GetLocation ($3));
5271 : IDENTIFIER RETURN opt_expression SEMICOLON
5273 var lt = (Tokenizer.LocatedToken) $1;
5274 string s = lt.Value;
5276 report.Error (1003, lt.Location, "; expected");
5277 } else if ($3 == null) {
5278 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5279 } else if (lang_version == LanguageVersion.ISO_1){
5280 FeatureIsNotAvailable (lt.Location, "iterators");
5283 current_block.ParametersBlock.TopBlock.IsIterator = true;
5284 $$ = new Yield ((Expression) $3, lt.Location);
5285 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5287 | IDENTIFIER BREAK SEMICOLON
5289 var lt = (Tokenizer.LocatedToken) $1;
5290 string s = lt.Value;
5292 report.Error (1003, lt.Location, "; expected");
5293 } else if (lang_version == LanguageVersion.ISO_1){
5294 FeatureIsNotAvailable (lt.Location, "iterators");
5297 current_block.ParametersBlock.TopBlock.IsIterator = true;
5298 $$ = new YieldBreak (lt.Location);
5299 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5309 : TRY block catch_clauses
5311 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5313 | TRY block FINALLY block
5315 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5316 lbag.AddStatement ($$, GetLocation ($3));
5318 | TRY block catch_clauses FINALLY block
5320 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5321 lbag.AddStatement ($$, GetLocation ($4));
5325 report.Error (1524, GetLocation ($1), "Expected catch or finally");
5333 var l = new List<Catch> (2);
5338 | catch_clauses catch_clause
5340 var l = (List<Catch>) $1;
5342 Catch c = (Catch) $2;
5343 if (l [0].IsGeneral) {
5344 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5364 $$ = new Catch ((Block) $2, GetLocation ($1));
5366 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5368 start_block (GetLocation ($2));
5369 var c = new Catch (current_block, GetLocation ($1));
5370 c.TypeExpression = (FullNamedExpression) $3;
5373 var lt = (Tokenizer.LocatedToken) $4;
5374 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5375 current_block.AddLocalName (c.Variable);
5378 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5385 | CATCH open_parens_any error
5387 if (yyToken == Token.CLOSE_PARENS) {
5388 report.Error (1015, lexer.Location,
5389 "A type that derives from `System.Exception', `object', or `string' expected");
5391 Error_SyntaxError (yyToken);
5394 $$ = new Catch (null, GetLocation ($1));
5401 $$ = new Checked ((Block) $2, GetLocation ($1));
5408 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5415 if (!settings.Unsafe)
5416 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5418 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5423 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5425 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5426 Warning_EmptyStatement (GetLocation ($5));
5428 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5429 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5434 : FIXED open_parens_any variable_type IDENTIFIER
5436 start_block (GetLocation ($2));
5438 current_block.IsCompilerGenerated = true;
5439 var lt = (Tokenizer.LocatedToken) $4;
5440 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5441 current_block.AddLocalName (li);
5442 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5444 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5446 $$ = current_variable;
5447 current_variable = null;
5451 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5452 Warning_EmptyStatement (GetLocation ($10));
5454 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5455 current_block.AddStatement (f);
5456 $$ = end_block (GetLocation ($8));
5461 : USING open_parens_any variable_type IDENTIFIER
5463 start_block (GetLocation ($2));
5465 current_block.IsCompilerGenerated = true;
5466 var lt = (Tokenizer.LocatedToken) $4;
5467 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5468 current_block.AddLocalName (li);
5469 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5471 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5473 $$ = current_variable;
5474 current_variable = null;
5478 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5479 Warning_EmptyStatement (GetLocation ($10));
5481 Using u = new Using ((Using.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5482 current_block.AddStatement (u);
5483 $$ = end_block (GetLocation ($8));
5485 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5487 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5488 Warning_EmptyStatement (GetLocation ($5));
5490 Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5491 lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
5496 using_or_fixed_variable_initializer
5499 report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
5501 | ASSIGN variable_initializer
5503 current_variable.Initializer = (Expression) $2;
5504 $$ = current_variable;
5512 : first_from_clause query_body
5514 lexer.query_parsing = false;
5516 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5518 from.Tail.Next = (Linq.AQueryClause)$2;
5521 current_block.SetEndLocation (lexer.Location);
5522 current_block = current_block.Parent;
5524 | nested_from_clause query_body
5526 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5528 from.Tail.Next = (Linq.AQueryClause)$2;
5531 current_block.SetEndLocation (lexer.Location);
5532 current_block = current_block.Parent;
5535 // Bubble up COMPLETE_COMPLETION productions
5536 | first_from_clause COMPLETE_COMPLETION {
5537 lexer.query_parsing = false;
5540 current_block.SetEndLocation (lexer.Location);
5541 current_block = current_block.Parent;
5543 | nested_from_clause COMPLETE_COMPLETION {
5545 current_block.SetEndLocation (lexer.Location);
5546 current_block = current_block.Parent;
5551 : FROM_FIRST IDENTIFIER IN expression
5553 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5555 var lt = (Tokenizer.LocatedToken) $2;
5556 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5557 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5559 | FROM_FIRST type IDENTIFIER IN expression
5561 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5563 var lt = (Tokenizer.LocatedToken) $3;
5564 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5565 $$ = new Linq.QueryExpression (
5566 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5567 IdentifierType = (FullNamedExpression)$2
5574 : FROM IDENTIFIER IN expression
5576 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5578 var lt = (Tokenizer.LocatedToken) $2;
5579 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5580 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5582 | FROM type IDENTIFIER IN expression
5584 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5586 var lt = (Tokenizer.LocatedToken) $3;
5587 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5588 $$ = new Linq.QueryExpression (
5589 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5590 IdentifierType = (FullNamedExpression)$2
5597 : FROM IDENTIFIER IN
5599 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5603 var lt = (Tokenizer.LocatedToken) $2;
5604 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5605 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5607 current_block.SetEndLocation (lexer.Location);
5608 current_block = current_block.Parent;
5610 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5612 | FROM type IDENTIFIER IN
5614 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5618 var lt = (Tokenizer.LocatedToken) $3;
5619 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5621 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5622 IdentifierType = (FullNamedExpression)$2
5625 current_block.SetEndLocation (lexer.Location);
5626 current_block = current_block.Parent;
5628 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5633 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5635 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5638 head.Next = (Linq.AQueryClause)$3;
5641 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5642 clause.Tail.Next = head;
5648 | opt_query_body_clauses COMPLETE_COMPLETION
5651 Error_SyntaxError (yyToken);
5656 select_or_group_clause
5659 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5663 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5665 current_block.SetEndLocation (lexer.Location);
5666 current_block = current_block.Parent;
5670 if (linq_clause_blocks == null)
5671 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5673 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5674 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5678 current_block.SetEndLocation (lexer.Location);
5679 current_block = current_block.Parent;
5681 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5685 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5687 current_block.SetEndLocation (lexer.Location);
5688 current_block = current_block.Parent;
5692 opt_query_body_clauses
5694 | query_body_clauses
5699 | query_body_clauses query_body_clause
5701 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5715 : LET IDENTIFIER ASSIGN
5717 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5721 var lt = (Tokenizer.LocatedToken) $2;
5722 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5723 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5725 current_block.SetEndLocation (lexer.Location);
5726 current_block = current_block.Parent;
5728 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5735 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5739 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5741 current_block.SetEndLocation (lexer.Location);
5742 current_block = current_block.Parent;
5747 : JOIN IDENTIFIER IN
5749 if (linq_clause_blocks == null)
5750 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5752 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5753 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5757 current_block.SetEndLocation (lexer.Location);
5758 current_block = current_block.Parent;
5760 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5761 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5765 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5766 current_block.SetEndLocation (lexer.Location);
5767 current_block = current_block.Parent;
5769 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5771 expression opt_join_into
5773 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5774 current_block.SetEndLocation (lexer.Location);
5776 var outer_selector = linq_clause_blocks.Pop ();
5777 var block = linq_clause_blocks.Pop ();
5779 var lt = (Tokenizer.LocatedToken) $2;
5780 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5781 Linq.RangeVariable into;
5785 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5788 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5790 var parent = block.Parent;
5791 while (parent is Linq.QueryBlock) {
5792 parent = parent.Parent;
5794 current_block.Parent = parent;
5796 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5798 lt = (Tokenizer.LocatedToken) $12;
5799 into = new Linq.RangeVariable (lt.Value, lt.Location);
5801 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5804 current_block = block.Parent;
5805 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5807 | JOIN type IDENTIFIER IN
5809 if (linq_clause_blocks == null)
5810 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5812 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5813 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5817 current_block.SetEndLocation (lexer.Location);
5818 current_block = current_block.Parent;
5820 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5821 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5825 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5826 current_block.SetEndLocation (lexer.Location);
5827 current_block = current_block.Parent;
5829 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5831 expression opt_join_into
5833 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5834 current_block.SetEndLocation (lexer.Location);
5836 var outer_selector = linq_clause_blocks.Pop ();
5837 var block = linq_clause_blocks.Pop ();
5839 var lt = (Tokenizer.LocatedToken) $3;
5840 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5841 Linq.RangeVariable into;
5845 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5846 IdentifierType = (FullNamedExpression)$2
5850 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5852 var parent = block.Parent;
5853 while (parent is Linq.QueryBlock) {
5854 parent = parent.Parent;
5856 current_block.Parent = parent;
5858 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5860 lt = (Tokenizer.LocatedToken) $13;
5861 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
5863 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
5864 IdentifierType = (FullNamedExpression)$2
5868 current_block = block.Parent;
5869 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5884 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5888 current_block.SetEndLocation (lexer.Location);
5889 current_block = current_block.Parent;
5899 current_block.SetEndLocation (lexer.Location);
5900 current_block = current_block.Parent;
5902 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5906 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5913 | orderings_then_by COMMA
5915 current_block.SetEndLocation (lexer.Location);
5916 current_block = current_block.Parent;
5918 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
5922 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5930 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5932 | expression ASCENDING
5934 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5936 | expression DESCENDING
5938 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5945 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5947 | expression ASCENDING
5949 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5951 | expression DESCENDING
5953 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5958 opt_query_continuation
5962 // query continuation block is not linked with query block but with block
5963 // before. This means each query can use same range variable names for
5964 // different identifiers.
5966 current_block.SetEndLocation (GetLocation ($1));
5967 current_block = current_block.Parent;
5969 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5971 if (linq_clause_blocks == null)
5972 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5974 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5978 var current_block = linq_clause_blocks.Pop ();
5979 var lt = (Tokenizer.LocatedToken) $2;
5980 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5981 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
5982 next = (Linq.AQueryClause)$4
5988 // Support for using the compiler as an interactive parser
5990 // The INTERACTIVE_PARSER token is first sent to parse our
5991 // productions; If the result is a Statement, the parsing
5992 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5993 // to setup the blocks in advance.
5995 // This setup is here so that in the future we can add
5996 // support for other constructs (type parsing, namespaces, etc)
5997 // that do not require a block to be setup in advance
6001 : EVAL_STATEMENT_PARSER EOF
6002 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6003 | EVAL_STATEMENT_PARSER
6005 current_container = new Class (current_namespace, current_class, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6006 current_class = current_container;
6008 // (ref object retval)
6009 Parameter [] mpar = new Parameter [1];
6010 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6012 ParametersCompiled pars = new ParametersCompiled (mpar);
6013 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6014 if (settings.Unsafe)
6015 mods |= Modifiers.UNSAFE;
6017 current_local_parameters = pars;
6018 Method method = new Method (
6021 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6023 new MemberName ("Host"),
6025 null /* attributes */);
6027 current_container.AddMethod (method);
6029 oob_stack.Push (method);
6030 ++lexer.parsing_block;
6031 start_block (lexer.Location);
6033 interactive_statement_list opt_COMPLETE_COMPLETION
6035 --lexer.parsing_block;
6036 Method method = (Method) oob_stack.Pop ();
6038 method.Block = (ToplevelBlock) end_block(lexer.Location);
6040 InteractiveResult = (Class) pop_current_class ();
6041 current_local_parameters = null;
6043 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6046 interactive_compilation_unit
6047 : opt_extern_alias_directives opt_using_directives
6048 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6051 opt_COMPLETE_COMPLETION
6053 | COMPLETE_COMPLETION
6056 close_brace_or_complete_completion
6058 | COMPLETE_COMPLETION
6062 // XML documentation code references micro parser
6064 documentation_parsing
6067 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6072 : doc_type_declaration_name opt_doc_method_sig
6074 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6076 | builtin_types opt_doc_method_sig
6078 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6079 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6082 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6084 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6085 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6086 var lt = (Tokenizer.LocatedToken) $3;
6087 $$ = new MemberName (lt.Value);
6089 | doc_type_declaration_name DOT THIS
6091 $$ = new MemberName ((MemberName) $1, new MemberName (MemberCache.IndexerNameAlias));
6093 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6095 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6097 opt_doc_parameters CLOSE_BRACKET
6099 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6100 $$ = new MemberName ((MemberName) $1, new MemberName (MemberCache.IndexerNameAlias));
6102 | EXPLICIT OPERATOR type opt_doc_method_sig
6104 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6105 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6106 module.DocumentationBuilder.ParsedParameters = p;
6107 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6110 | IMPLICIT OPERATOR type opt_doc_method_sig
6112 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6113 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6114 module.DocumentationBuilder.ParsedParameters = p;
6115 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6118 | OPERATOR overloadable_operator opt_doc_method_sig
6120 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6121 module.DocumentationBuilder.ParsedParameters = p;
6122 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6127 doc_type_declaration_name
6128 : type_declaration_name
6129 | doc_type_declaration_name DOT type_declaration_name
6131 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6139 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6141 opt_doc_parameters CLOSE_PARENS
6150 $$ = new List<DocumentationParameter> (0);
6158 var parameters = new List<DocumentationParameter> ();
6159 parameters.Add ((DocumentationParameter) $1);
6162 | doc_parameters COMMA doc_parameter
6164 var parameters = $1 as List<DocumentationParameter>;
6165 parameters.Add ((DocumentationParameter) $3);
6171 : opt_parameter_modifier parameter_type
6174 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6176 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6183 // A class used to hold info about an operator declarator
6185 class OperatorDeclaration {
6186 public readonly Operator.OpType optype;
6187 public readonly FullNamedExpression ret_type;
6188 public readonly Location location;
6190 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6193 this.ret_type = ret_type;
6194 this.location = location;
6198 void Error_ExpectingTypeName (Expression expr)
6200 if (expr is Invocation){
6201 report.Error (1002, expr.Location, "Expecting `;'");
6203 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6207 void Error_ParameterModifierNotValid (string modifier, Location loc)
6209 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6213 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6215 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6216 Parameter.GetModifierSignature (mod));
6219 void Error_TypeExpected (Location loc)
6221 report.Error (1031, loc, "Type expected");
6224 void Error_UnsafeCodeNotAllowed (Location loc)
6226 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6229 void Warning_EmptyStatement (Location loc)
6231 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6234 void Error_NamedArgumentExpected (NamedArgument a)
6236 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6239 void push_current_class (TypeContainer tc, object partial_token)
6241 if (module.Evaluator != null && current_container is ModuleContainer){
6242 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6245 undo.AddTypeContainer (current_container, tc);
6248 if (partial_token != null)
6249 current_container = current_container.AddPartial (tc);
6251 current_container = current_container.AddTypeContainer (tc);
6253 ++lexer.parsing_declaration;
6257 DeclSpace pop_current_class ()
6259 DeclSpace retval = current_class;
6261 current_class = current_class.Parent;
6262 current_container = current_class.PartialContainer;
6268 // Given the @class_name name, it creates a fully qualified name
6269 // based on the containing declaration space
6272 MakeName (MemberName class_name)
6274 Namespace ns = current_namespace.NS;
6276 if (current_container == module) {
6277 if (ns.Name.Length != 0)
6278 return new MemberName (ns.MemberName, class_name);
6282 return new MemberName (current_container.MemberName, class_name);
6286 [System.Diagnostics.Conditional ("FULL_AST")]
6287 void StoreModifierLocation (object token, Location loc)
6292 if (mod_locations == null)
6293 mod_locations = new List<Tuple<Modifiers, Location>> ();
6295 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6298 string CheckAttributeTarget (string a, Location l)
6301 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6305 report.Warning (658, 1, l,
6306 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6307 return string.Empty;
6310 static bool IsUnaryOperator (Operator.OpType op)
6314 case Operator.OpType.LogicalNot:
6315 case Operator.OpType.OnesComplement:
6316 case Operator.OpType.Increment:
6317 case Operator.OpType.Decrement:
6318 case Operator.OpType.True:
6319 case Operator.OpType.False:
6320 case Operator.OpType.UnaryPlus:
6321 case Operator.OpType.UnaryNegation:
6327 void syntax_error (Location l, string msg)
6329 report.Error (1003, l, "Syntax error, " + msg);
6334 public Tokenizer Lexer {
6340 static CSharpParser ()
6342 oob_stack = new Stack<object> ();
6345 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
6346 : this (reader, file, file.NamespaceContainer.Module.Compiler.Report)
6350 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
6353 current_namespace = file.NamespaceContainer;
6355 this.module = current_namespace.Module;
6356 this.compiler = module.Compiler;
6357 this.settings = compiler.Settings;
6358 this.report = report;
6360 lang_version = settings.Version;
6361 doc_support = settings.DocumentationFile != null;
6362 current_class = current_namespace.SlaveDeclSpace;
6363 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6365 lexer = new Tokenizer (reader, file, compiler);
6367 use_global_stacks = true;
6370 public void parse ()
6372 eof_token = Token.EOF;
6373 Tokenizer.LocatedToken.Initialize ();
6376 if (yacc_verbose_flag > 1)
6377 yyparse (lexer, new yydebug.yyDebugSimple ());
6381 Tokenizer tokenizer = lexer as Tokenizer;
6382 tokenizer.cleanup ();
6383 } catch (Exception e){
6384 if (e is yyParser.yyUnexpectedEof) {
6385 Error_SyntaxError (yyToken);
6386 UnexpectedEOF = true;
6390 if (e is yyParser.yyException) {
6391 report.Error (-25, lexer.Location, "Parsing error");
6393 // Used by compiler-tester to test internal errors
6394 if (yacc_verbose_flag > 0)
6397 report.Error (589, lexer.Location, "Internal compiler error during parsing");
6402 void CheckToken (int error, int yyToken, string msg, Location loc)
6404 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6405 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6407 report.Error (error, loc, msg);
6410 string ConsumeStoredComment ()
6412 string s = tmpComment;
6414 Lexer.doc_state = XmlCommentState.Allowed;
6418 void FeatureIsNotAvailable (Location loc, string feature)
6420 report.FeatureIsNotAvailable (compiler, loc, feature);
6423 Location GetLocation (object obj)
6425 var lt = obj as Tokenizer.LocatedToken;
6429 var mn = obj as MemberName;
6433 var expr = obj as Expression;
6435 return expr.Location;
6437 return lexer.Location;
6440 public LocationsBag LocationsBag {
6449 void start_block (Location loc)
6451 if (current_block == null) {
6452 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6453 parsing_anonymous_method = false;
6454 } else if (parsing_anonymous_method) {
6455 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6456 parsing_anonymous_method = false;
6458 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6463 end_block (Location loc)
6465 Block retval = current_block.Explicit;
6466 retval.SetEndLocation (loc);
6467 current_block = retval.Parent;
6471 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6473 oob_stack.Push (current_anonymous_method);
6474 oob_stack.Push (current_local_parameters);
6475 oob_stack.Push (current_variable);
6477 current_local_parameters = parameters;
6479 if (lang_version <= LanguageVersion.ISO_2)
6480 FeatureIsNotAvailable (loc, "lambda expressions");
6482 current_anonymous_method = new LambdaExpression (isAsync, loc);
6484 if (lang_version == LanguageVersion.ISO_1)
6485 FeatureIsNotAvailable (loc, "anonymous methods");
6487 current_anonymous_method = new AnonymousMethodExpression (isAsync, loc);
6490 // Force the next block to be created as a ToplevelBlock
6491 parsing_anonymous_method = true;
6495 * Completes the anonymous method processing, if lambda_expr is null, this
6496 * means that we have a Statement instead of an Expression embedded
6498 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6500 AnonymousMethodExpression retval;
6502 current_anonymous_method.Block = anon_block;
6503 retval = current_anonymous_method;
6505 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6506 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6507 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6512 void Error_SyntaxError (int token)
6514 Error_SyntaxError (0, token, "Unexpected symbol");
6517 void Error_SyntaxError (int error_code, int token, string msg)
6519 Lexer.CompleteOnEOF = false;
6521 // An error message has been reported by tokenizer
6522 if (token == Token.ERROR)
6525 string symbol = GetSymbolName (token);
6526 string expecting = GetExpecting ();
6527 var loc = lexer.Location - symbol.Length;
6529 if (error_code == 0) {
6530 if (expecting == "`identifier'") {
6531 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6532 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6537 expecting = "identifier";
6538 } else if (expecting == "`)'") {
6545 if (string.IsNullOrEmpty (expecting))
6546 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6548 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6551 string GetExpecting ()
6553 int [] tokens = yyExpectingTokens (yyExpectingState);
6554 var names = new List<string> (tokens.Length);
6555 bool has_type = false;
6556 bool has_identifier = false;
6557 for (int i = 0; i < tokens.Length; i++){
6558 int token = tokens [i];
6559 has_identifier |= token == Token.IDENTIFIER;
6561 string name = GetTokenName (token);
6562 if (name == "<internal>")
6565 has_type |= name == "type";
6566 if (names.Contains (name))
6573 // Too many tokens to enumerate
6575 if (names.Count > 8)
6578 if (has_type && has_identifier)
6579 names.Remove ("identifier");
6581 if (names.Count == 1)
6582 return "`" + GetTokenName (tokens [0]) + "'";
6584 StringBuilder sb = new StringBuilder ();
6586 int count = names.Count;
6587 for (int i = 0; i < count; i++){
6588 bool last = i + 1 == count;
6592 sb.Append (names [i]);
6593 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6595 return sb.ToString ();
6599 string GetSymbolName (int token)
6603 return ((Constant)lexer.Value).GetValue ().ToString ();
6604 case Token.IDENTIFIER:
6605 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6647 case Token.BITWISE_AND:
6649 case Token.BITWISE_OR:
6663 case Token.OP_SHIFT_LEFT:
6665 case Token.OP_SHIFT_RIGHT:
6685 case Token.OP_COALESCING:
6687 case Token.OP_MULT_ASSIGN:
6689 case Token.OP_DIV_ASSIGN:
6691 case Token.OP_MOD_ASSIGN:
6693 case Token.OP_ADD_ASSIGN:
6695 case Token.OP_SUB_ASSIGN:
6697 case Token.OP_SHIFT_LEFT_ASSIGN:
6699 case Token.OP_SHIFT_RIGHT_ASSIGN:
6701 case Token.OP_AND_ASSIGN:
6703 case Token.OP_XOR_ASSIGN:
6705 case Token.OP_OR_ASSIGN:
6709 return GetTokenName (token);
6712 static string GetTokenName (int token)
6715 case Token.ABSTRACT:
6737 case Token.CONTINUE:
6741 case Token.DELEGATE:
6751 case Token.EXPLICIT:
6754 case Token.EXTERN_ALIAS:
6770 case Token.IMPLICIT:
6774 case Token.INTERFACE:
6776 case Token.INTERNAL:
6782 case Token.NAMESPACE:
6788 case Token.OPERATOR:
6792 case Token.OVERRIDE:
6798 case Token.PROTECTED:
6802 case Token.READONLY:
6814 case Token.STACKALLOC:
6815 return "stackalloc";
6832 case Token.UNCHECKED:
6840 case Token.VOLATILE:
6848 case Token.REFVALUE:
6849 return "__refvalue";
6859 case Token.FROM_FIRST:
6877 case Token.ASCENDING:
6879 case Token.DESCENDING:
6880 return "descending";
6887 case Token.OPEN_BRACE:
6889 case Token.CLOSE_BRACE:
6891 case Token.OPEN_BRACKET:
6892 case Token.OPEN_BRACKET_EXPR:
6894 case Token.CLOSE_BRACKET:
6896 case Token.OPEN_PARENS_CAST:
6897 case Token.OPEN_PARENS_LAMBDA:
6898 case Token.OPEN_PARENS:
6900 case Token.CLOSE_PARENS:
6906 case Token.DEFAULT_COLON:
6910 case Token.SEMICOLON:
6921 case Token.BITWISE_AND:
6922 case Token.BITWISE_OR:
6929 case Token.OP_SHIFT_LEFT:
6930 case Token.OP_SHIFT_RIGHT:
6938 case Token.OP_COALESCING:
6939 case Token.OP_MULT_ASSIGN:
6940 case Token.OP_DIV_ASSIGN:
6941 case Token.OP_MOD_ASSIGN:
6942 case Token.OP_ADD_ASSIGN:
6943 case Token.OP_SUB_ASSIGN:
6944 case Token.OP_SHIFT_LEFT_ASSIGN:
6945 case Token.OP_SHIFT_RIGHT_ASSIGN:
6946 case Token.OP_AND_ASSIGN:
6947 case Token.OP_XOR_ASSIGN:
6948 case Token.OP_OR_ASSIGN:
6949 return "<operator>";
6971 case Token.OP_GENERICS_LT:
6972 case Token.GENERIC_DIMENSION:
6974 case Token.OP_GENERICS_GT:
6977 case Token.INTERR_NULLABLE:
6979 case Token.DOUBLE_COLON:
6983 case Token.IDENTIFIER:
6984 return "identifier";
6987 return "end-of-file";
6989 // All of these are internal.
6992 case Token.FIRST_KEYWORD:
6993 case Token.EVAL_COMPILATION_UNIT_PARSER:
6994 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6995 case Token.EVAL_STATEMENT_PARSER:
6996 case Token.LAST_KEYWORD:
6997 case Token.GENERATE_COMPLETION:
6998 case Token.COMPLETE_COMPLETION:
6999 return "<internal>";
7001 // A bit more robust.
7003 return yyNames [token];