3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.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-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
39 All = Ref | Out | This | Params | Arglist | DefaultValue | ReadOnly,
40 PrimaryConstructor = Ref | Out | Params | DefaultValue
43 static readonly object ModifierNone = 0;
44 static readonly object RefStructToken = new object ();
45 static readonly object RefPartialStructToken = new object ();
47 NamespaceContainer current_namespace;
48 TypeContainer current_container;
49 TypeDefinition current_type;
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 BlockVariable 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;
81 /// An out-of-band stack.
83 Stack<object> oob_stack;
86 /// Controls the verbosity of the errors produced by the parser
88 int yacc_verbose_flag;
91 /// Used by the interactive shell, flags whether EOF was reached
92 /// and an error was produced
94 public bool UnexpectedEOF;
99 readonly CompilationSourceFile file;
102 /// Temporary Xml documentation cache.
103 /// For enum types, we need one more temporary store.
106 string enumTypeComment;
108 /// Current attribute target
109 string current_attr_target;
111 ParameterModifierType valid_param_mod;
113 bool default_parameter_used;
115 /// When using the interactive parser, this holds the
116 /// resulting expression
117 public Class InteractiveResult;
120 // Keeps track of global data changes to undo on parser error
124 bool? interactive_async;
126 Stack<Linq.QueryBlock> linq_clause_blocks;
128 ModuleContainer module;
130 readonly CompilerContext compiler;
131 readonly LanguageVersion lang_version;
132 readonly bool doc_support;
133 readonly CompilerSettings settings;
134 readonly Report report;
137 // Instead of allocating carrier array everytime we
138 // share the bucket for very common constructs which can never
141 List<Parameter> parameters_bucket;
144 // Full AST support members
147 List<Tuple<Modifiers, Location>> mod_locations;
148 Stack<Location> location_stack;
152 %token NONE /* This token is never returned by our lexer */
153 %token ERROR // This is used not by the parser, but by the tokenizer.
157 *These are the C# keywords
257 %token INTERR_NULLABLE
264 %token INTERR_OPERATOR
266 %token INTERPOLATED_STRING
267 %token INTERPOLATED_STRING_END
270 /* C# keywords which are not really keywords */
276 /* C# single character operators/punctuation. */
304 /* C# multi-character operators. */
309 %token OP_SHIFT_RIGHT
316 %token OP_MULT_ASSIGN
321 %token OP_SHIFT_LEFT_ASSIGN
322 %token OP_SHIFT_RIGHT_ASSIGN
329 /* Generics <,> tokens */
330 %token OP_GENERICS_LT
331 %token OP_GENERICS_LT_DECL
332 %token OP_GENERICS_GT
337 %token OPEN_PARENS_LAMBDA
338 %token OPEN_PARENS_CAST
339 %token GENERIC_DIMENSION
341 %token OPEN_BRACKET_EXPR
342 %token OPEN_PARENS_DECONSTRUCT
346 // Make the parser go into eval mode parsing (statements and compilation units).
347 %token EVAL_STATEMENT_PARSER
348 %token EVAL_COMPILATION_UNIT_PARSER
349 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
354 // This token is generated to trigger the completion engine at this point
356 %token GENERATE_COMPLETION
359 // This token is return repeatedly after the first GENERATE_COMPLETION
360 // token is produced and before the final EOF
362 %token COMPLETE_COMPLETION
364 /* Add precedence rules to solve dangling else s/r conflict */
368 /* Define the operator tokens and their precedences */
376 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
378 %left STAR DIV PERCENT
379 %right BANG CARRET UMINUS
380 %nonassoc OP_INC OP_DEC
382 %left OPEN_BRACKET OPEN_BRACE
385 %start compilation_unit
389 : outer_declaration opt_EOF
391 Lexer.check_incorrect_doc_comment ();
393 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
394 | documentation_parsing
398 : opt_extern_alias_directives opt_using_directives
399 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
402 Attributes attrs = (Attributes) $4;
403 report.Error (1730, attrs.Attrs [0].Location,
404 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
406 current_namespace.UnattachedAttributes = attrs;
409 | opt_extern_alias_directives opt_using_directives attribute_sections
411 Attributes attrs = (Attributes) $3;
413 foreach (var a in attrs.Attrs) {
414 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
417 if (a.ExplicitTarget == null)
418 report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
422 module.AddAttributes ((Attributes) $3, current_namespace);
426 if (yyToken == Token.EXTERN_ALIAS)
427 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
429 Error_SyntaxError (yyToken);
438 extern_alias_directives
439 : extern_alias_directive
440 | extern_alias_directives extern_alias_directive
443 extern_alias_directive
444 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
446 var lt = (LocatedToken) $2;
449 syntax_error (lt.Location, "`alias' expected");
451 if (lang_version == LanguageVersion.ISO_1)
452 FeatureIsNotAvailable (lt.Location, "external alias");
454 lt = (LocatedToken) $3;
455 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
456 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
459 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
460 current_namespace.AddUsing (na);
462 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
467 Error_SyntaxError (yyToken);
473 | using_directives using_directive
480 Lexer.doc_state = XmlCommentState.Allowed;
485 : USING opt_static namespace_or_type_expr SEMICOLON
489 if (lang_version <= LanguageVersion.V_5)
490 FeatureIsNotAvailable (GetLocation ($2), "using static");
492 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
493 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
495 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
496 lbag.AddLocation (uc, GetLocation ($4));
499 current_namespace.AddUsing (uc);
501 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
503 var lt = (LocatedToken) $3;
504 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
505 report.Warning (440, 2, lt.Location,
506 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
510 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
513 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
514 current_namespace.AddUsing (un);
516 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
520 Error_SyntaxError (yyToken);
531 // Strictly speaking, namespaces don't have attributes but
532 // we parse global attributes along with namespace declarations and then
535 namespace_declaration
536 : opt_attributes NAMESPACE namespace_name
538 Attributes attrs = (Attributes) $1;
539 var name = (MemberName) $3;
541 bool valid_global_attrs = true;
542 if ((current_namespace.DeclarationFound || current_namespace != file)) {
543 valid_global_attrs = false;
545 foreach (var a in attrs.Attrs) {
546 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
549 valid_global_attrs = false;
554 if (!valid_global_attrs)
555 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
558 module.AddAttributes (attrs, current_namespace);
560 var ns = new NamespaceContainer (name, current_namespace);
561 current_namespace.AddTypeContainer (ns);
562 current_container = current_namespace = ns;
567 Lexer.doc_state = XmlCommentState.Allowed;
569 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
572 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
574 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
576 current_container = current_namespace = current_namespace.Parent;
578 | opt_attributes NAMESPACE namespace_name
580 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
582 var name = (MemberName) $3;
583 var ns = new NamespaceContainer (name, current_namespace);
584 lbag.AddLocation (ns, GetLocation ($2));
585 current_namespace.AddTypeContainer (ns);
594 Error_SyntaxError (yyToken);
602 var lt = (LocatedToken) $1;
603 $$ = new MemberName (lt.Value, lt.Location);
605 | namespace_name DOT IDENTIFIER
607 var lt = (LocatedToken) $3;
608 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
609 lbag.AddLocation ($$, GetLocation ($2));
613 Error_SyntaxError (yyToken);
614 $$ = new MemberName ("<invalid>", lexer.Location);
633 opt_extern_alias_directives
635 | extern_alias_directives
638 opt_namespace_or_type_declarations
640 | namespace_or_type_declarations
643 namespace_or_type_declarations
644 : namespace_or_type_declaration
645 | namespace_or_type_declarations namespace_or_type_declaration
648 namespace_or_type_declaration
652 TypeContainer ds = (TypeContainer)$1;
654 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
655 report.Error (1527, ds.Location,
656 "Namespace elements cannot be explicitly declared as private, protected, protected internal, or private protected");
659 // Here is a trick, for explicit attributes we don't know where they belong to until
660 // we parse succeeding declaration hence we parse them as normal and re-attach them
661 // when we know whether they are global (assembly:, module:) or local (type:).
662 if (ds.OptAttributes != null) {
663 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
666 current_namespace.DeclarationFound = true;
668 | namespace_declaration
670 current_namespace.DeclarationFound = true;
672 | attribute_sections CLOSE_BRACE {
673 current_namespace.UnattachedAttributes = (Attributes) $1;
674 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
682 | interface_declaration
684 | delegate_declaration
686 // Enable this when we have handled all errors, because this acts as a generic fallback
689 // Console.WriteLine ("Token=" + yyToken);
690 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
706 var sect = (List<Attribute>) $1;
707 $$ = new Attributes (sect);
709 | attribute_sections attribute_section
711 Attributes attrs = $1 as Attributes;
712 var sect = (List<Attribute>) $2;
714 attrs = new Attributes (sect);
715 else if (sect != null)
716 attrs.AddAttributes (sect);
724 PushLocation (GetLocation ($1));
725 lexer.parsing_attribute_section = true;
727 attribute_section_cont
729 lexer.parsing_attribute_section = false;
734 attribute_section_cont
735 : attribute_target COLON
737 current_attr_target = (string) $1;
738 if (current_attr_target == "assembly" || current_attr_target == "module") {
739 Lexer.check_incorrect_doc_comment ();
742 attribute_list opt_comma CLOSE_BRACKET
744 // when attribute target is invalid
745 if (current_attr_target == string.Empty)
746 $$ = new List<Attribute> (0);
750 lbag.InsertLocation ($$, 0, PopLocation ());
752 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
754 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
757 current_attr_target = null;
758 lexer.parsing_attribute_section = false;
760 | attribute_list opt_comma CLOSE_BRACKET
764 lbag.InsertLocation ($$, 0, PopLocation ());
766 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
768 lbag.AddLocation ($$, GetLocation($3));
773 Error_SyntaxError (yyToken);
775 var lt = (LocatedToken) $1;
776 var tne = new SimpleName (lt.Value, null, lt.Location);
778 $$ = new List<Attribute> () {
779 new Attribute (null, tne, null, GetLocation ($1), false)
784 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
785 Error_SyntaxError (yyToken);
794 var lt = (LocatedToken) $1;
795 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
797 | EVENT { $$ = "event"; }
798 | RETURN { $$ = "return"; }
804 $$ = new List<Attribute> (4) { (Attribute) $1 };
806 | attribute_list COMMA attribute
808 var attrs = (List<Attribute>) $1;
810 attrs.Add ((Attribute) $3);
811 lbag.AppendTo (attrs, GetLocation ($2));
821 ++lexer.parsing_block;
823 opt_attribute_arguments
825 --lexer.parsing_block;
827 var tne = (ATypeNameExpression) $1;
828 if (tne.HasTypeArguments) {
829 report.Error (404, tne.Location, "Attributes cannot be generic");
832 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
837 : namespace_or_type_expr
840 opt_attribute_arguments
841 : /* empty */ { $$ = null; }
842 | OPEN_PARENS attribute_arguments CLOSE_PARENS
850 : /* empty */ { $$ = null; }
851 | positional_or_named_argument
853 Arguments a = new Arguments (4);
854 a.Add ((Argument) $1);
855 $$ = new Arguments [] { a, null };
857 | named_attribute_argument
859 Arguments a = new Arguments (4);
860 a.Add ((Argument) $1);
861 $$ = new Arguments [] { null, a };
863 | attribute_arguments COMMA positional_or_named_argument
865 Arguments[] o = (Arguments[]) $1;
867 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
868 o [0] = new Arguments (4);
871 Arguments args = ((Arguments) o [0]);
872 if (lang_version < LanguageVersion.V_7_2 && args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
873 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
875 args.Add ((Argument) $3);
877 | attribute_arguments COMMA named_attribute_argument
879 Arguments[] o = (Arguments[]) $1;
881 o [1] = new Arguments (4);
884 ((Arguments) o [1]).Add ((Argument) $3);
888 positional_or_named_argument
891 $$ = new Argument ((Expression) $1);
896 Error_SyntaxError (yyToken);
901 named_attribute_argument
904 ++lexer.parsing_block;
908 --lexer.parsing_block;
909 var lt = (LocatedToken) $1;
910 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
911 lbag.AddLocation ($$, GetLocation($2));
916 : identifier_inside_body COLON opt_named_modifier named_argument_expr
918 if (lang_version <= LanguageVersion.V_3)
919 FeatureIsNotAvailable (GetLocation ($1), "named argument");
921 // Avoid boxing in common case (no modifier)
922 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
924 var lt = (LocatedToken) $1;
925 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
926 lbag.AddLocation ($$, GetLocation($2));
928 | identifier_inside_body COLON OUT named_argument_expr_or_out_variable_declaration
930 if (lang_version <= LanguageVersion.V_3)
931 FeatureIsNotAvailable (GetLocation ($1), "named argument");
933 var lt = (LocatedToken) $1;
934 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, Argument.AType.Out);
935 lbag.AddLocation ($$, GetLocation($2));
940 : expression_or_error
943 named_argument_expr_or_out_variable_declaration
944 : expression_or_error
945 | out_variable_declaration
949 : /* empty */ { $$ = null; }
952 $$ = Argument.AType.Ref;
956 opt_class_member_declarations
958 | class_member_declarations
961 class_member_declarations
962 : class_member_declaration
964 lexer.parsing_modifiers = true;
965 lexer.parsing_block = 0;
967 | class_member_declarations class_member_declaration
969 lexer.parsing_modifiers = true;
970 lexer.parsing_block = 0;
974 class_member_declaration
975 : constant_declaration
978 | property_declaration
980 | indexer_declaration
981 | operator_declaration
982 | constructor_declaration
983 | primary_constructor_body
984 | destructor_declaration
986 | attributes_without_members
990 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
991 GetSymbolName (yyToken));
993 lexer.parsing_generic_declaration = false;
997 primary_constructor_body
1000 current_local_parameters = current_type.PrimaryConstructorParameters;
1001 if (current_local_parameters == null) {
1002 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
1003 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1006 ++lexer.parsing_block;
1007 start_block (GetLocation ($1));
1009 opt_statement_list block_end
1011 current_local_parameters = null;
1012 var t = current_type as ClassOrStruct;
1014 var b = (ToplevelBlock) $4;
1015 if (t.PrimaryConstructorBlock != null) {
1016 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
1018 t.PrimaryConstructorBlock = b;
1031 if (lang_version < LanguageVersion.V_7_2) {
1032 FeatureIsNotAvailable (GetLocation ($1), "ref structs");
1035 $$ = RefStructToken;
1037 | REF_PARTIAL STRUCT
1039 if (lang_version < LanguageVersion.V_7_2) {
1040 FeatureIsNotAvailable (GetLocation ($1), "ref structs");
1043 $$ = RefPartialStructToken;
1052 type_declaration_name
1054 var mods = (Modifiers) $2;
1055 if ((mods & Modifiers.READONLY) != 0 && lang_version < LanguageVersion.V_7_2) {
1056 FeatureIsNotAvailable (GetLocation ($4), "readonly structs");
1059 mods |= Modifiers.REF;
1060 if ($4 == RefPartialStructToken) {
1061 mods |= Modifiers.PARTIAL;
1066 lexer.ConstraintsParsing = true;
1067 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1068 push_current_container (new Struct (current_container, (MemberName) $5, mods, (Attributes) $1), $3);
1070 opt_primary_parameters
1072 opt_type_parameter_constraints_clauses
1074 valid_param_mod = 0;
1075 lexer.ConstraintsParsing = false;
1078 current_type.PrimaryConstructorParameters = (ParametersCompiled) $7;
1081 current_container.SetConstraints ((List<Constraints>) $9);
1084 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1086 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1088 lexer.parsing_modifiers = true;
1093 Lexer.doc_state = XmlCommentState.Allowed;
1095 opt_class_member_declarations CLOSE_BRACE
1097 --lexer.parsing_declaration;
1099 Lexer.doc_state = XmlCommentState.Allowed;
1104 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
1106 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
1108 $$ = pop_current_class ();
1110 | opt_attributes opt_modifiers opt_partial struct_keyword error
1112 Error_SyntaxError (yyToken);
1116 constant_declaration
1119 CONST type IDENTIFIER
1121 var lt = (LocatedToken) $5;
1122 var mod = (Modifiers) $2;
1123 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1124 current_type.AddMember (current_field);
1126 if ((mod & Modifiers.STATIC) != 0) {
1127 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1132 constant_initializer opt_constant_declarators SEMICOLON
1135 current_field.DocComment = Lexer.consume_doc_comment ();
1136 Lexer.doc_state = XmlCommentState.Allowed;
1139 current_field.Initializer = (ConstInitializer) $7;
1140 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1141 current_field = null;
1147 Error_SyntaxError (yyToken);
1149 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1153 opt_constant_declarators
1155 | constant_declarators
1158 constant_declarators
1159 : constant_declarator
1161 current_field.AddDeclarator ((FieldDeclarator) $1);
1163 | constant_declarators constant_declarator
1165 current_field.AddDeclarator ((FieldDeclarator) $2);
1170 : COMMA IDENTIFIER constant_initializer
1172 var lt = (LocatedToken) $2;
1173 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1174 lbag.AddLocation ($$, GetLocation ($1));
1178 constant_initializer
1181 ++lexer.parsing_block;
1183 constant_initializer_expr
1185 --lexer.parsing_block;
1186 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1190 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1195 constant_initializer_expr
1196 : constant_expression
1203 ref_member_type IDENTIFIER
1205 lexer.parsing_generic_declaration = false;
1207 FullNamedExpression type = (FullNamedExpression) $3;
1208 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1209 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1211 var lt = (LocatedToken) $4;
1212 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1213 current_type.AddField (current_field);
1216 opt_field_initializer
1217 opt_field_declarators
1221 current_field.DocComment = Lexer.consume_doc_comment ();
1222 Lexer.doc_state = XmlCommentState.Allowed;
1225 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1227 current_field = null;
1231 FIXED simple_type IDENTIFIER
1233 if (lang_version < LanguageVersion.ISO_2)
1234 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1236 var lt = (LocatedToken) $5;
1237 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1238 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1240 current_type.AddField (current_field);
1242 fixed_field_size opt_fixed_field_declarators SEMICOLON
1245 current_field.DocComment = Lexer.consume_doc_comment ();
1246 Lexer.doc_state = XmlCommentState.Allowed;
1249 current_field.Initializer = (ConstInitializer) $7;
1250 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1252 current_field = null;
1256 FIXED simple_type error
1259 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1263 opt_field_initializer
1267 ++lexer.parsing_block;
1268 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1269 start_block (GetLocation ($1));
1271 variable_initializer
1273 --lexer.parsing_block;
1274 current_field.Initializer = (Expression) $3;
1275 lbag.AppendToMember (current_field, GetLocation ($1));
1276 end_block (lexer.Location);
1277 current_local_parameters = null;
1281 opt_field_declarators
1289 current_field.AddDeclarator ((FieldDeclarator) $1);
1291 | field_declarators field_declarator
1293 current_field.AddDeclarator ((FieldDeclarator) $2);
1300 var lt = (LocatedToken) $2;
1301 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1302 lbag.AddLocation ($$, GetLocation ($1));
1304 | COMMA IDENTIFIER ASSIGN
1306 ++lexer.parsing_block;
1308 variable_initializer
1310 --lexer.parsing_block;
1311 var lt = (LocatedToken) $2;
1312 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1313 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1317 opt_fixed_field_declarators
1319 | fixed_field_declarators
1322 fixed_field_declarators
1323 : fixed_field_declarator
1325 current_field.AddDeclarator ((FieldDeclarator) $1);
1327 | fixed_field_declarators fixed_field_declarator
1329 current_field.AddDeclarator ((FieldDeclarator) $2);
1333 fixed_field_declarator
1334 : COMMA IDENTIFIER fixed_field_size
1336 var lt = (LocatedToken) $2;
1337 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1338 lbag.AddLocation ($$, GetLocation ($1));
1345 ++lexer.parsing_block;
1347 expression CLOSE_BRACKET
1349 --lexer.parsing_block;
1350 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1351 lbag.AddLocation ($$, GetLocation ($4));
1353 | OPEN_BRACKET error
1355 report.Error (443, lexer.Location, "Value or constant expected");
1360 variable_initializer
1365 // It has to be here for the parent to safely restore artificial block
1366 Error_SyntaxError (yyToken);
1375 Lexer.doc_state = XmlCommentState.NotAllowed;
1377 // Was added earlier in the case of body being eof for full ast
1381 Method method = (Method) $1;
1382 method.Block = (ToplevelBlock) $3;
1383 async_block = false;
1385 if (method.Block == null) {
1386 method.ParameterInfo.CheckParameters (method);
1388 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1389 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1390 method.GetSignatureForError ());
1393 if (current_container.Kind == MemberKind.Interface) {
1394 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1395 method.GetSignatureForError ());
1399 current_local_parameters = null;
1402 Lexer.doc_state = XmlCommentState.Allowed;
1413 lexer.parsing_generic_declaration = true;
1417 if (lang_version < LanguageVersion.V_7) {
1418 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
1421 $$ = new ReferenceTypeExpr ((FullNamedExpression) $3, GetLocation ($1));
1425 lexer.parsing_generic_declaration = true;
1429 if (lang_version < LanguageVersion.V_7_2) {
1430 FeatureIsNotAvailable (GetLocation ($2), "readonly references");
1433 $$ = new ReferenceTypeExpr ((FullNamedExpression) $4, true, GetLocation ($1));
1441 method_declaration_name OPEN_PARENS
1443 valid_param_mod = ParameterModifierType.All;
1445 opt_formal_parameter_list CLOSE_PARENS
1447 valid_param_mod = 0;
1448 MemberName name = (MemberName) $4;
1449 current_local_parameters = (ParametersCompiled) $7;
1451 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1452 name, current_local_parameters, (Attributes) $1);
1454 current_type.AddMember (method);
1456 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1459 method.DocComment = Lexer.consume_doc_comment ();
1461 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1465 lexer.ConstraintsParsing = true;
1467 opt_type_parameter_constraints_clauses
1469 lexer.ConstraintsParsing = false;
1472 var method = (Method) $9;
1473 method.SetConstraints ((List<Constraints>) $10);
1483 lexer.parsing_generic_declaration = true;
1485 method_declaration_name
1488 lexer.parsing_generic_declaration = false;
1489 valid_param_mod = ParameterModifierType.All;
1491 opt_formal_parameter_list CLOSE_PARENS
1493 lexer.ConstraintsParsing = true;
1495 opt_type_parameter_constraints_clauses
1497 lexer.ConstraintsParsing = false;
1498 valid_param_mod = 0;
1500 MemberName name = (MemberName) $6;
1501 current_local_parameters = (ParametersCompiled) $9;
1503 var modifiers = (Modifiers) $2;
1504 modifiers |= Modifiers.PARTIAL;
1506 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1507 modifiers, name, current_local_parameters, (Attributes) $1);
1509 current_type.AddMember (method);
1511 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1514 method.SetConstraints ((List<Constraints>) $12);
1517 method.DocComment = Lexer.consume_doc_comment ();
1519 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1520 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1526 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1528 MemberName name = (MemberName) $5;
1529 report.Error (1585, name.Location,
1530 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1532 var method = Method.Create (current_type, (FullNamedExpression) $3,
1533 0, name, (ParametersCompiled) $7, (Attributes) $1);
1535 current_type.AddMember (method);
1537 current_local_parameters = (ParametersCompiled) $7;
1540 method.DocComment = Lexer.consume_doc_comment ();
1547 method_declaration_name error
1549 Error_SyntaxError (yyToken);
1550 current_local_parameters = ParametersCompiled.Undefined;
1552 MemberName name = (MemberName) $4;
1553 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1554 name, current_local_parameters, (Attributes) $1);
1556 current_type.AddMember (method);
1559 method.DocComment = Lexer.consume_doc_comment ();
1568 | SEMICOLON { $$ = null; }
1577 | SEMICOLON { current_block = null; $$ = null; }
1580 if (lang_version < LanguageVersion.V_7) {
1581 FeatureIsNotAvailable (GetLocation ($1), "expression body constructor");
1584 ++lexer.parsing_block;
1586 expression SEMICOLON
1588 lexer.parsing_block = 0;
1589 current_block.AddStatement (CreateExpressionBodiedStatement ((Expression) $3));
1590 var b = end_block (GetLocation ($4));
1591 b.IsCompilerGenerated = true;
1593 current_block = null;
1600 if (lang_version < LanguageVersion.V_6) {
1601 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1604 ++lexer.parsing_block;
1605 start_block (GetLocation ($1));
1607 lambda_arrow_expression SEMICOLON
1609 lexer.parsing_block = 0;
1610 current_block.AddStatement (CreateExpressionBodiedStatement ((Expression) $3));
1611 var b = end_block (GetLocation ($4));
1612 b.IsCompilerGenerated = true;
1617 opt_formal_parameter_list
1618 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1619 | formal_parameter_list
1622 formal_parameter_list
1625 var pars_list = (List<Parameter>) $1;
1626 $$ = new ParametersCompiled (pars_list.ToArray ());
1628 | fixed_parameters COMMA parameter_array
1630 var pars_list = (List<Parameter>) $1;
1631 pars_list.Add ((Parameter) $3);
1633 $$ = new ParametersCompiled (pars_list.ToArray ());
1635 | fixed_parameters COMMA arglist_modifier
1637 var pars_list = (List<Parameter>) $1;
1638 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1639 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1641 | parameter_array COMMA error
1644 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1646 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1648 | fixed_parameters COMMA parameter_array COMMA error
1651 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1653 var pars_list = (List<Parameter>) $1;
1654 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1656 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1658 | arglist_modifier COMMA error
1660 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1662 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1664 | fixed_parameters COMMA ARGLIST COMMA error
1666 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1668 var pars_list = (List<Parameter>) $1;
1669 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1671 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1675 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1679 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1683 Error_SyntaxError (yyToken);
1684 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1691 parameters_bucket.Clear ();
1692 Parameter p = (Parameter) $1;
1693 parameters_bucket.Add (p);
1695 default_parameter_used = p.HasDefaultValue;
1696 $$ = parameters_bucket;
1698 | fixed_parameters COMMA fixed_parameter
1700 var pars = (List<Parameter>) $1;
1701 Parameter p = (Parameter) $3;
1703 if (p.HasExtensionMethodModifier)
1704 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1705 else if (!p.HasDefaultValue && default_parameter_used)
1706 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1708 default_parameter_used |= p.HasDefaultValue;
1711 lbag.AddLocation (p, GetLocation ($2));
1720 opt_parameter_modifier
1722 identifier_inside_body
1724 var lt = (LocatedToken) $4;
1725 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1728 opt_parameter_modifier
1730 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1732 var lt = (LocatedToken) $4;
1733 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1734 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1736 | attribute_sections error
1738 Error_SyntaxError (yyToken);
1739 Location l = GetLocation ($2);
1740 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1743 opt_parameter_modifier
1747 Error_SyntaxError (yyToken);
1748 Location l = GetLocation ($4);
1749 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1752 opt_parameter_modifier
1754 identifier_inside_body
1757 ++lexer.parsing_block;
1761 --lexer.parsing_block;
1762 if (lang_version <= LanguageVersion.V_3) {
1763 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1766 Parameter.Modifier mod = (Parameter.Modifier) $2;
1767 if (mod != Parameter.Modifier.NONE) {
1769 case Parameter.Modifier.REF:
1770 case Parameter.Modifier.OUT:
1771 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1772 Parameter.GetModifierSignature (mod));
1775 case Parameter.Modifier.This:
1776 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1777 Parameter.GetModifierSignature (mod));
1780 throw new NotImplementedException (mod.ToString ());
1783 mod = Parameter.Modifier.NONE;
1786 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1787 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1789 var lt = (LocatedToken) $4;
1790 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1791 lbag.AddLocation ($$, GetLocation ($5));
1794 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1798 opt_parameter_modifier
1799 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1800 | parameter_modifiers
1804 : parameter_modifier
1808 | parameter_modifiers parameter_modifier
1810 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1811 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1812 if (((Parameter.Modifier)$1 & p2) == p2) {
1813 Error_DuplicateParameterModifier (lexer.Location, p2);
1814 } else if ((mod & ~(Parameter.Modifier.This | Parameter.Modifier.ReadOnly)) == 0) {
1817 switch (mod & ~Parameter.Modifier.This) {
1818 case Parameter.Modifier.REF:
1819 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1821 case Parameter.Modifier.OUT:
1822 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1825 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1836 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1837 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1839 $$ = Parameter.Modifier.REF;
1843 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1844 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1846 $$ = Parameter.Modifier.OUT;
1850 if ((valid_param_mod & ParameterModifierType.This) == 0)
1851 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1853 if (lang_version <= LanguageVersion.ISO_2)
1854 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1856 $$ = Parameter.Modifier.This;
1860 if (lang_version < LanguageVersion.V_7_2)
1861 FeatureIsNotAvailable (GetLocation ($1), "readonly references");
1863 $$ = Parameter.Modifier.ReadOnly;
1868 : opt_attributes params_modifier type IDENTIFIER
1870 var lt = (LocatedToken) $4;
1871 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1873 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1875 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1877 var lt = (LocatedToken) $4;
1878 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1880 | opt_attributes params_modifier type error
1882 Error_SyntaxError (yyToken);
1884 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1891 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1892 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1894 | PARAMS parameter_modifier
1896 Parameter.Modifier mod = (Parameter.Modifier)$2;
1897 if ((mod & Parameter.Modifier.This) != 0) {
1898 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1900 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref, out or in");
1903 | PARAMS params_modifier
1905 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1912 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1913 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1917 property_declaration
1921 member_declaration_name
1923 lexer.parsing_generic_declaration = false;
1925 tmpComment = Lexer.consume_doc_comment ();
1929 var type = (FullNamedExpression) $3;
1930 current_property = new Property (current_type, type, (Modifiers) $2,
1931 (MemberName) $4, (Attributes) $1);
1933 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1934 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1936 current_type.AddMember (current_property);
1937 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1939 lexer.PropertyParsing = true;
1941 accessor_declarations
1943 lexer.PropertyParsing = false;
1946 current_property.DocComment = ConsumeStoredComment ();
1948 if ($3 is ReferenceTypeExpr) {
1949 if (current_property.Get == null) {
1950 report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
1953 if (current_property.Set != null) {
1954 report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
1960 lbag.AppendToMember (current_property, GetLocation ($10));
1961 lexer.parsing_modifiers = true;
1963 opt_property_initializer
1965 current_property = null;
1970 member_declaration_name
1972 lexer.parsing_generic_declaration = false;
1974 tmpComment = Lexer.consume_doc_comment ();
1975 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1979 var type = (FullNamedExpression) $3;
1980 var property = new Property (current_type, type, (Modifiers) $2,
1981 (MemberName) $4, (Attributes) $1);
1983 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1984 property.Get.Block = (ToplevelBlock) $6;
1986 if (current_container.Kind == MemberKind.Interface) {
1987 report.Error (531, property.Get.Block.StartLocation,
1988 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1991 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1992 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1995 property.DocComment = ConsumeStoredComment ();
1997 current_type.AddMember (property);
1999 current_local_parameters = null;
2003 opt_property_initializer
2007 ++lexer.parsing_block;
2008 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2009 start_block (GetLocation ($1));
2011 property_initializer SEMICOLON
2013 --lexer.parsing_block;
2014 ((Property)current_property).Initializer = (Expression) $3;
2015 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
2016 end_block (GetLocation ($4));
2017 current_local_parameters = null;
2020 Lexer.doc_state = XmlCommentState.Allowed;
2024 property_initializer
2030 : opt_attributes opt_modifiers
2031 ref_member_type indexer_declaration_name OPEN_BRACKET
2033 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue | ParameterModifierType.ReadOnly;
2035 opt_formal_parameter_list CLOSE_BRACKET
2037 valid_param_mod = 0;
2038 var type = (FullNamedExpression) $3;
2039 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
2041 current_property = indexer;
2043 current_type.AddIndexer (indexer);
2044 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
2046 if (type.Type != null && type.Type.Kind == MemberKind.Void)
2047 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
2049 if (indexer.ParameterInfo.IsEmpty) {
2050 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
2054 tmpComment = Lexer.consume_doc_comment ();
2055 Lexer.doc_state = XmlCommentState.Allowed;
2058 lexer.PropertyParsing = true;
2059 current_local_parameters = (ParametersCompiled) $7;
2063 lexer.PropertyParsing = false;
2064 current_local_parameters = null;
2066 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
2067 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
2070 current_property.DocComment = ConsumeStoredComment ();
2072 if ($3 is ReferenceTypeExpr) {
2073 if (current_property.Get == null) {
2074 report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
2077 if (current_property.Set != null) {
2078 report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
2082 current_property = null;
2087 : OPEN_BRACE accessor_declarations CLOSE_BRACE
2089 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
2093 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
2094 current_property.Get.Block = (ToplevelBlock) $1;
2098 accessor_declarations
2099 : get_accessor_declaration
2100 | get_accessor_declaration accessor_declarations
2101 | set_accessor_declaration
2102 | set_accessor_declaration accessor_declarations
2105 if (yyToken == Token.CLOSE_BRACE) {
2106 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
2108 if (yyToken == Token.SEMICOLON)
2109 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
2111 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
2116 get_accessor_declaration
2117 : opt_attributes opt_modifiers GET
2119 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2120 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2123 if (current_property.Get != null) {
2124 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2127 if (current_property is Indexer) {
2128 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
2129 (Attributes) $1, GetLocation ($3));
2131 current_property.Get = new Property.GetMethod (current_property,
2132 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2135 current_local_parameters = current_property.Get.ParameterInfo;
2136 lbag.AddMember (current_property.Get, mod_locations);
2137 lexer.PropertyParsing = false;
2142 current_property.Get.Block = (ToplevelBlock) $5;
2144 if (current_container.Kind == MemberKind.Interface) {
2145 report.Error (531, current_property.Get.Block.StartLocation,
2146 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2150 current_local_parameters = null;
2151 lexer.PropertyParsing = true;
2154 if (Lexer.doc_state == XmlCommentState.Error)
2155 Lexer.doc_state = XmlCommentState.NotAllowed;
2159 set_accessor_declaration
2160 : opt_attributes opt_modifiers SET
2162 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2163 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2166 if (current_property.Set != null) {
2167 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2170 if (current_property is Indexer) {
2171 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2172 ParametersCompiled.MergeGenerated (compiler,
2173 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2174 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2176 (Attributes) $1, GetLocation ($3));
2178 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2179 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2180 (Attributes) $1, GetLocation ($3));
2183 current_local_parameters = current_property.Set.ParameterInfo;
2184 lbag.AddMember (current_property.Set, mod_locations);
2185 lexer.PropertyParsing = false;
2190 current_property.Set.Block = (ToplevelBlock) $5;
2192 if (current_container.Kind == MemberKind.Interface) {
2193 report.Error (531, current_property.Set.Block.StartLocation,
2194 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2198 current_local_parameters = null;
2199 lexer.PropertyParsing = true;
2202 && Lexer.doc_state == XmlCommentState.Error)
2203 Lexer.doc_state = XmlCommentState.NotAllowed;
2211 if (lang_version < LanguageVersion.V_7) {
2212 FeatureIsNotAvailable (GetLocation ($1), "expression body property accessor");
2222 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2228 interface_declaration
2235 type_declaration_name
2237 lexer.ConstraintsParsing = true;
2238 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2239 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2242 opt_type_parameter_constraints_clauses
2244 lexer.ConstraintsParsing = false;
2247 current_container.SetConstraints ((List<Constraints>) $9);
2250 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2251 Lexer.doc_state = XmlCommentState.Allowed;
2254 lexer.parsing_modifiers = true;
2256 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2258 --lexer.parsing_declaration;
2260 Lexer.doc_state = XmlCommentState.Allowed;
2265 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2267 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2269 $$ = pop_current_class ();
2271 | opt_attributes opt_modifiers opt_partial INTERFACE error
2273 Error_SyntaxError (yyToken);
2277 opt_interface_member_declarations
2279 | interface_member_declarations
2282 interface_member_declarations
2283 : interface_member_declaration
2285 lexer.parsing_modifiers = true;
2286 lexer.parsing_block = 0;
2288 | interface_member_declarations interface_member_declaration
2290 lexer.parsing_modifiers = true;
2291 lexer.parsing_block = 0;
2295 interface_member_declaration
2296 : constant_declaration
2298 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2302 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2304 | method_declaration
2305 | property_declaration
2307 | indexer_declaration
2308 | operator_declaration
2310 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2312 | constructor_declaration
2314 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2318 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2322 operator_declaration
2323 : opt_attributes opt_modifiers operator_declarator
2328 OperatorDeclaration decl = (OperatorDeclaration) $3;
2330 Operator op = new Operator (
2331 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2332 current_local_parameters,
2333 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2335 if (op.Block == null)
2336 op.ParameterInfo.CheckParameters (op);
2339 op.DocComment = tmpComment;
2340 Lexer.doc_state = XmlCommentState.Allowed;
2343 // Note again, checking is done in semantic analysis
2344 current_type.AddOperator (op);
2346 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2349 current_local_parameters = null;
2354 : type_expression_or_array
2357 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2358 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2363 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2365 valid_param_mod = ParameterModifierType.DefaultValue | ParameterModifierType.ReadOnly;
2366 if ((Operator.OpType) $3 == Operator.OpType.Is)
2367 valid_param_mod |= ParameterModifierType.Out;
2369 opt_formal_parameter_list CLOSE_PARENS
2371 valid_param_mod = 0;
2373 Location loc = GetLocation ($2);
2374 Operator.OpType op = (Operator.OpType) $3;
2375 current_local_parameters = (ParametersCompiled)$6;
2377 int p_count = current_local_parameters.Count;
2379 if (op == Operator.OpType.Addition)
2380 op = Operator.OpType.UnaryPlus;
2381 else if (op == Operator.OpType.Subtraction)
2382 op = Operator.OpType.UnaryNegation;
2385 if (IsUnaryOperator (op)) {
2387 report.Error (1020, loc, "Overloadable binary operator expected");
2388 } else if (p_count != 1) {
2389 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2390 Operator.GetName (op));
2392 } else if (op == Operator.OpType.Is) {
2393 // TODO: Special checks for is operator
2396 report.Error (1019, loc, "Overloadable unary operator expected");
2397 } else if (p_count != 2) {
2398 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2399 Operator.GetName (op));
2404 tmpComment = Lexer.consume_doc_comment ();
2405 Lexer.doc_state = XmlCommentState.NotAllowed;
2408 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2409 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2411 | conversion_operator_declarator
2414 overloadable_operator
2416 : BANG { $$ = Operator.OpType.LogicalNot; }
2417 | TILDE { $$ = Operator.OpType.OnesComplement; }
2418 | OP_INC { $$ = Operator.OpType.Increment; }
2419 | OP_DEC { $$ = Operator.OpType.Decrement; }
2420 | TRUE { $$ = Operator.OpType.True; }
2421 | FALSE { $$ = Operator.OpType.False; }
2422 // Unary and binary:
2423 | PLUS { $$ = Operator.OpType.Addition; }
2424 | MINUS { $$ = Operator.OpType.Subtraction; }
2426 | STAR { $$ = Operator.OpType.Multiply; }
2427 | DIV { $$ = Operator.OpType.Division; }
2428 | PERCENT { $$ = Operator.OpType.Modulus; }
2429 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2430 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2431 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2432 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2433 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2434 | OP_EQ { $$ = Operator.OpType.Equality; }
2435 | OP_NE { $$ = Operator.OpType.Inequality; }
2436 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2437 | OP_LT { $$ = Operator.OpType.LessThan; }
2438 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2439 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2442 if (lang_version != LanguageVersion.Experimental)
2443 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2445 $$ = Operator.OpType.Is;
2449 conversion_operator_declarator
2450 : IMPLICIT OPERATOR type OPEN_PARENS
2452 valid_param_mod = ParameterModifierType.DefaultValue | ParameterModifierType.ReadOnly;
2454 opt_formal_parameter_list CLOSE_PARENS
2456 valid_param_mod = 0;
2458 Location loc = GetLocation ($2);
2459 current_local_parameters = (ParametersCompiled)$6;
2461 if (current_local_parameters.Count != 1) {
2462 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2466 tmpComment = Lexer.consume_doc_comment ();
2467 Lexer.doc_state = XmlCommentState.NotAllowed;
2470 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2471 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2473 | EXPLICIT OPERATOR type OPEN_PARENS
2475 valid_param_mod = ParameterModifierType.DefaultValue | ParameterModifierType.ReadOnly;
2477 opt_formal_parameter_list CLOSE_PARENS
2479 valid_param_mod = 0;
2481 Location loc = GetLocation ($2);
2482 current_local_parameters = (ParametersCompiled)$6;
2484 if (current_local_parameters.Count != 1) {
2485 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2489 tmpComment = Lexer.consume_doc_comment ();
2490 Lexer.doc_state = XmlCommentState.NotAllowed;
2493 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2494 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2498 Error_SyntaxError (yyToken);
2499 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2500 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2504 Error_SyntaxError (yyToken);
2505 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2506 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2510 constructor_declaration
2511 : constructor_declarator
2514 Constructor c = (Constructor) $1;
2515 c.Block = (ToplevelBlock) $2;
2518 c.DocComment = ConsumeStoredComment ();
2520 current_local_parameters = null;
2522 Lexer.doc_state = XmlCommentState.Allowed;
2526 constructor_declarator
2532 tmpComment = Lexer.consume_doc_comment ();
2533 Lexer.doc_state = XmlCommentState.Allowed;
2536 valid_param_mod = ParameterModifierType.All;
2538 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2540 valid_param_mod = 0;
2541 current_local_parameters = (ParametersCompiled) $6;
2543 var lt = (LocatedToken) $3;
2544 var mods = (Modifiers) $2;
2545 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2547 if (lt.Value != current_container.MemberName.Name) {
2548 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2549 } else if ((mods & Modifiers.STATIC) != 0) {
2550 if (!current_local_parameters.IsEmpty) {
2551 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2552 c.GetSignatureForError ());
2555 if ((mods & Modifiers.AccessibilityMask) != 0){
2556 report.Error (515, c.Location,
2557 "`{0}': static constructor cannot have an access modifier",
2558 c.GetSignatureForError ());
2561 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2562 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2566 current_type.AddConstructor (c);
2567 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2571 // start block here, so possible anonymous methods inside
2572 // constructor initializer can get correct parent block
2574 start_block (lexer.Location);
2576 opt_constructor_initializer
2579 var c = (Constructor) $8;
2580 c.Initializer = (ConstructorInitializer) $9;
2583 report.Error (514, c.Location,
2584 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2585 c.GetSignatureForError ());
2593 opt_constructor_initializer
2595 | constructor_initializer
2598 constructor_initializer
2599 : COLON BASE OPEN_PARENS
2601 ++lexer.parsing_block;
2603 opt_argument_list CLOSE_PARENS
2605 --lexer.parsing_block;
2606 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2607 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2609 | COLON THIS OPEN_PARENS
2611 ++lexer.parsing_block;
2613 opt_argument_list CLOSE_PARENS
2615 --lexer.parsing_block;
2616 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2617 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2621 Error_SyntaxError (yyToken);
2622 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2623 lbag.AddLocation ($$, GetLocation ($1));
2627 Error_SyntaxError (yyToken);
2632 destructor_declaration
2633 : opt_attributes opt_modifiers TILDE
2636 tmpComment = Lexer.consume_doc_comment ();
2637 Lexer.doc_state = XmlCommentState.NotAllowed;
2640 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2642 IDENTIFIER OPEN_PARENS CLOSE_PARENS destructor_body
2644 var lt = (LocatedToken) $5;
2645 if (lt.Value != current_container.MemberName.Name){
2646 report.Error (574, lt.Location, "Name of destructor must match name of class");
2647 } else if (current_container.Kind != MemberKind.Class){
2648 report.Error (575, lt.Location, "Only class types can contain destructor");
2651 Destructor d = new Destructor (current_type, (Modifiers) $2,
2652 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2654 d.DocComment = ConsumeStoredComment ();
2656 d.Block = (ToplevelBlock) $8;
2657 current_type.AddMember (d);
2658 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2660 current_local_parameters = null;
2667 EVENT type member_declaration_name
2669 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2670 current_type.AddMember (current_event_field);
2672 if (current_event_field.MemberName.ExplicitInterface != null) {
2673 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2674 current_event_field.GetSignatureForError ());
2677 $$ = current_event_field;
2679 opt_event_initializer
2680 opt_event_declarators
2684 current_event_field.DocComment = Lexer.consume_doc_comment ();
2685 Lexer.doc_state = XmlCommentState.Allowed;
2688 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2689 current_event_field = null;
2693 EVENT type member_declaration_name
2696 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2697 current_type.AddMember (current_event);
2698 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2700 lexer.EventParsing = true;
2702 event_accessor_declarations
2704 if (current_container.Kind == MemberKind.Interface)
2705 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2707 lexer.EventParsing = false;
2712 current_event.DocComment = Lexer.consume_doc_comment ();
2713 Lexer.doc_state = XmlCommentState.Allowed;
2716 lbag.AppendToMember (current_event, GetLocation ($9));
2717 current_event = null;
2718 current_local_parameters = null;
2724 Error_SyntaxError (yyToken);
2726 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2730 opt_event_initializer
2734 ++lexer.parsing_block;
2736 event_variable_initializer
2738 --lexer.parsing_block;
2739 current_event_field.Initializer = (Expression) $3;
2743 opt_event_declarators
2751 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2753 | event_declarators event_declarator
2755 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2762 var lt = (LocatedToken) $2;
2763 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2764 lbag.AddLocation ($$, GetLocation ($1));
2766 | COMMA IDENTIFIER ASSIGN event_variable_initializer
2768 var lt = (LocatedToken) $2;
2769 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $4);
2770 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2774 event_variable_initializer
2776 if (current_container.Kind == MemberKind.Interface) {
2777 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2778 current_event_field.GetSignatureForError ());
2781 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2782 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2783 current_event_field.GetSignatureForError ());
2786 ++lexer.parsing_block;
2787 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2788 start_block (lexer.Location);
2790 variable_initializer
2794 --lexer.parsing_block;
2795 end_block (lexer.Location);
2796 current_local_parameters = null;
2800 event_accessor_declarations
2801 : add_accessor_declaration remove_accessor_declaration
2802 | remove_accessor_declaration add_accessor_declaration
2803 | add_accessor_declaration
2805 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2806 current_event.GetSignatureForError ());
2808 | remove_accessor_declaration
2810 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2811 current_event.GetSignatureForError ());
2815 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2820 add_accessor_declaration
2821 : opt_attributes opt_modifiers ADD
2823 if ($2 != ModifierNone) {
2824 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2827 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2828 current_local_parameters = current_event.Add.ParameterInfo;
2830 lbag.AddMember (current_event.Add, mod_locations);
2831 lexer.EventParsing = false;
2833 event_accessor_block
2835 lexer.EventParsing = true;
2837 current_event.Add.Block = (ToplevelBlock) $5;
2839 if (current_container.Kind == MemberKind.Interface) {
2840 report.Error (531, current_event.Add.Block.StartLocation,
2841 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2844 current_local_parameters = null;
2848 remove_accessor_declaration
2849 : opt_attributes opt_modifiers REMOVE
2851 if ($2 != ModifierNone) {
2852 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2855 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2856 current_local_parameters = current_event.Remove.ParameterInfo;
2858 lbag.AddMember (current_event.Remove, mod_locations);
2859 lexer.EventParsing = false;
2861 event_accessor_block
2863 lexer.EventParsing = true;
2865 current_event.Remove.Block = (ToplevelBlock) $5;
2867 if (current_container.Kind == MemberKind.Interface) {
2868 report.Error (531, current_event.Remove.Block.StartLocation,
2869 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2872 current_local_parameters = null;
2876 event_accessor_block
2879 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2885 if (lang_version < LanguageVersion.V_7) {
2886 FeatureIsNotAvailable (GetLocation ($1), "expression body event accessor");
2891 attributes_without_members
2892 : attribute_sections CLOSE_BRACE
2894 current_type.UnattachedAttributes = (Attributes) $1;
2895 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2896 lexer.putback ('}');
2900 // For full ast try to recover incomplete ambiguous member
2901 // declaration in form on class X { public int }
2903 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2905 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2907 lexer.putback ('}');
2909 lexer.parsing_generic_declaration = false;
2910 FullNamedExpression type = (FullNamedExpression) $3;
2911 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2912 current_type.AddField (current_field);
2920 ENUM type_declaration_name
2924 enumTypeComment = Lexer.consume_doc_comment ();
2929 Lexer.doc_state = XmlCommentState.Allowed;
2931 MemberName name = (MemberName) $4;
2932 if (name.IsGeneric) {
2933 report.Error (1675, name.Location, "Enums cannot have type parameters");
2936 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2938 opt_enum_member_declarations
2940 lexer.parsing_modifiers = true;
2942 // here will be evaluated after CLOSE_BLACE is consumed.
2944 Lexer.doc_state = XmlCommentState.Allowed;
2946 CLOSE_BRACE opt_semicolon
2949 current_container.DocComment = enumTypeComment;
2951 --lexer.parsing_declaration;
2954 // em.DocComment = ev.DocComment;
2956 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2957 $$ = pop_current_class ();
2969 Error_TypeExpected (GetLocation ($1));
2974 opt_enum_member_declarations
2976 | enum_member_declarations
2977 | enum_member_declarations COMMA
2979 lbag.AddLocation ($1, GetLocation ($2));
2983 enum_member_declarations
2984 : enum_member_declaration
2985 | enum_member_declarations COMMA enum_member_declaration
2987 lbag.AddLocation ($1, GetLocation ($2));
2992 enum_member_declaration
2993 : opt_attributes IDENTIFIER
2995 var lt = (LocatedToken) $2;
2996 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2997 ((Enum) current_type).AddEnumMember (em);
3000 em.DocComment = Lexer.consume_doc_comment ();
3001 Lexer.doc_state = XmlCommentState.Allowed;
3006 | opt_attributes IDENTIFIER
3008 ++lexer.parsing_block;
3010 tmpComment = Lexer.consume_doc_comment ();
3011 Lexer.doc_state = XmlCommentState.NotAllowed;
3014 ASSIGN constant_expression
3016 --lexer.parsing_block;
3018 var lt = (LocatedToken) $2;
3019 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
3020 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
3021 ((Enum) current_type).AddEnumMember (em);
3024 em.DocComment = ConsumeStoredComment ();
3028 | opt_attributes IDENTIFIER error
3030 Error_SyntaxError (yyToken);
3032 var lt = (LocatedToken) $2;
3033 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
3034 ((Enum) current_type).AddEnumMember (em);
3037 em.DocComment = Lexer.consume_doc_comment ();
3038 Lexer.doc_state = XmlCommentState.Allowed;
3043 | attributes_without_members
3046 delegate_declaration
3050 ref_member_type type_declaration_name
3053 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue | ParameterModifierType.ReadOnly;
3055 opt_formal_parameter_list CLOSE_PARENS
3057 valid_param_mod = 0;
3059 ParametersCompiled p = (ParametersCompiled) $8;
3061 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
3063 p.CheckParameters (del);
3065 current_container.AddTypeContainer (del);
3067 current_delegate = del;
3068 lexer.ConstraintsParsing = true;
3070 opt_type_parameter_constraints_clauses
3072 lexer.ConstraintsParsing = false;
3077 current_delegate.DocComment = Lexer.consume_doc_comment ();
3078 Lexer.doc_state = XmlCommentState.Allowed;
3082 current_delegate.SetConstraints ((List<Constraints>) $11);
3083 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
3085 $$ = current_delegate;
3087 current_delegate = null;
3095 if (lang_version < LanguageVersion.ISO_2)
3096 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
3098 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
3102 namespace_or_type_expr
3104 | qualified_alias_member IDENTIFIER opt_type_argument_list
3106 var lt1 = (LocatedToken) $1;
3107 var lt2 = (LocatedToken) $2;
3109 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3110 lbag.AddLocation ($$, GetLocation ($2));
3112 | qualified_alias_member IDENTIFIER generic_dimension
3114 var lt1 = (LocatedToken) $1;
3115 var lt2 = (LocatedToken) $2;
3117 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3118 lbag.AddLocation ($$, GetLocation ($2));
3124 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
3126 var lt = (LocatedToken) $3;
3127 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3128 lbag.AddLocation ($$, GetLocation ($2));
3130 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
3132 var lt = (LocatedToken) $3;
3133 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3134 lbag.AddLocation ($$, GetLocation ($2));
3139 : IDENTIFIER opt_type_argument_list
3141 var lt = (LocatedToken) $1;
3142 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3144 | IDENTIFIER generic_dimension
3146 var lt = (LocatedToken) $1;
3147 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3152 // Generics arguments (any type, without attributes)
3154 opt_type_argument_list
3156 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3158 if (lang_version < LanguageVersion.ISO_2)
3159 FeatureIsNotAvailable (GetLocation ($1), "generics");
3163 | OP_GENERICS_LT error
3165 Error_TypeExpected (lexer.Location);
3166 $$ = new TypeArguments ();
3173 TypeArguments type_args = new TypeArguments ();
3174 type_args.Add ((FullNamedExpression) $1);
3177 | type_arguments COMMA type
3179 TypeArguments type_args = (TypeArguments) $1;
3180 type_args.Add ((FullNamedExpression) $3);
3186 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3188 type_declaration_name
3191 lexer.parsing_generic_declaration = true;
3193 opt_type_parameter_list
3195 lexer.parsing_generic_declaration = false;
3196 var lt = (LocatedToken) $1;
3197 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3201 member_declaration_name
3202 : method_declaration_name
3204 MemberName mn = (MemberName)$1;
3205 if (mn.TypeParameters != null)
3206 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3207 mn.GetSignatureForError ()));
3211 method_declaration_name
3212 : type_declaration_name
3213 | explicit_interface IDENTIFIER opt_type_parameter_list
3215 lexer.parsing_generic_declaration = false;
3216 var lt = (LocatedToken) $2;
3217 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3221 indexer_declaration_name
3224 lexer.parsing_generic_declaration = false;
3225 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3227 | explicit_interface THIS
3229 lexer.parsing_generic_declaration = false;
3230 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3235 : IDENTIFIER opt_type_argument_list DOT
3237 var lt = (LocatedToken) $1;
3238 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3239 lbag.AddLocation ($$, GetLocation ($3));
3241 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3243 var lt1 = (LocatedToken) $1;
3244 var lt2 = (LocatedToken) $2;
3246 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3247 lbag.AddLocation ($$, GetLocation ($4));
3249 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3251 var lt = (LocatedToken) $2;
3252 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3253 lbag.AddLocation ($$, GetLocation ($4));
3257 opt_type_parameter_list
3259 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3261 if (lang_version < LanguageVersion.ISO_2)
3262 FeatureIsNotAvailable (GetLocation ($1), "generics");
3265 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3272 var tparams = new TypeParameters ();
3273 tparams.Add ((TypeParameter)$1);
3276 | type_parameters COMMA type_parameter
3278 var tparams = (TypeParameters) $1;
3279 tparams.Add ((TypeParameter)$3);
3281 lbag.AddLocation ($3, GetLocation ($3));
3286 : opt_attributes opt_type_parameter_variance IDENTIFIER
3288 var lt = (LocatedToken)$3;
3289 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3293 if (GetTokenName (yyToken) == "type")
3294 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3296 Error_SyntaxError (yyToken);
3298 $$ = new TypeParameter (MemberName.Null, null, null);
3303 // All types where void is allowed
3306 : type_expression_or_array
3309 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3316 lexer.parsing_generic_declaration = true;
3321 // A type which does not allow `void' to be used
3324 : type_expression_or_array
3334 : type_expression_or_array
3337 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3338 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3342 type_expression_or_array
3344 | type_expression rank_specifiers
3346 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3351 : namespace_or_type_expr opt_nullable
3354 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3356 var sn = $1 as SimpleName;
3357 if (sn != null && sn.Name == "var")
3358 $$ = new VarExpr (sn.Location);
3363 | namespace_or_type_expr pointer_stars
3365 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3367 | builtin_type_expression
3368 | OPEN_PARENS tuple_elements CLOSE_PARENS opt_nullable
3370 if (lang_version < LanguageVersion.V_7)
3371 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3373 var a = (Tuple<TypeArguments, List<string>>) $2;
3374 if (a.Item1.Count < 2) {
3375 report.Error (8124, GetLocation ($1), "Tuple must contain at least two elements");
3378 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
3381 $$ = new ComposedCast ((FullNamedExpression) $$, (ComposedTypeSpecifier) $4);
3386 : tuple_element tuple_element_name
3388 var type_args = new TypeArguments ();
3389 type_args.Add ((FullNamedExpression) $1);
3391 var names = new List<string> (2);
3392 var lt = (LocatedToken) $2;
3393 names.Add (lt?.Value);
3395 $$ = Tuple.Create (type_args, names);
3397 | tuple_elements COMMA tuple_element tuple_element_name
3399 var a = (Tuple<TypeArguments, List<string>>) $1;
3400 a.Item1.Add ((FullNamedExpression) $3);
3401 var lt = (LocatedToken) $4;
3402 a.Item2.Add (lt?.Value);
3419 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3420 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3424 builtin_type_expression
3425 : builtin_types opt_nullable
3428 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3430 | builtin_types pointer_stars
3432 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3434 | VOID pointer_stars
3436 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3443 var types = new List<FullNamedExpression> (2);
3444 types.Add ((FullNamedExpression) $1);
3447 | type_list COMMA base_type_name
3449 var types = (List<FullNamedExpression>) $1;
3450 types.Add ((FullNamedExpression) $3);
3458 if ($1 is ComposedCast) {
3459 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3466 * replaces all the productions for isolating the various
3467 * simple types, but we need this to reuse it easily in variable_type
3470 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3471 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3472 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3473 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3474 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3475 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3480 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3481 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3482 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3483 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3484 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3485 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3486 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3487 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3488 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3492 // Expressions, section 7.5
3497 : type_name_expression
3499 | array_creation_expression
3500 | parenthesized_expression
3501 | default_value_expression
3502 | invocation_expression
3506 | post_increment_expression
3507 | post_decrement_expression
3508 | object_or_delegate_creation_expression
3509 | anonymous_type_expression
3512 | checked_expression
3513 | unchecked_expression
3514 | pointer_member_access
3515 | anonymous_method_expression
3516 | undocumented_expressions
3517 | interpolated_string
3521 type_name_expression
3523 | IDENTIFIER GENERATE_COMPLETION {
3524 var lt = (LocatedToken) $1;
3525 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3534 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3538 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3539 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3543 : OPEN_PARENS tuple_literal_elements CLOSE_PARENS
3545 if (lang_version < LanguageVersion.V_7)
3546 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3548 $$ = new TupleLiteral ((List<TupleLiteralElement>)$2, GetLocation ($1));
3552 tuple_literal_elements
3553 : tuple_literal_element COMMA tuple_literal_element
3555 $$ = new List<TupleLiteralElement> () {
3556 (TupleLiteralElement) $1, (TupleLiteralElement) $3
3559 | tuple_literal_elements COMMA tuple_literal_element
3561 var list = (List<TupleLiteralElement>)$1;
3562 list.Add ((TupleLiteralElement) $3);
3566 tuple_literal_element
3569 $$ = new TupleLiteralElement ((Expression) $1);
3571 | IDENTIFIER COLON expression
3573 var lt = (LocatedToken) $1;
3574 $$ = new TupleLiteralElement (lt.Value, (Expression) $3, lt.Location);
3579 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3581 if (lang_version < LanguageVersion.V_6)
3582 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3584 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3586 | INTERPOLATED_STRING_END
3588 if (lang_version < LanguageVersion.V_6)
3589 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3591 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3598 var list = new List<Expression> ();
3599 list.Add ((InterpolatedStringInsert) $1);
3602 | interpolations INTERPOLATED_STRING interpolation
3604 var list = (List<Expression>) $1;
3605 list.Add ((StringLiteral) $2);
3606 list.Add ((InterpolatedStringInsert) $3);
3614 $$ = new InterpolatedStringInsert ((Expression) $1);
3616 | expression COMMA expression
3618 $$ = new InterpolatedStringInsert ((Expression) $1) {
3619 Alignment = (Expression)$3
3624 lexer.parsing_interpolation_format = true;
3628 lexer.parsing_interpolation_format = false;
3630 $$ = new InterpolatedStringInsert ((Expression) $1) {
3634 | expression COMMA expression COLON
3636 lexer.parsing_interpolation_format = true;
3640 lexer.parsing_interpolation_format = false;
3642 $$ = new InterpolatedStringInsert ((Expression) $1) {
3643 Alignment = (Expression)$3,
3644 Format = (string) $6
3651 // Here is the trick, tokenizer may think that parens is a special but
3652 // parser is interested in open parens only, so we merge them.
3653 // Consider: if (a)foo ();
3661 // Use this production to accept closing parenthesis or
3662 // performing completion
3666 | COMPLETE_COMPLETION
3670 parenthesized_expression
3671 : OPEN_PARENS expression CLOSE_PARENS
3673 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3674 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3676 | OPEN_PARENS expression COMPLETE_COMPLETION
3678 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3683 : primary_expression DOT identifier_inside_body opt_type_argument_list
3685 var lt = (LocatedToken) $3;
3686 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3687 lbag.AddLocation ($$, GetLocation ($2));
3689 | primary_expression DOT identifier_inside_body generic_dimension
3691 var lt = (LocatedToken) $3;
3692 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3693 lbag.AddLocation ($$, GetLocation ($2));
3695 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3697 if (lang_version < LanguageVersion.V_6)
3698 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3700 var lt = (LocatedToken) $4;
3701 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3702 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3704 | builtin_types DOT identifier_inside_body opt_type_argument_list
3706 var lt = (LocatedToken) $3;
3707 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3708 lbag.AddLocation ($$, GetLocation ($2));
3710 | BASE DOT identifier_inside_body opt_type_argument_list
3712 var lt = (LocatedToken) $3;
3713 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3714 lbag.AddLocation ($$, GetLocation ($2));
3716 | AWAIT DOT identifier_inside_body opt_type_argument_list
3718 var lt = (LocatedToken) $3;
3719 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3720 lbag.AddLocation ($$, GetLocation ($2));
3722 | qualified_alias_member identifier_inside_body opt_type_argument_list
3724 var lt1 = (LocatedToken) $1;
3725 var lt2 = (LocatedToken) $2;
3727 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3728 lbag.AddLocation ($$, GetLocation ($2));
3730 | qualified_alias_member identifier_inside_body generic_dimension
3732 var lt1 = (LocatedToken) $1;
3733 var lt2 = (LocatedToken) $2;
3735 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3736 lbag.AddLocation ($$, GetLocation ($2));
3738 | primary_expression DOT GENERATE_COMPLETION {
3739 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3741 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3742 var lt = (LocatedToken) $3;
3743 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3745 | builtin_types DOT GENERATE_COMPLETION
3747 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3749 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3750 var lt = (LocatedToken) $3;
3751 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3755 invocation_expression
3756 : primary_expression open_parens_any opt_argument_list close_parens
3758 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3759 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3761 | primary_expression open_parens_any argument_list error
3763 Error_SyntaxError (yyToken);
3765 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3766 lbag.AddLocation ($$, GetLocation ($2));
3768 | primary_expression open_parens_any error
3770 Error_SyntaxError (yyToken);
3772 $$ = new Invocation ((Expression) $1, null);
3773 lbag.AddLocation ($$, GetLocation ($2));
3777 opt_object_or_collection_initializer
3778 : /* empty */ { $$ = null; }
3779 | object_or_collection_initializer
3782 object_or_collection_initializer
3783 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3786 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3788 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3790 lbag.AddLocation ($$, GetLocation ($3));
3792 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3794 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3795 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3799 opt_member_initializer_list
3800 : /* empty */ { $$ = null; }
3801 | member_initializer_list
3807 member_initializer_list
3808 : member_initializer
3810 var a = new List<Expression> ();
3811 a.Add ((Expression) $1);
3814 | member_initializer_list COMMA member_initializer
3816 var a = (List<Expression>)$1;
3817 a.Add ((Expression) $3);
3820 | member_initializer_list error {
3821 Error_SyntaxError (yyToken);
3827 : IDENTIFIER ASSIGN initializer_value
3829 var lt = (LocatedToken) $1;
3830 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3831 lbag.AddLocation ($$, GetLocation ($2));
3833 | AWAIT ASSIGN initializer_value
3835 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3836 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3837 lbag.AddLocation ($$, GetLocation ($2));
3839 | GENERATE_COMPLETION
3841 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3843 | non_assignment_expression opt_COMPLETE_COMPLETION {
3844 CompletionSimpleName csn = $1 as CompletionSimpleName;
3846 $$ = new CollectionElementInitializer ((Expression)$1);
3848 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3850 | OPEN_BRACE expression_list CLOSE_BRACE
3853 $$ = new CollectionElementInitializer (GetLocation ($1));
3855 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3857 lbag.AddLocation ($$, GetLocation ($3));
3859 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3861 if (lang_version < LanguageVersion.V_6)
3862 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3864 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3865 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3867 | OPEN_BRACE CLOSE_BRACE
3869 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3870 $$ = new CollectionElementInitializer (GetLocation ($1));
3871 lbag.AddLocation ($$, GetLocation ($2));
3877 | object_or_collection_initializer
3881 : /* empty */ { $$ = null; }
3886 : argument_or_named_argument
3888 Arguments list = new Arguments (4);
3889 list.Add ((Argument) $1);
3892 | argument_list COMMA argument
3894 Arguments list = (Arguments) $1;
3895 if (lang_version < LanguageVersion.V_7_2 && list [list.Count - 1] is NamedArgument)
3896 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3898 list.Add ((Argument) $3);
3901 | argument_list COMMA named_argument
3903 Arguments list = (Arguments) $1;
3904 NamedArgument a = (NamedArgument) $3;
3905 for (int i = 0; i < list.Count; ++i) {
3906 NamedArgument na = list [i] as NamedArgument;
3907 if (na != null && na.Name == a.Name)
3908 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3915 | argument_list COMMA error
3917 if (lexer.putback_char == -1)
3918 lexer.putback (')'); // TODO: Wrong but what can I do
3919 Error_SyntaxError (yyToken);
3924 report.Error (839, GetLocation ($1), "An argument is missing");
3932 $$ = new Argument ((Expression) $1);
3934 | non_simple_argument
3937 argument_or_named_argument
3943 : REF variable_reference
3945 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3946 lbag.AddLocation ($$, GetLocation ($1));
3948 | OUT variable_reference
3950 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3951 lbag.AddLocation ($$, GetLocation ($1));
3953 | OUT out_variable_declaration
3955 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3957 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3959 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3960 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3962 | ARGLIST OPEN_PARENS CLOSE_PARENS
3964 $$ = new Argument (new Arglist (GetLocation ($1)));
3965 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3967 | IN variable_reference
3969 if (lang_version < LanguageVersion.V_7_2)
3970 FeatureIsNotAvailable (GetLocation ($1), "readonly references");
3972 $$ = new Argument ((Expression) $2, Argument.AType.Readonly);
3973 lbag.AddLocation ($$, GetLocation ($1));
3977 out_variable_declaration
3978 : variable_type identifier_inside_body
3980 if (lang_version < LanguageVersion.V_7)
3981 FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
3983 var lt = (LocatedToken) $2;
3984 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3985 current_block.AddLocalName (lv);
3986 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3995 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3997 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3998 lbag.AddLocation ($$, GetLocation ($4));
4000 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
4002 if (lang_version < LanguageVersion.V_6)
4003 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
4005 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
4006 ConditionalAccess = true
4009 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
4011 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
4013 Error_SyntaxError (yyToken);
4014 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
4016 | primary_expression OPEN_BRACKET_EXPR error
4018 Error_SyntaxError (yyToken);
4019 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
4024 : expression_or_error
4026 var list = new List<Expression> (4);
4027 list.Add ((Expression) $1);
4030 | expression_list COMMA expression_or_error
4032 var list = (List<Expression>) $1;
4033 list.Add ((Expression) $3);
4038 expression_list_arguments
4039 : expression_list_argument
4041 Arguments args = new Arguments (4);
4042 args.Add ((Argument) $1);
4045 | expression_list_arguments COMMA expression_list_argument
4047 Arguments args = (Arguments) $1;
4048 if (lang_version < LanguageVersion.V_7_2 && args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4049 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4051 args.Add ((Argument) $3);
4056 expression_list_argument
4059 $$ = new Argument ((Expression) $1);
4067 $$ = new This (GetLocation ($1));
4072 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
4074 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
4075 lbag.AddLocation ($$, GetLocation ($4));
4077 | BASE OPEN_BRACKET error
4079 Error_SyntaxError (yyToken);
4080 $$ = new ElementAccess (null, null, GetLocation ($2));
4084 post_increment_expression
4085 : primary_expression OP_INC
4087 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
4091 post_decrement_expression
4092 : primary_expression OP_DEC
4094 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
4098 object_or_delegate_creation_expression
4099 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
4102 if (lang_version <= LanguageVersion.ISO_2)
4103 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
4105 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
4107 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
4110 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4112 | NEW new_expr_type object_or_collection_initializer
4114 if (lang_version <= LanguageVersion.ISO_2)
4115 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
4117 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
4121 array_creation_expression
4122 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
4124 opt_array_initializer
4126 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
4127 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
4128 Next = (ComposedTypeSpecifier) $6
4129 }, (ArrayInitializer) $7, GetLocation ($1)) {
4130 NoEmptyInterpolation = true
4133 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4135 | NEW new_expr_type rank_specifiers opt_array_initializer
4138 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
4140 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
4141 NoEmptyInterpolation = true
4144 | NEW rank_specifier array_initializer
4146 if (lang_version <= LanguageVersion.ISO_2)
4147 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
4149 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
4151 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
4153 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
4154 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
4156 | NEW new_expr_type error
4158 Error_SyntaxError (yyToken);
4159 // It can be any of new expression, create the most common one
4160 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
4166 ++lexer.parsing_type;
4170 --lexer.parsing_type;
4175 anonymous_type_expression
4176 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
4178 if (lang_version <= LanguageVersion.ISO_2)
4179 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
4181 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
4183 // TODO: lbag comma location
4184 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4186 | NEW OPEN_BRACE GENERATE_COMPLETION
4188 $$ = new EmptyCompletion ();
4192 anonymous_type_parameters_opt_comma
4193 : anonymous_type_parameters_opt
4194 | anonymous_type_parameters COMMA
4197 anonymous_type_parameters_opt
4199 | anonymous_type_parameters
4202 anonymous_type_parameters
4203 : anonymous_type_parameter
4205 var a = new List<AnonymousTypeParameter> (4);
4206 a.Add ((AnonymousTypeParameter) $1);
4209 | anonymous_type_parameters COMMA anonymous_type_parameter
4211 var a = (List<AnonymousTypeParameter>) $1;
4212 a.Add ((AnonymousTypeParameter) $3);
4215 | COMPLETE_COMPLETION
4217 $$ = new EmptyCompletion ();
4219 | anonymous_type_parameter COMPLETE_COMPLETION
4225 anonymous_type_parameter
4226 : identifier_inside_body ASSIGN variable_initializer
4228 var lt = (LocatedToken)$1;
4229 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4230 lbag.AddLocation ($$, GetLocation ($2));
4232 | identifier_inside_body
4234 var lt = (LocatedToken)$1;
4235 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4236 lt.Value, lt.Location);
4240 MemberAccess ma = (MemberAccess) $1;
4241 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4245 report.Error (746, lexer.Location,
4246 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4258 | rank_specifier rank_specifiers
4260 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4266 : OPEN_BRACKET CLOSE_BRACKET
4268 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4269 lbag.AddLocation ($$, GetLocation ($2));
4271 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4273 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4274 lbag.AddLocation ($$, GetLocation ($3));
4283 | dim_separators COMMA
4285 $$ = ((int) $1) + 1;
4289 opt_array_initializer
4301 : OPEN_BRACE CLOSE_BRACE
4303 var ai = new ArrayInitializer (0, GetLocation ($1));
4304 ai.VariableDeclaration = current_variable;
4305 lbag.AddLocation (ai, GetLocation ($2));
4308 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4310 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4311 ai.VariableDeclaration = current_variable;
4313 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4315 lbag.AddLocation (ai, GetLocation ($4));
4321 variable_initializer_list
4322 : variable_initializer
4324 var list = new List<Expression> (4);
4325 list.Add ((Expression) $1);
4328 | variable_initializer_list COMMA variable_initializer
4330 var list = (List<Expression>) $1;
4331 list.Add ((Expression) $3);
4337 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4339 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4340 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4344 typeof_type_expression
4348 Error_TypeExpected (lexer.Location);
4356 if (lang_version < LanguageVersion.ISO_2)
4357 FeatureIsNotAvailable (GetLocation ($1), "generics");
4363 qualified_alias_member
4364 : IDENTIFIER DOUBLE_COLON
4366 var lt = (LocatedToken) $1;
4367 if (lang_version == LanguageVersion.ISO_1)
4368 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4375 : SIZEOF open_parens_any type CLOSE_PARENS
4377 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4378 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4380 | SIZEOF open_parens_any type error
4382 Error_SyntaxError (yyToken);
4384 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4385 lbag.AddLocation ($$, GetLocation ($2));
4390 : CHECKED open_parens_any expression CLOSE_PARENS
4392 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4393 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4397 Error_SyntaxError (yyToken);
4399 $$ = new CheckedExpr (null, GetLocation ($1));
4403 unchecked_expression
4404 : UNCHECKED open_parens_any expression CLOSE_PARENS
4406 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4407 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4411 Error_SyntaxError (yyToken);
4413 $$ = new UnCheckedExpr (null, GetLocation ($1));
4417 pointer_member_access
4418 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4420 var lt = (LocatedToken) $3;
4421 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4425 anonymous_method_expression
4426 : DELEGATE opt_anonymous_method_signature
4428 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4432 $$ = end_anonymous ((ParametersBlock) $4);
4434 | ASYNC DELEGATE opt_anonymous_method_signature
4436 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4440 $$ = end_anonymous ((ParametersBlock) $5);
4444 opt_anonymous_method_signature
4447 $$ = ParametersCompiled.Undefined;
4449 | anonymous_method_signature
4452 anonymous_method_signature
4455 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.ReadOnly;
4457 opt_formal_parameter_list CLOSE_PARENS
4459 valid_param_mod = 0;
4464 default_value_expression
4465 : DEFAULT_VALUE open_parens_any type CLOSE_PARENS
4467 if (lang_version < LanguageVersion.ISO_2)
4468 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4470 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4471 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4478 if (lang_version < LanguageVersion.V_7_1)
4479 FeatureIsNotAvailable (GetLocation ($1), "default literal");
4481 $$ = new DefaultLiteralExpression (GetLocation ($1));
4486 : primary_expression
4487 | BANG prefixed_unary_expression
4489 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4491 | TILDE prefixed_unary_expression
4493 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4495 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4497 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4498 lbag.AddLocation ($$, GetLocation ($3));
4500 | AWAIT prefixed_unary_expression
4503 if (current_anonymous_method is LambdaExpression) {
4504 report.Error (4034, GetLocation ($1),
4505 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4506 } else if (current_anonymous_method != null) {
4507 report.Error (4035, GetLocation ($1),
4508 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4509 } else if (interactive_async != null) {
4510 current_block.Explicit.RegisterAsyncAwait ();
4511 interactive_async = true;
4513 report.Error (4033, GetLocation ($1),
4514 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4517 current_block.Explicit.RegisterAsyncAwait ();
4520 $$ = new Await ((Expression) $2, GetLocation ($1));
4522 | THROW_EXPR prefixed_unary_expression
4524 if (lang_version < LanguageVersion.V_7)
4525 FeatureIsNotAvailable (lexer.Location, "throw expression");
4527 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4531 Error_SyntaxError (yyToken);
4533 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4537 Error_SyntaxError (yyToken);
4539 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4541 | OPEN_PARENS_CAST type CLOSE_PARENS error
4543 Error_SyntaxError (yyToken);
4545 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4546 lbag.AddLocation ($$, GetLocation ($3));
4550 Error_SyntaxError (yyToken);
4552 $$ = new Await (null, GetLocation ($1));
4557 // The idea to split this out is from Rhys' grammar
4558 // to solve the problem with casts.
4560 prefixed_unary_expression
4562 | PLUS prefixed_unary_expression
4564 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4566 | MINUS prefixed_unary_expression
4568 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4570 | OP_INC prefixed_unary_expression
4572 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4574 | OP_DEC prefixed_unary_expression
4576 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4578 | STAR prefixed_unary_expression
4580 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4582 | BITWISE_AND prefixed_unary_expression
4584 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4588 Error_SyntaxError (yyToken);
4590 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4594 Error_SyntaxError (yyToken);
4596 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4600 Error_SyntaxError (yyToken);
4602 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4606 Error_SyntaxError (yyToken);
4608 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4612 Error_SyntaxError (yyToken);
4614 $$ = new Indirection (null, GetLocation ($1));
4618 Error_SyntaxError (yyToken);
4620 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4623 multiplicative_expression
4624 : prefixed_unary_expression
4625 | multiplicative_expression STAR prefixed_unary_expression
4627 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4628 lbag.AddLocation ($$, GetLocation ($2));
4630 | multiplicative_expression DIV prefixed_unary_expression
4632 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4633 lbag.AddLocation ($$, GetLocation ($2));
4635 | multiplicative_expression PERCENT prefixed_unary_expression
4637 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4638 lbag.AddLocation ($$, GetLocation ($2));
4640 | multiplicative_expression STAR error
4642 Error_SyntaxError (yyToken);
4644 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4645 lbag.AddLocation ($$, GetLocation ($2));
4647 | multiplicative_expression DIV error
4649 Error_SyntaxError (yyToken);
4651 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4652 lbag.AddLocation ($$, GetLocation ($2));
4654 | multiplicative_expression PERCENT error
4656 Error_SyntaxError (yyToken);
4658 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4659 lbag.AddLocation ($$, GetLocation ($2));
4664 : multiplicative_expression
4665 | additive_expression PLUS multiplicative_expression
4667 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4668 lbag.AddLocation ($$, GetLocation ($2));
4670 | additive_expression MINUS multiplicative_expression
4672 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4673 lbag.AddLocation ($$, GetLocation ($2));
4675 | additive_expression PLUS error
4677 Error_SyntaxError (yyToken);
4679 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4680 lbag.AddLocation ($$, GetLocation ($2));
4682 | additive_expression MINUS error
4684 Error_SyntaxError (yyToken);
4686 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4687 lbag.AddLocation ($$, GetLocation ($2));
4689 | additive_expression AS type
4691 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4693 | additive_expression IS pattern_type_expr opt_identifier
4695 var is_expr = new Is ((Expression) $1, ((FullNamedExpression) $3), GetLocation ($2));
4697 if (lang_version < LanguageVersion.V_7)
4698 FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
4700 var lt = (LocatedToken) $4;
4701 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
4702 is_expr.Variable = lv;
4703 current_block.AddLocalName (lv.Name, lv, true);
4708 | additive_expression IS pattern_expr
4710 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4711 if (lang_version != LanguageVersion.Experimental)
4712 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4716 | additive_expression AS error
4718 Error_SyntaxError (yyToken);
4720 $$ = new As ((Expression) $1, null, GetLocation ($2));
4722 | additive_expression IS error
4724 Error_SyntaxError (yyToken);
4726 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4730 var lt = (LocatedToken) $1;
4731 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4735 var lt = (LocatedToken) $1;
4736 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4746 | PLUS prefixed_unary_expression
4748 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4750 | MINUS prefixed_unary_expression
4752 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4755 | default_value_expression
4756 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4758 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4759 lbag.AddLocation ($$, GetLocation ($3));
4763 $$ = new WildcardPattern (GetLocation ($1));
4765 /* | pattern_expr_invocation */
4770 pattern_expr_invocation
4771 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4773 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4779 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4781 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4785 pattern_property_list
4786 : pattern_property_entry
4788 var list = new List<PropertyPatternMember> ();
4789 list.Add ((PropertyPatternMember) $1);
4792 | pattern_property_list COMMA pattern_property_entry
4794 var list = (List<PropertyPatternMember>) $1;
4795 list.Add ((PropertyPatternMember) $3);
4800 pattern_property_entry
4801 : identifier_inside_body IS pattern
4803 var lt = (LocatedToken) $1;
4804 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4810 | pattern_type_expr opt_identifier
4813 var lt = (LocatedToken) $2;
4814 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4815 current_block.AddLocalName (variable);
4824 $$ = new Arguments (0);
4832 Arguments args = new Arguments (4);
4833 args.Add ((Argument) $1);
4836 | pattern_list COMMA pattern_argument
4838 Arguments args = (Arguments) $1;
4839 if (lang_version < LanguageVersion.V_7_2 && args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4840 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4842 args.Add ((Argument) $3);
4851 $$ = new Argument ((Expression) $1);
4853 | IDENTIFIER COLON pattern
4855 var lt = (LocatedToken) $1;
4856 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4862 : additive_expression
4863 | shift_expression OP_SHIFT_LEFT additive_expression
4865 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4866 lbag.AddLocation ($$, GetLocation ($2));
4868 | shift_expression OP_SHIFT_RIGHT additive_expression
4870 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4871 lbag.AddLocation ($$, GetLocation ($2));
4873 | shift_expression OP_SHIFT_LEFT error
4875 Error_SyntaxError (yyToken);
4877 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4878 lbag.AddLocation ($$, GetLocation ($2));
4880 | shift_expression OP_SHIFT_RIGHT error
4882 Error_SyntaxError (yyToken);
4884 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4885 lbag.AddLocation ($$, GetLocation ($2));
4889 relational_expression
4891 | relational_expression OP_LT shift_expression
4893 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4894 lbag.AddLocation ($$, GetLocation ($2));
4896 | relational_expression OP_GT shift_expression
4898 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4899 lbag.AddLocation ($$, GetLocation ($2));
4901 | relational_expression OP_LE shift_expression
4903 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4904 lbag.AddLocation ($$, GetLocation ($2));
4906 | relational_expression OP_GE shift_expression
4908 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4909 lbag.AddLocation ($$, GetLocation ($2));
4911 | relational_expression OP_LT error
4913 Error_SyntaxError (yyToken);
4915 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4916 lbag.AddLocation ($$, GetLocation ($2));
4918 | relational_expression OP_GT error
4920 Error_SyntaxError (yyToken);
4922 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4923 lbag.AddLocation ($$, GetLocation ($2));
4925 | relational_expression OP_LE error
4927 Error_SyntaxError (yyToken);
4929 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4930 lbag.AddLocation ($$, GetLocation ($2));
4932 | relational_expression OP_GE error
4934 Error_SyntaxError (yyToken);
4936 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4937 lbag.AddLocation ($$, GetLocation ($2));
4942 : relational_expression
4943 | equality_expression OP_EQ relational_expression
4945 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4946 lbag.AddLocation ($$, GetLocation ($2));
4948 | equality_expression OP_NE relational_expression
4950 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4951 lbag.AddLocation ($$, GetLocation ($2));
4953 | equality_expression OP_EQ error
4955 Error_SyntaxError (yyToken);
4957 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4958 lbag.AddLocation ($$, GetLocation ($2));
4960 | equality_expression OP_NE error
4962 Error_SyntaxError (yyToken);
4964 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4965 lbag.AddLocation ($$, GetLocation ($2));
4970 : equality_expression
4971 | and_expression BITWISE_AND equality_expression
4973 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4974 lbag.AddLocation ($$, GetLocation ($2));
4976 | and_expression BITWISE_AND error
4978 Error_SyntaxError (yyToken);
4980 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4981 lbag.AddLocation ($$, GetLocation ($2));
4985 exclusive_or_expression
4987 | exclusive_or_expression CARRET and_expression
4989 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4990 lbag.AddLocation ($$, GetLocation ($2));
4992 | exclusive_or_expression CARRET error
4994 Error_SyntaxError (yyToken);
4996 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4997 lbag.AddLocation ($$, GetLocation ($2));
5001 inclusive_or_expression
5002 : exclusive_or_expression
5003 | inclusive_or_expression BITWISE_OR exclusive_or_expression
5005 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
5006 lbag.AddLocation ($$, GetLocation ($2));
5008 | inclusive_or_expression BITWISE_OR error
5010 Error_SyntaxError (yyToken);
5012 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
5013 lbag.AddLocation ($$, GetLocation ($2));
5017 conditional_and_expression
5018 : inclusive_or_expression
5019 | conditional_and_expression OP_AND inclusive_or_expression
5021 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
5022 lbag.AddLocation ($$, GetLocation ($2));
5024 | conditional_and_expression OP_AND error
5026 Error_SyntaxError (yyToken);
5028 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
5029 lbag.AddLocation ($$, GetLocation ($2));
5033 conditional_or_expression
5034 : conditional_and_expression
5035 | conditional_or_expression OP_OR conditional_and_expression
5037 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
5038 lbag.AddLocation ($$, GetLocation ($2));
5040 | conditional_or_expression OP_OR error
5042 Error_SyntaxError (yyToken);
5044 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
5045 lbag.AddLocation ($$, GetLocation ($2));
5049 null_coalescing_expression
5050 : conditional_or_expression
5051 | conditional_or_expression OP_COALESCING null_coalescing_expression
5053 if (lang_version < LanguageVersion.ISO_2)
5054 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
5056 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
5057 lbag.AddLocation ($$, GetLocation ($2));
5062 conditional_oper_expr
5064 | stackalloc_expression
5067 conditional_expression
5068 : null_coalescing_expression
5069 | null_coalescing_expression INTERR conditional_oper_expr COLON conditional_oper_expr
5071 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
5072 lbag.AddLocation ($$, GetLocation ($4));
5074 | null_coalescing_expression INTERR conditional_oper_expr COLON THROW prefixed_unary_expression
5076 if (lang_version < LanguageVersion.V_7)
5077 FeatureIsNotAvailable (GetLocation ($5), "throw expression");
5079 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
5080 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
5081 lbag.AddLocation ($$, GetLocation ($4));
5083 | null_coalescing_expression INTERR reference_expression COLON reference_expression
5085 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
5086 lbag.AddLocation ($$, GetLocation ($4));
5088 | null_coalescing_expression INTERR conditional_oper_expr error
5090 Error_SyntaxError (yyToken);
5092 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
5094 | null_coalescing_expression INTERR conditional_oper_expr COLON error
5096 Error_SyntaxError (yyToken);
5098 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
5099 lbag.AddLocation ($$, GetLocation ($4));
5101 | null_coalescing_expression INTERR conditional_oper_expr COLON CLOSE_BRACE
5103 Error_SyntaxError (Token.CLOSE_BRACE);
5105 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
5106 lbag.AddLocation ($$, GetLocation ($4));
5107 lexer.putback ('}');
5111 assignment_expression
5112 : prefixed_unary_expression ASSIGN expression
5114 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
5115 lbag.AddLocation ($$, GetLocation ($2));
5117 | prefixed_unary_expression OP_MULT_ASSIGN expression
5119 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
5120 lbag.AddLocation ($$, GetLocation ($2));
5122 | prefixed_unary_expression OP_DIV_ASSIGN expression
5124 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
5125 lbag.AddLocation ($$, GetLocation ($2));
5127 | prefixed_unary_expression OP_MOD_ASSIGN expression
5129 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
5130 lbag.AddLocation ($$, GetLocation ($2));
5132 | prefixed_unary_expression OP_ADD_ASSIGN expression
5134 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
5135 lbag.AddLocation ($$, GetLocation ($2));
5137 | prefixed_unary_expression OP_SUB_ASSIGN expression
5139 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
5140 lbag.AddLocation ($$, GetLocation ($2));
5142 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
5144 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
5145 lbag.AddLocation ($$, GetLocation ($2));
5147 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
5149 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
5150 lbag.AddLocation ($$, GetLocation ($2));
5152 | prefixed_unary_expression OP_AND_ASSIGN expression
5154 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
5155 lbag.AddLocation ($$, GetLocation ($2));
5157 | prefixed_unary_expression OP_OR_ASSIGN expression
5159 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
5160 lbag.AddLocation ($$, GetLocation ($2));
5162 | prefixed_unary_expression OP_XOR_ASSIGN expression
5164 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
5165 lbag.AddLocation ($$, GetLocation ($2));
5167 | OPEN_PARENS_DECONSTRUCT deconstruct_assignment CLOSE_PARENS ASSIGN expression
5169 if (lang_version < LanguageVersion.V_7)
5170 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5172 var exprs = (List<Expression>) $2;
5173 $$ = new TupleDeconstruct (exprs, (Expression) $5, GetLocation ($4));
5175 | OPEN_PARENS_DECONSTRUCT deconstruct_declaration CLOSE_PARENS ASSIGN expression
5177 if (lang_version < LanguageVersion.V_7)
5178 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5180 var exprs = (List<BlockVariable>) $2;
5181 $$ = new TupleDeconstruct (exprs, (Expression) $5, GetLocation ($4));
5185 deconstruct_assignment
5186 : expression COMMA expression
5188 $$ = new List<Expression> () {
5193 | deconstruct_assignment COMMA expression
5195 var src = (List<Expression>) $1;
5196 src.Add ((Expression) $3);
5201 deconstruct_declaration
5202 : variable_type identifier_inside_body
5204 var lt = (LocatedToken) $2;
5205 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5206 current_block.AddLocalName (li);
5207 $$ = new List<BlockVariable> (2) {
5208 new BlockVariable ((FullNamedExpression) $1, li)
5211 | deconstruct_declaration COMMA variable_type identifier_inside_body
5213 var lt = (LocatedToken) $4;
5214 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5215 current_block.AddLocalName (li);
5217 var src = (List<BlockVariable>) $1;
5218 src.Add (new BlockVariable ((FullNamedExpression) $3, li));
5221 | deconstruct_declaration COMMA identifier_inside_body
5223 var lt = (LocatedToken) $3;
5224 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5226 if (lt.Value != "_") {
5227 report.Error (8184, lt.Location, "A deconstruction cannot mix declarations and expressions on the left-hand-side");
5229 li.Type = InternalType.Discard;
5232 var src = (List<BlockVariable>) $1;
5233 src.Add (new BlockVariable (new TypeExpression (li.Type, lt.Location), li));
5238 lambda_parameter_list
5241 var pars = new List<Parameter> (4);
5242 pars.Add ((Parameter) $1);
5246 | lambda_parameter_list COMMA lambda_parameter
5248 var pars = (List<Parameter>) $1;
5249 Parameter p = (Parameter)$3;
5250 if (pars[0].GetType () != p.GetType ()) {
5251 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
5260 : parameter_modifier parameter_type identifier_inside_body
5262 var lt = (LocatedToken) $3;
5264 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
5266 | parameter_type identifier_inside_body
5268 var lt = (LocatedToken) $2;
5270 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
5274 var lt = (LocatedToken) $1;
5275 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5279 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5280 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5284 opt_lambda_parameter_list
5285 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
5286 | lambda_parameter_list {
5287 var pars_list = (List<Parameter>) $1;
5288 $$ = new ParametersCompiled (pars_list.ToArray ());
5292 lambda_expression_body
5294 start_block (Location.Null);
5296 lambda_arrow_expression // All expressions must handle error or current block won't be restored and breaking ast completely
5298 Block b = end_block (Location.Null);
5299 b.IsCompilerGenerated = true;
5300 b.AddStatement (new ContextualReturn ((Expression) $2));
5306 // Handles only cases like foo = x.FirstOrDefault (l => );
5307 // where we must restore current_variable
5308 Block b = end_block (Location.Null);
5309 b.IsCompilerGenerated = true;
5311 Error_SyntaxError (yyToken);
5316 lambda_arrow_expression
5318 | reference_expression
5325 Error_SyntaxError (yyToken);
5333 var lt = (LocatedToken) $1;
5334 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5335 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5337 lambda_expression_body
5339 $$ = end_anonymous ((ParametersBlock) $4);
5340 lbag.AddLocation ($$, GetLocation ($2));
5344 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5345 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5346 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5348 lambda_expression_body
5350 $$ = end_anonymous ((ParametersBlock) $4);
5351 lbag.AddLocation ($$, GetLocation ($2));
5353 | ASYNC identifier_inside_body ARROW
5355 var lt = (LocatedToken) $2;
5356 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5357 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5359 lambda_expression_body
5361 $$ = end_anonymous ((ParametersBlock) $5);
5362 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5364 | OPEN_PARENS_LAMBDA
5366 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.ReadOnly;
5368 opt_lambda_parameter_list CLOSE_PARENS ARROW
5370 valid_param_mod = 0;
5371 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5373 lambda_expression_body
5375 $$ = end_anonymous ((ParametersBlock) $7);
5376 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5378 | ASYNC OPEN_PARENS_LAMBDA
5380 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.ReadOnly;
5382 opt_lambda_parameter_list CLOSE_PARENS ARROW
5384 valid_param_mod = 0;
5385 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5387 lambda_expression_body
5389 $$ = end_anonymous ((ParametersBlock) $8);
5390 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5395 : assignment_expression
5396 | non_assignment_expression
5399 non_assignment_expression
5400 : conditional_expression
5405 $$ = new ArglistAccess (GetLocation ($1));
5409 undocumented_expressions
5410 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5412 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5413 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5415 | REFTYPE open_parens_any expression CLOSE_PARENS
5417 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5418 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5420 | MAKEREF open_parens_any expression CLOSE_PARENS
5422 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5423 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5434 $$ = new BooleanExpression ((Expression) $1);
5438 opt_primary_parameters
5443 | primary_parameters
5447 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5451 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5452 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5454 if (lang_version != LanguageVersion.Experimental)
5455 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5459 opt_primary_parameters_with_class_base
5468 | primary_parameters
5472 | primary_parameters class_base
5476 | primary_parameters class_base OPEN_PARENS
5478 ++lexer.parsing_block;
5479 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5481 opt_argument_list CLOSE_PARENS
5483 lbag.AppendToMember (current_container, GetLocation ($6));
5484 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5485 --lexer.parsing_block;
5501 type_declaration_name
5503 lexer.ConstraintsParsing = true;
5505 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5506 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5507 FeatureIsNotAvailable (c.Location, "static classes");
5510 push_current_container (c, $3);
5511 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5513 opt_primary_parameters_with_class_base
5514 opt_type_parameter_constraints_clauses
5516 valid_param_mod = 0;
5517 lexer.ConstraintsParsing = false;
5520 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5523 current_container.SetConstraints ((List<Constraints>) $9);
5524 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5527 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5528 Lexer.doc_state = XmlCommentState.Allowed;
5531 lexer.parsing_modifiers = true;
5533 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5535 --lexer.parsing_declaration;
5537 Lexer.doc_state = XmlCommentState.Allowed;
5542 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5544 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5546 $$ = pop_current_class ();
5554 { $$ = $1; } // location
5560 mod_locations = null;
5562 lexer.parsing_modifiers = false;
5566 lexer.parsing_modifiers = false;
5572 | modifiers modifier
5574 var m1 = (Modifiers) $1;
5575 var m2 = (Modifiers) $2;
5577 if ((m1 & m2) != 0) {
5578 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5579 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5580 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0) {
5581 var accessibility = (m2 | m1 & Modifiers.AccessibilityMask);
5583 if (accessibility == (Modifiers.PRIVATE | Modifiers.PROTECTED)) {
5584 if (lang_version < LanguageVersion.V_7_2) {
5585 FeatureIsNotAvailable (lexer.Location, "private protected");
5587 } else if (accessibility != (Modifiers.PROTECTED | Modifiers.INTERNAL)) {
5588 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5589 "More than one protection modifier specified");
5601 StoreModifierLocation ($$, GetLocation ($1));
5603 if (current_container.Kind == MemberKind.Namespace)
5604 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5608 $$ = Modifiers.PUBLIC;
5609 StoreModifierLocation ($$, GetLocation ($1));
5613 $$ = Modifiers.PROTECTED;
5614 StoreModifierLocation ($$, GetLocation ($1));
5618 $$ = Modifiers.INTERNAL;
5619 StoreModifierLocation ($$, GetLocation ($1));
5623 $$ = Modifiers.PRIVATE;
5624 StoreModifierLocation ($$, GetLocation ($1));
5628 $$ = Modifiers.ABSTRACT;
5629 StoreModifierLocation ($$, GetLocation ($1));
5633 $$ = Modifiers.SEALED;
5634 StoreModifierLocation ($$, GetLocation ($1));
5638 $$ = Modifiers.STATIC;
5639 StoreModifierLocation ($$, GetLocation ($1));
5643 $$ = Modifiers.READONLY;
5644 StoreModifierLocation ($$, GetLocation ($1));
5648 $$ = Modifiers.VIRTUAL;
5649 StoreModifierLocation ($$, GetLocation ($1));
5653 $$ = Modifiers.OVERRIDE;
5654 StoreModifierLocation ($$, GetLocation ($1));
5658 $$ = Modifiers.EXTERN;
5659 StoreModifierLocation ($$, GetLocation ($1));
5663 $$ = Modifiers.VOLATILE;
5664 StoreModifierLocation ($$, GetLocation ($1));
5668 $$ = Modifiers.UNSAFE;
5669 StoreModifierLocation ($$, GetLocation ($1));
5670 if (!settings.Unsafe)
5671 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5675 $$ = Modifiers.ASYNC;
5676 StoreModifierLocation ($$, GetLocation ($1));
5688 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5690 | COLON type_list error
5692 Error_SyntaxError (yyToken);
5694 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5698 opt_type_parameter_constraints_clauses
5700 | type_parameter_constraints_clauses
5706 type_parameter_constraints_clauses
5707 : type_parameter_constraints_clause
5709 var constraints = new List<Constraints> (1);
5710 constraints.Add ((Constraints) $1);
5713 | type_parameter_constraints_clauses type_parameter_constraints_clause
5715 var constraints = (List<Constraints>) $1;
5716 Constraints new_constraint = (Constraints)$2;
5718 foreach (Constraints c in constraints) {
5719 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5720 report.Error (409, new_constraint.Location,
5721 "A constraint clause has already been specified for type parameter `{0}'",
5722 new_constraint.TypeParameter.Value);
5726 constraints.Add (new_constraint);
5731 type_parameter_constraints_clause
5732 : WHERE IDENTIFIER COLON type_parameter_constraints
5734 var lt = (LocatedToken) $2;
5735 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5736 lbag.AddLocation ($$, GetLocation ($3));
5738 | WHERE IDENTIFIER error
5740 Error_SyntaxError (yyToken);
5742 var lt = (LocatedToken) $2;
5743 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5747 type_parameter_constraints
5748 : type_parameter_constraint
5750 var constraints = new List<FullNamedExpression> (1);
5751 constraints.Add ((FullNamedExpression) $1);
5754 | type_parameter_constraints COMMA type_parameter_constraint
5756 var constraints = (List<FullNamedExpression>) $1;
5757 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5758 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5759 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5762 prev = $3 as SpecialContraintExpr;
5764 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5765 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5767 prev = constraints [0] as SpecialContraintExpr;
5768 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5769 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5774 constraints.Add ((FullNamedExpression) $3);
5779 type_parameter_constraint
5782 if ($1 is ComposedCast)
5783 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5787 | NEW OPEN_PARENS CLOSE_PARENS
5789 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5790 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5794 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5798 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5802 opt_type_parameter_variance
5807 | type_parameter_variance
5809 if (lang_version <= LanguageVersion.V_3)
5810 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5816 type_parameter_variance
5819 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5823 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5832 // A block is "contained" on the following places:
5834 // property_declaration as part of the accessor body (get/set)
5835 // operator_declaration
5836 // constructor_declaration
5837 // destructor_declaration
5838 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5843 ++lexer.parsing_block;
5844 start_block (GetLocation ($1));
5846 opt_statement_list block_end
5855 --lexer.parsing_block;
5856 $$ = end_block (GetLocation ($1));
5858 | COMPLETE_COMPLETION
5860 --lexer.parsing_block;
5861 $$ = end_block (lexer.Location);
5869 ++lexer.parsing_block;
5870 current_block.StartLocation = GetLocation ($1);
5872 opt_statement_list CLOSE_BRACE
5874 --lexer.parsing_block;
5875 $$ = end_block (GetLocation ($4));
5886 | statement_list statement
5890 : block_variable_declaration
5892 current_block.AddStatement ((Statement) $1);
5894 | valid_declaration_statement
5896 current_block.AddStatement ((Statement) $1);
5901 Error_SyntaxError (yyToken);
5907 // The interactive_statement and its derivatives are only
5908 // used to provide a special version of `expression_statement'
5909 // that has a side effect of assigning the expression to
5912 interactive_statement_list
5913 : interactive_statement
5914 | interactive_statement_list interactive_statement
5917 interactive_statement
5918 : block_variable_declaration
5920 current_block.AddStatement ((Statement) $1);
5922 | interactive_valid_declaration_statement
5924 current_block.AddStatement ((Statement) $1);
5929 valid_declaration_statement
5932 | expression_statement
5933 | selection_statement
5934 | iteration_statement
5938 | unchecked_statement
5945 interactive_valid_declaration_statement
5948 | interactive_expression_statement
5949 | selection_statement
5950 | iteration_statement
5954 | unchecked_statement
5962 : valid_declaration_statement
5963 | block_variable_declaration
5965 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5970 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5975 Error_SyntaxError (yyToken);
5976 $$ = new EmptyStatement (GetLocation ($1));
5983 // Uses lexer.Location because semicolon location is not kept in quick mode
5984 $$ = new EmptyStatement (lexer.Location);
5989 : identifier_inside_body COLON
5991 var lt = (LocatedToken) $1;
5992 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5993 lbag.AddLocation (labeled, GetLocation ($2));
5994 current_block.AddLabel (labeled);
5995 current_block.AddStatement (labeled);
6001 : variable_type_simple
6002 | variable_type_simple rank_specifiers
6005 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
6007 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
6012 * The following is from Rhys' grammar:
6013 * > Types in local variable declarations must be recognized as
6014 * > expressions to prevent reduce/reduce errors in the grammar.
6015 * > The expressions are converted into types during semantic analysis.
6017 variable_type_simple
6018 : type_name_expression opt_nullable
6020 var expr = (ATypeNameExpression) $1;
6022 if (expr.Name == "var" && expr is SimpleName)
6023 $$ = new VarExpr (expr.Location);
6027 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
6030 | type_name_expression pointer_stars
6032 var expr = (ATypeNameExpression) $1;
6033 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
6035 | builtin_type_expression
6036 | tuple_type opt_nullable
6041 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
6047 : OPEN_PARENS tuple_type_elements CLOSE_PARENS
6049 if (lang_version < LanguageVersion.V_7)
6050 FeatureIsNotAvailable (GetLocation ($1), "tuples");
6052 var a = (Tuple<TypeArguments, List<string>>) $2;
6054 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
6059 : variable_type IDENTIFIER /* opt_identifier */ COMMA variable_type IDENTIFIER /* opt_identifier */
6061 var type_args = new TypeArguments ();
6063 type_args.Add ((FullNamedExpression) $1);
6064 type_args.Add ((FullNamedExpression) $4);
6066 var names = new List<string> (2);
6067 var lt = (LocatedToken) $2;
6068 names.Add (lt?.Value);
6069 lt = (LocatedToken) $5;
6070 names.Add (lt?.Value);
6072 $$ = Tuple.Create (type_args, names);
6074 | tuple_type_elements COMMA variable_type IDENTIFIER /* opt_identifier */
6076 var a = (Tuple<TypeArguments, List<string>>) $1;
6077 a.Item1.Add ((FullNamedExpression) $3);
6078 var lt = (LocatedToken) $4;
6079 a.Item2.Add (lt?.Value);
6086 | pointer_star pointer_stars
6088 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
6096 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
6100 identifier_inside_body
6104 $$ = Error_AwaitAsIdentifier ($1);
6108 block_variable_declaration
6109 : variable_type identifier_inside_body
6111 var lt = (LocatedToken) $2;
6112 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6113 current_block.AddLocalName (li);
6114 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6116 opt_local_variable_initializer opt_variable_declarators SEMICOLON
6118 $$ = current_variable;
6119 current_variable = null;
6121 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
6123 lbag.AddLocation ($$, GetLocation ($6));
6125 | CONST variable_type identifier_inside_body
6127 var lt = (LocatedToken) $3;
6128 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
6129 current_block.AddLocalName (li);
6130 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
6132 const_variable_initializer opt_const_declarators SEMICOLON
6134 $$ = current_variable;
6135 current_variable = null;
6136 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
6138 | REF variable_type identifier_inside_body
6140 if (lang_version < LanguageVersion.V_7) {
6141 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
6144 var lt = (LocatedToken) $3;
6145 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ByRef, lt.Location);
6146 current_block.AddLocalName (li);
6147 current_variable = new BlockVariable ((FullNamedExpression) $2, li);
6149 opt_local_variable_initializer opt_variable_declarators SEMICOLON
6151 $$ = current_variable;
6152 current_variable = null;
6154 lbag.AddLocation ($$, PopLocation (), GetLocation ($7));
6156 report.Error (8174, GetLocation ($3), "A declaration of a by-reference variable must have an initializer");
6157 lbag.AddLocation ($$, GetLocation ($7));
6160 | REF READONLY variable_type identifier_inside_body
6162 if (lang_version < LanguageVersion.V_7_2) {
6163 FeatureIsNotAvailable (GetLocation ($2), "readonly references");
6166 var lt = (LocatedToken) $4;
6167 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ByRef | LocalVariable.Flags.ReadonlyMask, lt.Location);
6168 current_block.AddLocalName (li);
6169 current_variable = new BlockVariable ((FullNamedExpression) $3, li);
6171 opt_local_variable_initializer opt_variable_declarators SEMICOLON
6173 $$ = current_variable;
6174 current_variable = null;
6176 lbag.AddLocation ($$, PopLocation (), GetLocation ($8));
6178 report.Error (8174, GetLocation ($3), "A declaration of a by-reference variable must have an initializer");
6179 lbag.AddLocation ($$, GetLocation ($8));
6184 opt_local_variable_initializer
6186 | ASSIGN block_variable_initializer
6188 current_variable.Initializer = (Expression) $2;
6189 PushLocation (GetLocation ($1));
6190 $$ = current_variable;
6194 if (yyToken == Token.OPEN_BRACKET_EXPR) {
6195 report.Error (650, lexer.Location,
6196 "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");
6198 Error_SyntaxError (yyToken);
6203 opt_variable_declarators
6205 | variable_declarators
6208 opt_using_or_fixed_variable_declarators
6210 | variable_declarators
6212 foreach (var d in current_variable.Declarators) {
6213 if (d.Initializer == null)
6214 Error_MissingInitializer (d.Variable.Location);
6219 variable_declarators
6220 : variable_declarator
6221 | variable_declarators variable_declarator
6225 : COMMA identifier_inside_body
6227 var lt = (LocatedToken) $2;
6228 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
6229 var d = new BlockVariableDeclarator (li, null);
6230 current_variable.AddDeclarator (d);
6231 current_block.AddLocalName (li);
6232 lbag.AddLocation (d, GetLocation ($1));
6234 | COMMA identifier_inside_body ASSIGN block_variable_initializer
6236 var lt = (LocatedToken) $2;
6237 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
6238 var d = new BlockVariableDeclarator (li, (Expression) $4);
6239 current_variable.AddDeclarator (d);
6240 current_block.AddLocalName (li);
6241 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6245 const_variable_initializer
6248 report.Error (145, lexer.Location, "A const field requires a value to be provided");
6250 | ASSIGN constant_initializer_expr
6252 current_variable.Initializer = (Expression) $2;
6256 opt_const_declarators
6263 | const_declarators const_declarator
6267 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
6269 var lt = (LocatedToken) $2;
6270 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
6271 var d = new BlockVariableDeclarator (li, (Expression) $4);
6272 current_variable.AddDeclarator (d);
6273 current_block.AddLocalName (li);
6274 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6278 block_variable_initializer
6279 : variable_initializer
6280 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
6282 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
6283 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6285 | STACKALLOC simple_type
6287 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
6288 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
6290 | reference_expression
6293 stackalloc_expression
6294 : STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
6296 if (lang_version < LanguageVersion.V_7_2) {
6297 FeatureIsNotAvailable (GetLocation ($1), "ref structs");
6300 $$ = new SpanStackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
6301 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6303 | STACKALLOC simple_type
6305 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
6306 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
6310 reference_expression
6313 if (lang_version < LanguageVersion.V_7) {
6314 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
6317 $$ = new ReferenceExpression ((Expression) $2, GetLocation ($1));
6321 expression_statement
6322 : statement_expression SEMICOLON
6325 lbag.AddStatement ($$, GetLocation ($2));
6327 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
6328 | statement_expression CLOSE_BRACE
6331 report.Error (1002, GetLocation ($2), "; expected");
6332 lexer.putback ('}');
6336 interactive_expression_statement
6337 : interactive_statement_expression SEMICOLON { $$ = $1; }
6338 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
6342 // We have to do the wrapping here and not in the case above,
6343 // because statement_expression is used for example in for_statement
6345 statement_expression
6348 ExpressionStatement s = $1 as ExpressionStatement;
6350 var expr = $1 as Expression;
6351 $$ = new StatementErrorExpression (expr);
6353 $$ = new StatementExpression (s);
6358 interactive_statement_expression
6361 Expression expr = (Expression) $1;
6362 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
6366 Error_SyntaxError (yyToken);
6367 $$ = new EmptyStatement (GetLocation ($1));
6377 : IF open_parens_any boolean_expression CLOSE_PARENS
6380 if ($5 is EmptyStatement)
6381 Warning_EmptyStatement (GetLocation ($5));
6383 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6384 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6386 | IF open_parens_any boolean_expression CLOSE_PARENS
6387 embedded_statement ELSE embedded_statement
6389 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
6390 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
6392 if ($5 is EmptyStatement)
6393 Warning_EmptyStatement (GetLocation ($5));
6394 if ($7 is EmptyStatement)
6395 Warning_EmptyStatement (GetLocation ($7));
6397 | IF open_parens_any boolean_expression error
6399 Error_SyntaxError (yyToken);
6401 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
6402 lbag.AddStatement ($$, GetLocation ($2));
6407 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
6409 start_block (GetLocation ($5));
6411 opt_switch_sections CLOSE_BRACE
6413 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
6414 end_block (GetLocation ($8));
6415 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6417 | SWITCH open_parens_any expression error
6419 Error_SyntaxError (yyToken);
6421 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
6422 lbag.AddStatement ($$, GetLocation ($2));
6429 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6436 | switch_sections switch_section
6439 Error_SyntaxError (yyToken);
6444 : switch_labels statement_list
6450 var label = (SwitchLabel) $1;
6451 label.SectionStart = true;
6452 current_block.AddStatement (label);
6454 | switch_labels switch_label
6456 current_block.AddStatement ((Statement) $2);
6461 : CASE constant_expression COLON
6463 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6464 lbag.AddLocation ($$, GetLocation ($3));
6466 | CASE constant_expression error
6468 Error_SyntaxError (yyToken);
6469 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6472 | CASE pattern_expr_invocation COLON
6474 if (lang_version != LanguageVersion.Experimental)
6475 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6477 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6478 PatternMatching = true
6480 lbag.AddLocation ($$, GetLocation ($3));
6484 | CASE pattern_type_expr IDENTIFIER COLON
6486 if (lang_version < LanguageVersion.V_7)
6487 FeatureIsNotAvailable (GetLocation ($1), "pattern matching");
6489 // $$ = new SwitchLabel ((FullNamedExpression) $2), GetLocation ($1)) {
6490 // PatternMatching = true
6493 throw new NotImplementedException ("type pattern matching");
6497 $$ = new SwitchLabel (null, GetLocation ($1));
6509 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6511 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6512 Warning_EmptyStatement (GetLocation ($5));
6514 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6515 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6517 | WHILE open_parens_any boolean_expression error
6519 Error_SyntaxError (yyToken);
6521 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6522 lbag.AddStatement ($$, GetLocation ($2));
6527 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6529 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6530 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6532 | DO embedded_statement error
6534 Error_SyntaxError (yyToken);
6535 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6537 | DO embedded_statement WHILE open_parens_any boolean_expression error
6539 Error_SyntaxError (yyToken);
6541 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6542 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6547 : FOR open_parens_any
6549 start_block (GetLocation ($2));
6550 current_block.IsCompilerGenerated = true;
6551 For f = new For (GetLocation ($1));
6552 current_block.AddStatement (f);
6561 // Has to use be extra rule to recover started block
6563 : opt_for_initializer SEMICOLON
6565 ((For) $0).Initializer = (Statement) $1;
6567 // Pass the "For" object to the iterator_part4
6568 oob_stack.Push ($0);
6570 for_condition_and_iterator_part
6573 var locations = (Tuple<Location,Location>) $4;
6575 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6576 Warning_EmptyStatement (GetLocation ($5));
6579 f.Statement = (Statement) $5;
6580 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6582 $$ = end_block (GetLocation ($2));
6586 Error_SyntaxError (yyToken);
6587 $$ = end_block (current_block.StartLocation);
6591 for_condition_and_iterator_part
6592 : opt_for_condition SEMICOLON
6594 For f = (For) oob_stack.Peek ();
6595 f.Condition = (BooleanExpression) $1;
6598 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6601 // Handle errors in the case of opt_for_condition being followed by
6602 // a close parenthesis
6603 | opt_for_condition close_parens_close_brace {
6604 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6605 For f = (For) oob_stack.Peek ();
6606 f.Condition = (BooleanExpression) $1;
6607 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6612 : opt_for_iterator CLOSE_PARENS {
6613 For f = (For) oob_stack.Peek ();
6614 f.Iterator = (Statement) $1;
6615 $$ = GetLocation ($2);
6617 | opt_for_iterator CLOSE_BRACE {
6618 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6619 For f = (For) oob_stack.Peek ();
6620 f.Iterator = (Statement) $1;
6621 $$ = GetLocation ($2);
6625 close_parens_close_brace
6627 | CLOSE_BRACE { lexer.putback ('}'); }
6631 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6636 : variable_type identifier_inside_body
6638 var lt = (LocatedToken) $2;
6639 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6640 current_block.AddLocalName (li);
6641 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6643 opt_local_variable_initializer opt_variable_declarators
6645 $$ = current_variable;
6647 lbag.AddLocation (current_variable, PopLocation ());
6649 current_variable = null;
6651 | statement_expression_list
6655 : /* empty */ { $$ = null; }
6656 | boolean_expression
6660 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6665 : statement_expression_list
6668 statement_expression_list
6669 : statement_expression
6670 | statement_expression_list COMMA statement_expression
6672 var sl = $1 as StatementList;
6674 sl = new StatementList ((Statement) $1, (Statement) $3);
6675 lbag.AddStatement (sl, GetLocation ($2));
6677 sl.Add ((Statement) $3);
6678 lbag.AppendTo (sl, GetLocation ($2));
6686 : FOREACH open_parens_any type error
6688 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6690 start_block (GetLocation ($2));
6691 current_block.IsCompilerGenerated = true;
6693 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6694 current_block.AddStatement (f);
6696 lbag.AddStatement (f, GetLocation ($2));
6697 $$ = end_block (GetLocation ($4));
6699 | FOREACH open_parens_any type identifier_inside_body error
6701 Error_SyntaxError (yyToken);
6703 start_block (GetLocation ($2));
6704 current_block.IsCompilerGenerated = true;
6706 var lt = (LocatedToken) $4;
6707 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6708 current_block.AddLocalName (li);
6710 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6711 current_block.AddStatement (f);
6713 lbag.AddStatement (f, GetLocation ($2));
6714 $$ = end_block (GetLocation ($5));
6716 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6718 start_block (GetLocation ($2));
6719 current_block.IsCompilerGenerated = true;
6721 var lt = (LocatedToken) $4;
6722 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6723 current_block.AddLocalName (li);
6728 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6729 Warning_EmptyStatement (GetLocation ($9));
6731 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6732 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6733 end_block (GetLocation ($7));
6741 | continue_statement
6751 $$ = new Break (GetLocation ($1));
6752 lbag.AddStatement ($$, GetLocation ($2));
6757 : CONTINUE SEMICOLON
6759 $$ = new Continue (GetLocation ($1));
6760 lbag.AddStatement ($$, GetLocation ($2));
6764 Error_SyntaxError (yyToken);
6765 $$ = new Continue (GetLocation ($1));
6770 : GOTO identifier_inside_body SEMICOLON
6772 var lt = (LocatedToken) $2;
6773 $$ = new Goto (lt.Value, GetLocation ($1));
6774 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6776 | GOTO CASE constant_expression SEMICOLON
6778 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6779 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6781 | GOTO DEFAULT SEMICOLON
6783 $$ = new GotoDefault (GetLocation ($1));
6784 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6789 : RETURN opt_expression SEMICOLON
6791 $$ = new Return ((Expression) $2, GetLocation ($1));
6792 lbag.AddStatement ($$, GetLocation ($3));
6794 | RETURN reference_expression SEMICOLON
6796 $$ = new Return ((Expression) $2, GetLocation ($1));
6797 lbag.AddStatement ($$, GetLocation ($3));
6799 | RETURN expression error
6801 Error_SyntaxError (yyToken);
6802 $$ = new Return ((Expression) $2, GetLocation ($1));
6806 Error_SyntaxError (yyToken);
6807 $$ = new Return (null, GetLocation ($1));
6812 : THROW expression SEMICOLON
6814 $$ = new Throw ((Expression) $2, GetLocation ($1));
6815 lbag.AddStatement ($$, GetLocation ($3));
6819 $$ = new Throw (null, GetLocation ($1));
6820 lbag.AddStatement ($$, GetLocation ($2));
6822 | THROW expression error
6824 Error_SyntaxError (yyToken);
6825 $$ = new Throw ((Expression) $2, GetLocation ($1));
6829 Error_SyntaxError (yyToken);
6830 $$ = new Throw (null, GetLocation ($1));
6835 : identifier_inside_body RETURN opt_expression SEMICOLON
6837 var lt = (LocatedToken) $1;
6838 string s = lt.Value;
6840 report.Error (1003, lt.Location, "; expected");
6841 } else if ($3 == null) {
6842 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6843 } else if (lang_version == LanguageVersion.ISO_1){
6844 FeatureIsNotAvailable (lt.Location, "iterators");
6847 current_block.Explicit.RegisterIteratorYield ();
6848 $$ = new Yield ((Expression) $3, lt.Location);
6849 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6851 | identifier_inside_body RETURN expression error
6853 Error_SyntaxError (yyToken);
6855 var lt = (LocatedToken) $1;
6856 string s = lt.Value;
6858 report.Error (1003, lt.Location, "; expected");
6859 } else if ($3 == null) {
6860 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6861 } else if (lang_version == LanguageVersion.ISO_1){
6862 FeatureIsNotAvailable (lt.Location, "iterators");
6865 current_block.Explicit.RegisterIteratorYield ();
6866 $$ = new Yield ((Expression) $3, lt.Location);
6867 lbag.AddStatement ($$, GetLocation ($2));
6869 | identifier_inside_body BREAK SEMICOLON
6871 var lt = (LocatedToken) $1;
6872 string s = lt.Value;
6874 report.Error (1003, lt.Location, "; expected");
6875 } else if (lang_version == LanguageVersion.ISO_1){
6876 FeatureIsNotAvailable (lt.Location, "iterators");
6879 current_block.ParametersBlock.TopBlock.IsIterator = true;
6880 $$ = new YieldBreak (lt.Location);
6881 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6891 : TRY block catch_clauses
6893 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6895 | TRY block FINALLY block
6897 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6898 lbag.AddStatement ($$, GetLocation ($3));
6900 | TRY block catch_clauses FINALLY block
6902 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6903 lbag.AddStatement ($$, GetLocation ($4));
6907 Error_SyntaxError (1524, yyToken);
6908 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6915 var l = new List<Catch> (2);
6920 | catch_clauses catch_clause
6922 var l = (List<Catch>) $1;
6924 Catch c = (Catch) $2;
6925 var prev_catch = l [l.Count - 1];
6926 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6927 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6937 | identifier_inside_body
6941 : CATCH opt_catch_filter block
6943 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6944 c.Filter = (CatchFilterExpression) $2;
6947 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6949 start_block (GetLocation ($2));
6950 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6951 c.TypeExpression = (FullNamedExpression) $3;
6954 var lt = (LocatedToken) $4;
6955 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6956 current_block.AddLocalName (c.Variable);
6959 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6961 lexer.parsing_catch_when = true;
6963 opt_catch_filter_or_error
6965 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6968 | CATCH open_parens_any error
6970 if (yyToken == Token.CLOSE_PARENS) {
6971 report.Error (1015, lexer.Location,
6972 "A type that derives from `System.Exception', `object', or `string' expected");
6974 Error_SyntaxError (yyToken);
6977 $$ = new Catch (null, GetLocation ($1));
6981 opt_catch_filter_or_error
6982 : opt_catch_filter block_prepared
6988 end_block (Location.Null);
6989 Error_SyntaxError (yyToken);
6996 lexer.parsing_catch_when = false;
7000 lexer.parsing_catch_when = false;
7002 open_parens_any expression CLOSE_PARENS
7004 if (lang_version <= LanguageVersion.V_5)
7005 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
7007 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
7008 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
7015 $$ = new Checked ((Block) $2, GetLocation ($1));
7022 $$ = new Unchecked ((Block) $2, GetLocation ($1));
7029 if (!settings.Unsafe)
7030 Error_UnsafeCodeNotAllowed (GetLocation ($1));
7032 $$ = new Unsafe ((Block) $3, GetLocation ($1));
7037 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
7039 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
7040 Warning_EmptyStatement (GetLocation ($5));
7042 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
7043 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
7045 | LOCK open_parens_any expression error
7047 Error_SyntaxError (yyToken);
7049 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
7050 lbag.AddStatement ($$, GetLocation ($2));
7055 : FIXED open_parens_any variable_type identifier_inside_body
7057 start_block (GetLocation ($2));
7059 current_block.IsCompilerGenerated = true;
7060 var lt = (LocatedToken) $4;
7061 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
7062 current_block.AddLocalName (li);
7063 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
7065 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
7067 $$ = current_variable;
7068 current_variable = null;
7072 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
7073 Warning_EmptyStatement (GetLocation ($10));
7075 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
7076 current_block.AddStatement (f);
7077 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
7078 $$ = end_block (GetLocation ($8));
7083 : USING open_parens_any variable_type identifier_inside_body
7085 start_block (GetLocation ($2));
7087 current_block.IsCompilerGenerated = true;
7088 var lt = (LocatedToken) $4;
7089 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
7090 current_block.AddLocalName (li);
7091 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
7093 using_initialization CLOSE_PARENS
7095 $$ = current_variable;
7096 current_variable = null;
7100 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
7101 Warning_EmptyStatement (GetLocation ($9));
7103 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
7104 current_block.AddStatement (u);
7105 $$ = end_block (GetLocation ($7));
7107 | USING open_parens_any expression CLOSE_PARENS embedded_statement
7109 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
7110 Warning_EmptyStatement (GetLocation ($5));
7112 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
7113 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
7115 | USING open_parens_any expression error
7117 Error_SyntaxError (yyToken);
7119 $$ = new Using ((Expression) $3, null, GetLocation ($1));
7120 lbag.AddStatement ($$, GetLocation ($2));
7124 using_initialization
7125 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
7128 // It has to be here for the parent to safely restore artificial block
7129 Error_SyntaxError (yyToken);
7133 using_or_fixed_variable_initializer
7136 Error_MissingInitializer (lexer.Location);
7138 | ASSIGN variable_initializer
7140 current_variable.Initializer = (Expression) $2;
7141 $$ = current_variable;
7149 : first_from_clause query_body
7151 lexer.query_parsing = false;
7153 Linq.AQueryClause from = $1 as Linq.AQueryClause;
7155 from.Tail.Next = (Linq.AQueryClause)$2;
7158 current_block.SetEndLocation (lexer.Location);
7159 current_block = current_block.Parent;
7161 | nested_from_clause query_body
7163 Linq.AQueryClause from = $1 as Linq.AQueryClause;
7165 from.Tail.Next = (Linq.AQueryClause)$2;
7168 current_block.SetEndLocation (lexer.Location);
7169 current_block = current_block.Parent;
7172 // Bubble up COMPLETE_COMPLETION productions
7173 | first_from_clause COMPLETE_COMPLETION {
7174 lexer.query_parsing = false;
7177 current_block.SetEndLocation (lexer.Location);
7178 current_block = current_block.Parent;
7180 | nested_from_clause COMPLETE_COMPLETION {
7182 current_block.SetEndLocation (lexer.Location);
7183 current_block = current_block.Parent;
7188 : FROM_FIRST identifier_inside_body IN expression
7190 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7192 var lt = (LocatedToken) $2;
7193 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7194 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
7195 lbag.AddLocation (clause, GetLocation ($3));
7196 $$ = new Linq.QueryExpression (clause);
7198 | FROM_FIRST type identifier_inside_body IN expression
7200 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7202 var lt = (LocatedToken) $3;
7203 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7204 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
7205 IdentifierType = (FullNamedExpression)$2
7207 lbag.AddLocation (clause, GetLocation ($4));
7208 $$ = new Linq.QueryExpression (clause);
7213 : FROM identifier_inside_body IN expression
7215 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7217 var lt = (LocatedToken) $2;
7218 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7219 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
7220 lbag.AddLocation (clause, GetLocation ($3));
7221 $$ = new Linq.QueryExpression (clause);
7223 | FROM type identifier_inside_body IN expression
7225 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7227 var lt = (LocatedToken) $3;
7228 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7229 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
7230 IdentifierType = (FullNamedExpression)$2
7232 lbag.AddLocation (clause, GetLocation ($4));
7233 $$ = new Linq.QueryExpression (clause);
7238 : FROM identifier_inside_body IN
7240 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7244 var lt = (LocatedToken) $2;
7245 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7246 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
7248 current_block.SetEndLocation (lexer.Location);
7249 current_block = current_block.Parent;
7251 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7252 lbag.AddLocation ($$, GetLocation ($3));
7254 | FROM type identifier_inside_body IN
7256 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7260 var lt = (LocatedToken) $3;
7261 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7263 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
7264 IdentifierType = (FullNamedExpression)$2
7267 current_block.SetEndLocation (lexer.Location);
7268 current_block = current_block.Parent;
7270 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7272 lbag.AddLocation ($$, GetLocation ($4));
7277 : query_body_clauses select_or_group_clause opt_query_continuation
7279 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7282 head.Next = (Linq.AQueryClause)$3;
7285 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7286 clause.Tail.Next = head;
7292 | select_or_group_clause opt_query_continuation
7294 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7297 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7298 clause.Tail.Next = head;
7304 | query_body_clauses COMPLETE_COMPLETION
7305 | query_body_clauses error
7307 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
7312 Error_SyntaxError (yyToken);
7317 select_or_group_clause
7320 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7324 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7326 current_block.SetEndLocation (lexer.Location);
7327 current_block = current_block.Parent;
7331 if (linq_clause_blocks == null)
7332 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7334 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7335 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
7339 current_block.SetEndLocation (lexer.Location);
7340 current_block = current_block.Parent;
7342 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7346 var obj = (object[]) $5;
7348 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
7349 lbag.AddLocation ($$, (Location) obj[1]);
7351 current_block.SetEndLocation (lexer.Location);
7352 current_block = current_block.Parent;
7357 : BY expression_or_error
7359 $$ = new object[] { $2, GetLocation ($1) };
7363 Error_SyntaxError (yyToken);
7364 $$ = new object[2] { null, Location.Null };
7370 | query_body_clauses query_body_clause
7372 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
7386 : LET identifier_inside_body ASSIGN
7388 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7392 var lt = (LocatedToken) $2;
7393 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7394 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
7395 lbag.AddLocation ($$, GetLocation ($3));
7397 current_block.SetEndLocation (lexer.Location);
7398 current_block = current_block.Parent;
7400 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7407 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7411 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7413 current_block.SetEndLocation (lexer.Location);
7414 current_block = current_block.Parent;
7419 : JOIN identifier_inside_body IN
7421 if (linq_clause_blocks == null)
7422 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7424 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7425 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7427 expression_or_error ON
7429 current_block.SetEndLocation (lexer.Location);
7430 current_block = current_block.Parent;
7432 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7433 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7435 expression_or_error EQUALS
7437 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7438 current_block.SetEndLocation (lexer.Location);
7439 current_block = current_block.Parent;
7441 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7443 expression_or_error opt_join_into
7445 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7446 current_block.SetEndLocation (lexer.Location);
7448 var outer_selector = linq_clause_blocks.Pop ();
7449 var block = linq_clause_blocks.Pop ();
7451 var lt = (LocatedToken) $2;
7452 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7453 Linq.RangeVariable into;
7457 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7458 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7461 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7463 var parent = block.Parent;
7464 while (parent is Linq.QueryBlock) {
7465 parent = parent.Parent;
7467 current_block.Parent = parent;
7469 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7471 lt = (LocatedToken) $12;
7472 into = new Linq.RangeVariable (lt.Value, lt.Location);
7474 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7475 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7478 current_block = block.Parent;
7479 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7481 | JOIN type identifier_inside_body IN
7483 if (linq_clause_blocks == null)
7484 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7486 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7487 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7489 expression_or_error ON
7491 current_block.SetEndLocation (lexer.Location);
7492 current_block = current_block.Parent;
7494 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7495 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7497 expression_or_error EQUALS
7499 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7500 current_block.SetEndLocation (lexer.Location);
7501 current_block = current_block.Parent;
7503 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7505 expression_or_error opt_join_into
7507 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7508 current_block.SetEndLocation (lexer.Location);
7510 var outer_selector = linq_clause_blocks.Pop ();
7511 var block = linq_clause_blocks.Pop ();
7513 var lt = (LocatedToken) $3;
7514 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7515 Linq.RangeVariable into;
7519 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7520 IdentifierType = (FullNamedExpression)$2
7522 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7525 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7527 var parent = block.Parent;
7528 while (parent is Linq.QueryBlock) {
7529 parent = parent.Parent;
7531 current_block.Parent = parent;
7533 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7535 lt = (LocatedToken) $13;
7536 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7538 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7539 IdentifierType = (FullNamedExpression)$2
7543 current_block = block.Parent;
7544 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7550 | INTO identifier_inside_body
7559 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7563 current_block.SetEndLocation (lexer.Location);
7564 current_block = current_block.Parent;
7574 current_block.SetEndLocation (lexer.Location);
7575 current_block = current_block.Parent;
7577 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7581 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7588 | orderings_then_by COMMA
7590 current_block.SetEndLocation (lexer.Location);
7591 current_block = current_block.Parent;
7593 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7597 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7605 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7607 | expression ASCENDING
7609 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7610 lbag.AddLocation ($$, GetLocation ($2));
7612 | expression DESCENDING
7614 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7615 lbag.AddLocation ($$, GetLocation ($2));
7622 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7624 | expression ASCENDING
7626 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7627 lbag.AddLocation ($$, GetLocation ($2));
7629 | expression DESCENDING
7631 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7632 lbag.AddLocation ($$, GetLocation ($2));
7637 opt_query_continuation
7639 | INTO identifier_inside_body
7641 // query continuation block is not linked with query block but with block
7642 // before. This means each query can use same range variable names for
7643 // different identifiers.
7645 current_block.SetEndLocation (GetLocation ($1));
7646 current_block = current_block.Parent;
7648 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7650 if (linq_clause_blocks == null)
7651 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7653 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7657 var current_block = linq_clause_blocks.Pop ();
7658 var lt = (LocatedToken) $2;
7659 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7660 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7661 next = (Linq.AQueryClause)$4
7667 // Support for using the compiler as an interactive parser
7669 // The INTERACTIVE_PARSER token is first sent to parse our
7670 // productions; If the result is a Statement, the parsing
7671 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7672 // to setup the blocks in advance.
7674 // This setup is here so that in the future we can add
7675 // support for other constructs (type parsing, namespaces, etc)
7676 // that do not require a block to be setup in advance
7680 : EVAL_STATEMENT_PARSER EOF
7681 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7682 | EVAL_STATEMENT_PARSER
7684 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7686 // (ref object retval)
7687 Parameter [] mpar = new Parameter [1];
7688 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7690 ParametersCompiled pars = new ParametersCompiled (mpar);
7691 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7692 if (settings.Unsafe)
7693 mods |= Modifiers.UNSAFE;
7695 current_local_parameters = pars;
7696 var method = new InteractiveMethod (
7698 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7702 current_type.AddMember (method);
7703 oob_stack.Push (method);
7705 interactive_async = false;
7707 ++lexer.parsing_block;
7708 start_block (lexer.Location);
7710 interactive_statement_list opt_COMPLETE_COMPLETION
7712 --lexer.parsing_block;
7713 var method = (InteractiveMethod) oob_stack.Pop ();
7714 method.Block = (ToplevelBlock) end_block(lexer.Location);
7716 if (interactive_async == true) {
7717 method.ChangeToAsync ();
7720 InteractiveResult = (Class) pop_current_class ();
7721 current_local_parameters = null;
7723 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7726 interactive_compilation_unit
7727 : opt_extern_alias_directives opt_using_directives
7728 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7731 opt_COMPLETE_COMPLETION
7733 | COMPLETE_COMPLETION
7736 close_brace_or_complete_completion
7738 | COMPLETE_COMPLETION
7742 // XML documentation code references micro parser
7744 documentation_parsing
7747 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7752 : doc_type_declaration_name opt_doc_method_sig
7754 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7756 | builtin_types opt_doc_method_sig
7758 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7759 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7762 | VOID opt_doc_method_sig
7764 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7765 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7768 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7770 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7771 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7772 var lt = (LocatedToken) $3;
7773 $$ = new MemberName (lt.Value);
7775 | doc_type_declaration_name DOT THIS
7777 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7779 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7781 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.ReadOnly;
7783 opt_doc_parameters CLOSE_BRACKET
7785 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7786 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7788 | EXPLICIT OPERATOR type opt_doc_method_sig
7790 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7791 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7792 module.DocumentationBuilder.ParsedParameters = p;
7793 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7796 | IMPLICIT OPERATOR type opt_doc_method_sig
7798 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7799 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7800 module.DocumentationBuilder.ParsedParameters = p;
7801 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7804 | OPERATOR overloadable_operator opt_doc_method_sig
7806 var p = (List<DocumentationParameter>)$3;
7807 module.DocumentationBuilder.ParsedParameters = p;
7808 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7813 doc_type_declaration_name
7814 : type_declaration_name
7815 | doc_type_declaration_name DOT type_declaration_name
7817 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7825 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.ReadOnly;
7827 opt_doc_parameters CLOSE_PARENS
7836 $$ = new List<DocumentationParameter> (0);
7844 var parameters = new List<DocumentationParameter> ();
7845 parameters.Add ((DocumentationParameter) $1);
7848 | doc_parameters COMMA doc_parameter
7850 var parameters = $1 as List<DocumentationParameter>;
7851 parameters.Add ((DocumentationParameter) $3);
7857 : opt_parameter_modifier parameter_type
7860 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7862 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7869 // A class used to hold info about an operator declarator
7871 class OperatorDeclaration {
7872 public readonly Operator.OpType optype;
7873 public readonly FullNamedExpression ret_type;
7874 public readonly Location location;
7876 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7879 this.ret_type = ret_type;
7880 this.location = location;
7884 void Error_ExpectingTypeName (Expression expr)
7886 if (expr is Invocation){
7887 report.Error (1002, expr.Location, "Expecting `;'");
7889 expr.Error_InvalidExpressionStatement (report);
7893 void Error_ParameterModifierNotValid (string modifier, Location loc)
7895 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7899 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7901 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7902 Parameter.GetModifierSignature (mod));
7905 void Error_TypeExpected (Location loc)
7907 report.Error (1031, loc, "Type expected");
7910 void Error_UnsafeCodeNotAllowed (Location loc)
7912 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7915 void Warning_EmptyStatement (Location loc)
7917 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7920 void Error_NamedArgumentExpected (NamedArgument a)
7922 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments when using language version older than 7.2");
7925 void Error_MissingInitializer (Location loc)
7927 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7930 object Error_AwaitAsIdentifier (object token)
7933 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7934 return new LocatedToken ("await", GetLocation (token));
7940 void push_current_container (TypeDefinition tc, object partial_token)
7942 if (module.Evaluator != null){
7943 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7947 undo.AddTypeContainer (current_container, tc);
7950 if (partial_token != null)
7951 current_container.AddPartial (tc);
7953 current_container.AddTypeContainer (tc);
7955 ++lexer.parsing_declaration;
7956 current_container = tc;
7960 TypeContainer pop_current_class ()
7962 var retval = current_container;
7964 current_container = current_container.Parent;
7965 current_type = current_type.Parent as TypeDefinition;
7970 [System.Diagnostics.Conditional ("FULL_AST")]
7971 void StoreModifierLocation (object token, Location loc)
7976 if (mod_locations == null)
7977 mod_locations = new List<Tuple<Modifiers, Location>> ();
7979 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7982 [System.Diagnostics.Conditional ("FULL_AST")]
7983 void PushLocation (Location loc)
7985 if (location_stack == null)
7986 location_stack = new Stack<Location> ();
7988 location_stack.Push (loc);
7991 Location PopLocation ()
7993 if (location_stack == null)
7994 return Location.Null;
7996 return location_stack.Pop ();
7999 string CheckAttributeTarget (int token, string a, Location l)
8002 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
8006 if (!Tokenizer.IsValidIdentifier (a)) {
8007 Error_SyntaxError (token);
8009 report.Warning (658, 1, l,
8010 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
8013 return string.Empty;
8016 static bool IsUnaryOperator (Operator.OpType op)
8020 case Operator.OpType.LogicalNot:
8021 case Operator.OpType.OnesComplement:
8022 case Operator.OpType.Increment:
8023 case Operator.OpType.Decrement:
8024 case Operator.OpType.True:
8025 case Operator.OpType.False:
8026 case Operator.OpType.UnaryPlus:
8027 case Operator.OpType.UnaryNegation:
8033 static Statement CreateExpressionBodiedStatement (Expression expr)
8035 if (expr is ThrowExpression te)
8036 return new StatementExpression (te);
8038 return new ContextualReturn (expr);
8041 void syntax_error (Location l, string msg)
8043 report.Error (1003, l, "Syntax error, " + msg);
8048 public Tokenizer Lexer {
8054 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
8055 : this (reader, file, file.Compiler.Report, session)
8059 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
8062 current_container = current_namespace = file;
8064 this.module = file.Module;
8065 this.compiler = file.Compiler;
8066 this.settings = compiler.Settings;
8067 this.report = report;
8069 lang_version = settings.Version;
8070 yacc_verbose_flag = settings.VerboseParserFlag;
8071 doc_support = settings.DocumentationFile != null;
8072 lexer = new Tokenizer (reader, file, session, report);
8073 oob_stack = new Stack<object> ();
8074 lbag = session.LocationsBag;
8075 use_global_stacks = session.UseJayGlobalArrays;
8076 parameters_bucket = session.ParametersStack;
8079 public void parse ()
8081 eof_token = Token.EOF;
8084 if (yacc_verbose_flag > 1)
8085 yyparse (lexer, new yydebug.yyDebugSimple ());
8089 Tokenizer tokenizer = lexer as Tokenizer;
8090 tokenizer.cleanup ();
8091 } catch (Exception e){
8092 if (e is yyParser.yyUnexpectedEof) {
8093 Error_SyntaxError (yyToken);
8094 UnexpectedEOF = true;
8098 if (e is yyParser.yyException) {
8099 if (report.Errors == 0)
8100 report.Error (-25, lexer.Location, "Parsing error");
8102 // Used by compiler-tester to test internal errors
8103 if (yacc_verbose_flag > 0 || e is FatalException)
8106 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
8111 void CheckToken (int error, int yyToken, string msg, Location loc)
8113 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
8114 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
8116 report.Error (error, loc, msg);
8119 string ConsumeStoredComment ()
8121 string s = tmpComment;
8123 Lexer.doc_state = XmlCommentState.Allowed;
8127 void FeatureIsNotAvailable (Location loc, string feature)
8129 report.FeatureIsNotAvailable (compiler, loc, feature);
8132 Location GetLocation (object obj)
8134 var lt = obj as LocatedToken;
8138 var mn = obj as MemberName;
8142 var expr = obj as Expression;
8144 return expr.Location;
8146 return lexer.Location;
8149 void start_block (Location loc)
8151 if (current_block == null) {
8152 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
8153 parsing_anonymous_method = false;
8154 } else if (parsing_anonymous_method) {
8155 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
8156 parsing_anonymous_method = false;
8158 current_block = new ExplicitBlock (current_block, loc, Location.Null);
8162 Block end_block (Location loc)
8164 Block retval = current_block.Explicit;
8165 retval.SetEndLocation (loc);
8166 current_block = retval.Parent;
8170 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
8172 oob_stack.Push (current_anonymous_method);
8173 oob_stack.Push (current_local_parameters);
8174 oob_stack.Push (current_variable);
8175 oob_stack.Push (async_block);
8177 current_local_parameters = parameters;
8179 if (lang_version <= LanguageVersion.ISO_2)
8180 FeatureIsNotAvailable (loc, "lambda expressions");
8182 current_anonymous_method = new LambdaExpression (loc);
8184 if (lang_version == LanguageVersion.ISO_1)
8185 FeatureIsNotAvailable (loc, "anonymous methods");
8187 current_anonymous_method = new AnonymousMethodExpression (loc);
8190 async_block = isAsync;
8191 // Force the next block to be created as a ToplevelBlock
8192 parsing_anonymous_method = true;
8196 * Completes the anonymous method processing, if lambda_expr is null, this
8197 * means that we have a Statement instead of an Expression embedded
8199 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
8201 AnonymousMethodExpression retval;
8204 anon_block.IsAsync = true;
8206 current_anonymous_method.Block = anon_block;
8207 retval = current_anonymous_method;
8209 async_block = (bool) oob_stack.Pop ();
8210 current_variable = (BlockVariable) oob_stack.Pop ();
8211 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
8212 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
8217 void Error_SyntaxError (int token)
8219 Error_SyntaxError (0, token);
8222 void Error_SyntaxError (int error_code, int token)
8224 Error_SyntaxError (error_code, token, "Unexpected symbol");
8227 void Error_SyntaxError (int error_code, int token, string msg)
8229 Lexer.CompleteOnEOF = false;
8231 // An error message has been reported by tokenizer
8232 if (token == Token.ERROR)
8235 // Avoid duplicit error message after unterminated string literals
8236 if (token == Token.LITERAL && lexer.Location.Column == 0)
8239 string symbol = GetSymbolName (token);
8240 string expecting = GetExpecting ();
8241 var loc = lexer.Location - symbol.Length;
8243 if (error_code == 0) {
8244 if (expecting == "`identifier'") {
8245 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
8246 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
8251 expecting = "identifier";
8252 } else if (expecting == "`)'") {
8259 if (string.IsNullOrEmpty (expecting))
8260 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
8262 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
8265 string GetExpecting ()
8267 int [] tokens = yyExpectingTokens (yyExpectingState);
8268 var names = new List<string> (tokens.Length);
8269 bool has_type = false;
8270 bool has_identifier = false;
8271 for (int i = 0; i < tokens.Length; i++){
8272 int token = tokens [i];
8273 has_identifier |= token == Token.IDENTIFIER;
8275 string name = GetTokenName (token);
8276 if (name == "<internal>")
8279 has_type |= name == "type";
8280 if (names.Contains (name))
8287 // Too many tokens to enumerate
8289 if (names.Count > 8)
8292 if (has_type && has_identifier)
8293 names.Remove ("identifier");
8295 if (names.Count == 1)
8296 return "`" + GetTokenName (tokens [0]) + "'";
8298 StringBuilder sb = new StringBuilder ();
8300 int count = names.Count;
8301 for (int i = 0; i < count; i++){
8302 bool last = i + 1 == count;
8306 sb.Append (names [i]);
8307 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
8309 return sb.ToString ();
8313 string GetSymbolName (int token)
8317 return ((Constant)lexer.Value).GetValue ().ToString ();
8318 case Token.IDENTIFIER:
8319 return ((LocatedToken)lexer.Value).Value;
8361 case Token.BITWISE_AND:
8363 case Token.BITWISE_OR:
8377 case Token.OP_SHIFT_LEFT:
8379 case Token.OP_SHIFT_RIGHT:
8399 case Token.OP_COALESCING:
8401 case Token.OP_MULT_ASSIGN:
8403 case Token.OP_DIV_ASSIGN:
8405 case Token.OP_MOD_ASSIGN:
8407 case Token.OP_ADD_ASSIGN:
8409 case Token.OP_SUB_ASSIGN:
8411 case Token.OP_SHIFT_LEFT_ASSIGN:
8413 case Token.OP_SHIFT_RIGHT_ASSIGN:
8415 case Token.OP_AND_ASSIGN:
8417 case Token.OP_XOR_ASSIGN:
8419 case Token.OP_OR_ASSIGN:
8423 return GetTokenName (token);
8426 static string GetTokenName (int token)
8429 case Token.ABSTRACT:
8451 case Token.CONTINUE:
8454 case Token.DEFAULT_VALUE:
8456 case Token.DELEGATE:
8466 case Token.EXPLICIT:
8469 case Token.EXTERN_ALIAS:
8485 case Token.IMPLICIT:
8489 case Token.INTERFACE:
8491 case Token.INTERNAL:
8497 case Token.NAMESPACE:
8503 case Token.OPERATOR:
8507 case Token.OVERRIDE:
8513 case Token.PROTECTED:
8517 case Token.READONLY:
8520 case Token.REF_STRUCT:
8521 case Token.REF_PARTIAL:
8531 case Token.STACKALLOC:
8532 return "stackalloc";
8542 case Token.THROW_EXPR:
8550 case Token.UNCHECKED:
8558 case Token.VOLATILE:
8566 case Token.REFVALUE:
8567 return "__refvalue";
8577 case Token.FROM_FIRST:
8595 case Token.ASCENDING:
8597 case Token.DESCENDING:
8598 return "descending";
8605 case Token.OPEN_BRACE:
8607 case Token.CLOSE_BRACE:
8609 case Token.OPEN_BRACKET:
8610 case Token.OPEN_BRACKET_EXPR:
8612 case Token.CLOSE_BRACKET:
8614 case Token.OPEN_PARENS_CAST:
8615 case Token.OPEN_PARENS_LAMBDA:
8616 case Token.OPEN_PARENS_DECONSTRUCT:
8617 case Token.OPEN_PARENS:
8619 case Token.CLOSE_PARENS:
8625 case Token.DEFAULT_COLON:
8629 case Token.SEMICOLON:
8635 case Token.INTERPOLATED_STRING_END:
8637 case Token.INTERPOLATED_STRING:
8646 case Token.BITWISE_AND:
8647 case Token.BITWISE_OR:
8654 case Token.OP_SHIFT_LEFT:
8655 case Token.OP_SHIFT_RIGHT:
8663 case Token.OP_COALESCING:
8664 case Token.OP_MULT_ASSIGN:
8665 case Token.OP_DIV_ASSIGN:
8666 case Token.OP_MOD_ASSIGN:
8667 case Token.OP_ADD_ASSIGN:
8668 case Token.OP_SUB_ASSIGN:
8669 case Token.OP_SHIFT_LEFT_ASSIGN:
8670 case Token.OP_SHIFT_RIGHT_ASSIGN:
8671 case Token.OP_AND_ASSIGN:
8672 case Token.OP_XOR_ASSIGN:
8673 case Token.OP_OR_ASSIGN:
8674 case Token.INTERR_OPERATOR:
8675 return "<operator>";
8697 case Token.OP_GENERICS_LT:
8698 case Token.GENERIC_DIMENSION:
8700 case Token.OP_GENERICS_GT:
8703 case Token.INTERR_NULLABLE:
8705 case Token.DOUBLE_COLON:
8709 case Token.IDENTIFIER:
8711 return "identifier";
8714 return "end-of-file";
8716 // All of these are internal.
8719 case Token.FIRST_KEYWORD:
8720 case Token.EVAL_COMPILATION_UNIT_PARSER:
8721 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8722 case Token.EVAL_STATEMENT_PARSER:
8723 case Token.LAST_KEYWORD:
8724 case Token.GENERATE_COMPLETION:
8725 case Token.COMPLETE_COMPLETION:
8726 return "<internal>";
8728 // A bit more robust.
8730 return yyNames [token];