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
339 // Make the parser go into eval mode parsing (statements and compilation units).
340 %token EVAL_STATEMENT_PARSER
341 %token EVAL_COMPILATION_UNIT_PARSER
342 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
347 // This token is generated to trigger the completion engine at this point
349 %token GENERATE_COMPLETION
352 // This token is return repeatedly after the first GENERATE_COMPLETION
353 // token is produced and before the final EOF
355 %token COMPLETE_COMPLETION
357 /* Add precedence rules to solve dangling else s/r conflict */
361 /* Define the operator tokens and their precedences */
369 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
371 %left STAR DIV PERCENT
372 %right BANG CARRET UMINUS
373 %nonassoc OP_INC OP_DEC
375 %left OPEN_BRACKET OPEN_BRACE
378 %start compilation_unit
382 : outer_declaration opt_EOF
384 Lexer.check_incorrect_doc_comment ();
386 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
387 | documentation_parsing
391 : opt_extern_alias_directives opt_using_directives
392 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
395 Attributes attrs = (Attributes) $4;
396 report.Error (1730, attrs.Attrs [0].Location,
397 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
399 current_namespace.UnattachedAttributes = attrs;
402 | opt_extern_alias_directives opt_using_directives attribute_sections
404 Attributes attrs = (Attributes) $3;
406 foreach (var a in attrs.Attrs) {
407 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
410 if (a.ExplicitTarget == null)
411 report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
415 module.AddAttributes ((Attributes) $3, current_namespace);
419 if (yyToken == Token.EXTERN_ALIAS)
420 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
422 Error_SyntaxError (yyToken);
431 extern_alias_directives
432 : extern_alias_directive
433 | extern_alias_directives extern_alias_directive
436 extern_alias_directive
437 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
439 var lt = (LocatedToken) $2;
442 syntax_error (lt.Location, "`alias' expected");
444 if (lang_version == LanguageVersion.ISO_1)
445 FeatureIsNotAvailable (lt.Location, "external alias");
447 lt = (LocatedToken) $3;
448 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
449 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
452 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
453 current_namespace.AddUsing (na);
455 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
460 Error_SyntaxError (yyToken);
466 | using_directives using_directive
473 Lexer.doc_state = XmlCommentState.Allowed;
478 : USING opt_static namespace_or_type_expr SEMICOLON
482 if (lang_version <= LanguageVersion.V_5)
483 FeatureIsNotAvailable (GetLocation ($2), "using static");
485 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
486 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
488 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
489 lbag.AddLocation (uc, GetLocation ($4));
492 current_namespace.AddUsing (uc);
494 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
496 var lt = (LocatedToken) $3;
497 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
498 report.Warning (440, 2, lt.Location,
499 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
503 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
506 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
507 current_namespace.AddUsing (un);
509 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
513 Error_SyntaxError (yyToken);
524 // Strictly speaking, namespaces don't have attributes but
525 // we parse global attributes along with namespace declarations and then
528 namespace_declaration
529 : opt_attributes NAMESPACE namespace_name
531 Attributes attrs = (Attributes) $1;
532 var name = (MemberName) $3;
534 bool valid_global_attrs = true;
535 if ((current_namespace.DeclarationFound || current_namespace != file)) {
536 valid_global_attrs = false;
538 foreach (var a in attrs.Attrs) {
539 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
542 valid_global_attrs = false;
547 if (!valid_global_attrs)
548 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
551 module.AddAttributes (attrs, current_namespace);
553 var ns = new NamespaceContainer (name, current_namespace);
554 current_namespace.AddTypeContainer (ns);
555 current_container = current_namespace = ns;
560 Lexer.doc_state = XmlCommentState.Allowed;
562 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
565 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
567 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
569 current_container = current_namespace = current_namespace.Parent;
571 | opt_attributes NAMESPACE namespace_name
573 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
575 var name = (MemberName) $3;
576 var ns = new NamespaceContainer (name, current_namespace);
577 lbag.AddLocation (ns, GetLocation ($2));
578 current_namespace.AddTypeContainer (ns);
587 Error_SyntaxError (yyToken);
595 var lt = (LocatedToken) $1;
596 $$ = new MemberName (lt.Value, lt.Location);
598 | namespace_name DOT IDENTIFIER
600 var lt = (LocatedToken) $3;
601 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
602 lbag.AddLocation ($$, GetLocation ($2));
606 Error_SyntaxError (yyToken);
607 $$ = new MemberName ("<invalid>", lexer.Location);
626 opt_extern_alias_directives
628 | extern_alias_directives
631 opt_namespace_or_type_declarations
633 | namespace_or_type_declarations
636 namespace_or_type_declarations
637 : namespace_or_type_declaration
638 | namespace_or_type_declarations namespace_or_type_declaration
641 namespace_or_type_declaration
645 TypeContainer ds = (TypeContainer)$1;
647 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
648 report.Error (1527, ds.Location,
649 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
652 // Here is a trick, for explicit attributes we don't know where they belong to until
653 // we parse succeeding declaration hence we parse them as normal and re-attach them
654 // when we know whether they are global (assembly:, module:) or local (type:).
655 if (ds.OptAttributes != null) {
656 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
659 current_namespace.DeclarationFound = true;
661 | namespace_declaration
663 current_namespace.DeclarationFound = true;
665 | attribute_sections CLOSE_BRACE {
666 current_namespace.UnattachedAttributes = (Attributes) $1;
667 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
675 | interface_declaration
677 | delegate_declaration
679 // Enable this when we have handled all errors, because this acts as a generic fallback
682 // Console.WriteLine ("Token=" + yyToken);
683 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
699 var sect = (List<Attribute>) $1;
700 $$ = new Attributes (sect);
702 | attribute_sections attribute_section
704 Attributes attrs = $1 as Attributes;
705 var sect = (List<Attribute>) $2;
707 attrs = new Attributes (sect);
708 else if (sect != null)
709 attrs.AddAttributes (sect);
717 PushLocation (GetLocation ($1));
718 lexer.parsing_attribute_section = true;
720 attribute_section_cont
722 lexer.parsing_attribute_section = false;
727 attribute_section_cont
728 : attribute_target COLON
730 current_attr_target = (string) $1;
731 if (current_attr_target == "assembly" || current_attr_target == "module") {
732 Lexer.check_incorrect_doc_comment ();
735 attribute_list opt_comma CLOSE_BRACKET
737 // when attribute target is invalid
738 if (current_attr_target == string.Empty)
739 $$ = new List<Attribute> (0);
743 lbag.InsertLocation ($$, 0, PopLocation ());
745 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
747 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
750 current_attr_target = null;
751 lexer.parsing_attribute_section = false;
753 | attribute_list opt_comma CLOSE_BRACKET
757 lbag.InsertLocation ($$, 0, PopLocation ());
759 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
761 lbag.AddLocation ($$, GetLocation($3));
766 Error_SyntaxError (yyToken);
768 var lt = (LocatedToken) $1;
769 var tne = new SimpleName (lt.Value, null, lt.Location);
771 $$ = new List<Attribute> () {
772 new Attribute (null, tne, null, GetLocation ($1), false)
777 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
778 Error_SyntaxError (yyToken);
787 var lt = (LocatedToken) $1;
788 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
790 | EVENT { $$ = "event"; }
791 | RETURN { $$ = "return"; }
797 $$ = new List<Attribute> (4) { (Attribute) $1 };
799 | attribute_list COMMA attribute
801 var attrs = (List<Attribute>) $1;
803 attrs.Add ((Attribute) $3);
804 lbag.AppendTo (attrs, GetLocation ($2));
814 ++lexer.parsing_block;
816 opt_attribute_arguments
818 --lexer.parsing_block;
820 var tne = (ATypeNameExpression) $1;
821 if (tne.HasTypeArguments) {
822 report.Error (404, tne.Location, "Attributes cannot be generic");
825 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
830 : namespace_or_type_expr
833 opt_attribute_arguments
834 : /* empty */ { $$ = null; }
835 | OPEN_PARENS attribute_arguments CLOSE_PARENS
843 : /* empty */ { $$ = null; }
844 | positional_or_named_argument
846 Arguments a = new Arguments (4);
847 a.Add ((Argument) $1);
848 $$ = new Arguments [] { a, null };
850 | named_attribute_argument
852 Arguments a = new Arguments (4);
853 a.Add ((Argument) $1);
854 $$ = new Arguments [] { null, a };
856 | attribute_arguments COMMA positional_or_named_argument
858 Arguments[] o = (Arguments[]) $1;
860 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
861 o [0] = new Arguments (4);
864 Arguments args = ((Arguments) o [0]);
865 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
866 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
868 args.Add ((Argument) $3);
870 | attribute_arguments COMMA named_attribute_argument
872 Arguments[] o = (Arguments[]) $1;
874 o [1] = new Arguments (4);
877 ((Arguments) o [1]).Add ((Argument) $3);
881 positional_or_named_argument
884 $$ = new Argument ((Expression) $1);
889 Error_SyntaxError (yyToken);
894 named_attribute_argument
897 ++lexer.parsing_block;
901 --lexer.parsing_block;
902 var lt = (LocatedToken) $1;
903 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
904 lbag.AddLocation ($$, GetLocation($2));
909 : identifier_inside_body COLON opt_named_modifier named_argument_expr
911 if (lang_version <= LanguageVersion.V_3)
912 FeatureIsNotAvailable (GetLocation ($1), "named argument");
914 // Avoid boxing in common case (no modifier)
915 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
917 var lt = (LocatedToken) $1;
918 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
919 lbag.AddLocation ($$, GetLocation($2));
921 | identifier_inside_body COLON OUT named_argument_expr_or_out_variable_declaration
923 if (lang_version <= LanguageVersion.V_3)
924 FeatureIsNotAvailable (GetLocation ($1), "named argument");
926 var lt = (LocatedToken) $1;
927 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, Argument.AType.Out);
928 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
3247 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3248 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3252 builtin_type_expression
3253 : builtin_types opt_nullable
3256 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3258 | builtin_types pointer_stars
3260 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3262 | VOID pointer_stars
3264 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3271 var types = new List<FullNamedExpression> (2);
3272 types.Add ((FullNamedExpression) $1);
3275 | type_list COMMA base_type_name
3277 var types = (List<FullNamedExpression>) $1;
3278 types.Add ((FullNamedExpression) $3);
3286 if ($1 is ComposedCast) {
3287 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3294 * replaces all the productions for isolating the various
3295 * simple types, but we need this to reuse it easily in variable_type
3298 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3299 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3300 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3301 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3302 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3303 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3308 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3309 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3310 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3311 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3312 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3313 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3314 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3315 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3316 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3320 // Expressions, section 7.5
3325 : type_name_expression
3327 | array_creation_expression
3328 | parenthesized_expression
3329 | default_value_expression
3330 | invocation_expression
3334 | post_increment_expression
3335 | post_decrement_expression
3336 | object_or_delegate_creation_expression
3337 | anonymous_type_expression
3340 | checked_expression
3341 | unchecked_expression
3342 | pointer_member_access
3343 | anonymous_method_expression
3344 | undocumented_expressions
3345 | interpolated_string
3348 type_name_expression
3350 | IDENTIFIER GENERATE_COMPLETION {
3351 var lt = (LocatedToken) $1;
3352 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3360 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3364 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3365 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3369 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3371 if (lang_version < LanguageVersion.V_6)
3372 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3374 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3376 | INTERPOLATED_STRING_END
3378 if (lang_version < LanguageVersion.V_6)
3379 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3381 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3388 var list = new List<Expression> ();
3389 list.Add ((InterpolatedStringInsert) $1);
3392 | interpolations INTERPOLATED_STRING interpolation
3394 var list = (List<Expression>) $1;
3395 list.Add ((StringLiteral) $2);
3396 list.Add ((InterpolatedStringInsert) $3);
3404 $$ = new InterpolatedStringInsert ((Expression) $1);
3406 | expression COMMA expression
3408 $$ = new InterpolatedStringInsert ((Expression) $1) {
3409 Alignment = (Expression)$3
3414 lexer.parsing_interpolation_format = true;
3418 lexer.parsing_interpolation_format = false;
3420 $$ = new InterpolatedStringInsert ((Expression) $1) {
3424 | expression COMMA expression COLON
3426 lexer.parsing_interpolation_format = true;
3430 lexer.parsing_interpolation_format = false;
3432 $$ = new InterpolatedStringInsert ((Expression) $1) {
3433 Alignment = (Expression)$3,
3434 Format = (string) $6
3441 // Here is the trick, tokenizer may think that parens is a special but
3442 // parser is interested in open parens only, so we merge them.
3443 // Consider: if (a)foo ();
3451 // Use this production to accept closing parenthesis or
3452 // performing completion
3456 | COMPLETE_COMPLETION
3460 parenthesized_expression
3461 : OPEN_PARENS expression CLOSE_PARENS
3463 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3464 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3466 | OPEN_PARENS expression COMPLETE_COMPLETION
3468 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3473 : primary_expression DOT identifier_inside_body opt_type_argument_list
3475 var lt = (LocatedToken) $3;
3476 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3477 lbag.AddLocation ($$, GetLocation ($2));
3479 | primary_expression DOT identifier_inside_body generic_dimension
3481 var lt = (LocatedToken) $3;
3482 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3483 lbag.AddLocation ($$, GetLocation ($2));
3485 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3487 if (lang_version < LanguageVersion.V_6)
3488 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3490 var lt = (LocatedToken) $4;
3491 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3492 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3494 | builtin_types DOT identifier_inside_body opt_type_argument_list
3496 var lt = (LocatedToken) $3;
3497 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3498 lbag.AddLocation ($$, GetLocation ($2));
3500 | BASE DOT identifier_inside_body opt_type_argument_list
3502 var lt = (LocatedToken) $3;
3503 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3504 lbag.AddLocation ($$, GetLocation ($2));
3506 | AWAIT DOT identifier_inside_body opt_type_argument_list
3508 var lt = (LocatedToken) $3;
3509 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3510 lbag.AddLocation ($$, GetLocation ($2));
3512 | qualified_alias_member identifier_inside_body opt_type_argument_list
3514 var lt1 = (LocatedToken) $1;
3515 var lt2 = (LocatedToken) $2;
3517 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3518 lbag.AddLocation ($$, GetLocation ($2));
3520 | qualified_alias_member identifier_inside_body generic_dimension
3522 var lt1 = (LocatedToken) $1;
3523 var lt2 = (LocatedToken) $2;
3525 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3526 lbag.AddLocation ($$, GetLocation ($2));
3528 | primary_expression DOT GENERATE_COMPLETION {
3529 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3531 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3532 var lt = (LocatedToken) $3;
3533 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3535 | builtin_types DOT GENERATE_COMPLETION
3537 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3539 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3540 var lt = (LocatedToken) $3;
3541 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3545 invocation_expression
3546 : primary_expression open_parens_any opt_argument_list close_parens
3548 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3549 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3551 | primary_expression open_parens_any argument_list error
3553 Error_SyntaxError (yyToken);
3555 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3556 lbag.AddLocation ($$, GetLocation ($2));
3558 | primary_expression open_parens_any error
3560 Error_SyntaxError (yyToken);
3562 $$ = new Invocation ((Expression) $1, null);
3563 lbag.AddLocation ($$, GetLocation ($2));
3567 opt_object_or_collection_initializer
3568 : /* empty */ { $$ = null; }
3569 | object_or_collection_initializer
3572 object_or_collection_initializer
3573 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3576 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3578 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3580 lbag.AddLocation ($$, GetLocation ($3));
3582 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3584 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3585 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3589 opt_member_initializer_list
3590 : /* empty */ { $$ = null; }
3591 | member_initializer_list
3597 member_initializer_list
3598 : member_initializer
3600 var a = new List<Expression> ();
3601 a.Add ((Expression) $1);
3604 | member_initializer_list COMMA member_initializer
3606 var a = (List<Expression>)$1;
3607 a.Add ((Expression) $3);
3610 | member_initializer_list error {
3611 Error_SyntaxError (yyToken);
3617 : IDENTIFIER ASSIGN initializer_value
3619 var lt = (LocatedToken) $1;
3620 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3621 lbag.AddLocation ($$, GetLocation ($2));
3623 | AWAIT ASSIGN initializer_value
3625 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3626 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3627 lbag.AddLocation ($$, GetLocation ($2));
3629 | GENERATE_COMPLETION
3631 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3633 | non_assignment_expression opt_COMPLETE_COMPLETION {
3634 CompletionSimpleName csn = $1 as CompletionSimpleName;
3636 $$ = new CollectionElementInitializer ((Expression)$1);
3638 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3640 | OPEN_BRACE expression_list CLOSE_BRACE
3643 $$ = new CollectionElementInitializer (GetLocation ($1));
3645 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3647 lbag.AddLocation ($$, GetLocation ($3));
3649 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3651 if (lang_version < LanguageVersion.V_6)
3652 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3654 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3655 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3657 | OPEN_BRACE CLOSE_BRACE
3659 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3660 $$ = new CollectionElementInitializer (GetLocation ($1));
3661 lbag.AddLocation ($$, GetLocation ($2));
3667 | object_or_collection_initializer
3671 : /* empty */ { $$ = null; }
3676 : argument_or_named_argument
3678 Arguments list = new Arguments (4);
3679 list.Add ((Argument) $1);
3682 | argument_list COMMA argument
3684 Arguments list = (Arguments) $1;
3685 if (list [list.Count - 1] is NamedArgument)
3686 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3688 list.Add ((Argument) $3);
3691 | argument_list COMMA named_argument
3693 Arguments list = (Arguments) $1;
3694 NamedArgument a = (NamedArgument) $3;
3695 for (int i = 0; i < list.Count; ++i) {
3696 NamedArgument na = list [i] as NamedArgument;
3697 if (na != null && na.Name == a.Name)
3698 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3705 | argument_list COMMA error
3707 if (lexer.putback_char == -1)
3708 lexer.putback (')'); // TODO: Wrong but what can I do
3709 Error_SyntaxError (yyToken);
3714 report.Error (839, GetLocation ($1), "An argument is missing");
3722 $$ = new Argument ((Expression) $1);
3724 | non_simple_argument
3727 argument_or_named_argument
3733 : REF variable_reference
3735 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3736 lbag.AddLocation ($$, GetLocation ($1));
3738 | OUT variable_reference
3740 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3741 lbag.AddLocation ($$, GetLocation ($1));
3743 | OUT out_variable_declaration
3745 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3747 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3749 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3750 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3752 | ARGLIST OPEN_PARENS CLOSE_PARENS
3754 $$ = new Argument (new Arglist (GetLocation ($1)));
3755 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3759 out_variable_declaration
3760 : variable_type identifier_inside_body
3762 if (lang_version < LanguageVersion.V_7)
3763 FeatureIsNotAvailable (GetLocation ($1), "out variable declaration");
3765 var lt = (LocatedToken) $2;
3766 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3767 current_block.AddLocalName (lv);
3768 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3777 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3779 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3780 lbag.AddLocation ($$, GetLocation ($4));
3782 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3784 if (lang_version < LanguageVersion.V_6)
3785 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3787 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3788 ConditionalAccess = true
3791 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3793 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3795 Error_SyntaxError (yyToken);
3796 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3798 | primary_expression OPEN_BRACKET_EXPR error
3800 Error_SyntaxError (yyToken);
3801 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3806 : expression_or_error
3808 var list = new List<Expression> (4);
3809 list.Add ((Expression) $1);
3812 | expression_list COMMA expression_or_error
3814 var list = (List<Expression>) $1;
3815 list.Add ((Expression) $3);
3820 expression_list_arguments
3821 : expression_list_argument
3823 Arguments args = new Arguments (4);
3824 args.Add ((Argument) $1);
3827 | expression_list_arguments COMMA expression_list_argument
3829 Arguments args = (Arguments) $1;
3830 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3831 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3833 args.Add ((Argument) $3);
3838 expression_list_argument
3841 $$ = new Argument ((Expression) $1);
3849 $$ = new This (GetLocation ($1));
3854 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3856 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3857 lbag.AddLocation ($$, GetLocation ($4));
3859 | BASE OPEN_BRACKET error
3861 Error_SyntaxError (yyToken);
3862 $$ = new ElementAccess (null, null, GetLocation ($2));
3866 post_increment_expression
3867 : primary_expression OP_INC
3869 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3873 post_decrement_expression
3874 : primary_expression OP_DEC
3876 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3880 object_or_delegate_creation_expression
3881 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3884 if (lang_version <= LanguageVersion.ISO_2)
3885 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3887 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3889 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3892 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3894 | NEW new_expr_type object_or_collection_initializer
3896 if (lang_version <= LanguageVersion.ISO_2)
3897 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3899 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3903 array_creation_expression
3904 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3906 opt_array_initializer
3908 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3909 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3910 Next = (ComposedTypeSpecifier) $6
3911 }, (ArrayInitializer) $7, GetLocation ($1)) {
3912 NoEmptyInterpolation = true
3915 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3917 | NEW new_expr_type rank_specifiers opt_array_initializer
3920 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3922 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
3923 NoEmptyInterpolation = true
3926 | NEW rank_specifier array_initializer
3928 if (lang_version <= LanguageVersion.ISO_2)
3929 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3931 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3933 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3935 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3936 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3938 | NEW new_expr_type error
3940 Error_SyntaxError (yyToken);
3941 // It can be any of new expression, create the most common one
3942 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3948 ++lexer.parsing_type;
3952 --lexer.parsing_type;
3957 anonymous_type_expression
3958 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3960 if (lang_version <= LanguageVersion.ISO_2)
3961 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3963 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3965 // TODO: lbag comma location
3966 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3968 | NEW OPEN_BRACE GENERATE_COMPLETION
3970 $$ = new EmptyCompletion ();
3974 anonymous_type_parameters_opt_comma
3975 : anonymous_type_parameters_opt
3976 | anonymous_type_parameters COMMA
3979 anonymous_type_parameters_opt
3981 | anonymous_type_parameters
3984 anonymous_type_parameters
3985 : anonymous_type_parameter
3987 var a = new List<AnonymousTypeParameter> (4);
3988 a.Add ((AnonymousTypeParameter) $1);
3991 | anonymous_type_parameters COMMA anonymous_type_parameter
3993 var a = (List<AnonymousTypeParameter>) $1;
3994 a.Add ((AnonymousTypeParameter) $3);
3997 | COMPLETE_COMPLETION
3999 $$ = new EmptyCompletion ();
4001 | anonymous_type_parameter COMPLETE_COMPLETION
4007 anonymous_type_parameter
4008 : identifier_inside_body ASSIGN variable_initializer
4010 var lt = (LocatedToken)$1;
4011 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4012 lbag.AddLocation ($$, GetLocation ($2));
4014 | identifier_inside_body
4016 var lt = (LocatedToken)$1;
4017 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4018 lt.Value, lt.Location);
4022 MemberAccess ma = (MemberAccess) $1;
4023 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4027 report.Error (746, lexer.Location,
4028 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4040 | rank_specifier rank_specifiers
4042 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4048 : OPEN_BRACKET CLOSE_BRACKET
4050 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4051 lbag.AddLocation ($$, GetLocation ($2));
4053 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4055 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4056 lbag.AddLocation ($$, GetLocation ($3));
4065 | dim_separators COMMA
4067 $$ = ((int) $1) + 1;
4071 opt_array_initializer
4083 : OPEN_BRACE CLOSE_BRACE
4085 var ai = new ArrayInitializer (0, GetLocation ($1));
4086 ai.VariableDeclaration = current_variable;
4087 lbag.AddLocation (ai, GetLocation ($2));
4090 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4092 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4093 ai.VariableDeclaration = current_variable;
4095 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4097 lbag.AddLocation (ai, GetLocation ($4));
4103 variable_initializer_list
4104 : variable_initializer
4106 var list = new List<Expression> (4);
4107 list.Add ((Expression) $1);
4110 | variable_initializer_list COMMA variable_initializer
4112 var list = (List<Expression>) $1;
4113 list.Add ((Expression) $3);
4119 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4121 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4122 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4126 typeof_type_expression
4130 Error_TypeExpected (lexer.Location);
4138 if (lang_version < LanguageVersion.ISO_2)
4139 FeatureIsNotAvailable (GetLocation ($1), "generics");
4145 qualified_alias_member
4146 : IDENTIFIER DOUBLE_COLON
4148 var lt = (LocatedToken) $1;
4149 if (lang_version == LanguageVersion.ISO_1)
4150 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4157 : SIZEOF open_parens_any type CLOSE_PARENS
4159 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4160 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4162 | SIZEOF open_parens_any type error
4164 Error_SyntaxError (yyToken);
4166 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4167 lbag.AddLocation ($$, GetLocation ($2));
4172 : CHECKED open_parens_any expression CLOSE_PARENS
4174 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4175 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4179 Error_SyntaxError (yyToken);
4181 $$ = new CheckedExpr (null, GetLocation ($1));
4185 unchecked_expression
4186 : UNCHECKED open_parens_any expression CLOSE_PARENS
4188 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4189 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4193 Error_SyntaxError (yyToken);
4195 $$ = new UnCheckedExpr (null, GetLocation ($1));
4199 pointer_member_access
4200 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4202 var lt = (LocatedToken) $3;
4203 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4207 anonymous_method_expression
4208 : DELEGATE opt_anonymous_method_signature
4210 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4214 $$ = end_anonymous ((ParametersBlock) $4);
4216 | ASYNC DELEGATE opt_anonymous_method_signature
4218 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4222 $$ = end_anonymous ((ParametersBlock) $5);
4226 opt_anonymous_method_signature
4229 $$ = ParametersCompiled.Undefined;
4231 | anonymous_method_signature
4234 anonymous_method_signature
4237 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4239 opt_formal_parameter_list CLOSE_PARENS
4241 valid_param_mod = 0;
4246 default_value_expression
4247 : DEFAULT open_parens_any type CLOSE_PARENS
4249 if (lang_version < LanguageVersion.ISO_2)
4250 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4252 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4253 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4258 : primary_expression
4259 | BANG prefixed_unary_expression
4261 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4263 | TILDE prefixed_unary_expression
4265 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4267 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4269 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4270 lbag.AddLocation ($$, GetLocation ($3));
4272 | AWAIT prefixed_unary_expression
4275 if (current_anonymous_method is LambdaExpression) {
4276 report.Error (4034, GetLocation ($1),
4277 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4278 } else if (current_anonymous_method != null) {
4279 report.Error (4035, GetLocation ($1),
4280 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4281 } else if (interactive_async != null) {
4282 current_block.Explicit.RegisterAsyncAwait ();
4283 interactive_async = true;
4285 report.Error (4033, GetLocation ($1),
4286 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4289 current_block.Explicit.RegisterAsyncAwait ();
4292 $$ = new Await ((Expression) $2, GetLocation ($1));
4294 | THROW_EXPR prefixed_unary_expression
4296 if (lang_version < LanguageVersion.V_7)
4297 FeatureIsNotAvailable (lexer.Location, "throw expression");
4299 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4303 Error_SyntaxError (yyToken);
4305 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4309 Error_SyntaxError (yyToken);
4311 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4313 | OPEN_PARENS_CAST type CLOSE_PARENS error
4315 Error_SyntaxError (yyToken);
4317 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4318 lbag.AddLocation ($$, GetLocation ($3));
4322 Error_SyntaxError (yyToken);
4324 $$ = new Await (null, GetLocation ($1));
4329 // The idea to split this out is from Rhys' grammar
4330 // to solve the problem with casts.
4332 prefixed_unary_expression
4334 | PLUS prefixed_unary_expression
4336 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4338 | MINUS prefixed_unary_expression
4340 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4342 | OP_INC prefixed_unary_expression
4344 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4346 | OP_DEC prefixed_unary_expression
4348 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4350 | STAR prefixed_unary_expression
4352 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4354 | BITWISE_AND prefixed_unary_expression
4356 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4360 Error_SyntaxError (yyToken);
4362 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4366 Error_SyntaxError (yyToken);
4368 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4372 Error_SyntaxError (yyToken);
4374 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4378 Error_SyntaxError (yyToken);
4380 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4384 Error_SyntaxError (yyToken);
4386 $$ = new Indirection (null, GetLocation ($1));
4390 Error_SyntaxError (yyToken);
4392 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4396 multiplicative_expression
4397 : prefixed_unary_expression
4398 | multiplicative_expression STAR prefixed_unary_expression
4400 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4401 lbag.AddLocation ($$, GetLocation ($2));
4403 | multiplicative_expression DIV prefixed_unary_expression
4405 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4406 lbag.AddLocation ($$, GetLocation ($2));
4408 | multiplicative_expression PERCENT prefixed_unary_expression
4410 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4411 lbag.AddLocation ($$, GetLocation ($2));
4413 | multiplicative_expression STAR error
4415 Error_SyntaxError (yyToken);
4417 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4418 lbag.AddLocation ($$, GetLocation ($2));
4420 | multiplicative_expression DIV error
4422 Error_SyntaxError (yyToken);
4424 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4425 lbag.AddLocation ($$, GetLocation ($2));
4427 | multiplicative_expression PERCENT error
4429 Error_SyntaxError (yyToken);
4431 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4432 lbag.AddLocation ($$, GetLocation ($2));
4437 : multiplicative_expression
4438 | additive_expression PLUS multiplicative_expression
4440 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4441 lbag.AddLocation ($$, GetLocation ($2));
4443 | additive_expression MINUS multiplicative_expression
4445 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4446 lbag.AddLocation ($$, GetLocation ($2));
4448 | additive_expression PLUS error
4450 Error_SyntaxError (yyToken);
4452 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4453 lbag.AddLocation ($$, GetLocation ($2));
4455 | additive_expression MINUS error
4457 Error_SyntaxError (yyToken);
4459 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4460 lbag.AddLocation ($$, GetLocation ($2));
4462 | additive_expression AS type
4464 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4466 | additive_expression IS pattern_type_expr opt_identifier
4468 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4470 if (lang_version < LanguageVersion.V_7)
4471 FeatureIsNotAvailable (GetLocation ($4), "pattern matching");
4473 var lt = (LocatedToken) $4;
4474 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
4475 is_expr.Variable = lv;
4476 current_block.AddLocalName (lv);
4481 | additive_expression IS pattern_expr
4483 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4484 if (lang_version != LanguageVersion.Experimental)
4485 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4489 | additive_expression AS error
4491 Error_SyntaxError (yyToken);
4493 $$ = new As ((Expression) $1, null, GetLocation ($2));
4495 | additive_expression IS error
4497 Error_SyntaxError (yyToken);
4499 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4503 var lt = (LocatedToken) $1;
4504 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4508 var lt = (LocatedToken) $1;
4509 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4519 | PLUS prefixed_unary_expression
4521 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4523 | MINUS prefixed_unary_expression
4525 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4528 | default_value_expression
4529 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4531 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4532 lbag.AddLocation ($$, GetLocation ($3));
4536 $$ = new WildcardPattern (GetLocation ($1));
4538 | pattern_expr_invocation
4542 pattern_expr_invocation
4543 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4545 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4550 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4552 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4556 pattern_property_list
4557 : pattern_property_entry
4559 var list = new List<PropertyPatternMember> ();
4560 list.Add ((PropertyPatternMember) $1);
4563 | pattern_property_list COMMA pattern_property_entry
4565 var list = (List<PropertyPatternMember>) $1;
4566 list.Add ((PropertyPatternMember) $3);
4571 pattern_property_entry
4572 : identifier_inside_body IS pattern
4574 var lt = (LocatedToken) $1;
4575 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4581 | pattern_type_expr opt_identifier
4584 var lt = (LocatedToken) $2;
4585 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4586 current_block.AddLocalName (variable);
4594 $$ = new Arguments (0);
4602 Arguments args = new Arguments (4);
4603 args.Add ((Argument) $1);
4606 | pattern_list COMMA pattern_argument
4608 Arguments args = (Arguments) $1;
4609 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4610 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4612 args.Add ((Argument) $3);
4620 $$ = new Argument ((Expression) $1);
4622 | IDENTIFIER COLON pattern
4624 var lt = (LocatedToken) $1;
4625 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4630 : additive_expression
4631 | shift_expression OP_SHIFT_LEFT additive_expression
4633 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4634 lbag.AddLocation ($$, GetLocation ($2));
4636 | shift_expression OP_SHIFT_RIGHT additive_expression
4638 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4639 lbag.AddLocation ($$, GetLocation ($2));
4641 | shift_expression OP_SHIFT_LEFT error
4643 Error_SyntaxError (yyToken);
4645 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4646 lbag.AddLocation ($$, GetLocation ($2));
4648 | shift_expression OP_SHIFT_RIGHT error
4650 Error_SyntaxError (yyToken);
4652 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4653 lbag.AddLocation ($$, GetLocation ($2));
4657 relational_expression
4659 | relational_expression OP_LT shift_expression
4661 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4662 lbag.AddLocation ($$, GetLocation ($2));
4664 | relational_expression OP_GT shift_expression
4666 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4667 lbag.AddLocation ($$, GetLocation ($2));
4669 | relational_expression OP_LE shift_expression
4671 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4672 lbag.AddLocation ($$, GetLocation ($2));
4674 | relational_expression OP_GE shift_expression
4676 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4677 lbag.AddLocation ($$, GetLocation ($2));
4679 | relational_expression OP_LT error
4681 Error_SyntaxError (yyToken);
4683 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4684 lbag.AddLocation ($$, GetLocation ($2));
4686 | relational_expression OP_GT error
4688 Error_SyntaxError (yyToken);
4690 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4691 lbag.AddLocation ($$, GetLocation ($2));
4693 | relational_expression OP_LE error
4695 Error_SyntaxError (yyToken);
4697 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4698 lbag.AddLocation ($$, GetLocation ($2));
4700 | relational_expression OP_GE error
4702 Error_SyntaxError (yyToken);
4704 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4705 lbag.AddLocation ($$, GetLocation ($2));
4710 : relational_expression
4711 | equality_expression OP_EQ relational_expression
4713 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4714 lbag.AddLocation ($$, GetLocation ($2));
4716 | equality_expression OP_NE relational_expression
4718 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4719 lbag.AddLocation ($$, GetLocation ($2));
4721 | equality_expression OP_EQ error
4723 Error_SyntaxError (yyToken);
4725 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4726 lbag.AddLocation ($$, GetLocation ($2));
4728 | equality_expression OP_NE error
4730 Error_SyntaxError (yyToken);
4732 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4733 lbag.AddLocation ($$, GetLocation ($2));
4738 : equality_expression
4739 | and_expression BITWISE_AND equality_expression
4741 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4742 lbag.AddLocation ($$, GetLocation ($2));
4744 | and_expression BITWISE_AND error
4746 Error_SyntaxError (yyToken);
4748 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4749 lbag.AddLocation ($$, GetLocation ($2));
4753 exclusive_or_expression
4755 | exclusive_or_expression CARRET and_expression
4757 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4758 lbag.AddLocation ($$, GetLocation ($2));
4760 | exclusive_or_expression CARRET error
4762 Error_SyntaxError (yyToken);
4764 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4765 lbag.AddLocation ($$, GetLocation ($2));
4769 inclusive_or_expression
4770 : exclusive_or_expression
4771 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4773 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4774 lbag.AddLocation ($$, GetLocation ($2));
4776 | inclusive_or_expression BITWISE_OR error
4778 Error_SyntaxError (yyToken);
4780 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4781 lbag.AddLocation ($$, GetLocation ($2));
4785 conditional_and_expression
4786 : inclusive_or_expression
4787 | conditional_and_expression OP_AND inclusive_or_expression
4789 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4790 lbag.AddLocation ($$, GetLocation ($2));
4792 | conditional_and_expression OP_AND error
4794 Error_SyntaxError (yyToken);
4796 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4797 lbag.AddLocation ($$, GetLocation ($2));
4801 conditional_or_expression
4802 : conditional_and_expression
4803 | conditional_or_expression OP_OR conditional_and_expression
4805 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4806 lbag.AddLocation ($$, GetLocation ($2));
4808 | conditional_or_expression OP_OR error
4810 Error_SyntaxError (yyToken);
4812 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4813 lbag.AddLocation ($$, GetLocation ($2));
4817 null_coalescing_expression
4818 : conditional_or_expression
4819 | conditional_or_expression OP_COALESCING null_coalescing_expression
4821 if (lang_version < LanguageVersion.ISO_2)
4822 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4824 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4825 lbag.AddLocation ($$, GetLocation ($2));
4829 conditional_expression
4830 : null_coalescing_expression
4831 | null_coalescing_expression INTERR expression COLON expression
4833 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4834 lbag.AddLocation ($$, GetLocation ($4));
4836 | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4838 if (lang_version < LanguageVersion.V_7)
4839 FeatureIsNotAvailable (lexer.Location, "throw expression");
4841 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4842 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4843 lbag.AddLocation ($$, GetLocation ($4));
4845 | null_coalescing_expression INTERR expression error
4847 Error_SyntaxError (yyToken);
4849 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4851 | null_coalescing_expression INTERR expression COLON error
4853 Error_SyntaxError (yyToken);
4855 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4856 lbag.AddLocation ($$, GetLocation ($4));
4858 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4860 Error_SyntaxError (Token.CLOSE_BRACE);
4862 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4863 lbag.AddLocation ($$, GetLocation ($4));
4864 lexer.putback ('}');
4868 assignment_expression
4869 : prefixed_unary_expression ASSIGN expression
4871 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4872 lbag.AddLocation ($$, GetLocation ($2));
4874 | prefixed_unary_expression OP_MULT_ASSIGN expression
4876 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4877 lbag.AddLocation ($$, GetLocation ($2));
4879 | prefixed_unary_expression OP_DIV_ASSIGN expression
4881 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4882 lbag.AddLocation ($$, GetLocation ($2));
4884 | prefixed_unary_expression OP_MOD_ASSIGN expression
4886 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4887 lbag.AddLocation ($$, GetLocation ($2));
4889 | prefixed_unary_expression OP_ADD_ASSIGN expression
4891 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4892 lbag.AddLocation ($$, GetLocation ($2));
4894 | prefixed_unary_expression OP_SUB_ASSIGN expression
4896 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4897 lbag.AddLocation ($$, GetLocation ($2));
4899 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4901 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4902 lbag.AddLocation ($$, GetLocation ($2));
4904 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4906 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4907 lbag.AddLocation ($$, GetLocation ($2));
4909 | prefixed_unary_expression OP_AND_ASSIGN expression
4911 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4912 lbag.AddLocation ($$, GetLocation ($2));
4914 | prefixed_unary_expression OP_OR_ASSIGN expression
4916 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4917 lbag.AddLocation ($$, GetLocation ($2));
4919 | prefixed_unary_expression OP_XOR_ASSIGN expression
4921 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4922 lbag.AddLocation ($$, GetLocation ($2));
4926 lambda_parameter_list
4929 var pars = new List<Parameter> (4);
4930 pars.Add ((Parameter) $1);
4934 | lambda_parameter_list COMMA lambda_parameter
4936 var pars = (List<Parameter>) $1;
4937 Parameter p = (Parameter)$3;
4938 if (pars[0].GetType () != p.GetType ()) {
4939 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4948 : parameter_modifier parameter_type identifier_inside_body
4950 var lt = (LocatedToken) $3;
4952 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4954 | parameter_type identifier_inside_body
4956 var lt = (LocatedToken) $2;
4958 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4962 var lt = (LocatedToken) $1;
4963 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4967 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4968 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4972 opt_lambda_parameter_list
4973 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4974 | lambda_parameter_list {
4975 var pars_list = (List<Parameter>) $1;
4976 $$ = new ParametersCompiled (pars_list.ToArray ());
4980 lambda_expression_body
4982 start_block (Location.Null);
4984 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4986 Block b = end_block (Location.Null);
4987 b.IsCompilerGenerated = true;
4988 b.AddStatement (new ContextualReturn ((Expression) $2));
4994 // Handles only cases like foo = x.FirstOrDefault (l => );
4995 // where we must restore current_variable
4996 Block b = end_block (Location.Null);
4997 b.IsCompilerGenerated = true;
4999 Error_SyntaxError (yyToken);
5008 Error_SyntaxError (yyToken);
5016 var lt = (LocatedToken) $1;
5017 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5018 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5020 lambda_expression_body
5022 $$ = end_anonymous ((ParametersBlock) $4);
5023 lbag.AddLocation ($$, GetLocation ($2));
5027 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5028 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5029 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5031 lambda_expression_body
5033 $$ = end_anonymous ((ParametersBlock) $4);
5034 lbag.AddLocation ($$, GetLocation ($2));
5036 | ASYNC identifier_inside_body ARROW
5038 var lt = (LocatedToken) $2;
5039 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5040 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5042 lambda_expression_body
5044 $$ = end_anonymous ((ParametersBlock) $5);
5045 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5047 | OPEN_PARENS_LAMBDA
5049 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5051 opt_lambda_parameter_list CLOSE_PARENS ARROW
5053 valid_param_mod = 0;
5054 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5056 lambda_expression_body
5058 $$ = end_anonymous ((ParametersBlock) $7);
5059 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5061 | ASYNC OPEN_PARENS_LAMBDA
5063 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5065 opt_lambda_parameter_list CLOSE_PARENS ARROW
5067 valid_param_mod = 0;
5068 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5070 lambda_expression_body
5072 $$ = end_anonymous ((ParametersBlock) $8);
5073 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5078 : assignment_expression
5079 | non_assignment_expression
5082 non_assignment_expression
5083 : conditional_expression
5088 $$ = new ArglistAccess (GetLocation ($1));
5092 undocumented_expressions
5093 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5095 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5096 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5098 | REFTYPE open_parens_any expression CLOSE_PARENS
5100 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5101 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5103 | MAKEREF open_parens_any expression CLOSE_PARENS
5105 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5106 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5117 $$ = new BooleanExpression ((Expression) $1);
5121 opt_primary_parameters
5126 | primary_parameters
5130 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5134 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5135 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5137 if (lang_version != LanguageVersion.Experimental)
5138 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5142 opt_primary_parameters_with_class_base
5151 | primary_parameters
5155 | primary_parameters class_base
5159 | primary_parameters class_base OPEN_PARENS
5161 ++lexer.parsing_block;
5162 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5164 opt_argument_list CLOSE_PARENS
5166 lbag.AppendToMember (current_container, GetLocation ($6));
5167 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5168 --lexer.parsing_block;
5184 type_declaration_name
5186 lexer.ConstraintsParsing = true;
5188 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5189 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5190 FeatureIsNotAvailable (c.Location, "static classes");
5193 push_current_container (c, $3);
5194 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5196 opt_primary_parameters_with_class_base
5197 opt_type_parameter_constraints_clauses
5199 valid_param_mod = 0;
5200 lexer.ConstraintsParsing = false;
5203 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5206 current_container.SetConstraints ((List<Constraints>) $9);
5207 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5210 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5211 Lexer.doc_state = XmlCommentState.Allowed;
5214 lexer.parsing_modifiers = true;
5216 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5218 --lexer.parsing_declaration;
5220 Lexer.doc_state = XmlCommentState.Allowed;
5225 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5227 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5229 $$ = pop_current_class ();
5237 { $$ = $1; } // location
5243 mod_locations = null;
5245 lexer.parsing_modifiers = false;
5249 lexer.parsing_modifiers = false;
5255 | modifiers modifier
5257 var m1 = (Modifiers) $1;
5258 var m2 = (Modifiers) $2;
5260 if ((m1 & m2) != 0) {
5261 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5262 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5263 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5264 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5265 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5266 "More than one protection modifier specified");
5277 StoreModifierLocation ($$, GetLocation ($1));
5279 if (current_container.Kind == MemberKind.Namespace)
5280 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5284 $$ = Modifiers.PUBLIC;
5285 StoreModifierLocation ($$, GetLocation ($1));
5289 $$ = Modifiers.PROTECTED;
5290 StoreModifierLocation ($$, GetLocation ($1));
5294 $$ = Modifiers.INTERNAL;
5295 StoreModifierLocation ($$, GetLocation ($1));
5299 $$ = Modifiers.PRIVATE;
5300 StoreModifierLocation ($$, GetLocation ($1));
5304 $$ = Modifiers.ABSTRACT;
5305 StoreModifierLocation ($$, GetLocation ($1));
5309 $$ = Modifiers.SEALED;
5310 StoreModifierLocation ($$, GetLocation ($1));
5314 $$ = Modifiers.STATIC;
5315 StoreModifierLocation ($$, GetLocation ($1));
5319 $$ = Modifiers.READONLY;
5320 StoreModifierLocation ($$, GetLocation ($1));
5324 $$ = Modifiers.VIRTUAL;
5325 StoreModifierLocation ($$, GetLocation ($1));
5329 $$ = Modifiers.OVERRIDE;
5330 StoreModifierLocation ($$, GetLocation ($1));
5334 $$ = Modifiers.EXTERN;
5335 StoreModifierLocation ($$, GetLocation ($1));
5339 $$ = Modifiers.VOLATILE;
5340 StoreModifierLocation ($$, GetLocation ($1));
5344 $$ = Modifiers.UNSAFE;
5345 StoreModifierLocation ($$, GetLocation ($1));
5346 if (!settings.Unsafe)
5347 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5351 $$ = Modifiers.ASYNC;
5352 StoreModifierLocation ($$, GetLocation ($1));
5364 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5366 | COLON type_list error
5368 Error_SyntaxError (yyToken);
5370 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5374 opt_type_parameter_constraints_clauses
5376 | type_parameter_constraints_clauses
5382 type_parameter_constraints_clauses
5383 : type_parameter_constraints_clause
5385 var constraints = new List<Constraints> (1);
5386 constraints.Add ((Constraints) $1);
5389 | type_parameter_constraints_clauses type_parameter_constraints_clause
5391 var constraints = (List<Constraints>) $1;
5392 Constraints new_constraint = (Constraints)$2;
5394 foreach (Constraints c in constraints) {
5395 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5396 report.Error (409, new_constraint.Location,
5397 "A constraint clause has already been specified for type parameter `{0}'",
5398 new_constraint.TypeParameter.Value);
5402 constraints.Add (new_constraint);
5407 type_parameter_constraints_clause
5408 : WHERE IDENTIFIER COLON type_parameter_constraints
5410 var lt = (LocatedToken) $2;
5411 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5412 lbag.AddLocation ($$, GetLocation ($3));
5414 | WHERE IDENTIFIER error
5416 Error_SyntaxError (yyToken);
5418 var lt = (LocatedToken) $2;
5419 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5423 type_parameter_constraints
5424 : type_parameter_constraint
5426 var constraints = new List<FullNamedExpression> (1);
5427 constraints.Add ((FullNamedExpression) $1);
5430 | type_parameter_constraints COMMA type_parameter_constraint
5432 var constraints = (List<FullNamedExpression>) $1;
5433 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5434 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5435 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5438 prev = $3 as SpecialContraintExpr;
5440 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5441 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5443 prev = constraints [0] as SpecialContraintExpr;
5444 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5445 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5450 constraints.Add ((FullNamedExpression) $3);
5455 type_parameter_constraint
5458 if ($1 is ComposedCast)
5459 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5463 | NEW OPEN_PARENS CLOSE_PARENS
5465 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5466 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5470 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5474 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5478 opt_type_parameter_variance
5483 | type_parameter_variance
5485 if (lang_version <= LanguageVersion.V_3)
5486 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5492 type_parameter_variance
5495 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5499 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5508 // A block is "contained" on the following places:
5510 // property_declaration as part of the accessor body (get/set)
5511 // operator_declaration
5512 // constructor_declaration
5513 // destructor_declaration
5514 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5519 ++lexer.parsing_block;
5520 start_block (GetLocation ($1));
5522 opt_statement_list block_end
5531 --lexer.parsing_block;
5532 $$ = end_block (GetLocation ($1));
5534 | COMPLETE_COMPLETION
5536 --lexer.parsing_block;
5537 $$ = end_block (lexer.Location);
5545 ++lexer.parsing_block;
5546 current_block.StartLocation = GetLocation ($1);
5548 opt_statement_list CLOSE_BRACE
5550 --lexer.parsing_block;
5551 $$ = end_block (GetLocation ($4));
5562 | statement_list statement
5566 : block_variable_declaration
5568 current_block.AddStatement ((Statement) $1);
5570 | valid_declaration_statement
5572 current_block.AddStatement ((Statement) $1);
5577 Error_SyntaxError (yyToken);
5583 // The interactive_statement and its derivatives are only
5584 // used to provide a special version of `expression_statement'
5585 // that has a side effect of assigning the expression to
5588 interactive_statement_list
5589 : interactive_statement
5590 | interactive_statement_list interactive_statement
5593 interactive_statement
5594 : block_variable_declaration
5596 current_block.AddStatement ((Statement) $1);
5598 | interactive_valid_declaration_statement
5600 current_block.AddStatement ((Statement) $1);
5605 valid_declaration_statement
5608 | expression_statement
5609 | selection_statement
5610 | iteration_statement
5614 | unchecked_statement
5621 interactive_valid_declaration_statement
5624 | interactive_expression_statement
5625 | selection_statement
5626 | iteration_statement
5630 | unchecked_statement
5638 : valid_declaration_statement
5639 | block_variable_declaration
5641 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5646 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5651 Error_SyntaxError (yyToken);
5652 $$ = new EmptyStatement (GetLocation ($1));
5659 // Uses lexer.Location because semicolon location is not kept in quick mode
5660 $$ = new EmptyStatement (lexer.Location);
5665 : identifier_inside_body COLON
5667 var lt = (LocatedToken) $1;
5668 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5669 lbag.AddLocation (labeled, GetLocation ($2));
5670 current_block.AddLabel (labeled);
5671 current_block.AddStatement (labeled);
5677 : variable_type_simple
5678 | variable_type_simple rank_specifiers
5681 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5683 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5688 * The following is from Rhys' grammar:
5689 * > Types in local variable declarations must be recognized as
5690 * > expressions to prevent reduce/reduce errors in the grammar.
5691 * > The expressions are converted into types during semantic analysis.
5693 variable_type_simple
5694 : type_name_expression opt_nullable
5696 // Ok, the above "primary_expression" is there to get rid of
5697 // both reduce/reduce and shift/reduces in the grammar, it should
5698 // really just be "type_name". If you use type_name, a reduce/reduce
5699 // creeps up. If you use namespace_or_type_name (which is all we need
5700 // really) two shift/reduces appear.
5703 // So the super-trick is that primary_expression
5704 // can only be either a SimpleName or a MemberAccess.
5705 // The MemberAccess case arises when you have a fully qualified type-name like :
5707 // SimpleName is when you have
5710 var expr = (ATypeNameExpression) $1;
5712 if (expr.Name == "var" && expr is SimpleName)
5713 $$ = new VarExpr (expr.Location);
5717 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5720 | type_name_expression pointer_stars
5722 var expr = (ATypeNameExpression) $1;
5723 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5725 | builtin_type_expression
5731 | pointer_star pointer_stars
5733 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5741 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5745 identifier_inside_body
5749 $$ = Error_AwaitAsIdentifier ($1);
5753 block_variable_declaration
5754 : variable_type identifier_inside_body
5756 var lt = (LocatedToken) $2;
5757 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5758 current_block.AddLocalName (li);
5759 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5761 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5763 $$ = current_variable;
5764 current_variable = null;
5766 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5768 lbag.AddLocation ($$, GetLocation ($6));
5770 | CONST variable_type identifier_inside_body
5772 var lt = (LocatedToken) $3;
5773 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5774 current_block.AddLocalName (li);
5775 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5777 const_variable_initializer opt_const_declarators SEMICOLON
5779 $$ = current_variable;
5780 current_variable = null;
5781 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5785 opt_local_variable_initializer
5787 | ASSIGN block_variable_initializer
5789 current_variable.Initializer = (Expression) $2;
5790 PushLocation (GetLocation ($1));
5791 $$ = current_variable;
5795 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5796 report.Error (650, lexer.Location,
5797 "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");
5799 Error_SyntaxError (yyToken);
5804 opt_variable_declarators
5806 | variable_declarators
5809 opt_using_or_fixed_variable_declarators
5811 | variable_declarators
5813 foreach (var d in current_variable.Declarators) {
5814 if (d.Initializer == null)
5815 Error_MissingInitializer (d.Variable.Location);
5820 variable_declarators
5821 : variable_declarator
5822 | variable_declarators variable_declarator
5826 : COMMA identifier_inside_body
5828 var lt = (LocatedToken) $2;
5829 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5830 var d = new BlockVariableDeclarator (li, null);
5831 current_variable.AddDeclarator (d);
5832 current_block.AddLocalName (li);
5833 lbag.AddLocation (d, GetLocation ($1));
5835 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5837 var lt = (LocatedToken) $2;
5838 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5839 var d = new BlockVariableDeclarator (li, (Expression) $4);
5840 current_variable.AddDeclarator (d);
5841 current_block.AddLocalName (li);
5842 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5846 const_variable_initializer
5849 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5851 | ASSIGN constant_initializer_expr
5853 current_variable.Initializer = (Expression) $2;
5857 opt_const_declarators
5864 | const_declarators const_declarator
5868 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5870 var lt = (LocatedToken) $2;
5871 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5872 var d = new BlockVariableDeclarator (li, (Expression) $4);
5873 current_variable.AddDeclarator (d);
5874 current_block.AddLocalName (li);
5875 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5879 block_variable_initializer
5880 : variable_initializer
5881 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5883 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5884 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5886 | STACKALLOC simple_type
5888 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5889 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5893 expression_statement
5894 : statement_expression SEMICOLON
5897 lbag.AddStatement ($$, GetLocation ($2));
5899 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5900 | statement_expression CLOSE_BRACE
5903 report.Error (1002, GetLocation ($2), "; expected");
5904 lexer.putback ('}');
5908 interactive_expression_statement
5909 : interactive_statement_expression SEMICOLON { $$ = $1; }
5910 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5914 // We have to do the wrapping here and not in the case above,
5915 // because statement_expression is used for example in for_statement
5917 statement_expression
5920 ExpressionStatement s = $1 as ExpressionStatement;
5922 var expr = $1 as Expression;
5923 $$ = new StatementErrorExpression (expr);
5925 $$ = new StatementExpression (s);
5930 interactive_statement_expression
5933 Expression expr = (Expression) $1;
5934 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5938 Error_SyntaxError (yyToken);
5939 $$ = new EmptyStatement (GetLocation ($1));
5949 : IF open_parens_any boolean_expression CLOSE_PARENS
5952 if ($5 is EmptyStatement)
5953 Warning_EmptyStatement (GetLocation ($5));
5955 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5956 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5958 | IF open_parens_any boolean_expression CLOSE_PARENS
5959 embedded_statement ELSE embedded_statement
5961 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5962 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5964 if ($5 is EmptyStatement)
5965 Warning_EmptyStatement (GetLocation ($5));
5966 if ($7 is EmptyStatement)
5967 Warning_EmptyStatement (GetLocation ($7));
5969 | IF open_parens_any boolean_expression error
5971 Error_SyntaxError (yyToken);
5973 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5974 lbag.AddStatement ($$, GetLocation ($2));
5979 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5981 start_block (GetLocation ($5));
5983 opt_switch_sections CLOSE_BRACE
5985 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5986 end_block (GetLocation ($8));
5987 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5989 | SWITCH open_parens_any expression error
5991 Error_SyntaxError (yyToken);
5993 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5994 lbag.AddStatement ($$, GetLocation ($2));
6001 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6008 | switch_sections switch_section
6011 Error_SyntaxError (yyToken);
6016 : switch_labels statement_list
6022 var label = (SwitchLabel) $1;
6023 label.SectionStart = true;
6024 current_block.AddStatement (label);
6026 | switch_labels switch_label
6028 current_block.AddStatement ((Statement) $2);
6033 : CASE constant_expression COLON
6035 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6036 lbag.AddLocation ($$, GetLocation ($3));
6038 | CASE constant_expression error
6040 Error_SyntaxError (yyToken);
6041 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6044 | CASE pattern_expr_invocation COLON
6046 if (lang_version != LanguageVersion.Experimental)
6047 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6049 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6050 PatternMatching = true
6052 lbag.AddLocation ($$, GetLocation ($3));
6057 $$ = new SwitchLabel (null, GetLocation ($1));
6069 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6071 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6072 Warning_EmptyStatement (GetLocation ($5));
6074 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6075 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6077 | WHILE open_parens_any boolean_expression error
6079 Error_SyntaxError (yyToken);
6081 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6082 lbag.AddStatement ($$, GetLocation ($2));
6087 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6089 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6090 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6092 | DO embedded_statement error
6094 Error_SyntaxError (yyToken);
6095 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6097 | DO embedded_statement WHILE open_parens_any boolean_expression error
6099 Error_SyntaxError (yyToken);
6101 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6102 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6107 : FOR open_parens_any
6109 start_block (GetLocation ($2));
6110 current_block.IsCompilerGenerated = true;
6111 For f = new For (GetLocation ($1));
6112 current_block.AddStatement (f);
6121 // Has to use be extra rule to recover started block
6123 : opt_for_initializer SEMICOLON
6125 ((For) $0).Initializer = (Statement) $1;
6127 // Pass the "For" object to the iterator_part4
6128 oob_stack.Push ($0);
6130 for_condition_and_iterator_part
6133 var locations = (Tuple<Location,Location>) $4;
6135 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6136 Warning_EmptyStatement (GetLocation ($5));
6139 f.Statement = (Statement) $5;
6140 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6142 $$ = end_block (GetLocation ($2));
6146 Error_SyntaxError (yyToken);
6147 $$ = end_block (current_block.StartLocation);
6151 for_condition_and_iterator_part
6152 : opt_for_condition SEMICOLON
6154 For f = (For) oob_stack.Peek ();
6155 f.Condition = (BooleanExpression) $1;
6158 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6161 // Handle errors in the case of opt_for_condition being followed by
6162 // a close parenthesis
6163 | opt_for_condition close_parens_close_brace {
6164 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6165 For f = (For) oob_stack.Peek ();
6166 f.Condition = (BooleanExpression) $1;
6167 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6172 : opt_for_iterator CLOSE_PARENS {
6173 For f = (For) oob_stack.Peek ();
6174 f.Iterator = (Statement) $1;
6175 $$ = GetLocation ($2);
6177 | opt_for_iterator CLOSE_BRACE {
6178 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6179 For f = (For) oob_stack.Peek ();
6180 f.Iterator = (Statement) $1;
6181 $$ = GetLocation ($2);
6185 close_parens_close_brace
6187 | CLOSE_BRACE { lexer.putback ('}'); }
6191 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6196 : variable_type identifier_inside_body
6198 var lt = (LocatedToken) $2;
6199 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6200 current_block.AddLocalName (li);
6201 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6203 opt_local_variable_initializer opt_variable_declarators
6205 $$ = current_variable;
6207 lbag.AddLocation (current_variable, PopLocation ());
6209 current_variable = null;
6211 | statement_expression_list
6215 : /* empty */ { $$ = null; }
6216 | boolean_expression
6220 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6225 : statement_expression_list
6228 statement_expression_list
6229 : statement_expression
6230 | statement_expression_list COMMA statement_expression
6232 var sl = $1 as StatementList;
6234 sl = new StatementList ((Statement) $1, (Statement) $3);
6235 lbag.AddStatement (sl, GetLocation ($2));
6237 sl.Add ((Statement) $3);
6238 lbag.AppendTo (sl, GetLocation ($2));
6246 : FOREACH open_parens_any type error
6248 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6250 start_block (GetLocation ($2));
6251 current_block.IsCompilerGenerated = true;
6253 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6254 current_block.AddStatement (f);
6256 lbag.AddStatement (f, GetLocation ($2));
6257 $$ = end_block (GetLocation ($4));
6259 | FOREACH open_parens_any type identifier_inside_body error
6261 Error_SyntaxError (yyToken);
6263 start_block (GetLocation ($2));
6264 current_block.IsCompilerGenerated = true;
6266 var lt = (LocatedToken) $4;
6267 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6268 current_block.AddLocalName (li);
6270 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6271 current_block.AddStatement (f);
6273 lbag.AddStatement (f, GetLocation ($2));
6274 $$ = end_block (GetLocation ($5));
6276 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6278 start_block (GetLocation ($2));
6279 current_block.IsCompilerGenerated = true;
6281 var lt = (LocatedToken) $4;
6282 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6283 current_block.AddLocalName (li);
6288 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6289 Warning_EmptyStatement (GetLocation ($9));
6291 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6292 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6293 end_block (GetLocation ($7));
6301 | continue_statement
6311 $$ = new Break (GetLocation ($1));
6312 lbag.AddStatement ($$, GetLocation ($2));
6317 : CONTINUE SEMICOLON
6319 $$ = new Continue (GetLocation ($1));
6320 lbag.AddStatement ($$, GetLocation ($2));
6324 Error_SyntaxError (yyToken);
6325 $$ = new Continue (GetLocation ($1));
6330 : GOTO identifier_inside_body SEMICOLON
6332 var lt = (LocatedToken) $2;
6333 $$ = new Goto (lt.Value, GetLocation ($1));
6334 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6336 | GOTO CASE constant_expression SEMICOLON
6338 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6339 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6341 | GOTO DEFAULT SEMICOLON
6343 $$ = new GotoDefault (GetLocation ($1));
6344 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6349 : RETURN opt_expression SEMICOLON
6351 $$ = new Return ((Expression) $2, GetLocation ($1));
6352 lbag.AddStatement ($$, GetLocation ($3));
6354 | RETURN expression error
6356 Error_SyntaxError (yyToken);
6357 $$ = new Return ((Expression) $2, GetLocation ($1));
6361 Error_SyntaxError (yyToken);
6362 $$ = new Return (null, GetLocation ($1));
6367 : THROW expression SEMICOLON
6369 $$ = new Throw ((Expression) $2, GetLocation ($1));
6370 lbag.AddStatement ($$, GetLocation ($3));
6374 $$ = new Throw (null, GetLocation ($1));
6375 lbag.AddStatement ($$, GetLocation ($2));
6377 | THROW expression error
6379 Error_SyntaxError (yyToken);
6380 $$ = new Throw ((Expression) $2, GetLocation ($1));
6384 Error_SyntaxError (yyToken);
6385 $$ = new Throw (null, GetLocation ($1));
6390 : identifier_inside_body RETURN opt_expression SEMICOLON
6392 var lt = (LocatedToken) $1;
6393 string s = lt.Value;
6395 report.Error (1003, lt.Location, "; expected");
6396 } else if ($3 == null) {
6397 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6398 } else if (lang_version == LanguageVersion.ISO_1){
6399 FeatureIsNotAvailable (lt.Location, "iterators");
6402 current_block.Explicit.RegisterIteratorYield ();
6403 $$ = new Yield ((Expression) $3, lt.Location);
6404 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6406 | identifier_inside_body RETURN expression error
6408 Error_SyntaxError (yyToken);
6410 var lt = (LocatedToken) $1;
6411 string s = lt.Value;
6413 report.Error (1003, lt.Location, "; expected");
6414 } else if ($3 == null) {
6415 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6416 } else if (lang_version == LanguageVersion.ISO_1){
6417 FeatureIsNotAvailable (lt.Location, "iterators");
6420 current_block.Explicit.RegisterIteratorYield ();
6421 $$ = new Yield ((Expression) $3, lt.Location);
6422 lbag.AddStatement ($$, GetLocation ($2));
6424 | identifier_inside_body BREAK SEMICOLON
6426 var lt = (LocatedToken) $1;
6427 string s = lt.Value;
6429 report.Error (1003, lt.Location, "; expected");
6430 } else if (lang_version == LanguageVersion.ISO_1){
6431 FeatureIsNotAvailable (lt.Location, "iterators");
6434 current_block.ParametersBlock.TopBlock.IsIterator = true;
6435 $$ = new YieldBreak (lt.Location);
6436 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6446 : TRY block catch_clauses
6448 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6450 | TRY block FINALLY block
6452 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6453 lbag.AddStatement ($$, GetLocation ($3));
6455 | TRY block catch_clauses FINALLY block
6457 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6458 lbag.AddStatement ($$, GetLocation ($4));
6462 Error_SyntaxError (1524, yyToken);
6463 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6470 var l = new List<Catch> (2);
6475 | catch_clauses catch_clause
6477 var l = (List<Catch>) $1;
6479 Catch c = (Catch) $2;
6480 var prev_catch = l [l.Count - 1];
6481 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6482 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6492 | identifier_inside_body
6496 : CATCH opt_catch_filter block
6498 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6499 c.Filter = (CatchFilterExpression) $2;
6502 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6504 start_block (GetLocation ($2));
6505 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6506 c.TypeExpression = (FullNamedExpression) $3;
6509 var lt = (LocatedToken) $4;
6510 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6511 current_block.AddLocalName (c.Variable);
6514 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6516 lexer.parsing_catch_when = true;
6518 opt_catch_filter_or_error
6520 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6523 | CATCH open_parens_any error
6525 if (yyToken == Token.CLOSE_PARENS) {
6526 report.Error (1015, lexer.Location,
6527 "A type that derives from `System.Exception', `object', or `string' expected");
6529 Error_SyntaxError (yyToken);
6532 $$ = new Catch (null, GetLocation ($1));
6536 opt_catch_filter_or_error
6537 : opt_catch_filter block_prepared
6543 end_block (Location.Null);
6544 Error_SyntaxError (yyToken);
6551 lexer.parsing_catch_when = false;
6555 lexer.parsing_catch_when = false;
6557 open_parens_any expression CLOSE_PARENS
6559 if (lang_version <= LanguageVersion.V_5)
6560 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6562 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6563 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6570 $$ = new Checked ((Block) $2, GetLocation ($1));
6577 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6584 if (!settings.Unsafe)
6585 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6587 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6592 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6594 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6595 Warning_EmptyStatement (GetLocation ($5));
6597 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6598 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6600 | LOCK open_parens_any expression error
6602 Error_SyntaxError (yyToken);
6604 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6605 lbag.AddStatement ($$, GetLocation ($2));
6610 : FIXED open_parens_any variable_type identifier_inside_body
6612 start_block (GetLocation ($2));
6614 current_block.IsCompilerGenerated = true;
6615 var lt = (LocatedToken) $4;
6616 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6617 current_block.AddLocalName (li);
6618 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6620 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6622 $$ = current_variable;
6623 current_variable = null;
6627 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6628 Warning_EmptyStatement (GetLocation ($10));
6630 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6631 current_block.AddStatement (f);
6632 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6633 $$ = end_block (GetLocation ($8));
6638 : USING open_parens_any variable_type identifier_inside_body
6640 start_block (GetLocation ($2));
6642 current_block.IsCompilerGenerated = true;
6643 var lt = (LocatedToken) $4;
6644 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6645 current_block.AddLocalName (li);
6646 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6648 using_initialization CLOSE_PARENS
6650 $$ = current_variable;
6651 current_variable = null;
6655 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6656 Warning_EmptyStatement (GetLocation ($9));
6658 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6659 current_block.AddStatement (u);
6660 $$ = end_block (GetLocation ($7));
6662 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6664 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6665 Warning_EmptyStatement (GetLocation ($5));
6667 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6668 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6670 | USING open_parens_any expression error
6672 Error_SyntaxError (yyToken);
6674 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6675 lbag.AddStatement ($$, GetLocation ($2));
6679 using_initialization
6680 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6683 // It has to be here for the parent to safely restore artificial block
6684 Error_SyntaxError (yyToken);
6688 using_or_fixed_variable_initializer
6691 Error_MissingInitializer (lexer.Location);
6693 | ASSIGN variable_initializer
6695 current_variable.Initializer = (Expression) $2;
6696 $$ = current_variable;
6704 : first_from_clause query_body
6706 lexer.query_parsing = false;
6708 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6710 from.Tail.Next = (Linq.AQueryClause)$2;
6713 current_block.SetEndLocation (lexer.Location);
6714 current_block = current_block.Parent;
6716 | nested_from_clause query_body
6718 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6720 from.Tail.Next = (Linq.AQueryClause)$2;
6723 current_block.SetEndLocation (lexer.Location);
6724 current_block = current_block.Parent;
6727 // Bubble up COMPLETE_COMPLETION productions
6728 | first_from_clause COMPLETE_COMPLETION {
6729 lexer.query_parsing = false;
6732 current_block.SetEndLocation (lexer.Location);
6733 current_block = current_block.Parent;
6735 | nested_from_clause COMPLETE_COMPLETION {
6737 current_block.SetEndLocation (lexer.Location);
6738 current_block = current_block.Parent;
6743 : FROM_FIRST identifier_inside_body IN expression
6745 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6747 var lt = (LocatedToken) $2;
6748 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6749 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6750 lbag.AddLocation (clause, GetLocation ($3));
6751 $$ = new Linq.QueryExpression (clause);
6753 | FROM_FIRST type identifier_inside_body IN expression
6755 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6757 var lt = (LocatedToken) $3;
6758 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6759 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6760 IdentifierType = (FullNamedExpression)$2
6762 lbag.AddLocation (clause, GetLocation ($4));
6763 $$ = new Linq.QueryExpression (clause);
6768 : FROM identifier_inside_body IN expression
6770 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6772 var lt = (LocatedToken) $2;
6773 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6774 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6775 lbag.AddLocation (clause, GetLocation ($3));
6776 $$ = new Linq.QueryExpression (clause);
6778 | FROM type identifier_inside_body IN expression
6780 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6782 var lt = (LocatedToken) $3;
6783 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6784 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6785 IdentifierType = (FullNamedExpression)$2
6787 lbag.AddLocation (clause, GetLocation ($4));
6788 $$ = new Linq.QueryExpression (clause);
6793 : FROM identifier_inside_body IN
6795 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6799 var lt = (LocatedToken) $2;
6800 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6801 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6803 current_block.SetEndLocation (lexer.Location);
6804 current_block = current_block.Parent;
6806 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6807 lbag.AddLocation ($$, GetLocation ($3));
6809 | FROM type identifier_inside_body IN
6811 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6815 var lt = (LocatedToken) $3;
6816 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6818 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6819 IdentifierType = (FullNamedExpression)$2
6822 current_block.SetEndLocation (lexer.Location);
6823 current_block = current_block.Parent;
6825 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6827 lbag.AddLocation ($$, GetLocation ($4));
6832 : query_body_clauses select_or_group_clause opt_query_continuation
6834 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6837 head.Next = (Linq.AQueryClause)$3;
6840 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6841 clause.Tail.Next = head;
6847 | select_or_group_clause opt_query_continuation
6849 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6852 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6853 clause.Tail.Next = head;
6859 | query_body_clauses COMPLETE_COMPLETION
6860 | query_body_clauses error
6862 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6867 Error_SyntaxError (yyToken);
6872 select_or_group_clause
6875 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6879 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6881 current_block.SetEndLocation (lexer.Location);
6882 current_block = current_block.Parent;
6886 if (linq_clause_blocks == null)
6887 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6889 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6890 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6894 current_block.SetEndLocation (lexer.Location);
6895 current_block = current_block.Parent;
6897 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6901 var obj = (object[]) $5;
6903 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6904 lbag.AddLocation ($$, (Location) obj[1]);
6906 current_block.SetEndLocation (lexer.Location);
6907 current_block = current_block.Parent;
6912 : BY expression_or_error
6914 $$ = new object[] { $2, GetLocation ($1) };
6918 Error_SyntaxError (yyToken);
6919 $$ = new object[2] { null, Location.Null };
6925 | query_body_clauses query_body_clause
6927 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6941 : LET identifier_inside_body ASSIGN
6943 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6947 var lt = (LocatedToken) $2;
6948 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6949 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6950 lbag.AddLocation ($$, GetLocation ($3));
6952 current_block.SetEndLocation (lexer.Location);
6953 current_block = current_block.Parent;
6955 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6962 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6966 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6968 current_block.SetEndLocation (lexer.Location);
6969 current_block = current_block.Parent;
6974 : JOIN identifier_inside_body IN
6976 if (linq_clause_blocks == null)
6977 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6979 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6980 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6982 expression_or_error ON
6984 current_block.SetEndLocation (lexer.Location);
6985 current_block = current_block.Parent;
6987 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6988 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6990 expression_or_error EQUALS
6992 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6993 current_block.SetEndLocation (lexer.Location);
6994 current_block = current_block.Parent;
6996 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6998 expression_or_error opt_join_into
7000 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7001 current_block.SetEndLocation (lexer.Location);
7003 var outer_selector = linq_clause_blocks.Pop ();
7004 var block = linq_clause_blocks.Pop ();
7006 var lt = (LocatedToken) $2;
7007 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7008 Linq.RangeVariable into;
7012 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7013 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7016 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7018 var parent = block.Parent;
7019 while (parent is Linq.QueryBlock) {
7020 parent = parent.Parent;
7022 current_block.Parent = parent;
7024 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7026 lt = (LocatedToken) $12;
7027 into = new Linq.RangeVariable (lt.Value, lt.Location);
7029 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7030 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7033 current_block = block.Parent;
7034 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7036 | JOIN type identifier_inside_body IN
7038 if (linq_clause_blocks == null)
7039 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7041 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7042 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7044 expression_or_error ON
7046 current_block.SetEndLocation (lexer.Location);
7047 current_block = current_block.Parent;
7049 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7050 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7052 expression_or_error EQUALS
7054 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7055 current_block.SetEndLocation (lexer.Location);
7056 current_block = current_block.Parent;
7058 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7060 expression_or_error opt_join_into
7062 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7063 current_block.SetEndLocation (lexer.Location);
7065 var outer_selector = linq_clause_blocks.Pop ();
7066 var block = linq_clause_blocks.Pop ();
7068 var lt = (LocatedToken) $3;
7069 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7070 Linq.RangeVariable into;
7074 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7075 IdentifierType = (FullNamedExpression)$2
7077 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7080 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7082 var parent = block.Parent;
7083 while (parent is Linq.QueryBlock) {
7084 parent = parent.Parent;
7086 current_block.Parent = parent;
7088 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7090 lt = (LocatedToken) $13;
7091 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7093 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7094 IdentifierType = (FullNamedExpression)$2
7098 current_block = block.Parent;
7099 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7105 | INTO identifier_inside_body
7114 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7118 current_block.SetEndLocation (lexer.Location);
7119 current_block = current_block.Parent;
7129 current_block.SetEndLocation (lexer.Location);
7130 current_block = current_block.Parent;
7132 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7136 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7143 | orderings_then_by COMMA
7145 current_block.SetEndLocation (lexer.Location);
7146 current_block = current_block.Parent;
7148 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7152 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7160 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7162 | expression ASCENDING
7164 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7165 lbag.AddLocation ($$, GetLocation ($2));
7167 | expression DESCENDING
7169 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7170 lbag.AddLocation ($$, GetLocation ($2));
7177 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7179 | expression ASCENDING
7181 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7182 lbag.AddLocation ($$, GetLocation ($2));
7184 | expression DESCENDING
7186 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7187 lbag.AddLocation ($$, GetLocation ($2));
7192 opt_query_continuation
7194 | INTO identifier_inside_body
7196 // query continuation block is not linked with query block but with block
7197 // before. This means each query can use same range variable names for
7198 // different identifiers.
7200 current_block.SetEndLocation (GetLocation ($1));
7201 current_block = current_block.Parent;
7203 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7205 if (linq_clause_blocks == null)
7206 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7208 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7212 var current_block = linq_clause_blocks.Pop ();
7213 var lt = (LocatedToken) $2;
7214 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7215 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7216 next = (Linq.AQueryClause)$4
7222 // Support for using the compiler as an interactive parser
7224 // The INTERACTIVE_PARSER token is first sent to parse our
7225 // productions; If the result is a Statement, the parsing
7226 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7227 // to setup the blocks in advance.
7229 // This setup is here so that in the future we can add
7230 // support for other constructs (type parsing, namespaces, etc)
7231 // that do not require a block to be setup in advance
7235 : EVAL_STATEMENT_PARSER EOF
7236 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7237 | EVAL_STATEMENT_PARSER
7239 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7241 // (ref object retval)
7242 Parameter [] mpar = new Parameter [1];
7243 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7245 ParametersCompiled pars = new ParametersCompiled (mpar);
7246 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7247 if (settings.Unsafe)
7248 mods |= Modifiers.UNSAFE;
7250 current_local_parameters = pars;
7251 var method = new InteractiveMethod (
7253 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7257 current_type.AddMember (method);
7258 oob_stack.Push (method);
7260 interactive_async = false;
7262 ++lexer.parsing_block;
7263 start_block (lexer.Location);
7265 interactive_statement_list opt_COMPLETE_COMPLETION
7267 --lexer.parsing_block;
7268 var method = (InteractiveMethod) oob_stack.Pop ();
7269 method.Block = (ToplevelBlock) end_block(lexer.Location);
7271 if (interactive_async == true) {
7272 method.ChangeToAsync ();
7275 InteractiveResult = (Class) pop_current_class ();
7276 current_local_parameters = null;
7278 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7281 interactive_compilation_unit
7282 : opt_extern_alias_directives opt_using_directives
7283 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7286 opt_COMPLETE_COMPLETION
7288 | COMPLETE_COMPLETION
7291 close_brace_or_complete_completion
7293 | COMPLETE_COMPLETION
7297 // XML documentation code references micro parser
7299 documentation_parsing
7302 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7307 : doc_type_declaration_name opt_doc_method_sig
7309 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7311 | builtin_types opt_doc_method_sig
7313 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7314 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7317 | VOID opt_doc_method_sig
7319 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7320 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7323 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7325 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7326 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7327 var lt = (LocatedToken) $3;
7328 $$ = new MemberName (lt.Value);
7330 | doc_type_declaration_name DOT THIS
7332 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7334 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7336 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7338 opt_doc_parameters CLOSE_BRACKET
7340 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7341 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7343 | EXPLICIT OPERATOR type opt_doc_method_sig
7345 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7346 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7347 module.DocumentationBuilder.ParsedParameters = p;
7348 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7351 | IMPLICIT OPERATOR type opt_doc_method_sig
7353 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7354 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7355 module.DocumentationBuilder.ParsedParameters = p;
7356 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7359 | OPERATOR overloadable_operator opt_doc_method_sig
7361 var p = (List<DocumentationParameter>)$3;
7362 module.DocumentationBuilder.ParsedParameters = p;
7363 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7368 doc_type_declaration_name
7369 : type_declaration_name
7370 | doc_type_declaration_name DOT type_declaration_name
7372 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7380 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7382 opt_doc_parameters CLOSE_PARENS
7391 $$ = new List<DocumentationParameter> (0);
7399 var parameters = new List<DocumentationParameter> ();
7400 parameters.Add ((DocumentationParameter) $1);
7403 | doc_parameters COMMA doc_parameter
7405 var parameters = $1 as List<DocumentationParameter>;
7406 parameters.Add ((DocumentationParameter) $3);
7412 : opt_parameter_modifier parameter_type
7415 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7417 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7424 // A class used to hold info about an operator declarator
7426 class OperatorDeclaration {
7427 public readonly Operator.OpType optype;
7428 public readonly FullNamedExpression ret_type;
7429 public readonly Location location;
7431 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7434 this.ret_type = ret_type;
7435 this.location = location;
7439 void Error_ExpectingTypeName (Expression expr)
7441 if (expr is Invocation){
7442 report.Error (1002, expr.Location, "Expecting `;'");
7444 expr.Error_InvalidExpressionStatement (report);
7448 void Error_ParameterModifierNotValid (string modifier, Location loc)
7450 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7454 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7456 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7457 Parameter.GetModifierSignature (mod));
7460 void Error_TypeExpected (Location loc)
7462 report.Error (1031, loc, "Type expected");
7465 void Error_UnsafeCodeNotAllowed (Location loc)
7467 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7470 void Warning_EmptyStatement (Location loc)
7472 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7475 void Error_NamedArgumentExpected (NamedArgument a)
7477 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7480 void Error_MissingInitializer (Location loc)
7482 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7485 object Error_AwaitAsIdentifier (object token)
7488 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7489 return new LocatedToken ("await", GetLocation (token));
7495 void push_current_container (TypeDefinition tc, object partial_token)
7497 if (module.Evaluator != null){
7498 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7502 undo.AddTypeContainer (current_container, tc);
7505 if (partial_token != null)
7506 current_container.AddPartial (tc);
7508 current_container.AddTypeContainer (tc);
7510 ++lexer.parsing_declaration;
7511 current_container = tc;
7515 TypeContainer pop_current_class ()
7517 var retval = current_container;
7519 current_container = current_container.Parent;
7520 current_type = current_type.Parent as TypeDefinition;
7525 [System.Diagnostics.Conditional ("FULL_AST")]
7526 void StoreModifierLocation (object token, Location loc)
7531 if (mod_locations == null)
7532 mod_locations = new List<Tuple<Modifiers, Location>> ();
7534 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7537 [System.Diagnostics.Conditional ("FULL_AST")]
7538 void PushLocation (Location loc)
7540 if (location_stack == null)
7541 location_stack = new Stack<Location> ();
7543 location_stack.Push (loc);
7546 Location PopLocation ()
7548 if (location_stack == null)
7549 return Location.Null;
7551 return location_stack.Pop ();
7554 string CheckAttributeTarget (int token, string a, Location l)
7557 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7561 if (!Tokenizer.IsValidIdentifier (a)) {
7562 Error_SyntaxError (token);
7564 report.Warning (658, 1, l,
7565 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7568 return string.Empty;
7571 static bool IsUnaryOperator (Operator.OpType op)
7575 case Operator.OpType.LogicalNot:
7576 case Operator.OpType.OnesComplement:
7577 case Operator.OpType.Increment:
7578 case Operator.OpType.Decrement:
7579 case Operator.OpType.True:
7580 case Operator.OpType.False:
7581 case Operator.OpType.UnaryPlus:
7582 case Operator.OpType.UnaryNegation:
7588 void syntax_error (Location l, string msg)
7590 report.Error (1003, l, "Syntax error, " + msg);
7595 public Tokenizer Lexer {
7601 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7602 : this (reader, file, file.Compiler.Report, session)
7606 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7609 current_container = current_namespace = file;
7611 this.module = file.Module;
7612 this.compiler = file.Compiler;
7613 this.settings = compiler.Settings;
7614 this.report = report;
7616 lang_version = settings.Version;
7617 yacc_verbose_flag = settings.VerboseParserFlag;
7618 doc_support = settings.DocumentationFile != null;
7619 lexer = new Tokenizer (reader, file, session, report);
7620 oob_stack = new Stack<object> ();
7621 lbag = session.LocationsBag;
7622 use_global_stacks = session.UseJayGlobalArrays;
7623 parameters_bucket = session.ParametersStack;
7626 public void parse ()
7628 eof_token = Token.EOF;
7631 if (yacc_verbose_flag > 1)
7632 yyparse (lexer, new yydebug.yyDebugSimple ());
7636 Tokenizer tokenizer = lexer as Tokenizer;
7637 tokenizer.cleanup ();
7638 } catch (Exception e){
7639 if (e is yyParser.yyUnexpectedEof) {
7640 Error_SyntaxError (yyToken);
7641 UnexpectedEOF = true;
7645 if (e is yyParser.yyException) {
7646 if (report.Errors == 0)
7647 report.Error (-25, lexer.Location, "Parsing error");
7649 // Used by compiler-tester to test internal errors
7650 if (yacc_verbose_flag > 0 || e is FatalException)
7653 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7658 void CheckToken (int error, int yyToken, string msg, Location loc)
7660 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7661 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7663 report.Error (error, loc, msg);
7666 string ConsumeStoredComment ()
7668 string s = tmpComment;
7670 Lexer.doc_state = XmlCommentState.Allowed;
7674 void FeatureIsNotAvailable (Location loc, string feature)
7676 report.FeatureIsNotAvailable (compiler, loc, feature);
7679 Location GetLocation (object obj)
7681 var lt = obj as LocatedToken;
7685 var mn = obj as MemberName;
7689 var expr = obj as Expression;
7691 return expr.Location;
7693 return lexer.Location;
7696 void start_block (Location loc)
7698 if (current_block == null) {
7699 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7700 parsing_anonymous_method = false;
7701 } else if (parsing_anonymous_method) {
7702 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7703 parsing_anonymous_method = false;
7705 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7709 Block end_block (Location loc)
7711 Block retval = current_block.Explicit;
7712 retval.SetEndLocation (loc);
7713 current_block = retval.Parent;
7717 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7719 oob_stack.Push (current_anonymous_method);
7720 oob_stack.Push (current_local_parameters);
7721 oob_stack.Push (current_variable);
7722 oob_stack.Push (async_block);
7724 current_local_parameters = parameters;
7726 if (lang_version <= LanguageVersion.ISO_2)
7727 FeatureIsNotAvailable (loc, "lambda expressions");
7729 current_anonymous_method = new LambdaExpression (loc);
7731 if (lang_version == LanguageVersion.ISO_1)
7732 FeatureIsNotAvailable (loc, "anonymous methods");
7734 current_anonymous_method = new AnonymousMethodExpression (loc);
7737 async_block = isAsync;
7738 // Force the next block to be created as a ToplevelBlock
7739 parsing_anonymous_method = true;
7743 * Completes the anonymous method processing, if lambda_expr is null, this
7744 * means that we have a Statement instead of an Expression embedded
7746 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7748 AnonymousMethodExpression retval;
7751 anon_block.IsAsync = true;
7753 current_anonymous_method.Block = anon_block;
7754 retval = current_anonymous_method;
7756 async_block = (bool) oob_stack.Pop ();
7757 current_variable = (BlockVariable) oob_stack.Pop ();
7758 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7759 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7764 void Error_SyntaxError (int token)
7766 Error_SyntaxError (0, token);
7769 void Error_SyntaxError (int error_code, int token)
7771 Error_SyntaxError (error_code, token, "Unexpected symbol");
7774 void Error_SyntaxError (int error_code, int token, string msg)
7776 Lexer.CompleteOnEOF = false;
7778 // An error message has been reported by tokenizer
7779 if (token == Token.ERROR)
7782 // Avoid duplicit error message after unterminated string literals
7783 if (token == Token.LITERAL && lexer.Location.Column == 0)
7786 string symbol = GetSymbolName (token);
7787 string expecting = GetExpecting ();
7788 var loc = lexer.Location - symbol.Length;
7790 if (error_code == 0) {
7791 if (expecting == "`identifier'") {
7792 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7793 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7798 expecting = "identifier";
7799 } else if (expecting == "`)'") {
7806 if (string.IsNullOrEmpty (expecting))
7807 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7809 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7812 string GetExpecting ()
7814 int [] tokens = yyExpectingTokens (yyExpectingState);
7815 var names = new List<string> (tokens.Length);
7816 bool has_type = false;
7817 bool has_identifier = false;
7818 for (int i = 0; i < tokens.Length; i++){
7819 int token = tokens [i];
7820 has_identifier |= token == Token.IDENTIFIER;
7822 string name = GetTokenName (token);
7823 if (name == "<internal>")
7826 has_type |= name == "type";
7827 if (names.Contains (name))
7834 // Too many tokens to enumerate
7836 if (names.Count > 8)
7839 if (has_type && has_identifier)
7840 names.Remove ("identifier");
7842 if (names.Count == 1)
7843 return "`" + GetTokenName (tokens [0]) + "'";
7845 StringBuilder sb = new StringBuilder ();
7847 int count = names.Count;
7848 for (int i = 0; i < count; i++){
7849 bool last = i + 1 == count;
7853 sb.Append (names [i]);
7854 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7856 return sb.ToString ();
7860 string GetSymbolName (int token)
7864 return ((Constant)lexer.Value).GetValue ().ToString ();
7865 case Token.IDENTIFIER:
7866 return ((LocatedToken)lexer.Value).Value;
7908 case Token.BITWISE_AND:
7910 case Token.BITWISE_OR:
7924 case Token.OP_SHIFT_LEFT:
7926 case Token.OP_SHIFT_RIGHT:
7946 case Token.OP_COALESCING:
7948 case Token.OP_MULT_ASSIGN:
7950 case Token.OP_DIV_ASSIGN:
7952 case Token.OP_MOD_ASSIGN:
7954 case Token.OP_ADD_ASSIGN:
7956 case Token.OP_SUB_ASSIGN:
7958 case Token.OP_SHIFT_LEFT_ASSIGN:
7960 case Token.OP_SHIFT_RIGHT_ASSIGN:
7962 case Token.OP_AND_ASSIGN:
7964 case Token.OP_XOR_ASSIGN:
7966 case Token.OP_OR_ASSIGN:
7970 return GetTokenName (token);
7973 static string GetTokenName (int token)
7976 case Token.ABSTRACT:
7998 case Token.CONTINUE:
8002 case Token.DELEGATE:
8012 case Token.EXPLICIT:
8015 case Token.EXTERN_ALIAS:
8031 case Token.IMPLICIT:
8035 case Token.INTERFACE:
8037 case Token.INTERNAL:
8043 case Token.NAMESPACE:
8049 case Token.OPERATOR:
8053 case Token.OVERRIDE:
8059 case Token.PROTECTED:
8063 case Token.READONLY:
8075 case Token.STACKALLOC:
8076 return "stackalloc";
8086 case Token.THROW_EXPR:
8094 case Token.UNCHECKED:
8102 case Token.VOLATILE:
8110 case Token.REFVALUE:
8111 return "__refvalue";
8121 case Token.FROM_FIRST:
8139 case Token.ASCENDING:
8141 case Token.DESCENDING:
8142 return "descending";
8149 case Token.OPEN_BRACE:
8151 case Token.CLOSE_BRACE:
8153 case Token.OPEN_BRACKET:
8154 case Token.OPEN_BRACKET_EXPR:
8156 case Token.CLOSE_BRACKET:
8158 case Token.OPEN_PARENS_CAST:
8159 case Token.OPEN_PARENS_LAMBDA:
8160 case Token.OPEN_PARENS:
8162 case Token.CLOSE_PARENS:
8168 case Token.DEFAULT_COLON:
8172 case Token.SEMICOLON:
8178 case Token.INTERPOLATED_STRING_END:
8180 case Token.INTERPOLATED_STRING:
8189 case Token.BITWISE_AND:
8190 case Token.BITWISE_OR:
8197 case Token.OP_SHIFT_LEFT:
8198 case Token.OP_SHIFT_RIGHT:
8206 case Token.OP_COALESCING:
8207 case Token.OP_MULT_ASSIGN:
8208 case Token.OP_DIV_ASSIGN:
8209 case Token.OP_MOD_ASSIGN:
8210 case Token.OP_ADD_ASSIGN:
8211 case Token.OP_SUB_ASSIGN:
8212 case Token.OP_SHIFT_LEFT_ASSIGN:
8213 case Token.OP_SHIFT_RIGHT_ASSIGN:
8214 case Token.OP_AND_ASSIGN:
8215 case Token.OP_XOR_ASSIGN:
8216 case Token.OP_OR_ASSIGN:
8217 case Token.INTERR_OPERATOR:
8218 return "<operator>";
8240 case Token.OP_GENERICS_LT:
8241 case Token.GENERIC_DIMENSION:
8243 case Token.OP_GENERICS_GT:
8246 case Token.INTERR_NULLABLE:
8248 case Token.DOUBLE_COLON:
8252 case Token.IDENTIFIER:
8254 return "identifier";
8257 return "end-of-file";
8259 // All of these are internal.
8262 case Token.FIRST_KEYWORD:
8263 case Token.EVAL_COMPILATION_UNIT_PARSER:
8264 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8265 case Token.EVAL_STATEMENT_PARSER:
8266 case Token.LAST_KEYWORD:
8267 case Token.GENERATE_COMPLETION:
8268 case Token.COMPLETE_COMPLETION:
8269 return "<internal>";
8271 // A bit more robust.
8273 return yyNames [token];