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,
38 All = Ref | Out | This | Params | Arglist | DefaultValue,
39 PrimaryConstructor = Ref | Out | Params | DefaultValue
42 static readonly object ModifierNone = 0;
44 NamespaceContainer current_namespace;
45 TypeContainer current_container;
46 TypeDefinition current_type;
47 PropertyBase current_property;
48 EventProperty current_event;
49 EventField current_event_field;
50 FieldBase current_field;
53 /// Current block is used to add statements as we find
58 BlockVariable current_variable;
60 Delegate current_delegate;
62 AnonymousMethodExpression current_anonymous_method;
65 /// This is used by the unary_expression code to resolve
66 /// a name against a parameter.
69 // FIXME: This is very ugly and it's very hard to reset it correctly
70 // on all places, especially when some parameters are autogenerated.
71 ParametersCompiled current_local_parameters;
73 bool parsing_anonymous_method;
78 /// An out-of-band stack.
80 Stack<object> oob_stack;
83 /// Controls the verbosity of the errors produced by the parser
85 int yacc_verbose_flag;
88 /// Used by the interactive shell, flags whether EOF was reached
89 /// and an error was produced
91 public bool UnexpectedEOF;
96 readonly CompilationSourceFile file;
99 /// Temporary Xml documentation cache.
100 /// For enum types, we need one more temporary store.
103 string enumTypeComment;
105 /// Current attribute target
106 string current_attr_target;
108 ParameterModifierType valid_param_mod;
110 bool default_parameter_used;
112 /// When using the interactive parser, this holds the
113 /// resulting expression
114 public Class InteractiveResult;
117 // Keeps track of global data changes to undo on parser error
121 bool? interactive_async;
123 Stack<Linq.QueryBlock> linq_clause_blocks;
125 ModuleContainer module;
127 readonly CompilerContext compiler;
128 readonly LanguageVersion lang_version;
129 readonly bool doc_support;
130 readonly CompilerSettings settings;
131 readonly Report report;
134 // Instead of allocating carrier array everytime we
135 // share the bucket for very common constructs which can never
138 List<Parameter> parameters_bucket;
141 // Full AST support members
144 List<Tuple<Modifiers, Location>> mod_locations;
145 Stack<Location> location_stack;
149 %token NONE /* This token is never returned by our lexer */
150 %token ERROR // This is used not by the parser, but by the tokenizer.
154 *These are the C# keywords
253 %token INTERR_NULLABLE
260 %token INTERR_OPERATOR
262 %token INTERPOLATED_STRING
263 %token INTERPOLATED_STRING_END
266 /* C# keywords which are not really keywords */
272 /* C# single character operators/punctuation. */
300 /* C# multi-character operators. */
305 %token OP_SHIFT_RIGHT
312 %token OP_MULT_ASSIGN
317 %token OP_SHIFT_LEFT_ASSIGN
318 %token OP_SHIFT_RIGHT_ASSIGN
325 /* Generics <,> tokens */
326 %token OP_GENERICS_LT
327 %token OP_GENERICS_LT_DECL
328 %token OP_GENERICS_GT
333 %token OPEN_PARENS_LAMBDA
334 %token OPEN_PARENS_CAST
335 %token GENERIC_DIMENSION
337 %token OPEN_BRACKET_EXPR
338 %token OPEN_PARENS_DECONSTRUCT
340 // Make the parser go into eval mode parsing (statements and compilation units).
341 %token EVAL_STATEMENT_PARSER
342 %token EVAL_COMPILATION_UNIT_PARSER
343 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
348 // This token is generated to trigger the completion engine at this point
350 %token GENERATE_COMPLETION
353 // This token is return repeatedly after the first GENERATE_COMPLETION
354 // token is produced and before the final EOF
356 %token COMPLETE_COMPLETION
358 /* Add precedence rules to solve dangling else s/r conflict */
362 /* Define the operator tokens and their precedences */
370 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
372 %left STAR DIV PERCENT
373 %right BANG CARRET UMINUS
374 %nonassoc OP_INC OP_DEC
376 %left OPEN_BRACKET OPEN_BRACE
379 %start compilation_unit
383 : outer_declaration opt_EOF
385 Lexer.check_incorrect_doc_comment ();
387 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
388 | documentation_parsing
392 : opt_extern_alias_directives opt_using_directives
393 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
396 Attributes attrs = (Attributes) $4;
397 report.Error (1730, attrs.Attrs [0].Location,
398 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
400 current_namespace.UnattachedAttributes = attrs;
403 | opt_extern_alias_directives opt_using_directives attribute_sections
405 Attributes attrs = (Attributes) $3;
407 foreach (var a in attrs.Attrs) {
408 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
411 if (a.ExplicitTarget == null)
412 report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
416 module.AddAttributes ((Attributes) $3, current_namespace);
420 if (yyToken == Token.EXTERN_ALIAS)
421 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
423 Error_SyntaxError (yyToken);
432 extern_alias_directives
433 : extern_alias_directive
434 | extern_alias_directives extern_alias_directive
437 extern_alias_directive
438 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
440 var lt = (LocatedToken) $2;
443 syntax_error (lt.Location, "`alias' expected");
445 if (lang_version == LanguageVersion.ISO_1)
446 FeatureIsNotAvailable (lt.Location, "external alias");
448 lt = (LocatedToken) $3;
449 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
450 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
453 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
454 current_namespace.AddUsing (na);
456 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
461 Error_SyntaxError (yyToken);
467 | using_directives using_directive
474 Lexer.doc_state = XmlCommentState.Allowed;
479 : USING opt_static namespace_or_type_expr SEMICOLON
483 if (lang_version <= LanguageVersion.V_5)
484 FeatureIsNotAvailable (GetLocation ($2), "using static");
486 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
487 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
489 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
490 lbag.AddLocation (uc, GetLocation ($4));
493 current_namespace.AddUsing (uc);
495 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
497 var lt = (LocatedToken) $3;
498 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
499 report.Warning (440, 2, lt.Location,
500 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
504 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
507 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
508 current_namespace.AddUsing (un);
510 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
514 Error_SyntaxError (yyToken);
525 // Strictly speaking, namespaces don't have attributes but
526 // we parse global attributes along with namespace declarations and then
529 namespace_declaration
530 : opt_attributes NAMESPACE namespace_name
532 Attributes attrs = (Attributes) $1;
533 var name = (MemberName) $3;
535 bool valid_global_attrs = true;
536 if ((current_namespace.DeclarationFound || current_namespace != file)) {
537 valid_global_attrs = false;
539 foreach (var a in attrs.Attrs) {
540 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
543 valid_global_attrs = false;
548 if (!valid_global_attrs)
549 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
552 module.AddAttributes (attrs, current_namespace);
554 var ns = new NamespaceContainer (name, current_namespace);
555 current_namespace.AddTypeContainer (ns);
556 current_container = current_namespace = ns;
561 Lexer.doc_state = XmlCommentState.Allowed;
563 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
566 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
568 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
570 current_container = current_namespace = current_namespace.Parent;
572 | opt_attributes NAMESPACE namespace_name
574 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
576 var name = (MemberName) $3;
577 var ns = new NamespaceContainer (name, current_namespace);
578 lbag.AddLocation (ns, GetLocation ($2));
579 current_namespace.AddTypeContainer (ns);
588 Error_SyntaxError (yyToken);
596 var lt = (LocatedToken) $1;
597 $$ = new MemberName (lt.Value, lt.Location);
599 | namespace_name DOT IDENTIFIER
601 var lt = (LocatedToken) $3;
602 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
603 lbag.AddLocation ($$, GetLocation ($2));
607 Error_SyntaxError (yyToken);
608 $$ = new MemberName ("<invalid>", lexer.Location);
627 opt_extern_alias_directives
629 | extern_alias_directives
632 opt_namespace_or_type_declarations
634 | namespace_or_type_declarations
637 namespace_or_type_declarations
638 : namespace_or_type_declaration
639 | namespace_or_type_declarations namespace_or_type_declaration
642 namespace_or_type_declaration
646 TypeContainer ds = (TypeContainer)$1;
648 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
649 report.Error (1527, ds.Location,
650 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
653 // Here is a trick, for explicit attributes we don't know where they belong to until
654 // we parse succeeding declaration hence we parse them as normal and re-attach them
655 // when we know whether they are global (assembly:, module:) or local (type:).
656 if (ds.OptAttributes != null) {
657 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
660 current_namespace.DeclarationFound = true;
662 | namespace_declaration
664 current_namespace.DeclarationFound = true;
666 | attribute_sections CLOSE_BRACE {
667 current_namespace.UnattachedAttributes = (Attributes) $1;
668 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
676 | interface_declaration
678 | delegate_declaration
680 // Enable this when we have handled all errors, because this acts as a generic fallback
683 // Console.WriteLine ("Token=" + yyToken);
684 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
700 var sect = (List<Attribute>) $1;
701 $$ = new Attributes (sect);
703 | attribute_sections attribute_section
705 Attributes attrs = $1 as Attributes;
706 var sect = (List<Attribute>) $2;
708 attrs = new Attributes (sect);
709 else if (sect != null)
710 attrs.AddAttributes (sect);
718 PushLocation (GetLocation ($1));
719 lexer.parsing_attribute_section = true;
721 attribute_section_cont
723 lexer.parsing_attribute_section = false;
728 attribute_section_cont
729 : attribute_target COLON
731 current_attr_target = (string) $1;
732 if (current_attr_target == "assembly" || current_attr_target == "module") {
733 Lexer.check_incorrect_doc_comment ();
736 attribute_list opt_comma CLOSE_BRACKET
738 // when attribute target is invalid
739 if (current_attr_target == string.Empty)
740 $$ = new List<Attribute> (0);
744 lbag.InsertLocation ($$, 0, PopLocation ());
746 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
748 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
751 current_attr_target = null;
752 lexer.parsing_attribute_section = false;
754 | attribute_list opt_comma CLOSE_BRACKET
758 lbag.InsertLocation ($$, 0, PopLocation ());
760 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
762 lbag.AddLocation ($$, GetLocation($3));
767 Error_SyntaxError (yyToken);
769 var lt = (LocatedToken) $1;
770 var tne = new SimpleName (lt.Value, null, lt.Location);
772 $$ = new List<Attribute> () {
773 new Attribute (null, tne, null, GetLocation ($1), false)
778 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
779 Error_SyntaxError (yyToken);
788 var lt = (LocatedToken) $1;
789 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
791 | EVENT { $$ = "event"; }
792 | RETURN { $$ = "return"; }
798 $$ = new List<Attribute> (4) { (Attribute) $1 };
800 | attribute_list COMMA attribute
802 var attrs = (List<Attribute>) $1;
804 attrs.Add ((Attribute) $3);
805 lbag.AppendTo (attrs, GetLocation ($2));
815 ++lexer.parsing_block;
817 opt_attribute_arguments
819 --lexer.parsing_block;
821 var tne = (ATypeNameExpression) $1;
822 if (tne.HasTypeArguments) {
823 report.Error (404, tne.Location, "Attributes cannot be generic");
826 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
831 : namespace_or_type_expr
834 opt_attribute_arguments
835 : /* empty */ { $$ = null; }
836 | OPEN_PARENS attribute_arguments CLOSE_PARENS
844 : /* empty */ { $$ = null; }
845 | positional_or_named_argument
847 Arguments a = new Arguments (4);
848 a.Add ((Argument) $1);
849 $$ = new Arguments [] { a, null };
851 | named_attribute_argument
853 Arguments a = new Arguments (4);
854 a.Add ((Argument) $1);
855 $$ = new Arguments [] { null, a };
857 | attribute_arguments COMMA positional_or_named_argument
859 Arguments[] o = (Arguments[]) $1;
861 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
862 o [0] = new Arguments (4);
865 Arguments args = ((Arguments) o [0]);
866 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
867 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
869 args.Add ((Argument) $3);
871 | attribute_arguments COMMA named_attribute_argument
873 Arguments[] o = (Arguments[]) $1;
875 o [1] = new Arguments (4);
878 ((Arguments) o [1]).Add ((Argument) $3);
882 positional_or_named_argument
885 $$ = new Argument ((Expression) $1);
890 Error_SyntaxError (yyToken);
895 named_attribute_argument
898 ++lexer.parsing_block;
902 --lexer.parsing_block;
903 var lt = (LocatedToken) $1;
904 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
905 lbag.AddLocation ($$, GetLocation($2));
910 : identifier_inside_body COLON opt_named_modifier named_argument_expr
912 if (lang_version <= LanguageVersion.V_3)
913 FeatureIsNotAvailable (GetLocation ($1), "named argument");
915 // Avoid boxing in common case (no modifier)
916 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
918 var lt = (LocatedToken) $1;
919 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
920 lbag.AddLocation ($$, GetLocation($2));
922 | identifier_inside_body COLON OUT named_argument_expr_or_out_variable_declaration
924 if (lang_version <= LanguageVersion.V_3)
925 FeatureIsNotAvailable (GetLocation ($1), "named argument");
927 var lt = (LocatedToken) $1;
928 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, Argument.AType.Out);
929 lbag.AddLocation ($$, GetLocation($2));
934 : expression_or_error
937 named_argument_expr_or_out_variable_declaration
938 : expression_or_error
939 | out_variable_declaration
943 : /* empty */ { $$ = null; }
946 $$ = Argument.AType.Ref;
950 opt_class_member_declarations
952 | class_member_declarations
955 class_member_declarations
956 : class_member_declaration
958 lexer.parsing_modifiers = true;
959 lexer.parsing_block = 0;
961 | class_member_declarations class_member_declaration
963 lexer.parsing_modifiers = true;
964 lexer.parsing_block = 0;
968 class_member_declaration
969 : constant_declaration
972 | property_declaration
974 | indexer_declaration
975 | operator_declaration
976 | constructor_declaration
977 | primary_constructor_body
978 | destructor_declaration
980 | attributes_without_members
984 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
985 GetSymbolName (yyToken));
987 lexer.parsing_generic_declaration = false;
991 primary_constructor_body
994 current_local_parameters = current_type.PrimaryConstructorParameters;
995 if (current_local_parameters == null) {
996 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
997 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1000 ++lexer.parsing_block;
1001 start_block (GetLocation ($1));
1003 opt_statement_list block_end
1005 current_local_parameters = null;
1006 var t = current_type as ClassOrStruct;
1008 var b = (ToplevelBlock) $4;
1009 if (t.PrimaryConstructorBlock != null) {
1010 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
1012 t.PrimaryConstructorBlock = b;
1023 type_declaration_name
1025 var mods = (Modifiers) $2;
1026 if ((mods & Modifiers.READONLY) != 0 && lang_version < LanguageVersion.V_7_2) {
1027 FeatureIsNotAvailable (GetLocation ($4), "readonly structs");
1030 lexer.ConstraintsParsing = true;
1031 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1032 push_current_container (new Struct (current_container, (MemberName) $5, mods, (Attributes) $1), $3);
1034 opt_primary_parameters
1036 opt_type_parameter_constraints_clauses
1038 valid_param_mod = 0;
1039 lexer.ConstraintsParsing = false;
1042 current_type.PrimaryConstructorParameters = (ParametersCompiled) $7;
1045 current_container.SetConstraints ((List<Constraints>) $9);
1048 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1050 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1052 lexer.parsing_modifiers = true;
1057 Lexer.doc_state = XmlCommentState.Allowed;
1059 opt_class_member_declarations CLOSE_BRACE
1061 --lexer.parsing_declaration;
1063 Lexer.doc_state = XmlCommentState.Allowed;
1068 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
1070 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
1072 $$ = pop_current_class ();
1074 | opt_attributes opt_modifiers opt_partial STRUCT error
1076 Error_SyntaxError (yyToken);
1080 constant_declaration
1083 CONST type IDENTIFIER
1085 var lt = (LocatedToken) $5;
1086 var mod = (Modifiers) $2;
1087 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1088 current_type.AddMember (current_field);
1090 if ((mod & Modifiers.STATIC) != 0) {
1091 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1096 constant_initializer opt_constant_declarators SEMICOLON
1099 current_field.DocComment = Lexer.consume_doc_comment ();
1100 Lexer.doc_state = XmlCommentState.Allowed;
1103 current_field.Initializer = (ConstInitializer) $7;
1104 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1105 current_field = null;
1111 Error_SyntaxError (yyToken);
1113 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1117 opt_constant_declarators
1119 | constant_declarators
1122 constant_declarators
1123 : constant_declarator
1125 current_field.AddDeclarator ((FieldDeclarator) $1);
1127 | constant_declarators constant_declarator
1129 current_field.AddDeclarator ((FieldDeclarator) $2);
1134 : COMMA IDENTIFIER constant_initializer
1136 var lt = (LocatedToken) $2;
1137 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1138 lbag.AddLocation ($$, GetLocation ($1));
1142 constant_initializer
1145 ++lexer.parsing_block;
1147 constant_initializer_expr
1149 --lexer.parsing_block;
1150 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1154 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1159 constant_initializer_expr
1160 : constant_expression
1167 ref_member_type IDENTIFIER
1169 lexer.parsing_generic_declaration = false;
1171 FullNamedExpression type = (FullNamedExpression) $3;
1172 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1173 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1175 var lt = (LocatedToken) $4;
1176 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1177 current_type.AddField (current_field);
1180 opt_field_initializer
1181 opt_field_declarators
1185 current_field.DocComment = Lexer.consume_doc_comment ();
1186 Lexer.doc_state = XmlCommentState.Allowed;
1189 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1191 current_field = null;
1195 FIXED simple_type IDENTIFIER
1197 if (lang_version < LanguageVersion.ISO_2)
1198 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1200 var lt = (LocatedToken) $5;
1201 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1202 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1204 current_type.AddField (current_field);
1206 fixed_field_size opt_fixed_field_declarators SEMICOLON
1209 current_field.DocComment = Lexer.consume_doc_comment ();
1210 Lexer.doc_state = XmlCommentState.Allowed;
1213 current_field.Initializer = (ConstInitializer) $7;
1214 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1216 current_field = null;
1220 FIXED simple_type error
1223 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1227 opt_field_initializer
1231 ++lexer.parsing_block;
1232 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1233 start_block (GetLocation ($1));
1235 variable_initializer
1237 --lexer.parsing_block;
1238 current_field.Initializer = (Expression) $3;
1239 lbag.AppendToMember (current_field, GetLocation ($1));
1240 end_block (lexer.Location);
1241 current_local_parameters = null;
1245 opt_field_declarators
1253 current_field.AddDeclarator ((FieldDeclarator) $1);
1255 | field_declarators field_declarator
1257 current_field.AddDeclarator ((FieldDeclarator) $2);
1264 var lt = (LocatedToken) $2;
1265 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1266 lbag.AddLocation ($$, GetLocation ($1));
1268 | COMMA IDENTIFIER ASSIGN
1270 ++lexer.parsing_block;
1272 variable_initializer
1274 --lexer.parsing_block;
1275 var lt = (LocatedToken) $2;
1276 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1277 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1281 opt_fixed_field_declarators
1283 | fixed_field_declarators
1286 fixed_field_declarators
1287 : fixed_field_declarator
1289 current_field.AddDeclarator ((FieldDeclarator) $1);
1291 | fixed_field_declarators fixed_field_declarator
1293 current_field.AddDeclarator ((FieldDeclarator) $2);
1297 fixed_field_declarator
1298 : COMMA IDENTIFIER fixed_field_size
1300 var lt = (LocatedToken) $2;
1301 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1302 lbag.AddLocation ($$, GetLocation ($1));
1309 ++lexer.parsing_block;
1311 expression CLOSE_BRACKET
1313 --lexer.parsing_block;
1314 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1315 lbag.AddLocation ($$, GetLocation ($4));
1317 | OPEN_BRACKET error
1319 report.Error (443, lexer.Location, "Value or constant expected");
1324 variable_initializer
1329 // It has to be here for the parent to safely restore artificial block
1330 Error_SyntaxError (yyToken);
1339 Lexer.doc_state = XmlCommentState.NotAllowed;
1341 // Was added earlier in the case of body being eof for full ast
1345 Method method = (Method) $1;
1346 method.Block = (ToplevelBlock) $3;
1347 async_block = false;
1349 if (method.Block == null) {
1350 method.ParameterInfo.CheckParameters (method);
1352 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1353 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1354 method.GetSignatureForError ());
1357 if (current_container.Kind == MemberKind.Interface) {
1358 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1359 method.GetSignatureForError ());
1363 current_local_parameters = null;
1366 Lexer.doc_state = XmlCommentState.Allowed;
1377 lexer.parsing_generic_declaration = true;
1381 if (lang_version < LanguageVersion.V_7) {
1382 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
1385 $$ = new ReferenceTypeExpr ((FullNamedExpression) $3, GetLocation ($1));
1393 method_declaration_name OPEN_PARENS
1395 valid_param_mod = ParameterModifierType.All;
1397 opt_formal_parameter_list CLOSE_PARENS
1399 valid_param_mod = 0;
1400 MemberName name = (MemberName) $4;
1401 current_local_parameters = (ParametersCompiled) $7;
1403 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1404 name, current_local_parameters, (Attributes) $1);
1406 current_type.AddMember (method);
1408 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1411 method.DocComment = Lexer.consume_doc_comment ();
1413 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1417 lexer.ConstraintsParsing = true;
1419 opt_type_parameter_constraints_clauses
1421 lexer.ConstraintsParsing = false;
1424 var method = (Method) $9;
1425 method.SetConstraints ((List<Constraints>) $10);
1435 lexer.parsing_generic_declaration = true;
1437 method_declaration_name
1440 lexer.parsing_generic_declaration = false;
1441 valid_param_mod = ParameterModifierType.All;
1443 opt_formal_parameter_list CLOSE_PARENS
1445 lexer.ConstraintsParsing = true;
1447 opt_type_parameter_constraints_clauses
1449 lexer.ConstraintsParsing = false;
1450 valid_param_mod = 0;
1452 MemberName name = (MemberName) $6;
1453 current_local_parameters = (ParametersCompiled) $9;
1455 var modifiers = (Modifiers) $2;
1456 modifiers |= Modifiers.PARTIAL;
1458 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1459 modifiers, name, current_local_parameters, (Attributes) $1);
1461 current_type.AddMember (method);
1463 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1466 method.SetConstraints ((List<Constraints>) $12);
1469 method.DocComment = Lexer.consume_doc_comment ();
1471 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1472 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1478 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1480 MemberName name = (MemberName) $5;
1481 report.Error (1585, name.Location,
1482 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1484 var method = Method.Create (current_type, (FullNamedExpression) $3,
1485 0, name, (ParametersCompiled) $7, (Attributes) $1);
1487 current_type.AddMember (method);
1489 current_local_parameters = (ParametersCompiled) $7;
1492 method.DocComment = Lexer.consume_doc_comment ();
1499 method_declaration_name error
1501 Error_SyntaxError (yyToken);
1502 current_local_parameters = ParametersCompiled.Undefined;
1504 MemberName name = (MemberName) $4;
1505 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1506 name, current_local_parameters, (Attributes) $1);
1508 current_type.AddMember (method);
1511 method.DocComment = Lexer.consume_doc_comment ();
1520 | SEMICOLON { $$ = null; }
1529 | SEMICOLON { current_block = null; $$ = null; }
1532 if (lang_version < LanguageVersion.V_7) {
1533 FeatureIsNotAvailable (GetLocation ($1), "expression body constructor");
1536 ++lexer.parsing_block;
1538 expression SEMICOLON
1540 lexer.parsing_block = 0;
1541 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1542 var b = end_block (GetLocation ($4));
1543 b.IsCompilerGenerated = true;
1545 current_block = null;
1552 if (lang_version < LanguageVersion.V_6) {
1553 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1556 ++lexer.parsing_block;
1557 start_block (GetLocation ($1));
1559 lambda_arrow_expression SEMICOLON
1561 lexer.parsing_block = 0;
1562 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1563 var b = end_block (GetLocation ($4));
1564 b.IsCompilerGenerated = true;
1569 opt_formal_parameter_list
1570 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1571 | formal_parameter_list
1574 formal_parameter_list
1577 var pars_list = (List<Parameter>) $1;
1578 $$ = new ParametersCompiled (pars_list.ToArray ());
1580 | fixed_parameters COMMA parameter_array
1582 var pars_list = (List<Parameter>) $1;
1583 pars_list.Add ((Parameter) $3);
1585 $$ = new ParametersCompiled (pars_list.ToArray ());
1587 | fixed_parameters COMMA arglist_modifier
1589 var pars_list = (List<Parameter>) $1;
1590 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1591 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1593 | parameter_array COMMA error
1596 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1598 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1600 | fixed_parameters COMMA parameter_array COMMA error
1603 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1605 var pars_list = (List<Parameter>) $1;
1606 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1608 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1610 | arglist_modifier COMMA error
1612 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1614 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1616 | fixed_parameters COMMA ARGLIST COMMA error
1618 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1620 var pars_list = (List<Parameter>) $1;
1621 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1623 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1627 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1631 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1635 Error_SyntaxError (yyToken);
1636 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1643 parameters_bucket.Clear ();
1644 Parameter p = (Parameter) $1;
1645 parameters_bucket.Add (p);
1647 default_parameter_used = p.HasDefaultValue;
1648 $$ = parameters_bucket;
1650 | fixed_parameters COMMA fixed_parameter
1652 var pars = (List<Parameter>) $1;
1653 Parameter p = (Parameter) $3;
1655 if (p.HasExtensionMethodModifier)
1656 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1657 else if (!p.HasDefaultValue && default_parameter_used)
1658 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1660 default_parameter_used |= p.HasDefaultValue;
1663 lbag.AddLocation (p, GetLocation ($2));
1672 opt_parameter_modifier
1674 identifier_inside_body
1676 var lt = (LocatedToken) $4;
1677 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1680 opt_parameter_modifier
1682 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1684 var lt = (LocatedToken) $4;
1685 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1686 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1688 | attribute_sections error
1690 Error_SyntaxError (yyToken);
1691 Location l = GetLocation ($2);
1692 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1695 opt_parameter_modifier
1699 Error_SyntaxError (yyToken);
1700 Location l = GetLocation ($4);
1701 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1704 opt_parameter_modifier
1706 identifier_inside_body
1709 ++lexer.parsing_block;
1713 --lexer.parsing_block;
1714 if (lang_version <= LanguageVersion.V_3) {
1715 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1718 Parameter.Modifier mod = (Parameter.Modifier) $2;
1719 if (mod != Parameter.Modifier.NONE) {
1721 case Parameter.Modifier.REF:
1722 case Parameter.Modifier.OUT:
1723 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1724 Parameter.GetModifierSignature (mod));
1727 case Parameter.Modifier.This:
1728 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1729 Parameter.GetModifierSignature (mod));
1732 throw new NotImplementedException (mod.ToString ());
1735 mod = Parameter.Modifier.NONE;
1738 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1739 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1741 var lt = (LocatedToken) $4;
1742 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1743 lbag.AddLocation ($$, GetLocation ($5));
1746 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1750 opt_parameter_modifier
1751 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1752 | parameter_modifiers
1756 : parameter_modifier
1760 | parameter_modifiers parameter_modifier
1762 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1763 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1764 if (((Parameter.Modifier)$1 & p2) == p2) {
1765 Error_DuplicateParameterModifier (lexer.Location, p2);
1767 switch (mod & ~Parameter.Modifier.This) {
1768 case Parameter.Modifier.REF:
1769 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1771 case Parameter.Modifier.OUT:
1772 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1775 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1786 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1787 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1789 $$ = Parameter.Modifier.REF;
1793 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1794 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1796 $$ = Parameter.Modifier.OUT;
1800 if ((valid_param_mod & ParameterModifierType.This) == 0)
1801 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1803 if (lang_version <= LanguageVersion.ISO_2)
1804 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1806 $$ = Parameter.Modifier.This;
1811 : opt_attributes params_modifier type IDENTIFIER
1813 var lt = (LocatedToken) $4;
1814 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1816 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1818 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1820 var lt = (LocatedToken) $4;
1821 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1823 | opt_attributes params_modifier type error
1825 Error_SyntaxError (yyToken);
1827 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1834 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1835 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1837 | PARAMS parameter_modifier
1839 Parameter.Modifier mod = (Parameter.Modifier)$2;
1840 if ((mod & Parameter.Modifier.This) != 0) {
1841 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1843 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1846 | PARAMS params_modifier
1848 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1855 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1856 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1860 property_declaration
1864 member_declaration_name
1866 lexer.parsing_generic_declaration = false;
1868 tmpComment = Lexer.consume_doc_comment ();
1872 var type = (FullNamedExpression) $3;
1873 current_property = new Property (current_type, type, (Modifiers) $2,
1874 (MemberName) $4, (Attributes) $1);
1876 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1877 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1879 current_type.AddMember (current_property);
1880 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1882 lexer.PropertyParsing = true;
1884 accessor_declarations
1886 lexer.PropertyParsing = false;
1889 current_property.DocComment = ConsumeStoredComment ();
1891 if ($3 is ReferenceTypeExpr) {
1892 if (current_property.Get == null) {
1893 report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
1896 if (current_property.Set != null) {
1897 report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
1903 lbag.AppendToMember (current_property, GetLocation ($10));
1904 lexer.parsing_modifiers = true;
1906 opt_property_initializer
1908 current_property = null;
1913 member_declaration_name
1915 lexer.parsing_generic_declaration = false;
1917 tmpComment = Lexer.consume_doc_comment ();
1918 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1922 var type = (FullNamedExpression) $3;
1923 var property = new Property (current_type, type, (Modifiers) $2,
1924 (MemberName) $4, (Attributes) $1);
1926 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1927 property.Get.Block = (ToplevelBlock) $6;
1929 if (current_container.Kind == MemberKind.Interface) {
1930 report.Error (531, property.Get.Block.StartLocation,
1931 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1934 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1935 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1938 property.DocComment = ConsumeStoredComment ();
1940 current_type.AddMember (property);
1942 current_local_parameters = null;
1946 opt_property_initializer
1950 ++lexer.parsing_block;
1951 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1952 start_block (GetLocation ($1));
1954 property_initializer SEMICOLON
1956 --lexer.parsing_block;
1957 ((Property)current_property).Initializer = (Expression) $3;
1958 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1959 end_block (GetLocation ($4));
1960 current_local_parameters = null;
1963 Lexer.doc_state = XmlCommentState.Allowed;
1967 property_initializer
1973 : opt_attributes opt_modifiers
1974 ref_member_type indexer_declaration_name OPEN_BRACKET
1976 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1978 opt_formal_parameter_list CLOSE_BRACKET
1980 valid_param_mod = 0;
1981 var type = (FullNamedExpression) $3;
1982 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1984 current_property = indexer;
1986 current_type.AddIndexer (indexer);
1987 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1989 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1990 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1992 if (indexer.ParameterInfo.IsEmpty) {
1993 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1997 tmpComment = Lexer.consume_doc_comment ();
1998 Lexer.doc_state = XmlCommentState.Allowed;
2001 lexer.PropertyParsing = true;
2002 current_local_parameters = (ParametersCompiled) $7;
2006 lexer.PropertyParsing = false;
2007 current_local_parameters = null;
2009 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
2010 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
2013 current_property.DocComment = ConsumeStoredComment ();
2015 if ($3 is ReferenceTypeExpr) {
2016 if (current_property.Get == null) {
2017 report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
2020 if (current_property.Set != null) {
2021 report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
2025 current_property = null;
2030 : OPEN_BRACE accessor_declarations CLOSE_BRACE
2032 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
2036 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
2037 current_property.Get.Block = (ToplevelBlock) $1;
2041 accessor_declarations
2042 : get_accessor_declaration
2043 | get_accessor_declaration accessor_declarations
2044 | set_accessor_declaration
2045 | set_accessor_declaration accessor_declarations
2048 if (yyToken == Token.CLOSE_BRACE) {
2049 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
2051 if (yyToken == Token.SEMICOLON)
2052 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
2054 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
2059 get_accessor_declaration
2060 : opt_attributes opt_modifiers GET
2062 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2063 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2066 if (current_property.Get != null) {
2067 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2070 if (current_property is Indexer) {
2071 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
2072 (Attributes) $1, GetLocation ($3));
2074 current_property.Get = new Property.GetMethod (current_property,
2075 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2078 current_local_parameters = current_property.Get.ParameterInfo;
2079 lbag.AddMember (current_property.Get, mod_locations);
2080 lexer.PropertyParsing = false;
2085 current_property.Get.Block = (ToplevelBlock) $5;
2087 if (current_container.Kind == MemberKind.Interface) {
2088 report.Error (531, current_property.Get.Block.StartLocation,
2089 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2093 current_local_parameters = null;
2094 lexer.PropertyParsing = true;
2097 if (Lexer.doc_state == XmlCommentState.Error)
2098 Lexer.doc_state = XmlCommentState.NotAllowed;
2102 set_accessor_declaration
2103 : opt_attributes opt_modifiers SET
2105 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2106 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2109 if (current_property.Set != null) {
2110 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2113 if (current_property is Indexer) {
2114 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2115 ParametersCompiled.MergeGenerated (compiler,
2116 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2117 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2119 (Attributes) $1, GetLocation ($3));
2121 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2122 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2123 (Attributes) $1, GetLocation ($3));
2126 current_local_parameters = current_property.Set.ParameterInfo;
2127 lbag.AddMember (current_property.Set, mod_locations);
2128 lexer.PropertyParsing = false;
2133 current_property.Set.Block = (ToplevelBlock) $5;
2135 if (current_container.Kind == MemberKind.Interface) {
2136 report.Error (531, current_property.Set.Block.StartLocation,
2137 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2141 current_local_parameters = null;
2142 lexer.PropertyParsing = true;
2145 && Lexer.doc_state == XmlCommentState.Error)
2146 Lexer.doc_state = XmlCommentState.NotAllowed;
2160 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2166 interface_declaration
2173 type_declaration_name
2175 lexer.ConstraintsParsing = true;
2176 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2177 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2180 opt_type_parameter_constraints_clauses
2182 lexer.ConstraintsParsing = false;
2185 current_container.SetConstraints ((List<Constraints>) $9);
2188 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2189 Lexer.doc_state = XmlCommentState.Allowed;
2192 lexer.parsing_modifiers = true;
2194 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2196 --lexer.parsing_declaration;
2198 Lexer.doc_state = XmlCommentState.Allowed;
2203 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2205 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2207 $$ = pop_current_class ();
2209 | opt_attributes opt_modifiers opt_partial INTERFACE error
2211 Error_SyntaxError (yyToken);
2215 opt_interface_member_declarations
2217 | interface_member_declarations
2220 interface_member_declarations
2221 : interface_member_declaration
2223 lexer.parsing_modifiers = true;
2224 lexer.parsing_block = 0;
2226 | interface_member_declarations interface_member_declaration
2228 lexer.parsing_modifiers = true;
2229 lexer.parsing_block = 0;
2233 interface_member_declaration
2234 : constant_declaration
2236 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2240 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2242 | method_declaration
2243 | property_declaration
2245 | indexer_declaration
2246 | operator_declaration
2248 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2250 | constructor_declaration
2252 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2256 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2260 operator_declaration
2261 : opt_attributes opt_modifiers operator_declarator
2266 OperatorDeclaration decl = (OperatorDeclaration) $3;
2268 Operator op = new Operator (
2269 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2270 current_local_parameters,
2271 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2273 if (op.Block == null)
2274 op.ParameterInfo.CheckParameters (op);
2277 op.DocComment = tmpComment;
2278 Lexer.doc_state = XmlCommentState.Allowed;
2281 // Note again, checking is done in semantic analysis
2282 current_type.AddOperator (op);
2284 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2287 current_local_parameters = null;
2292 : type_expression_or_array
2295 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2296 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2301 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2303 valid_param_mod = ParameterModifierType.DefaultValue;
2304 if ((Operator.OpType) $3 == Operator.OpType.Is)
2305 valid_param_mod |= ParameterModifierType.Out;
2307 opt_formal_parameter_list CLOSE_PARENS
2309 valid_param_mod = 0;
2311 Location loc = GetLocation ($2);
2312 Operator.OpType op = (Operator.OpType) $3;
2313 current_local_parameters = (ParametersCompiled)$6;
2315 int p_count = current_local_parameters.Count;
2317 if (op == Operator.OpType.Addition)
2318 op = Operator.OpType.UnaryPlus;
2319 else if (op == Operator.OpType.Subtraction)
2320 op = Operator.OpType.UnaryNegation;
2323 if (IsUnaryOperator (op)) {
2325 report.Error (1020, loc, "Overloadable binary operator expected");
2326 } else if (p_count != 1) {
2327 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2328 Operator.GetName (op));
2330 } else if (op == Operator.OpType.Is) {
2331 // TODO: Special checks for is operator
2334 report.Error (1019, loc, "Overloadable unary operator expected");
2335 } else if (p_count != 2) {
2336 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2337 Operator.GetName (op));
2342 tmpComment = Lexer.consume_doc_comment ();
2343 Lexer.doc_state = XmlCommentState.NotAllowed;
2346 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2347 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2349 | conversion_operator_declarator
2352 overloadable_operator
2354 : BANG { $$ = Operator.OpType.LogicalNot; }
2355 | TILDE { $$ = Operator.OpType.OnesComplement; }
2356 | OP_INC { $$ = Operator.OpType.Increment; }
2357 | OP_DEC { $$ = Operator.OpType.Decrement; }
2358 | TRUE { $$ = Operator.OpType.True; }
2359 | FALSE { $$ = Operator.OpType.False; }
2360 // Unary and binary:
2361 | PLUS { $$ = Operator.OpType.Addition; }
2362 | MINUS { $$ = Operator.OpType.Subtraction; }
2364 | STAR { $$ = Operator.OpType.Multiply; }
2365 | DIV { $$ = Operator.OpType.Division; }
2366 | PERCENT { $$ = Operator.OpType.Modulus; }
2367 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2368 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2369 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2370 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2371 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2372 | OP_EQ { $$ = Operator.OpType.Equality; }
2373 | OP_NE { $$ = Operator.OpType.Inequality; }
2374 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2375 | OP_LT { $$ = Operator.OpType.LessThan; }
2376 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2377 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2380 if (lang_version != LanguageVersion.Experimental)
2381 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2383 $$ = Operator.OpType.Is;
2387 conversion_operator_declarator
2388 : IMPLICIT OPERATOR type OPEN_PARENS
2390 valid_param_mod = ParameterModifierType.DefaultValue;
2392 opt_formal_parameter_list CLOSE_PARENS
2394 valid_param_mod = 0;
2396 Location loc = GetLocation ($2);
2397 current_local_parameters = (ParametersCompiled)$6;
2399 if (current_local_parameters.Count != 1) {
2400 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2404 tmpComment = Lexer.consume_doc_comment ();
2405 Lexer.doc_state = XmlCommentState.NotAllowed;
2408 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2409 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2411 | EXPLICIT OPERATOR type OPEN_PARENS
2413 valid_param_mod = ParameterModifierType.DefaultValue;
2415 opt_formal_parameter_list CLOSE_PARENS
2417 valid_param_mod = 0;
2419 Location loc = GetLocation ($2);
2420 current_local_parameters = (ParametersCompiled)$6;
2422 if (current_local_parameters.Count != 1) {
2423 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2427 tmpComment = Lexer.consume_doc_comment ();
2428 Lexer.doc_state = XmlCommentState.NotAllowed;
2431 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2432 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2436 Error_SyntaxError (yyToken);
2437 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2438 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2442 Error_SyntaxError (yyToken);
2443 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2444 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2448 constructor_declaration
2449 : constructor_declarator
2452 Constructor c = (Constructor) $1;
2453 c.Block = (ToplevelBlock) $2;
2456 c.DocComment = ConsumeStoredComment ();
2458 current_local_parameters = null;
2460 Lexer.doc_state = XmlCommentState.Allowed;
2464 constructor_declarator
2470 tmpComment = Lexer.consume_doc_comment ();
2471 Lexer.doc_state = XmlCommentState.Allowed;
2474 valid_param_mod = ParameterModifierType.All;
2476 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2478 valid_param_mod = 0;
2479 current_local_parameters = (ParametersCompiled) $6;
2481 var lt = (LocatedToken) $3;
2482 var mods = (Modifiers) $2;
2483 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2485 if (lt.Value != current_container.MemberName.Name) {
2486 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2487 } else if ((mods & Modifiers.STATIC) != 0) {
2488 if (!current_local_parameters.IsEmpty) {
2489 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2490 c.GetSignatureForError ());
2493 if ((mods & Modifiers.AccessibilityMask) != 0){
2494 report.Error (515, c.Location,
2495 "`{0}': static constructor cannot have an access modifier",
2496 c.GetSignatureForError ());
2499 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2500 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2504 current_type.AddConstructor (c);
2505 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2509 // start block here, so possible anonymous methods inside
2510 // constructor initializer can get correct parent block
2512 start_block (lexer.Location);
2514 opt_constructor_initializer
2517 var c = (Constructor) $8;
2518 c.Initializer = (ConstructorInitializer) $9;
2521 report.Error (514, c.Location,
2522 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2523 c.GetSignatureForError ());
2531 opt_constructor_initializer
2533 | constructor_initializer
2536 constructor_initializer
2537 : COLON BASE OPEN_PARENS
2539 ++lexer.parsing_block;
2541 opt_argument_list CLOSE_PARENS
2543 --lexer.parsing_block;
2544 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2545 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2547 | COLON THIS OPEN_PARENS
2549 ++lexer.parsing_block;
2551 opt_argument_list CLOSE_PARENS
2553 --lexer.parsing_block;
2554 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2555 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2559 Error_SyntaxError (yyToken);
2560 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2561 lbag.AddLocation ($$, GetLocation ($1));
2565 Error_SyntaxError (yyToken);
2570 destructor_declaration
2571 : opt_attributes opt_modifiers TILDE
2574 tmpComment = Lexer.consume_doc_comment ();
2575 Lexer.doc_state = XmlCommentState.NotAllowed;
2578 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2580 IDENTIFIER OPEN_PARENS CLOSE_PARENS destructor_body
2582 var lt = (LocatedToken) $5;
2583 if (lt.Value != current_container.MemberName.Name){
2584 report.Error (574, lt.Location, "Name of destructor must match name of class");
2585 } else if (current_container.Kind != MemberKind.Class){
2586 report.Error (575, lt.Location, "Only class types can contain destructor");
2589 Destructor d = new Destructor (current_type, (Modifiers) $2,
2590 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2592 d.DocComment = ConsumeStoredComment ();
2594 d.Block = (ToplevelBlock) $8;
2595 current_type.AddMember (d);
2596 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2598 current_local_parameters = null;
2605 EVENT type member_declaration_name
2607 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2608 current_type.AddMember (current_event_field);
2610 if (current_event_field.MemberName.ExplicitInterface != null) {
2611 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2612 current_event_field.GetSignatureForError ());
2615 $$ = current_event_field;
2617 opt_event_initializer
2618 opt_event_declarators
2622 current_event_field.DocComment = Lexer.consume_doc_comment ();
2623 Lexer.doc_state = XmlCommentState.Allowed;
2626 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2627 current_event_field = null;
2631 EVENT type member_declaration_name
2634 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2635 current_type.AddMember (current_event);
2636 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2638 lexer.EventParsing = true;
2640 event_accessor_declarations
2642 if (current_container.Kind == MemberKind.Interface)
2643 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2645 lexer.EventParsing = false;
2650 current_event.DocComment = Lexer.consume_doc_comment ();
2651 Lexer.doc_state = XmlCommentState.Allowed;
2654 lbag.AppendToMember (current_event, GetLocation ($9));
2655 current_event = null;
2656 current_local_parameters = null;
2662 Error_SyntaxError (yyToken);
2664 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2668 opt_event_initializer
2672 ++lexer.parsing_block;
2674 event_variable_initializer
2676 --lexer.parsing_block;
2677 current_event_field.Initializer = (Expression) $3;
2681 opt_event_declarators
2689 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2691 | event_declarators event_declarator
2693 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2700 var lt = (LocatedToken) $2;
2701 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2702 lbag.AddLocation ($$, GetLocation ($1));
2704 | COMMA IDENTIFIER ASSIGN event_variable_initializer
2706 var lt = (LocatedToken) $2;
2707 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $4);
2708 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2712 event_variable_initializer
2714 if (current_container.Kind == MemberKind.Interface) {
2715 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2716 current_event_field.GetSignatureForError ());
2719 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2720 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2721 current_event_field.GetSignatureForError ());
2724 ++lexer.parsing_block;
2725 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2726 start_block (lexer.Location);
2728 variable_initializer
2732 --lexer.parsing_block;
2733 end_block (lexer.Location);
2734 current_local_parameters = null;
2738 event_accessor_declarations
2739 : add_accessor_declaration remove_accessor_declaration
2740 | remove_accessor_declaration add_accessor_declaration
2741 | add_accessor_declaration
2743 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2744 current_event.GetSignatureForError ());
2746 | remove_accessor_declaration
2748 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2749 current_event.GetSignatureForError ());
2753 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2758 add_accessor_declaration
2759 : opt_attributes opt_modifiers ADD
2761 if ($2 != ModifierNone) {
2762 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2765 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2766 current_local_parameters = current_event.Add.ParameterInfo;
2768 lbag.AddMember (current_event.Add, mod_locations);
2769 lexer.EventParsing = false;
2771 event_accessor_block
2773 lexer.EventParsing = true;
2775 current_event.Add.Block = (ToplevelBlock) $5;
2777 if (current_container.Kind == MemberKind.Interface) {
2778 report.Error (531, current_event.Add.Block.StartLocation,
2779 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2782 current_local_parameters = null;
2786 remove_accessor_declaration
2787 : opt_attributes opt_modifiers REMOVE
2789 if ($2 != ModifierNone) {
2790 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2793 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2794 current_local_parameters = current_event.Remove.ParameterInfo;
2796 lbag.AddMember (current_event.Remove, mod_locations);
2797 lexer.EventParsing = false;
2799 event_accessor_block
2801 lexer.EventParsing = true;
2803 current_event.Remove.Block = (ToplevelBlock) $5;
2805 if (current_container.Kind == MemberKind.Interface) {
2806 report.Error (531, current_event.Remove.Block.StartLocation,
2807 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2810 current_local_parameters = null;
2814 event_accessor_block
2817 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2824 attributes_without_members
2825 : attribute_sections CLOSE_BRACE
2827 current_type.UnattachedAttributes = (Attributes) $1;
2828 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2829 lexer.putback ('}');
2833 // For full ast try to recover incomplete ambiguous member
2834 // declaration in form on class X { public int }
2836 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2838 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2840 lexer.putback ('}');
2842 lexer.parsing_generic_declaration = false;
2843 FullNamedExpression type = (FullNamedExpression) $3;
2844 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2845 current_type.AddField (current_field);
2853 ENUM type_declaration_name
2857 enumTypeComment = Lexer.consume_doc_comment ();
2862 Lexer.doc_state = XmlCommentState.Allowed;
2864 MemberName name = (MemberName) $4;
2865 if (name.IsGeneric) {
2866 report.Error (1675, name.Location, "Enums cannot have type parameters");
2869 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2871 opt_enum_member_declarations
2873 lexer.parsing_modifiers = true;
2875 // here will be evaluated after CLOSE_BLACE is consumed.
2877 Lexer.doc_state = XmlCommentState.Allowed;
2879 CLOSE_BRACE opt_semicolon
2882 current_container.DocComment = enumTypeComment;
2884 --lexer.parsing_declaration;
2887 // em.DocComment = ev.DocComment;
2889 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2890 $$ = pop_current_class ();
2902 Error_TypeExpected (GetLocation ($1));
2907 opt_enum_member_declarations
2909 | enum_member_declarations
2910 | enum_member_declarations COMMA
2912 lbag.AddLocation ($1, GetLocation ($2));
2916 enum_member_declarations
2917 : enum_member_declaration
2918 | enum_member_declarations COMMA enum_member_declaration
2920 lbag.AddLocation ($1, GetLocation ($2));
2925 enum_member_declaration
2926 : opt_attributes IDENTIFIER
2928 var lt = (LocatedToken) $2;
2929 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2930 ((Enum) current_type).AddEnumMember (em);
2933 em.DocComment = Lexer.consume_doc_comment ();
2934 Lexer.doc_state = XmlCommentState.Allowed;
2939 | opt_attributes IDENTIFIER
2941 ++lexer.parsing_block;
2943 tmpComment = Lexer.consume_doc_comment ();
2944 Lexer.doc_state = XmlCommentState.NotAllowed;
2947 ASSIGN constant_expression
2949 --lexer.parsing_block;
2951 var lt = (LocatedToken) $2;
2952 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2953 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2954 ((Enum) current_type).AddEnumMember (em);
2957 em.DocComment = ConsumeStoredComment ();
2961 | opt_attributes IDENTIFIER error
2963 Error_SyntaxError (yyToken);
2965 var lt = (LocatedToken) $2;
2966 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2967 ((Enum) current_type).AddEnumMember (em);
2970 em.DocComment = Lexer.consume_doc_comment ();
2971 Lexer.doc_state = XmlCommentState.Allowed;
2976 | attributes_without_members
2979 delegate_declaration
2983 ref_member_type type_declaration_name
2986 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2988 opt_formal_parameter_list CLOSE_PARENS
2990 valid_param_mod = 0;
2992 ParametersCompiled p = (ParametersCompiled) $8;
2994 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2996 p.CheckParameters (del);
2998 current_container.AddTypeContainer (del);
3000 current_delegate = del;
3001 lexer.ConstraintsParsing = true;
3003 opt_type_parameter_constraints_clauses
3005 lexer.ConstraintsParsing = false;
3010 current_delegate.DocComment = Lexer.consume_doc_comment ();
3011 Lexer.doc_state = XmlCommentState.Allowed;
3015 current_delegate.SetConstraints ((List<Constraints>) $11);
3016 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
3018 $$ = current_delegate;
3020 current_delegate = null;
3028 if (lang_version < LanguageVersion.ISO_2)
3029 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
3031 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
3035 namespace_or_type_expr
3037 | qualified_alias_member IDENTIFIER opt_type_argument_list
3039 var lt1 = (LocatedToken) $1;
3040 var lt2 = (LocatedToken) $2;
3042 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3043 lbag.AddLocation ($$, GetLocation ($2));
3045 | qualified_alias_member IDENTIFIER generic_dimension
3047 var lt1 = (LocatedToken) $1;
3048 var lt2 = (LocatedToken) $2;
3050 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3051 lbag.AddLocation ($$, GetLocation ($2));
3057 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
3059 var lt = (LocatedToken) $3;
3060 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3061 lbag.AddLocation ($$, GetLocation ($2));
3063 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
3065 var lt = (LocatedToken) $3;
3066 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3067 lbag.AddLocation ($$, GetLocation ($2));
3072 : IDENTIFIER opt_type_argument_list
3074 var lt = (LocatedToken) $1;
3075 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3077 | IDENTIFIER generic_dimension
3079 var lt = (LocatedToken) $1;
3080 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3085 // Generics arguments (any type, without attributes)
3087 opt_type_argument_list
3089 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3091 if (lang_version < LanguageVersion.ISO_2)
3092 FeatureIsNotAvailable (GetLocation ($1), "generics");
3096 | OP_GENERICS_LT error
3098 Error_TypeExpected (lexer.Location);
3099 $$ = new TypeArguments ();
3106 TypeArguments type_args = new TypeArguments ();
3107 type_args.Add ((FullNamedExpression) $1);
3110 | type_arguments COMMA type
3112 TypeArguments type_args = (TypeArguments) $1;
3113 type_args.Add ((FullNamedExpression) $3);
3119 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3121 type_declaration_name
3124 lexer.parsing_generic_declaration = true;
3126 opt_type_parameter_list
3128 lexer.parsing_generic_declaration = false;
3129 var lt = (LocatedToken) $1;
3130 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3134 member_declaration_name
3135 : method_declaration_name
3137 MemberName mn = (MemberName)$1;
3138 if (mn.TypeParameters != null)
3139 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3140 mn.GetSignatureForError ()));
3144 method_declaration_name
3145 : type_declaration_name
3146 | explicit_interface IDENTIFIER opt_type_parameter_list
3148 lexer.parsing_generic_declaration = false;
3149 var lt = (LocatedToken) $2;
3150 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3154 indexer_declaration_name
3157 lexer.parsing_generic_declaration = false;
3158 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3160 | explicit_interface THIS
3162 lexer.parsing_generic_declaration = false;
3163 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3168 : IDENTIFIER opt_type_argument_list DOT
3170 var lt = (LocatedToken) $1;
3171 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3172 lbag.AddLocation ($$, GetLocation ($3));
3174 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3176 var lt1 = (LocatedToken) $1;
3177 var lt2 = (LocatedToken) $2;
3179 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3180 lbag.AddLocation ($$, GetLocation ($4));
3182 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3184 var lt = (LocatedToken) $2;
3185 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3186 lbag.AddLocation ($$, GetLocation ($4));
3190 opt_type_parameter_list
3192 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3194 if (lang_version < LanguageVersion.ISO_2)
3195 FeatureIsNotAvailable (GetLocation ($1), "generics");
3198 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3205 var tparams = new TypeParameters ();
3206 tparams.Add ((TypeParameter)$1);
3209 | type_parameters COMMA type_parameter
3211 var tparams = (TypeParameters) $1;
3212 tparams.Add ((TypeParameter)$3);
3214 lbag.AddLocation ($3, GetLocation ($3));
3219 : opt_attributes opt_type_parameter_variance IDENTIFIER
3221 var lt = (LocatedToken)$3;
3222 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3226 if (GetTokenName (yyToken) == "type")
3227 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3229 Error_SyntaxError (yyToken);
3231 $$ = new TypeParameter (MemberName.Null, null, null);
3236 // All types where void is allowed
3239 : type_expression_or_array
3242 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3249 lexer.parsing_generic_declaration = true;
3254 // A type which does not allow `void' to be used
3257 : type_expression_or_array
3267 : type_expression_or_array
3270 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3271 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3275 type_expression_or_array
3277 | type_expression rank_specifiers
3279 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3284 : namespace_or_type_expr opt_nullable
3287 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3289 var sn = $1 as SimpleName;
3290 if (sn != null && sn.Name == "var")
3291 $$ = new VarExpr (sn.Location);
3296 | namespace_or_type_expr pointer_stars
3298 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3300 | builtin_type_expression
3301 | OPEN_PARENS tuple_elements CLOSE_PARENS opt_nullable
3303 if (lang_version < LanguageVersion.V_7)
3304 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3306 var a = (Tuple<TypeArguments, List<string>>) $2;
3307 if (a.Item1.Count < 2) {
3308 report.Error (8124, GetLocation ($1), "Tuple must contain at least two elements");
3311 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
3314 $$ = new ComposedCast ((FullNamedExpression) $$, (ComposedTypeSpecifier) $4);
3319 : tuple_element tuple_element_name
3321 var type_args = new TypeArguments ();
3322 type_args.Add ((FullNamedExpression) $1);
3324 var names = new List<string> (2);
3325 var lt = (LocatedToken) $2;
3326 names.Add (lt?.Value);
3328 $$ = Tuple.Create (type_args, names);
3330 | tuple_elements COMMA tuple_element tuple_element_name
3332 var a = (Tuple<TypeArguments, List<string>>) $1;
3333 a.Item1.Add ((FullNamedExpression) $3);
3334 var lt = (LocatedToken) $4;
3335 a.Item2.Add (lt?.Value);
3352 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3353 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3357 builtin_type_expression
3358 : builtin_types opt_nullable
3361 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3363 | builtin_types pointer_stars
3365 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3367 | VOID pointer_stars
3369 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3376 var types = new List<FullNamedExpression> (2);
3377 types.Add ((FullNamedExpression) $1);
3380 | type_list COMMA base_type_name
3382 var types = (List<FullNamedExpression>) $1;
3383 types.Add ((FullNamedExpression) $3);
3391 if ($1 is ComposedCast) {
3392 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3399 * replaces all the productions for isolating the various
3400 * simple types, but we need this to reuse it easily in variable_type
3403 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3404 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3405 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3406 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3407 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3408 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3413 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3414 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3415 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3416 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3417 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3418 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3419 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3420 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3421 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3425 // Expressions, section 7.5
3430 : type_name_expression
3432 | array_creation_expression
3433 | parenthesized_expression
3434 | default_value_expression
3435 | invocation_expression
3439 | post_increment_expression
3440 | post_decrement_expression
3441 | object_or_delegate_creation_expression
3442 | anonymous_type_expression
3445 | checked_expression
3446 | unchecked_expression
3447 | pointer_member_access
3448 | anonymous_method_expression
3449 | undocumented_expressions
3450 | interpolated_string
3453 type_name_expression
3455 | IDENTIFIER GENERATE_COMPLETION {
3456 var lt = (LocatedToken) $1;
3457 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3466 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3470 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3471 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3475 : OPEN_PARENS tuple_literal_elements CLOSE_PARENS
3477 if (lang_version < LanguageVersion.V_7)
3478 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3480 $$ = new TupleLiteral ((List<TupleLiteralElement>)$2, GetLocation ($1));
3484 tuple_literal_elements
3485 : tuple_literal_element COMMA tuple_literal_element
3487 $$ = new List<TupleLiteralElement> () {
3488 (TupleLiteralElement) $1, (TupleLiteralElement) $3
3491 | tuple_literal_elements COMMA tuple_literal_element
3493 var list = (List<TupleLiteralElement>)$1;
3494 list.Add ((TupleLiteralElement) $3);
3498 tuple_literal_element
3501 $$ = new TupleLiteralElement ((Expression) $1);
3503 | IDENTIFIER COLON expression
3505 var lt = (LocatedToken) $1;
3506 $$ = new TupleLiteralElement (lt.Value, (Expression) $3, lt.Location);
3511 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3513 if (lang_version < LanguageVersion.V_6)
3514 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3516 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3518 | INTERPOLATED_STRING_END
3520 if (lang_version < LanguageVersion.V_6)
3521 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3523 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3530 var list = new List<Expression> ();
3531 list.Add ((InterpolatedStringInsert) $1);
3534 | interpolations INTERPOLATED_STRING interpolation
3536 var list = (List<Expression>) $1;
3537 list.Add ((StringLiteral) $2);
3538 list.Add ((InterpolatedStringInsert) $3);
3546 $$ = new InterpolatedStringInsert ((Expression) $1);
3548 | expression COMMA expression
3550 $$ = new InterpolatedStringInsert ((Expression) $1) {
3551 Alignment = (Expression)$3
3556 lexer.parsing_interpolation_format = true;
3560 lexer.parsing_interpolation_format = false;
3562 $$ = new InterpolatedStringInsert ((Expression) $1) {
3566 | expression COMMA expression COLON
3568 lexer.parsing_interpolation_format = true;
3572 lexer.parsing_interpolation_format = false;
3574 $$ = new InterpolatedStringInsert ((Expression) $1) {
3575 Alignment = (Expression)$3,
3576 Format = (string) $6
3583 // Here is the trick, tokenizer may think that parens is a special but
3584 // parser is interested in open parens only, so we merge them.
3585 // Consider: if (a)foo ();
3593 // Use this production to accept closing parenthesis or
3594 // performing completion
3598 | COMPLETE_COMPLETION
3602 parenthesized_expression
3603 : OPEN_PARENS expression CLOSE_PARENS
3605 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3606 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3608 | OPEN_PARENS expression COMPLETE_COMPLETION
3610 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3615 : primary_expression DOT identifier_inside_body opt_type_argument_list
3617 var lt = (LocatedToken) $3;
3618 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3619 lbag.AddLocation ($$, GetLocation ($2));
3621 | primary_expression DOT identifier_inside_body generic_dimension
3623 var lt = (LocatedToken) $3;
3624 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3625 lbag.AddLocation ($$, GetLocation ($2));
3627 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3629 if (lang_version < LanguageVersion.V_6)
3630 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3632 var lt = (LocatedToken) $4;
3633 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3634 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3636 | builtin_types DOT identifier_inside_body opt_type_argument_list
3638 var lt = (LocatedToken) $3;
3639 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3640 lbag.AddLocation ($$, GetLocation ($2));
3642 | BASE DOT identifier_inside_body opt_type_argument_list
3644 var lt = (LocatedToken) $3;
3645 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3646 lbag.AddLocation ($$, GetLocation ($2));
3648 | AWAIT DOT identifier_inside_body opt_type_argument_list
3650 var lt = (LocatedToken) $3;
3651 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3652 lbag.AddLocation ($$, GetLocation ($2));
3654 | qualified_alias_member identifier_inside_body opt_type_argument_list
3656 var lt1 = (LocatedToken) $1;
3657 var lt2 = (LocatedToken) $2;
3659 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3660 lbag.AddLocation ($$, GetLocation ($2));
3662 | qualified_alias_member identifier_inside_body generic_dimension
3664 var lt1 = (LocatedToken) $1;
3665 var lt2 = (LocatedToken) $2;
3667 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3668 lbag.AddLocation ($$, GetLocation ($2));
3670 | primary_expression DOT GENERATE_COMPLETION {
3671 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3673 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3674 var lt = (LocatedToken) $3;
3675 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3677 | builtin_types DOT GENERATE_COMPLETION
3679 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3681 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3682 var lt = (LocatedToken) $3;
3683 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3687 invocation_expression
3688 : primary_expression open_parens_any opt_argument_list close_parens
3690 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3691 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3693 | primary_expression open_parens_any argument_list error
3695 Error_SyntaxError (yyToken);
3697 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3698 lbag.AddLocation ($$, GetLocation ($2));
3700 | primary_expression open_parens_any error
3702 Error_SyntaxError (yyToken);
3704 $$ = new Invocation ((Expression) $1, null);
3705 lbag.AddLocation ($$, GetLocation ($2));
3709 opt_object_or_collection_initializer
3710 : /* empty */ { $$ = null; }
3711 | object_or_collection_initializer
3714 object_or_collection_initializer
3715 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3718 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3720 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3722 lbag.AddLocation ($$, GetLocation ($3));
3724 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3726 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3727 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3731 opt_member_initializer_list
3732 : /* empty */ { $$ = null; }
3733 | member_initializer_list
3739 member_initializer_list
3740 : member_initializer
3742 var a = new List<Expression> ();
3743 a.Add ((Expression) $1);
3746 | member_initializer_list COMMA member_initializer
3748 var a = (List<Expression>)$1;
3749 a.Add ((Expression) $3);
3752 | member_initializer_list error {
3753 Error_SyntaxError (yyToken);
3759 : IDENTIFIER ASSIGN initializer_value
3761 var lt = (LocatedToken) $1;
3762 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3763 lbag.AddLocation ($$, GetLocation ($2));
3765 | AWAIT ASSIGN initializer_value
3767 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3768 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3769 lbag.AddLocation ($$, GetLocation ($2));
3771 | GENERATE_COMPLETION
3773 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3775 | non_assignment_expression opt_COMPLETE_COMPLETION {
3776 CompletionSimpleName csn = $1 as CompletionSimpleName;
3778 $$ = new CollectionElementInitializer ((Expression)$1);
3780 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3782 | OPEN_BRACE expression_list CLOSE_BRACE
3785 $$ = new CollectionElementInitializer (GetLocation ($1));
3787 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3789 lbag.AddLocation ($$, GetLocation ($3));
3791 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3793 if (lang_version < LanguageVersion.V_6)
3794 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3796 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3797 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3799 | OPEN_BRACE CLOSE_BRACE
3801 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3802 $$ = new CollectionElementInitializer (GetLocation ($1));
3803 lbag.AddLocation ($$, GetLocation ($2));
3809 | object_or_collection_initializer
3813 : /* empty */ { $$ = null; }
3818 : argument_or_named_argument
3820 Arguments list = new Arguments (4);
3821 list.Add ((Argument) $1);
3824 | argument_list COMMA argument
3826 Arguments list = (Arguments) $1;
3827 if (list [list.Count - 1] is NamedArgument)
3828 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3830 list.Add ((Argument) $3);
3833 | argument_list COMMA named_argument
3835 Arguments list = (Arguments) $1;
3836 NamedArgument a = (NamedArgument) $3;
3837 for (int i = 0; i < list.Count; ++i) {
3838 NamedArgument na = list [i] as NamedArgument;
3839 if (na != null && na.Name == a.Name)
3840 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3847 | argument_list COMMA error
3849 if (lexer.putback_char == -1)
3850 lexer.putback (')'); // TODO: Wrong but what can I do
3851 Error_SyntaxError (yyToken);
3856 report.Error (839, GetLocation ($1), "An argument is missing");
3864 $$ = new Argument ((Expression) $1);
3866 | non_simple_argument
3869 argument_or_named_argument
3875 : REF variable_reference
3877 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3878 lbag.AddLocation ($$, GetLocation ($1));
3880 | OUT variable_reference
3882 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3883 lbag.AddLocation ($$, GetLocation ($1));
3885 | OUT out_variable_declaration
3887 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3889 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3891 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3892 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3894 | ARGLIST OPEN_PARENS CLOSE_PARENS
3896 $$ = new Argument (new Arglist (GetLocation ($1)));
3897 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3901 out_variable_declaration
3902 : variable_type identifier_inside_body
3904 if (lang_version < LanguageVersion.V_7)
3905 FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
3907 var lt = (LocatedToken) $2;
3908 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3909 current_block.AddLocalName (lv);
3910 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3919 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3921 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3922 lbag.AddLocation ($$, GetLocation ($4));
3924 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3926 if (lang_version < LanguageVersion.V_6)
3927 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3929 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3930 ConditionalAccess = true
3933 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3935 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3937 Error_SyntaxError (yyToken);
3938 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3940 | primary_expression OPEN_BRACKET_EXPR error
3942 Error_SyntaxError (yyToken);
3943 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3948 : expression_or_error
3950 var list = new List<Expression> (4);
3951 list.Add ((Expression) $1);
3954 | expression_list COMMA expression_or_error
3956 var list = (List<Expression>) $1;
3957 list.Add ((Expression) $3);
3962 expression_list_arguments
3963 : expression_list_argument
3965 Arguments args = new Arguments (4);
3966 args.Add ((Argument) $1);
3969 | expression_list_arguments COMMA expression_list_argument
3971 Arguments args = (Arguments) $1;
3972 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3973 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3975 args.Add ((Argument) $3);
3980 expression_list_argument
3983 $$ = new Argument ((Expression) $1);
3991 $$ = new This (GetLocation ($1));
3996 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3998 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3999 lbag.AddLocation ($$, GetLocation ($4));
4001 | BASE OPEN_BRACKET error
4003 Error_SyntaxError (yyToken);
4004 $$ = new ElementAccess (null, null, GetLocation ($2));
4008 post_increment_expression
4009 : primary_expression OP_INC
4011 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
4015 post_decrement_expression
4016 : primary_expression OP_DEC
4018 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
4022 object_or_delegate_creation_expression
4023 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
4026 if (lang_version <= LanguageVersion.ISO_2)
4027 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
4029 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
4031 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
4034 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4036 | NEW new_expr_type object_or_collection_initializer
4038 if (lang_version <= LanguageVersion.ISO_2)
4039 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
4041 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
4045 array_creation_expression
4046 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
4048 opt_array_initializer
4050 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
4051 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
4052 Next = (ComposedTypeSpecifier) $6
4053 }, (ArrayInitializer) $7, GetLocation ($1)) {
4054 NoEmptyInterpolation = true
4057 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4059 | NEW new_expr_type rank_specifiers opt_array_initializer
4062 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
4064 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
4065 NoEmptyInterpolation = true
4068 | NEW rank_specifier array_initializer
4070 if (lang_version <= LanguageVersion.ISO_2)
4071 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
4073 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
4075 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
4077 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
4078 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
4080 | NEW new_expr_type error
4082 Error_SyntaxError (yyToken);
4083 // It can be any of new expression, create the most common one
4084 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
4090 ++lexer.parsing_type;
4094 --lexer.parsing_type;
4099 anonymous_type_expression
4100 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
4102 if (lang_version <= LanguageVersion.ISO_2)
4103 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
4105 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
4107 // TODO: lbag comma location
4108 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4110 | NEW OPEN_BRACE GENERATE_COMPLETION
4112 $$ = new EmptyCompletion ();
4116 anonymous_type_parameters_opt_comma
4117 : anonymous_type_parameters_opt
4118 | anonymous_type_parameters COMMA
4121 anonymous_type_parameters_opt
4123 | anonymous_type_parameters
4126 anonymous_type_parameters
4127 : anonymous_type_parameter
4129 var a = new List<AnonymousTypeParameter> (4);
4130 a.Add ((AnonymousTypeParameter) $1);
4133 | anonymous_type_parameters COMMA anonymous_type_parameter
4135 var a = (List<AnonymousTypeParameter>) $1;
4136 a.Add ((AnonymousTypeParameter) $3);
4139 | COMPLETE_COMPLETION
4141 $$ = new EmptyCompletion ();
4143 | anonymous_type_parameter COMPLETE_COMPLETION
4149 anonymous_type_parameter
4150 : identifier_inside_body ASSIGN variable_initializer
4152 var lt = (LocatedToken)$1;
4153 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4154 lbag.AddLocation ($$, GetLocation ($2));
4156 | identifier_inside_body
4158 var lt = (LocatedToken)$1;
4159 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4160 lt.Value, lt.Location);
4164 MemberAccess ma = (MemberAccess) $1;
4165 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4169 report.Error (746, lexer.Location,
4170 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4182 | rank_specifier rank_specifiers
4184 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4190 : OPEN_BRACKET CLOSE_BRACKET
4192 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4193 lbag.AddLocation ($$, GetLocation ($2));
4195 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4197 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4198 lbag.AddLocation ($$, GetLocation ($3));
4207 | dim_separators COMMA
4209 $$ = ((int) $1) + 1;
4213 opt_array_initializer
4225 : OPEN_BRACE CLOSE_BRACE
4227 var ai = new ArrayInitializer (0, GetLocation ($1));
4228 ai.VariableDeclaration = current_variable;
4229 lbag.AddLocation (ai, GetLocation ($2));
4232 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4234 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4235 ai.VariableDeclaration = current_variable;
4237 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4239 lbag.AddLocation (ai, GetLocation ($4));
4245 variable_initializer_list
4246 : variable_initializer
4248 var list = new List<Expression> (4);
4249 list.Add ((Expression) $1);
4252 | variable_initializer_list COMMA variable_initializer
4254 var list = (List<Expression>) $1;
4255 list.Add ((Expression) $3);
4261 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4263 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4264 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4268 typeof_type_expression
4272 Error_TypeExpected (lexer.Location);
4280 if (lang_version < LanguageVersion.ISO_2)
4281 FeatureIsNotAvailable (GetLocation ($1), "generics");
4287 qualified_alias_member
4288 : IDENTIFIER DOUBLE_COLON
4290 var lt = (LocatedToken) $1;
4291 if (lang_version == LanguageVersion.ISO_1)
4292 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4299 : SIZEOF open_parens_any type CLOSE_PARENS
4301 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4302 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4304 | SIZEOF open_parens_any type error
4306 Error_SyntaxError (yyToken);
4308 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4309 lbag.AddLocation ($$, GetLocation ($2));
4314 : CHECKED open_parens_any expression CLOSE_PARENS
4316 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4317 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4321 Error_SyntaxError (yyToken);
4323 $$ = new CheckedExpr (null, GetLocation ($1));
4327 unchecked_expression
4328 : UNCHECKED open_parens_any expression CLOSE_PARENS
4330 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4331 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4335 Error_SyntaxError (yyToken);
4337 $$ = new UnCheckedExpr (null, GetLocation ($1));
4341 pointer_member_access
4342 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4344 var lt = (LocatedToken) $3;
4345 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4349 anonymous_method_expression
4350 : DELEGATE opt_anonymous_method_signature
4352 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4356 $$ = end_anonymous ((ParametersBlock) $4);
4358 | ASYNC DELEGATE opt_anonymous_method_signature
4360 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4364 $$ = end_anonymous ((ParametersBlock) $5);
4368 opt_anonymous_method_signature
4371 $$ = ParametersCompiled.Undefined;
4373 | anonymous_method_signature
4376 anonymous_method_signature
4379 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4381 opt_formal_parameter_list CLOSE_PARENS
4383 valid_param_mod = 0;
4388 default_value_expression
4389 : DEFAULT open_parens_any type CLOSE_PARENS
4391 if (lang_version < LanguageVersion.ISO_2)
4392 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4394 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4395 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4400 : primary_expression
4401 | BANG prefixed_unary_expression
4403 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4405 | TILDE prefixed_unary_expression
4407 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4409 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4411 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4412 lbag.AddLocation ($$, GetLocation ($3));
4414 | AWAIT prefixed_unary_expression
4417 if (current_anonymous_method is LambdaExpression) {
4418 report.Error (4034, GetLocation ($1),
4419 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4420 } else if (current_anonymous_method != null) {
4421 report.Error (4035, GetLocation ($1),
4422 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4423 } else if (interactive_async != null) {
4424 current_block.Explicit.RegisterAsyncAwait ();
4425 interactive_async = true;
4427 report.Error (4033, GetLocation ($1),
4428 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4431 current_block.Explicit.RegisterAsyncAwait ();
4434 $$ = new Await ((Expression) $2, GetLocation ($1));
4436 | THROW_EXPR prefixed_unary_expression
4438 if (lang_version < LanguageVersion.V_7)
4439 FeatureIsNotAvailable (lexer.Location, "throw expression");
4441 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4445 Error_SyntaxError (yyToken);
4447 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4451 Error_SyntaxError (yyToken);
4453 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4455 | OPEN_PARENS_CAST type CLOSE_PARENS error
4457 Error_SyntaxError (yyToken);
4459 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4460 lbag.AddLocation ($$, GetLocation ($3));
4464 Error_SyntaxError (yyToken);
4466 $$ = new Await (null, GetLocation ($1));
4471 // The idea to split this out is from Rhys' grammar
4472 // to solve the problem with casts.
4474 prefixed_unary_expression
4476 | PLUS prefixed_unary_expression
4478 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4480 | MINUS prefixed_unary_expression
4482 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4484 | OP_INC prefixed_unary_expression
4486 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4488 | OP_DEC prefixed_unary_expression
4490 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4492 | STAR prefixed_unary_expression
4494 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4496 | BITWISE_AND prefixed_unary_expression
4498 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4502 Error_SyntaxError (yyToken);
4504 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4508 Error_SyntaxError (yyToken);
4510 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4514 Error_SyntaxError (yyToken);
4516 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4520 Error_SyntaxError (yyToken);
4522 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4526 Error_SyntaxError (yyToken);
4528 $$ = new Indirection (null, GetLocation ($1));
4532 Error_SyntaxError (yyToken);
4534 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4537 multiplicative_expression
4538 : prefixed_unary_expression
4539 | multiplicative_expression STAR prefixed_unary_expression
4541 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4542 lbag.AddLocation ($$, GetLocation ($2));
4544 | multiplicative_expression DIV prefixed_unary_expression
4546 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4547 lbag.AddLocation ($$, GetLocation ($2));
4549 | multiplicative_expression PERCENT prefixed_unary_expression
4551 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4552 lbag.AddLocation ($$, GetLocation ($2));
4554 | multiplicative_expression STAR error
4556 Error_SyntaxError (yyToken);
4558 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4559 lbag.AddLocation ($$, GetLocation ($2));
4561 | multiplicative_expression DIV error
4563 Error_SyntaxError (yyToken);
4565 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4566 lbag.AddLocation ($$, GetLocation ($2));
4568 | multiplicative_expression PERCENT error
4570 Error_SyntaxError (yyToken);
4572 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4573 lbag.AddLocation ($$, GetLocation ($2));
4578 : multiplicative_expression
4579 | additive_expression PLUS multiplicative_expression
4581 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4582 lbag.AddLocation ($$, GetLocation ($2));
4584 | additive_expression MINUS multiplicative_expression
4586 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4587 lbag.AddLocation ($$, GetLocation ($2));
4589 | additive_expression PLUS error
4591 Error_SyntaxError (yyToken);
4593 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4594 lbag.AddLocation ($$, GetLocation ($2));
4596 | additive_expression MINUS error
4598 Error_SyntaxError (yyToken);
4600 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4601 lbag.AddLocation ($$, GetLocation ($2));
4603 | additive_expression AS type
4605 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4607 | additive_expression IS pattern_type_expr opt_identifier
4609 var is_expr = new Is ((Expression) $1, ((FullNamedExpression) $3), GetLocation ($2));
4611 if (lang_version < LanguageVersion.V_7)
4612 FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
4614 var lt = (LocatedToken) $4;
4615 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
4616 is_expr.Variable = lv;
4617 current_block.AddLocalName (lv);
4622 | additive_expression IS pattern_expr
4624 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4625 if (lang_version != LanguageVersion.Experimental)
4626 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4630 | additive_expression AS error
4632 Error_SyntaxError (yyToken);
4634 $$ = new As ((Expression) $1, null, GetLocation ($2));
4636 | additive_expression IS error
4638 Error_SyntaxError (yyToken);
4640 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4644 var lt = (LocatedToken) $1;
4645 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4649 var lt = (LocatedToken) $1;
4650 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4660 | PLUS prefixed_unary_expression
4662 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4664 | MINUS prefixed_unary_expression
4666 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4669 | default_value_expression
4670 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4672 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4673 lbag.AddLocation ($$, GetLocation ($3));
4677 $$ = new WildcardPattern (GetLocation ($1));
4679 /* | pattern_expr_invocation */
4684 pattern_expr_invocation
4685 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4687 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4693 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4695 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4699 pattern_property_list
4700 : pattern_property_entry
4702 var list = new List<PropertyPatternMember> ();
4703 list.Add ((PropertyPatternMember) $1);
4706 | pattern_property_list COMMA pattern_property_entry
4708 var list = (List<PropertyPatternMember>) $1;
4709 list.Add ((PropertyPatternMember) $3);
4714 pattern_property_entry
4715 : identifier_inside_body IS pattern
4717 var lt = (LocatedToken) $1;
4718 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4724 | pattern_type_expr opt_identifier
4727 var lt = (LocatedToken) $2;
4728 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4729 current_block.AddLocalName (variable);
4738 $$ = new Arguments (0);
4746 Arguments args = new Arguments (4);
4747 args.Add ((Argument) $1);
4750 | pattern_list COMMA pattern_argument
4752 Arguments args = (Arguments) $1;
4753 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4754 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4756 args.Add ((Argument) $3);
4765 $$ = new Argument ((Expression) $1);
4767 | IDENTIFIER COLON pattern
4769 var lt = (LocatedToken) $1;
4770 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4776 : additive_expression
4777 | shift_expression OP_SHIFT_LEFT additive_expression
4779 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4780 lbag.AddLocation ($$, GetLocation ($2));
4782 | shift_expression OP_SHIFT_RIGHT additive_expression
4784 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4785 lbag.AddLocation ($$, GetLocation ($2));
4787 | shift_expression OP_SHIFT_LEFT error
4789 Error_SyntaxError (yyToken);
4791 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4792 lbag.AddLocation ($$, GetLocation ($2));
4794 | shift_expression OP_SHIFT_RIGHT error
4796 Error_SyntaxError (yyToken);
4798 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4799 lbag.AddLocation ($$, GetLocation ($2));
4803 relational_expression
4805 | relational_expression OP_LT shift_expression
4807 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4808 lbag.AddLocation ($$, GetLocation ($2));
4810 | relational_expression OP_GT shift_expression
4812 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4813 lbag.AddLocation ($$, GetLocation ($2));
4815 | relational_expression OP_LE shift_expression
4817 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4818 lbag.AddLocation ($$, GetLocation ($2));
4820 | relational_expression OP_GE shift_expression
4822 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4823 lbag.AddLocation ($$, GetLocation ($2));
4825 | relational_expression OP_LT error
4827 Error_SyntaxError (yyToken);
4829 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4830 lbag.AddLocation ($$, GetLocation ($2));
4832 | relational_expression OP_GT error
4834 Error_SyntaxError (yyToken);
4836 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4837 lbag.AddLocation ($$, GetLocation ($2));
4839 | relational_expression OP_LE error
4841 Error_SyntaxError (yyToken);
4843 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4844 lbag.AddLocation ($$, GetLocation ($2));
4846 | relational_expression OP_GE error
4848 Error_SyntaxError (yyToken);
4850 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4851 lbag.AddLocation ($$, GetLocation ($2));
4856 : relational_expression
4857 | equality_expression OP_EQ relational_expression
4859 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4860 lbag.AddLocation ($$, GetLocation ($2));
4862 | equality_expression OP_NE relational_expression
4864 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4865 lbag.AddLocation ($$, GetLocation ($2));
4867 | equality_expression OP_EQ error
4869 Error_SyntaxError (yyToken);
4871 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4872 lbag.AddLocation ($$, GetLocation ($2));
4874 | equality_expression OP_NE error
4876 Error_SyntaxError (yyToken);
4878 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4879 lbag.AddLocation ($$, GetLocation ($2));
4884 : equality_expression
4885 | and_expression BITWISE_AND equality_expression
4887 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4888 lbag.AddLocation ($$, GetLocation ($2));
4890 | and_expression BITWISE_AND error
4892 Error_SyntaxError (yyToken);
4894 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4895 lbag.AddLocation ($$, GetLocation ($2));
4899 exclusive_or_expression
4901 | exclusive_or_expression CARRET and_expression
4903 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4904 lbag.AddLocation ($$, GetLocation ($2));
4906 | exclusive_or_expression CARRET error
4908 Error_SyntaxError (yyToken);
4910 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4911 lbag.AddLocation ($$, GetLocation ($2));
4915 inclusive_or_expression
4916 : exclusive_or_expression
4917 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4919 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4920 lbag.AddLocation ($$, GetLocation ($2));
4922 | inclusive_or_expression BITWISE_OR error
4924 Error_SyntaxError (yyToken);
4926 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4927 lbag.AddLocation ($$, GetLocation ($2));
4931 conditional_and_expression
4932 : inclusive_or_expression
4933 | conditional_and_expression OP_AND inclusive_or_expression
4935 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4936 lbag.AddLocation ($$, GetLocation ($2));
4938 | conditional_and_expression OP_AND error
4940 Error_SyntaxError (yyToken);
4942 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4943 lbag.AddLocation ($$, GetLocation ($2));
4947 conditional_or_expression
4948 : conditional_and_expression
4949 | conditional_or_expression OP_OR conditional_and_expression
4951 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4952 lbag.AddLocation ($$, GetLocation ($2));
4954 | conditional_or_expression OP_OR error
4956 Error_SyntaxError (yyToken);
4958 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4959 lbag.AddLocation ($$, GetLocation ($2));
4963 null_coalescing_expression
4964 : conditional_or_expression
4965 | conditional_or_expression OP_COALESCING null_coalescing_expression
4967 if (lang_version < LanguageVersion.ISO_2)
4968 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4970 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4971 lbag.AddLocation ($$, GetLocation ($2));
4975 conditional_expression
4976 : null_coalescing_expression
4977 | null_coalescing_expression INTERR expression COLON expression
4979 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4980 lbag.AddLocation ($$, GetLocation ($4));
4982 | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4984 if (lang_version < LanguageVersion.V_7)
4985 FeatureIsNotAvailable (lexer.Location, "throw expression");
4987 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4988 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4989 lbag.AddLocation ($$, GetLocation ($4));
4991 | null_coalescing_expression INTERR expression error
4993 Error_SyntaxError (yyToken);
4995 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4997 | null_coalescing_expression INTERR expression COLON error
4999 Error_SyntaxError (yyToken);
5001 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
5002 lbag.AddLocation ($$, GetLocation ($4));
5004 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
5006 Error_SyntaxError (Token.CLOSE_BRACE);
5008 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
5009 lbag.AddLocation ($$, GetLocation ($4));
5010 lexer.putback ('}');
5014 assignment_expression
5015 : prefixed_unary_expression ASSIGN expression
5017 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
5018 lbag.AddLocation ($$, GetLocation ($2));
5020 | prefixed_unary_expression OP_MULT_ASSIGN expression
5022 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
5023 lbag.AddLocation ($$, GetLocation ($2));
5025 | prefixed_unary_expression OP_DIV_ASSIGN expression
5027 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
5028 lbag.AddLocation ($$, GetLocation ($2));
5030 | prefixed_unary_expression OP_MOD_ASSIGN expression
5032 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
5033 lbag.AddLocation ($$, GetLocation ($2));
5035 | prefixed_unary_expression OP_ADD_ASSIGN expression
5037 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
5038 lbag.AddLocation ($$, GetLocation ($2));
5040 | prefixed_unary_expression OP_SUB_ASSIGN expression
5042 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
5043 lbag.AddLocation ($$, GetLocation ($2));
5045 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
5047 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
5048 lbag.AddLocation ($$, GetLocation ($2));
5050 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
5052 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
5053 lbag.AddLocation ($$, GetLocation ($2));
5055 | prefixed_unary_expression OP_AND_ASSIGN expression
5057 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
5058 lbag.AddLocation ($$, GetLocation ($2));
5060 | prefixed_unary_expression OP_OR_ASSIGN expression
5062 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
5063 lbag.AddLocation ($$, GetLocation ($2));
5065 | prefixed_unary_expression OP_XOR_ASSIGN expression
5067 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
5068 lbag.AddLocation ($$, GetLocation ($2));
5070 | OPEN_PARENS_DECONSTRUCT deconstruct_exprs CLOSE_PARENS ASSIGN expression
5072 if (lang_version < LanguageVersion.V_7)
5073 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5075 var exprs = (List<Expression>) $2;
5076 $$ = new TupleDeconstruct (exprs, (Expression) $5, GetLocation ($4));
5081 : expression COMMA expression
5083 $$ = new List<Expression> () {
5088 | deconstruct_exprs COMMA expression
5090 var src = (List<Expression>) $1;
5091 src.Add ((Expression) $3);
5096 lambda_parameter_list
5099 var pars = new List<Parameter> (4);
5100 pars.Add ((Parameter) $1);
5104 | lambda_parameter_list COMMA lambda_parameter
5106 var pars = (List<Parameter>) $1;
5107 Parameter p = (Parameter)$3;
5108 if (pars[0].GetType () != p.GetType ()) {
5109 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
5118 : parameter_modifier parameter_type identifier_inside_body
5120 var lt = (LocatedToken) $3;
5122 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
5124 | parameter_type identifier_inside_body
5126 var lt = (LocatedToken) $2;
5128 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
5132 var lt = (LocatedToken) $1;
5133 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5137 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5138 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5142 opt_lambda_parameter_list
5143 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
5144 | lambda_parameter_list {
5145 var pars_list = (List<Parameter>) $1;
5146 $$ = new ParametersCompiled (pars_list.ToArray ());
5150 lambda_expression_body
5152 start_block (Location.Null);
5154 lambda_arrow_expression // All expressions must handle error or current block won't be restored and breaking ast completely
5156 Block b = end_block (Location.Null);
5157 b.IsCompilerGenerated = true;
5158 b.AddStatement (new ContextualReturn ((Expression) $2));
5164 // Handles only cases like foo = x.FirstOrDefault (l => );
5165 // where we must restore current_variable
5166 Block b = end_block (Location.Null);
5167 b.IsCompilerGenerated = true;
5169 Error_SyntaxError (yyToken);
5174 lambda_arrow_expression
5176 | reference_expression
5183 Error_SyntaxError (yyToken);
5191 var lt = (LocatedToken) $1;
5192 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5193 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5195 lambda_expression_body
5197 $$ = end_anonymous ((ParametersBlock) $4);
5198 lbag.AddLocation ($$, GetLocation ($2));
5202 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5203 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5204 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5206 lambda_expression_body
5208 $$ = end_anonymous ((ParametersBlock) $4);
5209 lbag.AddLocation ($$, GetLocation ($2));
5211 | ASYNC identifier_inside_body ARROW
5213 var lt = (LocatedToken) $2;
5214 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5215 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5217 lambda_expression_body
5219 $$ = end_anonymous ((ParametersBlock) $5);
5220 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5222 | OPEN_PARENS_LAMBDA
5224 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5226 opt_lambda_parameter_list CLOSE_PARENS ARROW
5228 valid_param_mod = 0;
5229 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5231 lambda_expression_body
5233 $$ = end_anonymous ((ParametersBlock) $7);
5234 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5236 | ASYNC OPEN_PARENS_LAMBDA
5238 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5240 opt_lambda_parameter_list CLOSE_PARENS ARROW
5242 valid_param_mod = 0;
5243 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5245 lambda_expression_body
5247 $$ = end_anonymous ((ParametersBlock) $8);
5248 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5253 : assignment_expression
5254 | non_assignment_expression
5257 non_assignment_expression
5258 : conditional_expression
5263 $$ = new ArglistAccess (GetLocation ($1));
5267 undocumented_expressions
5268 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5270 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5271 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5273 | REFTYPE open_parens_any expression CLOSE_PARENS
5275 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5276 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5278 | MAKEREF open_parens_any expression CLOSE_PARENS
5280 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5281 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5292 $$ = new BooleanExpression ((Expression) $1);
5296 opt_primary_parameters
5301 | primary_parameters
5305 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5309 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5310 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5312 if (lang_version != LanguageVersion.Experimental)
5313 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5317 opt_primary_parameters_with_class_base
5326 | primary_parameters
5330 | primary_parameters class_base
5334 | primary_parameters class_base OPEN_PARENS
5336 ++lexer.parsing_block;
5337 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5339 opt_argument_list CLOSE_PARENS
5341 lbag.AppendToMember (current_container, GetLocation ($6));
5342 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5343 --lexer.parsing_block;
5359 type_declaration_name
5361 lexer.ConstraintsParsing = true;
5363 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5364 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5365 FeatureIsNotAvailable (c.Location, "static classes");
5368 push_current_container (c, $3);
5369 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5371 opt_primary_parameters_with_class_base
5372 opt_type_parameter_constraints_clauses
5374 valid_param_mod = 0;
5375 lexer.ConstraintsParsing = false;
5378 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5381 current_container.SetConstraints ((List<Constraints>) $9);
5382 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5385 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5386 Lexer.doc_state = XmlCommentState.Allowed;
5389 lexer.parsing_modifiers = true;
5391 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5393 --lexer.parsing_declaration;
5395 Lexer.doc_state = XmlCommentState.Allowed;
5400 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5402 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5404 $$ = pop_current_class ();
5412 { $$ = $1; } // location
5418 mod_locations = null;
5420 lexer.parsing_modifiers = false;
5424 lexer.parsing_modifiers = false;
5430 | modifiers modifier
5432 var m1 = (Modifiers) $1;
5433 var m2 = (Modifiers) $2;
5435 if ((m1 & m2) != 0) {
5436 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5437 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5438 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5439 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5440 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5441 "More than one protection modifier specified");
5452 StoreModifierLocation ($$, GetLocation ($1));
5454 if (current_container.Kind == MemberKind.Namespace)
5455 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5459 $$ = Modifiers.PUBLIC;
5460 StoreModifierLocation ($$, GetLocation ($1));
5464 $$ = Modifiers.PROTECTED;
5465 StoreModifierLocation ($$, GetLocation ($1));
5469 $$ = Modifiers.INTERNAL;
5470 StoreModifierLocation ($$, GetLocation ($1));
5474 $$ = Modifiers.PRIVATE;
5475 StoreModifierLocation ($$, GetLocation ($1));
5479 $$ = Modifiers.ABSTRACT;
5480 StoreModifierLocation ($$, GetLocation ($1));
5484 $$ = Modifiers.SEALED;
5485 StoreModifierLocation ($$, GetLocation ($1));
5489 $$ = Modifiers.STATIC;
5490 StoreModifierLocation ($$, GetLocation ($1));
5494 $$ = Modifiers.READONLY;
5495 StoreModifierLocation ($$, GetLocation ($1));
5499 $$ = Modifiers.VIRTUAL;
5500 StoreModifierLocation ($$, GetLocation ($1));
5504 $$ = Modifiers.OVERRIDE;
5505 StoreModifierLocation ($$, GetLocation ($1));
5509 $$ = Modifiers.EXTERN;
5510 StoreModifierLocation ($$, GetLocation ($1));
5514 $$ = Modifiers.VOLATILE;
5515 StoreModifierLocation ($$, GetLocation ($1));
5519 $$ = Modifiers.UNSAFE;
5520 StoreModifierLocation ($$, GetLocation ($1));
5521 if (!settings.Unsafe)
5522 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5526 $$ = Modifiers.ASYNC;
5527 StoreModifierLocation ($$, GetLocation ($1));
5539 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5541 | COLON type_list error
5543 Error_SyntaxError (yyToken);
5545 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5549 opt_type_parameter_constraints_clauses
5551 | type_parameter_constraints_clauses
5557 type_parameter_constraints_clauses
5558 : type_parameter_constraints_clause
5560 var constraints = new List<Constraints> (1);
5561 constraints.Add ((Constraints) $1);
5564 | type_parameter_constraints_clauses type_parameter_constraints_clause
5566 var constraints = (List<Constraints>) $1;
5567 Constraints new_constraint = (Constraints)$2;
5569 foreach (Constraints c in constraints) {
5570 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5571 report.Error (409, new_constraint.Location,
5572 "A constraint clause has already been specified for type parameter `{0}'",
5573 new_constraint.TypeParameter.Value);
5577 constraints.Add (new_constraint);
5582 type_parameter_constraints_clause
5583 : WHERE IDENTIFIER COLON type_parameter_constraints
5585 var lt = (LocatedToken) $2;
5586 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5587 lbag.AddLocation ($$, GetLocation ($3));
5589 | WHERE IDENTIFIER error
5591 Error_SyntaxError (yyToken);
5593 var lt = (LocatedToken) $2;
5594 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5598 type_parameter_constraints
5599 : type_parameter_constraint
5601 var constraints = new List<FullNamedExpression> (1);
5602 constraints.Add ((FullNamedExpression) $1);
5605 | type_parameter_constraints COMMA type_parameter_constraint
5607 var constraints = (List<FullNamedExpression>) $1;
5608 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5609 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5610 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5613 prev = $3 as SpecialContraintExpr;
5615 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5616 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5618 prev = constraints [0] as SpecialContraintExpr;
5619 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5620 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5625 constraints.Add ((FullNamedExpression) $3);
5630 type_parameter_constraint
5633 if ($1 is ComposedCast)
5634 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5638 | NEW OPEN_PARENS CLOSE_PARENS
5640 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5641 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5645 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5649 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5653 opt_type_parameter_variance
5658 | type_parameter_variance
5660 if (lang_version <= LanguageVersion.V_3)
5661 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5667 type_parameter_variance
5670 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5674 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5683 // A block is "contained" on the following places:
5685 // property_declaration as part of the accessor body (get/set)
5686 // operator_declaration
5687 // constructor_declaration
5688 // destructor_declaration
5689 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5694 ++lexer.parsing_block;
5695 start_block (GetLocation ($1));
5697 opt_statement_list block_end
5706 --lexer.parsing_block;
5707 $$ = end_block (GetLocation ($1));
5709 | COMPLETE_COMPLETION
5711 --lexer.parsing_block;
5712 $$ = end_block (lexer.Location);
5720 ++lexer.parsing_block;
5721 current_block.StartLocation = GetLocation ($1);
5723 opt_statement_list CLOSE_BRACE
5725 --lexer.parsing_block;
5726 $$ = end_block (GetLocation ($4));
5737 | statement_list statement
5741 : block_variable_declaration
5743 current_block.AddStatement ((Statement) $1);
5745 | valid_declaration_statement
5747 current_block.AddStatement ((Statement) $1);
5752 Error_SyntaxError (yyToken);
5758 // The interactive_statement and its derivatives are only
5759 // used to provide a special version of `expression_statement'
5760 // that has a side effect of assigning the expression to
5763 interactive_statement_list
5764 : interactive_statement
5765 | interactive_statement_list interactive_statement
5768 interactive_statement
5769 : block_variable_declaration
5771 current_block.AddStatement ((Statement) $1);
5773 | interactive_valid_declaration_statement
5775 current_block.AddStatement ((Statement) $1);
5780 valid_declaration_statement
5783 | expression_statement
5784 | selection_statement
5785 | iteration_statement
5789 | unchecked_statement
5796 interactive_valid_declaration_statement
5799 | interactive_expression_statement
5800 | selection_statement
5801 | iteration_statement
5805 | unchecked_statement
5813 : valid_declaration_statement
5814 | block_variable_declaration
5816 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5821 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5826 Error_SyntaxError (yyToken);
5827 $$ = new EmptyStatement (GetLocation ($1));
5834 // Uses lexer.Location because semicolon location is not kept in quick mode
5835 $$ = new EmptyStatement (lexer.Location);
5840 : identifier_inside_body COLON
5842 var lt = (LocatedToken) $1;
5843 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5844 lbag.AddLocation (labeled, GetLocation ($2));
5845 current_block.AddLabel (labeled);
5846 current_block.AddStatement (labeled);
5852 : variable_type_simple
5853 | variable_type_simple rank_specifiers
5856 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5858 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5863 * The following is from Rhys' grammar:
5864 * > Types in local variable declarations must be recognized as
5865 * > expressions to prevent reduce/reduce errors in the grammar.
5866 * > The expressions are converted into types during semantic analysis.
5868 variable_type_simple
5869 : type_name_expression opt_nullable
5871 var expr = (ATypeNameExpression) $1;
5873 if (expr.Name == "var" && expr is SimpleName)
5874 $$ = new VarExpr (expr.Location);
5878 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5881 | type_name_expression pointer_stars
5883 var expr = (ATypeNameExpression) $1;
5884 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5886 | builtin_type_expression
5887 | tuple_type opt_nullable
5892 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5898 : OPEN_PARENS tuple_type_elements CLOSE_PARENS
5900 if (lang_version < LanguageVersion.V_7)
5901 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5903 var a = (Tuple<TypeArguments, List<string>>) $2;
5905 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
5910 : variable_type IDENTIFIER /* opt_identifier */ COMMA variable_type IDENTIFIER /* opt_identifier */
5912 var type_args = new TypeArguments ();
5914 type_args.Add ((FullNamedExpression) $1);
5915 type_args.Add ((FullNamedExpression) $4);
5917 var names = new List<string> (2);
5918 var lt = (LocatedToken) $2;
5919 names.Add (lt?.Value);
5920 lt = (LocatedToken) $5;
5921 names.Add (lt?.Value);
5923 $$ = Tuple.Create (type_args, names);
5925 | tuple_type_elements COMMA variable_type IDENTIFIER /* opt_identifier */
5927 var a = (Tuple<TypeArguments, List<string>>) $1;
5928 a.Item1.Add ((FullNamedExpression) $3);
5929 var lt = (LocatedToken) $4;
5930 a.Item2.Add (lt?.Value);
5937 | pointer_star pointer_stars
5939 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5947 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5951 identifier_inside_body
5955 $$ = Error_AwaitAsIdentifier ($1);
5959 block_variable_declaration
5960 : variable_type identifier_inside_body
5962 var lt = (LocatedToken) $2;
5963 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5964 current_block.AddLocalName (li);
5965 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5967 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5969 $$ = current_variable;
5970 current_variable = null;
5972 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5974 lbag.AddLocation ($$, GetLocation ($6));
5976 | CONST variable_type identifier_inside_body
5978 var lt = (LocatedToken) $3;
5979 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5980 current_block.AddLocalName (li);
5981 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5983 const_variable_initializer opt_const_declarators SEMICOLON
5985 $$ = current_variable;
5986 current_variable = null;
5987 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5989 | REF variable_type identifier_inside_body
5991 if (lang_version < LanguageVersion.V_7) {
5992 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
5995 var lt = (LocatedToken) $3;
5996 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ByRef, lt.Location);
5997 current_block.AddLocalName (li);
5998 current_variable = new BlockVariable ((FullNamedExpression) $2, li);
6000 opt_local_variable_initializer opt_variable_declarators SEMICOLON
6002 $$ = current_variable;
6003 current_variable = null;
6005 lbag.AddLocation ($$, PopLocation (), GetLocation ($7));
6007 report.Error (8174, GetLocation ($3), "A declaration of a by-reference variable must have an initializer");
6008 lbag.AddLocation ($$, GetLocation ($7));
6013 opt_local_variable_initializer
6015 | ASSIGN block_variable_initializer
6017 current_variable.Initializer = (Expression) $2;
6018 PushLocation (GetLocation ($1));
6019 $$ = current_variable;
6023 if (yyToken == Token.OPEN_BRACKET_EXPR) {
6024 report.Error (650, lexer.Location,
6025 "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");
6027 Error_SyntaxError (yyToken);
6032 opt_variable_declarators
6034 | variable_declarators
6037 opt_using_or_fixed_variable_declarators
6039 | variable_declarators
6041 foreach (var d in current_variable.Declarators) {
6042 if (d.Initializer == null)
6043 Error_MissingInitializer (d.Variable.Location);
6048 variable_declarators
6049 : variable_declarator
6050 | variable_declarators variable_declarator
6054 : COMMA identifier_inside_body
6056 var lt = (LocatedToken) $2;
6057 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
6058 var d = new BlockVariableDeclarator (li, null);
6059 current_variable.AddDeclarator (d);
6060 current_block.AddLocalName (li);
6061 lbag.AddLocation (d, GetLocation ($1));
6063 | COMMA identifier_inside_body ASSIGN block_variable_initializer
6065 var lt = (LocatedToken) $2;
6066 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
6067 var d = new BlockVariableDeclarator (li, (Expression) $4);
6068 current_variable.AddDeclarator (d);
6069 current_block.AddLocalName (li);
6070 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6074 const_variable_initializer
6077 report.Error (145, lexer.Location, "A const field requires a value to be provided");
6079 | ASSIGN constant_initializer_expr
6081 current_variable.Initializer = (Expression) $2;
6085 opt_const_declarators
6092 | const_declarators const_declarator
6096 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
6098 var lt = (LocatedToken) $2;
6099 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
6100 var d = new BlockVariableDeclarator (li, (Expression) $4);
6101 current_variable.AddDeclarator (d);
6102 current_block.AddLocalName (li);
6103 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6107 block_variable_initializer
6108 : variable_initializer
6109 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
6111 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
6112 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6114 | STACKALLOC simple_type
6116 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
6117 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
6119 | reference_expression
6122 reference_expression
6125 if (lang_version < LanguageVersion.V_7) {
6126 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
6129 $$ = new ReferenceExpression ((Expression) $2, GetLocation ($1));
6133 expression_statement
6134 : statement_expression SEMICOLON
6137 lbag.AddStatement ($$, GetLocation ($2));
6139 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
6140 | statement_expression CLOSE_BRACE
6143 report.Error (1002, GetLocation ($2), "; expected");
6144 lexer.putback ('}');
6148 interactive_expression_statement
6149 : interactive_statement_expression SEMICOLON { $$ = $1; }
6150 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
6154 // We have to do the wrapping here and not in the case above,
6155 // because statement_expression is used for example in for_statement
6157 statement_expression
6160 ExpressionStatement s = $1 as ExpressionStatement;
6162 var expr = $1 as Expression;
6163 $$ = new StatementErrorExpression (expr);
6165 $$ = new StatementExpression (s);
6170 interactive_statement_expression
6173 Expression expr = (Expression) $1;
6174 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
6178 Error_SyntaxError (yyToken);
6179 $$ = new EmptyStatement (GetLocation ($1));
6189 : IF open_parens_any boolean_expression CLOSE_PARENS
6192 if ($5 is EmptyStatement)
6193 Warning_EmptyStatement (GetLocation ($5));
6195 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6196 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6198 | IF open_parens_any boolean_expression CLOSE_PARENS
6199 embedded_statement ELSE embedded_statement
6201 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
6202 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
6204 if ($5 is EmptyStatement)
6205 Warning_EmptyStatement (GetLocation ($5));
6206 if ($7 is EmptyStatement)
6207 Warning_EmptyStatement (GetLocation ($7));
6209 | IF open_parens_any boolean_expression error
6211 Error_SyntaxError (yyToken);
6213 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
6214 lbag.AddStatement ($$, GetLocation ($2));
6219 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
6221 start_block (GetLocation ($5));
6223 opt_switch_sections CLOSE_BRACE
6225 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
6226 end_block (GetLocation ($8));
6227 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6229 | SWITCH open_parens_any expression error
6231 Error_SyntaxError (yyToken);
6233 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
6234 lbag.AddStatement ($$, GetLocation ($2));
6241 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6248 | switch_sections switch_section
6251 Error_SyntaxError (yyToken);
6256 : switch_labels statement_list
6262 var label = (SwitchLabel) $1;
6263 label.SectionStart = true;
6264 current_block.AddStatement (label);
6266 | switch_labels switch_label
6268 current_block.AddStatement ((Statement) $2);
6273 : CASE constant_expression COLON
6275 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6276 lbag.AddLocation ($$, GetLocation ($3));
6278 | CASE constant_expression error
6280 Error_SyntaxError (yyToken);
6281 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6284 | CASE pattern_expr_invocation COLON
6286 if (lang_version != LanguageVersion.Experimental)
6287 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6289 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6290 PatternMatching = true
6292 lbag.AddLocation ($$, GetLocation ($3));
6296 | CASE pattern_type_expr IDENTIFIER COLON
6298 if (lang_version < LanguageVersion.V_7)
6299 FeatureIsNotAvailable (GetLocation ($1), "pattern matching");
6301 // $$ = new SwitchLabel ((FullNamedExpression) $2), GetLocation ($1)) {
6302 // PatternMatching = true
6305 throw new NotImplementedException ("type pattern matching");
6309 $$ = new SwitchLabel (null, GetLocation ($1));
6321 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6323 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6324 Warning_EmptyStatement (GetLocation ($5));
6326 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6327 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6329 | WHILE open_parens_any boolean_expression error
6331 Error_SyntaxError (yyToken);
6333 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6334 lbag.AddStatement ($$, GetLocation ($2));
6339 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6341 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6342 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6344 | DO embedded_statement error
6346 Error_SyntaxError (yyToken);
6347 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6349 | DO embedded_statement WHILE open_parens_any boolean_expression error
6351 Error_SyntaxError (yyToken);
6353 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6354 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6359 : FOR open_parens_any
6361 start_block (GetLocation ($2));
6362 current_block.IsCompilerGenerated = true;
6363 For f = new For (GetLocation ($1));
6364 current_block.AddStatement (f);
6373 // Has to use be extra rule to recover started block
6375 : opt_for_initializer SEMICOLON
6377 ((For) $0).Initializer = (Statement) $1;
6379 // Pass the "For" object to the iterator_part4
6380 oob_stack.Push ($0);
6382 for_condition_and_iterator_part
6385 var locations = (Tuple<Location,Location>) $4;
6387 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6388 Warning_EmptyStatement (GetLocation ($5));
6391 f.Statement = (Statement) $5;
6392 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6394 $$ = end_block (GetLocation ($2));
6398 Error_SyntaxError (yyToken);
6399 $$ = end_block (current_block.StartLocation);
6403 for_condition_and_iterator_part
6404 : opt_for_condition SEMICOLON
6406 For f = (For) oob_stack.Peek ();
6407 f.Condition = (BooleanExpression) $1;
6410 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6413 // Handle errors in the case of opt_for_condition being followed by
6414 // a close parenthesis
6415 | opt_for_condition close_parens_close_brace {
6416 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6417 For f = (For) oob_stack.Peek ();
6418 f.Condition = (BooleanExpression) $1;
6419 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6424 : opt_for_iterator CLOSE_PARENS {
6425 For f = (For) oob_stack.Peek ();
6426 f.Iterator = (Statement) $1;
6427 $$ = GetLocation ($2);
6429 | opt_for_iterator CLOSE_BRACE {
6430 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6431 For f = (For) oob_stack.Peek ();
6432 f.Iterator = (Statement) $1;
6433 $$ = GetLocation ($2);
6437 close_parens_close_brace
6439 | CLOSE_BRACE { lexer.putback ('}'); }
6443 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6448 : variable_type identifier_inside_body
6450 var lt = (LocatedToken) $2;
6451 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6452 current_block.AddLocalName (li);
6453 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6455 opt_local_variable_initializer opt_variable_declarators
6457 $$ = current_variable;
6459 lbag.AddLocation (current_variable, PopLocation ());
6461 current_variable = null;
6463 | statement_expression_list
6467 : /* empty */ { $$ = null; }
6468 | boolean_expression
6472 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6477 : statement_expression_list
6480 statement_expression_list
6481 : statement_expression
6482 | statement_expression_list COMMA statement_expression
6484 var sl = $1 as StatementList;
6486 sl = new StatementList ((Statement) $1, (Statement) $3);
6487 lbag.AddStatement (sl, GetLocation ($2));
6489 sl.Add ((Statement) $3);
6490 lbag.AppendTo (sl, GetLocation ($2));
6498 : FOREACH open_parens_any type error
6500 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6502 start_block (GetLocation ($2));
6503 current_block.IsCompilerGenerated = true;
6505 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6506 current_block.AddStatement (f);
6508 lbag.AddStatement (f, GetLocation ($2));
6509 $$ = end_block (GetLocation ($4));
6511 | FOREACH open_parens_any type identifier_inside_body error
6513 Error_SyntaxError (yyToken);
6515 start_block (GetLocation ($2));
6516 current_block.IsCompilerGenerated = true;
6518 var lt = (LocatedToken) $4;
6519 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6520 current_block.AddLocalName (li);
6522 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6523 current_block.AddStatement (f);
6525 lbag.AddStatement (f, GetLocation ($2));
6526 $$ = end_block (GetLocation ($5));
6528 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6530 start_block (GetLocation ($2));
6531 current_block.IsCompilerGenerated = true;
6533 var lt = (LocatedToken) $4;
6534 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6535 current_block.AddLocalName (li);
6540 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6541 Warning_EmptyStatement (GetLocation ($9));
6543 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6544 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6545 end_block (GetLocation ($7));
6553 | continue_statement
6563 $$ = new Break (GetLocation ($1));
6564 lbag.AddStatement ($$, GetLocation ($2));
6569 : CONTINUE SEMICOLON
6571 $$ = new Continue (GetLocation ($1));
6572 lbag.AddStatement ($$, GetLocation ($2));
6576 Error_SyntaxError (yyToken);
6577 $$ = new Continue (GetLocation ($1));
6582 : GOTO identifier_inside_body SEMICOLON
6584 var lt = (LocatedToken) $2;
6585 $$ = new Goto (lt.Value, GetLocation ($1));
6586 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6588 | GOTO CASE constant_expression SEMICOLON
6590 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6591 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6593 | GOTO DEFAULT SEMICOLON
6595 $$ = new GotoDefault (GetLocation ($1));
6596 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6601 : RETURN opt_expression SEMICOLON
6603 $$ = new Return ((Expression) $2, GetLocation ($1));
6604 lbag.AddStatement ($$, GetLocation ($3));
6606 | RETURN reference_expression SEMICOLON
6608 $$ = new Return ((Expression) $2, GetLocation ($1));
6609 lbag.AddStatement ($$, GetLocation ($3));
6611 | RETURN expression error
6613 Error_SyntaxError (yyToken);
6614 $$ = new Return ((Expression) $2, GetLocation ($1));
6618 Error_SyntaxError (yyToken);
6619 $$ = new Return (null, GetLocation ($1));
6624 : THROW expression SEMICOLON
6626 $$ = new Throw ((Expression) $2, GetLocation ($1));
6627 lbag.AddStatement ($$, GetLocation ($3));
6631 $$ = new Throw (null, GetLocation ($1));
6632 lbag.AddStatement ($$, GetLocation ($2));
6634 | THROW expression error
6636 Error_SyntaxError (yyToken);
6637 $$ = new Throw ((Expression) $2, GetLocation ($1));
6641 Error_SyntaxError (yyToken);
6642 $$ = new Throw (null, GetLocation ($1));
6647 : identifier_inside_body RETURN opt_expression SEMICOLON
6649 var lt = (LocatedToken) $1;
6650 string s = lt.Value;
6652 report.Error (1003, lt.Location, "; expected");
6653 } else if ($3 == null) {
6654 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6655 } else if (lang_version == LanguageVersion.ISO_1){
6656 FeatureIsNotAvailable (lt.Location, "iterators");
6659 current_block.Explicit.RegisterIteratorYield ();
6660 $$ = new Yield ((Expression) $3, lt.Location);
6661 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6663 | identifier_inside_body RETURN expression error
6665 Error_SyntaxError (yyToken);
6667 var lt = (LocatedToken) $1;
6668 string s = lt.Value;
6670 report.Error (1003, lt.Location, "; expected");
6671 } else if ($3 == null) {
6672 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6673 } else if (lang_version == LanguageVersion.ISO_1){
6674 FeatureIsNotAvailable (lt.Location, "iterators");
6677 current_block.Explicit.RegisterIteratorYield ();
6678 $$ = new Yield ((Expression) $3, lt.Location);
6679 lbag.AddStatement ($$, GetLocation ($2));
6681 | identifier_inside_body BREAK SEMICOLON
6683 var lt = (LocatedToken) $1;
6684 string s = lt.Value;
6686 report.Error (1003, lt.Location, "; expected");
6687 } else if (lang_version == LanguageVersion.ISO_1){
6688 FeatureIsNotAvailable (lt.Location, "iterators");
6691 current_block.ParametersBlock.TopBlock.IsIterator = true;
6692 $$ = new YieldBreak (lt.Location);
6693 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6703 : TRY block catch_clauses
6705 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6707 | TRY block FINALLY block
6709 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6710 lbag.AddStatement ($$, GetLocation ($3));
6712 | TRY block catch_clauses FINALLY block
6714 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6715 lbag.AddStatement ($$, GetLocation ($4));
6719 Error_SyntaxError (1524, yyToken);
6720 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6727 var l = new List<Catch> (2);
6732 | catch_clauses catch_clause
6734 var l = (List<Catch>) $1;
6736 Catch c = (Catch) $2;
6737 var prev_catch = l [l.Count - 1];
6738 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6739 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6749 | identifier_inside_body
6753 : CATCH opt_catch_filter block
6755 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6756 c.Filter = (CatchFilterExpression) $2;
6759 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6761 start_block (GetLocation ($2));
6762 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6763 c.TypeExpression = (FullNamedExpression) $3;
6766 var lt = (LocatedToken) $4;
6767 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6768 current_block.AddLocalName (c.Variable);
6771 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6773 lexer.parsing_catch_when = true;
6775 opt_catch_filter_or_error
6777 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6780 | CATCH open_parens_any error
6782 if (yyToken == Token.CLOSE_PARENS) {
6783 report.Error (1015, lexer.Location,
6784 "A type that derives from `System.Exception', `object', or `string' expected");
6786 Error_SyntaxError (yyToken);
6789 $$ = new Catch (null, GetLocation ($1));
6793 opt_catch_filter_or_error
6794 : opt_catch_filter block_prepared
6800 end_block (Location.Null);
6801 Error_SyntaxError (yyToken);
6808 lexer.parsing_catch_when = false;
6812 lexer.parsing_catch_when = false;
6814 open_parens_any expression CLOSE_PARENS
6816 if (lang_version <= LanguageVersion.V_5)
6817 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6819 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6820 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6827 $$ = new Checked ((Block) $2, GetLocation ($1));
6834 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6841 if (!settings.Unsafe)
6842 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6844 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6849 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6851 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6852 Warning_EmptyStatement (GetLocation ($5));
6854 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6855 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6857 | LOCK open_parens_any expression error
6859 Error_SyntaxError (yyToken);
6861 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6862 lbag.AddStatement ($$, GetLocation ($2));
6867 : FIXED open_parens_any variable_type identifier_inside_body
6869 start_block (GetLocation ($2));
6871 current_block.IsCompilerGenerated = true;
6872 var lt = (LocatedToken) $4;
6873 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6874 current_block.AddLocalName (li);
6875 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6877 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6879 $$ = current_variable;
6880 current_variable = null;
6884 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6885 Warning_EmptyStatement (GetLocation ($10));
6887 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6888 current_block.AddStatement (f);
6889 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6890 $$ = end_block (GetLocation ($8));
6895 : USING open_parens_any variable_type identifier_inside_body
6897 start_block (GetLocation ($2));
6899 current_block.IsCompilerGenerated = true;
6900 var lt = (LocatedToken) $4;
6901 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6902 current_block.AddLocalName (li);
6903 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6905 using_initialization CLOSE_PARENS
6907 $$ = current_variable;
6908 current_variable = null;
6912 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6913 Warning_EmptyStatement (GetLocation ($9));
6915 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6916 current_block.AddStatement (u);
6917 $$ = end_block (GetLocation ($7));
6919 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6921 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6922 Warning_EmptyStatement (GetLocation ($5));
6924 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6925 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6927 | USING open_parens_any expression error
6929 Error_SyntaxError (yyToken);
6931 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6932 lbag.AddStatement ($$, GetLocation ($2));
6936 using_initialization
6937 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6940 // It has to be here for the parent to safely restore artificial block
6941 Error_SyntaxError (yyToken);
6945 using_or_fixed_variable_initializer
6948 Error_MissingInitializer (lexer.Location);
6950 | ASSIGN variable_initializer
6952 current_variable.Initializer = (Expression) $2;
6953 $$ = current_variable;
6961 : first_from_clause query_body
6963 lexer.query_parsing = false;
6965 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6967 from.Tail.Next = (Linq.AQueryClause)$2;
6970 current_block.SetEndLocation (lexer.Location);
6971 current_block = current_block.Parent;
6973 | nested_from_clause query_body
6975 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6977 from.Tail.Next = (Linq.AQueryClause)$2;
6980 current_block.SetEndLocation (lexer.Location);
6981 current_block = current_block.Parent;
6984 // Bubble up COMPLETE_COMPLETION productions
6985 | first_from_clause COMPLETE_COMPLETION {
6986 lexer.query_parsing = false;
6989 current_block.SetEndLocation (lexer.Location);
6990 current_block = current_block.Parent;
6992 | nested_from_clause COMPLETE_COMPLETION {
6994 current_block.SetEndLocation (lexer.Location);
6995 current_block = current_block.Parent;
7000 : FROM_FIRST identifier_inside_body IN expression
7002 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7004 var lt = (LocatedToken) $2;
7005 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7006 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
7007 lbag.AddLocation (clause, GetLocation ($3));
7008 $$ = new Linq.QueryExpression (clause);
7010 | FROM_FIRST type identifier_inside_body IN expression
7012 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7014 var lt = (LocatedToken) $3;
7015 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7016 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
7017 IdentifierType = (FullNamedExpression)$2
7019 lbag.AddLocation (clause, GetLocation ($4));
7020 $$ = new Linq.QueryExpression (clause);
7025 : FROM identifier_inside_body IN expression
7027 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7029 var lt = (LocatedToken) $2;
7030 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7031 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
7032 lbag.AddLocation (clause, GetLocation ($3));
7033 $$ = new Linq.QueryExpression (clause);
7035 | FROM type identifier_inside_body IN expression
7037 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7039 var lt = (LocatedToken) $3;
7040 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7041 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
7042 IdentifierType = (FullNamedExpression)$2
7044 lbag.AddLocation (clause, GetLocation ($4));
7045 $$ = new Linq.QueryExpression (clause);
7050 : FROM identifier_inside_body IN
7052 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7056 var lt = (LocatedToken) $2;
7057 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7058 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
7060 current_block.SetEndLocation (lexer.Location);
7061 current_block = current_block.Parent;
7063 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7064 lbag.AddLocation ($$, GetLocation ($3));
7066 | FROM type identifier_inside_body IN
7068 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7072 var lt = (LocatedToken) $3;
7073 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7075 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
7076 IdentifierType = (FullNamedExpression)$2
7079 current_block.SetEndLocation (lexer.Location);
7080 current_block = current_block.Parent;
7082 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7084 lbag.AddLocation ($$, GetLocation ($4));
7089 : query_body_clauses select_or_group_clause opt_query_continuation
7091 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7094 head.Next = (Linq.AQueryClause)$3;
7097 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7098 clause.Tail.Next = head;
7104 | select_or_group_clause opt_query_continuation
7106 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7109 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7110 clause.Tail.Next = head;
7116 | query_body_clauses COMPLETE_COMPLETION
7117 | query_body_clauses error
7119 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
7124 Error_SyntaxError (yyToken);
7129 select_or_group_clause
7132 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7136 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7138 current_block.SetEndLocation (lexer.Location);
7139 current_block = current_block.Parent;
7143 if (linq_clause_blocks == null)
7144 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7146 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7147 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
7151 current_block.SetEndLocation (lexer.Location);
7152 current_block = current_block.Parent;
7154 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7158 var obj = (object[]) $5;
7160 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
7161 lbag.AddLocation ($$, (Location) obj[1]);
7163 current_block.SetEndLocation (lexer.Location);
7164 current_block = current_block.Parent;
7169 : BY expression_or_error
7171 $$ = new object[] { $2, GetLocation ($1) };
7175 Error_SyntaxError (yyToken);
7176 $$ = new object[2] { null, Location.Null };
7182 | query_body_clauses query_body_clause
7184 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
7198 : LET identifier_inside_body ASSIGN
7200 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7204 var lt = (LocatedToken) $2;
7205 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7206 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
7207 lbag.AddLocation ($$, GetLocation ($3));
7209 current_block.SetEndLocation (lexer.Location);
7210 current_block = current_block.Parent;
7212 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7219 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7223 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7225 current_block.SetEndLocation (lexer.Location);
7226 current_block = current_block.Parent;
7231 : JOIN identifier_inside_body IN
7233 if (linq_clause_blocks == null)
7234 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7236 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7237 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7239 expression_or_error ON
7241 current_block.SetEndLocation (lexer.Location);
7242 current_block = current_block.Parent;
7244 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7245 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7247 expression_or_error EQUALS
7249 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7250 current_block.SetEndLocation (lexer.Location);
7251 current_block = current_block.Parent;
7253 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7255 expression_or_error opt_join_into
7257 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7258 current_block.SetEndLocation (lexer.Location);
7260 var outer_selector = linq_clause_blocks.Pop ();
7261 var block = linq_clause_blocks.Pop ();
7263 var lt = (LocatedToken) $2;
7264 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7265 Linq.RangeVariable into;
7269 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7270 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7273 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7275 var parent = block.Parent;
7276 while (parent is Linq.QueryBlock) {
7277 parent = parent.Parent;
7279 current_block.Parent = parent;
7281 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7283 lt = (LocatedToken) $12;
7284 into = new Linq.RangeVariable (lt.Value, lt.Location);
7286 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7287 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7290 current_block = block.Parent;
7291 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7293 | JOIN type identifier_inside_body IN
7295 if (linq_clause_blocks == null)
7296 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7298 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7299 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7301 expression_or_error ON
7303 current_block.SetEndLocation (lexer.Location);
7304 current_block = current_block.Parent;
7306 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7307 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7309 expression_or_error EQUALS
7311 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7312 current_block.SetEndLocation (lexer.Location);
7313 current_block = current_block.Parent;
7315 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7317 expression_or_error opt_join_into
7319 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7320 current_block.SetEndLocation (lexer.Location);
7322 var outer_selector = linq_clause_blocks.Pop ();
7323 var block = linq_clause_blocks.Pop ();
7325 var lt = (LocatedToken) $3;
7326 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7327 Linq.RangeVariable into;
7331 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7332 IdentifierType = (FullNamedExpression)$2
7334 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7337 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7339 var parent = block.Parent;
7340 while (parent is Linq.QueryBlock) {
7341 parent = parent.Parent;
7343 current_block.Parent = parent;
7345 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7347 lt = (LocatedToken) $13;
7348 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7350 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7351 IdentifierType = (FullNamedExpression)$2
7355 current_block = block.Parent;
7356 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7362 | INTO identifier_inside_body
7371 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7375 current_block.SetEndLocation (lexer.Location);
7376 current_block = current_block.Parent;
7386 current_block.SetEndLocation (lexer.Location);
7387 current_block = current_block.Parent;
7389 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7393 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7400 | orderings_then_by COMMA
7402 current_block.SetEndLocation (lexer.Location);
7403 current_block = current_block.Parent;
7405 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7409 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7417 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7419 | expression ASCENDING
7421 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7422 lbag.AddLocation ($$, GetLocation ($2));
7424 | expression DESCENDING
7426 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7427 lbag.AddLocation ($$, GetLocation ($2));
7434 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7436 | expression ASCENDING
7438 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7439 lbag.AddLocation ($$, GetLocation ($2));
7441 | expression DESCENDING
7443 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7444 lbag.AddLocation ($$, GetLocation ($2));
7449 opt_query_continuation
7451 | INTO identifier_inside_body
7453 // query continuation block is not linked with query block but with block
7454 // before. This means each query can use same range variable names for
7455 // different identifiers.
7457 current_block.SetEndLocation (GetLocation ($1));
7458 current_block = current_block.Parent;
7460 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7462 if (linq_clause_blocks == null)
7463 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7465 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7469 var current_block = linq_clause_blocks.Pop ();
7470 var lt = (LocatedToken) $2;
7471 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7472 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7473 next = (Linq.AQueryClause)$4
7479 // Support for using the compiler as an interactive parser
7481 // The INTERACTIVE_PARSER token is first sent to parse our
7482 // productions; If the result is a Statement, the parsing
7483 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7484 // to setup the blocks in advance.
7486 // This setup is here so that in the future we can add
7487 // support for other constructs (type parsing, namespaces, etc)
7488 // that do not require a block to be setup in advance
7492 : EVAL_STATEMENT_PARSER EOF
7493 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7494 | EVAL_STATEMENT_PARSER
7496 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7498 // (ref object retval)
7499 Parameter [] mpar = new Parameter [1];
7500 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7502 ParametersCompiled pars = new ParametersCompiled (mpar);
7503 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7504 if (settings.Unsafe)
7505 mods |= Modifiers.UNSAFE;
7507 current_local_parameters = pars;
7508 var method = new InteractiveMethod (
7510 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7514 current_type.AddMember (method);
7515 oob_stack.Push (method);
7517 interactive_async = false;
7519 ++lexer.parsing_block;
7520 start_block (lexer.Location);
7522 interactive_statement_list opt_COMPLETE_COMPLETION
7524 --lexer.parsing_block;
7525 var method = (InteractiveMethod) oob_stack.Pop ();
7526 method.Block = (ToplevelBlock) end_block(lexer.Location);
7528 if (interactive_async == true) {
7529 method.ChangeToAsync ();
7532 InteractiveResult = (Class) pop_current_class ();
7533 current_local_parameters = null;
7535 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7538 interactive_compilation_unit
7539 : opt_extern_alias_directives opt_using_directives
7540 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7543 opt_COMPLETE_COMPLETION
7545 | COMPLETE_COMPLETION
7548 close_brace_or_complete_completion
7550 | COMPLETE_COMPLETION
7554 // XML documentation code references micro parser
7556 documentation_parsing
7559 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7564 : doc_type_declaration_name opt_doc_method_sig
7566 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7568 | builtin_types opt_doc_method_sig
7570 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7571 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7574 | VOID opt_doc_method_sig
7576 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7577 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7580 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7582 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7583 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7584 var lt = (LocatedToken) $3;
7585 $$ = new MemberName (lt.Value);
7587 | doc_type_declaration_name DOT THIS
7589 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7591 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7593 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7595 opt_doc_parameters CLOSE_BRACKET
7597 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7598 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7600 | EXPLICIT OPERATOR type opt_doc_method_sig
7602 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7603 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7604 module.DocumentationBuilder.ParsedParameters = p;
7605 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7608 | IMPLICIT OPERATOR type opt_doc_method_sig
7610 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7611 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7612 module.DocumentationBuilder.ParsedParameters = p;
7613 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7616 | OPERATOR overloadable_operator opt_doc_method_sig
7618 var p = (List<DocumentationParameter>)$3;
7619 module.DocumentationBuilder.ParsedParameters = p;
7620 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7625 doc_type_declaration_name
7626 : type_declaration_name
7627 | doc_type_declaration_name DOT type_declaration_name
7629 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7637 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7639 opt_doc_parameters CLOSE_PARENS
7648 $$ = new List<DocumentationParameter> (0);
7656 var parameters = new List<DocumentationParameter> ();
7657 parameters.Add ((DocumentationParameter) $1);
7660 | doc_parameters COMMA doc_parameter
7662 var parameters = $1 as List<DocumentationParameter>;
7663 parameters.Add ((DocumentationParameter) $3);
7669 : opt_parameter_modifier parameter_type
7672 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7674 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7681 // A class used to hold info about an operator declarator
7683 class OperatorDeclaration {
7684 public readonly Operator.OpType optype;
7685 public readonly FullNamedExpression ret_type;
7686 public readonly Location location;
7688 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7691 this.ret_type = ret_type;
7692 this.location = location;
7696 void Error_ExpectingTypeName (Expression expr)
7698 if (expr is Invocation){
7699 report.Error (1002, expr.Location, "Expecting `;'");
7701 expr.Error_InvalidExpressionStatement (report);
7705 void Error_ParameterModifierNotValid (string modifier, Location loc)
7707 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7711 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7713 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7714 Parameter.GetModifierSignature (mod));
7717 void Error_TypeExpected (Location loc)
7719 report.Error (1031, loc, "Type expected");
7722 void Error_UnsafeCodeNotAllowed (Location loc)
7724 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7727 void Warning_EmptyStatement (Location loc)
7729 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7732 void Error_NamedArgumentExpected (NamedArgument a)
7734 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7737 void Error_MissingInitializer (Location loc)
7739 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7742 object Error_AwaitAsIdentifier (object token)
7745 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7746 return new LocatedToken ("await", GetLocation (token));
7752 void push_current_container (TypeDefinition tc, object partial_token)
7754 if (module.Evaluator != null){
7755 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7759 undo.AddTypeContainer (current_container, tc);
7762 if (partial_token != null)
7763 current_container.AddPartial (tc);
7765 current_container.AddTypeContainer (tc);
7767 ++lexer.parsing_declaration;
7768 current_container = tc;
7772 TypeContainer pop_current_class ()
7774 var retval = current_container;
7776 current_container = current_container.Parent;
7777 current_type = current_type.Parent as TypeDefinition;
7782 [System.Diagnostics.Conditional ("FULL_AST")]
7783 void StoreModifierLocation (object token, Location loc)
7788 if (mod_locations == null)
7789 mod_locations = new List<Tuple<Modifiers, Location>> ();
7791 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7794 [System.Diagnostics.Conditional ("FULL_AST")]
7795 void PushLocation (Location loc)
7797 if (location_stack == null)
7798 location_stack = new Stack<Location> ();
7800 location_stack.Push (loc);
7803 Location PopLocation ()
7805 if (location_stack == null)
7806 return Location.Null;
7808 return location_stack.Pop ();
7811 string CheckAttributeTarget (int token, string a, Location l)
7814 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7818 if (!Tokenizer.IsValidIdentifier (a)) {
7819 Error_SyntaxError (token);
7821 report.Warning (658, 1, l,
7822 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7825 return string.Empty;
7828 static bool IsUnaryOperator (Operator.OpType op)
7832 case Operator.OpType.LogicalNot:
7833 case Operator.OpType.OnesComplement:
7834 case Operator.OpType.Increment:
7835 case Operator.OpType.Decrement:
7836 case Operator.OpType.True:
7837 case Operator.OpType.False:
7838 case Operator.OpType.UnaryPlus:
7839 case Operator.OpType.UnaryNegation:
7845 void syntax_error (Location l, string msg)
7847 report.Error (1003, l, "Syntax error, " + msg);
7852 public Tokenizer Lexer {
7858 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7859 : this (reader, file, file.Compiler.Report, session)
7863 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7866 current_container = current_namespace = file;
7868 this.module = file.Module;
7869 this.compiler = file.Compiler;
7870 this.settings = compiler.Settings;
7871 this.report = report;
7873 lang_version = settings.Version;
7874 yacc_verbose_flag = settings.VerboseParserFlag;
7875 doc_support = settings.DocumentationFile != null;
7876 lexer = new Tokenizer (reader, file, session, report);
7877 oob_stack = new Stack<object> ();
7878 lbag = session.LocationsBag;
7879 use_global_stacks = session.UseJayGlobalArrays;
7880 parameters_bucket = session.ParametersStack;
7883 public void parse ()
7885 eof_token = Token.EOF;
7888 if (yacc_verbose_flag > 1)
7889 yyparse (lexer, new yydebug.yyDebugSimple ());
7893 Tokenizer tokenizer = lexer as Tokenizer;
7894 tokenizer.cleanup ();
7895 } catch (Exception e){
7896 if (e is yyParser.yyUnexpectedEof) {
7897 Error_SyntaxError (yyToken);
7898 UnexpectedEOF = true;
7902 if (e is yyParser.yyException) {
7903 if (report.Errors == 0)
7904 report.Error (-25, lexer.Location, "Parsing error");
7906 // Used by compiler-tester to test internal errors
7907 if (yacc_verbose_flag > 0 || e is FatalException)
7910 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7915 void CheckToken (int error, int yyToken, string msg, Location loc)
7917 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7918 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7920 report.Error (error, loc, msg);
7923 string ConsumeStoredComment ()
7925 string s = tmpComment;
7927 Lexer.doc_state = XmlCommentState.Allowed;
7931 void FeatureIsNotAvailable (Location loc, string feature)
7933 report.FeatureIsNotAvailable (compiler, loc, feature);
7936 Location GetLocation (object obj)
7938 var lt = obj as LocatedToken;
7942 var mn = obj as MemberName;
7946 var expr = obj as Expression;
7948 return expr.Location;
7950 return lexer.Location;
7953 void start_block (Location loc)
7955 if (current_block == null) {
7956 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7957 parsing_anonymous_method = false;
7958 } else if (parsing_anonymous_method) {
7959 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7960 parsing_anonymous_method = false;
7962 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7966 Block end_block (Location loc)
7968 Block retval = current_block.Explicit;
7969 retval.SetEndLocation (loc);
7970 current_block = retval.Parent;
7974 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7976 oob_stack.Push (current_anonymous_method);
7977 oob_stack.Push (current_local_parameters);
7978 oob_stack.Push (current_variable);
7979 oob_stack.Push (async_block);
7981 current_local_parameters = parameters;
7983 if (lang_version <= LanguageVersion.ISO_2)
7984 FeatureIsNotAvailable (loc, "lambda expressions");
7986 current_anonymous_method = new LambdaExpression (loc);
7988 if (lang_version == LanguageVersion.ISO_1)
7989 FeatureIsNotAvailable (loc, "anonymous methods");
7991 current_anonymous_method = new AnonymousMethodExpression (loc);
7994 async_block = isAsync;
7995 // Force the next block to be created as a ToplevelBlock
7996 parsing_anonymous_method = true;
8000 * Completes the anonymous method processing, if lambda_expr is null, this
8001 * means that we have a Statement instead of an Expression embedded
8003 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
8005 AnonymousMethodExpression retval;
8008 anon_block.IsAsync = true;
8010 current_anonymous_method.Block = anon_block;
8011 retval = current_anonymous_method;
8013 async_block = (bool) oob_stack.Pop ();
8014 current_variable = (BlockVariable) oob_stack.Pop ();
8015 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
8016 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
8021 void Error_SyntaxError (int token)
8023 Error_SyntaxError (0, token);
8026 void Error_SyntaxError (int error_code, int token)
8028 Error_SyntaxError (error_code, token, "Unexpected symbol");
8031 void Error_SyntaxError (int error_code, int token, string msg)
8033 Lexer.CompleteOnEOF = false;
8035 // An error message has been reported by tokenizer
8036 if (token == Token.ERROR)
8039 // Avoid duplicit error message after unterminated string literals
8040 if (token == Token.LITERAL && lexer.Location.Column == 0)
8043 string symbol = GetSymbolName (token);
8044 string expecting = GetExpecting ();
8045 var loc = lexer.Location - symbol.Length;
8047 if (error_code == 0) {
8048 if (expecting == "`identifier'") {
8049 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
8050 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
8055 expecting = "identifier";
8056 } else if (expecting == "`)'") {
8063 if (string.IsNullOrEmpty (expecting))
8064 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
8066 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
8069 string GetExpecting ()
8071 int [] tokens = yyExpectingTokens (yyExpectingState);
8072 var names = new List<string> (tokens.Length);
8073 bool has_type = false;
8074 bool has_identifier = false;
8075 for (int i = 0; i < tokens.Length; i++){
8076 int token = tokens [i];
8077 has_identifier |= token == Token.IDENTIFIER;
8079 string name = GetTokenName (token);
8080 if (name == "<internal>")
8083 has_type |= name == "type";
8084 if (names.Contains (name))
8091 // Too many tokens to enumerate
8093 if (names.Count > 8)
8096 if (has_type && has_identifier)
8097 names.Remove ("identifier");
8099 if (names.Count == 1)
8100 return "`" + GetTokenName (tokens [0]) + "'";
8102 StringBuilder sb = new StringBuilder ();
8104 int count = names.Count;
8105 for (int i = 0; i < count; i++){
8106 bool last = i + 1 == count;
8110 sb.Append (names [i]);
8111 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
8113 return sb.ToString ();
8117 string GetSymbolName (int token)
8121 return ((Constant)lexer.Value).GetValue ().ToString ();
8122 case Token.IDENTIFIER:
8123 return ((LocatedToken)lexer.Value).Value;
8165 case Token.BITWISE_AND:
8167 case Token.BITWISE_OR:
8181 case Token.OP_SHIFT_LEFT:
8183 case Token.OP_SHIFT_RIGHT:
8203 case Token.OP_COALESCING:
8205 case Token.OP_MULT_ASSIGN:
8207 case Token.OP_DIV_ASSIGN:
8209 case Token.OP_MOD_ASSIGN:
8211 case Token.OP_ADD_ASSIGN:
8213 case Token.OP_SUB_ASSIGN:
8215 case Token.OP_SHIFT_LEFT_ASSIGN:
8217 case Token.OP_SHIFT_RIGHT_ASSIGN:
8219 case Token.OP_AND_ASSIGN:
8221 case Token.OP_XOR_ASSIGN:
8223 case Token.OP_OR_ASSIGN:
8227 return GetTokenName (token);
8230 static string GetTokenName (int token)
8233 case Token.ABSTRACT:
8255 case Token.CONTINUE:
8259 case Token.DELEGATE:
8269 case Token.EXPLICIT:
8272 case Token.EXTERN_ALIAS:
8288 case Token.IMPLICIT:
8292 case Token.INTERFACE:
8294 case Token.INTERNAL:
8300 case Token.NAMESPACE:
8306 case Token.OPERATOR:
8310 case Token.OVERRIDE:
8316 case Token.PROTECTED:
8320 case Token.READONLY:
8332 case Token.STACKALLOC:
8333 return "stackalloc";
8343 case Token.THROW_EXPR:
8351 case Token.UNCHECKED:
8359 case Token.VOLATILE:
8367 case Token.REFVALUE:
8368 return "__refvalue";
8378 case Token.FROM_FIRST:
8396 case Token.ASCENDING:
8398 case Token.DESCENDING:
8399 return "descending";
8406 case Token.OPEN_BRACE:
8408 case Token.CLOSE_BRACE:
8410 case Token.OPEN_BRACKET:
8411 case Token.OPEN_BRACKET_EXPR:
8413 case Token.CLOSE_BRACKET:
8415 case Token.OPEN_PARENS_CAST:
8416 case Token.OPEN_PARENS_LAMBDA:
8417 case Token.OPEN_PARENS_DECONSTRUCT:
8418 case Token.OPEN_PARENS:
8420 case Token.CLOSE_PARENS:
8426 case Token.DEFAULT_COLON:
8430 case Token.SEMICOLON:
8436 case Token.INTERPOLATED_STRING_END:
8438 case Token.INTERPOLATED_STRING:
8447 case Token.BITWISE_AND:
8448 case Token.BITWISE_OR:
8455 case Token.OP_SHIFT_LEFT:
8456 case Token.OP_SHIFT_RIGHT:
8464 case Token.OP_COALESCING:
8465 case Token.OP_MULT_ASSIGN:
8466 case Token.OP_DIV_ASSIGN:
8467 case Token.OP_MOD_ASSIGN:
8468 case Token.OP_ADD_ASSIGN:
8469 case Token.OP_SUB_ASSIGN:
8470 case Token.OP_SHIFT_LEFT_ASSIGN:
8471 case Token.OP_SHIFT_RIGHT_ASSIGN:
8472 case Token.OP_AND_ASSIGN:
8473 case Token.OP_XOR_ASSIGN:
8474 case Token.OP_OR_ASSIGN:
8475 case Token.INTERR_OPERATOR:
8476 return "<operator>";
8498 case Token.OP_GENERICS_LT:
8499 case Token.GENERIC_DIMENSION:
8501 case Token.OP_GENERICS_GT:
8504 case Token.INTERR_NULLABLE:
8506 case Token.DOUBLE_COLON:
8510 case Token.IDENTIFIER:
8512 return "identifier";
8515 return "end-of-file";
8517 // All of these are internal.
8520 case Token.FIRST_KEYWORD:
8521 case Token.EVAL_COMPILATION_UNIT_PARSER:
8522 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8523 case Token.EVAL_STATEMENT_PARSER:
8524 case Token.LAST_KEYWORD:
8525 case Token.GENERATE_COMPLETION:
8526 case Token.COMPLETE_COMPLETION:
8527 return "<internal>";
8529 // A bit more robust.
8531 return yyNames [token];