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;
1025 type_declaration_name
1027 lexer.ConstraintsParsing = true;
1028 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1029 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1031 opt_primary_parameters
1033 opt_type_parameter_constraints_clauses
1035 valid_param_mod = 0;
1036 lexer.ConstraintsParsing = false;
1039 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
1042 current_container.SetConstraints ((List<Constraints>) $10);
1045 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1047 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1049 lexer.parsing_modifiers = true;
1054 Lexer.doc_state = XmlCommentState.Allowed;
1056 opt_class_member_declarations CLOSE_BRACE
1058 --lexer.parsing_declaration;
1060 Lexer.doc_state = XmlCommentState.Allowed;
1065 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1067 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1069 $$ = pop_current_class ();
1071 | opt_attributes opt_modifiers opt_partial STRUCT error
1073 Error_SyntaxError (yyToken);
1077 constant_declaration
1080 CONST type IDENTIFIER
1082 var lt = (LocatedToken) $5;
1083 var mod = (Modifiers) $2;
1084 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1085 current_type.AddMember (current_field);
1087 if ((mod & Modifiers.STATIC) != 0) {
1088 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1093 constant_initializer opt_constant_declarators SEMICOLON
1096 current_field.DocComment = Lexer.consume_doc_comment ();
1097 Lexer.doc_state = XmlCommentState.Allowed;
1100 current_field.Initializer = (ConstInitializer) $7;
1101 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1102 current_field = null;
1108 Error_SyntaxError (yyToken);
1110 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1114 opt_constant_declarators
1116 | constant_declarators
1119 constant_declarators
1120 : constant_declarator
1122 current_field.AddDeclarator ((FieldDeclarator) $1);
1124 | constant_declarators constant_declarator
1126 current_field.AddDeclarator ((FieldDeclarator) $2);
1131 : COMMA IDENTIFIER constant_initializer
1133 var lt = (LocatedToken) $2;
1134 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1135 lbag.AddLocation ($$, GetLocation ($1));
1139 constant_initializer
1142 ++lexer.parsing_block;
1144 constant_initializer_expr
1146 --lexer.parsing_block;
1147 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1151 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1156 constant_initializer_expr
1157 : constant_expression
1164 ref_member_type IDENTIFIER
1166 lexer.parsing_generic_declaration = false;
1168 FullNamedExpression type = (FullNamedExpression) $3;
1169 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1170 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1172 var lt = (LocatedToken) $4;
1173 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1174 current_type.AddField (current_field);
1177 opt_field_initializer
1178 opt_field_declarators
1182 current_field.DocComment = Lexer.consume_doc_comment ();
1183 Lexer.doc_state = XmlCommentState.Allowed;
1186 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1188 current_field = null;
1192 FIXED simple_type IDENTIFIER
1194 if (lang_version < LanguageVersion.ISO_2)
1195 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1197 var lt = (LocatedToken) $5;
1198 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1199 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1201 current_type.AddField (current_field);
1203 fixed_field_size opt_fixed_field_declarators SEMICOLON
1206 current_field.DocComment = Lexer.consume_doc_comment ();
1207 Lexer.doc_state = XmlCommentState.Allowed;
1210 current_field.Initializer = (ConstInitializer) $7;
1211 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1213 current_field = null;
1217 FIXED simple_type error
1220 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1224 opt_field_initializer
1228 ++lexer.parsing_block;
1229 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1230 start_block (GetLocation ($1));
1232 variable_initializer
1234 --lexer.parsing_block;
1235 current_field.Initializer = (Expression) $3;
1236 lbag.AppendToMember (current_field, GetLocation ($1));
1237 end_block (lexer.Location);
1238 current_local_parameters = null;
1242 opt_field_declarators
1250 current_field.AddDeclarator ((FieldDeclarator) $1);
1252 | field_declarators field_declarator
1254 current_field.AddDeclarator ((FieldDeclarator) $2);
1261 var lt = (LocatedToken) $2;
1262 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1263 lbag.AddLocation ($$, GetLocation ($1));
1265 | COMMA IDENTIFIER ASSIGN
1267 ++lexer.parsing_block;
1269 variable_initializer
1271 --lexer.parsing_block;
1272 var lt = (LocatedToken) $2;
1273 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1274 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1278 opt_fixed_field_declarators
1280 | fixed_field_declarators
1283 fixed_field_declarators
1284 : fixed_field_declarator
1286 current_field.AddDeclarator ((FieldDeclarator) $1);
1288 | fixed_field_declarators fixed_field_declarator
1290 current_field.AddDeclarator ((FieldDeclarator) $2);
1294 fixed_field_declarator
1295 : COMMA IDENTIFIER fixed_field_size
1297 var lt = (LocatedToken) $2;
1298 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1299 lbag.AddLocation ($$, GetLocation ($1));
1306 ++lexer.parsing_block;
1308 expression CLOSE_BRACKET
1310 --lexer.parsing_block;
1311 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1312 lbag.AddLocation ($$, GetLocation ($4));
1314 | OPEN_BRACKET error
1316 report.Error (443, lexer.Location, "Value or constant expected");
1321 variable_initializer
1326 // It has to be here for the parent to safely restore artificial block
1327 Error_SyntaxError (yyToken);
1336 Lexer.doc_state = XmlCommentState.NotAllowed;
1338 // Was added earlier in the case of body being eof for full ast
1342 Method method = (Method) $1;
1343 method.Block = (ToplevelBlock) $3;
1344 async_block = false;
1346 if (method.Block == null) {
1347 method.ParameterInfo.CheckParameters (method);
1349 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1350 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1351 method.GetSignatureForError ());
1354 if (current_container.Kind == MemberKind.Interface) {
1355 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1356 method.GetSignatureForError ());
1360 current_local_parameters = null;
1363 Lexer.doc_state = XmlCommentState.Allowed;
1374 lexer.parsing_generic_declaration = true;
1378 if (lang_version < LanguageVersion.V_7) {
1379 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
1382 $$ = new ReferenceTypeExpr ((FullNamedExpression) $3, GetLocation ($1));
1390 method_declaration_name OPEN_PARENS
1392 valid_param_mod = ParameterModifierType.All;
1394 opt_formal_parameter_list CLOSE_PARENS
1396 valid_param_mod = 0;
1397 MemberName name = (MemberName) $4;
1398 current_local_parameters = (ParametersCompiled) $7;
1400 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1401 name, current_local_parameters, (Attributes) $1);
1403 current_type.AddMember (method);
1405 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1408 method.DocComment = Lexer.consume_doc_comment ();
1410 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1414 lexer.ConstraintsParsing = true;
1416 opt_type_parameter_constraints_clauses
1418 lexer.ConstraintsParsing = false;
1421 var method = (Method) $9;
1422 method.SetConstraints ((List<Constraints>) $10);
1432 lexer.parsing_generic_declaration = true;
1434 method_declaration_name
1437 lexer.parsing_generic_declaration = false;
1438 valid_param_mod = ParameterModifierType.All;
1440 opt_formal_parameter_list CLOSE_PARENS
1442 lexer.ConstraintsParsing = true;
1444 opt_type_parameter_constraints_clauses
1446 lexer.ConstraintsParsing = false;
1447 valid_param_mod = 0;
1449 MemberName name = (MemberName) $6;
1450 current_local_parameters = (ParametersCompiled) $9;
1452 var modifiers = (Modifiers) $2;
1453 modifiers |= Modifiers.PARTIAL;
1455 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1456 modifiers, name, current_local_parameters, (Attributes) $1);
1458 current_type.AddMember (method);
1460 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1463 method.SetConstraints ((List<Constraints>) $12);
1466 method.DocComment = Lexer.consume_doc_comment ();
1468 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1469 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1475 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1477 MemberName name = (MemberName) $5;
1478 report.Error (1585, name.Location,
1479 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1481 var method = Method.Create (current_type, (FullNamedExpression) $3,
1482 0, name, (ParametersCompiled) $7, (Attributes) $1);
1484 current_type.AddMember (method);
1486 current_local_parameters = (ParametersCompiled) $7;
1489 method.DocComment = Lexer.consume_doc_comment ();
1496 method_declaration_name error
1498 Error_SyntaxError (yyToken);
1499 current_local_parameters = ParametersCompiled.Undefined;
1501 MemberName name = (MemberName) $4;
1502 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1503 name, current_local_parameters, (Attributes) $1);
1505 current_type.AddMember (method);
1508 method.DocComment = Lexer.consume_doc_comment ();
1517 | SEMICOLON { $$ = null; }
1526 | SEMICOLON { current_block = null; $$ = null; }
1529 if (lang_version < LanguageVersion.V_7) {
1530 FeatureIsNotAvailable (GetLocation ($1), "expression body constructor");
1533 ++lexer.parsing_block;
1535 expression SEMICOLON
1537 lexer.parsing_block = 0;
1538 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1539 var b = end_block (GetLocation ($4));
1540 b.IsCompilerGenerated = true;
1542 current_block = null;
1549 if (lang_version < LanguageVersion.V_6) {
1550 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1553 ++lexer.parsing_block;
1554 start_block (GetLocation ($1));
1556 lambda_arrow_expression SEMICOLON
1558 lexer.parsing_block = 0;
1559 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1560 var b = end_block (GetLocation ($4));
1561 b.IsCompilerGenerated = true;
1566 opt_formal_parameter_list
1567 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1568 | formal_parameter_list
1571 formal_parameter_list
1574 var pars_list = (List<Parameter>) $1;
1575 $$ = new ParametersCompiled (pars_list.ToArray ());
1577 | fixed_parameters COMMA parameter_array
1579 var pars_list = (List<Parameter>) $1;
1580 pars_list.Add ((Parameter) $3);
1582 $$ = new ParametersCompiled (pars_list.ToArray ());
1584 | fixed_parameters COMMA arglist_modifier
1586 var pars_list = (List<Parameter>) $1;
1587 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1588 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1590 | parameter_array COMMA error
1593 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1595 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1597 | fixed_parameters COMMA parameter_array COMMA error
1600 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1602 var pars_list = (List<Parameter>) $1;
1603 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1605 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1607 | arglist_modifier COMMA error
1609 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1611 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1613 | fixed_parameters COMMA ARGLIST COMMA error
1615 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1617 var pars_list = (List<Parameter>) $1;
1618 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1620 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1624 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1628 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1632 Error_SyntaxError (yyToken);
1633 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1640 parameters_bucket.Clear ();
1641 Parameter p = (Parameter) $1;
1642 parameters_bucket.Add (p);
1644 default_parameter_used = p.HasDefaultValue;
1645 $$ = parameters_bucket;
1647 | fixed_parameters COMMA fixed_parameter
1649 var pars = (List<Parameter>) $1;
1650 Parameter p = (Parameter) $3;
1652 if (p.HasExtensionMethodModifier)
1653 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1654 else if (!p.HasDefaultValue && default_parameter_used)
1655 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1657 default_parameter_used |= p.HasDefaultValue;
1660 lbag.AddLocation (p, GetLocation ($2));
1669 opt_parameter_modifier
1671 identifier_inside_body
1673 var lt = (LocatedToken) $4;
1674 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1677 opt_parameter_modifier
1679 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1681 var lt = (LocatedToken) $4;
1682 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1683 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1685 | attribute_sections error
1687 Error_SyntaxError (yyToken);
1688 Location l = GetLocation ($2);
1689 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1692 opt_parameter_modifier
1696 Error_SyntaxError (yyToken);
1697 Location l = GetLocation ($4);
1698 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1701 opt_parameter_modifier
1703 identifier_inside_body
1706 ++lexer.parsing_block;
1710 --lexer.parsing_block;
1711 if (lang_version <= LanguageVersion.V_3) {
1712 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1715 Parameter.Modifier mod = (Parameter.Modifier) $2;
1716 if (mod != Parameter.Modifier.NONE) {
1718 case Parameter.Modifier.REF:
1719 case Parameter.Modifier.OUT:
1720 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1721 Parameter.GetModifierSignature (mod));
1724 case Parameter.Modifier.This:
1725 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1726 Parameter.GetModifierSignature (mod));
1729 throw new NotImplementedException (mod.ToString ());
1732 mod = Parameter.Modifier.NONE;
1735 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1736 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1738 var lt = (LocatedToken) $4;
1739 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1740 lbag.AddLocation ($$, GetLocation ($5));
1743 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1747 opt_parameter_modifier
1748 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1749 | parameter_modifiers
1753 : parameter_modifier
1757 | parameter_modifiers parameter_modifier
1759 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1760 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1761 if (((Parameter.Modifier)$1 & p2) == p2) {
1762 Error_DuplicateParameterModifier (lexer.Location, p2);
1764 switch (mod & ~Parameter.Modifier.This) {
1765 case Parameter.Modifier.REF:
1766 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1768 case Parameter.Modifier.OUT:
1769 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1772 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1783 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1784 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1786 $$ = Parameter.Modifier.REF;
1790 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1791 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1793 $$ = Parameter.Modifier.OUT;
1797 if ((valid_param_mod & ParameterModifierType.This) == 0)
1798 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1800 if (lang_version <= LanguageVersion.ISO_2)
1801 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1803 $$ = Parameter.Modifier.This;
1808 : opt_attributes params_modifier type IDENTIFIER
1810 var lt = (LocatedToken) $4;
1811 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1813 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1815 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1817 var lt = (LocatedToken) $4;
1818 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1820 | opt_attributes params_modifier type error
1822 Error_SyntaxError (yyToken);
1824 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1831 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1832 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1834 | PARAMS parameter_modifier
1836 Parameter.Modifier mod = (Parameter.Modifier)$2;
1837 if ((mod & Parameter.Modifier.This) != 0) {
1838 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1840 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1843 | PARAMS params_modifier
1845 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1852 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1853 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1857 property_declaration
1861 member_declaration_name
1863 lexer.parsing_generic_declaration = false;
1865 tmpComment = Lexer.consume_doc_comment ();
1869 var type = (FullNamedExpression) $3;
1870 current_property = new Property (current_type, type, (Modifiers) $2,
1871 (MemberName) $4, (Attributes) $1);
1873 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1874 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1876 current_type.AddMember (current_property);
1877 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1879 lexer.PropertyParsing = true;
1881 accessor_declarations
1883 lexer.PropertyParsing = false;
1886 current_property.DocComment = ConsumeStoredComment ();
1888 if ($3 is ReferenceTypeExpr) {
1889 if (current_property.Get == null) {
1890 report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
1893 if (current_property.Set != null) {
1894 report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
1900 lbag.AppendToMember (current_property, GetLocation ($10));
1901 lexer.parsing_modifiers = true;
1903 opt_property_initializer
1905 current_property = null;
1910 member_declaration_name
1912 lexer.parsing_generic_declaration = false;
1914 tmpComment = Lexer.consume_doc_comment ();
1915 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1919 var type = (FullNamedExpression) $3;
1920 var property = new Property (current_type, type, (Modifiers) $2,
1921 (MemberName) $4, (Attributes) $1);
1923 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1924 property.Get.Block = (ToplevelBlock) $6;
1926 if (current_container.Kind == MemberKind.Interface) {
1927 report.Error (531, property.Get.Block.StartLocation,
1928 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1931 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1932 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1935 property.DocComment = ConsumeStoredComment ();
1937 current_type.AddMember (property);
1939 current_local_parameters = null;
1943 opt_property_initializer
1947 ++lexer.parsing_block;
1948 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1949 start_block (GetLocation ($1));
1951 property_initializer SEMICOLON
1953 --lexer.parsing_block;
1954 ((Property)current_property).Initializer = (Expression) $3;
1955 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1956 end_block (GetLocation ($4));
1957 current_local_parameters = null;
1960 Lexer.doc_state = XmlCommentState.Allowed;
1964 property_initializer
1970 : opt_attributes opt_modifiers
1971 ref_member_type indexer_declaration_name OPEN_BRACKET
1973 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1975 opt_formal_parameter_list CLOSE_BRACKET
1977 valid_param_mod = 0;
1978 var type = (FullNamedExpression) $3;
1979 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1981 current_property = indexer;
1983 current_type.AddIndexer (indexer);
1984 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1986 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1987 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1989 if (indexer.ParameterInfo.IsEmpty) {
1990 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1994 tmpComment = Lexer.consume_doc_comment ();
1995 Lexer.doc_state = XmlCommentState.Allowed;
1998 lexer.PropertyParsing = true;
1999 current_local_parameters = (ParametersCompiled) $7;
2003 lexer.PropertyParsing = false;
2004 current_local_parameters = null;
2006 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
2007 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
2010 current_property.DocComment = ConsumeStoredComment ();
2012 if ($3 is ReferenceTypeExpr) {
2013 if (current_property.Get == null) {
2014 report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
2017 if (current_property.Set != null) {
2018 report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
2022 current_property = null;
2027 : OPEN_BRACE accessor_declarations CLOSE_BRACE
2029 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
2033 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
2034 current_property.Get.Block = (ToplevelBlock) $1;
2038 accessor_declarations
2039 : get_accessor_declaration
2040 | get_accessor_declaration accessor_declarations
2041 | set_accessor_declaration
2042 | set_accessor_declaration accessor_declarations
2045 if (yyToken == Token.CLOSE_BRACE) {
2046 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
2048 if (yyToken == Token.SEMICOLON)
2049 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
2051 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
2056 get_accessor_declaration
2057 : opt_attributes opt_modifiers GET
2059 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2060 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2063 if (current_property.Get != null) {
2064 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2067 if (current_property is Indexer) {
2068 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
2069 (Attributes) $1, GetLocation ($3));
2071 current_property.Get = new Property.GetMethod (current_property,
2072 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2075 current_local_parameters = current_property.Get.ParameterInfo;
2076 lbag.AddMember (current_property.Get, mod_locations);
2077 lexer.PropertyParsing = false;
2082 current_property.Get.Block = (ToplevelBlock) $5;
2084 if (current_container.Kind == MemberKind.Interface) {
2085 report.Error (531, current_property.Get.Block.StartLocation,
2086 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2090 current_local_parameters = null;
2091 lexer.PropertyParsing = true;
2094 if (Lexer.doc_state == XmlCommentState.Error)
2095 Lexer.doc_state = XmlCommentState.NotAllowed;
2099 set_accessor_declaration
2100 : opt_attributes opt_modifiers SET
2102 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2103 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2106 if (current_property.Set != null) {
2107 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2110 if (current_property is Indexer) {
2111 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2112 ParametersCompiled.MergeGenerated (compiler,
2113 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2114 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2116 (Attributes) $1, GetLocation ($3));
2118 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2119 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2120 (Attributes) $1, GetLocation ($3));
2123 current_local_parameters = current_property.Set.ParameterInfo;
2124 lbag.AddMember (current_property.Set, mod_locations);
2125 lexer.PropertyParsing = false;
2130 current_property.Set.Block = (ToplevelBlock) $5;
2132 if (current_container.Kind == MemberKind.Interface) {
2133 report.Error (531, current_property.Set.Block.StartLocation,
2134 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2138 current_local_parameters = null;
2139 lexer.PropertyParsing = true;
2142 && Lexer.doc_state == XmlCommentState.Error)
2143 Lexer.doc_state = XmlCommentState.NotAllowed;
2157 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2163 interface_declaration
2170 type_declaration_name
2172 lexer.ConstraintsParsing = true;
2173 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2174 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2177 opt_type_parameter_constraints_clauses
2179 lexer.ConstraintsParsing = false;
2182 current_container.SetConstraints ((List<Constraints>) $9);
2185 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2186 Lexer.doc_state = XmlCommentState.Allowed;
2189 lexer.parsing_modifiers = true;
2191 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2193 --lexer.parsing_declaration;
2195 Lexer.doc_state = XmlCommentState.Allowed;
2200 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2202 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2204 $$ = pop_current_class ();
2206 | opt_attributes opt_modifiers opt_partial INTERFACE error
2208 Error_SyntaxError (yyToken);
2212 opt_interface_member_declarations
2214 | interface_member_declarations
2217 interface_member_declarations
2218 : interface_member_declaration
2220 lexer.parsing_modifiers = true;
2221 lexer.parsing_block = 0;
2223 | interface_member_declarations interface_member_declaration
2225 lexer.parsing_modifiers = true;
2226 lexer.parsing_block = 0;
2230 interface_member_declaration
2231 : constant_declaration
2233 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2237 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2239 | method_declaration
2240 | property_declaration
2242 | indexer_declaration
2243 | operator_declaration
2245 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2247 | constructor_declaration
2249 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2253 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2257 operator_declaration
2258 : opt_attributes opt_modifiers operator_declarator
2263 OperatorDeclaration decl = (OperatorDeclaration) $3;
2265 Operator op = new Operator (
2266 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2267 current_local_parameters,
2268 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2270 if (op.Block == null)
2271 op.ParameterInfo.CheckParameters (op);
2274 op.DocComment = tmpComment;
2275 Lexer.doc_state = XmlCommentState.Allowed;
2278 // Note again, checking is done in semantic analysis
2279 current_type.AddOperator (op);
2281 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2284 current_local_parameters = null;
2289 : type_expression_or_array
2292 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2293 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2298 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2300 valid_param_mod = ParameterModifierType.DefaultValue;
2301 if ((Operator.OpType) $3 == Operator.OpType.Is)
2302 valid_param_mod |= ParameterModifierType.Out;
2304 opt_formal_parameter_list CLOSE_PARENS
2306 valid_param_mod = 0;
2308 Location loc = GetLocation ($2);
2309 Operator.OpType op = (Operator.OpType) $3;
2310 current_local_parameters = (ParametersCompiled)$6;
2312 int p_count = current_local_parameters.Count;
2314 if (op == Operator.OpType.Addition)
2315 op = Operator.OpType.UnaryPlus;
2316 else if (op == Operator.OpType.Subtraction)
2317 op = Operator.OpType.UnaryNegation;
2320 if (IsUnaryOperator (op)) {
2322 report.Error (1020, loc, "Overloadable binary operator expected");
2323 } else if (p_count != 1) {
2324 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2325 Operator.GetName (op));
2327 } else if (op == Operator.OpType.Is) {
2328 // TODO: Special checks for is operator
2331 report.Error (1019, loc, "Overloadable unary operator expected");
2332 } else if (p_count != 2) {
2333 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2334 Operator.GetName (op));
2339 tmpComment = Lexer.consume_doc_comment ();
2340 Lexer.doc_state = XmlCommentState.NotAllowed;
2343 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2344 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2346 | conversion_operator_declarator
2349 overloadable_operator
2351 : BANG { $$ = Operator.OpType.LogicalNot; }
2352 | TILDE { $$ = Operator.OpType.OnesComplement; }
2353 | OP_INC { $$ = Operator.OpType.Increment; }
2354 | OP_DEC { $$ = Operator.OpType.Decrement; }
2355 | TRUE { $$ = Operator.OpType.True; }
2356 | FALSE { $$ = Operator.OpType.False; }
2357 // Unary and binary:
2358 | PLUS { $$ = Operator.OpType.Addition; }
2359 | MINUS { $$ = Operator.OpType.Subtraction; }
2361 | STAR { $$ = Operator.OpType.Multiply; }
2362 | DIV { $$ = Operator.OpType.Division; }
2363 | PERCENT { $$ = Operator.OpType.Modulus; }
2364 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2365 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2366 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2367 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2368 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2369 | OP_EQ { $$ = Operator.OpType.Equality; }
2370 | OP_NE { $$ = Operator.OpType.Inequality; }
2371 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2372 | OP_LT { $$ = Operator.OpType.LessThan; }
2373 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2374 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2377 if (lang_version != LanguageVersion.Experimental)
2378 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2380 $$ = Operator.OpType.Is;
2384 conversion_operator_declarator
2385 : IMPLICIT OPERATOR type OPEN_PARENS
2387 valid_param_mod = ParameterModifierType.DefaultValue;
2389 opt_formal_parameter_list CLOSE_PARENS
2391 valid_param_mod = 0;
2393 Location loc = GetLocation ($2);
2394 current_local_parameters = (ParametersCompiled)$6;
2396 if (current_local_parameters.Count != 1) {
2397 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2401 tmpComment = Lexer.consume_doc_comment ();
2402 Lexer.doc_state = XmlCommentState.NotAllowed;
2405 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2406 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2408 | EXPLICIT OPERATOR type OPEN_PARENS
2410 valid_param_mod = ParameterModifierType.DefaultValue;
2412 opt_formal_parameter_list CLOSE_PARENS
2414 valid_param_mod = 0;
2416 Location loc = GetLocation ($2);
2417 current_local_parameters = (ParametersCompiled)$6;
2419 if (current_local_parameters.Count != 1) {
2420 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2424 tmpComment = Lexer.consume_doc_comment ();
2425 Lexer.doc_state = XmlCommentState.NotAllowed;
2428 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2429 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2433 Error_SyntaxError (yyToken);
2434 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2435 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2439 Error_SyntaxError (yyToken);
2440 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2441 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2445 constructor_declaration
2446 : constructor_declarator
2449 Constructor c = (Constructor) $1;
2450 c.Block = (ToplevelBlock) $2;
2453 c.DocComment = ConsumeStoredComment ();
2455 current_local_parameters = null;
2457 Lexer.doc_state = XmlCommentState.Allowed;
2461 constructor_declarator
2467 tmpComment = Lexer.consume_doc_comment ();
2468 Lexer.doc_state = XmlCommentState.Allowed;
2471 valid_param_mod = ParameterModifierType.All;
2473 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2475 valid_param_mod = 0;
2476 current_local_parameters = (ParametersCompiled) $6;
2478 var lt = (LocatedToken) $3;
2479 var mods = (Modifiers) $2;
2480 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2482 if (lt.Value != current_container.MemberName.Name) {
2483 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2484 } else if ((mods & Modifiers.STATIC) != 0) {
2485 if (!current_local_parameters.IsEmpty) {
2486 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2487 c.GetSignatureForError ());
2490 if ((mods & Modifiers.AccessibilityMask) != 0){
2491 report.Error (515, c.Location,
2492 "`{0}': static constructor cannot have an access modifier",
2493 c.GetSignatureForError ());
2496 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2497 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2501 current_type.AddConstructor (c);
2502 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2506 // start block here, so possible anonymous methods inside
2507 // constructor initializer can get correct parent block
2509 start_block (lexer.Location);
2511 opt_constructor_initializer
2514 var c = (Constructor) $8;
2515 c.Initializer = (ConstructorInitializer) $9;
2518 report.Error (514, c.Location,
2519 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2520 c.GetSignatureForError ());
2528 opt_constructor_initializer
2530 | constructor_initializer
2533 constructor_initializer
2534 : COLON BASE OPEN_PARENS
2536 ++lexer.parsing_block;
2538 opt_argument_list CLOSE_PARENS
2540 --lexer.parsing_block;
2541 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2542 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2544 | COLON THIS OPEN_PARENS
2546 ++lexer.parsing_block;
2548 opt_argument_list CLOSE_PARENS
2550 --lexer.parsing_block;
2551 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2552 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2556 Error_SyntaxError (yyToken);
2557 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2558 lbag.AddLocation ($$, GetLocation ($1));
2562 Error_SyntaxError (yyToken);
2567 destructor_declaration
2568 : opt_attributes opt_modifiers TILDE
2571 tmpComment = Lexer.consume_doc_comment ();
2572 Lexer.doc_state = XmlCommentState.NotAllowed;
2575 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2577 IDENTIFIER OPEN_PARENS CLOSE_PARENS destructor_body
2579 var lt = (LocatedToken) $5;
2580 if (lt.Value != current_container.MemberName.Name){
2581 report.Error (574, lt.Location, "Name of destructor must match name of class");
2582 } else if (current_container.Kind != MemberKind.Class){
2583 report.Error (575, lt.Location, "Only class types can contain destructor");
2586 Destructor d = new Destructor (current_type, (Modifiers) $2,
2587 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2589 d.DocComment = ConsumeStoredComment ();
2591 d.Block = (ToplevelBlock) $8;
2592 current_type.AddMember (d);
2593 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2595 current_local_parameters = null;
2602 EVENT type member_declaration_name
2604 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2605 current_type.AddMember (current_event_field);
2607 if (current_event_field.MemberName.ExplicitInterface != null) {
2608 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2609 current_event_field.GetSignatureForError ());
2612 $$ = current_event_field;
2614 opt_event_initializer
2615 opt_event_declarators
2619 current_event_field.DocComment = Lexer.consume_doc_comment ();
2620 Lexer.doc_state = XmlCommentState.Allowed;
2623 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2624 current_event_field = null;
2628 EVENT type member_declaration_name
2631 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2632 current_type.AddMember (current_event);
2633 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2635 lexer.EventParsing = true;
2637 event_accessor_declarations
2639 if (current_container.Kind == MemberKind.Interface)
2640 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2642 lexer.EventParsing = false;
2647 current_event.DocComment = Lexer.consume_doc_comment ();
2648 Lexer.doc_state = XmlCommentState.Allowed;
2651 lbag.AppendToMember (current_event, GetLocation ($9));
2652 current_event = null;
2653 current_local_parameters = null;
2659 Error_SyntaxError (yyToken);
2661 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2665 opt_event_initializer
2669 ++lexer.parsing_block;
2671 event_variable_initializer
2673 --lexer.parsing_block;
2674 current_event_field.Initializer = (Expression) $3;
2678 opt_event_declarators
2686 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2688 | event_declarators event_declarator
2690 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2697 var lt = (LocatedToken) $2;
2698 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2699 lbag.AddLocation ($$, GetLocation ($1));
2701 | COMMA IDENTIFIER ASSIGN event_variable_initializer
2703 var lt = (LocatedToken) $2;
2704 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $4);
2705 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2709 event_variable_initializer
2711 if (current_container.Kind == MemberKind.Interface) {
2712 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2713 current_event_field.GetSignatureForError ());
2716 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2717 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2718 current_event_field.GetSignatureForError ());
2721 ++lexer.parsing_block;
2722 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2723 start_block (lexer.Location);
2725 variable_initializer
2729 --lexer.parsing_block;
2730 end_block (lexer.Location);
2731 current_local_parameters = null;
2735 event_accessor_declarations
2736 : add_accessor_declaration remove_accessor_declaration
2737 | remove_accessor_declaration add_accessor_declaration
2738 | add_accessor_declaration
2740 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2741 current_event.GetSignatureForError ());
2743 | remove_accessor_declaration
2745 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2746 current_event.GetSignatureForError ());
2750 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2755 add_accessor_declaration
2756 : opt_attributes opt_modifiers ADD
2758 if ($2 != ModifierNone) {
2759 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2762 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2763 current_local_parameters = current_event.Add.ParameterInfo;
2765 lbag.AddMember (current_event.Add, mod_locations);
2766 lexer.EventParsing = false;
2768 event_accessor_block
2770 lexer.EventParsing = true;
2772 current_event.Add.Block = (ToplevelBlock) $5;
2774 if (current_container.Kind == MemberKind.Interface) {
2775 report.Error (531, current_event.Add.Block.StartLocation,
2776 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2779 current_local_parameters = null;
2783 remove_accessor_declaration
2784 : opt_attributes opt_modifiers REMOVE
2786 if ($2 != ModifierNone) {
2787 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2790 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2791 current_local_parameters = current_event.Remove.ParameterInfo;
2793 lbag.AddMember (current_event.Remove, mod_locations);
2794 lexer.EventParsing = false;
2796 event_accessor_block
2798 lexer.EventParsing = true;
2800 current_event.Remove.Block = (ToplevelBlock) $5;
2802 if (current_container.Kind == MemberKind.Interface) {
2803 report.Error (531, current_event.Remove.Block.StartLocation,
2804 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2807 current_local_parameters = null;
2811 event_accessor_block
2814 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2821 attributes_without_members
2822 : attribute_sections CLOSE_BRACE
2824 current_type.UnattachedAttributes = (Attributes) $1;
2825 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2826 lexer.putback ('}');
2830 // For full ast try to recover incomplete ambiguous member
2831 // declaration in form on class X { public int }
2833 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2835 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2837 lexer.putback ('}');
2839 lexer.parsing_generic_declaration = false;
2840 FullNamedExpression type = (FullNamedExpression) $3;
2841 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2842 current_type.AddField (current_field);
2850 ENUM type_declaration_name
2854 enumTypeComment = Lexer.consume_doc_comment ();
2859 Lexer.doc_state = XmlCommentState.Allowed;
2861 MemberName name = (MemberName) $4;
2862 if (name.IsGeneric) {
2863 report.Error (1675, name.Location, "Enums cannot have type parameters");
2866 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2868 opt_enum_member_declarations
2870 lexer.parsing_modifiers = true;
2872 // here will be evaluated after CLOSE_BLACE is consumed.
2874 Lexer.doc_state = XmlCommentState.Allowed;
2876 CLOSE_BRACE opt_semicolon
2879 current_container.DocComment = enumTypeComment;
2881 --lexer.parsing_declaration;
2884 // em.DocComment = ev.DocComment;
2886 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2887 $$ = pop_current_class ();
2899 Error_TypeExpected (GetLocation ($1));
2904 opt_enum_member_declarations
2906 | enum_member_declarations
2907 | enum_member_declarations COMMA
2909 lbag.AddLocation ($1, GetLocation ($2));
2913 enum_member_declarations
2914 : enum_member_declaration
2915 | enum_member_declarations COMMA enum_member_declaration
2917 lbag.AddLocation ($1, GetLocation ($2));
2922 enum_member_declaration
2923 : opt_attributes IDENTIFIER
2925 var lt = (LocatedToken) $2;
2926 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2927 ((Enum) current_type).AddEnumMember (em);
2930 em.DocComment = Lexer.consume_doc_comment ();
2931 Lexer.doc_state = XmlCommentState.Allowed;
2936 | opt_attributes IDENTIFIER
2938 ++lexer.parsing_block;
2940 tmpComment = Lexer.consume_doc_comment ();
2941 Lexer.doc_state = XmlCommentState.NotAllowed;
2944 ASSIGN constant_expression
2946 --lexer.parsing_block;
2948 var lt = (LocatedToken) $2;
2949 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2950 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2951 ((Enum) current_type).AddEnumMember (em);
2954 em.DocComment = ConsumeStoredComment ();
2958 | opt_attributes IDENTIFIER error
2960 Error_SyntaxError (yyToken);
2962 var lt = (LocatedToken) $2;
2963 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2964 ((Enum) current_type).AddEnumMember (em);
2967 em.DocComment = Lexer.consume_doc_comment ();
2968 Lexer.doc_state = XmlCommentState.Allowed;
2973 | attributes_without_members
2976 delegate_declaration
2980 ref_member_type type_declaration_name
2983 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2985 opt_formal_parameter_list CLOSE_PARENS
2987 valid_param_mod = 0;
2989 ParametersCompiled p = (ParametersCompiled) $8;
2991 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2993 p.CheckParameters (del);
2995 current_container.AddTypeContainer (del);
2997 current_delegate = del;
2998 lexer.ConstraintsParsing = true;
3000 opt_type_parameter_constraints_clauses
3002 lexer.ConstraintsParsing = false;
3007 current_delegate.DocComment = Lexer.consume_doc_comment ();
3008 Lexer.doc_state = XmlCommentState.Allowed;
3012 current_delegate.SetConstraints ((List<Constraints>) $11);
3013 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
3015 $$ = current_delegate;
3017 current_delegate = null;
3025 if (lang_version < LanguageVersion.ISO_2)
3026 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
3028 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
3032 namespace_or_type_expr
3034 | qualified_alias_member IDENTIFIER opt_type_argument_list
3036 var lt1 = (LocatedToken) $1;
3037 var lt2 = (LocatedToken) $2;
3039 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3040 lbag.AddLocation ($$, GetLocation ($2));
3042 | qualified_alias_member IDENTIFIER generic_dimension
3044 var lt1 = (LocatedToken) $1;
3045 var lt2 = (LocatedToken) $2;
3047 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3048 lbag.AddLocation ($$, GetLocation ($2));
3054 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
3056 var lt = (LocatedToken) $3;
3057 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3058 lbag.AddLocation ($$, GetLocation ($2));
3060 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
3062 var lt = (LocatedToken) $3;
3063 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3064 lbag.AddLocation ($$, GetLocation ($2));
3069 : IDENTIFIER opt_type_argument_list
3071 var lt = (LocatedToken) $1;
3072 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3074 | IDENTIFIER generic_dimension
3076 var lt = (LocatedToken) $1;
3077 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3082 // Generics arguments (any type, without attributes)
3084 opt_type_argument_list
3086 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3088 if (lang_version < LanguageVersion.ISO_2)
3089 FeatureIsNotAvailable (GetLocation ($1), "generics");
3093 | OP_GENERICS_LT error
3095 Error_TypeExpected (lexer.Location);
3096 $$ = new TypeArguments ();
3103 TypeArguments type_args = new TypeArguments ();
3104 type_args.Add ((FullNamedExpression) $1);
3107 | type_arguments COMMA type
3109 TypeArguments type_args = (TypeArguments) $1;
3110 type_args.Add ((FullNamedExpression) $3);
3116 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3118 type_declaration_name
3121 lexer.parsing_generic_declaration = true;
3123 opt_type_parameter_list
3125 lexer.parsing_generic_declaration = false;
3126 var lt = (LocatedToken) $1;
3127 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3131 member_declaration_name
3132 : method_declaration_name
3134 MemberName mn = (MemberName)$1;
3135 if (mn.TypeParameters != null)
3136 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3137 mn.GetSignatureForError ()));
3141 method_declaration_name
3142 : type_declaration_name
3143 | explicit_interface IDENTIFIER opt_type_parameter_list
3145 lexer.parsing_generic_declaration = false;
3146 var lt = (LocatedToken) $2;
3147 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3151 indexer_declaration_name
3154 lexer.parsing_generic_declaration = false;
3155 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3157 | explicit_interface THIS
3159 lexer.parsing_generic_declaration = false;
3160 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3165 : IDENTIFIER opt_type_argument_list DOT
3167 var lt = (LocatedToken) $1;
3168 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3169 lbag.AddLocation ($$, GetLocation ($3));
3171 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3173 var lt1 = (LocatedToken) $1;
3174 var lt2 = (LocatedToken) $2;
3176 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3177 lbag.AddLocation ($$, GetLocation ($4));
3179 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3181 var lt = (LocatedToken) $2;
3182 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3183 lbag.AddLocation ($$, GetLocation ($4));
3187 opt_type_parameter_list
3189 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3191 if (lang_version < LanguageVersion.ISO_2)
3192 FeatureIsNotAvailable (GetLocation ($1), "generics");
3195 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3202 var tparams = new TypeParameters ();
3203 tparams.Add ((TypeParameter)$1);
3206 | type_parameters COMMA type_parameter
3208 var tparams = (TypeParameters) $1;
3209 tparams.Add ((TypeParameter)$3);
3211 lbag.AddLocation ($3, GetLocation ($3));
3216 : opt_attributes opt_type_parameter_variance IDENTIFIER
3218 var lt = (LocatedToken)$3;
3219 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3223 if (GetTokenName (yyToken) == "type")
3224 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3226 Error_SyntaxError (yyToken);
3228 $$ = new TypeParameter (MemberName.Null, null, null);
3233 // All types where void is allowed
3236 : type_expression_or_array
3239 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3246 lexer.parsing_generic_declaration = true;
3251 // A type which does not allow `void' to be used
3254 : type_expression_or_array
3264 : type_expression_or_array
3267 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3268 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3272 type_expression_or_array
3274 | type_expression rank_specifiers
3276 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3281 : namespace_or_type_expr opt_nullable
3284 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3286 var sn = $1 as SimpleName;
3287 if (sn != null && sn.Name == "var")
3288 $$ = new VarExpr (sn.Location);
3293 | namespace_or_type_expr pointer_stars
3295 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3297 | builtin_type_expression
3298 | OPEN_PARENS tuple_elements CLOSE_PARENS opt_nullable
3300 if (lang_version < LanguageVersion.V_7)
3301 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3303 var a = (Tuple<TypeArguments, List<string>>) $2;
3304 if (a.Item1.Count < 2) {
3305 report.Error (8124, GetLocation ($1), "Tuple must contain at least two elements");
3308 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
3311 $$ = new ComposedCast ((FullNamedExpression) $$, (ComposedTypeSpecifier) $4);
3316 : tuple_element tuple_element_name
3318 var type_args = new TypeArguments ();
3319 type_args.Add ((FullNamedExpression) $1);
3321 var names = new List<string> (2);
3322 var lt = (LocatedToken) $2;
3323 names.Add (lt?.Value);
3325 $$ = Tuple.Create (type_args, names);
3327 | tuple_elements COMMA tuple_element tuple_element_name
3329 var a = (Tuple<TypeArguments, List<string>>) $1;
3330 a.Item1.Add ((FullNamedExpression) $3);
3331 var lt = (LocatedToken) $4;
3332 a.Item2.Add (lt?.Value);
3349 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3350 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3354 builtin_type_expression
3355 : builtin_types opt_nullable
3358 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3360 | builtin_types pointer_stars
3362 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3364 | VOID pointer_stars
3366 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3373 var types = new List<FullNamedExpression> (2);
3374 types.Add ((FullNamedExpression) $1);
3377 | type_list COMMA base_type_name
3379 var types = (List<FullNamedExpression>) $1;
3380 types.Add ((FullNamedExpression) $3);
3388 if ($1 is ComposedCast) {
3389 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3396 * replaces all the productions for isolating the various
3397 * simple types, but we need this to reuse it easily in variable_type
3400 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3401 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3402 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3403 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3404 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3405 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3410 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3411 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3412 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3413 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3414 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3415 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3416 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3417 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3418 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3422 // Expressions, section 7.5
3427 : type_name_expression
3429 | array_creation_expression
3430 | parenthesized_expression
3431 | default_value_expression
3432 | invocation_expression
3436 | post_increment_expression
3437 | post_decrement_expression
3438 | object_or_delegate_creation_expression
3439 | anonymous_type_expression
3442 | checked_expression
3443 | unchecked_expression
3444 | pointer_member_access
3445 | anonymous_method_expression
3446 | undocumented_expressions
3447 | interpolated_string
3450 type_name_expression
3452 | IDENTIFIER GENERATE_COMPLETION {
3453 var lt = (LocatedToken) $1;
3454 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3463 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3467 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3468 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3472 : OPEN_PARENS tuple_literal_elements CLOSE_PARENS
3474 if (lang_version < LanguageVersion.V_7)
3475 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3477 $$ = new TupleLiteral ((List<TupleLiteralElement>)$2, GetLocation ($1));
3481 tuple_literal_elements
3482 : tuple_literal_element COMMA tuple_literal_element
3484 $$ = new List<TupleLiteralElement> () {
3485 (TupleLiteralElement) $1, (TupleLiteralElement) $3
3488 | tuple_literal_elements COMMA tuple_literal_element
3490 var list = (List<TupleLiteralElement>)$1;
3491 list.Add ((TupleLiteralElement) $3);
3495 tuple_literal_element
3498 $$ = new TupleLiteralElement ((Expression) $1);
3500 | IDENTIFIER COLON expression
3502 var lt = (LocatedToken) $1;
3503 $$ = new TupleLiteralElement (lt.Value, (Expression) $3, lt.Location);
3508 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3510 if (lang_version < LanguageVersion.V_6)
3511 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3513 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3515 | INTERPOLATED_STRING_END
3517 if (lang_version < LanguageVersion.V_6)
3518 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3520 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3527 var list = new List<Expression> ();
3528 list.Add ((InterpolatedStringInsert) $1);
3531 | interpolations INTERPOLATED_STRING interpolation
3533 var list = (List<Expression>) $1;
3534 list.Add ((StringLiteral) $2);
3535 list.Add ((InterpolatedStringInsert) $3);
3543 $$ = new InterpolatedStringInsert ((Expression) $1);
3545 | expression COMMA expression
3547 $$ = new InterpolatedStringInsert ((Expression) $1) {
3548 Alignment = (Expression)$3
3553 lexer.parsing_interpolation_format = true;
3557 lexer.parsing_interpolation_format = false;
3559 $$ = new InterpolatedStringInsert ((Expression) $1) {
3563 | expression COMMA expression COLON
3565 lexer.parsing_interpolation_format = true;
3569 lexer.parsing_interpolation_format = false;
3571 $$ = new InterpolatedStringInsert ((Expression) $1) {
3572 Alignment = (Expression)$3,
3573 Format = (string) $6
3580 // Here is the trick, tokenizer may think that parens is a special but
3581 // parser is interested in open parens only, so we merge them.
3582 // Consider: if (a)foo ();
3590 // Use this production to accept closing parenthesis or
3591 // performing completion
3595 | COMPLETE_COMPLETION
3599 parenthesized_expression
3600 : OPEN_PARENS expression CLOSE_PARENS
3602 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3603 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3605 | OPEN_PARENS expression COMPLETE_COMPLETION
3607 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3612 : primary_expression DOT identifier_inside_body opt_type_argument_list
3614 var lt = (LocatedToken) $3;
3615 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3616 lbag.AddLocation ($$, GetLocation ($2));
3618 | primary_expression DOT identifier_inside_body generic_dimension
3620 var lt = (LocatedToken) $3;
3621 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3622 lbag.AddLocation ($$, GetLocation ($2));
3624 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3626 if (lang_version < LanguageVersion.V_6)
3627 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3629 var lt = (LocatedToken) $4;
3630 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3631 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3633 | builtin_types DOT identifier_inside_body opt_type_argument_list
3635 var lt = (LocatedToken) $3;
3636 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3637 lbag.AddLocation ($$, GetLocation ($2));
3639 | BASE DOT identifier_inside_body opt_type_argument_list
3641 var lt = (LocatedToken) $3;
3642 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3643 lbag.AddLocation ($$, GetLocation ($2));
3645 | AWAIT DOT identifier_inside_body opt_type_argument_list
3647 var lt = (LocatedToken) $3;
3648 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3649 lbag.AddLocation ($$, GetLocation ($2));
3651 | qualified_alias_member identifier_inside_body opt_type_argument_list
3653 var lt1 = (LocatedToken) $1;
3654 var lt2 = (LocatedToken) $2;
3656 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3657 lbag.AddLocation ($$, GetLocation ($2));
3659 | qualified_alias_member identifier_inside_body generic_dimension
3661 var lt1 = (LocatedToken) $1;
3662 var lt2 = (LocatedToken) $2;
3664 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3665 lbag.AddLocation ($$, GetLocation ($2));
3667 | primary_expression DOT GENERATE_COMPLETION {
3668 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3670 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3671 var lt = (LocatedToken) $3;
3672 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3674 | builtin_types DOT GENERATE_COMPLETION
3676 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3678 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3679 var lt = (LocatedToken) $3;
3680 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3684 invocation_expression
3685 : primary_expression open_parens_any opt_argument_list close_parens
3687 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3688 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3690 | primary_expression open_parens_any argument_list error
3692 Error_SyntaxError (yyToken);
3694 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3695 lbag.AddLocation ($$, GetLocation ($2));
3697 | primary_expression open_parens_any error
3699 Error_SyntaxError (yyToken);
3701 $$ = new Invocation ((Expression) $1, null);
3702 lbag.AddLocation ($$, GetLocation ($2));
3706 opt_object_or_collection_initializer
3707 : /* empty */ { $$ = null; }
3708 | object_or_collection_initializer
3711 object_or_collection_initializer
3712 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3715 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3717 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3719 lbag.AddLocation ($$, GetLocation ($3));
3721 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3723 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3724 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3728 opt_member_initializer_list
3729 : /* empty */ { $$ = null; }
3730 | member_initializer_list
3736 member_initializer_list
3737 : member_initializer
3739 var a = new List<Expression> ();
3740 a.Add ((Expression) $1);
3743 | member_initializer_list COMMA member_initializer
3745 var a = (List<Expression>)$1;
3746 a.Add ((Expression) $3);
3749 | member_initializer_list error {
3750 Error_SyntaxError (yyToken);
3756 : IDENTIFIER ASSIGN initializer_value
3758 var lt = (LocatedToken) $1;
3759 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3760 lbag.AddLocation ($$, GetLocation ($2));
3762 | AWAIT ASSIGN initializer_value
3764 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3765 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3766 lbag.AddLocation ($$, GetLocation ($2));
3768 | GENERATE_COMPLETION
3770 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3772 | non_assignment_expression opt_COMPLETE_COMPLETION {
3773 CompletionSimpleName csn = $1 as CompletionSimpleName;
3775 $$ = new CollectionElementInitializer ((Expression)$1);
3777 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3779 | OPEN_BRACE expression_list CLOSE_BRACE
3782 $$ = new CollectionElementInitializer (GetLocation ($1));
3784 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3786 lbag.AddLocation ($$, GetLocation ($3));
3788 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3790 if (lang_version < LanguageVersion.V_6)
3791 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3793 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3794 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3796 | OPEN_BRACE CLOSE_BRACE
3798 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3799 $$ = new CollectionElementInitializer (GetLocation ($1));
3800 lbag.AddLocation ($$, GetLocation ($2));
3806 | object_or_collection_initializer
3810 : /* empty */ { $$ = null; }
3815 : argument_or_named_argument
3817 Arguments list = new Arguments (4);
3818 list.Add ((Argument) $1);
3821 | argument_list COMMA argument
3823 Arguments list = (Arguments) $1;
3824 if (list [list.Count - 1] is NamedArgument)
3825 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3827 list.Add ((Argument) $3);
3830 | argument_list COMMA named_argument
3832 Arguments list = (Arguments) $1;
3833 NamedArgument a = (NamedArgument) $3;
3834 for (int i = 0; i < list.Count; ++i) {
3835 NamedArgument na = list [i] as NamedArgument;
3836 if (na != null && na.Name == a.Name)
3837 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3844 | argument_list COMMA error
3846 if (lexer.putback_char == -1)
3847 lexer.putback (')'); // TODO: Wrong but what can I do
3848 Error_SyntaxError (yyToken);
3853 report.Error (839, GetLocation ($1), "An argument is missing");
3861 $$ = new Argument ((Expression) $1);
3863 | non_simple_argument
3866 argument_or_named_argument
3872 : REF variable_reference
3874 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3875 lbag.AddLocation ($$, GetLocation ($1));
3877 | OUT variable_reference
3879 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3880 lbag.AddLocation ($$, GetLocation ($1));
3882 | OUT out_variable_declaration
3884 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3886 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3888 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3889 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3891 | ARGLIST OPEN_PARENS CLOSE_PARENS
3893 $$ = new Argument (new Arglist (GetLocation ($1)));
3894 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3898 out_variable_declaration
3899 : variable_type identifier_inside_body
3901 if (lang_version < LanguageVersion.V_7)
3902 FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
3904 var lt = (LocatedToken) $2;
3905 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3906 current_block.AddLocalName (lv);
3907 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3916 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3918 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3919 lbag.AddLocation ($$, GetLocation ($4));
3921 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3923 if (lang_version < LanguageVersion.V_6)
3924 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3926 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3927 ConditionalAccess = true
3930 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3932 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3934 Error_SyntaxError (yyToken);
3935 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3937 | primary_expression OPEN_BRACKET_EXPR error
3939 Error_SyntaxError (yyToken);
3940 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3945 : expression_or_error
3947 var list = new List<Expression> (4);
3948 list.Add ((Expression) $1);
3951 | expression_list COMMA expression_or_error
3953 var list = (List<Expression>) $1;
3954 list.Add ((Expression) $3);
3959 expression_list_arguments
3960 : expression_list_argument
3962 Arguments args = new Arguments (4);
3963 args.Add ((Argument) $1);
3966 | expression_list_arguments COMMA expression_list_argument
3968 Arguments args = (Arguments) $1;
3969 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3970 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3972 args.Add ((Argument) $3);
3977 expression_list_argument
3980 $$ = new Argument ((Expression) $1);
3988 $$ = new This (GetLocation ($1));
3993 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3995 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3996 lbag.AddLocation ($$, GetLocation ($4));
3998 | BASE OPEN_BRACKET error
4000 Error_SyntaxError (yyToken);
4001 $$ = new ElementAccess (null, null, GetLocation ($2));
4005 post_increment_expression
4006 : primary_expression OP_INC
4008 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
4012 post_decrement_expression
4013 : primary_expression OP_DEC
4015 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
4019 object_or_delegate_creation_expression
4020 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
4023 if (lang_version <= LanguageVersion.ISO_2)
4024 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
4026 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
4028 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
4031 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4033 | NEW new_expr_type object_or_collection_initializer
4035 if (lang_version <= LanguageVersion.ISO_2)
4036 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
4038 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
4042 array_creation_expression
4043 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
4045 opt_array_initializer
4047 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
4048 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
4049 Next = (ComposedTypeSpecifier) $6
4050 }, (ArrayInitializer) $7, GetLocation ($1)) {
4051 NoEmptyInterpolation = true
4054 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4056 | NEW new_expr_type rank_specifiers opt_array_initializer
4059 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
4061 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
4062 NoEmptyInterpolation = true
4065 | NEW rank_specifier array_initializer
4067 if (lang_version <= LanguageVersion.ISO_2)
4068 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
4070 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
4072 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
4074 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
4075 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
4077 | NEW new_expr_type error
4079 Error_SyntaxError (yyToken);
4080 // It can be any of new expression, create the most common one
4081 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
4087 ++lexer.parsing_type;
4091 --lexer.parsing_type;
4096 anonymous_type_expression
4097 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
4099 if (lang_version <= LanguageVersion.ISO_2)
4100 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
4102 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
4104 // TODO: lbag comma location
4105 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4107 | NEW OPEN_BRACE GENERATE_COMPLETION
4109 $$ = new EmptyCompletion ();
4113 anonymous_type_parameters_opt_comma
4114 : anonymous_type_parameters_opt
4115 | anonymous_type_parameters COMMA
4118 anonymous_type_parameters_opt
4120 | anonymous_type_parameters
4123 anonymous_type_parameters
4124 : anonymous_type_parameter
4126 var a = new List<AnonymousTypeParameter> (4);
4127 a.Add ((AnonymousTypeParameter) $1);
4130 | anonymous_type_parameters COMMA anonymous_type_parameter
4132 var a = (List<AnonymousTypeParameter>) $1;
4133 a.Add ((AnonymousTypeParameter) $3);
4136 | COMPLETE_COMPLETION
4138 $$ = new EmptyCompletion ();
4140 | anonymous_type_parameter COMPLETE_COMPLETION
4146 anonymous_type_parameter
4147 : identifier_inside_body ASSIGN variable_initializer
4149 var lt = (LocatedToken)$1;
4150 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4151 lbag.AddLocation ($$, GetLocation ($2));
4153 | identifier_inside_body
4155 var lt = (LocatedToken)$1;
4156 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4157 lt.Value, lt.Location);
4161 MemberAccess ma = (MemberAccess) $1;
4162 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4166 report.Error (746, lexer.Location,
4167 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4179 | rank_specifier rank_specifiers
4181 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4187 : OPEN_BRACKET CLOSE_BRACKET
4189 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4190 lbag.AddLocation ($$, GetLocation ($2));
4192 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4194 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4195 lbag.AddLocation ($$, GetLocation ($3));
4204 | dim_separators COMMA
4206 $$ = ((int) $1) + 1;
4210 opt_array_initializer
4222 : OPEN_BRACE CLOSE_BRACE
4224 var ai = new ArrayInitializer (0, GetLocation ($1));
4225 ai.VariableDeclaration = current_variable;
4226 lbag.AddLocation (ai, GetLocation ($2));
4229 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4231 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4232 ai.VariableDeclaration = current_variable;
4234 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4236 lbag.AddLocation (ai, GetLocation ($4));
4242 variable_initializer_list
4243 : variable_initializer
4245 var list = new List<Expression> (4);
4246 list.Add ((Expression) $1);
4249 | variable_initializer_list COMMA variable_initializer
4251 var list = (List<Expression>) $1;
4252 list.Add ((Expression) $3);
4258 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4260 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4261 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4265 typeof_type_expression
4269 Error_TypeExpected (lexer.Location);
4277 if (lang_version < LanguageVersion.ISO_2)
4278 FeatureIsNotAvailable (GetLocation ($1), "generics");
4284 qualified_alias_member
4285 : IDENTIFIER DOUBLE_COLON
4287 var lt = (LocatedToken) $1;
4288 if (lang_version == LanguageVersion.ISO_1)
4289 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4296 : SIZEOF open_parens_any type CLOSE_PARENS
4298 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4299 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4301 | SIZEOF open_parens_any type error
4303 Error_SyntaxError (yyToken);
4305 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4306 lbag.AddLocation ($$, GetLocation ($2));
4311 : CHECKED open_parens_any expression CLOSE_PARENS
4313 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4314 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4318 Error_SyntaxError (yyToken);
4320 $$ = new CheckedExpr (null, GetLocation ($1));
4324 unchecked_expression
4325 : UNCHECKED open_parens_any expression CLOSE_PARENS
4327 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4328 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4332 Error_SyntaxError (yyToken);
4334 $$ = new UnCheckedExpr (null, GetLocation ($1));
4338 pointer_member_access
4339 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4341 var lt = (LocatedToken) $3;
4342 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4346 anonymous_method_expression
4347 : DELEGATE opt_anonymous_method_signature
4349 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4353 $$ = end_anonymous ((ParametersBlock) $4);
4355 | ASYNC DELEGATE opt_anonymous_method_signature
4357 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4361 $$ = end_anonymous ((ParametersBlock) $5);
4365 opt_anonymous_method_signature
4368 $$ = ParametersCompiled.Undefined;
4370 | anonymous_method_signature
4373 anonymous_method_signature
4376 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4378 opt_formal_parameter_list CLOSE_PARENS
4380 valid_param_mod = 0;
4385 default_value_expression
4386 : DEFAULT open_parens_any type CLOSE_PARENS
4388 if (lang_version < LanguageVersion.ISO_2)
4389 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4391 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4392 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4397 : primary_expression
4398 | BANG prefixed_unary_expression
4400 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4402 | TILDE prefixed_unary_expression
4404 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4406 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4408 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4409 lbag.AddLocation ($$, GetLocation ($3));
4411 | AWAIT prefixed_unary_expression
4414 if (current_anonymous_method is LambdaExpression) {
4415 report.Error (4034, GetLocation ($1),
4416 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4417 } else if (current_anonymous_method != null) {
4418 report.Error (4035, GetLocation ($1),
4419 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4420 } else if (interactive_async != null) {
4421 current_block.Explicit.RegisterAsyncAwait ();
4422 interactive_async = true;
4424 report.Error (4033, GetLocation ($1),
4425 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4428 current_block.Explicit.RegisterAsyncAwait ();
4431 $$ = new Await ((Expression) $2, GetLocation ($1));
4433 | THROW_EXPR prefixed_unary_expression
4435 if (lang_version < LanguageVersion.V_7)
4436 FeatureIsNotAvailable (lexer.Location, "throw expression");
4438 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4442 Error_SyntaxError (yyToken);
4444 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4448 Error_SyntaxError (yyToken);
4450 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4452 | OPEN_PARENS_CAST type CLOSE_PARENS error
4454 Error_SyntaxError (yyToken);
4456 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4457 lbag.AddLocation ($$, GetLocation ($3));
4461 Error_SyntaxError (yyToken);
4463 $$ = new Await (null, GetLocation ($1));
4468 // The idea to split this out is from Rhys' grammar
4469 // to solve the problem with casts.
4471 prefixed_unary_expression
4473 | PLUS prefixed_unary_expression
4475 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4477 | MINUS prefixed_unary_expression
4479 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4481 | OP_INC prefixed_unary_expression
4483 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4485 | OP_DEC prefixed_unary_expression
4487 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4489 | STAR prefixed_unary_expression
4491 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4493 | BITWISE_AND prefixed_unary_expression
4495 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4499 Error_SyntaxError (yyToken);
4501 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4505 Error_SyntaxError (yyToken);
4507 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4511 Error_SyntaxError (yyToken);
4513 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4517 Error_SyntaxError (yyToken);
4519 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4523 Error_SyntaxError (yyToken);
4525 $$ = new Indirection (null, GetLocation ($1));
4529 Error_SyntaxError (yyToken);
4531 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4534 multiplicative_expression
4535 : prefixed_unary_expression
4536 | multiplicative_expression STAR prefixed_unary_expression
4538 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4539 lbag.AddLocation ($$, GetLocation ($2));
4541 | multiplicative_expression DIV prefixed_unary_expression
4543 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4544 lbag.AddLocation ($$, GetLocation ($2));
4546 | multiplicative_expression PERCENT prefixed_unary_expression
4548 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4549 lbag.AddLocation ($$, GetLocation ($2));
4551 | multiplicative_expression STAR error
4553 Error_SyntaxError (yyToken);
4555 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4556 lbag.AddLocation ($$, GetLocation ($2));
4558 | multiplicative_expression DIV error
4560 Error_SyntaxError (yyToken);
4562 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4563 lbag.AddLocation ($$, GetLocation ($2));
4565 | multiplicative_expression PERCENT error
4567 Error_SyntaxError (yyToken);
4569 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4570 lbag.AddLocation ($$, GetLocation ($2));
4575 : multiplicative_expression
4576 | additive_expression PLUS multiplicative_expression
4578 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4579 lbag.AddLocation ($$, GetLocation ($2));
4581 | additive_expression MINUS multiplicative_expression
4583 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4584 lbag.AddLocation ($$, GetLocation ($2));
4586 | additive_expression PLUS error
4588 Error_SyntaxError (yyToken);
4590 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4591 lbag.AddLocation ($$, GetLocation ($2));
4593 | additive_expression MINUS error
4595 Error_SyntaxError (yyToken);
4597 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4598 lbag.AddLocation ($$, GetLocation ($2));
4600 | additive_expression AS type
4602 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4604 | additive_expression IS pattern_type_expr opt_identifier
4606 var is_expr = new Is ((Expression) $1, ((FullNamedExpression) $3), GetLocation ($2));
4608 if (lang_version < LanguageVersion.V_7)
4609 FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
4611 var lt = (LocatedToken) $4;
4612 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
4613 is_expr.Variable = lv;
4614 current_block.AddLocalName (lv);
4619 | additive_expression IS pattern_expr
4621 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4622 if (lang_version != LanguageVersion.Experimental)
4623 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4627 | additive_expression AS error
4629 Error_SyntaxError (yyToken);
4631 $$ = new As ((Expression) $1, null, GetLocation ($2));
4633 | additive_expression IS error
4635 Error_SyntaxError (yyToken);
4637 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4641 var lt = (LocatedToken) $1;
4642 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4646 var lt = (LocatedToken) $1;
4647 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4657 | PLUS prefixed_unary_expression
4659 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4661 | MINUS prefixed_unary_expression
4663 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4666 | default_value_expression
4667 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4669 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4670 lbag.AddLocation ($$, GetLocation ($3));
4674 $$ = new WildcardPattern (GetLocation ($1));
4676 /* | pattern_expr_invocation */
4681 pattern_expr_invocation
4682 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4684 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4690 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4692 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4696 pattern_property_list
4697 : pattern_property_entry
4699 var list = new List<PropertyPatternMember> ();
4700 list.Add ((PropertyPatternMember) $1);
4703 | pattern_property_list COMMA pattern_property_entry
4705 var list = (List<PropertyPatternMember>) $1;
4706 list.Add ((PropertyPatternMember) $3);
4711 pattern_property_entry
4712 : identifier_inside_body IS pattern
4714 var lt = (LocatedToken) $1;
4715 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4721 | pattern_type_expr opt_identifier
4724 var lt = (LocatedToken) $2;
4725 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4726 current_block.AddLocalName (variable);
4735 $$ = new Arguments (0);
4743 Arguments args = new Arguments (4);
4744 args.Add ((Argument) $1);
4747 | pattern_list COMMA pattern_argument
4749 Arguments args = (Arguments) $1;
4750 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4751 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4753 args.Add ((Argument) $3);
4762 $$ = new Argument ((Expression) $1);
4764 | IDENTIFIER COLON pattern
4766 var lt = (LocatedToken) $1;
4767 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4773 : additive_expression
4774 | shift_expression OP_SHIFT_LEFT additive_expression
4776 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4777 lbag.AddLocation ($$, GetLocation ($2));
4779 | shift_expression OP_SHIFT_RIGHT additive_expression
4781 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4782 lbag.AddLocation ($$, GetLocation ($2));
4784 | shift_expression OP_SHIFT_LEFT error
4786 Error_SyntaxError (yyToken);
4788 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4789 lbag.AddLocation ($$, GetLocation ($2));
4791 | shift_expression OP_SHIFT_RIGHT error
4793 Error_SyntaxError (yyToken);
4795 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4796 lbag.AddLocation ($$, GetLocation ($2));
4800 relational_expression
4802 | relational_expression OP_LT shift_expression
4804 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4805 lbag.AddLocation ($$, GetLocation ($2));
4807 | relational_expression OP_GT shift_expression
4809 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4810 lbag.AddLocation ($$, GetLocation ($2));
4812 | relational_expression OP_LE shift_expression
4814 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4815 lbag.AddLocation ($$, GetLocation ($2));
4817 | relational_expression OP_GE shift_expression
4819 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4820 lbag.AddLocation ($$, GetLocation ($2));
4822 | relational_expression OP_LT error
4824 Error_SyntaxError (yyToken);
4826 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4827 lbag.AddLocation ($$, GetLocation ($2));
4829 | relational_expression OP_GT error
4831 Error_SyntaxError (yyToken);
4833 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4834 lbag.AddLocation ($$, GetLocation ($2));
4836 | relational_expression OP_LE error
4838 Error_SyntaxError (yyToken);
4840 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4841 lbag.AddLocation ($$, GetLocation ($2));
4843 | relational_expression OP_GE error
4845 Error_SyntaxError (yyToken);
4847 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4848 lbag.AddLocation ($$, GetLocation ($2));
4853 : relational_expression
4854 | equality_expression OP_EQ relational_expression
4856 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4857 lbag.AddLocation ($$, GetLocation ($2));
4859 | equality_expression OP_NE relational_expression
4861 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4862 lbag.AddLocation ($$, GetLocation ($2));
4864 | equality_expression OP_EQ error
4866 Error_SyntaxError (yyToken);
4868 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4869 lbag.AddLocation ($$, GetLocation ($2));
4871 | equality_expression OP_NE error
4873 Error_SyntaxError (yyToken);
4875 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4876 lbag.AddLocation ($$, GetLocation ($2));
4881 : equality_expression
4882 | and_expression BITWISE_AND equality_expression
4884 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4885 lbag.AddLocation ($$, GetLocation ($2));
4887 | and_expression BITWISE_AND error
4889 Error_SyntaxError (yyToken);
4891 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4892 lbag.AddLocation ($$, GetLocation ($2));
4896 exclusive_or_expression
4898 | exclusive_or_expression CARRET and_expression
4900 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4901 lbag.AddLocation ($$, GetLocation ($2));
4903 | exclusive_or_expression CARRET error
4905 Error_SyntaxError (yyToken);
4907 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4908 lbag.AddLocation ($$, GetLocation ($2));
4912 inclusive_or_expression
4913 : exclusive_or_expression
4914 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4916 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4917 lbag.AddLocation ($$, GetLocation ($2));
4919 | inclusive_or_expression BITWISE_OR error
4921 Error_SyntaxError (yyToken);
4923 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4924 lbag.AddLocation ($$, GetLocation ($2));
4928 conditional_and_expression
4929 : inclusive_or_expression
4930 | conditional_and_expression OP_AND inclusive_or_expression
4932 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4933 lbag.AddLocation ($$, GetLocation ($2));
4935 | conditional_and_expression OP_AND error
4937 Error_SyntaxError (yyToken);
4939 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4940 lbag.AddLocation ($$, GetLocation ($2));
4944 conditional_or_expression
4945 : conditional_and_expression
4946 | conditional_or_expression OP_OR conditional_and_expression
4948 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4949 lbag.AddLocation ($$, GetLocation ($2));
4951 | conditional_or_expression OP_OR error
4953 Error_SyntaxError (yyToken);
4955 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4956 lbag.AddLocation ($$, GetLocation ($2));
4960 null_coalescing_expression
4961 : conditional_or_expression
4962 | conditional_or_expression OP_COALESCING null_coalescing_expression
4964 if (lang_version < LanguageVersion.ISO_2)
4965 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4967 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4968 lbag.AddLocation ($$, GetLocation ($2));
4972 conditional_expression
4973 : null_coalescing_expression
4974 | null_coalescing_expression INTERR expression COLON expression
4976 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4977 lbag.AddLocation ($$, GetLocation ($4));
4979 | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4981 if (lang_version < LanguageVersion.V_7)
4982 FeatureIsNotAvailable (lexer.Location, "throw expression");
4984 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4985 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4986 lbag.AddLocation ($$, GetLocation ($4));
4988 | null_coalescing_expression INTERR expression error
4990 Error_SyntaxError (yyToken);
4992 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4994 | null_coalescing_expression INTERR expression COLON error
4996 Error_SyntaxError (yyToken);
4998 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4999 lbag.AddLocation ($$, GetLocation ($4));
5001 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
5003 Error_SyntaxError (Token.CLOSE_BRACE);
5005 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
5006 lbag.AddLocation ($$, GetLocation ($4));
5007 lexer.putback ('}');
5011 assignment_expression
5012 : prefixed_unary_expression ASSIGN expression
5014 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
5015 lbag.AddLocation ($$, GetLocation ($2));
5017 | prefixed_unary_expression OP_MULT_ASSIGN expression
5019 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
5020 lbag.AddLocation ($$, GetLocation ($2));
5022 | prefixed_unary_expression OP_DIV_ASSIGN expression
5024 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
5025 lbag.AddLocation ($$, GetLocation ($2));
5027 | prefixed_unary_expression OP_MOD_ASSIGN expression
5029 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
5030 lbag.AddLocation ($$, GetLocation ($2));
5032 | prefixed_unary_expression OP_ADD_ASSIGN expression
5034 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
5035 lbag.AddLocation ($$, GetLocation ($2));
5037 | prefixed_unary_expression OP_SUB_ASSIGN expression
5039 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
5040 lbag.AddLocation ($$, GetLocation ($2));
5042 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
5044 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
5045 lbag.AddLocation ($$, GetLocation ($2));
5047 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
5049 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
5050 lbag.AddLocation ($$, GetLocation ($2));
5052 | prefixed_unary_expression OP_AND_ASSIGN expression
5054 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
5055 lbag.AddLocation ($$, GetLocation ($2));
5057 | prefixed_unary_expression OP_OR_ASSIGN expression
5059 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
5060 lbag.AddLocation ($$, GetLocation ($2));
5062 | prefixed_unary_expression OP_XOR_ASSIGN expression
5064 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
5065 lbag.AddLocation ($$, GetLocation ($2));
5067 | OPEN_PARENS_DECONSTRUCT deconstruct_exprs CLOSE_PARENS ASSIGN expression
5069 if (lang_version < LanguageVersion.V_7)
5070 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5072 var exprs = (List<Expression>) $2;
5073 $$ = new TupleDeconstruct (exprs, (Expression) $5, GetLocation ($4));
5078 : expression COMMA expression
5080 $$ = new List<Expression> () {
5085 | deconstruct_exprs COMMA expression
5087 var src = (List<Expression>) $1;
5088 src.Add ((Expression) $3);
5093 lambda_parameter_list
5096 var pars = new List<Parameter> (4);
5097 pars.Add ((Parameter) $1);
5101 | lambda_parameter_list COMMA lambda_parameter
5103 var pars = (List<Parameter>) $1;
5104 Parameter p = (Parameter)$3;
5105 if (pars[0].GetType () != p.GetType ()) {
5106 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
5115 : parameter_modifier parameter_type identifier_inside_body
5117 var lt = (LocatedToken) $3;
5119 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
5121 | parameter_type identifier_inside_body
5123 var lt = (LocatedToken) $2;
5125 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
5129 var lt = (LocatedToken) $1;
5130 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5134 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5135 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5139 opt_lambda_parameter_list
5140 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
5141 | lambda_parameter_list {
5142 var pars_list = (List<Parameter>) $1;
5143 $$ = new ParametersCompiled (pars_list.ToArray ());
5147 lambda_expression_body
5149 start_block (Location.Null);
5151 lambda_arrow_expression // All expressions must handle error or current block won't be restored and breaking ast completely
5153 Block b = end_block (Location.Null);
5154 b.IsCompilerGenerated = true;
5155 b.AddStatement (new ContextualReturn ((Expression) $2));
5161 // Handles only cases like foo = x.FirstOrDefault (l => );
5162 // where we must restore current_variable
5163 Block b = end_block (Location.Null);
5164 b.IsCompilerGenerated = true;
5166 Error_SyntaxError (yyToken);
5171 lambda_arrow_expression
5173 | reference_expression
5180 Error_SyntaxError (yyToken);
5188 var lt = (LocatedToken) $1;
5189 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5190 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5192 lambda_expression_body
5194 $$ = end_anonymous ((ParametersBlock) $4);
5195 lbag.AddLocation ($$, GetLocation ($2));
5199 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5200 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5201 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5203 lambda_expression_body
5205 $$ = end_anonymous ((ParametersBlock) $4);
5206 lbag.AddLocation ($$, GetLocation ($2));
5208 | ASYNC identifier_inside_body ARROW
5210 var lt = (LocatedToken) $2;
5211 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5212 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5214 lambda_expression_body
5216 $$ = end_anonymous ((ParametersBlock) $5);
5217 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5219 | OPEN_PARENS_LAMBDA
5221 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5223 opt_lambda_parameter_list CLOSE_PARENS ARROW
5225 valid_param_mod = 0;
5226 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5228 lambda_expression_body
5230 $$ = end_anonymous ((ParametersBlock) $7);
5231 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5233 | ASYNC OPEN_PARENS_LAMBDA
5235 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5237 opt_lambda_parameter_list CLOSE_PARENS ARROW
5239 valid_param_mod = 0;
5240 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5242 lambda_expression_body
5244 $$ = end_anonymous ((ParametersBlock) $8);
5245 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5250 : assignment_expression
5251 | non_assignment_expression
5254 non_assignment_expression
5255 : conditional_expression
5260 $$ = new ArglistAccess (GetLocation ($1));
5264 undocumented_expressions
5265 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5267 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5268 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5270 | REFTYPE open_parens_any expression CLOSE_PARENS
5272 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5273 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5275 | MAKEREF open_parens_any expression CLOSE_PARENS
5277 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5278 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5289 $$ = new BooleanExpression ((Expression) $1);
5293 opt_primary_parameters
5298 | primary_parameters
5302 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5306 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5307 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5309 if (lang_version != LanguageVersion.Experimental)
5310 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5314 opt_primary_parameters_with_class_base
5323 | primary_parameters
5327 | primary_parameters class_base
5331 | primary_parameters class_base OPEN_PARENS
5333 ++lexer.parsing_block;
5334 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5336 opt_argument_list CLOSE_PARENS
5338 lbag.AppendToMember (current_container, GetLocation ($6));
5339 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5340 --lexer.parsing_block;
5356 type_declaration_name
5358 lexer.ConstraintsParsing = true;
5360 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5361 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5362 FeatureIsNotAvailable (c.Location, "static classes");
5365 push_current_container (c, $3);
5366 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5368 opt_primary_parameters_with_class_base
5369 opt_type_parameter_constraints_clauses
5371 valid_param_mod = 0;
5372 lexer.ConstraintsParsing = false;
5375 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5378 current_container.SetConstraints ((List<Constraints>) $9);
5379 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5382 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5383 Lexer.doc_state = XmlCommentState.Allowed;
5386 lexer.parsing_modifiers = true;
5388 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5390 --lexer.parsing_declaration;
5392 Lexer.doc_state = XmlCommentState.Allowed;
5397 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5399 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5401 $$ = pop_current_class ();
5409 { $$ = $1; } // location
5415 mod_locations = null;
5417 lexer.parsing_modifiers = false;
5421 lexer.parsing_modifiers = false;
5427 | modifiers modifier
5429 var m1 = (Modifiers) $1;
5430 var m2 = (Modifiers) $2;
5432 if ((m1 & m2) != 0) {
5433 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5434 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5435 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5436 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5437 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5438 "More than one protection modifier specified");
5449 StoreModifierLocation ($$, GetLocation ($1));
5451 if (current_container.Kind == MemberKind.Namespace)
5452 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5456 $$ = Modifiers.PUBLIC;
5457 StoreModifierLocation ($$, GetLocation ($1));
5461 $$ = Modifiers.PROTECTED;
5462 StoreModifierLocation ($$, GetLocation ($1));
5466 $$ = Modifiers.INTERNAL;
5467 StoreModifierLocation ($$, GetLocation ($1));
5471 $$ = Modifiers.PRIVATE;
5472 StoreModifierLocation ($$, GetLocation ($1));
5476 $$ = Modifiers.ABSTRACT;
5477 StoreModifierLocation ($$, GetLocation ($1));
5481 $$ = Modifiers.SEALED;
5482 StoreModifierLocation ($$, GetLocation ($1));
5486 $$ = Modifiers.STATIC;
5487 StoreModifierLocation ($$, GetLocation ($1));
5491 $$ = Modifiers.READONLY;
5492 StoreModifierLocation ($$, GetLocation ($1));
5496 $$ = Modifiers.VIRTUAL;
5497 StoreModifierLocation ($$, GetLocation ($1));
5501 $$ = Modifiers.OVERRIDE;
5502 StoreModifierLocation ($$, GetLocation ($1));
5506 $$ = Modifiers.EXTERN;
5507 StoreModifierLocation ($$, GetLocation ($1));
5511 $$ = Modifiers.VOLATILE;
5512 StoreModifierLocation ($$, GetLocation ($1));
5516 $$ = Modifiers.UNSAFE;
5517 StoreModifierLocation ($$, GetLocation ($1));
5518 if (!settings.Unsafe)
5519 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5523 $$ = Modifiers.ASYNC;
5524 StoreModifierLocation ($$, GetLocation ($1));
5536 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5538 | COLON type_list error
5540 Error_SyntaxError (yyToken);
5542 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5546 opt_type_parameter_constraints_clauses
5548 | type_parameter_constraints_clauses
5554 type_parameter_constraints_clauses
5555 : type_parameter_constraints_clause
5557 var constraints = new List<Constraints> (1);
5558 constraints.Add ((Constraints) $1);
5561 | type_parameter_constraints_clauses type_parameter_constraints_clause
5563 var constraints = (List<Constraints>) $1;
5564 Constraints new_constraint = (Constraints)$2;
5566 foreach (Constraints c in constraints) {
5567 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5568 report.Error (409, new_constraint.Location,
5569 "A constraint clause has already been specified for type parameter `{0}'",
5570 new_constraint.TypeParameter.Value);
5574 constraints.Add (new_constraint);
5579 type_parameter_constraints_clause
5580 : WHERE IDENTIFIER COLON type_parameter_constraints
5582 var lt = (LocatedToken) $2;
5583 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5584 lbag.AddLocation ($$, GetLocation ($3));
5586 | WHERE IDENTIFIER error
5588 Error_SyntaxError (yyToken);
5590 var lt = (LocatedToken) $2;
5591 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5595 type_parameter_constraints
5596 : type_parameter_constraint
5598 var constraints = new List<FullNamedExpression> (1);
5599 constraints.Add ((FullNamedExpression) $1);
5602 | type_parameter_constraints COMMA type_parameter_constraint
5604 var constraints = (List<FullNamedExpression>) $1;
5605 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5606 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5607 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5610 prev = $3 as SpecialContraintExpr;
5612 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5613 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5615 prev = constraints [0] as SpecialContraintExpr;
5616 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5617 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5622 constraints.Add ((FullNamedExpression) $3);
5627 type_parameter_constraint
5630 if ($1 is ComposedCast)
5631 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5635 | NEW OPEN_PARENS CLOSE_PARENS
5637 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5638 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5642 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5646 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5650 opt_type_parameter_variance
5655 | type_parameter_variance
5657 if (lang_version <= LanguageVersion.V_3)
5658 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5664 type_parameter_variance
5667 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5671 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5680 // A block is "contained" on the following places:
5682 // property_declaration as part of the accessor body (get/set)
5683 // operator_declaration
5684 // constructor_declaration
5685 // destructor_declaration
5686 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5691 ++lexer.parsing_block;
5692 start_block (GetLocation ($1));
5694 opt_statement_list block_end
5703 --lexer.parsing_block;
5704 $$ = end_block (GetLocation ($1));
5706 | COMPLETE_COMPLETION
5708 --lexer.parsing_block;
5709 $$ = end_block (lexer.Location);
5717 ++lexer.parsing_block;
5718 current_block.StartLocation = GetLocation ($1);
5720 opt_statement_list CLOSE_BRACE
5722 --lexer.parsing_block;
5723 $$ = end_block (GetLocation ($4));
5734 | statement_list statement
5738 : block_variable_declaration
5740 current_block.AddStatement ((Statement) $1);
5742 | valid_declaration_statement
5744 current_block.AddStatement ((Statement) $1);
5749 Error_SyntaxError (yyToken);
5755 // The interactive_statement and its derivatives are only
5756 // used to provide a special version of `expression_statement'
5757 // that has a side effect of assigning the expression to
5760 interactive_statement_list
5761 : interactive_statement
5762 | interactive_statement_list interactive_statement
5765 interactive_statement
5766 : block_variable_declaration
5768 current_block.AddStatement ((Statement) $1);
5770 | interactive_valid_declaration_statement
5772 current_block.AddStatement ((Statement) $1);
5777 valid_declaration_statement
5780 | expression_statement
5781 | selection_statement
5782 | iteration_statement
5786 | unchecked_statement
5793 interactive_valid_declaration_statement
5796 | interactive_expression_statement
5797 | selection_statement
5798 | iteration_statement
5802 | unchecked_statement
5810 : valid_declaration_statement
5811 | block_variable_declaration
5813 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5818 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5823 Error_SyntaxError (yyToken);
5824 $$ = new EmptyStatement (GetLocation ($1));
5831 // Uses lexer.Location because semicolon location is not kept in quick mode
5832 $$ = new EmptyStatement (lexer.Location);
5837 : identifier_inside_body COLON
5839 var lt = (LocatedToken) $1;
5840 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5841 lbag.AddLocation (labeled, GetLocation ($2));
5842 current_block.AddLabel (labeled);
5843 current_block.AddStatement (labeled);
5849 : variable_type_simple
5850 | variable_type_simple rank_specifiers
5853 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5855 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5860 * The following is from Rhys' grammar:
5861 * > Types in local variable declarations must be recognized as
5862 * > expressions to prevent reduce/reduce errors in the grammar.
5863 * > The expressions are converted into types during semantic analysis.
5865 variable_type_simple
5866 : type_name_expression opt_nullable
5868 var expr = (ATypeNameExpression) $1;
5870 if (expr.Name == "var" && expr is SimpleName)
5871 $$ = new VarExpr (expr.Location);
5875 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5878 | type_name_expression pointer_stars
5880 var expr = (ATypeNameExpression) $1;
5881 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5883 | builtin_type_expression
5884 | tuple_type opt_nullable
5889 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5895 : OPEN_PARENS tuple_type_elements CLOSE_PARENS
5897 if (lang_version < LanguageVersion.V_7)
5898 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5900 var a = (Tuple<TypeArguments, List<string>>) $2;
5902 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
5907 : variable_type IDENTIFIER /* opt_identifier */ COMMA variable_type IDENTIFIER /* opt_identifier */
5909 var type_args = new TypeArguments ();
5911 type_args.Add ((FullNamedExpression) $1);
5912 type_args.Add ((FullNamedExpression) $4);
5914 var names = new List<string> (2);
5915 var lt = (LocatedToken) $2;
5916 names.Add (lt?.Value);
5917 lt = (LocatedToken) $5;
5918 names.Add (lt?.Value);
5920 $$ = Tuple.Create (type_args, names);
5922 | tuple_type_elements COMMA variable_type IDENTIFIER /* opt_identifier */
5924 var a = (Tuple<TypeArguments, List<string>>) $1;
5925 a.Item1.Add ((FullNamedExpression) $3);
5926 var lt = (LocatedToken) $4;
5927 a.Item2.Add (lt?.Value);
5934 | pointer_star pointer_stars
5936 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5944 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5948 identifier_inside_body
5952 $$ = Error_AwaitAsIdentifier ($1);
5956 block_variable_declaration
5957 : variable_type identifier_inside_body
5959 var lt = (LocatedToken) $2;
5960 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5961 current_block.AddLocalName (li);
5962 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5964 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5966 $$ = current_variable;
5967 current_variable = null;
5969 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5971 lbag.AddLocation ($$, GetLocation ($6));
5973 | CONST variable_type identifier_inside_body
5975 var lt = (LocatedToken) $3;
5976 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5977 current_block.AddLocalName (li);
5978 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5980 const_variable_initializer opt_const_declarators SEMICOLON
5982 $$ = current_variable;
5983 current_variable = null;
5984 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5986 | REF variable_type identifier_inside_body
5988 if (lang_version < LanguageVersion.V_7) {
5989 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
5992 var lt = (LocatedToken) $3;
5993 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ByRef, lt.Location);
5994 current_block.AddLocalName (li);
5995 current_variable = new BlockVariable ((FullNamedExpression) $2, li);
5997 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5999 $$ = current_variable;
6000 current_variable = null;
6002 lbag.AddLocation ($$, PopLocation (), GetLocation ($7));
6004 report.Error (8174, GetLocation ($3), "A declaration of a by-reference variable must have an initializer");
6005 lbag.AddLocation ($$, GetLocation ($7));
6010 opt_local_variable_initializer
6012 | ASSIGN block_variable_initializer
6014 current_variable.Initializer = (Expression) $2;
6015 PushLocation (GetLocation ($1));
6016 $$ = current_variable;
6020 if (yyToken == Token.OPEN_BRACKET_EXPR) {
6021 report.Error (650, lexer.Location,
6022 "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");
6024 Error_SyntaxError (yyToken);
6029 opt_variable_declarators
6031 | variable_declarators
6034 opt_using_or_fixed_variable_declarators
6036 | variable_declarators
6038 foreach (var d in current_variable.Declarators) {
6039 if (d.Initializer == null)
6040 Error_MissingInitializer (d.Variable.Location);
6045 variable_declarators
6046 : variable_declarator
6047 | variable_declarators variable_declarator
6051 : COMMA identifier_inside_body
6053 var lt = (LocatedToken) $2;
6054 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
6055 var d = new BlockVariableDeclarator (li, null);
6056 current_variable.AddDeclarator (d);
6057 current_block.AddLocalName (li);
6058 lbag.AddLocation (d, GetLocation ($1));
6060 | COMMA identifier_inside_body ASSIGN block_variable_initializer
6062 var lt = (LocatedToken) $2;
6063 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
6064 var d = new BlockVariableDeclarator (li, (Expression) $4);
6065 current_variable.AddDeclarator (d);
6066 current_block.AddLocalName (li);
6067 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6071 const_variable_initializer
6074 report.Error (145, lexer.Location, "A const field requires a value to be provided");
6076 | ASSIGN constant_initializer_expr
6078 current_variable.Initializer = (Expression) $2;
6082 opt_const_declarators
6089 | const_declarators const_declarator
6093 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
6095 var lt = (LocatedToken) $2;
6096 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
6097 var d = new BlockVariableDeclarator (li, (Expression) $4);
6098 current_variable.AddDeclarator (d);
6099 current_block.AddLocalName (li);
6100 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6104 block_variable_initializer
6105 : variable_initializer
6106 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
6108 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
6109 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6111 | STACKALLOC simple_type
6113 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
6114 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
6116 | reference_expression
6119 reference_expression
6122 if (lang_version < LanguageVersion.V_7) {
6123 FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
6126 $$ = new ReferenceExpression ((Expression) $2, GetLocation ($1));
6130 expression_statement
6131 : statement_expression SEMICOLON
6134 lbag.AddStatement ($$, GetLocation ($2));
6136 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
6137 | statement_expression CLOSE_BRACE
6140 report.Error (1002, GetLocation ($2), "; expected");
6141 lexer.putback ('}');
6145 interactive_expression_statement
6146 : interactive_statement_expression SEMICOLON { $$ = $1; }
6147 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
6151 // We have to do the wrapping here and not in the case above,
6152 // because statement_expression is used for example in for_statement
6154 statement_expression
6157 ExpressionStatement s = $1 as ExpressionStatement;
6159 var expr = $1 as Expression;
6160 $$ = new StatementErrorExpression (expr);
6162 $$ = new StatementExpression (s);
6167 interactive_statement_expression
6170 Expression expr = (Expression) $1;
6171 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
6175 Error_SyntaxError (yyToken);
6176 $$ = new EmptyStatement (GetLocation ($1));
6186 : IF open_parens_any boolean_expression CLOSE_PARENS
6189 if ($5 is EmptyStatement)
6190 Warning_EmptyStatement (GetLocation ($5));
6192 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6193 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6195 | IF open_parens_any boolean_expression CLOSE_PARENS
6196 embedded_statement ELSE embedded_statement
6198 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
6199 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
6201 if ($5 is EmptyStatement)
6202 Warning_EmptyStatement (GetLocation ($5));
6203 if ($7 is EmptyStatement)
6204 Warning_EmptyStatement (GetLocation ($7));
6206 | IF open_parens_any boolean_expression error
6208 Error_SyntaxError (yyToken);
6210 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
6211 lbag.AddStatement ($$, GetLocation ($2));
6216 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
6218 start_block (GetLocation ($5));
6220 opt_switch_sections CLOSE_BRACE
6222 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
6223 end_block (GetLocation ($8));
6224 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6226 | SWITCH open_parens_any expression error
6228 Error_SyntaxError (yyToken);
6230 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
6231 lbag.AddStatement ($$, GetLocation ($2));
6238 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6245 | switch_sections switch_section
6248 Error_SyntaxError (yyToken);
6253 : switch_labels statement_list
6259 var label = (SwitchLabel) $1;
6260 label.SectionStart = true;
6261 current_block.AddStatement (label);
6263 | switch_labels switch_label
6265 current_block.AddStatement ((Statement) $2);
6270 : CASE constant_expression COLON
6272 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6273 lbag.AddLocation ($$, GetLocation ($3));
6275 | CASE constant_expression error
6277 Error_SyntaxError (yyToken);
6278 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6281 | CASE pattern_expr_invocation COLON
6283 if (lang_version != LanguageVersion.Experimental)
6284 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6286 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6287 PatternMatching = true
6289 lbag.AddLocation ($$, GetLocation ($3));
6293 | CASE pattern_type_expr IDENTIFIER COLON
6295 if (lang_version < LanguageVersion.V_7)
6296 FeatureIsNotAvailable (GetLocation ($1), "pattern matching");
6298 // $$ = new SwitchLabel ((FullNamedExpression) $2), GetLocation ($1)) {
6299 // PatternMatching = true
6302 throw new NotImplementedException ("type pattern matching");
6306 $$ = new SwitchLabel (null, GetLocation ($1));
6318 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6320 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6321 Warning_EmptyStatement (GetLocation ($5));
6323 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6324 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6326 | WHILE open_parens_any boolean_expression error
6328 Error_SyntaxError (yyToken);
6330 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6331 lbag.AddStatement ($$, GetLocation ($2));
6336 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6338 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6339 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6341 | DO embedded_statement error
6343 Error_SyntaxError (yyToken);
6344 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6346 | DO embedded_statement WHILE open_parens_any boolean_expression error
6348 Error_SyntaxError (yyToken);
6350 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6351 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6356 : FOR open_parens_any
6358 start_block (GetLocation ($2));
6359 current_block.IsCompilerGenerated = true;
6360 For f = new For (GetLocation ($1));
6361 current_block.AddStatement (f);
6370 // Has to use be extra rule to recover started block
6372 : opt_for_initializer SEMICOLON
6374 ((For) $0).Initializer = (Statement) $1;
6376 // Pass the "For" object to the iterator_part4
6377 oob_stack.Push ($0);
6379 for_condition_and_iterator_part
6382 var locations = (Tuple<Location,Location>) $4;
6384 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6385 Warning_EmptyStatement (GetLocation ($5));
6388 f.Statement = (Statement) $5;
6389 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6391 $$ = end_block (GetLocation ($2));
6395 Error_SyntaxError (yyToken);
6396 $$ = end_block (current_block.StartLocation);
6400 for_condition_and_iterator_part
6401 : opt_for_condition SEMICOLON
6403 For f = (For) oob_stack.Peek ();
6404 f.Condition = (BooleanExpression) $1;
6407 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6410 // Handle errors in the case of opt_for_condition being followed by
6411 // a close parenthesis
6412 | opt_for_condition close_parens_close_brace {
6413 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6414 For f = (For) oob_stack.Peek ();
6415 f.Condition = (BooleanExpression) $1;
6416 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6421 : opt_for_iterator CLOSE_PARENS {
6422 For f = (For) oob_stack.Peek ();
6423 f.Iterator = (Statement) $1;
6424 $$ = GetLocation ($2);
6426 | opt_for_iterator CLOSE_BRACE {
6427 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6428 For f = (For) oob_stack.Peek ();
6429 f.Iterator = (Statement) $1;
6430 $$ = GetLocation ($2);
6434 close_parens_close_brace
6436 | CLOSE_BRACE { lexer.putback ('}'); }
6440 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6445 : variable_type identifier_inside_body
6447 var lt = (LocatedToken) $2;
6448 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6449 current_block.AddLocalName (li);
6450 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6452 opt_local_variable_initializer opt_variable_declarators
6454 $$ = current_variable;
6456 lbag.AddLocation (current_variable, PopLocation ());
6458 current_variable = null;
6460 | statement_expression_list
6464 : /* empty */ { $$ = null; }
6465 | boolean_expression
6469 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6474 : statement_expression_list
6477 statement_expression_list
6478 : statement_expression
6479 | statement_expression_list COMMA statement_expression
6481 var sl = $1 as StatementList;
6483 sl = new StatementList ((Statement) $1, (Statement) $3);
6484 lbag.AddStatement (sl, GetLocation ($2));
6486 sl.Add ((Statement) $3);
6487 lbag.AppendTo (sl, GetLocation ($2));
6495 : FOREACH open_parens_any type error
6497 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6499 start_block (GetLocation ($2));
6500 current_block.IsCompilerGenerated = true;
6502 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6503 current_block.AddStatement (f);
6505 lbag.AddStatement (f, GetLocation ($2));
6506 $$ = end_block (GetLocation ($4));
6508 | FOREACH open_parens_any type identifier_inside_body error
6510 Error_SyntaxError (yyToken);
6512 start_block (GetLocation ($2));
6513 current_block.IsCompilerGenerated = true;
6515 var lt = (LocatedToken) $4;
6516 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6517 current_block.AddLocalName (li);
6519 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6520 current_block.AddStatement (f);
6522 lbag.AddStatement (f, GetLocation ($2));
6523 $$ = end_block (GetLocation ($5));
6525 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6527 start_block (GetLocation ($2));
6528 current_block.IsCompilerGenerated = true;
6530 var lt = (LocatedToken) $4;
6531 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6532 current_block.AddLocalName (li);
6537 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6538 Warning_EmptyStatement (GetLocation ($9));
6540 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6541 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6542 end_block (GetLocation ($7));
6550 | continue_statement
6560 $$ = new Break (GetLocation ($1));
6561 lbag.AddStatement ($$, GetLocation ($2));
6566 : CONTINUE SEMICOLON
6568 $$ = new Continue (GetLocation ($1));
6569 lbag.AddStatement ($$, GetLocation ($2));
6573 Error_SyntaxError (yyToken);
6574 $$ = new Continue (GetLocation ($1));
6579 : GOTO identifier_inside_body SEMICOLON
6581 var lt = (LocatedToken) $2;
6582 $$ = new Goto (lt.Value, GetLocation ($1));
6583 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6585 | GOTO CASE constant_expression SEMICOLON
6587 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6588 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6590 | GOTO DEFAULT SEMICOLON
6592 $$ = new GotoDefault (GetLocation ($1));
6593 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6598 : RETURN opt_expression SEMICOLON
6600 $$ = new Return ((Expression) $2, GetLocation ($1));
6601 lbag.AddStatement ($$, GetLocation ($3));
6603 | RETURN reference_expression SEMICOLON
6605 $$ = new Return ((Expression) $2, GetLocation ($1));
6606 lbag.AddStatement ($$, GetLocation ($3));
6608 | RETURN expression error
6610 Error_SyntaxError (yyToken);
6611 $$ = new Return ((Expression) $2, GetLocation ($1));
6615 Error_SyntaxError (yyToken);
6616 $$ = new Return (null, GetLocation ($1));
6621 : THROW expression SEMICOLON
6623 $$ = new Throw ((Expression) $2, GetLocation ($1));
6624 lbag.AddStatement ($$, GetLocation ($3));
6628 $$ = new Throw (null, GetLocation ($1));
6629 lbag.AddStatement ($$, GetLocation ($2));
6631 | THROW expression error
6633 Error_SyntaxError (yyToken);
6634 $$ = new Throw ((Expression) $2, GetLocation ($1));
6638 Error_SyntaxError (yyToken);
6639 $$ = new Throw (null, GetLocation ($1));
6644 : identifier_inside_body RETURN opt_expression SEMICOLON
6646 var lt = (LocatedToken) $1;
6647 string s = lt.Value;
6649 report.Error (1003, lt.Location, "; expected");
6650 } else if ($3 == null) {
6651 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6652 } else if (lang_version == LanguageVersion.ISO_1){
6653 FeatureIsNotAvailable (lt.Location, "iterators");
6656 current_block.Explicit.RegisterIteratorYield ();
6657 $$ = new Yield ((Expression) $3, lt.Location);
6658 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6660 | identifier_inside_body RETURN expression error
6662 Error_SyntaxError (yyToken);
6664 var lt = (LocatedToken) $1;
6665 string s = lt.Value;
6667 report.Error (1003, lt.Location, "; expected");
6668 } else if ($3 == null) {
6669 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6670 } else if (lang_version == LanguageVersion.ISO_1){
6671 FeatureIsNotAvailable (lt.Location, "iterators");
6674 current_block.Explicit.RegisterIteratorYield ();
6675 $$ = new Yield ((Expression) $3, lt.Location);
6676 lbag.AddStatement ($$, GetLocation ($2));
6678 | identifier_inside_body BREAK SEMICOLON
6680 var lt = (LocatedToken) $1;
6681 string s = lt.Value;
6683 report.Error (1003, lt.Location, "; expected");
6684 } else if (lang_version == LanguageVersion.ISO_1){
6685 FeatureIsNotAvailable (lt.Location, "iterators");
6688 current_block.ParametersBlock.TopBlock.IsIterator = true;
6689 $$ = new YieldBreak (lt.Location);
6690 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6700 : TRY block catch_clauses
6702 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6704 | TRY block FINALLY block
6706 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6707 lbag.AddStatement ($$, GetLocation ($3));
6709 | TRY block catch_clauses FINALLY block
6711 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6712 lbag.AddStatement ($$, GetLocation ($4));
6716 Error_SyntaxError (1524, yyToken);
6717 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6724 var l = new List<Catch> (2);
6729 | catch_clauses catch_clause
6731 var l = (List<Catch>) $1;
6733 Catch c = (Catch) $2;
6734 var prev_catch = l [l.Count - 1];
6735 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6736 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6746 | identifier_inside_body
6750 : CATCH opt_catch_filter block
6752 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6753 c.Filter = (CatchFilterExpression) $2;
6756 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6758 start_block (GetLocation ($2));
6759 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6760 c.TypeExpression = (FullNamedExpression) $3;
6763 var lt = (LocatedToken) $4;
6764 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6765 current_block.AddLocalName (c.Variable);
6768 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6770 lexer.parsing_catch_when = true;
6772 opt_catch_filter_or_error
6774 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6777 | CATCH open_parens_any error
6779 if (yyToken == Token.CLOSE_PARENS) {
6780 report.Error (1015, lexer.Location,
6781 "A type that derives from `System.Exception', `object', or `string' expected");
6783 Error_SyntaxError (yyToken);
6786 $$ = new Catch (null, GetLocation ($1));
6790 opt_catch_filter_or_error
6791 : opt_catch_filter block_prepared
6797 end_block (Location.Null);
6798 Error_SyntaxError (yyToken);
6805 lexer.parsing_catch_when = false;
6809 lexer.parsing_catch_when = false;
6811 open_parens_any expression CLOSE_PARENS
6813 if (lang_version <= LanguageVersion.V_5)
6814 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6816 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6817 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6824 $$ = new Checked ((Block) $2, GetLocation ($1));
6831 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6838 if (!settings.Unsafe)
6839 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6841 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6846 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6848 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6849 Warning_EmptyStatement (GetLocation ($5));
6851 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6852 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6854 | LOCK open_parens_any expression error
6856 Error_SyntaxError (yyToken);
6858 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6859 lbag.AddStatement ($$, GetLocation ($2));
6864 : FIXED open_parens_any variable_type identifier_inside_body
6866 start_block (GetLocation ($2));
6868 current_block.IsCompilerGenerated = true;
6869 var lt = (LocatedToken) $4;
6870 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6871 current_block.AddLocalName (li);
6872 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6874 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6876 $$ = current_variable;
6877 current_variable = null;
6881 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6882 Warning_EmptyStatement (GetLocation ($10));
6884 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6885 current_block.AddStatement (f);
6886 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6887 $$ = end_block (GetLocation ($8));
6892 : USING open_parens_any variable_type identifier_inside_body
6894 start_block (GetLocation ($2));
6896 current_block.IsCompilerGenerated = true;
6897 var lt = (LocatedToken) $4;
6898 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6899 current_block.AddLocalName (li);
6900 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6902 using_initialization CLOSE_PARENS
6904 $$ = current_variable;
6905 current_variable = null;
6909 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6910 Warning_EmptyStatement (GetLocation ($9));
6912 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6913 current_block.AddStatement (u);
6914 $$ = end_block (GetLocation ($7));
6916 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6918 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6919 Warning_EmptyStatement (GetLocation ($5));
6921 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6922 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6924 | USING open_parens_any expression error
6926 Error_SyntaxError (yyToken);
6928 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6929 lbag.AddStatement ($$, GetLocation ($2));
6933 using_initialization
6934 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6937 // It has to be here for the parent to safely restore artificial block
6938 Error_SyntaxError (yyToken);
6942 using_or_fixed_variable_initializer
6945 Error_MissingInitializer (lexer.Location);
6947 | ASSIGN variable_initializer
6949 current_variable.Initializer = (Expression) $2;
6950 $$ = current_variable;
6958 : first_from_clause query_body
6960 lexer.query_parsing = false;
6962 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6964 from.Tail.Next = (Linq.AQueryClause)$2;
6967 current_block.SetEndLocation (lexer.Location);
6968 current_block = current_block.Parent;
6970 | nested_from_clause query_body
6972 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6974 from.Tail.Next = (Linq.AQueryClause)$2;
6977 current_block.SetEndLocation (lexer.Location);
6978 current_block = current_block.Parent;
6981 // Bubble up COMPLETE_COMPLETION productions
6982 | first_from_clause COMPLETE_COMPLETION {
6983 lexer.query_parsing = false;
6986 current_block.SetEndLocation (lexer.Location);
6987 current_block = current_block.Parent;
6989 | nested_from_clause COMPLETE_COMPLETION {
6991 current_block.SetEndLocation (lexer.Location);
6992 current_block = current_block.Parent;
6997 : FROM_FIRST identifier_inside_body IN expression
6999 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7001 var lt = (LocatedToken) $2;
7002 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7003 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
7004 lbag.AddLocation (clause, GetLocation ($3));
7005 $$ = new Linq.QueryExpression (clause);
7007 | FROM_FIRST type identifier_inside_body IN expression
7009 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7011 var lt = (LocatedToken) $3;
7012 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7013 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
7014 IdentifierType = (FullNamedExpression)$2
7016 lbag.AddLocation (clause, GetLocation ($4));
7017 $$ = new Linq.QueryExpression (clause);
7022 : FROM identifier_inside_body IN expression
7024 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7026 var lt = (LocatedToken) $2;
7027 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7028 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
7029 lbag.AddLocation (clause, GetLocation ($3));
7030 $$ = new Linq.QueryExpression (clause);
7032 | FROM type identifier_inside_body IN expression
7034 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7036 var lt = (LocatedToken) $3;
7037 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7038 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
7039 IdentifierType = (FullNamedExpression)$2
7041 lbag.AddLocation (clause, GetLocation ($4));
7042 $$ = new Linq.QueryExpression (clause);
7047 : FROM identifier_inside_body IN
7049 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7053 var lt = (LocatedToken) $2;
7054 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7055 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
7057 current_block.SetEndLocation (lexer.Location);
7058 current_block = current_block.Parent;
7060 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7061 lbag.AddLocation ($$, GetLocation ($3));
7063 | FROM type identifier_inside_body IN
7065 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7069 var lt = (LocatedToken) $3;
7070 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7072 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
7073 IdentifierType = (FullNamedExpression)$2
7076 current_block.SetEndLocation (lexer.Location);
7077 current_block = current_block.Parent;
7079 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7081 lbag.AddLocation ($$, GetLocation ($4));
7086 : query_body_clauses select_or_group_clause opt_query_continuation
7088 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7091 head.Next = (Linq.AQueryClause)$3;
7094 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7095 clause.Tail.Next = head;
7101 | select_or_group_clause opt_query_continuation
7103 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7106 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7107 clause.Tail.Next = head;
7113 | query_body_clauses COMPLETE_COMPLETION
7114 | query_body_clauses error
7116 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
7121 Error_SyntaxError (yyToken);
7126 select_or_group_clause
7129 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7133 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7135 current_block.SetEndLocation (lexer.Location);
7136 current_block = current_block.Parent;
7140 if (linq_clause_blocks == null)
7141 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7143 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7144 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
7148 current_block.SetEndLocation (lexer.Location);
7149 current_block = current_block.Parent;
7151 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7155 var obj = (object[]) $5;
7157 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
7158 lbag.AddLocation ($$, (Location) obj[1]);
7160 current_block.SetEndLocation (lexer.Location);
7161 current_block = current_block.Parent;
7166 : BY expression_or_error
7168 $$ = new object[] { $2, GetLocation ($1) };
7172 Error_SyntaxError (yyToken);
7173 $$ = new object[2] { null, Location.Null };
7179 | query_body_clauses query_body_clause
7181 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
7195 : LET identifier_inside_body ASSIGN
7197 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7201 var lt = (LocatedToken) $2;
7202 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7203 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
7204 lbag.AddLocation ($$, GetLocation ($3));
7206 current_block.SetEndLocation (lexer.Location);
7207 current_block = current_block.Parent;
7209 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7216 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7220 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7222 current_block.SetEndLocation (lexer.Location);
7223 current_block = current_block.Parent;
7228 : JOIN identifier_inside_body IN
7230 if (linq_clause_blocks == null)
7231 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7233 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7234 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7236 expression_or_error ON
7238 current_block.SetEndLocation (lexer.Location);
7239 current_block = current_block.Parent;
7241 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7242 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7244 expression_or_error EQUALS
7246 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7247 current_block.SetEndLocation (lexer.Location);
7248 current_block = current_block.Parent;
7250 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7252 expression_or_error opt_join_into
7254 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7255 current_block.SetEndLocation (lexer.Location);
7257 var outer_selector = linq_clause_blocks.Pop ();
7258 var block = linq_clause_blocks.Pop ();
7260 var lt = (LocatedToken) $2;
7261 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7262 Linq.RangeVariable into;
7266 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7267 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7270 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7272 var parent = block.Parent;
7273 while (parent is Linq.QueryBlock) {
7274 parent = parent.Parent;
7276 current_block.Parent = parent;
7278 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7280 lt = (LocatedToken) $12;
7281 into = new Linq.RangeVariable (lt.Value, lt.Location);
7283 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7284 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7287 current_block = block.Parent;
7288 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7290 | JOIN type identifier_inside_body IN
7292 if (linq_clause_blocks == null)
7293 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7295 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7296 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7298 expression_or_error ON
7300 current_block.SetEndLocation (lexer.Location);
7301 current_block = current_block.Parent;
7303 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7304 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7306 expression_or_error EQUALS
7308 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7309 current_block.SetEndLocation (lexer.Location);
7310 current_block = current_block.Parent;
7312 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7314 expression_or_error opt_join_into
7316 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7317 current_block.SetEndLocation (lexer.Location);
7319 var outer_selector = linq_clause_blocks.Pop ();
7320 var block = linq_clause_blocks.Pop ();
7322 var lt = (LocatedToken) $3;
7323 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7324 Linq.RangeVariable into;
7328 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7329 IdentifierType = (FullNamedExpression)$2
7331 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7334 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7336 var parent = block.Parent;
7337 while (parent is Linq.QueryBlock) {
7338 parent = parent.Parent;
7340 current_block.Parent = parent;
7342 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7344 lt = (LocatedToken) $13;
7345 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7347 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7348 IdentifierType = (FullNamedExpression)$2
7352 current_block = block.Parent;
7353 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7359 | INTO identifier_inside_body
7368 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7372 current_block.SetEndLocation (lexer.Location);
7373 current_block = current_block.Parent;
7383 current_block.SetEndLocation (lexer.Location);
7384 current_block = current_block.Parent;
7386 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7390 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7397 | orderings_then_by COMMA
7399 current_block.SetEndLocation (lexer.Location);
7400 current_block = current_block.Parent;
7402 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7406 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7414 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7416 | expression ASCENDING
7418 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7419 lbag.AddLocation ($$, GetLocation ($2));
7421 | expression DESCENDING
7423 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7424 lbag.AddLocation ($$, GetLocation ($2));
7431 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7433 | expression ASCENDING
7435 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7436 lbag.AddLocation ($$, GetLocation ($2));
7438 | expression DESCENDING
7440 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7441 lbag.AddLocation ($$, GetLocation ($2));
7446 opt_query_continuation
7448 | INTO identifier_inside_body
7450 // query continuation block is not linked with query block but with block
7451 // before. This means each query can use same range variable names for
7452 // different identifiers.
7454 current_block.SetEndLocation (GetLocation ($1));
7455 current_block = current_block.Parent;
7457 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7459 if (linq_clause_blocks == null)
7460 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7462 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7466 var current_block = linq_clause_blocks.Pop ();
7467 var lt = (LocatedToken) $2;
7468 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7469 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7470 next = (Linq.AQueryClause)$4
7476 // Support for using the compiler as an interactive parser
7478 // The INTERACTIVE_PARSER token is first sent to parse our
7479 // productions; If the result is a Statement, the parsing
7480 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7481 // to setup the blocks in advance.
7483 // This setup is here so that in the future we can add
7484 // support for other constructs (type parsing, namespaces, etc)
7485 // that do not require a block to be setup in advance
7489 : EVAL_STATEMENT_PARSER EOF
7490 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7491 | EVAL_STATEMENT_PARSER
7493 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7495 // (ref object retval)
7496 Parameter [] mpar = new Parameter [1];
7497 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7499 ParametersCompiled pars = new ParametersCompiled (mpar);
7500 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7501 if (settings.Unsafe)
7502 mods |= Modifiers.UNSAFE;
7504 current_local_parameters = pars;
7505 var method = new InteractiveMethod (
7507 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7511 current_type.AddMember (method);
7512 oob_stack.Push (method);
7514 interactive_async = false;
7516 ++lexer.parsing_block;
7517 start_block (lexer.Location);
7519 interactive_statement_list opt_COMPLETE_COMPLETION
7521 --lexer.parsing_block;
7522 var method = (InteractiveMethod) oob_stack.Pop ();
7523 method.Block = (ToplevelBlock) end_block(lexer.Location);
7525 if (interactive_async == true) {
7526 method.ChangeToAsync ();
7529 InteractiveResult = (Class) pop_current_class ();
7530 current_local_parameters = null;
7532 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7535 interactive_compilation_unit
7536 : opt_extern_alias_directives opt_using_directives
7537 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7540 opt_COMPLETE_COMPLETION
7542 | COMPLETE_COMPLETION
7545 close_brace_or_complete_completion
7547 | COMPLETE_COMPLETION
7551 // XML documentation code references micro parser
7553 documentation_parsing
7556 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7561 : doc_type_declaration_name opt_doc_method_sig
7563 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7565 | builtin_types opt_doc_method_sig
7567 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7568 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7571 | VOID opt_doc_method_sig
7573 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7574 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7577 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7579 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7580 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7581 var lt = (LocatedToken) $3;
7582 $$ = new MemberName (lt.Value);
7584 | doc_type_declaration_name DOT THIS
7586 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7588 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7590 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7592 opt_doc_parameters CLOSE_BRACKET
7594 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7595 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7597 | EXPLICIT OPERATOR type opt_doc_method_sig
7599 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7600 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7601 module.DocumentationBuilder.ParsedParameters = p;
7602 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7605 | IMPLICIT OPERATOR type opt_doc_method_sig
7607 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7608 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7609 module.DocumentationBuilder.ParsedParameters = p;
7610 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7613 | OPERATOR overloadable_operator opt_doc_method_sig
7615 var p = (List<DocumentationParameter>)$3;
7616 module.DocumentationBuilder.ParsedParameters = p;
7617 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7622 doc_type_declaration_name
7623 : type_declaration_name
7624 | doc_type_declaration_name DOT type_declaration_name
7626 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7634 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7636 opt_doc_parameters CLOSE_PARENS
7645 $$ = new List<DocumentationParameter> (0);
7653 var parameters = new List<DocumentationParameter> ();
7654 parameters.Add ((DocumentationParameter) $1);
7657 | doc_parameters COMMA doc_parameter
7659 var parameters = $1 as List<DocumentationParameter>;
7660 parameters.Add ((DocumentationParameter) $3);
7666 : opt_parameter_modifier parameter_type
7669 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7671 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7678 // A class used to hold info about an operator declarator
7680 class OperatorDeclaration {
7681 public readonly Operator.OpType optype;
7682 public readonly FullNamedExpression ret_type;
7683 public readonly Location location;
7685 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7688 this.ret_type = ret_type;
7689 this.location = location;
7693 void Error_ExpectingTypeName (Expression expr)
7695 if (expr is Invocation){
7696 report.Error (1002, expr.Location, "Expecting `;'");
7698 expr.Error_InvalidExpressionStatement (report);
7702 void Error_ParameterModifierNotValid (string modifier, Location loc)
7704 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7708 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7710 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7711 Parameter.GetModifierSignature (mod));
7714 void Error_TypeExpected (Location loc)
7716 report.Error (1031, loc, "Type expected");
7719 void Error_UnsafeCodeNotAllowed (Location loc)
7721 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7724 void Warning_EmptyStatement (Location loc)
7726 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7729 void Error_NamedArgumentExpected (NamedArgument a)
7731 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7734 void Error_MissingInitializer (Location loc)
7736 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7739 object Error_AwaitAsIdentifier (object token)
7742 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7743 return new LocatedToken ("await", GetLocation (token));
7749 void push_current_container (TypeDefinition tc, object partial_token)
7751 if (module.Evaluator != null){
7752 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7756 undo.AddTypeContainer (current_container, tc);
7759 if (partial_token != null)
7760 current_container.AddPartial (tc);
7762 current_container.AddTypeContainer (tc);
7764 ++lexer.parsing_declaration;
7765 current_container = tc;
7769 TypeContainer pop_current_class ()
7771 var retval = current_container;
7773 current_container = current_container.Parent;
7774 current_type = current_type.Parent as TypeDefinition;
7779 [System.Diagnostics.Conditional ("FULL_AST")]
7780 void StoreModifierLocation (object token, Location loc)
7785 if (mod_locations == null)
7786 mod_locations = new List<Tuple<Modifiers, Location>> ();
7788 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7791 [System.Diagnostics.Conditional ("FULL_AST")]
7792 void PushLocation (Location loc)
7794 if (location_stack == null)
7795 location_stack = new Stack<Location> ();
7797 location_stack.Push (loc);
7800 Location PopLocation ()
7802 if (location_stack == null)
7803 return Location.Null;
7805 return location_stack.Pop ();
7808 string CheckAttributeTarget (int token, string a, Location l)
7811 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7815 if (!Tokenizer.IsValidIdentifier (a)) {
7816 Error_SyntaxError (token);
7818 report.Warning (658, 1, l,
7819 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7822 return string.Empty;
7825 static bool IsUnaryOperator (Operator.OpType op)
7829 case Operator.OpType.LogicalNot:
7830 case Operator.OpType.OnesComplement:
7831 case Operator.OpType.Increment:
7832 case Operator.OpType.Decrement:
7833 case Operator.OpType.True:
7834 case Operator.OpType.False:
7835 case Operator.OpType.UnaryPlus:
7836 case Operator.OpType.UnaryNegation:
7842 void syntax_error (Location l, string msg)
7844 report.Error (1003, l, "Syntax error, " + msg);
7849 public Tokenizer Lexer {
7855 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7856 : this (reader, file, file.Compiler.Report, session)
7860 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7863 current_container = current_namespace = file;
7865 this.module = file.Module;
7866 this.compiler = file.Compiler;
7867 this.settings = compiler.Settings;
7868 this.report = report;
7870 lang_version = settings.Version;
7871 yacc_verbose_flag = settings.VerboseParserFlag;
7872 doc_support = settings.DocumentationFile != null;
7873 lexer = new Tokenizer (reader, file, session, report);
7874 oob_stack = new Stack<object> ();
7875 lbag = session.LocationsBag;
7876 use_global_stacks = session.UseJayGlobalArrays;
7877 parameters_bucket = session.ParametersStack;
7880 public void parse ()
7882 eof_token = Token.EOF;
7885 if (yacc_verbose_flag > 1)
7886 yyparse (lexer, new yydebug.yyDebugSimple ());
7890 Tokenizer tokenizer = lexer as Tokenizer;
7891 tokenizer.cleanup ();
7892 } catch (Exception e){
7893 if (e is yyParser.yyUnexpectedEof) {
7894 Error_SyntaxError (yyToken);
7895 UnexpectedEOF = true;
7899 if (e is yyParser.yyException) {
7900 if (report.Errors == 0)
7901 report.Error (-25, lexer.Location, "Parsing error");
7903 // Used by compiler-tester to test internal errors
7904 if (yacc_verbose_flag > 0 || e is FatalException)
7907 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7912 void CheckToken (int error, int yyToken, string msg, Location loc)
7914 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7915 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7917 report.Error (error, loc, msg);
7920 string ConsumeStoredComment ()
7922 string s = tmpComment;
7924 Lexer.doc_state = XmlCommentState.Allowed;
7928 void FeatureIsNotAvailable (Location loc, string feature)
7930 report.FeatureIsNotAvailable (compiler, loc, feature);
7933 Location GetLocation (object obj)
7935 var lt = obj as LocatedToken;
7939 var mn = obj as MemberName;
7943 var expr = obj as Expression;
7945 return expr.Location;
7947 return lexer.Location;
7950 void start_block (Location loc)
7952 if (current_block == null) {
7953 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7954 parsing_anonymous_method = false;
7955 } else if (parsing_anonymous_method) {
7956 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7957 parsing_anonymous_method = false;
7959 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7963 Block end_block (Location loc)
7965 Block retval = current_block.Explicit;
7966 retval.SetEndLocation (loc);
7967 current_block = retval.Parent;
7971 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7973 oob_stack.Push (current_anonymous_method);
7974 oob_stack.Push (current_local_parameters);
7975 oob_stack.Push (current_variable);
7976 oob_stack.Push (async_block);
7978 current_local_parameters = parameters;
7980 if (lang_version <= LanguageVersion.ISO_2)
7981 FeatureIsNotAvailable (loc, "lambda expressions");
7983 current_anonymous_method = new LambdaExpression (loc);
7985 if (lang_version == LanguageVersion.ISO_1)
7986 FeatureIsNotAvailable (loc, "anonymous methods");
7988 current_anonymous_method = new AnonymousMethodExpression (loc);
7991 async_block = isAsync;
7992 // Force the next block to be created as a ToplevelBlock
7993 parsing_anonymous_method = true;
7997 * Completes the anonymous method processing, if lambda_expr is null, this
7998 * means that we have a Statement instead of an Expression embedded
8000 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
8002 AnonymousMethodExpression retval;
8005 anon_block.IsAsync = true;
8007 current_anonymous_method.Block = anon_block;
8008 retval = current_anonymous_method;
8010 async_block = (bool) oob_stack.Pop ();
8011 current_variable = (BlockVariable) oob_stack.Pop ();
8012 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
8013 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
8018 void Error_SyntaxError (int token)
8020 Error_SyntaxError (0, token);
8023 void Error_SyntaxError (int error_code, int token)
8025 Error_SyntaxError (error_code, token, "Unexpected symbol");
8028 void Error_SyntaxError (int error_code, int token, string msg)
8030 Lexer.CompleteOnEOF = false;
8032 // An error message has been reported by tokenizer
8033 if (token == Token.ERROR)
8036 // Avoid duplicit error message after unterminated string literals
8037 if (token == Token.LITERAL && lexer.Location.Column == 0)
8040 string symbol = GetSymbolName (token);
8041 string expecting = GetExpecting ();
8042 var loc = lexer.Location - symbol.Length;
8044 if (error_code == 0) {
8045 if (expecting == "`identifier'") {
8046 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
8047 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
8052 expecting = "identifier";
8053 } else if (expecting == "`)'") {
8060 if (string.IsNullOrEmpty (expecting))
8061 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
8063 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
8066 string GetExpecting ()
8068 int [] tokens = yyExpectingTokens (yyExpectingState);
8069 var names = new List<string> (tokens.Length);
8070 bool has_type = false;
8071 bool has_identifier = false;
8072 for (int i = 0; i < tokens.Length; i++){
8073 int token = tokens [i];
8074 has_identifier |= token == Token.IDENTIFIER;
8076 string name = GetTokenName (token);
8077 if (name == "<internal>")
8080 has_type |= name == "type";
8081 if (names.Contains (name))
8088 // Too many tokens to enumerate
8090 if (names.Count > 8)
8093 if (has_type && has_identifier)
8094 names.Remove ("identifier");
8096 if (names.Count == 1)
8097 return "`" + GetTokenName (tokens [0]) + "'";
8099 StringBuilder sb = new StringBuilder ();
8101 int count = names.Count;
8102 for (int i = 0; i < count; i++){
8103 bool last = i + 1 == count;
8107 sb.Append (names [i]);
8108 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
8110 return sb.ToString ();
8114 string GetSymbolName (int token)
8118 return ((Constant)lexer.Value).GetValue ().ToString ();
8119 case Token.IDENTIFIER:
8120 return ((LocatedToken)lexer.Value).Value;
8162 case Token.BITWISE_AND:
8164 case Token.BITWISE_OR:
8178 case Token.OP_SHIFT_LEFT:
8180 case Token.OP_SHIFT_RIGHT:
8200 case Token.OP_COALESCING:
8202 case Token.OP_MULT_ASSIGN:
8204 case Token.OP_DIV_ASSIGN:
8206 case Token.OP_MOD_ASSIGN:
8208 case Token.OP_ADD_ASSIGN:
8210 case Token.OP_SUB_ASSIGN:
8212 case Token.OP_SHIFT_LEFT_ASSIGN:
8214 case Token.OP_SHIFT_RIGHT_ASSIGN:
8216 case Token.OP_AND_ASSIGN:
8218 case Token.OP_XOR_ASSIGN:
8220 case Token.OP_OR_ASSIGN:
8224 return GetTokenName (token);
8227 static string GetTokenName (int token)
8230 case Token.ABSTRACT:
8252 case Token.CONTINUE:
8256 case Token.DELEGATE:
8266 case Token.EXPLICIT:
8269 case Token.EXTERN_ALIAS:
8285 case Token.IMPLICIT:
8289 case Token.INTERFACE:
8291 case Token.INTERNAL:
8297 case Token.NAMESPACE:
8303 case Token.OPERATOR:
8307 case Token.OVERRIDE:
8313 case Token.PROTECTED:
8317 case Token.READONLY:
8329 case Token.STACKALLOC:
8330 return "stackalloc";
8340 case Token.THROW_EXPR:
8348 case Token.UNCHECKED:
8356 case Token.VOLATILE:
8364 case Token.REFVALUE:
8365 return "__refvalue";
8375 case Token.FROM_FIRST:
8393 case Token.ASCENDING:
8395 case Token.DESCENDING:
8396 return "descending";
8403 case Token.OPEN_BRACE:
8405 case Token.CLOSE_BRACE:
8407 case Token.OPEN_BRACKET:
8408 case Token.OPEN_BRACKET_EXPR:
8410 case Token.CLOSE_BRACKET:
8412 case Token.OPEN_PARENS_CAST:
8413 case Token.OPEN_PARENS_LAMBDA:
8414 case Token.OPEN_PARENS_DECONSTRUCT:
8415 case Token.OPEN_PARENS:
8417 case Token.CLOSE_PARENS:
8423 case Token.DEFAULT_COLON:
8427 case Token.SEMICOLON:
8433 case Token.INTERPOLATED_STRING_END:
8435 case Token.INTERPOLATED_STRING:
8444 case Token.BITWISE_AND:
8445 case Token.BITWISE_OR:
8452 case Token.OP_SHIFT_LEFT:
8453 case Token.OP_SHIFT_RIGHT:
8461 case Token.OP_COALESCING:
8462 case Token.OP_MULT_ASSIGN:
8463 case Token.OP_DIV_ASSIGN:
8464 case Token.OP_MOD_ASSIGN:
8465 case Token.OP_ADD_ASSIGN:
8466 case Token.OP_SUB_ASSIGN:
8467 case Token.OP_SHIFT_LEFT_ASSIGN:
8468 case Token.OP_SHIFT_RIGHT_ASSIGN:
8469 case Token.OP_AND_ASSIGN:
8470 case Token.OP_XOR_ASSIGN:
8471 case Token.OP_OR_ASSIGN:
8472 case Token.INTERR_OPERATOR:
8473 return "<operator>";
8495 case Token.OP_GENERICS_LT:
8496 case Token.GENERIC_DIMENSION:
8498 case Token.OP_GENERICS_GT:
8501 case Token.INTERR_NULLABLE:
8503 case Token.DOUBLE_COLON:
8507 case Token.IDENTIFIER:
8509 return "identifier";
8512 return "end-of-file";
8514 // All of these are internal.
8517 case Token.FIRST_KEYWORD:
8518 case Token.EVAL_COMPILATION_UNIT_PARSER:
8519 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8520 case Token.EVAL_STATEMENT_PARSER:
8521 case Token.LAST_KEYWORD:
8522 case Token.GENERATE_COMPLETION:
8523 case Token.COMPLETE_COMPLETION:
8524 return "<internal>";
8526 // A bit more robust.
8528 return yyNames [token];