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
1340 method_body_expression_block
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 ();
1495 method_body_expression_block
1502 | SEMICOLON { $$ = null; }
1508 if (lang_version < LanguageVersion.V_6) {
1509 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1512 ++lexer.parsing_block;
1513 start_block (GetLocation ($1));
1515 expression SEMICOLON
1517 lexer.parsing_block = 0;
1518 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1519 var b = end_block (GetLocation ($4));
1520 b.IsCompilerGenerated = true;
1525 opt_formal_parameter_list
1526 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1527 | formal_parameter_list
1530 formal_parameter_list
1533 var pars_list = (List<Parameter>) $1;
1534 $$ = new ParametersCompiled (pars_list.ToArray ());
1536 | fixed_parameters COMMA parameter_array
1538 var pars_list = (List<Parameter>) $1;
1539 pars_list.Add ((Parameter) $3);
1541 $$ = new ParametersCompiled (pars_list.ToArray ());
1543 | fixed_parameters COMMA arglist_modifier
1545 var pars_list = (List<Parameter>) $1;
1546 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1547 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1549 | parameter_array COMMA error
1552 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1554 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1556 | fixed_parameters COMMA parameter_array COMMA error
1559 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1561 var pars_list = (List<Parameter>) $1;
1562 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1564 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1566 | arglist_modifier COMMA error
1568 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1570 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1572 | fixed_parameters COMMA ARGLIST COMMA error
1574 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1576 var pars_list = (List<Parameter>) $1;
1577 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1579 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1583 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1587 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1591 Error_SyntaxError (yyToken);
1592 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1599 parameters_bucket.Clear ();
1600 Parameter p = (Parameter) $1;
1601 parameters_bucket.Add (p);
1603 default_parameter_used = p.HasDefaultValue;
1604 $$ = parameters_bucket;
1606 | fixed_parameters COMMA fixed_parameter
1608 var pars = (List<Parameter>) $1;
1609 Parameter p = (Parameter) $3;
1611 if (p.HasExtensionMethodModifier)
1612 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1613 else if (!p.HasDefaultValue && default_parameter_used)
1614 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1616 default_parameter_used |= p.HasDefaultValue;
1619 lbag.AddLocation (p, GetLocation ($2));
1628 opt_parameter_modifier
1630 identifier_inside_body
1632 var lt = (LocatedToken) $4;
1633 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1636 opt_parameter_modifier
1638 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1640 var lt = (LocatedToken) $4;
1641 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1642 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1644 | attribute_sections error
1646 Error_SyntaxError (yyToken);
1647 Location l = GetLocation ($2);
1648 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1651 opt_parameter_modifier
1655 Error_SyntaxError (yyToken);
1656 Location l = GetLocation ($4);
1657 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1660 opt_parameter_modifier
1662 identifier_inside_body
1665 ++lexer.parsing_block;
1669 --lexer.parsing_block;
1670 if (lang_version <= LanguageVersion.V_3) {
1671 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1674 Parameter.Modifier mod = (Parameter.Modifier) $2;
1675 if (mod != Parameter.Modifier.NONE) {
1677 case Parameter.Modifier.REF:
1678 case Parameter.Modifier.OUT:
1679 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1680 Parameter.GetModifierSignature (mod));
1683 case Parameter.Modifier.This:
1684 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1685 Parameter.GetModifierSignature (mod));
1688 throw new NotImplementedException (mod.ToString ());
1691 mod = Parameter.Modifier.NONE;
1694 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1695 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1697 var lt = (LocatedToken) $4;
1698 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1699 lbag.AddLocation ($$, GetLocation ($5));
1702 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1706 opt_parameter_modifier
1707 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1708 | parameter_modifiers
1712 : parameter_modifier
1716 | parameter_modifiers parameter_modifier
1718 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1719 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1720 if (((Parameter.Modifier)$1 & p2) == p2) {
1721 Error_DuplicateParameterModifier (lexer.Location, p2);
1723 switch (mod & ~Parameter.Modifier.This) {
1724 case Parameter.Modifier.REF:
1725 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1727 case Parameter.Modifier.OUT:
1728 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1731 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1742 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1743 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1745 $$ = Parameter.Modifier.REF;
1749 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1750 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1752 $$ = Parameter.Modifier.OUT;
1756 if ((valid_param_mod & ParameterModifierType.This) == 0)
1757 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1759 if (lang_version <= LanguageVersion.ISO_2)
1760 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1762 $$ = Parameter.Modifier.This;
1767 : opt_attributes params_modifier type IDENTIFIER
1769 var lt = (LocatedToken) $4;
1770 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1772 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1774 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1776 var lt = (LocatedToken) $4;
1777 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1779 | opt_attributes params_modifier type error
1781 Error_SyntaxError (yyToken);
1783 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1790 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1791 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1793 | PARAMS parameter_modifier
1795 Parameter.Modifier mod = (Parameter.Modifier)$2;
1796 if ((mod & Parameter.Modifier.This) != 0) {
1797 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1799 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1802 | PARAMS params_modifier
1804 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1811 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1812 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1816 property_declaration
1820 member_declaration_name
1822 lexer.parsing_generic_declaration = false;
1824 tmpComment = Lexer.consume_doc_comment ();
1828 var type = (FullNamedExpression) $3;
1829 current_property = new Property (current_type, type, (Modifiers) $2,
1830 (MemberName) $4, (Attributes) $1);
1832 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1833 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1835 current_type.AddMember (current_property);
1836 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1838 lexer.PropertyParsing = true;
1840 accessor_declarations
1842 lexer.PropertyParsing = false;
1845 current_property.DocComment = ConsumeStoredComment ();
1849 lbag.AppendToMember (current_property, GetLocation ($10));
1850 lexer.parsing_modifiers = true;
1852 opt_property_initializer
1854 current_property = null;
1859 member_declaration_name
1861 lexer.parsing_generic_declaration = false;
1863 tmpComment = Lexer.consume_doc_comment ();
1864 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1868 var type = (FullNamedExpression) $3;
1869 var property = new Property (current_type, type, (Modifiers) $2,
1870 (MemberName) $4, (Attributes) $1);
1872 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1873 property.Get.Block = (ToplevelBlock) $6;
1875 if (current_container.Kind == MemberKind.Interface) {
1876 report.Error (531, property.Get.Block.StartLocation,
1877 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1880 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1881 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1884 property.DocComment = ConsumeStoredComment ();
1886 current_type.AddMember (property);
1888 current_local_parameters = null;
1892 opt_property_initializer
1896 ++lexer.parsing_block;
1897 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1898 start_block (GetLocation ($1));
1900 property_initializer SEMICOLON
1902 --lexer.parsing_block;
1903 ((Property)current_property).Initializer = (Expression) $3;
1904 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1905 end_block (GetLocation ($4));
1906 current_local_parameters = null;
1909 Lexer.doc_state = XmlCommentState.Allowed;
1913 property_initializer
1919 : opt_attributes opt_modifiers
1920 member_type indexer_declaration_name OPEN_BRACKET
1922 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1924 opt_formal_parameter_list CLOSE_BRACKET
1926 valid_param_mod = 0;
1927 var type = (FullNamedExpression) $3;
1928 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1930 current_property = indexer;
1932 current_type.AddIndexer (indexer);
1933 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1935 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1936 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1938 if (indexer.ParameterInfo.IsEmpty) {
1939 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1943 tmpComment = Lexer.consume_doc_comment ();
1944 Lexer.doc_state = XmlCommentState.Allowed;
1947 lexer.PropertyParsing = true;
1948 current_local_parameters = (ParametersCompiled) $7;
1952 lexer.PropertyParsing = false;
1953 current_local_parameters = null;
1955 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1956 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1959 current_property.DocComment = ConsumeStoredComment ();
1961 current_property = null;
1966 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1968 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1972 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1973 current_property.Get.Block = (ToplevelBlock) $1;
1977 accessor_declarations
1978 : get_accessor_declaration
1979 | get_accessor_declaration accessor_declarations
1980 | set_accessor_declaration
1981 | set_accessor_declaration accessor_declarations
1984 if (yyToken == Token.CLOSE_BRACE) {
1985 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1987 if (yyToken == Token.SEMICOLON)
1988 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1990 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1995 get_accessor_declaration
1996 : opt_attributes opt_modifiers GET
1998 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1999 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2002 if (current_property.Get != null) {
2003 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2006 if (current_property is Indexer) {
2007 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
2008 (Attributes) $1, GetLocation ($3));
2010 current_property.Get = new Property.GetMethod (current_property,
2011 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2014 current_local_parameters = current_property.Get.ParameterInfo;
2015 lbag.AddMember (current_property.Get, mod_locations);
2016 lexer.PropertyParsing = false;
2021 current_property.Get.Block = (ToplevelBlock) $5;
2023 if (current_container.Kind == MemberKind.Interface) {
2024 report.Error (531, current_property.Get.Block.StartLocation,
2025 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2029 current_local_parameters = null;
2030 lexer.PropertyParsing = true;
2033 if (Lexer.doc_state == XmlCommentState.Error)
2034 Lexer.doc_state = XmlCommentState.NotAllowed;
2038 set_accessor_declaration
2039 : opt_attributes opt_modifiers SET
2041 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2042 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2045 if (current_property.Set != null) {
2046 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2049 if (current_property is Indexer) {
2050 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2051 ParametersCompiled.MergeGenerated (compiler,
2052 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2053 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2055 (Attributes) $1, GetLocation ($3));
2057 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2058 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2059 (Attributes) $1, GetLocation ($3));
2062 current_local_parameters = current_property.Set.ParameterInfo;
2063 lbag.AddMember (current_property.Set, mod_locations);
2064 lexer.PropertyParsing = false;
2069 current_property.Set.Block = (ToplevelBlock) $5;
2071 if (current_container.Kind == MemberKind.Interface) {
2072 report.Error (531, current_property.Set.Block.StartLocation,
2073 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2077 current_local_parameters = null;
2078 lexer.PropertyParsing = true;
2081 && Lexer.doc_state == XmlCommentState.Error)
2082 Lexer.doc_state = XmlCommentState.NotAllowed;
2096 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2102 interface_declaration
2109 type_declaration_name
2111 lexer.ConstraintsParsing = true;
2112 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2113 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2116 opt_type_parameter_constraints_clauses
2118 lexer.ConstraintsParsing = false;
2121 current_container.SetConstraints ((List<Constraints>) $9);
2124 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2125 Lexer.doc_state = XmlCommentState.Allowed;
2128 lexer.parsing_modifiers = true;
2130 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2132 --lexer.parsing_declaration;
2134 Lexer.doc_state = XmlCommentState.Allowed;
2139 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2141 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2143 $$ = pop_current_class ();
2145 | opt_attributes opt_modifiers opt_partial INTERFACE error
2147 Error_SyntaxError (yyToken);
2151 opt_interface_member_declarations
2153 | interface_member_declarations
2156 interface_member_declarations
2157 : interface_member_declaration
2159 lexer.parsing_modifiers = true;
2160 lexer.parsing_block = 0;
2162 | interface_member_declarations interface_member_declaration
2164 lexer.parsing_modifiers = true;
2165 lexer.parsing_block = 0;
2169 interface_member_declaration
2170 : constant_declaration
2172 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2176 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2178 | method_declaration
2179 | property_declaration
2181 | indexer_declaration
2182 | operator_declaration
2184 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2186 | constructor_declaration
2188 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2192 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2196 operator_declaration
2197 : opt_attributes opt_modifiers operator_declarator
2200 method_body_expression_block
2202 OperatorDeclaration decl = (OperatorDeclaration) $3;
2204 Operator op = new Operator (
2205 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2206 current_local_parameters,
2207 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2209 if (op.Block == null)
2210 op.ParameterInfo.CheckParameters (op);
2213 op.DocComment = tmpComment;
2214 Lexer.doc_state = XmlCommentState.Allowed;
2217 // Note again, checking is done in semantic analysis
2218 current_type.AddOperator (op);
2220 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2223 current_local_parameters = null;
2228 : type_expression_or_array
2231 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2232 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2237 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2239 valid_param_mod = ParameterModifierType.DefaultValue;
2240 if ((Operator.OpType) $3 == Operator.OpType.Is)
2241 valid_param_mod |= ParameterModifierType.Out;
2243 opt_formal_parameter_list CLOSE_PARENS
2245 valid_param_mod = 0;
2247 Location loc = GetLocation ($2);
2248 Operator.OpType op = (Operator.OpType) $3;
2249 current_local_parameters = (ParametersCompiled)$6;
2251 int p_count = current_local_parameters.Count;
2253 if (op == Operator.OpType.Addition)
2254 op = Operator.OpType.UnaryPlus;
2255 else if (op == Operator.OpType.Subtraction)
2256 op = Operator.OpType.UnaryNegation;
2259 if (IsUnaryOperator (op)) {
2261 report.Error (1020, loc, "Overloadable binary operator expected");
2262 } else if (p_count != 1) {
2263 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2264 Operator.GetName (op));
2266 } else if (op == Operator.OpType.Is) {
2267 // TODO: Special checks for is operator
2270 report.Error (1019, loc, "Overloadable unary operator expected");
2271 } else if (p_count != 2) {
2272 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2273 Operator.GetName (op));
2278 tmpComment = Lexer.consume_doc_comment ();
2279 Lexer.doc_state = XmlCommentState.NotAllowed;
2282 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2283 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2285 | conversion_operator_declarator
2288 overloadable_operator
2290 : BANG { $$ = Operator.OpType.LogicalNot; }
2291 | TILDE { $$ = Operator.OpType.OnesComplement; }
2292 | OP_INC { $$ = Operator.OpType.Increment; }
2293 | OP_DEC { $$ = Operator.OpType.Decrement; }
2294 | TRUE { $$ = Operator.OpType.True; }
2295 | FALSE { $$ = Operator.OpType.False; }
2296 // Unary and binary:
2297 | PLUS { $$ = Operator.OpType.Addition; }
2298 | MINUS { $$ = Operator.OpType.Subtraction; }
2300 | STAR { $$ = Operator.OpType.Multiply; }
2301 | DIV { $$ = Operator.OpType.Division; }
2302 | PERCENT { $$ = Operator.OpType.Modulus; }
2303 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2304 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2305 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2306 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2307 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2308 | OP_EQ { $$ = Operator.OpType.Equality; }
2309 | OP_NE { $$ = Operator.OpType.Inequality; }
2310 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2311 | OP_LT { $$ = Operator.OpType.LessThan; }
2312 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2313 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2316 if (lang_version != LanguageVersion.Experimental)
2317 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2319 $$ = Operator.OpType.Is;
2323 conversion_operator_declarator
2324 : IMPLICIT OPERATOR type OPEN_PARENS
2326 valid_param_mod = ParameterModifierType.DefaultValue;
2328 opt_formal_parameter_list CLOSE_PARENS
2330 valid_param_mod = 0;
2332 Location loc = GetLocation ($2);
2333 current_local_parameters = (ParametersCompiled)$6;
2335 if (current_local_parameters.Count != 1) {
2336 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2340 tmpComment = Lexer.consume_doc_comment ();
2341 Lexer.doc_state = XmlCommentState.NotAllowed;
2344 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2345 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2347 | EXPLICIT OPERATOR type OPEN_PARENS
2349 valid_param_mod = ParameterModifierType.DefaultValue;
2351 opt_formal_parameter_list CLOSE_PARENS
2353 valid_param_mod = 0;
2355 Location loc = GetLocation ($2);
2356 current_local_parameters = (ParametersCompiled)$6;
2358 if (current_local_parameters.Count != 1) {
2359 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2363 tmpComment = Lexer.consume_doc_comment ();
2364 Lexer.doc_state = XmlCommentState.NotAllowed;
2367 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2368 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2372 Error_SyntaxError (yyToken);
2373 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2374 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2378 Error_SyntaxError (yyToken);
2379 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2380 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2384 constructor_declaration
2385 : constructor_declarator
2388 Constructor c = (Constructor) $1;
2389 c.Block = (ToplevelBlock) $2;
2392 c.DocComment = ConsumeStoredComment ();
2394 current_local_parameters = null;
2396 Lexer.doc_state = XmlCommentState.Allowed;
2400 constructor_declarator
2406 tmpComment = Lexer.consume_doc_comment ();
2407 Lexer.doc_state = XmlCommentState.Allowed;
2410 valid_param_mod = ParameterModifierType.All;
2412 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2414 valid_param_mod = 0;
2415 current_local_parameters = (ParametersCompiled) $6;
2417 var lt = (LocatedToken) $3;
2418 var mods = (Modifiers) $2;
2419 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2421 if (lt.Value != current_container.MemberName.Name) {
2422 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2423 } else if ((mods & Modifiers.STATIC) != 0) {
2424 if (!current_local_parameters.IsEmpty) {
2425 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2426 c.GetSignatureForError ());
2429 if ((mods & Modifiers.AccessibilityMask) != 0){
2430 report.Error (515, c.Location,
2431 "`{0}': static constructor cannot have an access modifier",
2432 c.GetSignatureForError ());
2435 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2436 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2440 current_type.AddConstructor (c);
2441 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2445 // start block here, so possible anonymous methods inside
2446 // constructor initializer can get correct parent block
2448 start_block (lexer.Location);
2450 opt_constructor_initializer
2453 var c = (Constructor) $8;
2454 c.Initializer = (ConstructorInitializer) $9;
2457 report.Error (514, c.Location,
2458 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2459 c.GetSignatureForError ());
2469 | SEMICOLON { current_block = null; $$ = null; }
2472 opt_constructor_initializer
2474 | constructor_initializer
2477 constructor_initializer
2478 : COLON BASE OPEN_PARENS
2480 ++lexer.parsing_block;
2482 opt_argument_list CLOSE_PARENS
2484 --lexer.parsing_block;
2485 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2486 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2488 | COLON THIS OPEN_PARENS
2490 ++lexer.parsing_block;
2492 opt_argument_list CLOSE_PARENS
2494 --lexer.parsing_block;
2495 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2496 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2500 Error_SyntaxError (yyToken);
2501 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2502 lbag.AddLocation ($$, GetLocation ($1));
2506 Error_SyntaxError (yyToken);
2511 destructor_declaration
2512 : opt_attributes opt_modifiers TILDE
2515 tmpComment = Lexer.consume_doc_comment ();
2516 Lexer.doc_state = XmlCommentState.NotAllowed;
2519 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2521 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2523 var lt = (LocatedToken) $5;
2524 if (lt.Value != current_container.MemberName.Name){
2525 report.Error (574, lt.Location, "Name of destructor must match name of class");
2526 } else if (current_container.Kind != MemberKind.Class){
2527 report.Error (575, lt.Location, "Only class types can contain destructor");
2530 Destructor d = new Destructor (current_type, (Modifiers) $2,
2531 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2533 d.DocComment = ConsumeStoredComment ();
2535 d.Block = (ToplevelBlock) $8;
2536 current_type.AddMember (d);
2537 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2539 current_local_parameters = null;
2546 EVENT type member_declaration_name
2548 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2549 current_type.AddMember (current_event_field);
2551 if (current_event_field.MemberName.ExplicitInterface != null) {
2552 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2553 current_event_field.GetSignatureForError ());
2556 $$ = current_event_field;
2558 opt_event_initializer
2559 opt_event_declarators
2563 current_event_field.DocComment = Lexer.consume_doc_comment ();
2564 Lexer.doc_state = XmlCommentState.Allowed;
2567 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2568 current_event_field = null;
2572 EVENT type member_declaration_name
2575 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2576 current_type.AddMember (current_event);
2577 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2579 lexer.EventParsing = true;
2581 event_accessor_declarations
2583 if (current_container.Kind == MemberKind.Interface)
2584 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2586 lexer.EventParsing = false;
2591 current_event.DocComment = Lexer.consume_doc_comment ();
2592 Lexer.doc_state = XmlCommentState.Allowed;
2595 lbag.AppendToMember (current_event, GetLocation ($9));
2596 current_event = null;
2597 current_local_parameters = null;
2603 Error_SyntaxError (yyToken);
2605 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2609 opt_event_initializer
2613 ++lexer.parsing_block;
2615 event_variable_initializer
2617 --lexer.parsing_block;
2618 current_event_field.Initializer = (Expression) $3;
2622 opt_event_declarators
2630 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2632 | event_declarators event_declarator
2634 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2641 var lt = (LocatedToken) $2;
2642 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2643 lbag.AddLocation ($$, GetLocation ($1));
2645 | COMMA IDENTIFIER ASSIGN event_variable_initializer
2647 var lt = (LocatedToken) $2;
2648 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $4);
2649 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2653 event_variable_initializer
2655 if (current_container.Kind == MemberKind.Interface) {
2656 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2657 current_event_field.GetSignatureForError ());
2660 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2661 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2662 current_event_field.GetSignatureForError ());
2665 ++lexer.parsing_block;
2666 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2667 start_block (lexer.Location);
2669 variable_initializer
2673 --lexer.parsing_block;
2674 end_block (lexer.Location);
2675 current_local_parameters = null;
2679 event_accessor_declarations
2680 : add_accessor_declaration remove_accessor_declaration
2681 | remove_accessor_declaration add_accessor_declaration
2682 | add_accessor_declaration
2684 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2685 current_event.GetSignatureForError ());
2687 | remove_accessor_declaration
2689 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2690 current_event.GetSignatureForError ());
2694 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2699 add_accessor_declaration
2700 : opt_attributes opt_modifiers ADD
2702 if ($2 != ModifierNone) {
2703 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2706 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2707 current_local_parameters = current_event.Add.ParameterInfo;
2709 lbag.AddMember (current_event.Add, mod_locations);
2710 lexer.EventParsing = false;
2712 event_accessor_block
2714 lexer.EventParsing = true;
2716 current_event.Add.Block = (ToplevelBlock) $5;
2718 if (current_container.Kind == MemberKind.Interface) {
2719 report.Error (531, current_event.Add.Block.StartLocation,
2720 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2723 current_local_parameters = null;
2727 remove_accessor_declaration
2728 : opt_attributes opt_modifiers REMOVE
2730 if ($2 != ModifierNone) {
2731 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2734 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2735 current_local_parameters = current_event.Remove.ParameterInfo;
2737 lbag.AddMember (current_event.Remove, mod_locations);
2738 lexer.EventParsing = false;
2740 event_accessor_block
2742 lexer.EventParsing = true;
2744 current_event.Remove.Block = (ToplevelBlock) $5;
2746 if (current_container.Kind == MemberKind.Interface) {
2747 report.Error (531, current_event.Remove.Block.StartLocation,
2748 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2751 current_local_parameters = null;
2755 event_accessor_block
2758 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2765 attributes_without_members
2766 : attribute_sections CLOSE_BRACE
2768 current_type.UnattachedAttributes = (Attributes) $1;
2769 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2770 lexer.putback ('}');
2774 // For full ast try to recover incomplete ambiguous member
2775 // declaration in form on class X { public int }
2777 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2779 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2781 lexer.putback ('}');
2783 lexer.parsing_generic_declaration = false;
2784 FullNamedExpression type = (FullNamedExpression) $3;
2785 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2786 current_type.AddField (current_field);
2794 ENUM type_declaration_name
2798 enumTypeComment = Lexer.consume_doc_comment ();
2803 Lexer.doc_state = XmlCommentState.Allowed;
2805 MemberName name = (MemberName) $4;
2806 if (name.IsGeneric) {
2807 report.Error (1675, name.Location, "Enums cannot have type parameters");
2810 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2812 opt_enum_member_declarations
2814 lexer.parsing_modifiers = true;
2816 // here will be evaluated after CLOSE_BLACE is consumed.
2818 Lexer.doc_state = XmlCommentState.Allowed;
2820 CLOSE_BRACE opt_semicolon
2823 current_container.DocComment = enumTypeComment;
2825 --lexer.parsing_declaration;
2828 // em.DocComment = ev.DocComment;
2830 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2831 $$ = pop_current_class ();
2843 Error_TypeExpected (GetLocation ($1));
2848 opt_enum_member_declarations
2850 | enum_member_declarations
2851 | enum_member_declarations COMMA
2853 lbag.AddLocation ($1, GetLocation ($2));
2857 enum_member_declarations
2858 : enum_member_declaration
2859 | enum_member_declarations COMMA enum_member_declaration
2861 lbag.AddLocation ($1, GetLocation ($2));
2866 enum_member_declaration
2867 : opt_attributes IDENTIFIER
2869 var lt = (LocatedToken) $2;
2870 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2871 ((Enum) current_type).AddEnumMember (em);
2874 em.DocComment = Lexer.consume_doc_comment ();
2875 Lexer.doc_state = XmlCommentState.Allowed;
2880 | opt_attributes IDENTIFIER
2882 ++lexer.parsing_block;
2884 tmpComment = Lexer.consume_doc_comment ();
2885 Lexer.doc_state = XmlCommentState.NotAllowed;
2888 ASSIGN constant_expression
2890 --lexer.parsing_block;
2892 var lt = (LocatedToken) $2;
2893 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2894 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2895 ((Enum) current_type).AddEnumMember (em);
2898 em.DocComment = ConsumeStoredComment ();
2902 | opt_attributes IDENTIFIER error
2904 Error_SyntaxError (yyToken);
2906 var lt = (LocatedToken) $2;
2907 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2908 ((Enum) current_type).AddEnumMember (em);
2911 em.DocComment = Lexer.consume_doc_comment ();
2912 Lexer.doc_state = XmlCommentState.Allowed;
2917 | attributes_without_members
2920 delegate_declaration
2924 member_type type_declaration_name
2927 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2929 opt_formal_parameter_list CLOSE_PARENS
2931 valid_param_mod = 0;
2933 ParametersCompiled p = (ParametersCompiled) $8;
2935 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2937 p.CheckParameters (del);
2939 current_container.AddTypeContainer (del);
2941 current_delegate = del;
2942 lexer.ConstraintsParsing = true;
2944 opt_type_parameter_constraints_clauses
2946 lexer.ConstraintsParsing = false;
2951 current_delegate.DocComment = Lexer.consume_doc_comment ();
2952 Lexer.doc_state = XmlCommentState.Allowed;
2956 current_delegate.SetConstraints ((List<Constraints>) $11);
2957 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2959 $$ = current_delegate;
2961 current_delegate = null;
2969 if (lang_version < LanguageVersion.ISO_2)
2970 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2972 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2976 namespace_or_type_expr
2978 | qualified_alias_member IDENTIFIER opt_type_argument_list
2980 var lt1 = (LocatedToken) $1;
2981 var lt2 = (LocatedToken) $2;
2983 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2984 lbag.AddLocation ($$, GetLocation ($2));
2986 | qualified_alias_member IDENTIFIER generic_dimension
2988 var lt1 = (LocatedToken) $1;
2989 var lt2 = (LocatedToken) $2;
2991 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2992 lbag.AddLocation ($$, GetLocation ($2));
2998 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
3000 var lt = (LocatedToken) $3;
3001 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3002 lbag.AddLocation ($$, GetLocation ($2));
3004 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
3006 var lt = (LocatedToken) $3;
3007 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3008 lbag.AddLocation ($$, GetLocation ($2));
3013 : IDENTIFIER opt_type_argument_list
3015 var lt = (LocatedToken) $1;
3016 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3018 | IDENTIFIER generic_dimension
3020 var lt = (LocatedToken) $1;
3021 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3026 // Generics arguments (any type, without attributes)
3028 opt_type_argument_list
3030 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3032 if (lang_version < LanguageVersion.ISO_2)
3033 FeatureIsNotAvailable (GetLocation ($1), "generics");
3037 | OP_GENERICS_LT error
3039 Error_TypeExpected (lexer.Location);
3040 $$ = new TypeArguments ();
3047 TypeArguments type_args = new TypeArguments ();
3048 type_args.Add ((FullNamedExpression) $1);
3051 | type_arguments COMMA type
3053 TypeArguments type_args = (TypeArguments) $1;
3054 type_args.Add ((FullNamedExpression) $3);
3060 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3062 type_declaration_name
3065 lexer.parsing_generic_declaration = true;
3067 opt_type_parameter_list
3069 lexer.parsing_generic_declaration = false;
3070 var lt = (LocatedToken) $1;
3071 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3075 member_declaration_name
3076 : method_declaration_name
3078 MemberName mn = (MemberName)$1;
3079 if (mn.TypeParameters != null)
3080 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3081 mn.GetSignatureForError ()));
3085 method_declaration_name
3086 : type_declaration_name
3087 | explicit_interface IDENTIFIER opt_type_parameter_list
3089 lexer.parsing_generic_declaration = false;
3090 var lt = (LocatedToken) $2;
3091 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3095 indexer_declaration_name
3098 lexer.parsing_generic_declaration = false;
3099 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3101 | explicit_interface THIS
3103 lexer.parsing_generic_declaration = false;
3104 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3109 : IDENTIFIER opt_type_argument_list DOT
3111 var lt = (LocatedToken) $1;
3112 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3113 lbag.AddLocation ($$, GetLocation ($3));
3115 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3117 var lt1 = (LocatedToken) $1;
3118 var lt2 = (LocatedToken) $2;
3120 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3121 lbag.AddLocation ($$, GetLocation ($4));
3123 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3125 var lt = (LocatedToken) $2;
3126 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3127 lbag.AddLocation ($$, GetLocation ($4));
3131 opt_type_parameter_list
3133 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3135 if (lang_version < LanguageVersion.ISO_2)
3136 FeatureIsNotAvailable (GetLocation ($1), "generics");
3139 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3146 var tparams = new TypeParameters ();
3147 tparams.Add ((TypeParameter)$1);
3150 | type_parameters COMMA type_parameter
3152 var tparams = (TypeParameters) $1;
3153 tparams.Add ((TypeParameter)$3);
3155 lbag.AddLocation ($3, GetLocation ($3));
3160 : opt_attributes opt_type_parameter_variance IDENTIFIER
3162 var lt = (LocatedToken)$3;
3163 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3167 if (GetTokenName (yyToken) == "type")
3168 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3170 Error_SyntaxError (yyToken);
3172 $$ = new TypeParameter (MemberName.Null, null, null);
3177 // All types where void is allowed
3180 : type_expression_or_array
3183 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3190 lexer.parsing_generic_declaration = true;
3195 // A type which does not allow `void' to be used
3198 : type_expression_or_array
3208 : type_expression_or_array
3211 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3212 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3216 type_expression_or_array
3218 | type_expression rank_specifiers
3220 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3225 : namespace_or_type_expr opt_nullable
3228 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3230 var sn = $1 as SimpleName;
3231 if (sn != null && sn.Name == "var")
3232 $$ = new VarExpr (sn.Location);
3237 | namespace_or_type_expr pointer_stars
3239 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3241 | builtin_type_expression
3242 | OPEN_PARENS tuple_elements CLOSE_PARENS opt_nullable
3244 if (lang_version < LanguageVersion.V_7)
3245 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3247 var a = (Tuple<TypeArguments, List<string>>) $2;
3248 if (a.Item1.Count < 2) {
3249 report.Error (8124, GetLocation ($1), "Tuple must contain at least two elements");
3252 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
3255 $$ = new ComposedCast ((FullNamedExpression) $$, (ComposedTypeSpecifier) $4);
3260 : tuple_element tuple_element_name
3262 var type_args = new TypeArguments ();
3263 type_args.Add ((FullNamedExpression) $1);
3265 var names = new List<string> (2);
3266 var lt = (LocatedToken) $2;
3267 names.Add (lt?.Value);
3269 $$ = Tuple.Create (type_args, names);
3271 | tuple_elements COMMA tuple_element tuple_element_name
3273 var a = (Tuple<TypeArguments, List<string>>) $1;
3274 a.Item1.Add ((FullNamedExpression) $3);
3275 var lt = (LocatedToken) $4;
3276 a.Item2.Add (lt?.Value);
3293 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3294 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3298 builtin_type_expression
3299 : builtin_types opt_nullable
3302 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3304 | builtin_types pointer_stars
3306 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3308 | VOID pointer_stars
3310 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3317 var types = new List<FullNamedExpression> (2);
3318 types.Add ((FullNamedExpression) $1);
3321 | type_list COMMA base_type_name
3323 var types = (List<FullNamedExpression>) $1;
3324 types.Add ((FullNamedExpression) $3);
3332 if ($1 is ComposedCast) {
3333 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3340 * replaces all the productions for isolating the various
3341 * simple types, but we need this to reuse it easily in variable_type
3344 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3345 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3346 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3347 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3348 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3349 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3354 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3355 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3356 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3357 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3358 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3359 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3360 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3361 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3362 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3366 // Expressions, section 7.5
3371 : type_name_expression
3373 | array_creation_expression
3374 | parenthesized_expression
3375 | default_value_expression
3376 | invocation_expression
3380 | post_increment_expression
3381 | post_decrement_expression
3382 | object_or_delegate_creation_expression
3383 | anonymous_type_expression
3386 | checked_expression
3387 | unchecked_expression
3388 | pointer_member_access
3389 | anonymous_method_expression
3390 | undocumented_expressions
3391 | interpolated_string
3394 type_name_expression
3396 | IDENTIFIER GENERATE_COMPLETION {
3397 var lt = (LocatedToken) $1;
3398 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3407 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3411 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3412 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3416 : OPEN_PARENS tuple_literal_elements CLOSE_PARENS
3418 if (lang_version < LanguageVersion.V_7)
3419 FeatureIsNotAvailable (GetLocation ($1), "tuples");
3421 $$ = new TupleLiteral ((List<TupleLiteralElement>)$2, GetLocation ($1));
3425 tuple_literal_elements
3426 : tuple_literal_element COMMA tuple_literal_element
3428 $$ = new List<TupleLiteralElement> () {
3429 (TupleLiteralElement) $1, (TupleLiteralElement) $3
3432 | tuple_literal_elements COMMA tuple_literal_element
3434 var list = (List<TupleLiteralElement>)$1;
3435 list.Add ((TupleLiteralElement) $3);
3439 tuple_literal_element
3442 $$ = new TupleLiteralElement ((Expression) $1);
3444 | IDENTIFIER COLON expression
3446 var lt = (LocatedToken) $1;
3447 $$ = new TupleLiteralElement (lt.Value, (Expression) $3, lt.Location);
3452 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3454 if (lang_version < LanguageVersion.V_6)
3455 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3457 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3459 | INTERPOLATED_STRING_END
3461 if (lang_version < LanguageVersion.V_6)
3462 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3464 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3471 var list = new List<Expression> ();
3472 list.Add ((InterpolatedStringInsert) $1);
3475 | interpolations INTERPOLATED_STRING interpolation
3477 var list = (List<Expression>) $1;
3478 list.Add ((StringLiteral) $2);
3479 list.Add ((InterpolatedStringInsert) $3);
3487 $$ = new InterpolatedStringInsert ((Expression) $1);
3489 | expression COMMA expression
3491 $$ = new InterpolatedStringInsert ((Expression) $1) {
3492 Alignment = (Expression)$3
3497 lexer.parsing_interpolation_format = true;
3501 lexer.parsing_interpolation_format = false;
3503 $$ = new InterpolatedStringInsert ((Expression) $1) {
3507 | expression COMMA expression COLON
3509 lexer.parsing_interpolation_format = true;
3513 lexer.parsing_interpolation_format = false;
3515 $$ = new InterpolatedStringInsert ((Expression) $1) {
3516 Alignment = (Expression)$3,
3517 Format = (string) $6
3524 // Here is the trick, tokenizer may think that parens is a special but
3525 // parser is interested in open parens only, so we merge them.
3526 // Consider: if (a)foo ();
3534 // Use this production to accept closing parenthesis or
3535 // performing completion
3539 | COMPLETE_COMPLETION
3543 parenthesized_expression
3544 : OPEN_PARENS expression CLOSE_PARENS
3546 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3547 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3549 | OPEN_PARENS expression COMPLETE_COMPLETION
3551 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3556 : primary_expression DOT identifier_inside_body opt_type_argument_list
3558 var lt = (LocatedToken) $3;
3559 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3560 lbag.AddLocation ($$, GetLocation ($2));
3562 | primary_expression DOT identifier_inside_body generic_dimension
3564 var lt = (LocatedToken) $3;
3565 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3566 lbag.AddLocation ($$, GetLocation ($2));
3568 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3570 if (lang_version < LanguageVersion.V_6)
3571 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3573 var lt = (LocatedToken) $4;
3574 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3575 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3577 | builtin_types DOT identifier_inside_body opt_type_argument_list
3579 var lt = (LocatedToken) $3;
3580 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3581 lbag.AddLocation ($$, GetLocation ($2));
3583 | BASE DOT identifier_inside_body opt_type_argument_list
3585 var lt = (LocatedToken) $3;
3586 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3587 lbag.AddLocation ($$, GetLocation ($2));
3589 | AWAIT DOT identifier_inside_body opt_type_argument_list
3591 var lt = (LocatedToken) $3;
3592 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3593 lbag.AddLocation ($$, GetLocation ($2));
3595 | qualified_alias_member identifier_inside_body opt_type_argument_list
3597 var lt1 = (LocatedToken) $1;
3598 var lt2 = (LocatedToken) $2;
3600 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3601 lbag.AddLocation ($$, GetLocation ($2));
3603 | qualified_alias_member identifier_inside_body generic_dimension
3605 var lt1 = (LocatedToken) $1;
3606 var lt2 = (LocatedToken) $2;
3608 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3609 lbag.AddLocation ($$, GetLocation ($2));
3611 | primary_expression DOT GENERATE_COMPLETION {
3612 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3614 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3615 var lt = (LocatedToken) $3;
3616 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3618 | builtin_types DOT GENERATE_COMPLETION
3620 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3622 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3623 var lt = (LocatedToken) $3;
3624 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3628 invocation_expression
3629 : primary_expression open_parens_any opt_argument_list close_parens
3631 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3632 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3634 | primary_expression open_parens_any argument_list error
3636 Error_SyntaxError (yyToken);
3638 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3639 lbag.AddLocation ($$, GetLocation ($2));
3641 | primary_expression open_parens_any error
3643 Error_SyntaxError (yyToken);
3645 $$ = new Invocation ((Expression) $1, null);
3646 lbag.AddLocation ($$, GetLocation ($2));
3650 opt_object_or_collection_initializer
3651 : /* empty */ { $$ = null; }
3652 | object_or_collection_initializer
3655 object_or_collection_initializer
3656 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3659 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3661 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3663 lbag.AddLocation ($$, GetLocation ($3));
3665 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3667 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3668 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3672 opt_member_initializer_list
3673 : /* empty */ { $$ = null; }
3674 | member_initializer_list
3680 member_initializer_list
3681 : member_initializer
3683 var a = new List<Expression> ();
3684 a.Add ((Expression) $1);
3687 | member_initializer_list COMMA member_initializer
3689 var a = (List<Expression>)$1;
3690 a.Add ((Expression) $3);
3693 | member_initializer_list error {
3694 Error_SyntaxError (yyToken);
3700 : IDENTIFIER ASSIGN initializer_value
3702 var lt = (LocatedToken) $1;
3703 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3704 lbag.AddLocation ($$, GetLocation ($2));
3706 | AWAIT ASSIGN initializer_value
3708 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3709 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3710 lbag.AddLocation ($$, GetLocation ($2));
3712 | GENERATE_COMPLETION
3714 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3716 | non_assignment_expression opt_COMPLETE_COMPLETION {
3717 CompletionSimpleName csn = $1 as CompletionSimpleName;
3719 $$ = new CollectionElementInitializer ((Expression)$1);
3721 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3723 | OPEN_BRACE expression_list CLOSE_BRACE
3726 $$ = new CollectionElementInitializer (GetLocation ($1));
3728 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3730 lbag.AddLocation ($$, GetLocation ($3));
3732 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3734 if (lang_version < LanguageVersion.V_6)
3735 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3737 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3738 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3740 | OPEN_BRACE CLOSE_BRACE
3742 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3743 $$ = new CollectionElementInitializer (GetLocation ($1));
3744 lbag.AddLocation ($$, GetLocation ($2));
3750 | object_or_collection_initializer
3754 : /* empty */ { $$ = null; }
3759 : argument_or_named_argument
3761 Arguments list = new Arguments (4);
3762 list.Add ((Argument) $1);
3765 | argument_list COMMA argument
3767 Arguments list = (Arguments) $1;
3768 if (list [list.Count - 1] is NamedArgument)
3769 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3771 list.Add ((Argument) $3);
3774 | argument_list COMMA named_argument
3776 Arguments list = (Arguments) $1;
3777 NamedArgument a = (NamedArgument) $3;
3778 for (int i = 0; i < list.Count; ++i) {
3779 NamedArgument na = list [i] as NamedArgument;
3780 if (na != null && na.Name == a.Name)
3781 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3788 | argument_list COMMA error
3790 if (lexer.putback_char == -1)
3791 lexer.putback (')'); // TODO: Wrong but what can I do
3792 Error_SyntaxError (yyToken);
3797 report.Error (839, GetLocation ($1), "An argument is missing");
3805 $$ = new Argument ((Expression) $1);
3807 | non_simple_argument
3810 argument_or_named_argument
3816 : REF variable_reference
3818 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3819 lbag.AddLocation ($$, GetLocation ($1));
3821 | OUT variable_reference
3823 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3824 lbag.AddLocation ($$, GetLocation ($1));
3826 | OUT out_variable_declaration
3828 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3830 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3832 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3833 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3835 | ARGLIST OPEN_PARENS CLOSE_PARENS
3837 $$ = new Argument (new Arglist (GetLocation ($1)));
3838 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3842 out_variable_declaration
3843 : variable_type identifier_inside_body
3845 if (lang_version < LanguageVersion.V_7)
3846 FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
3848 var lt = (LocatedToken) $2;
3849 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3850 current_block.AddLocalName (lv);
3851 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3860 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3862 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3863 lbag.AddLocation ($$, GetLocation ($4));
3865 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3867 if (lang_version < LanguageVersion.V_6)
3868 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3870 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3871 ConditionalAccess = true
3874 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3876 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3878 Error_SyntaxError (yyToken);
3879 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3881 | primary_expression OPEN_BRACKET_EXPR error
3883 Error_SyntaxError (yyToken);
3884 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3889 : expression_or_error
3891 var list = new List<Expression> (4);
3892 list.Add ((Expression) $1);
3895 | expression_list COMMA expression_or_error
3897 var list = (List<Expression>) $1;
3898 list.Add ((Expression) $3);
3903 expression_list_arguments
3904 : expression_list_argument
3906 Arguments args = new Arguments (4);
3907 args.Add ((Argument) $1);
3910 | expression_list_arguments COMMA expression_list_argument
3912 Arguments args = (Arguments) $1;
3913 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3914 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3916 args.Add ((Argument) $3);
3921 expression_list_argument
3924 $$ = new Argument ((Expression) $1);
3932 $$ = new This (GetLocation ($1));
3937 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3939 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3940 lbag.AddLocation ($$, GetLocation ($4));
3942 | BASE OPEN_BRACKET error
3944 Error_SyntaxError (yyToken);
3945 $$ = new ElementAccess (null, null, GetLocation ($2));
3949 post_increment_expression
3950 : primary_expression OP_INC
3952 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3956 post_decrement_expression
3957 : primary_expression OP_DEC
3959 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3963 object_or_delegate_creation_expression
3964 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3967 if (lang_version <= LanguageVersion.ISO_2)
3968 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3970 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3972 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3975 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3977 | NEW new_expr_type object_or_collection_initializer
3979 if (lang_version <= LanguageVersion.ISO_2)
3980 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3982 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3986 array_creation_expression
3987 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3989 opt_array_initializer
3991 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3992 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3993 Next = (ComposedTypeSpecifier) $6
3994 }, (ArrayInitializer) $7, GetLocation ($1)) {
3995 NoEmptyInterpolation = true
3998 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4000 | NEW new_expr_type rank_specifiers opt_array_initializer
4003 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
4005 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
4006 NoEmptyInterpolation = true
4009 | NEW rank_specifier array_initializer
4011 if (lang_version <= LanguageVersion.ISO_2)
4012 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
4014 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
4016 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
4018 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
4019 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
4021 | NEW new_expr_type error
4023 Error_SyntaxError (yyToken);
4024 // It can be any of new expression, create the most common one
4025 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
4031 ++lexer.parsing_type;
4035 --lexer.parsing_type;
4040 anonymous_type_expression
4041 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
4043 if (lang_version <= LanguageVersion.ISO_2)
4044 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
4046 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
4048 // TODO: lbag comma location
4049 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4051 | NEW OPEN_BRACE GENERATE_COMPLETION
4053 $$ = new EmptyCompletion ();
4057 anonymous_type_parameters_opt_comma
4058 : anonymous_type_parameters_opt
4059 | anonymous_type_parameters COMMA
4062 anonymous_type_parameters_opt
4064 | anonymous_type_parameters
4067 anonymous_type_parameters
4068 : anonymous_type_parameter
4070 var a = new List<AnonymousTypeParameter> (4);
4071 a.Add ((AnonymousTypeParameter) $1);
4074 | anonymous_type_parameters COMMA anonymous_type_parameter
4076 var a = (List<AnonymousTypeParameter>) $1;
4077 a.Add ((AnonymousTypeParameter) $3);
4080 | COMPLETE_COMPLETION
4082 $$ = new EmptyCompletion ();
4084 | anonymous_type_parameter COMPLETE_COMPLETION
4090 anonymous_type_parameter
4091 : identifier_inside_body ASSIGN variable_initializer
4093 var lt = (LocatedToken)$1;
4094 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4095 lbag.AddLocation ($$, GetLocation ($2));
4097 | identifier_inside_body
4099 var lt = (LocatedToken)$1;
4100 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4101 lt.Value, lt.Location);
4105 MemberAccess ma = (MemberAccess) $1;
4106 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4110 report.Error (746, lexer.Location,
4111 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4123 | rank_specifier rank_specifiers
4125 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4131 : OPEN_BRACKET CLOSE_BRACKET
4133 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4134 lbag.AddLocation ($$, GetLocation ($2));
4136 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4138 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4139 lbag.AddLocation ($$, GetLocation ($3));
4148 | dim_separators COMMA
4150 $$ = ((int) $1) + 1;
4154 opt_array_initializer
4166 : OPEN_BRACE CLOSE_BRACE
4168 var ai = new ArrayInitializer (0, GetLocation ($1));
4169 ai.VariableDeclaration = current_variable;
4170 lbag.AddLocation (ai, GetLocation ($2));
4173 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4175 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4176 ai.VariableDeclaration = current_variable;
4178 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4180 lbag.AddLocation (ai, GetLocation ($4));
4186 variable_initializer_list
4187 : variable_initializer
4189 var list = new List<Expression> (4);
4190 list.Add ((Expression) $1);
4193 | variable_initializer_list COMMA variable_initializer
4195 var list = (List<Expression>) $1;
4196 list.Add ((Expression) $3);
4202 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4204 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4205 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4209 typeof_type_expression
4213 Error_TypeExpected (lexer.Location);
4221 if (lang_version < LanguageVersion.ISO_2)
4222 FeatureIsNotAvailable (GetLocation ($1), "generics");
4228 qualified_alias_member
4229 : IDENTIFIER DOUBLE_COLON
4231 var lt = (LocatedToken) $1;
4232 if (lang_version == LanguageVersion.ISO_1)
4233 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4240 : SIZEOF open_parens_any type CLOSE_PARENS
4242 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4243 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4245 | SIZEOF open_parens_any type error
4247 Error_SyntaxError (yyToken);
4249 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4250 lbag.AddLocation ($$, GetLocation ($2));
4255 : CHECKED open_parens_any expression CLOSE_PARENS
4257 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4258 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4262 Error_SyntaxError (yyToken);
4264 $$ = new CheckedExpr (null, GetLocation ($1));
4268 unchecked_expression
4269 : UNCHECKED open_parens_any expression CLOSE_PARENS
4271 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4272 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4276 Error_SyntaxError (yyToken);
4278 $$ = new UnCheckedExpr (null, GetLocation ($1));
4282 pointer_member_access
4283 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4285 var lt = (LocatedToken) $3;
4286 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4290 anonymous_method_expression
4291 : DELEGATE opt_anonymous_method_signature
4293 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4297 $$ = end_anonymous ((ParametersBlock) $4);
4299 | ASYNC DELEGATE opt_anonymous_method_signature
4301 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4305 $$ = end_anonymous ((ParametersBlock) $5);
4309 opt_anonymous_method_signature
4312 $$ = ParametersCompiled.Undefined;
4314 | anonymous_method_signature
4317 anonymous_method_signature
4320 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4322 opt_formal_parameter_list CLOSE_PARENS
4324 valid_param_mod = 0;
4329 default_value_expression
4330 : DEFAULT open_parens_any type CLOSE_PARENS
4332 if (lang_version < LanguageVersion.ISO_2)
4333 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4335 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4336 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4341 : primary_expression
4342 | BANG prefixed_unary_expression
4344 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4346 | TILDE prefixed_unary_expression
4348 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4350 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4352 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4353 lbag.AddLocation ($$, GetLocation ($3));
4355 | AWAIT prefixed_unary_expression
4358 if (current_anonymous_method is LambdaExpression) {
4359 report.Error (4034, GetLocation ($1),
4360 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4361 } else if (current_anonymous_method != null) {
4362 report.Error (4035, GetLocation ($1),
4363 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4364 } else if (interactive_async != null) {
4365 current_block.Explicit.RegisterAsyncAwait ();
4366 interactive_async = true;
4368 report.Error (4033, GetLocation ($1),
4369 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4372 current_block.Explicit.RegisterAsyncAwait ();
4375 $$ = new Await ((Expression) $2, GetLocation ($1));
4377 | THROW_EXPR prefixed_unary_expression
4379 if (lang_version < LanguageVersion.V_7)
4380 FeatureIsNotAvailable (lexer.Location, "throw expression");
4382 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4386 Error_SyntaxError (yyToken);
4388 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4392 Error_SyntaxError (yyToken);
4394 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4396 | OPEN_PARENS_CAST type CLOSE_PARENS error
4398 Error_SyntaxError (yyToken);
4400 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4401 lbag.AddLocation ($$, GetLocation ($3));
4405 Error_SyntaxError (yyToken);
4407 $$ = new Await (null, GetLocation ($1));
4412 // The idea to split this out is from Rhys' grammar
4413 // to solve the problem with casts.
4415 prefixed_unary_expression
4417 | PLUS prefixed_unary_expression
4419 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4421 | MINUS prefixed_unary_expression
4423 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4425 | OP_INC prefixed_unary_expression
4427 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4429 | OP_DEC prefixed_unary_expression
4431 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4433 | STAR prefixed_unary_expression
4435 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4437 | BITWISE_AND prefixed_unary_expression
4439 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4443 Error_SyntaxError (yyToken);
4445 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4449 Error_SyntaxError (yyToken);
4451 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4455 Error_SyntaxError (yyToken);
4457 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4461 Error_SyntaxError (yyToken);
4463 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4467 Error_SyntaxError (yyToken);
4469 $$ = new Indirection (null, GetLocation ($1));
4473 Error_SyntaxError (yyToken);
4475 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4478 multiplicative_expression
4479 : prefixed_unary_expression
4480 | multiplicative_expression STAR prefixed_unary_expression
4482 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4483 lbag.AddLocation ($$, GetLocation ($2));
4485 | multiplicative_expression DIV prefixed_unary_expression
4487 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4488 lbag.AddLocation ($$, GetLocation ($2));
4490 | multiplicative_expression PERCENT prefixed_unary_expression
4492 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4493 lbag.AddLocation ($$, GetLocation ($2));
4495 | multiplicative_expression STAR error
4497 Error_SyntaxError (yyToken);
4499 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4500 lbag.AddLocation ($$, GetLocation ($2));
4502 | multiplicative_expression DIV error
4504 Error_SyntaxError (yyToken);
4506 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4507 lbag.AddLocation ($$, GetLocation ($2));
4509 | multiplicative_expression PERCENT error
4511 Error_SyntaxError (yyToken);
4513 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4514 lbag.AddLocation ($$, GetLocation ($2));
4519 : multiplicative_expression
4520 | additive_expression PLUS multiplicative_expression
4522 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4523 lbag.AddLocation ($$, GetLocation ($2));
4525 | additive_expression MINUS multiplicative_expression
4527 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4528 lbag.AddLocation ($$, GetLocation ($2));
4530 | additive_expression PLUS error
4532 Error_SyntaxError (yyToken);
4534 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4535 lbag.AddLocation ($$, GetLocation ($2));
4537 | additive_expression MINUS error
4539 Error_SyntaxError (yyToken);
4541 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4542 lbag.AddLocation ($$, GetLocation ($2));
4544 | additive_expression AS type
4546 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4548 | additive_expression IS pattern_type_expr opt_identifier
4550 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4552 if (lang_version < LanguageVersion.V_7)
4553 FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
4555 var lt = (LocatedToken) $4;
4556 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
4557 is_expr.Variable = lv;
4558 current_block.AddLocalName (lv);
4563 | additive_expression IS pattern_expr
4565 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4566 if (lang_version != LanguageVersion.Experimental)
4567 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4571 | additive_expression AS error
4573 Error_SyntaxError (yyToken);
4575 $$ = new As ((Expression) $1, null, GetLocation ($2));
4577 | additive_expression IS error
4579 Error_SyntaxError (yyToken);
4581 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4585 var lt = (LocatedToken) $1;
4586 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4590 var lt = (LocatedToken) $1;
4591 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4601 | PLUS prefixed_unary_expression
4603 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4605 | MINUS prefixed_unary_expression
4607 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4610 | default_value_expression
4611 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4613 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4614 lbag.AddLocation ($$, GetLocation ($3));
4618 $$ = new WildcardPattern (GetLocation ($1));
4620 /* | pattern_expr_invocation */
4625 pattern_expr_invocation
4626 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4628 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4634 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4636 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4640 pattern_property_list
4641 : pattern_property_entry
4643 var list = new List<PropertyPatternMember> ();
4644 list.Add ((PropertyPatternMember) $1);
4647 | pattern_property_list COMMA pattern_property_entry
4649 var list = (List<PropertyPatternMember>) $1;
4650 list.Add ((PropertyPatternMember) $3);
4655 pattern_property_entry
4656 : identifier_inside_body IS pattern
4658 var lt = (LocatedToken) $1;
4659 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4665 | pattern_type_expr opt_identifier
4668 var lt = (LocatedToken) $2;
4669 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4670 current_block.AddLocalName (variable);
4679 $$ = new Arguments (0);
4687 Arguments args = new Arguments (4);
4688 args.Add ((Argument) $1);
4691 | pattern_list COMMA pattern_argument
4693 Arguments args = (Arguments) $1;
4694 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4695 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4697 args.Add ((Argument) $3);
4706 $$ = new Argument ((Expression) $1);
4708 | IDENTIFIER COLON pattern
4710 var lt = (LocatedToken) $1;
4711 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4717 : additive_expression
4718 | shift_expression OP_SHIFT_LEFT additive_expression
4720 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4721 lbag.AddLocation ($$, GetLocation ($2));
4723 | shift_expression OP_SHIFT_RIGHT additive_expression
4725 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4726 lbag.AddLocation ($$, GetLocation ($2));
4728 | shift_expression OP_SHIFT_LEFT error
4730 Error_SyntaxError (yyToken);
4732 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4733 lbag.AddLocation ($$, GetLocation ($2));
4735 | shift_expression OP_SHIFT_RIGHT error
4737 Error_SyntaxError (yyToken);
4739 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4740 lbag.AddLocation ($$, GetLocation ($2));
4744 relational_expression
4746 | relational_expression OP_LT shift_expression
4748 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4749 lbag.AddLocation ($$, GetLocation ($2));
4751 | relational_expression OP_GT shift_expression
4753 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4754 lbag.AddLocation ($$, GetLocation ($2));
4756 | relational_expression OP_LE shift_expression
4758 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4759 lbag.AddLocation ($$, GetLocation ($2));
4761 | relational_expression OP_GE shift_expression
4763 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4764 lbag.AddLocation ($$, GetLocation ($2));
4766 | relational_expression OP_LT error
4768 Error_SyntaxError (yyToken);
4770 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4771 lbag.AddLocation ($$, GetLocation ($2));
4773 | relational_expression OP_GT error
4775 Error_SyntaxError (yyToken);
4777 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4778 lbag.AddLocation ($$, GetLocation ($2));
4780 | relational_expression OP_LE error
4782 Error_SyntaxError (yyToken);
4784 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4785 lbag.AddLocation ($$, GetLocation ($2));
4787 | relational_expression OP_GE error
4789 Error_SyntaxError (yyToken);
4791 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4792 lbag.AddLocation ($$, GetLocation ($2));
4797 : relational_expression
4798 | equality_expression OP_EQ relational_expression
4800 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4801 lbag.AddLocation ($$, GetLocation ($2));
4803 | equality_expression OP_NE relational_expression
4805 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4806 lbag.AddLocation ($$, GetLocation ($2));
4808 | equality_expression OP_EQ error
4810 Error_SyntaxError (yyToken);
4812 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4813 lbag.AddLocation ($$, GetLocation ($2));
4815 | equality_expression OP_NE error
4817 Error_SyntaxError (yyToken);
4819 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4820 lbag.AddLocation ($$, GetLocation ($2));
4825 : equality_expression
4826 | and_expression BITWISE_AND equality_expression
4828 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4829 lbag.AddLocation ($$, GetLocation ($2));
4831 | and_expression BITWISE_AND error
4833 Error_SyntaxError (yyToken);
4835 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4836 lbag.AddLocation ($$, GetLocation ($2));
4840 exclusive_or_expression
4842 | exclusive_or_expression CARRET and_expression
4844 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4845 lbag.AddLocation ($$, GetLocation ($2));
4847 | exclusive_or_expression CARRET error
4849 Error_SyntaxError (yyToken);
4851 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4852 lbag.AddLocation ($$, GetLocation ($2));
4856 inclusive_or_expression
4857 : exclusive_or_expression
4858 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4860 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4861 lbag.AddLocation ($$, GetLocation ($2));
4863 | inclusive_or_expression BITWISE_OR error
4865 Error_SyntaxError (yyToken);
4867 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4868 lbag.AddLocation ($$, GetLocation ($2));
4872 conditional_and_expression
4873 : inclusive_or_expression
4874 | conditional_and_expression OP_AND inclusive_or_expression
4876 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4877 lbag.AddLocation ($$, GetLocation ($2));
4879 | conditional_and_expression OP_AND error
4881 Error_SyntaxError (yyToken);
4883 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4884 lbag.AddLocation ($$, GetLocation ($2));
4888 conditional_or_expression
4889 : conditional_and_expression
4890 | conditional_or_expression OP_OR conditional_and_expression
4892 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4893 lbag.AddLocation ($$, GetLocation ($2));
4895 | conditional_or_expression OP_OR error
4897 Error_SyntaxError (yyToken);
4899 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4900 lbag.AddLocation ($$, GetLocation ($2));
4904 null_coalescing_expression
4905 : conditional_or_expression
4906 | conditional_or_expression OP_COALESCING null_coalescing_expression
4908 if (lang_version < LanguageVersion.ISO_2)
4909 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4911 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4912 lbag.AddLocation ($$, GetLocation ($2));
4916 conditional_expression
4917 : null_coalescing_expression
4918 | null_coalescing_expression INTERR expression COLON expression
4920 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4921 lbag.AddLocation ($$, GetLocation ($4));
4923 | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4925 if (lang_version < LanguageVersion.V_7)
4926 FeatureIsNotAvailable (lexer.Location, "throw expression");
4928 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4929 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4930 lbag.AddLocation ($$, GetLocation ($4));
4932 | null_coalescing_expression INTERR expression error
4934 Error_SyntaxError (yyToken);
4936 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4938 | null_coalescing_expression INTERR expression COLON error
4940 Error_SyntaxError (yyToken);
4942 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4943 lbag.AddLocation ($$, GetLocation ($4));
4945 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4947 Error_SyntaxError (Token.CLOSE_BRACE);
4949 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4950 lbag.AddLocation ($$, GetLocation ($4));
4951 lexer.putback ('}');
4955 assignment_expression
4956 : prefixed_unary_expression ASSIGN expression
4958 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4959 lbag.AddLocation ($$, GetLocation ($2));
4961 | prefixed_unary_expression OP_MULT_ASSIGN expression
4963 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4964 lbag.AddLocation ($$, GetLocation ($2));
4966 | prefixed_unary_expression OP_DIV_ASSIGN expression
4968 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4969 lbag.AddLocation ($$, GetLocation ($2));
4971 | prefixed_unary_expression OP_MOD_ASSIGN expression
4973 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4974 lbag.AddLocation ($$, GetLocation ($2));
4976 | prefixed_unary_expression OP_ADD_ASSIGN expression
4978 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4979 lbag.AddLocation ($$, GetLocation ($2));
4981 | prefixed_unary_expression OP_SUB_ASSIGN expression
4983 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4984 lbag.AddLocation ($$, GetLocation ($2));
4986 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4988 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4989 lbag.AddLocation ($$, GetLocation ($2));
4991 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4993 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4994 lbag.AddLocation ($$, GetLocation ($2));
4996 | prefixed_unary_expression OP_AND_ASSIGN expression
4998 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4999 lbag.AddLocation ($$, GetLocation ($2));
5001 | prefixed_unary_expression OP_OR_ASSIGN expression
5003 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
5004 lbag.AddLocation ($$, GetLocation ($2));
5006 | prefixed_unary_expression OP_XOR_ASSIGN expression
5008 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
5009 lbag.AddLocation ($$, GetLocation ($2));
5011 | OPEN_PARENS_DECONSTRUCT deconstruct_exprs CLOSE_PARENS ASSIGN expression
5013 if (lang_version < LanguageVersion.V_7)
5014 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5016 var exprs = (List<Expression>) $2;
5017 $$ = new TupleDeconstruct (exprs, (Expression) $5, GetLocation ($4));
5022 : expression COMMA expression
5024 $$ = new List<Expression> () {
5029 | deconstruct_exprs COMMA expression
5031 var src = (List<Expression>) $1;
5032 src.Add ((Expression) $3);
5037 lambda_parameter_list
5040 var pars = new List<Parameter> (4);
5041 pars.Add ((Parameter) $1);
5045 | lambda_parameter_list COMMA lambda_parameter
5047 var pars = (List<Parameter>) $1;
5048 Parameter p = (Parameter)$3;
5049 if (pars[0].GetType () != p.GetType ()) {
5050 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
5059 : parameter_modifier parameter_type identifier_inside_body
5061 var lt = (LocatedToken) $3;
5063 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
5065 | parameter_type identifier_inside_body
5067 var lt = (LocatedToken) $2;
5069 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
5073 var lt = (LocatedToken) $1;
5074 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5078 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5079 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
5083 opt_lambda_parameter_list
5084 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
5085 | lambda_parameter_list {
5086 var pars_list = (List<Parameter>) $1;
5087 $$ = new ParametersCompiled (pars_list.ToArray ());
5091 lambda_expression_body
5093 start_block (Location.Null);
5095 expression // All expressions must handle error or current block won't be restored and breaking ast completely
5097 Block b = end_block (Location.Null);
5098 b.IsCompilerGenerated = true;
5099 b.AddStatement (new ContextualReturn ((Expression) $2));
5105 // Handles only cases like foo = x.FirstOrDefault (l => );
5106 // where we must restore current_variable
5107 Block b = end_block (Location.Null);
5108 b.IsCompilerGenerated = true;
5110 Error_SyntaxError (yyToken);
5119 Error_SyntaxError (yyToken);
5127 var lt = (LocatedToken) $1;
5128 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5129 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5131 lambda_expression_body
5133 $$ = end_anonymous ((ParametersBlock) $4);
5134 lbag.AddLocation ($$, GetLocation ($2));
5138 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5139 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5140 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5142 lambda_expression_body
5144 $$ = end_anonymous ((ParametersBlock) $4);
5145 lbag.AddLocation ($$, GetLocation ($2));
5147 | ASYNC identifier_inside_body ARROW
5149 var lt = (LocatedToken) $2;
5150 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5151 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5153 lambda_expression_body
5155 $$ = end_anonymous ((ParametersBlock) $5);
5156 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5158 | OPEN_PARENS_LAMBDA
5160 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5162 opt_lambda_parameter_list CLOSE_PARENS ARROW
5164 valid_param_mod = 0;
5165 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5167 lambda_expression_body
5169 $$ = end_anonymous ((ParametersBlock) $7);
5170 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5172 | ASYNC OPEN_PARENS_LAMBDA
5174 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5176 opt_lambda_parameter_list CLOSE_PARENS ARROW
5178 valid_param_mod = 0;
5179 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5181 lambda_expression_body
5183 $$ = end_anonymous ((ParametersBlock) $8);
5184 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5189 : assignment_expression
5190 | non_assignment_expression
5193 non_assignment_expression
5194 : conditional_expression
5199 $$ = new ArglistAccess (GetLocation ($1));
5203 undocumented_expressions
5204 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5206 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5207 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5209 | REFTYPE open_parens_any expression CLOSE_PARENS
5211 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5212 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5214 | MAKEREF open_parens_any expression CLOSE_PARENS
5216 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5217 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5228 $$ = new BooleanExpression ((Expression) $1);
5232 opt_primary_parameters
5237 | primary_parameters
5241 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5245 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5246 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5248 if (lang_version != LanguageVersion.Experimental)
5249 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5253 opt_primary_parameters_with_class_base
5262 | primary_parameters
5266 | primary_parameters class_base
5270 | primary_parameters class_base OPEN_PARENS
5272 ++lexer.parsing_block;
5273 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5275 opt_argument_list CLOSE_PARENS
5277 lbag.AppendToMember (current_container, GetLocation ($6));
5278 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5279 --lexer.parsing_block;
5295 type_declaration_name
5297 lexer.ConstraintsParsing = true;
5299 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5300 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5301 FeatureIsNotAvailable (c.Location, "static classes");
5304 push_current_container (c, $3);
5305 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5307 opt_primary_parameters_with_class_base
5308 opt_type_parameter_constraints_clauses
5310 valid_param_mod = 0;
5311 lexer.ConstraintsParsing = false;
5314 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5317 current_container.SetConstraints ((List<Constraints>) $9);
5318 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5321 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5322 Lexer.doc_state = XmlCommentState.Allowed;
5325 lexer.parsing_modifiers = true;
5327 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5329 --lexer.parsing_declaration;
5331 Lexer.doc_state = XmlCommentState.Allowed;
5336 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5338 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5340 $$ = pop_current_class ();
5348 { $$ = $1; } // location
5354 mod_locations = null;
5356 lexer.parsing_modifiers = false;
5360 lexer.parsing_modifiers = false;
5366 | modifiers modifier
5368 var m1 = (Modifiers) $1;
5369 var m2 = (Modifiers) $2;
5371 if ((m1 & m2) != 0) {
5372 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5373 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5374 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5375 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5376 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5377 "More than one protection modifier specified");
5388 StoreModifierLocation ($$, GetLocation ($1));
5390 if (current_container.Kind == MemberKind.Namespace)
5391 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5395 $$ = Modifiers.PUBLIC;
5396 StoreModifierLocation ($$, GetLocation ($1));
5400 $$ = Modifiers.PROTECTED;
5401 StoreModifierLocation ($$, GetLocation ($1));
5405 $$ = Modifiers.INTERNAL;
5406 StoreModifierLocation ($$, GetLocation ($1));
5410 $$ = Modifiers.PRIVATE;
5411 StoreModifierLocation ($$, GetLocation ($1));
5415 $$ = Modifiers.ABSTRACT;
5416 StoreModifierLocation ($$, GetLocation ($1));
5420 $$ = Modifiers.SEALED;
5421 StoreModifierLocation ($$, GetLocation ($1));
5425 $$ = Modifiers.STATIC;
5426 StoreModifierLocation ($$, GetLocation ($1));
5430 $$ = Modifiers.READONLY;
5431 StoreModifierLocation ($$, GetLocation ($1));
5435 $$ = Modifiers.VIRTUAL;
5436 StoreModifierLocation ($$, GetLocation ($1));
5440 $$ = Modifiers.OVERRIDE;
5441 StoreModifierLocation ($$, GetLocation ($1));
5445 $$ = Modifiers.EXTERN;
5446 StoreModifierLocation ($$, GetLocation ($1));
5450 $$ = Modifiers.VOLATILE;
5451 StoreModifierLocation ($$, GetLocation ($1));
5455 $$ = Modifiers.UNSAFE;
5456 StoreModifierLocation ($$, GetLocation ($1));
5457 if (!settings.Unsafe)
5458 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5462 $$ = Modifiers.ASYNC;
5463 StoreModifierLocation ($$, GetLocation ($1));
5475 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5477 | COLON type_list error
5479 Error_SyntaxError (yyToken);
5481 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5485 opt_type_parameter_constraints_clauses
5487 | type_parameter_constraints_clauses
5493 type_parameter_constraints_clauses
5494 : type_parameter_constraints_clause
5496 var constraints = new List<Constraints> (1);
5497 constraints.Add ((Constraints) $1);
5500 | type_parameter_constraints_clauses type_parameter_constraints_clause
5502 var constraints = (List<Constraints>) $1;
5503 Constraints new_constraint = (Constraints)$2;
5505 foreach (Constraints c in constraints) {
5506 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5507 report.Error (409, new_constraint.Location,
5508 "A constraint clause has already been specified for type parameter `{0}'",
5509 new_constraint.TypeParameter.Value);
5513 constraints.Add (new_constraint);
5518 type_parameter_constraints_clause
5519 : WHERE IDENTIFIER COLON type_parameter_constraints
5521 var lt = (LocatedToken) $2;
5522 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5523 lbag.AddLocation ($$, GetLocation ($3));
5525 | WHERE IDENTIFIER error
5527 Error_SyntaxError (yyToken);
5529 var lt = (LocatedToken) $2;
5530 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5534 type_parameter_constraints
5535 : type_parameter_constraint
5537 var constraints = new List<FullNamedExpression> (1);
5538 constraints.Add ((FullNamedExpression) $1);
5541 | type_parameter_constraints COMMA type_parameter_constraint
5543 var constraints = (List<FullNamedExpression>) $1;
5544 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5545 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5546 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5549 prev = $3 as SpecialContraintExpr;
5551 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5552 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5554 prev = constraints [0] as SpecialContraintExpr;
5555 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5556 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5561 constraints.Add ((FullNamedExpression) $3);
5566 type_parameter_constraint
5569 if ($1 is ComposedCast)
5570 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5574 | NEW OPEN_PARENS CLOSE_PARENS
5576 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5577 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5581 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5585 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5589 opt_type_parameter_variance
5594 | type_parameter_variance
5596 if (lang_version <= LanguageVersion.V_3)
5597 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5603 type_parameter_variance
5606 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5610 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5619 // A block is "contained" on the following places:
5621 // property_declaration as part of the accessor body (get/set)
5622 // operator_declaration
5623 // constructor_declaration
5624 // destructor_declaration
5625 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5630 ++lexer.parsing_block;
5631 start_block (GetLocation ($1));
5633 opt_statement_list block_end
5642 --lexer.parsing_block;
5643 $$ = end_block (GetLocation ($1));
5645 | COMPLETE_COMPLETION
5647 --lexer.parsing_block;
5648 $$ = end_block (lexer.Location);
5656 ++lexer.parsing_block;
5657 current_block.StartLocation = GetLocation ($1);
5659 opt_statement_list CLOSE_BRACE
5661 --lexer.parsing_block;
5662 $$ = end_block (GetLocation ($4));
5673 | statement_list statement
5677 : block_variable_declaration
5679 current_block.AddStatement ((Statement) $1);
5681 | valid_declaration_statement
5683 current_block.AddStatement ((Statement) $1);
5688 Error_SyntaxError (yyToken);
5694 // The interactive_statement and its derivatives are only
5695 // used to provide a special version of `expression_statement'
5696 // that has a side effect of assigning the expression to
5699 interactive_statement_list
5700 : interactive_statement
5701 | interactive_statement_list interactive_statement
5704 interactive_statement
5705 : block_variable_declaration
5707 current_block.AddStatement ((Statement) $1);
5709 | interactive_valid_declaration_statement
5711 current_block.AddStatement ((Statement) $1);
5716 valid_declaration_statement
5719 | expression_statement
5720 | selection_statement
5721 | iteration_statement
5725 | unchecked_statement
5732 interactive_valid_declaration_statement
5735 | interactive_expression_statement
5736 | selection_statement
5737 | iteration_statement
5741 | unchecked_statement
5749 : valid_declaration_statement
5750 | block_variable_declaration
5752 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5757 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5762 Error_SyntaxError (yyToken);
5763 $$ = new EmptyStatement (GetLocation ($1));
5770 // Uses lexer.Location because semicolon location is not kept in quick mode
5771 $$ = new EmptyStatement (lexer.Location);
5776 : identifier_inside_body COLON
5778 var lt = (LocatedToken) $1;
5779 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5780 lbag.AddLocation (labeled, GetLocation ($2));
5781 current_block.AddLabel (labeled);
5782 current_block.AddStatement (labeled);
5788 : variable_type_simple
5789 | variable_type_simple rank_specifiers
5792 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5794 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5799 * The following is from Rhys' grammar:
5800 * > Types in local variable declarations must be recognized as
5801 * > expressions to prevent reduce/reduce errors in the grammar.
5802 * > The expressions are converted into types during semantic analysis.
5804 variable_type_simple
5805 : type_name_expression opt_nullable
5807 var expr = (ATypeNameExpression) $1;
5809 if (expr.Name == "var" && expr is SimpleName)
5810 $$ = new VarExpr (expr.Location);
5814 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5817 | type_name_expression pointer_stars
5819 var expr = (ATypeNameExpression) $1;
5820 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5822 | builtin_type_expression
5823 | tuple_type opt_nullable
5828 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5834 : OPEN_PARENS tuple_type_elements CLOSE_PARENS
5836 if (lang_version < LanguageVersion.V_7)
5837 FeatureIsNotAvailable (GetLocation ($1), "tuples");
5839 var a = (Tuple<TypeArguments, List<string>>) $2;
5841 $$ = new TupleTypeExpr (a.Item1, a.Item2, GetLocation ($1));
5846 : variable_type IDENTIFIER /* opt_identifier */ COMMA variable_type IDENTIFIER /* opt_identifier */
5848 var type_args = new TypeArguments ();
5850 type_args.Add ((FullNamedExpression) $1);
5851 type_args.Add ((FullNamedExpression) $4);
5853 var names = new List<string> (2);
5854 var lt = (LocatedToken) $2;
5855 names.Add (lt?.Value);
5856 lt = (LocatedToken) $5;
5857 names.Add (lt?.Value);
5859 $$ = Tuple.Create (type_args, names);
5861 | tuple_type_elements COMMA variable_type IDENTIFIER /* opt_identifier */
5863 var a = (Tuple<TypeArguments, List<string>>) $1;
5864 a.Item1.Add ((FullNamedExpression) $3);
5865 var lt = (LocatedToken) $4;
5866 a.Item2.Add (lt?.Value);
5873 | pointer_star pointer_stars
5875 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5883 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5887 identifier_inside_body
5891 $$ = Error_AwaitAsIdentifier ($1);
5895 block_variable_declaration
5896 : variable_type identifier_inside_body
5898 var lt = (LocatedToken) $2;
5899 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5900 current_block.AddLocalName (li);
5901 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5903 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5905 $$ = current_variable;
5906 current_variable = null;
5908 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5910 lbag.AddLocation ($$, GetLocation ($6));
5912 | CONST variable_type identifier_inside_body
5914 var lt = (LocatedToken) $3;
5915 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5916 current_block.AddLocalName (li);
5917 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5919 const_variable_initializer opt_const_declarators SEMICOLON
5921 $$ = current_variable;
5922 current_variable = null;
5923 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5927 opt_local_variable_initializer
5929 | ASSIGN block_variable_initializer
5931 current_variable.Initializer = (Expression) $2;
5932 PushLocation (GetLocation ($1));
5933 $$ = current_variable;
5937 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5938 report.Error (650, lexer.Location,
5939 "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");
5941 Error_SyntaxError (yyToken);
5946 opt_variable_declarators
5948 | variable_declarators
5951 opt_using_or_fixed_variable_declarators
5953 | variable_declarators
5955 foreach (var d in current_variable.Declarators) {
5956 if (d.Initializer == null)
5957 Error_MissingInitializer (d.Variable.Location);
5962 variable_declarators
5963 : variable_declarator
5964 | variable_declarators variable_declarator
5968 : COMMA identifier_inside_body
5970 var lt = (LocatedToken) $2;
5971 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5972 var d = new BlockVariableDeclarator (li, null);
5973 current_variable.AddDeclarator (d);
5974 current_block.AddLocalName (li);
5975 lbag.AddLocation (d, GetLocation ($1));
5977 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5979 var lt = (LocatedToken) $2;
5980 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5981 var d = new BlockVariableDeclarator (li, (Expression) $4);
5982 current_variable.AddDeclarator (d);
5983 current_block.AddLocalName (li);
5984 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5988 const_variable_initializer
5991 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5993 | ASSIGN constant_initializer_expr
5995 current_variable.Initializer = (Expression) $2;
5999 opt_const_declarators
6006 | const_declarators const_declarator
6010 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
6012 var lt = (LocatedToken) $2;
6013 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
6014 var d = new BlockVariableDeclarator (li, (Expression) $4);
6015 current_variable.AddDeclarator (d);
6016 current_block.AddLocalName (li);
6017 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
6021 block_variable_initializer
6022 : variable_initializer
6023 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
6025 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
6026 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6028 | STACKALLOC simple_type
6030 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
6031 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
6035 expression_statement
6036 : statement_expression SEMICOLON
6039 lbag.AddStatement ($$, GetLocation ($2));
6041 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
6042 | statement_expression CLOSE_BRACE
6045 report.Error (1002, GetLocation ($2), "; expected");
6046 lexer.putback ('}');
6050 interactive_expression_statement
6051 : interactive_statement_expression SEMICOLON { $$ = $1; }
6052 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
6056 // We have to do the wrapping here and not in the case above,
6057 // because statement_expression is used for example in for_statement
6059 statement_expression
6062 ExpressionStatement s = $1 as ExpressionStatement;
6064 var expr = $1 as Expression;
6065 $$ = new StatementErrorExpression (expr);
6067 $$ = new StatementExpression (s);
6072 interactive_statement_expression
6075 Expression expr = (Expression) $1;
6076 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
6080 Error_SyntaxError (yyToken);
6081 $$ = new EmptyStatement (GetLocation ($1));
6091 : IF open_parens_any boolean_expression CLOSE_PARENS
6094 if ($5 is EmptyStatement)
6095 Warning_EmptyStatement (GetLocation ($5));
6097 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6098 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6100 | IF open_parens_any boolean_expression CLOSE_PARENS
6101 embedded_statement ELSE embedded_statement
6103 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
6104 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
6106 if ($5 is EmptyStatement)
6107 Warning_EmptyStatement (GetLocation ($5));
6108 if ($7 is EmptyStatement)
6109 Warning_EmptyStatement (GetLocation ($7));
6111 | IF open_parens_any boolean_expression error
6113 Error_SyntaxError (yyToken);
6115 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
6116 lbag.AddStatement ($$, GetLocation ($2));
6121 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
6123 start_block (GetLocation ($5));
6125 opt_switch_sections CLOSE_BRACE
6127 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
6128 end_block (GetLocation ($8));
6129 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6131 | SWITCH open_parens_any expression error
6133 Error_SyntaxError (yyToken);
6135 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
6136 lbag.AddStatement ($$, GetLocation ($2));
6143 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6150 | switch_sections switch_section
6153 Error_SyntaxError (yyToken);
6158 : switch_labels statement_list
6164 var label = (SwitchLabel) $1;
6165 label.SectionStart = true;
6166 current_block.AddStatement (label);
6168 | switch_labels switch_label
6170 current_block.AddStatement ((Statement) $2);
6175 : CASE constant_expression COLON
6177 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6178 lbag.AddLocation ($$, GetLocation ($3));
6180 | CASE constant_expression error
6182 Error_SyntaxError (yyToken);
6183 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6186 | CASE pattern_expr_invocation COLON
6188 if (lang_version != LanguageVersion.Experimental)
6189 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6191 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6192 PatternMatching = true
6194 lbag.AddLocation ($$, GetLocation ($3));
6199 $$ = new SwitchLabel (null, GetLocation ($1));
6211 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6213 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6214 Warning_EmptyStatement (GetLocation ($5));
6216 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6217 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6219 | WHILE open_parens_any boolean_expression error
6221 Error_SyntaxError (yyToken);
6223 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6224 lbag.AddStatement ($$, GetLocation ($2));
6229 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6231 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6232 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6234 | DO embedded_statement error
6236 Error_SyntaxError (yyToken);
6237 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6239 | DO embedded_statement WHILE open_parens_any boolean_expression error
6241 Error_SyntaxError (yyToken);
6243 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6244 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6249 : FOR open_parens_any
6251 start_block (GetLocation ($2));
6252 current_block.IsCompilerGenerated = true;
6253 For f = new For (GetLocation ($1));
6254 current_block.AddStatement (f);
6263 // Has to use be extra rule to recover started block
6265 : opt_for_initializer SEMICOLON
6267 ((For) $0).Initializer = (Statement) $1;
6269 // Pass the "For" object to the iterator_part4
6270 oob_stack.Push ($0);
6272 for_condition_and_iterator_part
6275 var locations = (Tuple<Location,Location>) $4;
6277 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6278 Warning_EmptyStatement (GetLocation ($5));
6281 f.Statement = (Statement) $5;
6282 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6284 $$ = end_block (GetLocation ($2));
6288 Error_SyntaxError (yyToken);
6289 $$ = end_block (current_block.StartLocation);
6293 for_condition_and_iterator_part
6294 : opt_for_condition SEMICOLON
6296 For f = (For) oob_stack.Peek ();
6297 f.Condition = (BooleanExpression) $1;
6300 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6303 // Handle errors in the case of opt_for_condition being followed by
6304 // a close parenthesis
6305 | opt_for_condition close_parens_close_brace {
6306 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6307 For f = (For) oob_stack.Peek ();
6308 f.Condition = (BooleanExpression) $1;
6309 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6314 : opt_for_iterator CLOSE_PARENS {
6315 For f = (For) oob_stack.Peek ();
6316 f.Iterator = (Statement) $1;
6317 $$ = GetLocation ($2);
6319 | opt_for_iterator CLOSE_BRACE {
6320 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6321 For f = (For) oob_stack.Peek ();
6322 f.Iterator = (Statement) $1;
6323 $$ = GetLocation ($2);
6327 close_parens_close_brace
6329 | CLOSE_BRACE { lexer.putback ('}'); }
6333 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6338 : variable_type identifier_inside_body
6340 var lt = (LocatedToken) $2;
6341 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6342 current_block.AddLocalName (li);
6343 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6345 opt_local_variable_initializer opt_variable_declarators
6347 $$ = current_variable;
6349 lbag.AddLocation (current_variable, PopLocation ());
6351 current_variable = null;
6353 | statement_expression_list
6357 : /* empty */ { $$ = null; }
6358 | boolean_expression
6362 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6367 : statement_expression_list
6370 statement_expression_list
6371 : statement_expression
6372 | statement_expression_list COMMA statement_expression
6374 var sl = $1 as StatementList;
6376 sl = new StatementList ((Statement) $1, (Statement) $3);
6377 lbag.AddStatement (sl, GetLocation ($2));
6379 sl.Add ((Statement) $3);
6380 lbag.AppendTo (sl, GetLocation ($2));
6388 : FOREACH open_parens_any type error
6390 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6392 start_block (GetLocation ($2));
6393 current_block.IsCompilerGenerated = true;
6395 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6396 current_block.AddStatement (f);
6398 lbag.AddStatement (f, GetLocation ($2));
6399 $$ = end_block (GetLocation ($4));
6401 | FOREACH open_parens_any type identifier_inside_body error
6403 Error_SyntaxError (yyToken);
6405 start_block (GetLocation ($2));
6406 current_block.IsCompilerGenerated = true;
6408 var lt = (LocatedToken) $4;
6409 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6410 current_block.AddLocalName (li);
6412 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6413 current_block.AddStatement (f);
6415 lbag.AddStatement (f, GetLocation ($2));
6416 $$ = end_block (GetLocation ($5));
6418 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6420 start_block (GetLocation ($2));
6421 current_block.IsCompilerGenerated = true;
6423 var lt = (LocatedToken) $4;
6424 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6425 current_block.AddLocalName (li);
6430 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6431 Warning_EmptyStatement (GetLocation ($9));
6433 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6434 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6435 end_block (GetLocation ($7));
6443 | continue_statement
6453 $$ = new Break (GetLocation ($1));
6454 lbag.AddStatement ($$, GetLocation ($2));
6459 : CONTINUE SEMICOLON
6461 $$ = new Continue (GetLocation ($1));
6462 lbag.AddStatement ($$, GetLocation ($2));
6466 Error_SyntaxError (yyToken);
6467 $$ = new Continue (GetLocation ($1));
6472 : GOTO identifier_inside_body SEMICOLON
6474 var lt = (LocatedToken) $2;
6475 $$ = new Goto (lt.Value, GetLocation ($1));
6476 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6478 | GOTO CASE constant_expression SEMICOLON
6480 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6481 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6483 | GOTO DEFAULT SEMICOLON
6485 $$ = new GotoDefault (GetLocation ($1));
6486 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6491 : RETURN opt_expression SEMICOLON
6493 $$ = new Return ((Expression) $2, GetLocation ($1));
6494 lbag.AddStatement ($$, GetLocation ($3));
6496 | RETURN expression error
6498 Error_SyntaxError (yyToken);
6499 $$ = new Return ((Expression) $2, GetLocation ($1));
6503 Error_SyntaxError (yyToken);
6504 $$ = new Return (null, GetLocation ($1));
6509 : THROW expression SEMICOLON
6511 $$ = new Throw ((Expression) $2, GetLocation ($1));
6512 lbag.AddStatement ($$, GetLocation ($3));
6516 $$ = new Throw (null, GetLocation ($1));
6517 lbag.AddStatement ($$, GetLocation ($2));
6519 | THROW expression error
6521 Error_SyntaxError (yyToken);
6522 $$ = new Throw ((Expression) $2, GetLocation ($1));
6526 Error_SyntaxError (yyToken);
6527 $$ = new Throw (null, GetLocation ($1));
6532 : identifier_inside_body RETURN opt_expression SEMICOLON
6534 var lt = (LocatedToken) $1;
6535 string s = lt.Value;
6537 report.Error (1003, lt.Location, "; expected");
6538 } else if ($3 == null) {
6539 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6540 } else if (lang_version == LanguageVersion.ISO_1){
6541 FeatureIsNotAvailable (lt.Location, "iterators");
6544 current_block.Explicit.RegisterIteratorYield ();
6545 $$ = new Yield ((Expression) $3, lt.Location);
6546 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6548 | identifier_inside_body RETURN expression error
6550 Error_SyntaxError (yyToken);
6552 var lt = (LocatedToken) $1;
6553 string s = lt.Value;
6555 report.Error (1003, lt.Location, "; expected");
6556 } else if ($3 == null) {
6557 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6558 } else if (lang_version == LanguageVersion.ISO_1){
6559 FeatureIsNotAvailable (lt.Location, "iterators");
6562 current_block.Explicit.RegisterIteratorYield ();
6563 $$ = new Yield ((Expression) $3, lt.Location);
6564 lbag.AddStatement ($$, GetLocation ($2));
6566 | identifier_inside_body BREAK SEMICOLON
6568 var lt = (LocatedToken) $1;
6569 string s = lt.Value;
6571 report.Error (1003, lt.Location, "; expected");
6572 } else if (lang_version == LanguageVersion.ISO_1){
6573 FeatureIsNotAvailable (lt.Location, "iterators");
6576 current_block.ParametersBlock.TopBlock.IsIterator = true;
6577 $$ = new YieldBreak (lt.Location);
6578 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6588 : TRY block catch_clauses
6590 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6592 | TRY block FINALLY block
6594 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6595 lbag.AddStatement ($$, GetLocation ($3));
6597 | TRY block catch_clauses FINALLY block
6599 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6600 lbag.AddStatement ($$, GetLocation ($4));
6604 Error_SyntaxError (1524, yyToken);
6605 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6612 var l = new List<Catch> (2);
6617 | catch_clauses catch_clause
6619 var l = (List<Catch>) $1;
6621 Catch c = (Catch) $2;
6622 var prev_catch = l [l.Count - 1];
6623 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6624 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6634 | identifier_inside_body
6638 : CATCH opt_catch_filter block
6640 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6641 c.Filter = (CatchFilterExpression) $2;
6644 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6646 start_block (GetLocation ($2));
6647 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6648 c.TypeExpression = (FullNamedExpression) $3;
6651 var lt = (LocatedToken) $4;
6652 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6653 current_block.AddLocalName (c.Variable);
6656 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6658 lexer.parsing_catch_when = true;
6660 opt_catch_filter_or_error
6662 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6665 | CATCH open_parens_any error
6667 if (yyToken == Token.CLOSE_PARENS) {
6668 report.Error (1015, lexer.Location,
6669 "A type that derives from `System.Exception', `object', or `string' expected");
6671 Error_SyntaxError (yyToken);
6674 $$ = new Catch (null, GetLocation ($1));
6678 opt_catch_filter_or_error
6679 : opt_catch_filter block_prepared
6685 end_block (Location.Null);
6686 Error_SyntaxError (yyToken);
6693 lexer.parsing_catch_when = false;
6697 lexer.parsing_catch_when = false;
6699 open_parens_any expression CLOSE_PARENS
6701 if (lang_version <= LanguageVersion.V_5)
6702 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6704 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6705 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6712 $$ = new Checked ((Block) $2, GetLocation ($1));
6719 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6726 if (!settings.Unsafe)
6727 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6729 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6734 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6736 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6737 Warning_EmptyStatement (GetLocation ($5));
6739 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6740 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6742 | LOCK open_parens_any expression error
6744 Error_SyntaxError (yyToken);
6746 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6747 lbag.AddStatement ($$, GetLocation ($2));
6752 : FIXED open_parens_any variable_type identifier_inside_body
6754 start_block (GetLocation ($2));
6756 current_block.IsCompilerGenerated = true;
6757 var lt = (LocatedToken) $4;
6758 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6759 current_block.AddLocalName (li);
6760 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6762 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6764 $$ = current_variable;
6765 current_variable = null;
6769 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6770 Warning_EmptyStatement (GetLocation ($10));
6772 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6773 current_block.AddStatement (f);
6774 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6775 $$ = end_block (GetLocation ($8));
6780 : USING open_parens_any variable_type identifier_inside_body
6782 start_block (GetLocation ($2));
6784 current_block.IsCompilerGenerated = true;
6785 var lt = (LocatedToken) $4;
6786 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6787 current_block.AddLocalName (li);
6788 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6790 using_initialization CLOSE_PARENS
6792 $$ = current_variable;
6793 current_variable = null;
6797 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6798 Warning_EmptyStatement (GetLocation ($9));
6800 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6801 current_block.AddStatement (u);
6802 $$ = end_block (GetLocation ($7));
6804 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6806 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6807 Warning_EmptyStatement (GetLocation ($5));
6809 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6810 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6812 | USING open_parens_any expression error
6814 Error_SyntaxError (yyToken);
6816 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6817 lbag.AddStatement ($$, GetLocation ($2));
6821 using_initialization
6822 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6825 // It has to be here for the parent to safely restore artificial block
6826 Error_SyntaxError (yyToken);
6830 using_or_fixed_variable_initializer
6833 Error_MissingInitializer (lexer.Location);
6835 | ASSIGN variable_initializer
6837 current_variable.Initializer = (Expression) $2;
6838 $$ = current_variable;
6846 : first_from_clause query_body
6848 lexer.query_parsing = false;
6850 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6852 from.Tail.Next = (Linq.AQueryClause)$2;
6855 current_block.SetEndLocation (lexer.Location);
6856 current_block = current_block.Parent;
6858 | nested_from_clause query_body
6860 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6862 from.Tail.Next = (Linq.AQueryClause)$2;
6865 current_block.SetEndLocation (lexer.Location);
6866 current_block = current_block.Parent;
6869 // Bubble up COMPLETE_COMPLETION productions
6870 | first_from_clause COMPLETE_COMPLETION {
6871 lexer.query_parsing = false;
6874 current_block.SetEndLocation (lexer.Location);
6875 current_block = current_block.Parent;
6877 | nested_from_clause COMPLETE_COMPLETION {
6879 current_block.SetEndLocation (lexer.Location);
6880 current_block = current_block.Parent;
6885 : FROM_FIRST identifier_inside_body IN expression
6887 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6889 var lt = (LocatedToken) $2;
6890 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6891 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6892 lbag.AddLocation (clause, GetLocation ($3));
6893 $$ = new Linq.QueryExpression (clause);
6895 | FROM_FIRST type identifier_inside_body IN expression
6897 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6899 var lt = (LocatedToken) $3;
6900 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6901 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6902 IdentifierType = (FullNamedExpression)$2
6904 lbag.AddLocation (clause, GetLocation ($4));
6905 $$ = new Linq.QueryExpression (clause);
6910 : FROM identifier_inside_body IN expression
6912 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6914 var lt = (LocatedToken) $2;
6915 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6916 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6917 lbag.AddLocation (clause, GetLocation ($3));
6918 $$ = new Linq.QueryExpression (clause);
6920 | FROM type identifier_inside_body IN expression
6922 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6924 var lt = (LocatedToken) $3;
6925 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6926 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6927 IdentifierType = (FullNamedExpression)$2
6929 lbag.AddLocation (clause, GetLocation ($4));
6930 $$ = new Linq.QueryExpression (clause);
6935 : FROM identifier_inside_body IN
6937 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6941 var lt = (LocatedToken) $2;
6942 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6943 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6945 current_block.SetEndLocation (lexer.Location);
6946 current_block = current_block.Parent;
6948 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6949 lbag.AddLocation ($$, GetLocation ($3));
6951 | FROM type identifier_inside_body IN
6953 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6957 var lt = (LocatedToken) $3;
6958 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6960 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6961 IdentifierType = (FullNamedExpression)$2
6964 current_block.SetEndLocation (lexer.Location);
6965 current_block = current_block.Parent;
6967 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6969 lbag.AddLocation ($$, GetLocation ($4));
6974 : query_body_clauses select_or_group_clause opt_query_continuation
6976 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6979 head.Next = (Linq.AQueryClause)$3;
6982 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6983 clause.Tail.Next = head;
6989 | select_or_group_clause opt_query_continuation
6991 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6994 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6995 clause.Tail.Next = head;
7001 | query_body_clauses COMPLETE_COMPLETION
7002 | query_body_clauses error
7004 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
7009 Error_SyntaxError (yyToken);
7014 select_or_group_clause
7017 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7021 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7023 current_block.SetEndLocation (lexer.Location);
7024 current_block = current_block.Parent;
7028 if (linq_clause_blocks == null)
7029 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7031 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7032 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
7036 current_block.SetEndLocation (lexer.Location);
7037 current_block = current_block.Parent;
7039 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7043 var obj = (object[]) $5;
7045 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
7046 lbag.AddLocation ($$, (Location) obj[1]);
7048 current_block.SetEndLocation (lexer.Location);
7049 current_block = current_block.Parent;
7054 : BY expression_or_error
7056 $$ = new object[] { $2, GetLocation ($1) };
7060 Error_SyntaxError (yyToken);
7061 $$ = new object[2] { null, Location.Null };
7067 | query_body_clauses query_body_clause
7069 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
7083 : LET identifier_inside_body ASSIGN
7085 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7089 var lt = (LocatedToken) $2;
7090 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7091 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
7092 lbag.AddLocation ($$, GetLocation ($3));
7094 current_block.SetEndLocation (lexer.Location);
7095 current_block = current_block.Parent;
7097 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7104 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7108 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
7110 current_block.SetEndLocation (lexer.Location);
7111 current_block = current_block.Parent;
7116 : JOIN identifier_inside_body IN
7118 if (linq_clause_blocks == null)
7119 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7121 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7122 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7124 expression_or_error ON
7126 current_block.SetEndLocation (lexer.Location);
7127 current_block = current_block.Parent;
7129 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7130 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7132 expression_or_error EQUALS
7134 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7135 current_block.SetEndLocation (lexer.Location);
7136 current_block = current_block.Parent;
7138 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7140 expression_or_error opt_join_into
7142 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7143 current_block.SetEndLocation (lexer.Location);
7145 var outer_selector = linq_clause_blocks.Pop ();
7146 var block = linq_clause_blocks.Pop ();
7148 var lt = (LocatedToken) $2;
7149 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7150 Linq.RangeVariable into;
7154 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7155 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7158 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7160 var parent = block.Parent;
7161 while (parent is Linq.QueryBlock) {
7162 parent = parent.Parent;
7164 current_block.Parent = parent;
7166 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7168 lt = (LocatedToken) $12;
7169 into = new Linq.RangeVariable (lt.Value, lt.Location);
7171 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7172 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7175 current_block = block.Parent;
7176 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7178 | JOIN type identifier_inside_body IN
7180 if (linq_clause_blocks == null)
7181 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7183 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7184 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7186 expression_or_error ON
7188 current_block.SetEndLocation (lexer.Location);
7189 current_block = current_block.Parent;
7191 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7192 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7194 expression_or_error EQUALS
7196 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7197 current_block.SetEndLocation (lexer.Location);
7198 current_block = current_block.Parent;
7200 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7202 expression_or_error opt_join_into
7204 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7205 current_block.SetEndLocation (lexer.Location);
7207 var outer_selector = linq_clause_blocks.Pop ();
7208 var block = linq_clause_blocks.Pop ();
7210 var lt = (LocatedToken) $3;
7211 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7212 Linq.RangeVariable into;
7216 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7217 IdentifierType = (FullNamedExpression)$2
7219 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7222 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7224 var parent = block.Parent;
7225 while (parent is Linq.QueryBlock) {
7226 parent = parent.Parent;
7228 current_block.Parent = parent;
7230 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7232 lt = (LocatedToken) $13;
7233 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7235 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7236 IdentifierType = (FullNamedExpression)$2
7240 current_block = block.Parent;
7241 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7247 | INTO identifier_inside_body
7256 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7260 current_block.SetEndLocation (lexer.Location);
7261 current_block = current_block.Parent;
7271 current_block.SetEndLocation (lexer.Location);
7272 current_block = current_block.Parent;
7274 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7278 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7285 | orderings_then_by COMMA
7287 current_block.SetEndLocation (lexer.Location);
7288 current_block = current_block.Parent;
7290 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7294 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7302 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7304 | expression ASCENDING
7306 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7307 lbag.AddLocation ($$, GetLocation ($2));
7309 | expression DESCENDING
7311 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7312 lbag.AddLocation ($$, GetLocation ($2));
7319 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7321 | expression ASCENDING
7323 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7324 lbag.AddLocation ($$, GetLocation ($2));
7326 | expression DESCENDING
7328 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7329 lbag.AddLocation ($$, GetLocation ($2));
7334 opt_query_continuation
7336 | INTO identifier_inside_body
7338 // query continuation block is not linked with query block but with block
7339 // before. This means each query can use same range variable names for
7340 // different identifiers.
7342 current_block.SetEndLocation (GetLocation ($1));
7343 current_block = current_block.Parent;
7345 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7347 if (linq_clause_blocks == null)
7348 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7350 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7354 var current_block = linq_clause_blocks.Pop ();
7355 var lt = (LocatedToken) $2;
7356 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7357 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7358 next = (Linq.AQueryClause)$4
7364 // Support for using the compiler as an interactive parser
7366 // The INTERACTIVE_PARSER token is first sent to parse our
7367 // productions; If the result is a Statement, the parsing
7368 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7369 // to setup the blocks in advance.
7371 // This setup is here so that in the future we can add
7372 // support for other constructs (type parsing, namespaces, etc)
7373 // that do not require a block to be setup in advance
7377 : EVAL_STATEMENT_PARSER EOF
7378 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7379 | EVAL_STATEMENT_PARSER
7381 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7383 // (ref object retval)
7384 Parameter [] mpar = new Parameter [1];
7385 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7387 ParametersCompiled pars = new ParametersCompiled (mpar);
7388 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7389 if (settings.Unsafe)
7390 mods |= Modifiers.UNSAFE;
7392 current_local_parameters = pars;
7393 var method = new InteractiveMethod (
7395 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7399 current_type.AddMember (method);
7400 oob_stack.Push (method);
7402 interactive_async = false;
7404 ++lexer.parsing_block;
7405 start_block (lexer.Location);
7407 interactive_statement_list opt_COMPLETE_COMPLETION
7409 --lexer.parsing_block;
7410 var method = (InteractiveMethod) oob_stack.Pop ();
7411 method.Block = (ToplevelBlock) end_block(lexer.Location);
7413 if (interactive_async == true) {
7414 method.ChangeToAsync ();
7417 InteractiveResult = (Class) pop_current_class ();
7418 current_local_parameters = null;
7420 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7423 interactive_compilation_unit
7424 : opt_extern_alias_directives opt_using_directives
7425 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7428 opt_COMPLETE_COMPLETION
7430 | COMPLETE_COMPLETION
7433 close_brace_or_complete_completion
7435 | COMPLETE_COMPLETION
7439 // XML documentation code references micro parser
7441 documentation_parsing
7444 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7449 : doc_type_declaration_name opt_doc_method_sig
7451 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7453 | builtin_types opt_doc_method_sig
7455 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7456 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7459 | VOID opt_doc_method_sig
7461 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7462 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7465 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7467 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7468 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7469 var lt = (LocatedToken) $3;
7470 $$ = new MemberName (lt.Value);
7472 | doc_type_declaration_name DOT THIS
7474 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7476 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7478 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7480 opt_doc_parameters CLOSE_BRACKET
7482 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7483 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7485 | EXPLICIT OPERATOR type opt_doc_method_sig
7487 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7488 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7489 module.DocumentationBuilder.ParsedParameters = p;
7490 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7493 | IMPLICIT OPERATOR type opt_doc_method_sig
7495 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7496 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7497 module.DocumentationBuilder.ParsedParameters = p;
7498 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7501 | OPERATOR overloadable_operator opt_doc_method_sig
7503 var p = (List<DocumentationParameter>)$3;
7504 module.DocumentationBuilder.ParsedParameters = p;
7505 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7510 doc_type_declaration_name
7511 : type_declaration_name
7512 | doc_type_declaration_name DOT type_declaration_name
7514 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7522 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7524 opt_doc_parameters CLOSE_PARENS
7533 $$ = new List<DocumentationParameter> (0);
7541 var parameters = new List<DocumentationParameter> ();
7542 parameters.Add ((DocumentationParameter) $1);
7545 | doc_parameters COMMA doc_parameter
7547 var parameters = $1 as List<DocumentationParameter>;
7548 parameters.Add ((DocumentationParameter) $3);
7554 : opt_parameter_modifier parameter_type
7557 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7559 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7566 // A class used to hold info about an operator declarator
7568 class OperatorDeclaration {
7569 public readonly Operator.OpType optype;
7570 public readonly FullNamedExpression ret_type;
7571 public readonly Location location;
7573 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7576 this.ret_type = ret_type;
7577 this.location = location;
7581 void Error_ExpectingTypeName (Expression expr)
7583 if (expr is Invocation){
7584 report.Error (1002, expr.Location, "Expecting `;'");
7586 expr.Error_InvalidExpressionStatement (report);
7590 void Error_ParameterModifierNotValid (string modifier, Location loc)
7592 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7596 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7598 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7599 Parameter.GetModifierSignature (mod));
7602 void Error_TypeExpected (Location loc)
7604 report.Error (1031, loc, "Type expected");
7607 void Error_UnsafeCodeNotAllowed (Location loc)
7609 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7612 void Warning_EmptyStatement (Location loc)
7614 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7617 void Error_NamedArgumentExpected (NamedArgument a)
7619 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7622 void Error_MissingInitializer (Location loc)
7624 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7627 object Error_AwaitAsIdentifier (object token)
7630 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7631 return new LocatedToken ("await", GetLocation (token));
7637 void push_current_container (TypeDefinition tc, object partial_token)
7639 if (module.Evaluator != null){
7640 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7644 undo.AddTypeContainer (current_container, tc);
7647 if (partial_token != null)
7648 current_container.AddPartial (tc);
7650 current_container.AddTypeContainer (tc);
7652 ++lexer.parsing_declaration;
7653 current_container = tc;
7657 TypeContainer pop_current_class ()
7659 var retval = current_container;
7661 current_container = current_container.Parent;
7662 current_type = current_type.Parent as TypeDefinition;
7667 [System.Diagnostics.Conditional ("FULL_AST")]
7668 void StoreModifierLocation (object token, Location loc)
7673 if (mod_locations == null)
7674 mod_locations = new List<Tuple<Modifiers, Location>> ();
7676 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7679 [System.Diagnostics.Conditional ("FULL_AST")]
7680 void PushLocation (Location loc)
7682 if (location_stack == null)
7683 location_stack = new Stack<Location> ();
7685 location_stack.Push (loc);
7688 Location PopLocation ()
7690 if (location_stack == null)
7691 return Location.Null;
7693 return location_stack.Pop ();
7696 string CheckAttributeTarget (int token, string a, Location l)
7699 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7703 if (!Tokenizer.IsValidIdentifier (a)) {
7704 Error_SyntaxError (token);
7706 report.Warning (658, 1, l,
7707 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7710 return string.Empty;
7713 static bool IsUnaryOperator (Operator.OpType op)
7717 case Operator.OpType.LogicalNot:
7718 case Operator.OpType.OnesComplement:
7719 case Operator.OpType.Increment:
7720 case Operator.OpType.Decrement:
7721 case Operator.OpType.True:
7722 case Operator.OpType.False:
7723 case Operator.OpType.UnaryPlus:
7724 case Operator.OpType.UnaryNegation:
7730 void syntax_error (Location l, string msg)
7732 report.Error (1003, l, "Syntax error, " + msg);
7737 public Tokenizer Lexer {
7743 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7744 : this (reader, file, file.Compiler.Report, session)
7748 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7751 current_container = current_namespace = file;
7753 this.module = file.Module;
7754 this.compiler = file.Compiler;
7755 this.settings = compiler.Settings;
7756 this.report = report;
7758 lang_version = settings.Version;
7759 yacc_verbose_flag = settings.VerboseParserFlag;
7760 doc_support = settings.DocumentationFile != null;
7761 lexer = new Tokenizer (reader, file, session, report);
7762 oob_stack = new Stack<object> ();
7763 lbag = session.LocationsBag;
7764 use_global_stacks = session.UseJayGlobalArrays;
7765 parameters_bucket = session.ParametersStack;
7768 public void parse ()
7770 eof_token = Token.EOF;
7773 if (yacc_verbose_flag > 1)
7774 yyparse (lexer, new yydebug.yyDebugSimple ());
7778 Tokenizer tokenizer = lexer as Tokenizer;
7779 tokenizer.cleanup ();
7780 } catch (Exception e){
7781 if (e is yyParser.yyUnexpectedEof) {
7782 Error_SyntaxError (yyToken);
7783 UnexpectedEOF = true;
7787 if (e is yyParser.yyException) {
7788 if (report.Errors == 0)
7789 report.Error (-25, lexer.Location, "Parsing error");
7791 // Used by compiler-tester to test internal errors
7792 if (yacc_verbose_flag > 0 || e is FatalException)
7795 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7800 void CheckToken (int error, int yyToken, string msg, Location loc)
7802 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7803 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7805 report.Error (error, loc, msg);
7808 string ConsumeStoredComment ()
7810 string s = tmpComment;
7812 Lexer.doc_state = XmlCommentState.Allowed;
7816 void FeatureIsNotAvailable (Location loc, string feature)
7818 report.FeatureIsNotAvailable (compiler, loc, feature);
7821 Location GetLocation (object obj)
7823 var lt = obj as LocatedToken;
7827 var mn = obj as MemberName;
7831 var expr = obj as Expression;
7833 return expr.Location;
7835 return lexer.Location;
7838 void start_block (Location loc)
7840 if (current_block == null) {
7841 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7842 parsing_anonymous_method = false;
7843 } else if (parsing_anonymous_method) {
7844 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7845 parsing_anonymous_method = false;
7847 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7851 Block end_block (Location loc)
7853 Block retval = current_block.Explicit;
7854 retval.SetEndLocation (loc);
7855 current_block = retval.Parent;
7859 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7861 oob_stack.Push (current_anonymous_method);
7862 oob_stack.Push (current_local_parameters);
7863 oob_stack.Push (current_variable);
7864 oob_stack.Push (async_block);
7866 current_local_parameters = parameters;
7868 if (lang_version <= LanguageVersion.ISO_2)
7869 FeatureIsNotAvailable (loc, "lambda expressions");
7871 current_anonymous_method = new LambdaExpression (loc);
7873 if (lang_version == LanguageVersion.ISO_1)
7874 FeatureIsNotAvailable (loc, "anonymous methods");
7876 current_anonymous_method = new AnonymousMethodExpression (loc);
7879 async_block = isAsync;
7880 // Force the next block to be created as a ToplevelBlock
7881 parsing_anonymous_method = true;
7885 * Completes the anonymous method processing, if lambda_expr is null, this
7886 * means that we have a Statement instead of an Expression embedded
7888 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7890 AnonymousMethodExpression retval;
7893 anon_block.IsAsync = true;
7895 current_anonymous_method.Block = anon_block;
7896 retval = current_anonymous_method;
7898 async_block = (bool) oob_stack.Pop ();
7899 current_variable = (BlockVariable) oob_stack.Pop ();
7900 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7901 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7906 void Error_SyntaxError (int token)
7908 Error_SyntaxError (0, token);
7911 void Error_SyntaxError (int error_code, int token)
7913 Error_SyntaxError (error_code, token, "Unexpected symbol");
7916 void Error_SyntaxError (int error_code, int token, string msg)
7918 Lexer.CompleteOnEOF = false;
7920 // An error message has been reported by tokenizer
7921 if (token == Token.ERROR)
7924 // Avoid duplicit error message after unterminated string literals
7925 if (token == Token.LITERAL && lexer.Location.Column == 0)
7928 string symbol = GetSymbolName (token);
7929 string expecting = GetExpecting ();
7930 var loc = lexer.Location - symbol.Length;
7932 if (error_code == 0) {
7933 if (expecting == "`identifier'") {
7934 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7935 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7940 expecting = "identifier";
7941 } else if (expecting == "`)'") {
7948 if (string.IsNullOrEmpty (expecting))
7949 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7951 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7954 string GetExpecting ()
7956 int [] tokens = yyExpectingTokens (yyExpectingState);
7957 var names = new List<string> (tokens.Length);
7958 bool has_type = false;
7959 bool has_identifier = false;
7960 for (int i = 0; i < tokens.Length; i++){
7961 int token = tokens [i];
7962 has_identifier |= token == Token.IDENTIFIER;
7964 string name = GetTokenName (token);
7965 if (name == "<internal>")
7968 has_type |= name == "type";
7969 if (names.Contains (name))
7976 // Too many tokens to enumerate
7978 if (names.Count > 8)
7981 if (has_type && has_identifier)
7982 names.Remove ("identifier");
7984 if (names.Count == 1)
7985 return "`" + GetTokenName (tokens [0]) + "'";
7987 StringBuilder sb = new StringBuilder ();
7989 int count = names.Count;
7990 for (int i = 0; i < count; i++){
7991 bool last = i + 1 == count;
7995 sb.Append (names [i]);
7996 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7998 return sb.ToString ();
8002 string GetSymbolName (int token)
8006 return ((Constant)lexer.Value).GetValue ().ToString ();
8007 case Token.IDENTIFIER:
8008 return ((LocatedToken)lexer.Value).Value;
8050 case Token.BITWISE_AND:
8052 case Token.BITWISE_OR:
8066 case Token.OP_SHIFT_LEFT:
8068 case Token.OP_SHIFT_RIGHT:
8088 case Token.OP_COALESCING:
8090 case Token.OP_MULT_ASSIGN:
8092 case Token.OP_DIV_ASSIGN:
8094 case Token.OP_MOD_ASSIGN:
8096 case Token.OP_ADD_ASSIGN:
8098 case Token.OP_SUB_ASSIGN:
8100 case Token.OP_SHIFT_LEFT_ASSIGN:
8102 case Token.OP_SHIFT_RIGHT_ASSIGN:
8104 case Token.OP_AND_ASSIGN:
8106 case Token.OP_XOR_ASSIGN:
8108 case Token.OP_OR_ASSIGN:
8112 return GetTokenName (token);
8115 static string GetTokenName (int token)
8118 case Token.ABSTRACT:
8140 case Token.CONTINUE:
8144 case Token.DELEGATE:
8154 case Token.EXPLICIT:
8157 case Token.EXTERN_ALIAS:
8173 case Token.IMPLICIT:
8177 case Token.INTERFACE:
8179 case Token.INTERNAL:
8185 case Token.NAMESPACE:
8191 case Token.OPERATOR:
8195 case Token.OVERRIDE:
8201 case Token.PROTECTED:
8205 case Token.READONLY:
8217 case Token.STACKALLOC:
8218 return "stackalloc";
8228 case Token.THROW_EXPR:
8236 case Token.UNCHECKED:
8244 case Token.VOLATILE:
8252 case Token.REFVALUE:
8253 return "__refvalue";
8263 case Token.FROM_FIRST:
8281 case Token.ASCENDING:
8283 case Token.DESCENDING:
8284 return "descending";
8291 case Token.OPEN_BRACE:
8293 case Token.CLOSE_BRACE:
8295 case Token.OPEN_BRACKET:
8296 case Token.OPEN_BRACKET_EXPR:
8298 case Token.CLOSE_BRACKET:
8300 case Token.OPEN_PARENS_CAST:
8301 case Token.OPEN_PARENS_LAMBDA:
8302 case Token.OPEN_PARENS_DECONSTRUCT:
8303 case Token.OPEN_PARENS:
8305 case Token.CLOSE_PARENS:
8311 case Token.DEFAULT_COLON:
8315 case Token.SEMICOLON:
8321 case Token.INTERPOLATED_STRING_END:
8323 case Token.INTERPOLATED_STRING:
8332 case Token.BITWISE_AND:
8333 case Token.BITWISE_OR:
8340 case Token.OP_SHIFT_LEFT:
8341 case Token.OP_SHIFT_RIGHT:
8349 case Token.OP_COALESCING:
8350 case Token.OP_MULT_ASSIGN:
8351 case Token.OP_DIV_ASSIGN:
8352 case Token.OP_MOD_ASSIGN:
8353 case Token.OP_ADD_ASSIGN:
8354 case Token.OP_SUB_ASSIGN:
8355 case Token.OP_SHIFT_LEFT_ASSIGN:
8356 case Token.OP_SHIFT_RIGHT_ASSIGN:
8357 case Token.OP_AND_ASSIGN:
8358 case Token.OP_XOR_ASSIGN:
8359 case Token.OP_OR_ASSIGN:
8360 case Token.INTERR_OPERATOR:
8361 return "<operator>";
8383 case Token.OP_GENERICS_LT:
8384 case Token.GENERIC_DIMENSION:
8386 case Token.OP_GENERICS_GT:
8389 case Token.INTERR_NULLABLE:
8391 case Token.DOUBLE_COLON:
8395 case Token.IDENTIFIER:
8397 return "identifier";
8400 return "end-of-file";
8402 // All of these are internal.
8405 case Token.FIRST_KEYWORD:
8406 case Token.EVAL_COMPILATION_UNIT_PARSER:
8407 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8408 case Token.EVAL_STATEMENT_PARSER:
8409 case Token.LAST_KEYWORD:
8410 case Token.GENERATE_COMPLETION:
8411 case Token.COMPLETE_COMPLETION:
8412 return "<internal>";
8414 // A bit more robust.
8416 return yyNames [token];