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 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;
1371 method_declaration_name OPEN_PARENS
1373 valid_param_mod = ParameterModifierType.All;
1375 opt_formal_parameter_list CLOSE_PARENS
1377 valid_param_mod = 0;
1378 MemberName name = (MemberName) $4;
1379 current_local_parameters = (ParametersCompiled) $7;
1381 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1382 name, current_local_parameters, (Attributes) $1);
1384 current_type.AddMember (method);
1386 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1389 method.DocComment = Lexer.consume_doc_comment ();
1391 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1395 lexer.ConstraintsParsing = true;
1397 opt_type_parameter_constraints_clauses
1399 lexer.ConstraintsParsing = false;
1402 var method = (Method) $9;
1403 method.SetConstraints ((List<Constraints>) $10);
1413 lexer.parsing_generic_declaration = true;
1415 method_declaration_name
1418 lexer.parsing_generic_declaration = false;
1419 valid_param_mod = ParameterModifierType.All;
1421 opt_formal_parameter_list CLOSE_PARENS
1423 lexer.ConstraintsParsing = true;
1425 opt_type_parameter_constraints_clauses
1427 lexer.ConstraintsParsing = false;
1428 valid_param_mod = 0;
1430 MemberName name = (MemberName) $6;
1431 current_local_parameters = (ParametersCompiled) $9;
1433 var modifiers = (Modifiers) $2;
1434 modifiers |= Modifiers.PARTIAL;
1436 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1437 modifiers, name, current_local_parameters, (Attributes) $1);
1439 current_type.AddMember (method);
1441 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1444 method.SetConstraints ((List<Constraints>) $12);
1447 method.DocComment = Lexer.consume_doc_comment ();
1449 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1450 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1456 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1458 MemberName name = (MemberName) $5;
1459 report.Error (1585, name.Location,
1460 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1462 var method = Method.Create (current_type, (FullNamedExpression) $3,
1463 0, name, (ParametersCompiled) $7, (Attributes) $1);
1465 current_type.AddMember (method);
1467 current_local_parameters = (ParametersCompiled) $7;
1470 method.DocComment = Lexer.consume_doc_comment ();
1477 method_declaration_name error
1479 Error_SyntaxError (yyToken);
1480 current_local_parameters = ParametersCompiled.Undefined;
1482 MemberName name = (MemberName) $4;
1483 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1484 name, current_local_parameters, (Attributes) $1);
1486 current_type.AddMember (method);
1489 method.DocComment = Lexer.consume_doc_comment ();
1498 | SEMICOLON { $$ = null; }
1507 | SEMICOLON { current_block = null; $$ = null; }
1510 if (lang_version < LanguageVersion.V_7) {
1511 FeatureIsNotAvailable (GetLocation ($1), "expression body constructor");
1514 ++lexer.parsing_block;
1516 expression SEMICOLON
1518 lexer.parsing_block = 0;
1519 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1520 var b = end_block (GetLocation ($4));
1521 b.IsCompilerGenerated = true;
1523 current_block = null;
1530 if (lang_version < LanguageVersion.V_6) {
1531 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1534 ++lexer.parsing_block;
1535 start_block (GetLocation ($1));
1537 expression SEMICOLON
1539 lexer.parsing_block = 0;
1540 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1541 var b = end_block (GetLocation ($4));
1542 b.IsCompilerGenerated = true;
1547 opt_formal_parameter_list
1548 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1549 | formal_parameter_list
1552 formal_parameter_list
1555 var pars_list = (List<Parameter>) $1;
1556 $$ = new ParametersCompiled (pars_list.ToArray ());
1558 | fixed_parameters COMMA parameter_array
1560 var pars_list = (List<Parameter>) $1;
1561 pars_list.Add ((Parameter) $3);
1563 $$ = new ParametersCompiled (pars_list.ToArray ());
1565 | fixed_parameters COMMA arglist_modifier
1567 var pars_list = (List<Parameter>) $1;
1568 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1569 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1571 | parameter_array COMMA error
1574 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1576 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1578 | fixed_parameters COMMA parameter_array COMMA error
1581 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1583 var pars_list = (List<Parameter>) $1;
1584 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1586 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1588 | arglist_modifier COMMA error
1590 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1592 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1594 | fixed_parameters COMMA ARGLIST COMMA error
1596 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1598 var pars_list = (List<Parameter>) $1;
1599 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1601 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1605 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1609 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1613 Error_SyntaxError (yyToken);
1614 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1621 parameters_bucket.Clear ();
1622 Parameter p = (Parameter) $1;
1623 parameters_bucket.Add (p);
1625 default_parameter_used = p.HasDefaultValue;
1626 $$ = parameters_bucket;
1628 | fixed_parameters COMMA fixed_parameter
1630 var pars = (List<Parameter>) $1;
1631 Parameter p = (Parameter) $3;
1633 if (p.HasExtensionMethodModifier)
1634 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1635 else if (!p.HasDefaultValue && default_parameter_used)
1636 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1638 default_parameter_used |= p.HasDefaultValue;
1641 lbag.AddLocation (p, GetLocation ($2));
1650 opt_parameter_modifier
1652 identifier_inside_body
1654 var lt = (LocatedToken) $4;
1655 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1658 opt_parameter_modifier
1660 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1662 var lt = (LocatedToken) $4;
1663 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1664 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1666 | attribute_sections error
1668 Error_SyntaxError (yyToken);
1669 Location l = GetLocation ($2);
1670 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1673 opt_parameter_modifier
1677 Error_SyntaxError (yyToken);
1678 Location l = GetLocation ($4);
1679 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1682 opt_parameter_modifier
1684 identifier_inside_body
1687 ++lexer.parsing_block;
1691 --lexer.parsing_block;
1692 if (lang_version <= LanguageVersion.V_3) {
1693 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1696 Parameter.Modifier mod = (Parameter.Modifier) $2;
1697 if (mod != Parameter.Modifier.NONE) {
1699 case Parameter.Modifier.REF:
1700 case Parameter.Modifier.OUT:
1701 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1702 Parameter.GetModifierSignature (mod));
1705 case Parameter.Modifier.This:
1706 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1707 Parameter.GetModifierSignature (mod));
1710 throw new NotImplementedException (mod.ToString ());
1713 mod = Parameter.Modifier.NONE;
1716 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1717 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1719 var lt = (LocatedToken) $4;
1720 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1721 lbag.AddLocation ($$, GetLocation ($5));
1724 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1728 opt_parameter_modifier
1729 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1730 | parameter_modifiers
1734 : parameter_modifier
1738 | parameter_modifiers parameter_modifier
1740 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1741 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1742 if (((Parameter.Modifier)$1 & p2) == p2) {
1743 Error_DuplicateParameterModifier (lexer.Location, p2);
1745 switch (mod & ~Parameter.Modifier.This) {
1746 case Parameter.Modifier.REF:
1747 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1749 case Parameter.Modifier.OUT:
1750 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1753 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1764 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1765 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1767 $$ = Parameter.Modifier.REF;
1771 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1772 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1774 $$ = Parameter.Modifier.OUT;
1778 if ((valid_param_mod & ParameterModifierType.This) == 0)
1779 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1781 if (lang_version <= LanguageVersion.ISO_2)
1782 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1784 $$ = Parameter.Modifier.This;
1789 : opt_attributes params_modifier type IDENTIFIER
1791 var lt = (LocatedToken) $4;
1792 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1794 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1796 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1798 var lt = (LocatedToken) $4;
1799 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1801 | opt_attributes params_modifier type error
1803 Error_SyntaxError (yyToken);
1805 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1812 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1813 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1815 | PARAMS parameter_modifier
1817 Parameter.Modifier mod = (Parameter.Modifier)$2;
1818 if ((mod & Parameter.Modifier.This) != 0) {
1819 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1821 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1824 | PARAMS params_modifier
1826 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1833 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1834 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1838 property_declaration
1842 member_declaration_name
1844 lexer.parsing_generic_declaration = false;
1846 tmpComment = Lexer.consume_doc_comment ();
1850 var type = (FullNamedExpression) $3;
1851 current_property = new Property (current_type, type, (Modifiers) $2,
1852 (MemberName) $4, (Attributes) $1);
1854 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1855 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1857 current_type.AddMember (current_property);
1858 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1860 lexer.PropertyParsing = true;
1862 accessor_declarations
1864 lexer.PropertyParsing = false;
1867 current_property.DocComment = ConsumeStoredComment ();
1871 lbag.AppendToMember (current_property, GetLocation ($10));
1872 lexer.parsing_modifiers = true;
1874 opt_property_initializer
1876 current_property = null;
1881 member_declaration_name
1883 lexer.parsing_generic_declaration = false;
1885 tmpComment = Lexer.consume_doc_comment ();
1886 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1890 var type = (FullNamedExpression) $3;
1891 var property = new Property (current_type, type, (Modifiers) $2,
1892 (MemberName) $4, (Attributes) $1);
1894 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1895 property.Get.Block = (ToplevelBlock) $6;
1897 if (current_container.Kind == MemberKind.Interface) {
1898 report.Error (531, property.Get.Block.StartLocation,
1899 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1902 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1903 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1906 property.DocComment = ConsumeStoredComment ();
1908 current_type.AddMember (property);
1910 current_local_parameters = null;
1914 opt_property_initializer
1918 ++lexer.parsing_block;
1919 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1920 start_block (GetLocation ($1));
1922 property_initializer SEMICOLON
1924 --lexer.parsing_block;
1925 ((Property)current_property).Initializer = (Expression) $3;
1926 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1927 end_block (GetLocation ($4));
1928 current_local_parameters = null;
1931 Lexer.doc_state = XmlCommentState.Allowed;
1935 property_initializer
1941 : opt_attributes opt_modifiers
1942 member_type indexer_declaration_name OPEN_BRACKET
1944 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1946 opt_formal_parameter_list CLOSE_BRACKET
1948 valid_param_mod = 0;
1949 var type = (FullNamedExpression) $3;
1950 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1952 current_property = indexer;
1954 current_type.AddIndexer (indexer);
1955 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1957 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1958 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1960 if (indexer.ParameterInfo.IsEmpty) {
1961 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1965 tmpComment = Lexer.consume_doc_comment ();
1966 Lexer.doc_state = XmlCommentState.Allowed;
1969 lexer.PropertyParsing = true;
1970 current_local_parameters = (ParametersCompiled) $7;
1974 lexer.PropertyParsing = false;
1975 current_local_parameters = null;
1977 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1978 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1981 current_property.DocComment = ConsumeStoredComment ();
1983 current_property = null;
1988 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1990 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1994 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1995 current_property.Get.Block = (ToplevelBlock) $1;
1999 accessor_declarations
2000 : get_accessor_declaration
2001 | get_accessor_declaration accessor_declarations
2002 | set_accessor_declaration
2003 | set_accessor_declaration accessor_declarations
2006 if (yyToken == Token.CLOSE_BRACE) {
2007 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
2009 if (yyToken == Token.SEMICOLON)
2010 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
2012 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
2017 get_accessor_declaration
2018 : opt_attributes opt_modifiers GET
2020 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2021 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2024 if (current_property.Get != null) {
2025 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2028 if (current_property is Indexer) {
2029 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
2030 (Attributes) $1, GetLocation ($3));
2032 current_property.Get = new Property.GetMethod (current_property,
2033 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2036 current_local_parameters = current_property.Get.ParameterInfo;
2037 lbag.AddMember (current_property.Get, mod_locations);
2038 lexer.PropertyParsing = false;
2043 current_property.Get.Block = (ToplevelBlock) $5;
2045 if (current_container.Kind == MemberKind.Interface) {
2046 report.Error (531, current_property.Get.Block.StartLocation,
2047 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2051 current_local_parameters = null;
2052 lexer.PropertyParsing = true;
2055 if (Lexer.doc_state == XmlCommentState.Error)
2056 Lexer.doc_state = XmlCommentState.NotAllowed;
2060 set_accessor_declaration
2061 : opt_attributes opt_modifiers SET
2063 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2064 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2067 if (current_property.Set != null) {
2068 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2071 if (current_property is Indexer) {
2072 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2073 ParametersCompiled.MergeGenerated (compiler,
2074 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2075 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2077 (Attributes) $1, GetLocation ($3));
2079 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2080 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2081 (Attributes) $1, GetLocation ($3));
2084 current_local_parameters = current_property.Set.ParameterInfo;
2085 lbag.AddMember (current_property.Set, mod_locations);
2086 lexer.PropertyParsing = false;
2091 current_property.Set.Block = (ToplevelBlock) $5;
2093 if (current_container.Kind == MemberKind.Interface) {
2094 report.Error (531, current_property.Set.Block.StartLocation,
2095 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2099 current_local_parameters = null;
2100 lexer.PropertyParsing = true;
2103 && Lexer.doc_state == XmlCommentState.Error)
2104 Lexer.doc_state = XmlCommentState.NotAllowed;
2118 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2124 interface_declaration
2131 type_declaration_name
2133 lexer.ConstraintsParsing = true;
2134 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2135 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2138 opt_type_parameter_constraints_clauses
2140 lexer.ConstraintsParsing = false;
2143 current_container.SetConstraints ((List<Constraints>) $9);
2146 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2147 Lexer.doc_state = XmlCommentState.Allowed;
2150 lexer.parsing_modifiers = true;
2152 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2154 --lexer.parsing_declaration;
2156 Lexer.doc_state = XmlCommentState.Allowed;
2161 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2163 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2165 $$ = pop_current_class ();
2167 | opt_attributes opt_modifiers opt_partial INTERFACE error
2169 Error_SyntaxError (yyToken);
2173 opt_interface_member_declarations
2175 | interface_member_declarations
2178 interface_member_declarations
2179 : interface_member_declaration
2181 lexer.parsing_modifiers = true;
2182 lexer.parsing_block = 0;
2184 | interface_member_declarations interface_member_declaration
2186 lexer.parsing_modifiers = true;
2187 lexer.parsing_block = 0;
2191 interface_member_declaration
2192 : constant_declaration
2194 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2198 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2200 | method_declaration
2201 | property_declaration
2203 | indexer_declaration
2204 | operator_declaration
2206 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2208 | constructor_declaration
2210 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2214 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2218 operator_declaration
2219 : opt_attributes opt_modifiers operator_declarator
2224 OperatorDeclaration decl = (OperatorDeclaration) $3;
2226 Operator op = new Operator (
2227 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2228 current_local_parameters,
2229 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2231 if (op.Block == null)
2232 op.ParameterInfo.CheckParameters (op);
2235 op.DocComment = tmpComment;
2236 Lexer.doc_state = XmlCommentState.Allowed;
2239 // Note again, checking is done in semantic analysis
2240 current_type.AddOperator (op);
2242 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2245 current_local_parameters = null;
2250 : type_expression_or_array
2253 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2254 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2259 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2261 valid_param_mod = ParameterModifierType.DefaultValue;
2262 if ((Operator.OpType) $3 == Operator.OpType.Is)
2263 valid_param_mod |= ParameterModifierType.Out;
2265 opt_formal_parameter_list CLOSE_PARENS
2267 valid_param_mod = 0;
2269 Location loc = GetLocation ($2);
2270 Operator.OpType op = (Operator.OpType) $3;
2271 current_local_parameters = (ParametersCompiled)$6;
2273 int p_count = current_local_parameters.Count;
2275 if (op == Operator.OpType.Addition)
2276 op = Operator.OpType.UnaryPlus;
2277 else if (op == Operator.OpType.Subtraction)
2278 op = Operator.OpType.UnaryNegation;
2281 if (IsUnaryOperator (op)) {
2283 report.Error (1020, loc, "Overloadable binary operator expected");
2284 } else if (p_count != 1) {
2285 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2286 Operator.GetName (op));
2288 } else if (op == Operator.OpType.Is) {
2289 // TODO: Special checks for is operator
2292 report.Error (1019, loc, "Overloadable unary operator expected");
2293 } else if (p_count != 2) {
2294 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2295 Operator.GetName (op));
2300 tmpComment = Lexer.consume_doc_comment ();
2301 Lexer.doc_state = XmlCommentState.NotAllowed;
2304 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2305 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2307 | conversion_operator_declarator
2310 overloadable_operator
2312 : BANG { $$ = Operator.OpType.LogicalNot; }
2313 | TILDE { $$ = Operator.OpType.OnesComplement; }
2314 | OP_INC { $$ = Operator.OpType.Increment; }
2315 | OP_DEC { $$ = Operator.OpType.Decrement; }
2316 | TRUE { $$ = Operator.OpType.True; }
2317 | FALSE { $$ = Operator.OpType.False; }
2318 // Unary and binary:
2319 | PLUS { $$ = Operator.OpType.Addition; }
2320 | MINUS { $$ = Operator.OpType.Subtraction; }
2322 | STAR { $$ = Operator.OpType.Multiply; }
2323 | DIV { $$ = Operator.OpType.Division; }
2324 | PERCENT { $$ = Operator.OpType.Modulus; }
2325 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2326 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2327 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2328 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2329 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2330 | OP_EQ { $$ = Operator.OpType.Equality; }
2331 | OP_NE { $$ = Operator.OpType.Inequality; }
2332 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2333 | OP_LT { $$ = Operator.OpType.LessThan; }
2334 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2335 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2338 if (lang_version != LanguageVersion.Experimental)
2339 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2341 $$ = Operator.OpType.Is;
2345 conversion_operator_declarator
2346 : IMPLICIT OPERATOR type OPEN_PARENS
2348 valid_param_mod = ParameterModifierType.DefaultValue;
2350 opt_formal_parameter_list CLOSE_PARENS
2352 valid_param_mod = 0;
2354 Location loc = GetLocation ($2);
2355 current_local_parameters = (ParametersCompiled)$6;
2357 if (current_local_parameters.Count != 1) {
2358 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2362 tmpComment = Lexer.consume_doc_comment ();
2363 Lexer.doc_state = XmlCommentState.NotAllowed;
2366 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2367 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2369 | EXPLICIT OPERATOR type OPEN_PARENS
2371 valid_param_mod = ParameterModifierType.DefaultValue;
2373 opt_formal_parameter_list CLOSE_PARENS
2375 valid_param_mod = 0;
2377 Location loc = GetLocation ($2);
2378 current_local_parameters = (ParametersCompiled)$6;
2380 if (current_local_parameters.Count != 1) {
2381 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2385 tmpComment = Lexer.consume_doc_comment ();
2386 Lexer.doc_state = XmlCommentState.NotAllowed;
2389 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2390 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2394 Error_SyntaxError (yyToken);
2395 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2396 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2400 Error_SyntaxError (yyToken);
2401 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2402 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2406 constructor_declaration
2407 : constructor_declarator
2410 Constructor c = (Constructor) $1;
2411 c.Block = (ToplevelBlock) $2;
2414 c.DocComment = ConsumeStoredComment ();
2416 current_local_parameters = null;
2418 Lexer.doc_state = XmlCommentState.Allowed;
2422 constructor_declarator
2428 tmpComment = Lexer.consume_doc_comment ();
2429 Lexer.doc_state = XmlCommentState.Allowed;
2432 valid_param_mod = ParameterModifierType.All;
2434 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2436 valid_param_mod = 0;
2437 current_local_parameters = (ParametersCompiled) $6;
2439 var lt = (LocatedToken) $3;
2440 var mods = (Modifiers) $2;
2441 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2443 if (lt.Value != current_container.MemberName.Name) {
2444 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2445 } else if ((mods & Modifiers.STATIC) != 0) {
2446 if (!current_local_parameters.IsEmpty) {
2447 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2448 c.GetSignatureForError ());
2451 if ((mods & Modifiers.AccessibilityMask) != 0){
2452 report.Error (515, c.Location,
2453 "`{0}': static constructor cannot have an access modifier",
2454 c.GetSignatureForError ());
2457 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2458 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2462 current_type.AddConstructor (c);
2463 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2467 // start block here, so possible anonymous methods inside
2468 // constructor initializer can get correct parent block
2470 start_block (lexer.Location);
2472 opt_constructor_initializer
2475 var c = (Constructor) $8;
2476 c.Initializer = (ConstructorInitializer) $9;
2479 report.Error (514, c.Location,
2480 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2481 c.GetSignatureForError ());
2489 opt_constructor_initializer
2491 | constructor_initializer
2494 constructor_initializer
2495 : COLON BASE OPEN_PARENS
2497 ++lexer.parsing_block;
2499 opt_argument_list CLOSE_PARENS
2501 --lexer.parsing_block;
2502 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2503 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2505 | COLON THIS OPEN_PARENS
2507 ++lexer.parsing_block;
2509 opt_argument_list CLOSE_PARENS
2511 --lexer.parsing_block;
2512 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2513 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2517 Error_SyntaxError (yyToken);
2518 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2519 lbag.AddLocation ($$, GetLocation ($1));
2523 Error_SyntaxError (yyToken);
2528 destructor_declaration
2529 : opt_attributes opt_modifiers TILDE
2532 tmpComment = Lexer.consume_doc_comment ();
2533 Lexer.doc_state = XmlCommentState.NotAllowed;
2536 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2538 IDENTIFIER OPEN_PARENS CLOSE_PARENS destructor_body
2540 var lt = (LocatedToken) $5;
2541 if (lt.Value != current_container.MemberName.Name){
2542 report.Error (574, lt.Location, "Name of destructor must match name of class");
2543 } else if (current_container.Kind != MemberKind.Class){
2544 report.Error (575, lt.Location, "Only class types can contain destructor");
2547 Destructor d = new Destructor (current_type, (Modifiers) $2,
2548 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2550 d.DocComment = ConsumeStoredComment ();
2552 d.Block = (ToplevelBlock) $8;
2553 current_type.AddMember (d);
2554 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2556 current_local_parameters = null;
2563 EVENT type member_declaration_name
2565 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2566 current_type.AddMember (current_event_field);
2568 if (current_event_field.MemberName.ExplicitInterface != null) {
2569 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2570 current_event_field.GetSignatureForError ());
2573 $$ = current_event_field;
2575 opt_event_initializer
2576 opt_event_declarators
2580 current_event_field.DocComment = Lexer.consume_doc_comment ();
2581 Lexer.doc_state = XmlCommentState.Allowed;
2584 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2585 current_event_field = null;
2589 EVENT type member_declaration_name
2592 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2593 current_type.AddMember (current_event);
2594 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2596 lexer.EventParsing = true;
2598 event_accessor_declarations
2600 if (current_container.Kind == MemberKind.Interface)
2601 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2603 lexer.EventParsing = false;
2608 current_event.DocComment = Lexer.consume_doc_comment ();
2609 Lexer.doc_state = XmlCommentState.Allowed;
2612 lbag.AppendToMember (current_event, GetLocation ($9));
2613 current_event = null;
2614 current_local_parameters = null;
2620 Error_SyntaxError (yyToken);
2622 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2626 opt_event_initializer
2630 ++lexer.parsing_block;
2632 event_variable_initializer
2634 --lexer.parsing_block;
2635 current_event_field.Initializer = (Expression) $3;
2639 opt_event_declarators
2647 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2649 | event_declarators event_declarator
2651 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2658 var lt = (LocatedToken) $2;
2659 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2660 lbag.AddLocation ($$, GetLocation ($1));
2662 | COMMA IDENTIFIER ASSIGN event_variable_initializer
2664 var lt = (LocatedToken) $2;
2665 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $4);
2666 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2670 event_variable_initializer
2672 if (current_container.Kind == MemberKind.Interface) {
2673 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2674 current_event_field.GetSignatureForError ());
2677 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2678 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2679 current_event_field.GetSignatureForError ());
2682 ++lexer.parsing_block;
2683 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2684 start_block (lexer.Location);
2686 variable_initializer
2690 --lexer.parsing_block;
2691 end_block (lexer.Location);
2692 current_local_parameters = null;
2696 event_accessor_declarations
2697 : add_accessor_declaration remove_accessor_declaration
2698 | remove_accessor_declaration add_accessor_declaration
2699 | add_accessor_declaration
2701 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2702 current_event.GetSignatureForError ());
2704 | remove_accessor_declaration
2706 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2707 current_event.GetSignatureForError ());
2711 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2716 add_accessor_declaration
2717 : opt_attributes opt_modifiers ADD
2719 if ($2 != ModifierNone) {
2720 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2723 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2724 current_local_parameters = current_event.Add.ParameterInfo;
2726 lbag.AddMember (current_event.Add, mod_locations);
2727 lexer.EventParsing = false;
2729 event_accessor_block
2731 lexer.EventParsing = true;
2733 current_event.Add.Block = (ToplevelBlock) $5;
2735 if (current_container.Kind == MemberKind.Interface) {
2736 report.Error (531, current_event.Add.Block.StartLocation,
2737 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2740 current_local_parameters = null;
2744 remove_accessor_declaration
2745 : opt_attributes opt_modifiers REMOVE
2747 if ($2 != ModifierNone) {
2748 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2751 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2752 current_local_parameters = current_event.Remove.ParameterInfo;
2754 lbag.AddMember (current_event.Remove, mod_locations);
2755 lexer.EventParsing = false;
2757 event_accessor_block
2759 lexer.EventParsing = true;
2761 current_event.Remove.Block = (ToplevelBlock) $5;
2763 if (current_container.Kind == MemberKind.Interface) {
2764 report.Error (531, current_event.Remove.Block.StartLocation,
2765 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2768 current_local_parameters = null;
2772 event_accessor_block
2775 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2782 attributes_without_members
2783 : attribute_sections CLOSE_BRACE
2785 current_type.UnattachedAttributes = (Attributes) $1;
2786 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2787 lexer.putback ('}');
2791 // For full ast try to recover incomplete ambiguous member
2792 // declaration in form on class X { public int }
2794 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2796 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2798 lexer.putback ('}');
2800 lexer.parsing_generic_declaration = false;
2801 FullNamedExpression type = (FullNamedExpression) $3;
2802 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2803 current_type.AddField (current_field);
2811 ENUM type_declaration_name
2815 enumTypeComment = Lexer.consume_doc_comment ();
2820 Lexer.doc_state = XmlCommentState.Allowed;
2822 MemberName name = (MemberName) $4;
2823 if (name.IsGeneric) {
2824 report.Error (1675, name.Location, "Enums cannot have type parameters");
2827 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2829 opt_enum_member_declarations
2831 lexer.parsing_modifiers = true;
2833 // here will be evaluated after CLOSE_BLACE is consumed.
2835 Lexer.doc_state = XmlCommentState.Allowed;
2837 CLOSE_BRACE opt_semicolon
2840 current_container.DocComment = enumTypeComment;
2842 --lexer.parsing_declaration;
2845 // em.DocComment = ev.DocComment;
2847 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2848 $$ = pop_current_class ();
2860 Error_TypeExpected (GetLocation ($1));
2865 opt_enum_member_declarations
2867 | enum_member_declarations
2868 | enum_member_declarations COMMA
2870 lbag.AddLocation ($1, GetLocation ($2));
2874 enum_member_declarations
2875 : enum_member_declaration
2876 | enum_member_declarations COMMA enum_member_declaration
2878 lbag.AddLocation ($1, GetLocation ($2));
2883 enum_member_declaration
2884 : opt_attributes IDENTIFIER
2886 var lt = (LocatedToken) $2;
2887 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2888 ((Enum) current_type).AddEnumMember (em);
2891 em.DocComment = Lexer.consume_doc_comment ();
2892 Lexer.doc_state = XmlCommentState.Allowed;
2897 | opt_attributes IDENTIFIER
2899 ++lexer.parsing_block;
2901 tmpComment = Lexer.consume_doc_comment ();
2902 Lexer.doc_state = XmlCommentState.NotAllowed;
2905 ASSIGN constant_expression
2907 --lexer.parsing_block;
2909 var lt = (LocatedToken) $2;
2910 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2911 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2912 ((Enum) current_type).AddEnumMember (em);
2915 em.DocComment = ConsumeStoredComment ();
2919 | opt_attributes IDENTIFIER error
2921 Error_SyntaxError (yyToken);
2923 var lt = (LocatedToken) $2;
2924 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2925 ((Enum) current_type).AddEnumMember (em);
2928 em.DocComment = Lexer.consume_doc_comment ();
2929 Lexer.doc_state = XmlCommentState.Allowed;
2934 | attributes_without_members
2937 delegate_declaration
2941 member_type type_declaration_name
2944 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2946 opt_formal_parameter_list CLOSE_PARENS
2948 valid_param_mod = 0;
2950 ParametersCompiled p = (ParametersCompiled) $8;
2952 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2954 p.CheckParameters (del);
2956 current_container.AddTypeContainer (del);
2958 current_delegate = del;
2959 lexer.ConstraintsParsing = true;
2961 opt_type_parameter_constraints_clauses
2963 lexer.ConstraintsParsing = false;
2968 current_delegate.DocComment = Lexer.consume_doc_comment ();
2969 Lexer.doc_state = XmlCommentState.Allowed;
2973 current_delegate.SetConstraints ((List<Constraints>) $11);
2974 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2976 $$ = current_delegate;
2978 current_delegate = null;
2986 if (lang_version < LanguageVersion.ISO_2)
2987 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2989 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2993 namespace_or_type_expr
2995 | qualified_alias_member IDENTIFIER opt_type_argument_list
2997 var lt1 = (LocatedToken) $1;
2998 var lt2 = (LocatedToken) $2;
3000 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3001 lbag.AddLocation ($$, GetLocation ($2));
3003 | qualified_alias_member IDENTIFIER generic_dimension
3005 var lt1 = (LocatedToken) $1;
3006 var lt2 = (LocatedToken) $2;
3008 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3009 lbag.AddLocation ($$, GetLocation ($2));
3015 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
3017 var lt = (LocatedToken) $3;
3018 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3019 lbag.AddLocation ($$, GetLocation ($2));
3021 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
3023 var lt = (LocatedToken) $3;
3024 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3025 lbag.AddLocation ($$, GetLocation ($2));
3030 : IDENTIFIER opt_type_argument_list
3032 var lt = (LocatedToken) $1;
3033 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3035 | IDENTIFIER generic_dimension
3037 var lt = (LocatedToken) $1;
3038 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3043 // Generics arguments (any type, without attributes)
3045 opt_type_argument_list
3047 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3049 if (lang_version < LanguageVersion.ISO_2)
3050 FeatureIsNotAvailable (GetLocation ($1), "generics");
3054 | OP_GENERICS_LT error
3056 Error_TypeExpected (lexer.Location);
3057 $$ = new TypeArguments ();
3064 TypeArguments type_args = new TypeArguments ();
3065 type_args.Add ((FullNamedExpression) $1);
3068 | type_arguments COMMA type
3070 TypeArguments type_args = (TypeArguments) $1;
3071 type_args.Add ((FullNamedExpression) $3);
3077 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3079 type_declaration_name
3082 lexer.parsing_generic_declaration = true;
3084 opt_type_parameter_list
3086 lexer.parsing_generic_declaration = false;
3087 var lt = (LocatedToken) $1;
3088 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3092 member_declaration_name
3093 : method_declaration_name
3095 MemberName mn = (MemberName)$1;
3096 if (mn.TypeParameters != null)
3097 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3098 mn.GetSignatureForError ()));
3102 method_declaration_name
3103 : type_declaration_name
3104 | explicit_interface IDENTIFIER opt_type_parameter_list
3106 lexer.parsing_generic_declaration = false;
3107 var lt = (LocatedToken) $2;
3108 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3112 indexer_declaration_name
3115 lexer.parsing_generic_declaration = false;
3116 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3118 | explicit_interface THIS
3120 lexer.parsing_generic_declaration = false;
3121 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3126 : IDENTIFIER opt_type_argument_list DOT
3128 var lt = (LocatedToken) $1;
3129 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3130 lbag.AddLocation ($$, GetLocation ($3));
3132 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3134 var lt1 = (LocatedToken) $1;
3135 var lt2 = (LocatedToken) $2;
3137 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3138 lbag.AddLocation ($$, GetLocation ($4));
3140 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3142 var lt = (LocatedToken) $2;
3143 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3144 lbag.AddLocation ($$, GetLocation ($4));
3148 opt_type_parameter_list
3150 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3152 if (lang_version < LanguageVersion.ISO_2)
3153 FeatureIsNotAvailable (GetLocation ($1), "generics");
3156 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3163 var tparams = new TypeParameters ();
3164 tparams.Add ((TypeParameter)$1);
3167 | type_parameters COMMA type_parameter
3169 var tparams = (TypeParameters) $1;
3170 tparams.Add ((TypeParameter)$3);
3172 lbag.AddLocation ($3, GetLocation ($3));
3177 : opt_attributes opt_type_parameter_variance IDENTIFIER
3179 var lt = (LocatedToken)$3;
3180 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3184 if (GetTokenName (yyToken) == "type")
3185 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3187 Error_SyntaxError (yyToken);
3189 $$ = new TypeParameter (MemberName.Null, null, null);
3194 // All types where void is allowed
3197 : type_expression_or_array
3200 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3207 lexer.parsing_generic_declaration = true;
3212 // A type which does not allow `void' to be used
3215 : type_expression_or_array
3225 : type_expression_or_array
3228 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3229 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3233 type_expression_or_array
3235 | type_expression rank_specifiers
3237 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3242 : namespace_or_type_expr opt_nullable
3245 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3247 var sn = $1 as SimpleName;
3248 if (sn != null && sn.Name == "var")
3249 $$ = new VarExpr (sn.Location);
3254 | namespace_or_type_expr pointer_stars
3256 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3258 | builtin_type_expression
3259 | OPEN_PARENS tuple_elements CLOSE_PARENS opt_nullable
3261 if (lang_version < LanguageVersion.V_7)
3262 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3264 var a = (Tuple<TypeArguments, List<string>>) $2;
3265 if (a.Item1.Count < 2) {
3266 report.Error (8124, GetLocation ($1), "Tuple must contain at least two elements");
3269 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
3272 $$ = new ComposedCast ((FullNamedExpression) $$, (ComposedTypeSpecifier) $4);
3277 : tuple_element tuple_element_name
3279 var type_args = new TypeArguments ();
3280 type_args.Add ((FullNamedExpression) $1);
3282 var names = new List<string> (2);
3283 var lt = (LocatedToken) $2;
3284 names.Add (lt?.Value);
3286 $$ = Tuple.Create (type_args, names);
3288 | tuple_elements COMMA tuple_element tuple_element_name
3290 var a = (Tuple<TypeArguments, List<string>>) $1;
3291 a.Item1.Add ((FullNamedExpression) $3);
3292 var lt = (LocatedToken) $4;
3293 a.Item2.Add (lt?.Value);
3310 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3311 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3315 builtin_type_expression
3316 : builtin_types opt_nullable
3319 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3321 | builtin_types pointer_stars
3323 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3325 | VOID pointer_stars
3327 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3334 var types = new List<FullNamedExpression> (2);
3335 types.Add ((FullNamedExpression) $1);
3338 | type_list COMMA base_type_name
3340 var types = (List<FullNamedExpression>) $1;
3341 types.Add ((FullNamedExpression) $3);
3349 if ($1 is ComposedCast) {
3350 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3357 * replaces all the productions for isolating the various
3358 * simple types, but we need this to reuse it easily in variable_type
3361 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3362 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3363 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3364 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3365 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3366 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3371 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3372 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3373 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3374 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3375 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3376 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3377 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3378 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3379 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3383 // Expressions, section 7.5
3388 : type_name_expression
3390 | array_creation_expression
3391 | parenthesized_expression
3392 | default_value_expression
3393 | invocation_expression
3397 | post_increment_expression
3398 | post_decrement_expression
3399 | object_or_delegate_creation_expression
3400 | anonymous_type_expression
3403 | checked_expression
3404 | unchecked_expression
3405 | pointer_member_access
3406 | anonymous_method_expression
3407 | undocumented_expressions
3408 | interpolated_string
3411 type_name_expression
3413 | IDENTIFIER GENERATE_COMPLETION {
3414 var lt = (LocatedToken) $1;
3415 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3424 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3428 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3429 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3433 : OPEN_PARENS tuple_literal_elements CLOSE_PARENS
3435 if (lang_version < LanguageVersion.V_7)
3436 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3438 $$ = new TupleLiteral ((List<TupleLiteralElement>)$2, GetLocation ($1));
3442 tuple_literal_elements
3443 : tuple_literal_element COMMA tuple_literal_element
3445 $$ = new List<TupleLiteralElement> () {
3446 (TupleLiteralElement) $1, (TupleLiteralElement) $3
3449 | tuple_literal_elements COMMA tuple_literal_element
3451 var list = (List<TupleLiteralElement>)$1;
3452 list.Add ((TupleLiteralElement) $3);
3456 tuple_literal_element
3459 $$ = new TupleLiteralElement ((Expression) $1);
3461 | IDENTIFIER COLON expression
3463 var lt = (LocatedToken) $1;
3464 $$ = new TupleLiteralElement (lt.Value, (Expression) $3, lt.Location);
3469 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3471 if (lang_version < LanguageVersion.V_6)
3472 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3474 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3476 | INTERPOLATED_STRING_END
3478 if (lang_version < LanguageVersion.V_6)
3479 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3481 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3488 var list = new List<Expression> ();
3489 list.Add ((InterpolatedStringInsert) $1);
3492 | interpolations INTERPOLATED_STRING interpolation
3494 var list = (List<Expression>) $1;
3495 list.Add ((StringLiteral) $2);
3496 list.Add ((InterpolatedStringInsert) $3);
3504 $$ = new InterpolatedStringInsert ((Expression) $1);
3506 | expression COMMA expression
3508 $$ = new InterpolatedStringInsert ((Expression) $1) {
3509 Alignment = (Expression)$3
3514 lexer.parsing_interpolation_format = true;
3518 lexer.parsing_interpolation_format = false;
3520 $$ = new InterpolatedStringInsert ((Expression) $1) {
3524 | expression COMMA expression COLON
3526 lexer.parsing_interpolation_format = true;
3530 lexer.parsing_interpolation_format = false;
3532 $$ = new InterpolatedStringInsert ((Expression) $1) {
3533 Alignment = (Expression)$3,
3534 Format = (string) $6
3541 // Here is the trick, tokenizer may think that parens is a special but
3542 // parser is interested in open parens only, so we merge them.
3543 // Consider: if (a)foo ();
3551 // Use this production to accept closing parenthesis or
3552 // performing completion
3556 | COMPLETE_COMPLETION
3560 parenthesized_expression
3561 : OPEN_PARENS expression CLOSE_PARENS
3563 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3564 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3566 | OPEN_PARENS expression COMPLETE_COMPLETION
3568 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3573 : primary_expression DOT identifier_inside_body opt_type_argument_list
3575 var lt = (LocatedToken) $3;
3576 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3577 lbag.AddLocation ($$, GetLocation ($2));
3579 | primary_expression DOT identifier_inside_body generic_dimension
3581 var lt = (LocatedToken) $3;
3582 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3583 lbag.AddLocation ($$, GetLocation ($2));
3585 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3587 if (lang_version < LanguageVersion.V_6)
3588 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3590 var lt = (LocatedToken) $4;
3591 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3592 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3594 | builtin_types DOT identifier_inside_body opt_type_argument_list
3596 var lt = (LocatedToken) $3;
3597 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3598 lbag.AddLocation ($$, GetLocation ($2));
3600 | BASE DOT identifier_inside_body opt_type_argument_list
3602 var lt = (LocatedToken) $3;
3603 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3604 lbag.AddLocation ($$, GetLocation ($2));
3606 | AWAIT DOT identifier_inside_body opt_type_argument_list
3608 var lt = (LocatedToken) $3;
3609 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3610 lbag.AddLocation ($$, GetLocation ($2));
3612 | qualified_alias_member identifier_inside_body opt_type_argument_list
3614 var lt1 = (LocatedToken) $1;
3615 var lt2 = (LocatedToken) $2;
3617 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3618 lbag.AddLocation ($$, GetLocation ($2));
3620 | qualified_alias_member identifier_inside_body generic_dimension
3622 var lt1 = (LocatedToken) $1;
3623 var lt2 = (LocatedToken) $2;
3625 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3626 lbag.AddLocation ($$, GetLocation ($2));
3628 | primary_expression DOT GENERATE_COMPLETION {
3629 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3631 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3632 var lt = (LocatedToken) $3;
3633 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3635 | builtin_types DOT GENERATE_COMPLETION
3637 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3639 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3640 var lt = (LocatedToken) $3;
3641 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3645 invocation_expression
3646 : primary_expression open_parens_any opt_argument_list close_parens
3648 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3649 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3651 | primary_expression open_parens_any argument_list error
3653 Error_SyntaxError (yyToken);
3655 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3656 lbag.AddLocation ($$, GetLocation ($2));
3658 | primary_expression open_parens_any error
3660 Error_SyntaxError (yyToken);
3662 $$ = new Invocation ((Expression) $1, null);
3663 lbag.AddLocation ($$, GetLocation ($2));
3667 opt_object_or_collection_initializer
3668 : /* empty */ { $$ = null; }
3669 | object_or_collection_initializer
3672 object_or_collection_initializer
3673 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3676 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3678 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3680 lbag.AddLocation ($$, GetLocation ($3));
3682 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3684 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3685 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3689 opt_member_initializer_list
3690 : /* empty */ { $$ = null; }
3691 | member_initializer_list
3697 member_initializer_list
3698 : member_initializer
3700 var a = new List<Expression> ();
3701 a.Add ((Expression) $1);
3704 | member_initializer_list COMMA member_initializer
3706 var a = (List<Expression>)$1;
3707 a.Add ((Expression) $3);
3710 | member_initializer_list error {
3711 Error_SyntaxError (yyToken);
3717 : IDENTIFIER ASSIGN initializer_value
3719 var lt = (LocatedToken) $1;
3720 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3721 lbag.AddLocation ($$, GetLocation ($2));
3723 | AWAIT ASSIGN initializer_value
3725 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3726 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3727 lbag.AddLocation ($$, GetLocation ($2));
3729 | GENERATE_COMPLETION
3731 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3733 | non_assignment_expression opt_COMPLETE_COMPLETION {
3734 CompletionSimpleName csn = $1 as CompletionSimpleName;
3736 $$ = new CollectionElementInitializer ((Expression)$1);
3738 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3740 | OPEN_BRACE expression_list CLOSE_BRACE
3743 $$ = new CollectionElementInitializer (GetLocation ($1));
3745 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3747 lbag.AddLocation ($$, GetLocation ($3));
3749 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3751 if (lang_version < LanguageVersion.V_6)
3752 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3754 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3755 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3757 | OPEN_BRACE CLOSE_BRACE
3759 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3760 $$ = new CollectionElementInitializer (GetLocation ($1));
3761 lbag.AddLocation ($$, GetLocation ($2));
3767 | object_or_collection_initializer
3771 : /* empty */ { $$ = null; }
3776 : argument_or_named_argument
3778 Arguments list = new Arguments (4);
3779 list.Add ((Argument) $1);
3782 | argument_list COMMA argument
3784 Arguments list = (Arguments) $1;
3785 if (list [list.Count - 1] is NamedArgument)
3786 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3788 list.Add ((Argument) $3);
3791 | argument_list COMMA named_argument
3793 Arguments list = (Arguments) $1;
3794 NamedArgument a = (NamedArgument) $3;
3795 for (int i = 0; i < list.Count; ++i) {
3796 NamedArgument na = list [i] as NamedArgument;
3797 if (na != null && na.Name == a.Name)
3798 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3805 | argument_list COMMA error
3807 if (lexer.putback_char == -1)
3808 lexer.putback (')'); // TODO: Wrong but what can I do
3809 Error_SyntaxError (yyToken);
3814 report.Error (839, GetLocation ($1), "An argument is missing");
3822 $$ = new Argument ((Expression) $1);
3824 | non_simple_argument
3827 argument_or_named_argument
3833 : REF variable_reference
3835 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3836 lbag.AddLocation ($$, GetLocation ($1));
3838 | OUT variable_reference
3840 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3841 lbag.AddLocation ($$, GetLocation ($1));
3843 | OUT out_variable_declaration
3845 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3847 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3849 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3850 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3852 | ARGLIST OPEN_PARENS CLOSE_PARENS
3854 $$ = new Argument (new Arglist (GetLocation ($1)));
3855 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3859 out_variable_declaration
3860 : variable_type identifier_inside_body
3862 if (lang_version < LanguageVersion.V_7)
3863 FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
3865 var lt = (LocatedToken) $2;
3866 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3867 current_block.AddLocalName (lv);
3868 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3877 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3879 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3880 lbag.AddLocation ($$, GetLocation ($4));
3882 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3884 if (lang_version < LanguageVersion.V_6)
3885 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3887 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3888 ConditionalAccess = true
3891 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3893 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3895 Error_SyntaxError (yyToken);
3896 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3898 | primary_expression OPEN_BRACKET_EXPR error
3900 Error_SyntaxError (yyToken);
3901 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3906 : expression_or_error
3908 var list = new List<Expression> (4);
3909 list.Add ((Expression) $1);
3912 | expression_list COMMA expression_or_error
3914 var list = (List<Expression>) $1;
3915 list.Add ((Expression) $3);
3920 expression_list_arguments
3921 : expression_list_argument
3923 Arguments args = new Arguments (4);
3924 args.Add ((Argument) $1);
3927 | expression_list_arguments COMMA expression_list_argument
3929 Arguments args = (Arguments) $1;
3930 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3931 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3933 args.Add ((Argument) $3);
3938 expression_list_argument
3941 $$ = new Argument ((Expression) $1);
3949 $$ = new This (GetLocation ($1));
3954 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3956 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3957 lbag.AddLocation ($$, GetLocation ($4));
3959 | BASE OPEN_BRACKET error
3961 Error_SyntaxError (yyToken);
3962 $$ = new ElementAccess (null, null, GetLocation ($2));
3966 post_increment_expression
3967 : primary_expression OP_INC
3969 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3973 post_decrement_expression
3974 : primary_expression OP_DEC
3976 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3980 object_or_delegate_creation_expression
3981 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3984 if (lang_version <= LanguageVersion.ISO_2)
3985 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3987 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3989 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3992 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3994 | NEW new_expr_type object_or_collection_initializer
3996 if (lang_version <= LanguageVersion.ISO_2)
3997 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3999 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
4003 array_creation_expression
4004 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
4006 opt_array_initializer
4008 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
4009 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
4010 Next = (ComposedTypeSpecifier) $6
4011 }, (ArrayInitializer) $7, GetLocation ($1)) {
4012 NoEmptyInterpolation = true
4015 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4017 | NEW new_expr_type rank_specifiers opt_array_initializer
4020 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
4022 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
4023 NoEmptyInterpolation = true
4026 | NEW rank_specifier array_initializer
4028 if (lang_version <= LanguageVersion.ISO_2)
4029 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
4031 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
4033 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
4035 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
4036 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
4038 | NEW new_expr_type error
4040 Error_SyntaxError (yyToken);
4041 // It can be any of new expression, create the most common one
4042 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
4048 ++lexer.parsing_type;
4052 --lexer.parsing_type;
4057 anonymous_type_expression
4058 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
4060 if (lang_version <= LanguageVersion.ISO_2)
4061 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
4063 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
4065 // TODO: lbag comma location
4066 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4068 | NEW OPEN_BRACE GENERATE_COMPLETION
4070 $$ = new EmptyCompletion ();
4074 anonymous_type_parameters_opt_comma
4075 : anonymous_type_parameters_opt
4076 | anonymous_type_parameters COMMA
4079 anonymous_type_parameters_opt
4081 | anonymous_type_parameters
4084 anonymous_type_parameters
4085 : anonymous_type_parameter
4087 var a = new List<AnonymousTypeParameter> (4);
4088 a.Add ((AnonymousTypeParameter) $1);
4091 | anonymous_type_parameters COMMA anonymous_type_parameter
4093 var a = (List<AnonymousTypeParameter>) $1;
4094 a.Add ((AnonymousTypeParameter) $3);
4097 | COMPLETE_COMPLETION
4099 $$ = new EmptyCompletion ();
4101 | anonymous_type_parameter COMPLETE_COMPLETION
4107 anonymous_type_parameter
4108 : identifier_inside_body ASSIGN variable_initializer
4110 var lt = (LocatedToken)$1;
4111 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4112 lbag.AddLocation ($$, GetLocation ($2));
4114 | identifier_inside_body
4116 var lt = (LocatedToken)$1;
4117 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4118 lt.Value, lt.Location);
4122 MemberAccess ma = (MemberAccess) $1;
4123 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4127 report.Error (746, lexer.Location,
4128 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4140 | rank_specifier rank_specifiers
4142 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4148 : OPEN_BRACKET CLOSE_BRACKET
4150 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4151 lbag.AddLocation ($$, GetLocation ($2));
4153 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4155 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4156 lbag.AddLocation ($$, GetLocation ($3));
4165 | dim_separators COMMA
4167 $$ = ((int) $1) + 1;
4171 opt_array_initializer
4183 : OPEN_BRACE CLOSE_BRACE
4185 var ai = new ArrayInitializer (0, GetLocation ($1));
4186 ai.VariableDeclaration = current_variable;
4187 lbag.AddLocation (ai, GetLocation ($2));
4190 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4192 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4193 ai.VariableDeclaration = current_variable;
4195 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4197 lbag.AddLocation (ai, GetLocation ($4));
4203 variable_initializer_list
4204 : variable_initializer
4206 var list = new List<Expression> (4);
4207 list.Add ((Expression) $1);
4210 | variable_initializer_list COMMA variable_initializer
4212 var list = (List<Expression>) $1;
4213 list.Add ((Expression) $3);
4219 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4221 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4222 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4226 typeof_type_expression
4230 Error_TypeExpected (lexer.Location);
4238 if (lang_version < LanguageVersion.ISO_2)
4239 FeatureIsNotAvailable (GetLocation ($1), "generics");
4245 qualified_alias_member
4246 : IDENTIFIER DOUBLE_COLON
4248 var lt = (LocatedToken) $1;
4249 if (lang_version == LanguageVersion.ISO_1)
4250 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4257 : SIZEOF open_parens_any type CLOSE_PARENS
4259 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4260 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4262 | SIZEOF open_parens_any type error
4264 Error_SyntaxError (yyToken);
4266 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4267 lbag.AddLocation ($$, GetLocation ($2));
4272 : CHECKED open_parens_any expression CLOSE_PARENS
4274 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4275 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4279 Error_SyntaxError (yyToken);
4281 $$ = new CheckedExpr (null, GetLocation ($1));
4285 unchecked_expression
4286 : UNCHECKED open_parens_any expression CLOSE_PARENS
4288 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4289 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4293 Error_SyntaxError (yyToken);
4295 $$ = new UnCheckedExpr (null, GetLocation ($1));
4299 pointer_member_access
4300 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4302 var lt = (LocatedToken) $3;
4303 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4307 anonymous_method_expression
4308 : DELEGATE opt_anonymous_method_signature
4310 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4314 $$ = end_anonymous ((ParametersBlock) $4);
4316 | ASYNC DELEGATE opt_anonymous_method_signature
4318 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4322 $$ = end_anonymous ((ParametersBlock) $5);
4326 opt_anonymous_method_signature
4329 $$ = ParametersCompiled.Undefined;
4331 | anonymous_method_signature
4334 anonymous_method_signature
4337 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4339 opt_formal_parameter_list CLOSE_PARENS
4341 valid_param_mod = 0;
4346 default_value_expression
4347 : DEFAULT open_parens_any type CLOSE_PARENS
4349 if (lang_version < LanguageVersion.ISO_2)
4350 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4352 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4353 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4358 : primary_expression
4359 | BANG prefixed_unary_expression
4361 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4363 | TILDE prefixed_unary_expression
4365 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4367 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4369 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4370 lbag.AddLocation ($$, GetLocation ($3));
4372 | AWAIT prefixed_unary_expression
4375 if (current_anonymous_method is LambdaExpression) {
4376 report.Error (4034, GetLocation ($1),
4377 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4378 } else if (current_anonymous_method != null) {
4379 report.Error (4035, GetLocation ($1),
4380 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4381 } else if (interactive_async != null) {
4382 current_block.Explicit.RegisterAsyncAwait ();
4383 interactive_async = true;
4385 report.Error (4033, GetLocation ($1),
4386 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4389 current_block.Explicit.RegisterAsyncAwait ();
4392 $$ = new Await ((Expression) $2, GetLocation ($1));
4394 | THROW_EXPR prefixed_unary_expression
4396 if (lang_version < LanguageVersion.V_7)
4397 FeatureIsNotAvailable (lexer.Location, "throw expression");
4399 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4403 Error_SyntaxError (yyToken);
4405 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4409 Error_SyntaxError (yyToken);
4411 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4413 | OPEN_PARENS_CAST type CLOSE_PARENS error
4415 Error_SyntaxError (yyToken);
4417 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4418 lbag.AddLocation ($$, GetLocation ($3));
4422 Error_SyntaxError (yyToken);
4424 $$ = new Await (null, GetLocation ($1));
4429 // The idea to split this out is from Rhys' grammar
4430 // to solve the problem with casts.
4432 prefixed_unary_expression
4434 | PLUS prefixed_unary_expression
4436 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4438 | MINUS prefixed_unary_expression
4440 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4442 | OP_INC prefixed_unary_expression
4444 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4446 | OP_DEC prefixed_unary_expression
4448 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4450 | STAR prefixed_unary_expression
4452 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4454 | BITWISE_AND prefixed_unary_expression
4456 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4460 Error_SyntaxError (yyToken);
4462 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4466 Error_SyntaxError (yyToken);
4468 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4472 Error_SyntaxError (yyToken);
4474 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4478 Error_SyntaxError (yyToken);
4480 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4484 Error_SyntaxError (yyToken);
4486 $$ = new Indirection (null, GetLocation ($1));
4490 Error_SyntaxError (yyToken);
4492 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4495 multiplicative_expression
4496 : prefixed_unary_expression
4497 | multiplicative_expression STAR prefixed_unary_expression
4499 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4500 lbag.AddLocation ($$, GetLocation ($2));
4502 | multiplicative_expression DIV prefixed_unary_expression
4504 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4505 lbag.AddLocation ($$, GetLocation ($2));
4507 | multiplicative_expression PERCENT prefixed_unary_expression
4509 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4510 lbag.AddLocation ($$, GetLocation ($2));
4512 | multiplicative_expression STAR error
4514 Error_SyntaxError (yyToken);
4516 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4517 lbag.AddLocation ($$, GetLocation ($2));
4519 | multiplicative_expression DIV error
4521 Error_SyntaxError (yyToken);
4523 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4524 lbag.AddLocation ($$, GetLocation ($2));
4526 | multiplicative_expression PERCENT error
4528 Error_SyntaxError (yyToken);
4530 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4531 lbag.AddLocation ($$, GetLocation ($2));
4536 : multiplicative_expression
4537 | additive_expression PLUS multiplicative_expression
4539 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4540 lbag.AddLocation ($$, GetLocation ($2));
4542 | additive_expression MINUS multiplicative_expression
4544 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4545 lbag.AddLocation ($$, GetLocation ($2));
4547 | additive_expression PLUS error
4549 Error_SyntaxError (yyToken);
4551 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4552 lbag.AddLocation ($$, GetLocation ($2));
4554 | additive_expression MINUS error
4556 Error_SyntaxError (yyToken);
4558 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4559 lbag.AddLocation ($$, GetLocation ($2));
4561 | additive_expression AS type
4563 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4565 | additive_expression IS pattern_type_expr opt_identifier
4567 var is_expr = new Is ((Expression) $1, ((FullNamedExpression) $3), GetLocation ($2));
4569 if (lang_version < LanguageVersion.V_7)
4570 FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
4572 var lt = (LocatedToken) $4;
4573 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
4574 is_expr.Variable = lv;
4575 current_block.AddLocalName (lv);
4580 | additive_expression IS pattern_expr
4582 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4583 if (lang_version != LanguageVersion.Experimental)
4584 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4588 | additive_expression AS error
4590 Error_SyntaxError (yyToken);
4592 $$ = new As ((Expression) $1, null, GetLocation ($2));
4594 | additive_expression IS error
4596 Error_SyntaxError (yyToken);
4598 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4602 var lt = (LocatedToken) $1;
4603 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4607 var lt = (LocatedToken) $1;
4608 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4618 | PLUS prefixed_unary_expression
4620 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4622 | MINUS prefixed_unary_expression
4624 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4627 | default_value_expression
4628 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4630 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4631 lbag.AddLocation ($$, GetLocation ($3));
4635 $$ = new WildcardPattern (GetLocation ($1));
4637 /* | pattern_expr_invocation */
4642 pattern_expr_invocation
4643 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4645 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4651 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4653 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4657 pattern_property_list
4658 : pattern_property_entry
4660 var list = new List<PropertyPatternMember> ();
4661 list.Add ((PropertyPatternMember) $1);
4664 | pattern_property_list COMMA pattern_property_entry
4666 var list = (List<PropertyPatternMember>) $1;
4667 list.Add ((PropertyPatternMember) $3);
4672 pattern_property_entry
4673 : identifier_inside_body IS pattern
4675 var lt = (LocatedToken) $1;
4676 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4682 | pattern_type_expr opt_identifier
4685 var lt = (LocatedToken) $2;
4686 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4687 current_block.AddLocalName (variable);
4696 $$ = new Arguments (0);
4704 Arguments args = new Arguments (4);
4705 args.Add ((Argument) $1);
4708 | pattern_list COMMA pattern_argument
4710 Arguments args = (Arguments) $1;
4711 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4712 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4714 args.Add ((Argument) $3);
4723 $$ = new Argument ((Expression) $1);
4725 | IDENTIFIER COLON pattern
4727 var lt = (LocatedToken) $1;
4728 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4734 : additive_expression
4735 | shift_expression OP_SHIFT_LEFT additive_expression
4737 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4738 lbag.AddLocation ($$, GetLocation ($2));
4740 | shift_expression OP_SHIFT_RIGHT additive_expression
4742 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4743 lbag.AddLocation ($$, GetLocation ($2));
4745 | shift_expression OP_SHIFT_LEFT error
4747 Error_SyntaxError (yyToken);
4749 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4750 lbag.AddLocation ($$, GetLocation ($2));
4752 | shift_expression OP_SHIFT_RIGHT error
4754 Error_SyntaxError (yyToken);
4756 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4757 lbag.AddLocation ($$, GetLocation ($2));
4761 relational_expression
4763 | relational_expression OP_LT shift_expression
4765 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4766 lbag.AddLocation ($$, GetLocation ($2));
4768 | relational_expression OP_GT shift_expression
4770 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4771 lbag.AddLocation ($$, GetLocation ($2));
4773 | relational_expression OP_LE shift_expression
4775 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4776 lbag.AddLocation ($$, GetLocation ($2));
4778 | relational_expression OP_GE shift_expression
4780 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4781 lbag.AddLocation ($$, GetLocation ($2));
4783 | relational_expression OP_LT error
4785 Error_SyntaxError (yyToken);
4787 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4788 lbag.AddLocation ($$, GetLocation ($2));
4790 | relational_expression OP_GT error
4792 Error_SyntaxError (yyToken);
4794 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4795 lbag.AddLocation ($$, GetLocation ($2));
4797 | relational_expression OP_LE error
4799 Error_SyntaxError (yyToken);
4801 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4802 lbag.AddLocation ($$, GetLocation ($2));
4804 | relational_expression OP_GE error
4806 Error_SyntaxError (yyToken);
4808 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4809 lbag.AddLocation ($$, GetLocation ($2));
4814 : relational_expression
4815 | equality_expression OP_EQ relational_expression
4817 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4818 lbag.AddLocation ($$, GetLocation ($2));
4820 | equality_expression OP_NE relational_expression
4822 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4823 lbag.AddLocation ($$, GetLocation ($2));
4825 | equality_expression OP_EQ error
4827 Error_SyntaxError (yyToken);
4829 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4830 lbag.AddLocation ($$, GetLocation ($2));
4832 | equality_expression OP_NE error
4834 Error_SyntaxError (yyToken);
4836 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4837 lbag.AddLocation ($$, GetLocation ($2));
4842 : equality_expression
4843 | and_expression BITWISE_AND equality_expression
4845 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4846 lbag.AddLocation ($$, GetLocation ($2));
4848 | and_expression BITWISE_AND error
4850 Error_SyntaxError (yyToken);
4852 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4853 lbag.AddLocation ($$, GetLocation ($2));
4857 exclusive_or_expression
4859 | exclusive_or_expression CARRET and_expression
4861 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4862 lbag.AddLocation ($$, GetLocation ($2));
4864 | exclusive_or_expression CARRET error
4866 Error_SyntaxError (yyToken);
4868 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4869 lbag.AddLocation ($$, GetLocation ($2));
4873 inclusive_or_expression
4874 : exclusive_or_expression
4875 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4877 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4878 lbag.AddLocation ($$, GetLocation ($2));
4880 | inclusive_or_expression BITWISE_OR error
4882 Error_SyntaxError (yyToken);
4884 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4885 lbag.AddLocation ($$, GetLocation ($2));
4889 conditional_and_expression
4890 : inclusive_or_expression
4891 | conditional_and_expression OP_AND inclusive_or_expression
4893 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4894 lbag.AddLocation ($$, GetLocation ($2));
4896 | conditional_and_expression OP_AND error
4898 Error_SyntaxError (yyToken);
4900 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4901 lbag.AddLocation ($$, GetLocation ($2));
4905 conditional_or_expression
4906 : conditional_and_expression
4907 | conditional_or_expression OP_OR conditional_and_expression
4909 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4910 lbag.AddLocation ($$, GetLocation ($2));
4912 | conditional_or_expression OP_OR error
4914 Error_SyntaxError (yyToken);
4916 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4917 lbag.AddLocation ($$, GetLocation ($2));
4921 null_coalescing_expression
4922 : conditional_or_expression
4923 | conditional_or_expression OP_COALESCING null_coalescing_expression
4925 if (lang_version < LanguageVersion.ISO_2)
4926 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4928 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4929 lbag.AddLocation ($$, GetLocation ($2));
4933 conditional_expression
4934 : null_coalescing_expression
4935 | null_coalescing_expression INTERR expression COLON expression
4937 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4938 lbag.AddLocation ($$, GetLocation ($4));
4940 | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4942 if (lang_version < LanguageVersion.V_7)
4943 FeatureIsNotAvailable (lexer.Location, "throw expression");
4945 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4946 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4947 lbag.AddLocation ($$, GetLocation ($4));
4949 | null_coalescing_expression INTERR expression error
4951 Error_SyntaxError (yyToken);
4953 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4955 | null_coalescing_expression INTERR expression COLON error
4957 Error_SyntaxError (yyToken);
4959 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4960 lbag.AddLocation ($$, GetLocation ($4));
4962 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4964 Error_SyntaxError (Token.CLOSE_BRACE);
4966 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4967 lbag.AddLocation ($$, GetLocation ($4));
4968 lexer.putback ('}');
4972 assignment_expression
4973 : prefixed_unary_expression ASSIGN expression
4975 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4976 lbag.AddLocation ($$, GetLocation ($2));
4978 | prefixed_unary_expression OP_MULT_ASSIGN expression
4980 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4981 lbag.AddLocation ($$, GetLocation ($2));
4983 | prefixed_unary_expression OP_DIV_ASSIGN expression
4985 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4986 lbag.AddLocation ($$, GetLocation ($2));
4988 | prefixed_unary_expression OP_MOD_ASSIGN expression
4990 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4991 lbag.AddLocation ($$, GetLocation ($2));
4993 | prefixed_unary_expression OP_ADD_ASSIGN expression
4995 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4996 lbag.AddLocation ($$, GetLocation ($2));
4998 | prefixed_unary_expression OP_SUB_ASSIGN expression
5000 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
5001 lbag.AddLocation ($$, GetLocation ($2));
5003 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
5005 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
5006 lbag.AddLocation ($$, GetLocation ($2));
5008 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
5010 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
5011 lbag.AddLocation ($$, GetLocation ($2));
5013 | prefixed_unary_expression OP_AND_ASSIGN expression
5015 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
5016 lbag.AddLocation ($$, GetLocation ($2));
5018 | prefixed_unary_expression OP_OR_ASSIGN expression
5020 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
5021 lbag.AddLocation ($$, GetLocation ($2));
5023 | prefixed_unary_expression OP_XOR_ASSIGN expression
5025 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
5026 lbag.AddLocation ($$, GetLocation ($2));
5028 | OPEN_PARENS_DECONSTRUCT deconstruct_exprs CLOSE_PARENS ASSIGN expression
5030 if (lang_version < LanguageVersion.V_7)
5031 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5033 var exprs = (List<Expression>) $2;
5034 $$ = new TupleDeconstruct (exprs, (Expression) $5, GetLocation ($4));
5039 : expression COMMA expression
5041 $$ = new List<Expression> () {
5046 | deconstruct_exprs COMMA expression
5048 var src = (List<Expression>) $1;
5049 src.Add ((Expression) $3);
5054 lambda_parameter_list
5057 var pars = new List<Parameter> (4);
5058 pars.Add ((Parameter) $1);
5062 | lambda_parameter_list COMMA lambda_parameter
5064 var pars = (List<Parameter>) $1;
5065 Parameter p = (Parameter)$3;
5066 if (pars[0].GetType () != p.GetType ()) {
5067 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
5076 : parameter_modifier parameter_type identifier_inside_body
5078 var lt = (LocatedToken) $3;
5080 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
5082 | parameter_type identifier_inside_body
5084 var lt = (LocatedToken) $2;
5086 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
5090 var lt = (LocatedToken) $1;
5091 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5095 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5096 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5100 opt_lambda_parameter_list
5101 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
5102 | lambda_parameter_list {
5103 var pars_list = (List<Parameter>) $1;
5104 $$ = new ParametersCompiled (pars_list.ToArray ());
5108 lambda_expression_body
5110 start_block (Location.Null);
5112 expression // All expressions must handle error or current block won't be restored and breaking ast completely
5114 Block b = end_block (Location.Null);
5115 b.IsCompilerGenerated = true;
5116 b.AddStatement (new ContextualReturn ((Expression) $2));
5122 // Handles only cases like foo = x.FirstOrDefault (l => );
5123 // where we must restore current_variable
5124 Block b = end_block (Location.Null);
5125 b.IsCompilerGenerated = true;
5127 Error_SyntaxError (yyToken);
5136 Error_SyntaxError (yyToken);
5144 var lt = (LocatedToken) $1;
5145 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5146 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5148 lambda_expression_body
5150 $$ = end_anonymous ((ParametersBlock) $4);
5151 lbag.AddLocation ($$, GetLocation ($2));
5155 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5156 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5157 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5159 lambda_expression_body
5161 $$ = end_anonymous ((ParametersBlock) $4);
5162 lbag.AddLocation ($$, GetLocation ($2));
5164 | ASYNC identifier_inside_body ARROW
5166 var lt = (LocatedToken) $2;
5167 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5168 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5170 lambda_expression_body
5172 $$ = end_anonymous ((ParametersBlock) $5);
5173 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5175 | OPEN_PARENS_LAMBDA
5177 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5179 opt_lambda_parameter_list CLOSE_PARENS ARROW
5181 valid_param_mod = 0;
5182 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5184 lambda_expression_body
5186 $$ = end_anonymous ((ParametersBlock) $7);
5187 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5189 | ASYNC OPEN_PARENS_LAMBDA
5191 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5193 opt_lambda_parameter_list CLOSE_PARENS ARROW
5195 valid_param_mod = 0;
5196 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5198 lambda_expression_body
5200 $$ = end_anonymous ((ParametersBlock) $8);
5201 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5206 : assignment_expression
5207 | non_assignment_expression
5210 non_assignment_expression
5211 : conditional_expression
5216 $$ = new ArglistAccess (GetLocation ($1));
5220 undocumented_expressions
5221 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5223 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5224 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5226 | REFTYPE open_parens_any expression CLOSE_PARENS
5228 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5229 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5231 | MAKEREF open_parens_any expression CLOSE_PARENS
5233 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5234 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5245 $$ = new BooleanExpression ((Expression) $1);
5249 opt_primary_parameters
5254 | primary_parameters
5258 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5262 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5263 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5265 if (lang_version != LanguageVersion.Experimental)
5266 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5270 opt_primary_parameters_with_class_base
5279 | primary_parameters
5283 | primary_parameters class_base
5287 | primary_parameters class_base OPEN_PARENS
5289 ++lexer.parsing_block;
5290 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5292 opt_argument_list CLOSE_PARENS
5294 lbag.AppendToMember (current_container, GetLocation ($6));
5295 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5296 --lexer.parsing_block;
5312 type_declaration_name
5314 lexer.ConstraintsParsing = true;
5316 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5317 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5318 FeatureIsNotAvailable (c.Location, "static classes");
5321 push_current_container (c, $3);
5322 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5324 opt_primary_parameters_with_class_base
5325 opt_type_parameter_constraints_clauses
5327 valid_param_mod = 0;
5328 lexer.ConstraintsParsing = false;
5331 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5334 current_container.SetConstraints ((List<Constraints>) $9);
5335 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5338 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5339 Lexer.doc_state = XmlCommentState.Allowed;
5342 lexer.parsing_modifiers = true;
5344 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5346 --lexer.parsing_declaration;
5348 Lexer.doc_state = XmlCommentState.Allowed;
5353 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5355 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5357 $$ = pop_current_class ();
5365 { $$ = $1; } // location
5371 mod_locations = null;
5373 lexer.parsing_modifiers = false;
5377 lexer.parsing_modifiers = false;
5383 | modifiers modifier
5385 var m1 = (Modifiers) $1;
5386 var m2 = (Modifiers) $2;
5388 if ((m1 & m2) != 0) {
5389 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5390 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5391 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5392 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5393 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5394 "More than one protection modifier specified");
5405 StoreModifierLocation ($$, GetLocation ($1));
5407 if (current_container.Kind == MemberKind.Namespace)
5408 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5412 $$ = Modifiers.PUBLIC;
5413 StoreModifierLocation ($$, GetLocation ($1));
5417 $$ = Modifiers.PROTECTED;
5418 StoreModifierLocation ($$, GetLocation ($1));
5422 $$ = Modifiers.INTERNAL;
5423 StoreModifierLocation ($$, GetLocation ($1));
5427 $$ = Modifiers.PRIVATE;
5428 StoreModifierLocation ($$, GetLocation ($1));
5432 $$ = Modifiers.ABSTRACT;
5433 StoreModifierLocation ($$, GetLocation ($1));
5437 $$ = Modifiers.SEALED;
5438 StoreModifierLocation ($$, GetLocation ($1));
5442 $$ = Modifiers.STATIC;
5443 StoreModifierLocation ($$, GetLocation ($1));
5447 $$ = Modifiers.READONLY;
5448 StoreModifierLocation ($$, GetLocation ($1));
5452 $$ = Modifiers.VIRTUAL;
5453 StoreModifierLocation ($$, GetLocation ($1));
5457 $$ = Modifiers.OVERRIDE;
5458 StoreModifierLocation ($$, GetLocation ($1));
5462 $$ = Modifiers.EXTERN;
5463 StoreModifierLocation ($$, GetLocation ($1));
5467 $$ = Modifiers.VOLATILE;
5468 StoreModifierLocation ($$, GetLocation ($1));
5472 $$ = Modifiers.UNSAFE;
5473 StoreModifierLocation ($$, GetLocation ($1));
5474 if (!settings.Unsafe)
5475 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5479 $$ = Modifiers.ASYNC;
5480 StoreModifierLocation ($$, GetLocation ($1));
5492 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5494 | COLON type_list error
5496 Error_SyntaxError (yyToken);
5498 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5502 opt_type_parameter_constraints_clauses
5504 | type_parameter_constraints_clauses
5510 type_parameter_constraints_clauses
5511 : type_parameter_constraints_clause
5513 var constraints = new List<Constraints> (1);
5514 constraints.Add ((Constraints) $1);
5517 | type_parameter_constraints_clauses type_parameter_constraints_clause
5519 var constraints = (List<Constraints>) $1;
5520 Constraints new_constraint = (Constraints)$2;
5522 foreach (Constraints c in constraints) {
5523 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5524 report.Error (409, new_constraint.Location,
5525 "A constraint clause has already been specified for type parameter `{0}'",
5526 new_constraint.TypeParameter.Value);
5530 constraints.Add (new_constraint);
5535 type_parameter_constraints_clause
5536 : WHERE IDENTIFIER COLON type_parameter_constraints
5538 var lt = (LocatedToken) $2;
5539 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5540 lbag.AddLocation ($$, GetLocation ($3));
5542 | WHERE IDENTIFIER error
5544 Error_SyntaxError (yyToken);
5546 var lt = (LocatedToken) $2;
5547 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5551 type_parameter_constraints
5552 : type_parameter_constraint
5554 var constraints = new List<FullNamedExpression> (1);
5555 constraints.Add ((FullNamedExpression) $1);
5558 | type_parameter_constraints COMMA type_parameter_constraint
5560 var constraints = (List<FullNamedExpression>) $1;
5561 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5562 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5563 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5566 prev = $3 as SpecialContraintExpr;
5568 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5569 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5571 prev = constraints [0] as SpecialContraintExpr;
5572 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5573 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5578 constraints.Add ((FullNamedExpression) $3);
5583 type_parameter_constraint
5586 if ($1 is ComposedCast)
5587 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5591 | NEW OPEN_PARENS CLOSE_PARENS
5593 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5594 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5598 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5602 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5606 opt_type_parameter_variance
5611 | type_parameter_variance
5613 if (lang_version <= LanguageVersion.V_3)
5614 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5620 type_parameter_variance
5623 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5627 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5636 // A block is "contained" on the following places:
5638 // property_declaration as part of the accessor body (get/set)
5639 // operator_declaration
5640 // constructor_declaration
5641 // destructor_declaration
5642 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5647 ++lexer.parsing_block;
5648 start_block (GetLocation ($1));
5650 opt_statement_list block_end
5659 --lexer.parsing_block;
5660 $$ = end_block (GetLocation ($1));
5662 | COMPLETE_COMPLETION
5664 --lexer.parsing_block;
5665 $$ = end_block (lexer.Location);
5673 ++lexer.parsing_block;
5674 current_block.StartLocation = GetLocation ($1);
5676 opt_statement_list CLOSE_BRACE
5678 --lexer.parsing_block;
5679 $$ = end_block (GetLocation ($4));
5690 | statement_list statement
5694 : block_variable_declaration
5696 current_block.AddStatement ((Statement) $1);
5698 | valid_declaration_statement
5700 current_block.AddStatement ((Statement) $1);
5705 Error_SyntaxError (yyToken);
5711 // The interactive_statement and its derivatives are only
5712 // used to provide a special version of `expression_statement'
5713 // that has a side effect of assigning the expression to
5716 interactive_statement_list
5717 : interactive_statement
5718 | interactive_statement_list interactive_statement
5721 interactive_statement
5722 : block_variable_declaration
5724 current_block.AddStatement ((Statement) $1);
5726 | interactive_valid_declaration_statement
5728 current_block.AddStatement ((Statement) $1);
5733 valid_declaration_statement
5736 | expression_statement
5737 | selection_statement
5738 | iteration_statement
5742 | unchecked_statement
5749 interactive_valid_declaration_statement
5752 | interactive_expression_statement
5753 | selection_statement
5754 | iteration_statement
5758 | unchecked_statement
5766 : valid_declaration_statement
5767 | block_variable_declaration
5769 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5774 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5779 Error_SyntaxError (yyToken);
5780 $$ = new EmptyStatement (GetLocation ($1));
5787 // Uses lexer.Location because semicolon location is not kept in quick mode
5788 $$ = new EmptyStatement (lexer.Location);
5793 : identifier_inside_body COLON
5795 var lt = (LocatedToken) $1;
5796 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5797 lbag.AddLocation (labeled, GetLocation ($2));
5798 current_block.AddLabel (labeled);
5799 current_block.AddStatement (labeled);
5805 : variable_type_simple
5806 | variable_type_simple rank_specifiers
5809 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5811 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5816 * The following is from Rhys' grammar:
5817 * > Types in local variable declarations must be recognized as
5818 * > expressions to prevent reduce/reduce errors in the grammar.
5819 * > The expressions are converted into types during semantic analysis.
5821 variable_type_simple
5822 : type_name_expression opt_nullable
5824 var expr = (ATypeNameExpression) $1;
5826 if (expr.Name == "var" && expr is SimpleName)
5827 $$ = new VarExpr (expr.Location);
5831 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5834 | type_name_expression pointer_stars
5836 var expr = (ATypeNameExpression) $1;
5837 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5839 | builtin_type_expression
5840 | tuple_type opt_nullable
5845 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5851 : OPEN_PARENS tuple_type_elements CLOSE_PARENS
5853 if (lang_version < LanguageVersion.V_7)
5854 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5856 var a = (Tuple<TypeArguments, List<string>>) $2;
5858 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
5863 : variable_type IDENTIFIER /* opt_identifier */ COMMA variable_type IDENTIFIER /* opt_identifier */
5865 var type_args = new TypeArguments ();
5867 type_args.Add ((FullNamedExpression) $1);
5868 type_args.Add ((FullNamedExpression) $4);
5870 var names = new List<string> (2);
5871 var lt = (LocatedToken) $2;
5872 names.Add (lt?.Value);
5873 lt = (LocatedToken) $5;
5874 names.Add (lt?.Value);
5876 $$ = Tuple.Create (type_args, names);
5878 | tuple_type_elements COMMA variable_type IDENTIFIER /* opt_identifier */
5880 var a = (Tuple<TypeArguments, List<string>>) $1;
5881 a.Item1.Add ((FullNamedExpression) $3);
5882 var lt = (LocatedToken) $4;
5883 a.Item2.Add (lt?.Value);
5890 | pointer_star pointer_stars
5892 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5900 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5904 identifier_inside_body
5908 $$ = Error_AwaitAsIdentifier ($1);
5912 block_variable_declaration
5913 : variable_type identifier_inside_body
5915 var lt = (LocatedToken) $2;
5916 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5917 current_block.AddLocalName (li);
5918 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5920 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5922 $$ = current_variable;
5923 current_variable = null;
5925 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5927 lbag.AddLocation ($$, GetLocation ($6));
5929 | CONST variable_type identifier_inside_body
5931 var lt = (LocatedToken) $3;
5932 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5933 current_block.AddLocalName (li);
5934 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5936 const_variable_initializer opt_const_declarators SEMICOLON
5938 $$ = current_variable;
5939 current_variable = null;
5940 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5944 opt_local_variable_initializer
5946 | ASSIGN block_variable_initializer
5948 current_variable.Initializer = (Expression) $2;
5949 PushLocation (GetLocation ($1));
5950 $$ = current_variable;
5954 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5955 report.Error (650, lexer.Location,
5956 "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");
5958 Error_SyntaxError (yyToken);
5963 opt_variable_declarators
5965 | variable_declarators
5968 opt_using_or_fixed_variable_declarators
5970 | variable_declarators
5972 foreach (var d in current_variable.Declarators) {
5973 if (d.Initializer == null)
5974 Error_MissingInitializer (d.Variable.Location);
5979 variable_declarators
5980 : variable_declarator
5981 | variable_declarators variable_declarator
5985 : COMMA identifier_inside_body
5987 var lt = (LocatedToken) $2;
5988 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5989 var d = new BlockVariableDeclarator (li, null);
5990 current_variable.AddDeclarator (d);
5991 current_block.AddLocalName (li);
5992 lbag.AddLocation (d, GetLocation ($1));
5994 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5996 var lt = (LocatedToken) $2;
5997 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5998 var d = new BlockVariableDeclarator (li, (Expression) $4);
5999 current_variable.AddDeclarator (d);
6000 current_block.AddLocalName (li);
6001 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6005 const_variable_initializer
6008 report.Error (145, lexer.Location, "A const field requires a value to be provided");
6010 | ASSIGN constant_initializer_expr
6012 current_variable.Initializer = (Expression) $2;
6016 opt_const_declarators
6023 | const_declarators const_declarator
6027 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
6029 var lt = (LocatedToken) $2;
6030 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
6031 var d = new BlockVariableDeclarator (li, (Expression) $4);
6032 current_variable.AddDeclarator (d);
6033 current_block.AddLocalName (li);
6034 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6038 block_variable_initializer
6039 : variable_initializer
6040 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
6042 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
6043 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6045 | STACKALLOC simple_type
6047 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
6048 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
6052 expression_statement
6053 : statement_expression SEMICOLON
6056 lbag.AddStatement ($$, GetLocation ($2));
6058 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
6059 | statement_expression CLOSE_BRACE
6062 report.Error (1002, GetLocation ($2), "; expected");
6063 lexer.putback ('}');
6067 interactive_expression_statement
6068 : interactive_statement_expression SEMICOLON { $$ = $1; }
6069 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
6073 // We have to do the wrapping here and not in the case above,
6074 // because statement_expression is used for example in for_statement
6076 statement_expression
6079 ExpressionStatement s = $1 as ExpressionStatement;
6081 var expr = $1 as Expression;
6082 $$ = new StatementErrorExpression (expr);
6084 $$ = new StatementExpression (s);
6089 interactive_statement_expression
6092 Expression expr = (Expression) $1;
6093 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
6097 Error_SyntaxError (yyToken);
6098 $$ = new EmptyStatement (GetLocation ($1));
6108 : IF open_parens_any boolean_expression CLOSE_PARENS
6111 if ($5 is EmptyStatement)
6112 Warning_EmptyStatement (GetLocation ($5));
6114 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6115 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6117 | IF open_parens_any boolean_expression CLOSE_PARENS
6118 embedded_statement ELSE embedded_statement
6120 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
6121 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
6123 if ($5 is EmptyStatement)
6124 Warning_EmptyStatement (GetLocation ($5));
6125 if ($7 is EmptyStatement)
6126 Warning_EmptyStatement (GetLocation ($7));
6128 | IF open_parens_any boolean_expression error
6130 Error_SyntaxError (yyToken);
6132 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
6133 lbag.AddStatement ($$, GetLocation ($2));
6138 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
6140 start_block (GetLocation ($5));
6142 opt_switch_sections CLOSE_BRACE
6144 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
6145 end_block (GetLocation ($8));
6146 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6148 | SWITCH open_parens_any expression error
6150 Error_SyntaxError (yyToken);
6152 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
6153 lbag.AddStatement ($$, GetLocation ($2));
6160 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6167 | switch_sections switch_section
6170 Error_SyntaxError (yyToken);
6175 : switch_labels statement_list
6181 var label = (SwitchLabel) $1;
6182 label.SectionStart = true;
6183 current_block.AddStatement (label);
6185 | switch_labels switch_label
6187 current_block.AddStatement ((Statement) $2);
6192 : CASE constant_expression COLON
6194 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6195 lbag.AddLocation ($$, GetLocation ($3));
6197 | CASE constant_expression error
6199 Error_SyntaxError (yyToken);
6200 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6203 | CASE pattern_expr_invocation COLON
6205 if (lang_version != LanguageVersion.Experimental)
6206 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6208 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6209 PatternMatching = true
6211 lbag.AddLocation ($$, GetLocation ($3));
6215 | CASE pattern_type_expr IDENTIFIER COLON
6217 if (lang_version < LanguageVersion.V_7)
6218 FeatureIsNotAvailable (GetLocation ($1), "pattern matching");
6220 // $$ = new SwitchLabel ((FullNamedExpression) $2), GetLocation ($1)) {
6221 // PatternMatching = true
6224 throw new NotImplementedException ("type pattern matching");
6228 $$ = new SwitchLabel (null, GetLocation ($1));
6240 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6242 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6243 Warning_EmptyStatement (GetLocation ($5));
6245 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6246 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6248 | WHILE open_parens_any boolean_expression error
6250 Error_SyntaxError (yyToken);
6252 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6253 lbag.AddStatement ($$, GetLocation ($2));
6258 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6260 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6261 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6263 | DO embedded_statement error
6265 Error_SyntaxError (yyToken);
6266 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6268 | DO embedded_statement WHILE open_parens_any boolean_expression error
6270 Error_SyntaxError (yyToken);
6272 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6273 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6278 : FOR open_parens_any
6280 start_block (GetLocation ($2));
6281 current_block.IsCompilerGenerated = true;
6282 For f = new For (GetLocation ($1));
6283 current_block.AddStatement (f);
6292 // Has to use be extra rule to recover started block
6294 : opt_for_initializer SEMICOLON
6296 ((For) $0).Initializer = (Statement) $1;
6298 // Pass the "For" object to the iterator_part4
6299 oob_stack.Push ($0);
6301 for_condition_and_iterator_part
6304 var locations = (Tuple<Location,Location>) $4;
6306 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6307 Warning_EmptyStatement (GetLocation ($5));
6310 f.Statement = (Statement) $5;
6311 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6313 $$ = end_block (GetLocation ($2));
6317 Error_SyntaxError (yyToken);
6318 $$ = end_block (current_block.StartLocation);
6322 for_condition_and_iterator_part
6323 : opt_for_condition SEMICOLON
6325 For f = (For) oob_stack.Peek ();
6326 f.Condition = (BooleanExpression) $1;
6329 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6332 // Handle errors in the case of opt_for_condition being followed by
6333 // a close parenthesis
6334 | opt_for_condition close_parens_close_brace {
6335 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6336 For f = (For) oob_stack.Peek ();
6337 f.Condition = (BooleanExpression) $1;
6338 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6343 : opt_for_iterator CLOSE_PARENS {
6344 For f = (For) oob_stack.Peek ();
6345 f.Iterator = (Statement) $1;
6346 $$ = GetLocation ($2);
6348 | opt_for_iterator CLOSE_BRACE {
6349 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6350 For f = (For) oob_stack.Peek ();
6351 f.Iterator = (Statement) $1;
6352 $$ = GetLocation ($2);
6356 close_parens_close_brace
6358 | CLOSE_BRACE { lexer.putback ('}'); }
6362 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6367 : variable_type identifier_inside_body
6369 var lt = (LocatedToken) $2;
6370 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6371 current_block.AddLocalName (li);
6372 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6374 opt_local_variable_initializer opt_variable_declarators
6376 $$ = current_variable;
6378 lbag.AddLocation (current_variable, PopLocation ());
6380 current_variable = null;
6382 | statement_expression_list
6386 : /* empty */ { $$ = null; }
6387 | boolean_expression
6391 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6396 : statement_expression_list
6399 statement_expression_list
6400 : statement_expression
6401 | statement_expression_list COMMA statement_expression
6403 var sl = $1 as StatementList;
6405 sl = new StatementList ((Statement) $1, (Statement) $3);
6406 lbag.AddStatement (sl, GetLocation ($2));
6408 sl.Add ((Statement) $3);
6409 lbag.AppendTo (sl, GetLocation ($2));
6417 : FOREACH open_parens_any type error
6419 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6421 start_block (GetLocation ($2));
6422 current_block.IsCompilerGenerated = true;
6424 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6425 current_block.AddStatement (f);
6427 lbag.AddStatement (f, GetLocation ($2));
6428 $$ = end_block (GetLocation ($4));
6430 | FOREACH open_parens_any type identifier_inside_body error
6432 Error_SyntaxError (yyToken);
6434 start_block (GetLocation ($2));
6435 current_block.IsCompilerGenerated = true;
6437 var lt = (LocatedToken) $4;
6438 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6439 current_block.AddLocalName (li);
6441 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6442 current_block.AddStatement (f);
6444 lbag.AddStatement (f, GetLocation ($2));
6445 $$ = end_block (GetLocation ($5));
6447 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6449 start_block (GetLocation ($2));
6450 current_block.IsCompilerGenerated = true;
6452 var lt = (LocatedToken) $4;
6453 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6454 current_block.AddLocalName (li);
6459 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6460 Warning_EmptyStatement (GetLocation ($9));
6462 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6463 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6464 end_block (GetLocation ($7));
6472 | continue_statement
6482 $$ = new Break (GetLocation ($1));
6483 lbag.AddStatement ($$, GetLocation ($2));
6488 : CONTINUE SEMICOLON
6490 $$ = new Continue (GetLocation ($1));
6491 lbag.AddStatement ($$, GetLocation ($2));
6495 Error_SyntaxError (yyToken);
6496 $$ = new Continue (GetLocation ($1));
6501 : GOTO identifier_inside_body SEMICOLON
6503 var lt = (LocatedToken) $2;
6504 $$ = new Goto (lt.Value, GetLocation ($1));
6505 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6507 | GOTO CASE constant_expression SEMICOLON
6509 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6510 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6512 | GOTO DEFAULT SEMICOLON
6514 $$ = new GotoDefault (GetLocation ($1));
6515 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6520 : RETURN opt_expression SEMICOLON
6522 $$ = new Return ((Expression) $2, GetLocation ($1));
6523 lbag.AddStatement ($$, GetLocation ($3));
6525 | RETURN expression error
6527 Error_SyntaxError (yyToken);
6528 $$ = new Return ((Expression) $2, GetLocation ($1));
6532 Error_SyntaxError (yyToken);
6533 $$ = new Return (null, GetLocation ($1));
6538 : THROW expression SEMICOLON
6540 $$ = new Throw ((Expression) $2, GetLocation ($1));
6541 lbag.AddStatement ($$, GetLocation ($3));
6545 $$ = new Throw (null, GetLocation ($1));
6546 lbag.AddStatement ($$, GetLocation ($2));
6548 | THROW expression error
6550 Error_SyntaxError (yyToken);
6551 $$ = new Throw ((Expression) $2, GetLocation ($1));
6555 Error_SyntaxError (yyToken);
6556 $$ = new Throw (null, GetLocation ($1));
6561 : identifier_inside_body RETURN opt_expression SEMICOLON
6563 var lt = (LocatedToken) $1;
6564 string s = lt.Value;
6566 report.Error (1003, lt.Location, "; expected");
6567 } else if ($3 == null) {
6568 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6569 } else if (lang_version == LanguageVersion.ISO_1){
6570 FeatureIsNotAvailable (lt.Location, "iterators");
6573 current_block.Explicit.RegisterIteratorYield ();
6574 $$ = new Yield ((Expression) $3, lt.Location);
6575 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6577 | identifier_inside_body RETURN expression error
6579 Error_SyntaxError (yyToken);
6581 var lt = (LocatedToken) $1;
6582 string s = lt.Value;
6584 report.Error (1003, lt.Location, "; expected");
6585 } else if ($3 == null) {
6586 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6587 } else if (lang_version == LanguageVersion.ISO_1){
6588 FeatureIsNotAvailable (lt.Location, "iterators");
6591 current_block.Explicit.RegisterIteratorYield ();
6592 $$ = new Yield ((Expression) $3, lt.Location);
6593 lbag.AddStatement ($$, GetLocation ($2));
6595 | identifier_inside_body BREAK SEMICOLON
6597 var lt = (LocatedToken) $1;
6598 string s = lt.Value;
6600 report.Error (1003, lt.Location, "; expected");
6601 } else if (lang_version == LanguageVersion.ISO_1){
6602 FeatureIsNotAvailable (lt.Location, "iterators");
6605 current_block.ParametersBlock.TopBlock.IsIterator = true;
6606 $$ = new YieldBreak (lt.Location);
6607 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6617 : TRY block catch_clauses
6619 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6621 | TRY block FINALLY block
6623 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6624 lbag.AddStatement ($$, GetLocation ($3));
6626 | TRY block catch_clauses FINALLY block
6628 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6629 lbag.AddStatement ($$, GetLocation ($4));
6633 Error_SyntaxError (1524, yyToken);
6634 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6641 var l = new List<Catch> (2);
6646 | catch_clauses catch_clause
6648 var l = (List<Catch>) $1;
6650 Catch c = (Catch) $2;
6651 var prev_catch = l [l.Count - 1];
6652 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6653 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6663 | identifier_inside_body
6667 : CATCH opt_catch_filter block
6669 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6670 c.Filter = (CatchFilterExpression) $2;
6673 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6675 start_block (GetLocation ($2));
6676 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6677 c.TypeExpression = (FullNamedExpression) $3;
6680 var lt = (LocatedToken) $4;
6681 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6682 current_block.AddLocalName (c.Variable);
6685 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6687 lexer.parsing_catch_when = true;
6689 opt_catch_filter_or_error
6691 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6694 | CATCH open_parens_any error
6696 if (yyToken == Token.CLOSE_PARENS) {
6697 report.Error (1015, lexer.Location,
6698 "A type that derives from `System.Exception', `object', or `string' expected");
6700 Error_SyntaxError (yyToken);
6703 $$ = new Catch (null, GetLocation ($1));
6707 opt_catch_filter_or_error
6708 : opt_catch_filter block_prepared
6714 end_block (Location.Null);
6715 Error_SyntaxError (yyToken);
6722 lexer.parsing_catch_when = false;
6726 lexer.parsing_catch_when = false;
6728 open_parens_any expression CLOSE_PARENS
6730 if (lang_version <= LanguageVersion.V_5)
6731 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6733 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6734 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6741 $$ = new Checked ((Block) $2, GetLocation ($1));
6748 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6755 if (!settings.Unsafe)
6756 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6758 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6763 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6765 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6766 Warning_EmptyStatement (GetLocation ($5));
6768 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6769 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6771 | LOCK open_parens_any expression error
6773 Error_SyntaxError (yyToken);
6775 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6776 lbag.AddStatement ($$, GetLocation ($2));
6781 : FIXED open_parens_any variable_type identifier_inside_body
6783 start_block (GetLocation ($2));
6785 current_block.IsCompilerGenerated = true;
6786 var lt = (LocatedToken) $4;
6787 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6788 current_block.AddLocalName (li);
6789 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6791 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6793 $$ = current_variable;
6794 current_variable = null;
6798 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6799 Warning_EmptyStatement (GetLocation ($10));
6801 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6802 current_block.AddStatement (f);
6803 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6804 $$ = end_block (GetLocation ($8));
6809 : USING open_parens_any variable_type identifier_inside_body
6811 start_block (GetLocation ($2));
6813 current_block.IsCompilerGenerated = true;
6814 var lt = (LocatedToken) $4;
6815 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6816 current_block.AddLocalName (li);
6817 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6819 using_initialization CLOSE_PARENS
6821 $$ = current_variable;
6822 current_variable = null;
6826 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6827 Warning_EmptyStatement (GetLocation ($9));
6829 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6830 current_block.AddStatement (u);
6831 $$ = end_block (GetLocation ($7));
6833 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6835 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6836 Warning_EmptyStatement (GetLocation ($5));
6838 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6839 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6841 | USING open_parens_any expression error
6843 Error_SyntaxError (yyToken);
6845 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6846 lbag.AddStatement ($$, GetLocation ($2));
6850 using_initialization
6851 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6854 // It has to be here for the parent to safely restore artificial block
6855 Error_SyntaxError (yyToken);
6859 using_or_fixed_variable_initializer
6862 Error_MissingInitializer (lexer.Location);
6864 | ASSIGN variable_initializer
6866 current_variable.Initializer = (Expression) $2;
6867 $$ = current_variable;
6875 : first_from_clause query_body
6877 lexer.query_parsing = false;
6879 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6881 from.Tail.Next = (Linq.AQueryClause)$2;
6884 current_block.SetEndLocation (lexer.Location);
6885 current_block = current_block.Parent;
6887 | nested_from_clause query_body
6889 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6891 from.Tail.Next = (Linq.AQueryClause)$2;
6894 current_block.SetEndLocation (lexer.Location);
6895 current_block = current_block.Parent;
6898 // Bubble up COMPLETE_COMPLETION productions
6899 | first_from_clause COMPLETE_COMPLETION {
6900 lexer.query_parsing = false;
6903 current_block.SetEndLocation (lexer.Location);
6904 current_block = current_block.Parent;
6906 | nested_from_clause COMPLETE_COMPLETION {
6908 current_block.SetEndLocation (lexer.Location);
6909 current_block = current_block.Parent;
6914 : FROM_FIRST identifier_inside_body IN expression
6916 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6918 var lt = (LocatedToken) $2;
6919 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6920 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6921 lbag.AddLocation (clause, GetLocation ($3));
6922 $$ = new Linq.QueryExpression (clause);
6924 | FROM_FIRST type identifier_inside_body IN expression
6926 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6928 var lt = (LocatedToken) $3;
6929 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6930 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6931 IdentifierType = (FullNamedExpression)$2
6933 lbag.AddLocation (clause, GetLocation ($4));
6934 $$ = new Linq.QueryExpression (clause);
6939 : FROM identifier_inside_body IN expression
6941 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6943 var lt = (LocatedToken) $2;
6944 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6945 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6946 lbag.AddLocation (clause, GetLocation ($3));
6947 $$ = new Linq.QueryExpression (clause);
6949 | FROM type identifier_inside_body IN expression
6951 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6953 var lt = (LocatedToken) $3;
6954 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6955 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6956 IdentifierType = (FullNamedExpression)$2
6958 lbag.AddLocation (clause, GetLocation ($4));
6959 $$ = new Linq.QueryExpression (clause);
6964 : FROM identifier_inside_body IN
6966 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6970 var lt = (LocatedToken) $2;
6971 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6972 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6974 current_block.SetEndLocation (lexer.Location);
6975 current_block = current_block.Parent;
6977 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6978 lbag.AddLocation ($$, GetLocation ($3));
6980 | FROM type identifier_inside_body IN
6982 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6986 var lt = (LocatedToken) $3;
6987 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6989 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6990 IdentifierType = (FullNamedExpression)$2
6993 current_block.SetEndLocation (lexer.Location);
6994 current_block = current_block.Parent;
6996 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6998 lbag.AddLocation ($$, GetLocation ($4));
7003 : query_body_clauses select_or_group_clause opt_query_continuation
7005 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7008 head.Next = (Linq.AQueryClause)$3;
7011 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7012 clause.Tail.Next = head;
7018 | select_or_group_clause opt_query_continuation
7020 Linq.AQueryClause head = (Linq.AQueryClause)$2;
7023 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
7024 clause.Tail.Next = head;
7030 | query_body_clauses COMPLETE_COMPLETION
7031 | query_body_clauses error
7033 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
7038 Error_SyntaxError (yyToken);
7043 select_or_group_clause
7046 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7050 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7052 current_block.SetEndLocation (lexer.Location);
7053 current_block = current_block.Parent;
7057 if (linq_clause_blocks == null)
7058 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7060 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7061 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
7065 current_block.SetEndLocation (lexer.Location);
7066 current_block = current_block.Parent;
7068 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7072 var obj = (object[]) $5;
7074 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
7075 lbag.AddLocation ($$, (Location) obj[1]);
7077 current_block.SetEndLocation (lexer.Location);
7078 current_block = current_block.Parent;
7083 : BY expression_or_error
7085 $$ = new object[] { $2, GetLocation ($1) };
7089 Error_SyntaxError (yyToken);
7090 $$ = new object[2] { null, Location.Null };
7096 | query_body_clauses query_body_clause
7098 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
7112 : LET identifier_inside_body ASSIGN
7114 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7118 var lt = (LocatedToken) $2;
7119 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7120 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
7121 lbag.AddLocation ($$, GetLocation ($3));
7123 current_block.SetEndLocation (lexer.Location);
7124 current_block = current_block.Parent;
7126 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7133 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7137 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7139 current_block.SetEndLocation (lexer.Location);
7140 current_block = current_block.Parent;
7145 : JOIN identifier_inside_body IN
7147 if (linq_clause_blocks == null)
7148 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7150 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7151 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7153 expression_or_error ON
7155 current_block.SetEndLocation (lexer.Location);
7156 current_block = current_block.Parent;
7158 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7159 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7161 expression_or_error EQUALS
7163 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7164 current_block.SetEndLocation (lexer.Location);
7165 current_block = current_block.Parent;
7167 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7169 expression_or_error opt_join_into
7171 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7172 current_block.SetEndLocation (lexer.Location);
7174 var outer_selector = linq_clause_blocks.Pop ();
7175 var block = linq_clause_blocks.Pop ();
7177 var lt = (LocatedToken) $2;
7178 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7179 Linq.RangeVariable into;
7183 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7184 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7187 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7189 var parent = block.Parent;
7190 while (parent is Linq.QueryBlock) {
7191 parent = parent.Parent;
7193 current_block.Parent = parent;
7195 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7197 lt = (LocatedToken) $12;
7198 into = new Linq.RangeVariable (lt.Value, lt.Location);
7200 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7201 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7204 current_block = block.Parent;
7205 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7207 | JOIN type identifier_inside_body IN
7209 if (linq_clause_blocks == null)
7210 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7212 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7213 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7215 expression_or_error ON
7217 current_block.SetEndLocation (lexer.Location);
7218 current_block = current_block.Parent;
7220 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7221 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7223 expression_or_error EQUALS
7225 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7226 current_block.SetEndLocation (lexer.Location);
7227 current_block = current_block.Parent;
7229 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7231 expression_or_error opt_join_into
7233 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7234 current_block.SetEndLocation (lexer.Location);
7236 var outer_selector = linq_clause_blocks.Pop ();
7237 var block = linq_clause_blocks.Pop ();
7239 var lt = (LocatedToken) $3;
7240 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7241 Linq.RangeVariable into;
7245 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7246 IdentifierType = (FullNamedExpression)$2
7248 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7251 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7253 var parent = block.Parent;
7254 while (parent is Linq.QueryBlock) {
7255 parent = parent.Parent;
7257 current_block.Parent = parent;
7259 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7261 lt = (LocatedToken) $13;
7262 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7264 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7265 IdentifierType = (FullNamedExpression)$2
7269 current_block = block.Parent;
7270 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7276 | INTO identifier_inside_body
7285 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7289 current_block.SetEndLocation (lexer.Location);
7290 current_block = current_block.Parent;
7300 current_block.SetEndLocation (lexer.Location);
7301 current_block = current_block.Parent;
7303 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7307 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7314 | orderings_then_by COMMA
7316 current_block.SetEndLocation (lexer.Location);
7317 current_block = current_block.Parent;
7319 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7323 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7331 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7333 | expression ASCENDING
7335 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7336 lbag.AddLocation ($$, GetLocation ($2));
7338 | expression DESCENDING
7340 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7341 lbag.AddLocation ($$, GetLocation ($2));
7348 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7350 | expression ASCENDING
7352 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7353 lbag.AddLocation ($$, GetLocation ($2));
7355 | expression DESCENDING
7357 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7358 lbag.AddLocation ($$, GetLocation ($2));
7363 opt_query_continuation
7365 | INTO identifier_inside_body
7367 // query continuation block is not linked with query block but with block
7368 // before. This means each query can use same range variable names for
7369 // different identifiers.
7371 current_block.SetEndLocation (GetLocation ($1));
7372 current_block = current_block.Parent;
7374 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7376 if (linq_clause_blocks == null)
7377 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7379 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7383 var current_block = linq_clause_blocks.Pop ();
7384 var lt = (LocatedToken) $2;
7385 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7386 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7387 next = (Linq.AQueryClause)$4
7393 // Support for using the compiler as an interactive parser
7395 // The INTERACTIVE_PARSER token is first sent to parse our
7396 // productions; If the result is a Statement, the parsing
7397 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7398 // to setup the blocks in advance.
7400 // This setup is here so that in the future we can add
7401 // support for other constructs (type parsing, namespaces, etc)
7402 // that do not require a block to be setup in advance
7406 : EVAL_STATEMENT_PARSER EOF
7407 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7408 | EVAL_STATEMENT_PARSER
7410 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7412 // (ref object retval)
7413 Parameter [] mpar = new Parameter [1];
7414 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7416 ParametersCompiled pars = new ParametersCompiled (mpar);
7417 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7418 if (settings.Unsafe)
7419 mods |= Modifiers.UNSAFE;
7421 current_local_parameters = pars;
7422 var method = new InteractiveMethod (
7424 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7428 current_type.AddMember (method);
7429 oob_stack.Push (method);
7431 interactive_async = false;
7433 ++lexer.parsing_block;
7434 start_block (lexer.Location);
7436 interactive_statement_list opt_COMPLETE_COMPLETION
7438 --lexer.parsing_block;
7439 var method = (InteractiveMethod) oob_stack.Pop ();
7440 method.Block = (ToplevelBlock) end_block(lexer.Location);
7442 if (interactive_async == true) {
7443 method.ChangeToAsync ();
7446 InteractiveResult = (Class) pop_current_class ();
7447 current_local_parameters = null;
7449 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7452 interactive_compilation_unit
7453 : opt_extern_alias_directives opt_using_directives
7454 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7457 opt_COMPLETE_COMPLETION
7459 | COMPLETE_COMPLETION
7462 close_brace_or_complete_completion
7464 | COMPLETE_COMPLETION
7468 // XML documentation code references micro parser
7470 documentation_parsing
7473 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7478 : doc_type_declaration_name opt_doc_method_sig
7480 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7482 | builtin_types opt_doc_method_sig
7484 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7485 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7488 | VOID opt_doc_method_sig
7490 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7491 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7494 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7496 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7497 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7498 var lt = (LocatedToken) $3;
7499 $$ = new MemberName (lt.Value);
7501 | doc_type_declaration_name DOT THIS
7503 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7505 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7507 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7509 opt_doc_parameters CLOSE_BRACKET
7511 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7512 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7514 | EXPLICIT OPERATOR type opt_doc_method_sig
7516 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7517 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7518 module.DocumentationBuilder.ParsedParameters = p;
7519 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7522 | IMPLICIT OPERATOR type opt_doc_method_sig
7524 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7525 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7526 module.DocumentationBuilder.ParsedParameters = p;
7527 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7530 | OPERATOR overloadable_operator opt_doc_method_sig
7532 var p = (List<DocumentationParameter>)$3;
7533 module.DocumentationBuilder.ParsedParameters = p;
7534 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7539 doc_type_declaration_name
7540 : type_declaration_name
7541 | doc_type_declaration_name DOT type_declaration_name
7543 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7551 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7553 opt_doc_parameters CLOSE_PARENS
7562 $$ = new List<DocumentationParameter> (0);
7570 var parameters = new List<DocumentationParameter> ();
7571 parameters.Add ((DocumentationParameter) $1);
7574 | doc_parameters COMMA doc_parameter
7576 var parameters = $1 as List<DocumentationParameter>;
7577 parameters.Add ((DocumentationParameter) $3);
7583 : opt_parameter_modifier parameter_type
7586 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7588 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7595 // A class used to hold info about an operator declarator
7597 class OperatorDeclaration {
7598 public readonly Operator.OpType optype;
7599 public readonly FullNamedExpression ret_type;
7600 public readonly Location location;
7602 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7605 this.ret_type = ret_type;
7606 this.location = location;
7610 void Error_ExpectingTypeName (Expression expr)
7612 if (expr is Invocation){
7613 report.Error (1002, expr.Location, "Expecting `;'");
7615 expr.Error_InvalidExpressionStatement (report);
7619 void Error_ParameterModifierNotValid (string modifier, Location loc)
7621 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7625 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7627 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7628 Parameter.GetModifierSignature (mod));
7631 void Error_TypeExpected (Location loc)
7633 report.Error (1031, loc, "Type expected");
7636 void Error_UnsafeCodeNotAllowed (Location loc)
7638 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7641 void Warning_EmptyStatement (Location loc)
7643 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7646 void Error_NamedArgumentExpected (NamedArgument a)
7648 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7651 void Error_MissingInitializer (Location loc)
7653 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7656 object Error_AwaitAsIdentifier (object token)
7659 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7660 return new LocatedToken ("await", GetLocation (token));
7666 void push_current_container (TypeDefinition tc, object partial_token)
7668 if (module.Evaluator != null){
7669 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7673 undo.AddTypeContainer (current_container, tc);
7676 if (partial_token != null)
7677 current_container.AddPartial (tc);
7679 current_container.AddTypeContainer (tc);
7681 ++lexer.parsing_declaration;
7682 current_container = tc;
7686 TypeContainer pop_current_class ()
7688 var retval = current_container;
7690 current_container = current_container.Parent;
7691 current_type = current_type.Parent as TypeDefinition;
7696 [System.Diagnostics.Conditional ("FULL_AST")]
7697 void StoreModifierLocation (object token, Location loc)
7702 if (mod_locations == null)
7703 mod_locations = new List<Tuple<Modifiers, Location>> ();
7705 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7708 [System.Diagnostics.Conditional ("FULL_AST")]
7709 void PushLocation (Location loc)
7711 if (location_stack == null)
7712 location_stack = new Stack<Location> ();
7714 location_stack.Push (loc);
7717 Location PopLocation ()
7719 if (location_stack == null)
7720 return Location.Null;
7722 return location_stack.Pop ();
7725 string CheckAttributeTarget (int token, string a, Location l)
7728 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7732 if (!Tokenizer.IsValidIdentifier (a)) {
7733 Error_SyntaxError (token);
7735 report.Warning (658, 1, l,
7736 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7739 return string.Empty;
7742 static bool IsUnaryOperator (Operator.OpType op)
7746 case Operator.OpType.LogicalNot:
7747 case Operator.OpType.OnesComplement:
7748 case Operator.OpType.Increment:
7749 case Operator.OpType.Decrement:
7750 case Operator.OpType.True:
7751 case Operator.OpType.False:
7752 case Operator.OpType.UnaryPlus:
7753 case Operator.OpType.UnaryNegation:
7759 void syntax_error (Location l, string msg)
7761 report.Error (1003, l, "Syntax error, " + msg);
7766 public Tokenizer Lexer {
7772 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7773 : this (reader, file, file.Compiler.Report, session)
7777 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7780 current_container = current_namespace = file;
7782 this.module = file.Module;
7783 this.compiler = file.Compiler;
7784 this.settings = compiler.Settings;
7785 this.report = report;
7787 lang_version = settings.Version;
7788 yacc_verbose_flag = settings.VerboseParserFlag;
7789 doc_support = settings.DocumentationFile != null;
7790 lexer = new Tokenizer (reader, file, session, report);
7791 oob_stack = new Stack<object> ();
7792 lbag = session.LocationsBag;
7793 use_global_stacks = session.UseJayGlobalArrays;
7794 parameters_bucket = session.ParametersStack;
7797 public void parse ()
7799 eof_token = Token.EOF;
7802 if (yacc_verbose_flag > 1)
7803 yyparse (lexer, new yydebug.yyDebugSimple ());
7807 Tokenizer tokenizer = lexer as Tokenizer;
7808 tokenizer.cleanup ();
7809 } catch (Exception e){
7810 if (e is yyParser.yyUnexpectedEof) {
7811 Error_SyntaxError (yyToken);
7812 UnexpectedEOF = true;
7816 if (e is yyParser.yyException) {
7817 if (report.Errors == 0)
7818 report.Error (-25, lexer.Location, "Parsing error");
7820 // Used by compiler-tester to test internal errors
7821 if (yacc_verbose_flag > 0 || e is FatalException)
7824 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7829 void CheckToken (int error, int yyToken, string msg, Location loc)
7831 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7832 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7834 report.Error (error, loc, msg);
7837 string ConsumeStoredComment ()
7839 string s = tmpComment;
7841 Lexer.doc_state = XmlCommentState.Allowed;
7845 void FeatureIsNotAvailable (Location loc, string feature)
7847 report.FeatureIsNotAvailable (compiler, loc, feature);
7850 Location GetLocation (object obj)
7852 var lt = obj as LocatedToken;
7856 var mn = obj as MemberName;
7860 var expr = obj as Expression;
7862 return expr.Location;
7864 return lexer.Location;
7867 void start_block (Location loc)
7869 if (current_block == null) {
7870 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7871 parsing_anonymous_method = false;
7872 } else if (parsing_anonymous_method) {
7873 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7874 parsing_anonymous_method = false;
7876 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7880 Block end_block (Location loc)
7882 Block retval = current_block.Explicit;
7883 retval.SetEndLocation (loc);
7884 current_block = retval.Parent;
7888 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7890 oob_stack.Push (current_anonymous_method);
7891 oob_stack.Push (current_local_parameters);
7892 oob_stack.Push (current_variable);
7893 oob_stack.Push (async_block);
7895 current_local_parameters = parameters;
7897 if (lang_version <= LanguageVersion.ISO_2)
7898 FeatureIsNotAvailable (loc, "lambda expressions");
7900 current_anonymous_method = new LambdaExpression (loc);
7902 if (lang_version == LanguageVersion.ISO_1)
7903 FeatureIsNotAvailable (loc, "anonymous methods");
7905 current_anonymous_method = new AnonymousMethodExpression (loc);
7908 async_block = isAsync;
7909 // Force the next block to be created as a ToplevelBlock
7910 parsing_anonymous_method = true;
7914 * Completes the anonymous method processing, if lambda_expr is null, this
7915 * means that we have a Statement instead of an Expression embedded
7917 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7919 AnonymousMethodExpression retval;
7922 anon_block.IsAsync = true;
7924 current_anonymous_method.Block = anon_block;
7925 retval = current_anonymous_method;
7927 async_block = (bool) oob_stack.Pop ();
7928 current_variable = (BlockVariable) oob_stack.Pop ();
7929 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7930 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7935 void Error_SyntaxError (int token)
7937 Error_SyntaxError (0, token);
7940 void Error_SyntaxError (int error_code, int token)
7942 Error_SyntaxError (error_code, token, "Unexpected symbol");
7945 void Error_SyntaxError (int error_code, int token, string msg)
7947 Lexer.CompleteOnEOF = false;
7949 // An error message has been reported by tokenizer
7950 if (token == Token.ERROR)
7953 // Avoid duplicit error message after unterminated string literals
7954 if (token == Token.LITERAL && lexer.Location.Column == 0)
7957 string symbol = GetSymbolName (token);
7958 string expecting = GetExpecting ();
7959 var loc = lexer.Location - symbol.Length;
7961 if (error_code == 0) {
7962 if (expecting == "`identifier'") {
7963 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7964 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7969 expecting = "identifier";
7970 } else if (expecting == "`)'") {
7977 if (string.IsNullOrEmpty (expecting))
7978 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7980 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7983 string GetExpecting ()
7985 int [] tokens = yyExpectingTokens (yyExpectingState);
7986 var names = new List<string> (tokens.Length);
7987 bool has_type = false;
7988 bool has_identifier = false;
7989 for (int i = 0; i < tokens.Length; i++){
7990 int token = tokens [i];
7991 has_identifier |= token == Token.IDENTIFIER;
7993 string name = GetTokenName (token);
7994 if (name == "<internal>")
7997 has_type |= name == "type";
7998 if (names.Contains (name))
8005 // Too many tokens to enumerate
8007 if (names.Count > 8)
8010 if (has_type && has_identifier)
8011 names.Remove ("identifier");
8013 if (names.Count == 1)
8014 return "`" + GetTokenName (tokens [0]) + "'";
8016 StringBuilder sb = new StringBuilder ();
8018 int count = names.Count;
8019 for (int i = 0; i < count; i++){
8020 bool last = i + 1 == count;
8024 sb.Append (names [i]);
8025 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
8027 return sb.ToString ();
8031 string GetSymbolName (int token)
8035 return ((Constant)lexer.Value).GetValue ().ToString ();
8036 case Token.IDENTIFIER:
8037 return ((LocatedToken)lexer.Value).Value;
8079 case Token.BITWISE_AND:
8081 case Token.BITWISE_OR:
8095 case Token.OP_SHIFT_LEFT:
8097 case Token.OP_SHIFT_RIGHT:
8117 case Token.OP_COALESCING:
8119 case Token.OP_MULT_ASSIGN:
8121 case Token.OP_DIV_ASSIGN:
8123 case Token.OP_MOD_ASSIGN:
8125 case Token.OP_ADD_ASSIGN:
8127 case Token.OP_SUB_ASSIGN:
8129 case Token.OP_SHIFT_LEFT_ASSIGN:
8131 case Token.OP_SHIFT_RIGHT_ASSIGN:
8133 case Token.OP_AND_ASSIGN:
8135 case Token.OP_XOR_ASSIGN:
8137 case Token.OP_OR_ASSIGN:
8141 return GetTokenName (token);
8144 static string GetTokenName (int token)
8147 case Token.ABSTRACT:
8169 case Token.CONTINUE:
8173 case Token.DELEGATE:
8183 case Token.EXPLICIT:
8186 case Token.EXTERN_ALIAS:
8202 case Token.IMPLICIT:
8206 case Token.INTERFACE:
8208 case Token.INTERNAL:
8214 case Token.NAMESPACE:
8220 case Token.OPERATOR:
8224 case Token.OVERRIDE:
8230 case Token.PROTECTED:
8234 case Token.READONLY:
8246 case Token.STACKALLOC:
8247 return "stackalloc";
8257 case Token.THROW_EXPR:
8265 case Token.UNCHECKED:
8273 case Token.VOLATILE:
8281 case Token.REFVALUE:
8282 return "__refvalue";
8292 case Token.FROM_FIRST:
8310 case Token.ASCENDING:
8312 case Token.DESCENDING:
8313 return "descending";
8320 case Token.OPEN_BRACE:
8322 case Token.CLOSE_BRACE:
8324 case Token.OPEN_BRACKET:
8325 case Token.OPEN_BRACKET_EXPR:
8327 case Token.CLOSE_BRACKET:
8329 case Token.OPEN_PARENS_CAST:
8330 case Token.OPEN_PARENS_LAMBDA:
8331 case Token.OPEN_PARENS_DECONSTRUCT:
8332 case Token.OPEN_PARENS:
8334 case Token.CLOSE_PARENS:
8340 case Token.DEFAULT_COLON:
8344 case Token.SEMICOLON:
8350 case Token.INTERPOLATED_STRING_END:
8352 case Token.INTERPOLATED_STRING:
8361 case Token.BITWISE_AND:
8362 case Token.BITWISE_OR:
8369 case Token.OP_SHIFT_LEFT:
8370 case Token.OP_SHIFT_RIGHT:
8378 case Token.OP_COALESCING:
8379 case Token.OP_MULT_ASSIGN:
8380 case Token.OP_DIV_ASSIGN:
8381 case Token.OP_MOD_ASSIGN:
8382 case Token.OP_ADD_ASSIGN:
8383 case Token.OP_SUB_ASSIGN:
8384 case Token.OP_SHIFT_LEFT_ASSIGN:
8385 case Token.OP_SHIFT_RIGHT_ASSIGN:
8386 case Token.OP_AND_ASSIGN:
8387 case Token.OP_XOR_ASSIGN:
8388 case Token.OP_OR_ASSIGN:
8389 case Token.INTERR_OPERATOR:
8390 return "<operator>";
8412 case Token.OP_GENERICS_LT:
8413 case Token.GENERIC_DIMENSION:
8415 case Token.OP_GENERICS_GT:
8418 case Token.INTERR_NULLABLE:
8420 case Token.DOUBLE_COLON:
8424 case Token.IDENTIFIER:
8426 return "identifier";
8429 return "end-of-file";
8431 // All of these are internal.
8434 case Token.FIRST_KEYWORD:
8435 case Token.EVAL_COMPILATION_UNIT_PARSER:
8436 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8437 case Token.EVAL_STATEMENT_PARSER:
8438 case Token.LAST_KEYWORD:
8439 case Token.GENERATE_COMPLETION:
8440 case Token.COMPLETE_COMPLETION:
8441 return "<internal>";
8443 // A bit more robust.
8445 return yyNames [token];