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
265 /* C# keywords which are not really keywords */
271 /* C# single character operators/punctuation. */
299 /* C# multi-character operators. */
304 %token OP_SHIFT_RIGHT
311 %token OP_MULT_ASSIGN
316 %token OP_SHIFT_LEFT_ASSIGN
317 %token OP_SHIFT_RIGHT_ASSIGN
324 /* Generics <,> tokens */
325 %token OP_GENERICS_LT
326 %token OP_GENERICS_LT_DECL
327 %token OP_GENERICS_GT
332 %token OPEN_PARENS_LAMBDA
333 %token OPEN_PARENS_CAST
334 %token GENERIC_DIMENSION
336 %token OPEN_BRACKET_EXPR
338 // Make the parser go into eval mode parsing (statements and compilation units).
339 %token EVAL_STATEMENT_PARSER
340 %token EVAL_COMPILATION_UNIT_PARSER
341 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
346 // This token is generated to trigger the completion engine at this point
348 %token GENERATE_COMPLETION
351 // This token is return repeatedly after the first GENERATE_COMPLETION
352 // token is produced and before the final EOF
354 %token COMPLETE_COMPLETION
356 /* Add precedence rules to solve dangling else s/r conflict */
360 /* Define the operator tokens and their precedences */
368 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
370 %left STAR DIV PERCENT
371 %right BANG CARRET UMINUS
372 %nonassoc OP_INC OP_DEC
374 %left OPEN_BRACKET OPEN_BRACE
377 %start compilation_unit
381 : outer_declaration opt_EOF
383 Lexer.check_incorrect_doc_comment ();
385 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
386 | documentation_parsing
390 : opt_extern_alias_directives opt_using_directives
391 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
394 Attributes attrs = (Attributes) $4;
395 report.Error (1730, attrs.Attrs [0].Location,
396 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
398 current_namespace.UnattachedAttributes = attrs;
401 | opt_extern_alias_directives opt_using_directives attribute_sections
403 Attributes attrs = (Attributes) $3;
405 foreach (var a in attrs.Attrs) {
406 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
409 if (a.ExplicitTarget == null)
410 report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
414 module.AddAttributes ((Attributes) $3, current_namespace);
418 if (yyToken == Token.EXTERN_ALIAS)
419 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
421 Error_SyntaxError (yyToken);
430 extern_alias_directives
431 : extern_alias_directive
432 | extern_alias_directives extern_alias_directive
435 extern_alias_directive
436 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
438 var lt = (LocatedToken) $2;
441 syntax_error (lt.Location, "`alias' expected");
443 if (lang_version == LanguageVersion.ISO_1)
444 FeatureIsNotAvailable (lt.Location, "external alias");
446 lt = (LocatedToken) $3;
447 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
448 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
451 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
452 current_namespace.AddUsing (na);
454 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
459 Error_SyntaxError (yyToken);
465 | using_directives using_directive
472 Lexer.doc_state = XmlCommentState.Allowed;
477 : USING opt_static namespace_or_type_expr SEMICOLON
481 if (lang_version <= LanguageVersion.V_5)
482 FeatureIsNotAvailable (GetLocation ($2), "using static");
484 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
485 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
487 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
488 lbag.AddLocation (uc, GetLocation ($4));
491 current_namespace.AddUsing (uc);
493 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
495 var lt = (LocatedToken) $3;
496 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
497 report.Warning (440, 2, lt.Location,
498 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
502 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
505 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
506 current_namespace.AddUsing (un);
508 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
512 Error_SyntaxError (yyToken);
523 // Strictly speaking, namespaces don't have attributes but
524 // we parse global attributes along with namespace declarations and then
527 namespace_declaration
528 : opt_attributes NAMESPACE namespace_name
530 Attributes attrs = (Attributes) $1;
531 var name = (MemberName) $3;
533 bool valid_global_attrs = true;
534 if ((current_namespace.DeclarationFound || current_namespace != file)) {
535 valid_global_attrs = false;
537 foreach (var a in attrs.Attrs) {
538 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
541 valid_global_attrs = false;
546 if (!valid_global_attrs)
547 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
550 module.AddAttributes (attrs, current_namespace);
552 var ns = new NamespaceContainer (name, current_namespace);
553 current_namespace.AddTypeContainer (ns);
554 current_container = current_namespace = ns;
559 Lexer.doc_state = XmlCommentState.Allowed;
561 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
564 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
566 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
568 current_container = current_namespace = current_namespace.Parent;
570 | opt_attributes NAMESPACE namespace_name
572 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
574 var name = (MemberName) $3;
575 var ns = new NamespaceContainer (name, current_namespace);
576 lbag.AddLocation (ns, GetLocation ($2));
577 current_namespace.AddTypeContainer (ns);
586 Error_SyntaxError (yyToken);
594 var lt = (LocatedToken) $1;
595 $$ = new MemberName (lt.Value, lt.Location);
597 | namespace_name DOT IDENTIFIER
599 var lt = (LocatedToken) $3;
600 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
601 lbag.AddLocation ($$, GetLocation ($2));
605 Error_SyntaxError (yyToken);
606 $$ = new MemberName ("<invalid>", lexer.Location);
625 opt_extern_alias_directives
627 | extern_alias_directives
630 opt_namespace_or_type_declarations
632 | namespace_or_type_declarations
635 namespace_or_type_declarations
636 : namespace_or_type_declaration
637 | namespace_or_type_declarations namespace_or_type_declaration
640 namespace_or_type_declaration
644 TypeContainer ds = (TypeContainer)$1;
646 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
647 report.Error (1527, ds.Location,
648 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
651 // Here is a trick, for explicit attributes we don't know where they belong to until
652 // we parse succeeding declaration hence we parse them as normal and re-attach them
653 // when we know whether they are global (assembly:, module:) or local (type:).
654 if (ds.OptAttributes != null) {
655 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
658 current_namespace.DeclarationFound = true;
660 | namespace_declaration
662 current_namespace.DeclarationFound = true;
664 | attribute_sections CLOSE_BRACE {
665 current_namespace.UnattachedAttributes = (Attributes) $1;
666 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
674 | interface_declaration
676 | delegate_declaration
678 // Enable this when we have handled all errors, because this acts as a generic fallback
681 // Console.WriteLine ("Token=" + yyToken);
682 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
698 var sect = (List<Attribute>) $1;
699 $$ = new Attributes (sect);
701 | attribute_sections attribute_section
703 Attributes attrs = $1 as Attributes;
704 var sect = (List<Attribute>) $2;
706 attrs = new Attributes (sect);
707 else if (sect != null)
708 attrs.AddAttributes (sect);
716 PushLocation (GetLocation ($1));
717 lexer.parsing_attribute_section = true;
719 attribute_section_cont
721 lexer.parsing_attribute_section = false;
726 attribute_section_cont
727 : attribute_target COLON
729 current_attr_target = (string) $1;
730 if (current_attr_target == "assembly" || current_attr_target == "module") {
731 Lexer.check_incorrect_doc_comment ();
734 attribute_list opt_comma CLOSE_BRACKET
736 // when attribute target is invalid
737 if (current_attr_target == string.Empty)
738 $$ = new List<Attribute> (0);
742 lbag.InsertLocation ($$, 0, PopLocation ());
744 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
746 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
749 current_attr_target = null;
750 lexer.parsing_attribute_section = false;
752 | attribute_list opt_comma CLOSE_BRACKET
756 lbag.InsertLocation ($$, 0, PopLocation ());
758 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
760 lbag.AddLocation ($$, GetLocation($3));
765 Error_SyntaxError (yyToken);
767 var lt = (LocatedToken) $1;
768 var tne = new SimpleName (lt.Value, null, lt.Location);
770 $$ = new List<Attribute> () {
771 new Attribute (null, tne, null, GetLocation ($1), false)
776 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
777 Error_SyntaxError (yyToken);
786 var lt = (LocatedToken) $1;
787 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
789 | EVENT { $$ = "event"; }
790 | RETURN { $$ = "return"; }
796 $$ = new List<Attribute> (4) { (Attribute) $1 };
798 | attribute_list COMMA attribute
800 var attrs = (List<Attribute>) $1;
802 attrs.Add ((Attribute) $3);
803 lbag.AppendTo (attrs, GetLocation ($2));
813 ++lexer.parsing_block;
815 opt_attribute_arguments
817 --lexer.parsing_block;
819 var tne = (ATypeNameExpression) $1;
820 if (tne.HasTypeArguments) {
821 report.Error (404, tne.Location, "Attributes cannot be generic");
824 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
829 : namespace_or_type_expr
832 opt_attribute_arguments
833 : /* empty */ { $$ = null; }
834 | OPEN_PARENS attribute_arguments CLOSE_PARENS
842 : /* empty */ { $$ = null; }
843 | positional_or_named_argument
845 Arguments a = new Arguments (4);
846 a.Add ((Argument) $1);
847 $$ = new Arguments [] { a, null };
849 | named_attribute_argument
851 Arguments a = new Arguments (4);
852 a.Add ((Argument) $1);
853 $$ = new Arguments [] { null, a };
855 | attribute_arguments COMMA positional_or_named_argument
857 Arguments[] o = (Arguments[]) $1;
859 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
860 o [0] = new Arguments (4);
863 Arguments args = ((Arguments) o [0]);
864 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
865 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
867 args.Add ((Argument) $3);
869 | attribute_arguments COMMA named_attribute_argument
871 Arguments[] o = (Arguments[]) $1;
873 o [1] = new Arguments (4);
876 ((Arguments) o [1]).Add ((Argument) $3);
880 positional_or_named_argument
883 $$ = new Argument ((Expression) $1);
888 Error_SyntaxError (yyToken);
893 named_attribute_argument
896 ++lexer.parsing_block;
900 --lexer.parsing_block;
901 var lt = (LocatedToken) $1;
902 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
903 lbag.AddLocation ($$, GetLocation($2));
908 : identifier_inside_body COLON opt_named_modifier named_argument_expr
910 if (lang_version <= LanguageVersion.V_3)
911 FeatureIsNotAvailable (GetLocation ($1), "named argument");
913 // Avoid boxing in common case (no modifier)
914 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
916 var lt = (LocatedToken) $1;
917 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
918 lbag.AddLocation ($$, GetLocation($2));
923 : expression_or_error
924 // | declaration_expression
928 : /* empty */ { $$ = null; }
931 $$ = Argument.AType.Ref;
935 $$ = Argument.AType.Out;
939 opt_class_member_declarations
941 | class_member_declarations
944 class_member_declarations
945 : class_member_declaration
947 lexer.parsing_modifiers = true;
948 lexer.parsing_block = 0;
950 | class_member_declarations class_member_declaration
952 lexer.parsing_modifiers = true;
953 lexer.parsing_block = 0;
957 class_member_declaration
958 : constant_declaration
961 | property_declaration
963 | indexer_declaration
964 | operator_declaration
965 | constructor_declaration
966 | primary_constructor_body
967 | destructor_declaration
969 | attributes_without_members
973 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
974 GetSymbolName (yyToken));
976 lexer.parsing_generic_declaration = false;
980 primary_constructor_body
983 current_local_parameters = current_type.PrimaryConstructorParameters;
984 if (current_local_parameters == null) {
985 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
986 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
989 ++lexer.parsing_block;
990 start_block (GetLocation ($1));
992 opt_statement_list block_end
994 current_local_parameters = null;
995 var t = current_type as ClassOrStruct;
997 var b = (ToplevelBlock) $4;
998 if (t.PrimaryConstructorBlock != null) {
999 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
1001 t.PrimaryConstructorBlock = b;
1014 type_declaration_name
1016 lexer.ConstraintsParsing = true;
1017 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1018 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1020 opt_primary_parameters
1022 opt_type_parameter_constraints_clauses
1024 valid_param_mod = 0;
1025 lexer.ConstraintsParsing = false;
1028 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
1031 current_container.SetConstraints ((List<Constraints>) $10);
1034 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1036 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1038 lexer.parsing_modifiers = true;
1043 Lexer.doc_state = XmlCommentState.Allowed;
1045 opt_class_member_declarations CLOSE_BRACE
1047 --lexer.parsing_declaration;
1049 Lexer.doc_state = XmlCommentState.Allowed;
1054 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1056 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1058 $$ = pop_current_class ();
1060 | opt_attributes opt_modifiers opt_partial STRUCT error
1062 Error_SyntaxError (yyToken);
1066 constant_declaration
1069 CONST type IDENTIFIER
1071 var lt = (LocatedToken) $5;
1072 var mod = (Modifiers) $2;
1073 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1074 current_type.AddMember (current_field);
1076 if ((mod & Modifiers.STATIC) != 0) {
1077 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1082 constant_initializer opt_constant_declarators SEMICOLON
1085 current_field.DocComment = Lexer.consume_doc_comment ();
1086 Lexer.doc_state = XmlCommentState.Allowed;
1089 current_field.Initializer = (ConstInitializer) $7;
1090 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1091 current_field = null;
1097 Error_SyntaxError (yyToken);
1099 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1103 opt_constant_declarators
1105 | constant_declarators
1108 constant_declarators
1109 : constant_declarator
1111 current_field.AddDeclarator ((FieldDeclarator) $1);
1113 | constant_declarators constant_declarator
1115 current_field.AddDeclarator ((FieldDeclarator) $2);
1120 : COMMA IDENTIFIER constant_initializer
1122 var lt = (LocatedToken) $2;
1123 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1124 lbag.AddLocation ($$, GetLocation ($1));
1128 constant_initializer
1131 ++lexer.parsing_block;
1133 constant_initializer_expr
1135 --lexer.parsing_block;
1136 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1140 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1145 constant_initializer_expr
1146 : constant_expression
1153 member_type IDENTIFIER
1155 lexer.parsing_generic_declaration = false;
1157 FullNamedExpression type = (FullNamedExpression) $3;
1158 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1159 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1161 var lt = (LocatedToken) $4;
1162 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1163 current_type.AddField (current_field);
1166 opt_field_initializer
1167 opt_field_declarators
1171 current_field.DocComment = Lexer.consume_doc_comment ();
1172 Lexer.doc_state = XmlCommentState.Allowed;
1175 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1177 current_field = null;
1181 FIXED simple_type IDENTIFIER
1183 if (lang_version < LanguageVersion.ISO_2)
1184 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1186 var lt = (LocatedToken) $5;
1187 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1188 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1190 current_type.AddField (current_field);
1192 fixed_field_size opt_fixed_field_declarators SEMICOLON
1195 current_field.DocComment = Lexer.consume_doc_comment ();
1196 Lexer.doc_state = XmlCommentState.Allowed;
1199 current_field.Initializer = (ConstInitializer) $7;
1200 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1202 current_field = null;
1206 FIXED simple_type error
1209 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1213 opt_field_initializer
1217 ++lexer.parsing_block;
1218 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1219 start_block (GetLocation ($1));
1221 variable_initializer
1223 --lexer.parsing_block;
1224 current_field.Initializer = (Expression) $3;
1225 lbag.AppendToMember (current_field, GetLocation ($1));
1226 end_block (lexer.Location);
1227 current_local_parameters = null;
1231 opt_field_declarators
1239 current_field.AddDeclarator ((FieldDeclarator) $1);
1241 | field_declarators field_declarator
1243 current_field.AddDeclarator ((FieldDeclarator) $2);
1250 var lt = (LocatedToken) $2;
1251 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1252 lbag.AddLocation ($$, GetLocation ($1));
1254 | COMMA IDENTIFIER ASSIGN
1256 ++lexer.parsing_block;
1258 variable_initializer
1260 --lexer.parsing_block;
1261 var lt = (LocatedToken) $2;
1262 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1263 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1267 opt_fixed_field_declarators
1269 | fixed_field_declarators
1272 fixed_field_declarators
1273 : fixed_field_declarator
1275 current_field.AddDeclarator ((FieldDeclarator) $1);
1277 | fixed_field_declarators fixed_field_declarator
1279 current_field.AddDeclarator ((FieldDeclarator) $2);
1283 fixed_field_declarator
1284 : COMMA IDENTIFIER fixed_field_size
1286 var lt = (LocatedToken) $2;
1287 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1288 lbag.AddLocation ($$, GetLocation ($1));
1295 ++lexer.parsing_block;
1297 expression CLOSE_BRACKET
1299 --lexer.parsing_block;
1300 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1301 lbag.AddLocation ($$, GetLocation ($4));
1303 | OPEN_BRACKET error
1305 report.Error (443, lexer.Location, "Value or constant expected");
1310 variable_initializer
1315 // It has to be here for the parent to safely restore artificial block
1316 Error_SyntaxError (yyToken);
1325 Lexer.doc_state = XmlCommentState.NotAllowed;
1327 // Was added earlier in the case of body being eof for full ast
1329 method_body_expression_block
1331 Method method = (Method) $1;
1332 method.Block = (ToplevelBlock) $3;
1333 async_block = false;
1335 if (method.Block == null) {
1336 method.ParameterInfo.CheckParameters (method);
1338 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1339 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1340 method.GetSignatureForError ());
1343 if (current_container.Kind == MemberKind.Interface) {
1344 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1345 method.GetSignatureForError ());
1349 current_local_parameters = null;
1352 Lexer.doc_state = XmlCommentState.Allowed;
1360 method_declaration_name OPEN_PARENS
1362 valid_param_mod = ParameterModifierType.All;
1364 opt_formal_parameter_list CLOSE_PARENS
1366 valid_param_mod = 0;
1367 MemberName name = (MemberName) $4;
1368 current_local_parameters = (ParametersCompiled) $7;
1370 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1371 name, current_local_parameters, (Attributes) $1);
1373 current_type.AddMember (method);
1375 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1378 method.DocComment = Lexer.consume_doc_comment ();
1380 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1384 lexer.ConstraintsParsing = true;
1386 opt_type_parameter_constraints_clauses
1388 lexer.ConstraintsParsing = false;
1391 var method = (Method) $9;
1392 method.SetConstraints ((List<Constraints>) $10);
1402 lexer.parsing_generic_declaration = true;
1404 method_declaration_name
1407 lexer.parsing_generic_declaration = false;
1408 valid_param_mod = ParameterModifierType.All;
1410 opt_formal_parameter_list CLOSE_PARENS
1412 lexer.ConstraintsParsing = true;
1414 opt_type_parameter_constraints_clauses
1416 lexer.ConstraintsParsing = false;
1417 valid_param_mod = 0;
1419 MemberName name = (MemberName) $6;
1420 current_local_parameters = (ParametersCompiled) $9;
1422 var modifiers = (Modifiers) $2;
1423 modifiers |= Modifiers.PARTIAL;
1425 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1426 modifiers, name, current_local_parameters, (Attributes) $1);
1428 current_type.AddMember (method);
1430 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1433 method.SetConstraints ((List<Constraints>) $12);
1436 method.DocComment = Lexer.consume_doc_comment ();
1438 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1439 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1445 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1447 MemberName name = (MemberName) $5;
1448 report.Error (1585, name.Location,
1449 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1451 var method = Method.Create (current_type, (FullNamedExpression) $3,
1452 0, name, (ParametersCompiled) $7, (Attributes) $1);
1454 current_type.AddMember (method);
1456 current_local_parameters = (ParametersCompiled) $7;
1459 method.DocComment = Lexer.consume_doc_comment ();
1466 method_declaration_name error
1468 Error_SyntaxError (yyToken);
1469 current_local_parameters = ParametersCompiled.Undefined;
1471 MemberName name = (MemberName) $4;
1472 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1473 name, current_local_parameters, (Attributes) $1);
1475 current_type.AddMember (method);
1478 method.DocComment = Lexer.consume_doc_comment ();
1484 method_body_expression_block
1491 | SEMICOLON { $$ = null; }
1497 if (lang_version < LanguageVersion.V_6) {
1498 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1501 ++lexer.parsing_block;
1502 start_block (GetLocation ($1));
1504 expression SEMICOLON
1506 lexer.parsing_block = 0;
1507 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1508 var b = end_block (GetLocation ($4));
1509 b.IsCompilerGenerated = true;
1514 opt_formal_parameter_list
1515 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1516 | formal_parameter_list
1519 formal_parameter_list
1522 var pars_list = (List<Parameter>) $1;
1523 $$ = new ParametersCompiled (pars_list.ToArray ());
1525 | fixed_parameters COMMA parameter_array
1527 var pars_list = (List<Parameter>) $1;
1528 pars_list.Add ((Parameter) $3);
1530 $$ = new ParametersCompiled (pars_list.ToArray ());
1532 | fixed_parameters COMMA arglist_modifier
1534 var pars_list = (List<Parameter>) $1;
1535 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1536 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1538 | parameter_array COMMA error
1541 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1543 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1545 | fixed_parameters COMMA parameter_array COMMA error
1548 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1550 var pars_list = (List<Parameter>) $1;
1551 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1553 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1555 | arglist_modifier COMMA error
1557 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1559 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1561 | fixed_parameters COMMA ARGLIST COMMA error
1563 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1565 var pars_list = (List<Parameter>) $1;
1566 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1568 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1572 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1576 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1580 Error_SyntaxError (yyToken);
1581 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1588 parameters_bucket.Clear ();
1589 Parameter p = (Parameter) $1;
1590 parameters_bucket.Add (p);
1592 default_parameter_used = p.HasDefaultValue;
1593 $$ = parameters_bucket;
1595 | fixed_parameters COMMA fixed_parameter
1597 var pars = (List<Parameter>) $1;
1598 Parameter p = (Parameter) $3;
1600 if (p.HasExtensionMethodModifier)
1601 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1602 else if (!p.HasDefaultValue && default_parameter_used)
1603 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1605 default_parameter_used |= p.HasDefaultValue;
1608 lbag.AddLocation (p, GetLocation ($2));
1617 opt_parameter_modifier
1619 identifier_inside_body
1621 var lt = (LocatedToken) $4;
1622 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1625 opt_parameter_modifier
1627 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1629 var lt = (LocatedToken) $4;
1630 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1631 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1633 | attribute_sections error
1635 Error_SyntaxError (yyToken);
1636 Location l = GetLocation ($2);
1637 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1640 opt_parameter_modifier
1644 Error_SyntaxError (yyToken);
1645 Location l = GetLocation ($4);
1646 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1649 opt_parameter_modifier
1651 identifier_inside_body
1654 ++lexer.parsing_block;
1658 --lexer.parsing_block;
1659 if (lang_version <= LanguageVersion.V_3) {
1660 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1663 Parameter.Modifier mod = (Parameter.Modifier) $2;
1664 if (mod != Parameter.Modifier.NONE) {
1666 case Parameter.Modifier.REF:
1667 case Parameter.Modifier.OUT:
1668 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1669 Parameter.GetModifierSignature (mod));
1672 case Parameter.Modifier.This:
1673 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1674 Parameter.GetModifierSignature (mod));
1677 throw new NotImplementedException (mod.ToString ());
1680 mod = Parameter.Modifier.NONE;
1683 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1684 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1686 var lt = (LocatedToken) $4;
1687 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1688 lbag.AddLocation ($$, GetLocation ($5));
1691 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1695 opt_parameter_modifier
1696 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1697 | parameter_modifiers
1701 : parameter_modifier
1705 | parameter_modifiers parameter_modifier
1707 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1708 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1709 if (((Parameter.Modifier)$1 & p2) == p2) {
1710 Error_DuplicateParameterModifier (lexer.Location, p2);
1712 switch (mod & ~Parameter.Modifier.This) {
1713 case Parameter.Modifier.REF:
1714 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1716 case Parameter.Modifier.OUT:
1717 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1720 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1731 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1732 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1734 $$ = Parameter.Modifier.REF;
1738 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1739 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1741 $$ = Parameter.Modifier.OUT;
1745 if ((valid_param_mod & ParameterModifierType.This) == 0)
1746 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1748 if (lang_version <= LanguageVersion.ISO_2)
1749 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1751 $$ = Parameter.Modifier.This;
1756 : opt_attributes params_modifier type IDENTIFIER
1758 var lt = (LocatedToken) $4;
1759 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1761 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1763 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1765 var lt = (LocatedToken) $4;
1766 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1768 | opt_attributes params_modifier type error
1770 Error_SyntaxError (yyToken);
1772 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1779 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1780 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1782 | PARAMS parameter_modifier
1784 Parameter.Modifier mod = (Parameter.Modifier)$2;
1785 if ((mod & Parameter.Modifier.This) != 0) {
1786 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1788 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1791 | PARAMS params_modifier
1793 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1800 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1801 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1805 property_declaration
1809 member_declaration_name
1811 lexer.parsing_generic_declaration = false;
1813 tmpComment = Lexer.consume_doc_comment ();
1817 var type = (FullNamedExpression) $3;
1818 current_property = new Property (current_type, type, (Modifiers) $2,
1819 (MemberName) $4, (Attributes) $1);
1821 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1822 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1824 current_type.AddMember (current_property);
1825 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1827 lexer.PropertyParsing = true;
1829 accessor_declarations
1831 lexer.PropertyParsing = false;
1834 current_property.DocComment = ConsumeStoredComment ();
1838 lbag.AppendToMember (current_property, GetLocation ($10));
1839 lexer.parsing_modifiers = true;
1841 opt_property_initializer
1843 current_property = null;
1848 member_declaration_name
1850 lexer.parsing_generic_declaration = false;
1852 tmpComment = Lexer.consume_doc_comment ();
1853 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1857 var type = (FullNamedExpression) $3;
1858 var property = new Property (current_type, type, (Modifiers) $2,
1859 (MemberName) $4, (Attributes) $1);
1861 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1862 property.Get.Block = (ToplevelBlock) $6;
1864 if (current_container.Kind == MemberKind.Interface) {
1865 report.Error (531, property.Get.Block.StartLocation,
1866 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1869 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1870 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1873 property.DocComment = ConsumeStoredComment ();
1875 current_type.AddMember (property);
1877 current_local_parameters = null;
1881 opt_property_initializer
1885 ++lexer.parsing_block;
1886 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1887 start_block (GetLocation ($1));
1889 property_initializer SEMICOLON
1891 --lexer.parsing_block;
1892 ((Property)current_property).Initializer = (Expression) $3;
1893 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1894 end_block (GetLocation ($4));
1895 current_local_parameters = null;
1898 Lexer.doc_state = XmlCommentState.Allowed;
1902 property_initializer
1908 : opt_attributes opt_modifiers
1909 member_type indexer_declaration_name OPEN_BRACKET
1911 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1913 opt_formal_parameter_list CLOSE_BRACKET
1915 valid_param_mod = 0;
1916 var type = (FullNamedExpression) $3;
1917 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1919 current_property = indexer;
1921 current_type.AddIndexer (indexer);
1922 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1924 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1925 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1927 if (indexer.ParameterInfo.IsEmpty) {
1928 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1932 tmpComment = Lexer.consume_doc_comment ();
1933 Lexer.doc_state = XmlCommentState.Allowed;
1936 lexer.PropertyParsing = true;
1937 current_local_parameters = (ParametersCompiled) $7;
1941 lexer.PropertyParsing = false;
1942 current_local_parameters = null;
1944 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1945 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1948 current_property.DocComment = ConsumeStoredComment ();
1950 current_property = null;
1955 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1957 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1961 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1962 current_property.Get.Block = (ToplevelBlock) $1;
1966 accessor_declarations
1967 : get_accessor_declaration
1968 | get_accessor_declaration accessor_declarations
1969 | set_accessor_declaration
1970 | set_accessor_declaration accessor_declarations
1973 if (yyToken == Token.CLOSE_BRACE) {
1974 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1976 if (yyToken == Token.SEMICOLON)
1977 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1979 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1984 get_accessor_declaration
1985 : opt_attributes opt_modifiers GET
1987 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1988 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1991 if (current_property.Get != null) {
1992 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1995 if (current_property is Indexer) {
1996 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1997 (Attributes) $1, GetLocation ($3));
1999 current_property.Get = new Property.GetMethod (current_property,
2000 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2003 current_local_parameters = current_property.Get.ParameterInfo;
2004 lbag.AddMember (current_property.Get, mod_locations);
2005 lexer.PropertyParsing = false;
2010 current_property.Get.Block = (ToplevelBlock) $5;
2012 if (current_container.Kind == MemberKind.Interface) {
2013 report.Error (531, current_property.Get.Block.StartLocation,
2014 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2018 current_local_parameters = null;
2019 lexer.PropertyParsing = true;
2022 if (Lexer.doc_state == XmlCommentState.Error)
2023 Lexer.doc_state = XmlCommentState.NotAllowed;
2027 set_accessor_declaration
2028 : opt_attributes opt_modifiers SET
2030 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2031 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2034 if (current_property.Set != null) {
2035 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2038 if (current_property is Indexer) {
2039 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2040 ParametersCompiled.MergeGenerated (compiler,
2041 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2042 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2044 (Attributes) $1, GetLocation ($3));
2046 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2047 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2048 (Attributes) $1, GetLocation ($3));
2051 current_local_parameters = current_property.Set.ParameterInfo;
2052 lbag.AddMember (current_property.Set, mod_locations);
2053 lexer.PropertyParsing = false;
2058 current_property.Set.Block = (ToplevelBlock) $5;
2060 if (current_container.Kind == MemberKind.Interface) {
2061 report.Error (531, current_property.Set.Block.StartLocation,
2062 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2066 current_local_parameters = null;
2067 lexer.PropertyParsing = true;
2070 && Lexer.doc_state == XmlCommentState.Error)
2071 Lexer.doc_state = XmlCommentState.NotAllowed;
2084 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2089 interface_declaration
2096 type_declaration_name
2098 lexer.ConstraintsParsing = true;
2099 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2100 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2103 opt_type_parameter_constraints_clauses
2105 lexer.ConstraintsParsing = false;
2108 current_container.SetConstraints ((List<Constraints>) $9);
2111 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2112 Lexer.doc_state = XmlCommentState.Allowed;
2115 lexer.parsing_modifiers = true;
2117 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2119 --lexer.parsing_declaration;
2121 Lexer.doc_state = XmlCommentState.Allowed;
2126 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2128 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2130 $$ = pop_current_class ();
2132 | opt_attributes opt_modifiers opt_partial INTERFACE error
2134 Error_SyntaxError (yyToken);
2138 opt_interface_member_declarations
2140 | interface_member_declarations
2143 interface_member_declarations
2144 : interface_member_declaration
2146 lexer.parsing_modifiers = true;
2147 lexer.parsing_block = 0;
2149 | interface_member_declarations interface_member_declaration
2151 lexer.parsing_modifiers = true;
2152 lexer.parsing_block = 0;
2156 interface_member_declaration
2157 : constant_declaration
2159 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2163 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2165 | method_declaration
2166 | property_declaration
2168 | indexer_declaration
2169 | operator_declaration
2171 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2173 | constructor_declaration
2175 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2179 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2183 operator_declaration
2184 : opt_attributes opt_modifiers operator_declarator
2187 method_body_expression_block
2189 OperatorDeclaration decl = (OperatorDeclaration) $3;
2191 Operator op = new Operator (
2192 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2193 current_local_parameters,
2194 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2196 if (op.Block == null)
2197 op.ParameterInfo.CheckParameters (op);
2200 op.DocComment = tmpComment;
2201 Lexer.doc_state = XmlCommentState.Allowed;
2204 // Note again, checking is done in semantic analysis
2205 current_type.AddOperator (op);
2207 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2210 current_local_parameters = null;
2215 : type_expression_or_array
2218 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2219 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2224 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2226 valid_param_mod = ParameterModifierType.DefaultValue;
2227 if ((Operator.OpType) $3 == Operator.OpType.Is)
2228 valid_param_mod |= ParameterModifierType.Out;
2230 opt_formal_parameter_list CLOSE_PARENS
2232 valid_param_mod = 0;
2234 Location loc = GetLocation ($2);
2235 Operator.OpType op = (Operator.OpType) $3;
2236 current_local_parameters = (ParametersCompiled)$6;
2238 int p_count = current_local_parameters.Count;
2240 if (op == Operator.OpType.Addition)
2241 op = Operator.OpType.UnaryPlus;
2242 else if (op == Operator.OpType.Subtraction)
2243 op = Operator.OpType.UnaryNegation;
2246 if (IsUnaryOperator (op)) {
2248 report.Error (1020, loc, "Overloadable binary operator expected");
2249 } else if (p_count != 1) {
2250 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2251 Operator.GetName (op));
2253 } else if (op == Operator.OpType.Is) {
2254 // TODO: Special checks for is operator
2257 report.Error (1019, loc, "Overloadable unary operator expected");
2258 } else if (p_count != 2) {
2259 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2260 Operator.GetName (op));
2265 tmpComment = Lexer.consume_doc_comment ();
2266 Lexer.doc_state = XmlCommentState.NotAllowed;
2269 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2270 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2272 | conversion_operator_declarator
2275 overloadable_operator
2277 : BANG { $$ = Operator.OpType.LogicalNot; }
2278 | TILDE { $$ = Operator.OpType.OnesComplement; }
2279 | OP_INC { $$ = Operator.OpType.Increment; }
2280 | OP_DEC { $$ = Operator.OpType.Decrement; }
2281 | TRUE { $$ = Operator.OpType.True; }
2282 | FALSE { $$ = Operator.OpType.False; }
2283 // Unary and binary:
2284 | PLUS { $$ = Operator.OpType.Addition; }
2285 | MINUS { $$ = Operator.OpType.Subtraction; }
2287 | STAR { $$ = Operator.OpType.Multiply; }
2288 | DIV { $$ = Operator.OpType.Division; }
2289 | PERCENT { $$ = Operator.OpType.Modulus; }
2290 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2291 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2292 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2293 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2294 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2295 | OP_EQ { $$ = Operator.OpType.Equality; }
2296 | OP_NE { $$ = Operator.OpType.Inequality; }
2297 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2298 | OP_LT { $$ = Operator.OpType.LessThan; }
2299 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2300 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2303 if (lang_version != LanguageVersion.Experimental)
2304 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2306 $$ = Operator.OpType.Is;
2310 conversion_operator_declarator
2311 : IMPLICIT OPERATOR type OPEN_PARENS
2313 valid_param_mod = ParameterModifierType.DefaultValue;
2315 opt_formal_parameter_list CLOSE_PARENS
2317 valid_param_mod = 0;
2319 Location loc = GetLocation ($2);
2320 current_local_parameters = (ParametersCompiled)$6;
2322 if (current_local_parameters.Count != 1) {
2323 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2327 tmpComment = Lexer.consume_doc_comment ();
2328 Lexer.doc_state = XmlCommentState.NotAllowed;
2331 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2332 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2334 | EXPLICIT OPERATOR type OPEN_PARENS
2336 valid_param_mod = ParameterModifierType.DefaultValue;
2338 opt_formal_parameter_list CLOSE_PARENS
2340 valid_param_mod = 0;
2342 Location loc = GetLocation ($2);
2343 current_local_parameters = (ParametersCompiled)$6;
2345 if (current_local_parameters.Count != 1) {
2346 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2350 tmpComment = Lexer.consume_doc_comment ();
2351 Lexer.doc_state = XmlCommentState.NotAllowed;
2354 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2355 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2359 Error_SyntaxError (yyToken);
2360 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2361 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2365 Error_SyntaxError (yyToken);
2366 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2367 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2371 constructor_declaration
2372 : constructor_declarator
2375 Constructor c = (Constructor) $1;
2376 c.Block = (ToplevelBlock) $2;
2379 c.DocComment = ConsumeStoredComment ();
2381 current_local_parameters = null;
2383 Lexer.doc_state = XmlCommentState.Allowed;
2387 constructor_declarator
2393 tmpComment = Lexer.consume_doc_comment ();
2394 Lexer.doc_state = XmlCommentState.Allowed;
2397 valid_param_mod = ParameterModifierType.All;
2399 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2401 valid_param_mod = 0;
2402 current_local_parameters = (ParametersCompiled) $6;
2404 var lt = (LocatedToken) $3;
2405 var mods = (Modifiers) $2;
2406 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2408 if (lt.Value != current_container.MemberName.Name) {
2409 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2410 } else if ((mods & Modifiers.STATIC) != 0) {
2411 if (!current_local_parameters.IsEmpty) {
2412 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2413 c.GetSignatureForError ());
2416 if ((mods & Modifiers.AccessibilityMask) != 0){
2417 report.Error (515, c.Location,
2418 "`{0}': static constructor cannot have an access modifier",
2419 c.GetSignatureForError ());
2422 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2423 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2427 current_type.AddConstructor (c);
2428 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2432 // start block here, so possible anonymous methods inside
2433 // constructor initializer can get correct parent block
2435 start_block (lexer.Location);
2437 opt_constructor_initializer
2440 var c = (Constructor) $8;
2441 c.Initializer = (ConstructorInitializer) $9;
2444 report.Error (514, c.Location,
2445 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2446 c.GetSignatureForError ());
2456 | SEMICOLON { current_block = null; $$ = null; }
2459 opt_constructor_initializer
2461 | constructor_initializer
2464 constructor_initializer
2465 : COLON BASE OPEN_PARENS
2467 ++lexer.parsing_block;
2469 opt_argument_list CLOSE_PARENS
2471 --lexer.parsing_block;
2472 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2473 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2475 | COLON THIS OPEN_PARENS
2477 ++lexer.parsing_block;
2479 opt_argument_list CLOSE_PARENS
2481 --lexer.parsing_block;
2482 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2483 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2487 Error_SyntaxError (yyToken);
2488 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2489 lbag.AddLocation ($$, GetLocation ($1));
2493 Error_SyntaxError (yyToken);
2498 destructor_declaration
2499 : opt_attributes opt_modifiers TILDE
2502 tmpComment = Lexer.consume_doc_comment ();
2503 Lexer.doc_state = XmlCommentState.NotAllowed;
2506 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2508 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2510 var lt = (LocatedToken) $5;
2511 if (lt.Value != current_container.MemberName.Name){
2512 report.Error (574, lt.Location, "Name of destructor must match name of class");
2513 } else if (current_container.Kind != MemberKind.Class){
2514 report.Error (575, lt.Location, "Only class types can contain destructor");
2517 Destructor d = new Destructor (current_type, (Modifiers) $2,
2518 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2520 d.DocComment = ConsumeStoredComment ();
2522 d.Block = (ToplevelBlock) $8;
2523 current_type.AddMember (d);
2524 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2526 current_local_parameters = null;
2533 EVENT type member_declaration_name
2535 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2536 current_type.AddMember (current_event_field);
2538 if (current_event_field.MemberName.ExplicitInterface != null) {
2539 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2540 current_event_field.GetSignatureForError ());
2543 $$ = current_event_field;
2545 opt_event_initializer
2546 opt_event_declarators
2550 current_event_field.DocComment = Lexer.consume_doc_comment ();
2551 Lexer.doc_state = XmlCommentState.Allowed;
2554 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2555 current_event_field = null;
2559 EVENT type member_declaration_name
2562 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2563 current_type.AddMember (current_event);
2564 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2566 lexer.EventParsing = true;
2568 event_accessor_declarations
2570 if (current_container.Kind == MemberKind.Interface)
2571 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2573 lexer.EventParsing = false;
2578 current_event.DocComment = Lexer.consume_doc_comment ();
2579 Lexer.doc_state = XmlCommentState.Allowed;
2582 lbag.AppendToMember (current_event, GetLocation ($9));
2583 current_event = null;
2584 current_local_parameters = null;
2590 Error_SyntaxError (yyToken);
2592 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2596 opt_event_initializer
2600 ++lexer.parsing_block;
2602 event_variable_initializer
2604 --lexer.parsing_block;
2605 current_event_field.Initializer = (Expression) $3;
2609 opt_event_declarators
2617 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2619 | event_declarators event_declarator
2621 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2628 var lt = (LocatedToken) $2;
2629 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2630 lbag.AddLocation ($$, GetLocation ($1));
2632 | COMMA IDENTIFIER ASSIGN
2634 ++lexer.parsing_block;
2636 event_variable_initializer
2638 --lexer.parsing_block;
2639 var lt = (LocatedToken) $2;
2640 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2641 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2645 event_variable_initializer
2647 if (current_container.Kind == MemberKind.Interface) {
2648 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2649 current_event_field.GetSignatureForError ());
2652 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2653 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2654 current_event_field.GetSignatureForError ());
2657 variable_initializer
2663 event_accessor_declarations
2664 : add_accessor_declaration remove_accessor_declaration
2665 | remove_accessor_declaration add_accessor_declaration
2666 | add_accessor_declaration
2668 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2669 current_event.GetSignatureForError ());
2671 | remove_accessor_declaration
2673 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2674 current_event.GetSignatureForError ());
2678 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2683 add_accessor_declaration
2684 : opt_attributes opt_modifiers ADD
2686 if ($2 != ModifierNone) {
2687 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2690 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2691 current_local_parameters = current_event.Add.ParameterInfo;
2693 lbag.AddMember (current_event.Add, mod_locations);
2694 lexer.EventParsing = false;
2696 event_accessor_block
2698 lexer.EventParsing = true;
2700 current_event.Add.Block = (ToplevelBlock) $5;
2702 if (current_container.Kind == MemberKind.Interface) {
2703 report.Error (531, current_event.Add.Block.StartLocation,
2704 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2707 current_local_parameters = null;
2711 remove_accessor_declaration
2712 : opt_attributes opt_modifiers REMOVE
2714 if ($2 != ModifierNone) {
2715 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2718 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2719 current_local_parameters = current_event.Remove.ParameterInfo;
2721 lbag.AddMember (current_event.Remove, mod_locations);
2722 lexer.EventParsing = false;
2724 event_accessor_block
2726 lexer.EventParsing = true;
2728 current_event.Remove.Block = (ToplevelBlock) $5;
2730 if (current_container.Kind == MemberKind.Interface) {
2731 report.Error (531, current_event.Remove.Block.StartLocation,
2732 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2735 current_local_parameters = null;
2739 event_accessor_block
2742 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2748 attributes_without_members
2749 : attribute_sections CLOSE_BRACE
2751 current_type.UnattachedAttributes = (Attributes) $1;
2752 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2753 lexer.putback ('}');
2757 // For full ast try to recover incomplete ambiguous member
2758 // declaration in form on class X { public int }
2760 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2762 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2764 lexer.putback ('}');
2766 lexer.parsing_generic_declaration = false;
2767 FullNamedExpression type = (FullNamedExpression) $3;
2768 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2769 current_type.AddField (current_field);
2777 ENUM type_declaration_name
2781 enumTypeComment = Lexer.consume_doc_comment ();
2786 Lexer.doc_state = XmlCommentState.Allowed;
2788 MemberName name = (MemberName) $4;
2789 if (name.IsGeneric) {
2790 report.Error (1675, name.Location, "Enums cannot have type parameters");
2793 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2795 opt_enum_member_declarations
2797 lexer.parsing_modifiers = true;
2799 // here will be evaluated after CLOSE_BLACE is consumed.
2801 Lexer.doc_state = XmlCommentState.Allowed;
2803 CLOSE_BRACE opt_semicolon
2806 current_container.DocComment = enumTypeComment;
2808 --lexer.parsing_declaration;
2811 // em.DocComment = ev.DocComment;
2813 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2814 $$ = pop_current_class ();
2826 Error_TypeExpected (GetLocation ($1));
2831 opt_enum_member_declarations
2833 | enum_member_declarations
2834 | enum_member_declarations COMMA
2836 lbag.AddLocation ($1, GetLocation ($2));
2840 enum_member_declarations
2841 : enum_member_declaration
2842 | enum_member_declarations COMMA enum_member_declaration
2844 lbag.AddLocation ($1, GetLocation ($2));
2849 enum_member_declaration
2850 : opt_attributes IDENTIFIER
2852 var lt = (LocatedToken) $2;
2853 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2854 ((Enum) current_type).AddEnumMember (em);
2857 em.DocComment = Lexer.consume_doc_comment ();
2858 Lexer.doc_state = XmlCommentState.Allowed;
2863 | opt_attributes IDENTIFIER
2865 ++lexer.parsing_block;
2867 tmpComment = Lexer.consume_doc_comment ();
2868 Lexer.doc_state = XmlCommentState.NotAllowed;
2871 ASSIGN constant_expression
2873 --lexer.parsing_block;
2875 var lt = (LocatedToken) $2;
2876 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2877 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2878 ((Enum) current_type).AddEnumMember (em);
2881 em.DocComment = ConsumeStoredComment ();
2885 | opt_attributes IDENTIFIER error
2887 Error_SyntaxError (yyToken);
2889 var lt = (LocatedToken) $2;
2890 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2891 ((Enum) current_type).AddEnumMember (em);
2894 em.DocComment = Lexer.consume_doc_comment ();
2895 Lexer.doc_state = XmlCommentState.Allowed;
2900 | attributes_without_members
2903 delegate_declaration
2907 member_type type_declaration_name
2910 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2912 opt_formal_parameter_list CLOSE_PARENS
2914 valid_param_mod = 0;
2916 ParametersCompiled p = (ParametersCompiled) $8;
2918 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2920 p.CheckParameters (del);
2922 current_container.AddTypeContainer (del);
2924 current_delegate = del;
2925 lexer.ConstraintsParsing = true;
2927 opt_type_parameter_constraints_clauses
2929 lexer.ConstraintsParsing = false;
2934 current_delegate.DocComment = Lexer.consume_doc_comment ();
2935 Lexer.doc_state = XmlCommentState.Allowed;
2939 current_delegate.SetConstraints ((List<Constraints>) $11);
2940 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2942 $$ = current_delegate;
2944 current_delegate = null;
2952 if (lang_version < LanguageVersion.ISO_2)
2953 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2955 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2959 namespace_or_type_expr
2961 | qualified_alias_member IDENTIFIER opt_type_argument_list
2963 var lt1 = (LocatedToken) $1;
2964 var lt2 = (LocatedToken) $2;
2966 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2967 lbag.AddLocation ($$, GetLocation ($2));
2969 | qualified_alias_member IDENTIFIER generic_dimension
2971 var lt1 = (LocatedToken) $1;
2972 var lt2 = (LocatedToken) $2;
2974 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2975 lbag.AddLocation ($$, GetLocation ($2));
2981 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2983 var lt = (LocatedToken) $3;
2984 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2985 lbag.AddLocation ($$, GetLocation ($2));
2987 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2989 var lt = (LocatedToken) $3;
2990 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2991 lbag.AddLocation ($$, GetLocation ($2));
2996 : IDENTIFIER opt_type_argument_list
2998 var lt = (LocatedToken) $1;
2999 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3001 | IDENTIFIER generic_dimension
3003 var lt = (LocatedToken) $1;
3004 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3009 // Generics arguments (any type, without attributes)
3011 opt_type_argument_list
3013 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3015 if (lang_version < LanguageVersion.ISO_2)
3016 FeatureIsNotAvailable (GetLocation ($1), "generics");
3020 | OP_GENERICS_LT error
3022 Error_TypeExpected (lexer.Location);
3023 $$ = new TypeArguments ();
3030 TypeArguments type_args = new TypeArguments ();
3031 type_args.Add ((FullNamedExpression) $1);
3034 | type_arguments COMMA type
3036 TypeArguments type_args = (TypeArguments) $1;
3037 type_args.Add ((FullNamedExpression) $3);
3043 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3045 type_declaration_name
3048 lexer.parsing_generic_declaration = true;
3050 opt_type_parameter_list
3052 lexer.parsing_generic_declaration = false;
3053 var lt = (LocatedToken) $1;
3054 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3058 member_declaration_name
3059 : method_declaration_name
3061 MemberName mn = (MemberName)$1;
3062 if (mn.TypeParameters != null)
3063 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3064 mn.GetSignatureForError ()));
3068 method_declaration_name
3069 : type_declaration_name
3070 | explicit_interface IDENTIFIER opt_type_parameter_list
3072 lexer.parsing_generic_declaration = false;
3073 var lt = (LocatedToken) $2;
3074 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3078 indexer_declaration_name
3081 lexer.parsing_generic_declaration = false;
3082 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3084 | explicit_interface THIS
3086 lexer.parsing_generic_declaration = false;
3087 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3092 : IDENTIFIER opt_type_argument_list DOT
3094 var lt = (LocatedToken) $1;
3095 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3096 lbag.AddLocation ($$, GetLocation ($3));
3098 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3100 var lt1 = (LocatedToken) $1;
3101 var lt2 = (LocatedToken) $2;
3103 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3104 lbag.AddLocation ($$, GetLocation ($4));
3106 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3108 var lt = (LocatedToken) $2;
3109 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3110 lbag.AddLocation ($$, GetLocation ($4));
3114 opt_type_parameter_list
3116 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3118 if (lang_version < LanguageVersion.ISO_2)
3119 FeatureIsNotAvailable (GetLocation ($1), "generics");
3122 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3129 var tparams = new TypeParameters ();
3130 tparams.Add ((TypeParameter)$1);
3133 | type_parameters COMMA type_parameter
3135 var tparams = (TypeParameters) $1;
3136 tparams.Add ((TypeParameter)$3);
3138 lbag.AddLocation ($3, GetLocation ($3));
3143 : opt_attributes opt_type_parameter_variance IDENTIFIER
3145 var lt = (LocatedToken)$3;
3146 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3150 if (GetTokenName (yyToken) == "type")
3151 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3153 Error_SyntaxError (yyToken);
3155 $$ = new TypeParameter (MemberName.Null, null, null);
3160 // All types where void is allowed
3163 : type_expression_or_array
3166 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3173 lexer.parsing_generic_declaration = true;
3178 // A type which does not allow `void' to be used
3181 : type_expression_or_array
3191 : type_expression_or_array
3194 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3195 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3199 type_expression_or_array
3201 | type_expression rank_specifiers
3203 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3208 : namespace_or_type_expr opt_nullable
3211 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3213 var sn = $1 as SimpleName;
3214 if (sn != null && sn.Name == "var")
3215 $$ = new VarExpr (sn.Location);
3220 | namespace_or_type_expr pointer_stars
3222 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3224 | builtin_type_expression
3230 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3231 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3235 builtin_type_expression
3236 : builtin_types opt_nullable
3239 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3241 | builtin_types pointer_stars
3243 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3245 | VOID pointer_stars
3247 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3254 var types = new List<FullNamedExpression> (2);
3255 types.Add ((FullNamedExpression) $1);
3258 | type_list COMMA base_type_name
3260 var types = (List<FullNamedExpression>) $1;
3261 types.Add ((FullNamedExpression) $3);
3269 if ($1 is ComposedCast) {
3270 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3277 * replaces all the productions for isolating the various
3278 * simple types, but we need this to reuse it easily in variable_type
3281 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3282 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3283 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3284 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3285 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3286 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3291 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3292 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3293 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3294 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3295 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3296 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3297 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3298 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3299 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3303 // Expressions, section 7.5
3308 : type_name_expression
3310 | array_creation_expression
3311 | parenthesized_expression
3312 | default_value_expression
3313 | invocation_expression
3317 | post_increment_expression
3318 | post_decrement_expression
3319 | object_or_delegate_creation_expression
3320 | anonymous_type_expression
3323 | checked_expression
3324 | unchecked_expression
3325 | pointer_member_access
3326 | anonymous_method_expression
3327 | undocumented_expressions
3328 | interpolated_string
3331 type_name_expression
3333 | IDENTIFIER GENERATE_COMPLETION {
3334 var lt = (LocatedToken) $1;
3335 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3343 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3347 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3348 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3352 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3354 if (lang_version < LanguageVersion.V_6)
3355 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3357 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3359 | INTERPOLATED_STRING_END
3361 if (lang_version < LanguageVersion.V_6)
3362 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3364 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3371 var list = new List<Expression> ();
3372 list.Add ((InterpolatedStringInsert) $1);
3375 | interpolations INTERPOLATED_STRING interpolation
3377 var list = (List<Expression>) $1;
3378 list.Add ((StringLiteral) $2);
3379 list.Add ((InterpolatedStringInsert) $3);
3387 $$ = new InterpolatedStringInsert ((Expression) $1);
3389 | expression COMMA expression
3391 $$ = new InterpolatedStringInsert ((Expression) $1) {
3392 Alignment = (Expression)$3
3397 lexer.parsing_interpolation_format = true;
3401 lexer.parsing_interpolation_format = false;
3403 $$ = new InterpolatedStringInsert ((Expression) $1) {
3407 | expression COMMA expression COLON
3409 lexer.parsing_interpolation_format = true;
3413 lexer.parsing_interpolation_format = false;
3415 $$ = new InterpolatedStringInsert ((Expression) $1) {
3416 Alignment = (Expression)$3,
3417 Format = (string) $6
3424 // Here is the trick, tokenizer may think that parens is a special but
3425 // parser is interested in open parens only, so we merge them.
3426 // Consider: if (a)foo ();
3434 // Use this production to accept closing parenthesis or
3435 // performing completion
3439 | COMPLETE_COMPLETION
3443 parenthesized_expression
3444 : OPEN_PARENS expression CLOSE_PARENS
3446 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3447 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3449 | OPEN_PARENS expression COMPLETE_COMPLETION
3451 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3456 : primary_expression DOT identifier_inside_body opt_type_argument_list
3458 var lt = (LocatedToken) $3;
3459 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3460 lbag.AddLocation ($$, GetLocation ($2));
3462 | primary_expression DOT identifier_inside_body generic_dimension
3464 var lt = (LocatedToken) $3;
3465 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3466 lbag.AddLocation ($$, GetLocation ($2));
3468 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3470 if (lang_version < LanguageVersion.V_6)
3471 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3473 var lt = (LocatedToken) $4;
3474 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3475 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3477 | builtin_types DOT identifier_inside_body opt_type_argument_list
3479 var lt = (LocatedToken) $3;
3480 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3481 lbag.AddLocation ($$, GetLocation ($2));
3483 | BASE DOT identifier_inside_body opt_type_argument_list
3485 var lt = (LocatedToken) $3;
3486 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3487 lbag.AddLocation ($$, GetLocation ($2));
3489 | AWAIT DOT identifier_inside_body opt_type_argument_list
3491 var lt = (LocatedToken) $3;
3492 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3493 lbag.AddLocation ($$, GetLocation ($2));
3495 | qualified_alias_member identifier_inside_body opt_type_argument_list
3497 var lt1 = (LocatedToken) $1;
3498 var lt2 = (LocatedToken) $2;
3500 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3501 lbag.AddLocation ($$, GetLocation ($2));
3503 | qualified_alias_member identifier_inside_body generic_dimension
3505 var lt1 = (LocatedToken) $1;
3506 var lt2 = (LocatedToken) $2;
3508 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3509 lbag.AddLocation ($$, GetLocation ($2));
3511 | primary_expression DOT GENERATE_COMPLETION {
3512 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3514 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3515 var lt = (LocatedToken) $3;
3516 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3518 | builtin_types DOT GENERATE_COMPLETION
3520 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3522 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3523 var lt = (LocatedToken) $3;
3524 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3528 invocation_expression
3529 : primary_expression open_parens_any opt_argument_list close_parens
3531 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3532 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3534 | primary_expression open_parens_any argument_list error
3536 Error_SyntaxError (yyToken);
3538 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3539 lbag.AddLocation ($$, GetLocation ($2));
3541 | primary_expression open_parens_any error
3543 Error_SyntaxError (yyToken);
3545 $$ = new Invocation ((Expression) $1, null);
3546 lbag.AddLocation ($$, GetLocation ($2));
3550 opt_object_or_collection_initializer
3551 : /* empty */ { $$ = null; }
3552 | object_or_collection_initializer
3555 object_or_collection_initializer
3556 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3559 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3561 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3563 lbag.AddLocation ($$, GetLocation ($3));
3565 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3567 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3568 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3572 opt_member_initializer_list
3573 : /* empty */ { $$ = null; }
3574 | member_initializer_list
3580 member_initializer_list
3581 : member_initializer
3583 var a = new List<Expression> ();
3584 a.Add ((Expression) $1);
3587 | member_initializer_list COMMA member_initializer
3589 var a = (List<Expression>)$1;
3590 a.Add ((Expression) $3);
3593 | member_initializer_list error {
3594 Error_SyntaxError (yyToken);
3600 : IDENTIFIER ASSIGN initializer_value
3602 var lt = (LocatedToken) $1;
3603 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3604 lbag.AddLocation ($$, GetLocation ($2));
3606 | AWAIT ASSIGN initializer_value
3608 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3609 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3610 lbag.AddLocation ($$, GetLocation ($2));
3612 | GENERATE_COMPLETION
3614 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3616 | non_assignment_expression opt_COMPLETE_COMPLETION {
3617 CompletionSimpleName csn = $1 as CompletionSimpleName;
3619 $$ = new CollectionElementInitializer ((Expression)$1);
3621 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3623 | OPEN_BRACE expression_list CLOSE_BRACE
3626 $$ = new CollectionElementInitializer (GetLocation ($1));
3628 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3630 lbag.AddLocation ($$, GetLocation ($3));
3632 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3634 if (lang_version < LanguageVersion.V_6)
3635 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3637 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3638 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3640 | OPEN_BRACE CLOSE_BRACE
3642 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3643 $$ = new CollectionElementInitializer (GetLocation ($1));
3644 lbag.AddLocation ($$, GetLocation ($2));
3650 | object_or_collection_initializer
3654 : /* empty */ { $$ = null; }
3659 : argument_or_named_argument
3661 Arguments list = new Arguments (4);
3662 list.Add ((Argument) $1);
3665 | argument_list COMMA argument
3667 Arguments list = (Arguments) $1;
3668 if (list [list.Count - 1] is NamedArgument)
3669 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3671 list.Add ((Argument) $3);
3674 | argument_list COMMA named_argument
3676 Arguments list = (Arguments) $1;
3677 NamedArgument a = (NamedArgument) $3;
3678 for (int i = 0; i < list.Count; ++i) {
3679 NamedArgument na = list [i] as NamedArgument;
3680 if (na != null && na.Name == a.Name)
3681 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3688 | argument_list COMMA error
3690 if (lexer.putback_char == -1)
3691 lexer.putback (')'); // TODO: Wrong but what can I do
3692 Error_SyntaxError (yyToken);
3697 report.Error (839, GetLocation ($1), "An argument is missing");
3705 $$ = new Argument ((Expression) $1);
3707 | non_simple_argument
3710 argument_or_named_argument
3716 : REF variable_reference
3718 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3719 lbag.AddLocation ($$, GetLocation ($1));
3721 | REF declaration_expression
3723 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3725 | OUT variable_reference
3727 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3728 lbag.AddLocation ($$, GetLocation ($1));
3730 | OUT declaration_expression
3732 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3734 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3736 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3737 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3739 | ARGLIST OPEN_PARENS CLOSE_PARENS
3741 $$ = new Argument (new Arglist (GetLocation ($1)));
3742 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3746 declaration_expression
3747 : OPEN_PARENS declaration_expression CLOSE_PARENS
3749 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3750 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3753 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3755 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3756 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3758 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3760 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3761 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3764 | variable_type identifier_inside_body
3766 if (lang_version != LanguageVersion.Experimental)
3767 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3769 var lt = (LocatedToken) $2;
3770 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3771 current_block.AddLocalName (lv);
3772 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3774 | variable_type identifier_inside_body ASSIGN expression
3776 if (lang_version != LanguageVersion.Experimental)
3777 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3779 var lt = (LocatedToken) $2;
3780 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3781 current_block.AddLocalName (lv);
3782 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3783 Initializer = (Expression) $4
3793 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3795 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3796 lbag.AddLocation ($$, GetLocation ($4));
3798 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3800 if (lang_version < LanguageVersion.V_6)
3801 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3803 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3804 ConditionalAccess = true
3807 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3809 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3811 Error_SyntaxError (yyToken);
3812 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3814 | primary_expression OPEN_BRACKET_EXPR error
3816 Error_SyntaxError (yyToken);
3817 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3822 : expression_or_error
3824 var list = new List<Expression> (4);
3825 list.Add ((Expression) $1);
3828 | expression_list COMMA expression_or_error
3830 var list = (List<Expression>) $1;
3831 list.Add ((Expression) $3);
3836 expression_list_arguments
3837 : expression_list_argument
3839 Arguments args = new Arguments (4);
3840 args.Add ((Argument) $1);
3843 | expression_list_arguments COMMA expression_list_argument
3845 Arguments args = (Arguments) $1;
3846 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3847 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3849 args.Add ((Argument) $3);
3854 expression_list_argument
3857 $$ = new Argument ((Expression) $1);
3865 $$ = new This (GetLocation ($1));
3870 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3872 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3873 lbag.AddLocation ($$, GetLocation ($4));
3875 | BASE OPEN_BRACKET error
3877 Error_SyntaxError (yyToken);
3878 $$ = new ElementAccess (null, null, GetLocation ($2));
3882 post_increment_expression
3883 : primary_expression OP_INC
3885 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3889 post_decrement_expression
3890 : primary_expression OP_DEC
3892 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3896 object_or_delegate_creation_expression
3897 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3900 if (lang_version <= LanguageVersion.ISO_2)
3901 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3903 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3905 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3908 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3910 | NEW new_expr_type object_or_collection_initializer
3912 if (lang_version <= LanguageVersion.ISO_2)
3913 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3915 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3919 array_creation_expression
3920 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3922 opt_array_initializer
3924 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3925 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3926 Next = (ComposedTypeSpecifier) $6
3927 }, (ArrayInitializer) $7, GetLocation ($1)) {
3928 NoEmptyInterpolation = true
3931 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3933 | NEW new_expr_type rank_specifiers opt_array_initializer
3936 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3938 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
3939 NoEmptyInterpolation = true
3942 | NEW rank_specifier array_initializer
3944 if (lang_version <= LanguageVersion.ISO_2)
3945 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3947 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3949 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3951 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3952 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3954 | NEW new_expr_type error
3956 Error_SyntaxError (yyToken);
3957 // It can be any of new expression, create the most common one
3958 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3964 ++lexer.parsing_type;
3968 --lexer.parsing_type;
3973 anonymous_type_expression
3974 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3976 if (lang_version <= LanguageVersion.ISO_2)
3977 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3979 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3981 // TODO: lbag comma location
3982 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3984 | NEW OPEN_BRACE GENERATE_COMPLETION
3986 $$ = new EmptyCompletion ();
3990 anonymous_type_parameters_opt_comma
3991 : anonymous_type_parameters_opt
3992 | anonymous_type_parameters COMMA
3995 anonymous_type_parameters_opt
3997 | anonymous_type_parameters
4000 anonymous_type_parameters
4001 : anonymous_type_parameter
4003 var a = new List<AnonymousTypeParameter> (4);
4004 a.Add ((AnonymousTypeParameter) $1);
4007 | anonymous_type_parameters COMMA anonymous_type_parameter
4009 var a = (List<AnonymousTypeParameter>) $1;
4010 a.Add ((AnonymousTypeParameter) $3);
4013 | COMPLETE_COMPLETION
4015 $$ = new EmptyCompletion ();
4017 | anonymous_type_parameter COMPLETE_COMPLETION
4023 anonymous_type_parameter
4024 : identifier_inside_body ASSIGN variable_initializer
4026 var lt = (LocatedToken)$1;
4027 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4028 lbag.AddLocation ($$, GetLocation ($2));
4030 | identifier_inside_body
4032 var lt = (LocatedToken)$1;
4033 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4034 lt.Value, lt.Location);
4038 MemberAccess ma = (MemberAccess) $1;
4039 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4043 report.Error (746, lexer.Location,
4044 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4056 | rank_specifier rank_specifiers
4058 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4064 : OPEN_BRACKET CLOSE_BRACKET
4066 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4067 lbag.AddLocation ($$, GetLocation ($2));
4069 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4071 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4072 lbag.AddLocation ($$, GetLocation ($3));
4081 | dim_separators COMMA
4083 $$ = ((int) $1) + 1;
4087 opt_array_initializer
4099 : OPEN_BRACE CLOSE_BRACE
4101 var ai = new ArrayInitializer (0, GetLocation ($1));
4102 ai.VariableDeclaration = current_variable;
4103 lbag.AddLocation (ai, GetLocation ($2));
4106 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4108 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4109 ai.VariableDeclaration = current_variable;
4111 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4113 lbag.AddLocation (ai, GetLocation ($4));
4119 variable_initializer_list
4120 : variable_initializer
4122 var list = new List<Expression> (4);
4123 list.Add ((Expression) $1);
4126 | variable_initializer_list COMMA variable_initializer
4128 var list = (List<Expression>) $1;
4129 list.Add ((Expression) $3);
4135 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4137 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4138 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4142 typeof_type_expression
4146 Error_TypeExpected (lexer.Location);
4154 if (lang_version < LanguageVersion.ISO_2)
4155 FeatureIsNotAvailable (GetLocation ($1), "generics");
4161 qualified_alias_member
4162 : IDENTIFIER DOUBLE_COLON
4164 var lt = (LocatedToken) $1;
4165 if (lang_version == LanguageVersion.ISO_1)
4166 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4173 : SIZEOF open_parens_any type CLOSE_PARENS
4175 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4176 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4178 | SIZEOF open_parens_any type error
4180 Error_SyntaxError (yyToken);
4182 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4183 lbag.AddLocation ($$, GetLocation ($2));
4188 : CHECKED open_parens_any expression CLOSE_PARENS
4190 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4191 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4195 Error_SyntaxError (yyToken);
4197 $$ = new CheckedExpr (null, GetLocation ($1));
4201 unchecked_expression
4202 : UNCHECKED open_parens_any expression CLOSE_PARENS
4204 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4205 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4209 Error_SyntaxError (yyToken);
4211 $$ = new UnCheckedExpr (null, GetLocation ($1));
4215 pointer_member_access
4216 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4218 var lt = (LocatedToken) $3;
4219 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4223 anonymous_method_expression
4224 : DELEGATE opt_anonymous_method_signature
4226 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4230 $$ = end_anonymous ((ParametersBlock) $4);
4232 | ASYNC DELEGATE opt_anonymous_method_signature
4234 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4238 $$ = end_anonymous ((ParametersBlock) $5);
4242 opt_anonymous_method_signature
4245 $$ = ParametersCompiled.Undefined;
4247 | anonymous_method_signature
4250 anonymous_method_signature
4253 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4255 opt_formal_parameter_list CLOSE_PARENS
4257 valid_param_mod = 0;
4262 default_value_expression
4263 : DEFAULT open_parens_any type CLOSE_PARENS
4265 if (lang_version < LanguageVersion.ISO_2)
4266 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4268 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4269 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4274 : primary_expression
4275 | BANG prefixed_unary_expression
4277 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4279 | TILDE prefixed_unary_expression
4281 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4283 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4285 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4286 lbag.AddLocation ($$, GetLocation ($3));
4288 | AWAIT prefixed_unary_expression
4291 if (current_anonymous_method is LambdaExpression) {
4292 report.Error (4034, GetLocation ($1),
4293 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4294 } else if (current_anonymous_method != null) {
4295 report.Error (4035, GetLocation ($1),
4296 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4297 } else if (interactive_async != null) {
4298 current_block.Explicit.RegisterAsyncAwait ();
4299 interactive_async = true;
4301 report.Error (4033, GetLocation ($1),
4302 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4305 current_block.Explicit.RegisterAsyncAwait ();
4308 $$ = new Await ((Expression) $2, GetLocation ($1));
4312 Error_SyntaxError (yyToken);
4314 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4318 Error_SyntaxError (yyToken);
4320 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4322 | OPEN_PARENS_CAST type CLOSE_PARENS error
4324 Error_SyntaxError (yyToken);
4326 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4327 lbag.AddLocation ($$, GetLocation ($3));
4331 Error_SyntaxError (yyToken);
4333 $$ = new Await (null, GetLocation ($1));
4338 // The idea to split this out is from Rhys' grammar
4339 // to solve the problem with casts.
4341 prefixed_unary_expression
4343 | PLUS prefixed_unary_expression
4345 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4347 | MINUS prefixed_unary_expression
4349 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4351 | OP_INC prefixed_unary_expression
4353 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4355 | OP_DEC prefixed_unary_expression
4357 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4359 | STAR prefixed_unary_expression
4361 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4363 | BITWISE_AND prefixed_unary_expression
4365 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4369 Error_SyntaxError (yyToken);
4371 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4375 Error_SyntaxError (yyToken);
4377 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4381 Error_SyntaxError (yyToken);
4383 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4387 Error_SyntaxError (yyToken);
4389 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4393 Error_SyntaxError (yyToken);
4395 $$ = new Indirection (null, GetLocation ($1));
4399 Error_SyntaxError (yyToken);
4401 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4405 multiplicative_expression
4406 : prefixed_unary_expression
4407 | multiplicative_expression STAR prefixed_unary_expression
4409 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4410 lbag.AddLocation ($$, GetLocation ($2));
4412 | multiplicative_expression DIV prefixed_unary_expression
4414 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4415 lbag.AddLocation ($$, GetLocation ($2));
4417 | multiplicative_expression PERCENT prefixed_unary_expression
4419 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4420 lbag.AddLocation ($$, GetLocation ($2));
4422 | multiplicative_expression STAR error
4424 Error_SyntaxError (yyToken);
4426 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4427 lbag.AddLocation ($$, GetLocation ($2));
4429 | multiplicative_expression DIV error
4431 Error_SyntaxError (yyToken);
4433 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4434 lbag.AddLocation ($$, GetLocation ($2));
4436 | multiplicative_expression PERCENT error
4438 Error_SyntaxError (yyToken);
4440 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4441 lbag.AddLocation ($$, GetLocation ($2));
4446 : multiplicative_expression
4447 | additive_expression PLUS multiplicative_expression
4449 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4450 lbag.AddLocation ($$, GetLocation ($2));
4452 | additive_expression MINUS multiplicative_expression
4454 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4455 lbag.AddLocation ($$, GetLocation ($2));
4457 | additive_expression PLUS error
4459 Error_SyntaxError (yyToken);
4461 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4462 lbag.AddLocation ($$, GetLocation ($2));
4464 | additive_expression MINUS error
4466 Error_SyntaxError (yyToken);
4468 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4469 lbag.AddLocation ($$, GetLocation ($2));
4471 | additive_expression AS type
4473 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4475 | additive_expression IS pattern_type_expr opt_identifier
4477 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4479 if (lang_version != LanguageVersion.Experimental)
4480 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4482 var lt = (LocatedToken) $4;
4483 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4484 current_block.AddLocalName (is_expr.Variable);
4489 | additive_expression IS pattern_expr
4491 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4492 if (lang_version != LanguageVersion.Experimental)
4493 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4497 | additive_expression AS error
4499 Error_SyntaxError (yyToken);
4501 $$ = new As ((Expression) $1, null, GetLocation ($2));
4503 | additive_expression IS error
4505 Error_SyntaxError (yyToken);
4507 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4511 var lt = (LocatedToken) $1;
4512 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4516 var lt = (LocatedToken) $1;
4517 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4527 | PLUS prefixed_unary_expression
4529 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4531 | MINUS prefixed_unary_expression
4533 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4536 | default_value_expression
4537 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4539 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4540 lbag.AddLocation ($$, GetLocation ($3));
4544 $$ = new WildcardPattern (GetLocation ($1));
4546 | pattern_expr_invocation
4550 pattern_expr_invocation
4551 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4553 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4558 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4560 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4564 pattern_property_list
4565 : pattern_property_entry
4567 var list = new List<PropertyPatternMember> ();
4568 list.Add ((PropertyPatternMember) $1);
4571 | pattern_property_list COMMA pattern_property_entry
4573 var list = (List<PropertyPatternMember>) $1;
4574 list.Add ((PropertyPatternMember) $3);
4579 pattern_property_entry
4580 : identifier_inside_body IS pattern
4582 var lt = (LocatedToken) $1;
4583 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4589 | pattern_type_expr opt_identifier
4592 var lt = (LocatedToken) $2;
4593 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4594 current_block.AddLocalName (variable);
4602 $$ = new Arguments (0);
4610 Arguments args = new Arguments (4);
4611 args.Add ((Argument) $1);
4614 | pattern_list COMMA pattern_argument
4616 Arguments args = (Arguments) $1;
4617 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4618 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4620 args.Add ((Argument) $3);
4628 $$ = new Argument ((Expression) $1);
4630 | IDENTIFIER COLON pattern
4632 var lt = (LocatedToken) $1;
4633 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4638 : additive_expression
4639 | shift_expression OP_SHIFT_LEFT additive_expression
4641 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4642 lbag.AddLocation ($$, GetLocation ($2));
4644 | shift_expression OP_SHIFT_RIGHT additive_expression
4646 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4647 lbag.AddLocation ($$, GetLocation ($2));
4649 | shift_expression OP_SHIFT_LEFT error
4651 Error_SyntaxError (yyToken);
4653 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4654 lbag.AddLocation ($$, GetLocation ($2));
4656 | shift_expression OP_SHIFT_RIGHT error
4658 Error_SyntaxError (yyToken);
4660 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4661 lbag.AddLocation ($$, GetLocation ($2));
4665 relational_expression
4667 | relational_expression OP_LT shift_expression
4669 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4670 lbag.AddLocation ($$, GetLocation ($2));
4672 | relational_expression OP_GT shift_expression
4674 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4675 lbag.AddLocation ($$, GetLocation ($2));
4677 | relational_expression OP_LE shift_expression
4679 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4680 lbag.AddLocation ($$, GetLocation ($2));
4682 | relational_expression OP_GE shift_expression
4684 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4685 lbag.AddLocation ($$, GetLocation ($2));
4687 | relational_expression OP_LT error
4689 Error_SyntaxError (yyToken);
4691 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4692 lbag.AddLocation ($$, GetLocation ($2));
4694 | relational_expression OP_GT error
4696 Error_SyntaxError (yyToken);
4698 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4699 lbag.AddLocation ($$, GetLocation ($2));
4701 | relational_expression OP_LE error
4703 Error_SyntaxError (yyToken);
4705 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4706 lbag.AddLocation ($$, GetLocation ($2));
4708 | relational_expression OP_GE error
4710 Error_SyntaxError (yyToken);
4712 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4713 lbag.AddLocation ($$, GetLocation ($2));
4718 : relational_expression
4719 | equality_expression OP_EQ relational_expression
4721 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4722 lbag.AddLocation ($$, GetLocation ($2));
4724 | equality_expression OP_NE relational_expression
4726 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4727 lbag.AddLocation ($$, GetLocation ($2));
4729 | equality_expression OP_EQ error
4731 Error_SyntaxError (yyToken);
4733 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4734 lbag.AddLocation ($$, GetLocation ($2));
4736 | equality_expression OP_NE error
4738 Error_SyntaxError (yyToken);
4740 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4741 lbag.AddLocation ($$, GetLocation ($2));
4746 : equality_expression
4747 | and_expression BITWISE_AND equality_expression
4749 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4750 lbag.AddLocation ($$, GetLocation ($2));
4752 | and_expression BITWISE_AND error
4754 Error_SyntaxError (yyToken);
4756 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4757 lbag.AddLocation ($$, GetLocation ($2));
4761 exclusive_or_expression
4763 | exclusive_or_expression CARRET and_expression
4765 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4766 lbag.AddLocation ($$, GetLocation ($2));
4768 | exclusive_or_expression CARRET error
4770 Error_SyntaxError (yyToken);
4772 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4773 lbag.AddLocation ($$, GetLocation ($2));
4777 inclusive_or_expression
4778 : exclusive_or_expression
4779 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4781 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4782 lbag.AddLocation ($$, GetLocation ($2));
4784 | inclusive_or_expression BITWISE_OR error
4786 Error_SyntaxError (yyToken);
4788 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4789 lbag.AddLocation ($$, GetLocation ($2));
4793 conditional_and_expression
4794 : inclusive_or_expression
4795 | conditional_and_expression OP_AND inclusive_or_expression
4797 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4798 lbag.AddLocation ($$, GetLocation ($2));
4800 | conditional_and_expression OP_AND error
4802 Error_SyntaxError (yyToken);
4804 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4805 lbag.AddLocation ($$, GetLocation ($2));
4809 conditional_or_expression
4810 : conditional_and_expression
4811 | conditional_or_expression OP_OR conditional_and_expression
4813 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4814 lbag.AddLocation ($$, GetLocation ($2));
4816 | conditional_or_expression OP_OR error
4818 Error_SyntaxError (yyToken);
4820 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4821 lbag.AddLocation ($$, GetLocation ($2));
4825 null_coalescing_expression
4826 : conditional_or_expression
4827 | conditional_or_expression OP_COALESCING null_coalescing_expression
4829 if (lang_version < LanguageVersion.ISO_2)
4830 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4832 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4833 lbag.AddLocation ($$, GetLocation ($2));
4837 conditional_expression
4838 : null_coalescing_expression
4839 | null_coalescing_expression INTERR expression COLON expression
4841 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4842 lbag.AddLocation ($$, GetLocation ($4));
4844 | null_coalescing_expression INTERR expression error
4846 Error_SyntaxError (yyToken);
4848 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4850 | null_coalescing_expression INTERR expression COLON error
4852 Error_SyntaxError (yyToken);
4854 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4855 lbag.AddLocation ($$, GetLocation ($4));
4857 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4859 Error_SyntaxError (Token.CLOSE_BRACE);
4861 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4862 lbag.AddLocation ($$, GetLocation ($4));
4863 lexer.putback ('}');
4867 assignment_expression
4868 : prefixed_unary_expression ASSIGN expression
4870 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4871 lbag.AddLocation ($$, GetLocation ($2));
4873 | prefixed_unary_expression OP_MULT_ASSIGN expression
4875 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4876 lbag.AddLocation ($$, GetLocation ($2));
4878 | prefixed_unary_expression OP_DIV_ASSIGN expression
4880 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4881 lbag.AddLocation ($$, GetLocation ($2));
4883 | prefixed_unary_expression OP_MOD_ASSIGN expression
4885 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4886 lbag.AddLocation ($$, GetLocation ($2));
4888 | prefixed_unary_expression OP_ADD_ASSIGN expression
4890 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4891 lbag.AddLocation ($$, GetLocation ($2));
4893 | prefixed_unary_expression OP_SUB_ASSIGN expression
4895 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4896 lbag.AddLocation ($$, GetLocation ($2));
4898 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4900 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4901 lbag.AddLocation ($$, GetLocation ($2));
4903 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4905 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4906 lbag.AddLocation ($$, GetLocation ($2));
4908 | prefixed_unary_expression OP_AND_ASSIGN expression
4910 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4911 lbag.AddLocation ($$, GetLocation ($2));
4913 | prefixed_unary_expression OP_OR_ASSIGN expression
4915 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4916 lbag.AddLocation ($$, GetLocation ($2));
4918 | prefixed_unary_expression OP_XOR_ASSIGN expression
4920 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4921 lbag.AddLocation ($$, GetLocation ($2));
4925 lambda_parameter_list
4928 var pars = new List<Parameter> (4);
4929 pars.Add ((Parameter) $1);
4933 | lambda_parameter_list COMMA lambda_parameter
4935 var pars = (List<Parameter>) $1;
4936 Parameter p = (Parameter)$3;
4937 if (pars[0].GetType () != p.GetType ()) {
4938 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4947 : parameter_modifier parameter_type identifier_inside_body
4949 var lt = (LocatedToken) $3;
4951 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4953 | parameter_type identifier_inside_body
4955 var lt = (LocatedToken) $2;
4957 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4961 var lt = (LocatedToken) $1;
4962 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4966 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4967 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4971 opt_lambda_parameter_list
4972 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4973 | lambda_parameter_list {
4974 var pars_list = (List<Parameter>) $1;
4975 $$ = new ParametersCompiled (pars_list.ToArray ());
4979 lambda_expression_body
4981 start_block (Location.Null);
4983 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4985 Block b = end_block (Location.Null);
4986 b.IsCompilerGenerated = true;
4987 b.AddStatement (new ContextualReturn ((Expression) $2));
4993 // Handles only cases like foo = x.FirstOrDefault (l => );
4994 // where we must restore current_variable
4995 Block b = end_block (Location.Null);
4996 b.IsCompilerGenerated = true;
4998 Error_SyntaxError (yyToken);
5007 Error_SyntaxError (yyToken);
5015 var lt = (LocatedToken) $1;
5016 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5017 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5019 lambda_expression_body
5021 $$ = end_anonymous ((ParametersBlock) $4);
5022 lbag.AddLocation ($$, GetLocation ($2));
5026 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5027 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5028 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5030 lambda_expression_body
5032 $$ = end_anonymous ((ParametersBlock) $4);
5033 lbag.AddLocation ($$, GetLocation ($2));
5035 | ASYNC identifier_inside_body ARROW
5037 var lt = (LocatedToken) $2;
5038 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5039 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5041 lambda_expression_body
5043 $$ = end_anonymous ((ParametersBlock) $5);
5044 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5046 | OPEN_PARENS_LAMBDA
5048 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5050 opt_lambda_parameter_list CLOSE_PARENS ARROW
5052 valid_param_mod = 0;
5053 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5055 lambda_expression_body
5057 $$ = end_anonymous ((ParametersBlock) $7);
5058 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5060 | ASYNC OPEN_PARENS_LAMBDA
5062 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5064 opt_lambda_parameter_list CLOSE_PARENS ARROW
5066 valid_param_mod = 0;
5067 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5069 lambda_expression_body
5071 $$ = end_anonymous ((ParametersBlock) $8);
5072 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5077 : assignment_expression
5078 | non_assignment_expression
5081 non_assignment_expression
5082 : conditional_expression
5087 $$ = new ArglistAccess (GetLocation ($1));
5091 undocumented_expressions
5092 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5094 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5095 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5097 | REFTYPE open_parens_any expression CLOSE_PARENS
5099 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5100 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5102 | MAKEREF open_parens_any expression CLOSE_PARENS
5104 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5105 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5116 $$ = new BooleanExpression ((Expression) $1);
5120 opt_primary_parameters
5125 | primary_parameters
5129 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5133 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5134 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5136 if (lang_version != LanguageVersion.Experimental)
5137 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5141 opt_primary_parameters_with_class_base
5150 | primary_parameters
5154 | primary_parameters class_base
5158 | primary_parameters class_base OPEN_PARENS
5160 ++lexer.parsing_block;
5161 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5163 opt_argument_list CLOSE_PARENS
5165 lbag.AppendToMember (current_container, GetLocation ($6));
5166 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5167 --lexer.parsing_block;
5183 type_declaration_name
5185 lexer.ConstraintsParsing = true;
5187 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5188 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5189 FeatureIsNotAvailable (c.Location, "static classes");
5192 push_current_container (c, $3);
5193 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5195 opt_primary_parameters_with_class_base
5196 opt_type_parameter_constraints_clauses
5198 valid_param_mod = 0;
5199 lexer.ConstraintsParsing = false;
5202 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5205 current_container.SetConstraints ((List<Constraints>) $9);
5206 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5209 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5210 Lexer.doc_state = XmlCommentState.Allowed;
5213 lexer.parsing_modifiers = true;
5215 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5217 --lexer.parsing_declaration;
5219 Lexer.doc_state = XmlCommentState.Allowed;
5224 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5226 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5228 $$ = pop_current_class ();
5236 { $$ = $1; } // location
5242 mod_locations = null;
5244 lexer.parsing_modifiers = false;
5248 lexer.parsing_modifiers = false;
5254 | modifiers modifier
5256 var m1 = (Modifiers) $1;
5257 var m2 = (Modifiers) $2;
5259 if ((m1 & m2) != 0) {
5260 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5261 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5262 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5263 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5264 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5265 "More than one protection modifier specified");
5276 StoreModifierLocation ($$, GetLocation ($1));
5278 if (current_container.Kind == MemberKind.Namespace)
5279 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5283 $$ = Modifiers.PUBLIC;
5284 StoreModifierLocation ($$, GetLocation ($1));
5288 $$ = Modifiers.PROTECTED;
5289 StoreModifierLocation ($$, GetLocation ($1));
5293 $$ = Modifiers.INTERNAL;
5294 StoreModifierLocation ($$, GetLocation ($1));
5298 $$ = Modifiers.PRIVATE;
5299 StoreModifierLocation ($$, GetLocation ($1));
5303 $$ = Modifiers.ABSTRACT;
5304 StoreModifierLocation ($$, GetLocation ($1));
5308 $$ = Modifiers.SEALED;
5309 StoreModifierLocation ($$, GetLocation ($1));
5313 $$ = Modifiers.STATIC;
5314 StoreModifierLocation ($$, GetLocation ($1));
5318 $$ = Modifiers.READONLY;
5319 StoreModifierLocation ($$, GetLocation ($1));
5323 $$ = Modifiers.VIRTUAL;
5324 StoreModifierLocation ($$, GetLocation ($1));
5328 $$ = Modifiers.OVERRIDE;
5329 StoreModifierLocation ($$, GetLocation ($1));
5333 $$ = Modifiers.EXTERN;
5334 StoreModifierLocation ($$, GetLocation ($1));
5338 $$ = Modifiers.VOLATILE;
5339 StoreModifierLocation ($$, GetLocation ($1));
5343 $$ = Modifiers.UNSAFE;
5344 StoreModifierLocation ($$, GetLocation ($1));
5345 if (!settings.Unsafe)
5346 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5350 $$ = Modifiers.ASYNC;
5351 StoreModifierLocation ($$, GetLocation ($1));
5363 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5365 | COLON type_list error
5367 Error_SyntaxError (yyToken);
5369 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5373 opt_type_parameter_constraints_clauses
5375 | type_parameter_constraints_clauses
5381 type_parameter_constraints_clauses
5382 : type_parameter_constraints_clause
5384 var constraints = new List<Constraints> (1);
5385 constraints.Add ((Constraints) $1);
5388 | type_parameter_constraints_clauses type_parameter_constraints_clause
5390 var constraints = (List<Constraints>) $1;
5391 Constraints new_constraint = (Constraints)$2;
5393 foreach (Constraints c in constraints) {
5394 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5395 report.Error (409, new_constraint.Location,
5396 "A constraint clause has already been specified for type parameter `{0}'",
5397 new_constraint.TypeParameter.Value);
5401 constraints.Add (new_constraint);
5406 type_parameter_constraints_clause
5407 : WHERE IDENTIFIER COLON type_parameter_constraints
5409 var lt = (LocatedToken) $2;
5410 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5411 lbag.AddLocation ($$, GetLocation ($3));
5413 | WHERE IDENTIFIER error
5415 Error_SyntaxError (yyToken);
5417 var lt = (LocatedToken) $2;
5418 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5422 type_parameter_constraints
5423 : type_parameter_constraint
5425 var constraints = new List<FullNamedExpression> (1);
5426 constraints.Add ((FullNamedExpression) $1);
5429 | type_parameter_constraints COMMA type_parameter_constraint
5431 var constraints = (List<FullNamedExpression>) $1;
5432 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5433 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5434 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5437 prev = $3 as SpecialContraintExpr;
5439 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5440 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5442 prev = constraints [0] as SpecialContraintExpr;
5443 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5444 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5449 constraints.Add ((FullNamedExpression) $3);
5454 type_parameter_constraint
5457 if ($1 is ComposedCast)
5458 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5462 | NEW OPEN_PARENS CLOSE_PARENS
5464 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5465 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5469 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5473 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5477 opt_type_parameter_variance
5482 | type_parameter_variance
5484 if (lang_version <= LanguageVersion.V_3)
5485 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5491 type_parameter_variance
5494 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5498 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5507 // A block is "contained" on the following places:
5509 // property_declaration as part of the accessor body (get/set)
5510 // operator_declaration
5511 // constructor_declaration
5512 // destructor_declaration
5513 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5518 ++lexer.parsing_block;
5519 start_block (GetLocation ($1));
5521 opt_statement_list block_end
5530 --lexer.parsing_block;
5531 $$ = end_block (GetLocation ($1));
5533 | COMPLETE_COMPLETION
5535 --lexer.parsing_block;
5536 $$ = end_block (lexer.Location);
5544 ++lexer.parsing_block;
5545 current_block.StartLocation = GetLocation ($1);
5547 opt_statement_list CLOSE_BRACE
5549 --lexer.parsing_block;
5550 $$ = end_block (GetLocation ($4));
5561 | statement_list statement
5565 : block_variable_declaration
5567 current_block.AddStatement ((Statement) $1);
5569 | valid_declaration_statement
5571 current_block.AddStatement ((Statement) $1);
5576 Error_SyntaxError (yyToken);
5582 // The interactive_statement and its derivatives are only
5583 // used to provide a special version of `expression_statement'
5584 // that has a side effect of assigning the expression to
5587 interactive_statement_list
5588 : interactive_statement
5589 | interactive_statement_list interactive_statement
5592 interactive_statement
5593 : block_variable_declaration
5595 current_block.AddStatement ((Statement) $1);
5597 | interactive_valid_declaration_statement
5599 current_block.AddStatement ((Statement) $1);
5604 valid_declaration_statement
5607 | expression_statement
5608 | selection_statement
5609 | iteration_statement
5613 | unchecked_statement
5620 interactive_valid_declaration_statement
5623 | interactive_expression_statement
5624 | selection_statement
5625 | iteration_statement
5629 | unchecked_statement
5637 : valid_declaration_statement
5638 | block_variable_declaration
5640 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5645 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5650 Error_SyntaxError (yyToken);
5651 $$ = new EmptyStatement (GetLocation ($1));
5658 // Uses lexer.Location because semicolon location is not kept in quick mode
5659 $$ = new EmptyStatement (lexer.Location);
5664 : identifier_inside_body COLON
5666 var lt = (LocatedToken) $1;
5667 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5668 lbag.AddLocation (labeled, GetLocation ($2));
5669 current_block.AddLabel (labeled);
5670 current_block.AddStatement (labeled);
5676 : variable_type_simple
5677 | variable_type_simple rank_specifiers
5680 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5682 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5687 * The following is from Rhys' grammar:
5688 * > Types in local variable declarations must be recognized as
5689 * > expressions to prevent reduce/reduce errors in the grammar.
5690 * > The expressions are converted into types during semantic analysis.
5692 variable_type_simple
5693 : type_name_expression opt_nullable
5695 // Ok, the above "primary_expression" is there to get rid of
5696 // both reduce/reduce and shift/reduces in the grammar, it should
5697 // really just be "type_name". If you use type_name, a reduce/reduce
5698 // creeps up. If you use namespace_or_type_name (which is all we need
5699 // really) two shift/reduces appear.
5702 // So the super-trick is that primary_expression
5703 // can only be either a SimpleName or a MemberAccess.
5704 // The MemberAccess case arises when you have a fully qualified type-name like :
5706 // SimpleName is when you have
5709 var expr = (ATypeNameExpression) $1;
5711 if (expr.Name == "var" && expr is SimpleName)
5712 $$ = new VarExpr (expr.Location);
5716 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5719 | type_name_expression pointer_stars
5721 var expr = (ATypeNameExpression) $1;
5722 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5724 | builtin_type_expression
5730 | pointer_star pointer_stars
5732 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5740 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5744 identifier_inside_body
5748 $$ = Error_AwaitAsIdentifier ($1);
5752 block_variable_declaration
5753 : variable_type identifier_inside_body
5755 var lt = (LocatedToken) $2;
5756 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5757 current_block.AddLocalName (li);
5758 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5760 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5762 $$ = current_variable;
5763 current_variable = null;
5765 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5767 lbag.AddLocation ($$, GetLocation ($6));
5769 | CONST variable_type identifier_inside_body
5771 var lt = (LocatedToken) $3;
5772 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5773 current_block.AddLocalName (li);
5774 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5776 const_variable_initializer opt_const_declarators SEMICOLON
5778 $$ = current_variable;
5779 current_variable = null;
5780 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5784 opt_local_variable_initializer
5786 | ASSIGN block_variable_initializer
5788 current_variable.Initializer = (Expression) $2;
5789 PushLocation (GetLocation ($1));
5790 $$ = current_variable;
5794 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5795 report.Error (650, lexer.Location,
5796 "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");
5798 Error_SyntaxError (yyToken);
5803 opt_variable_declarators
5805 | variable_declarators
5808 opt_using_or_fixed_variable_declarators
5810 | variable_declarators
5812 foreach (var d in current_variable.Declarators) {
5813 if (d.Initializer == null)
5814 Error_MissingInitializer (d.Variable.Location);
5819 variable_declarators
5820 : variable_declarator
5821 | variable_declarators variable_declarator
5825 : COMMA identifier_inside_body
5827 var lt = (LocatedToken) $2;
5828 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5829 var d = new BlockVariableDeclarator (li, null);
5830 current_variable.AddDeclarator (d);
5831 current_block.AddLocalName (li);
5832 lbag.AddLocation (d, GetLocation ($1));
5834 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5836 var lt = (LocatedToken) $2;
5837 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5838 var d = new BlockVariableDeclarator (li, (Expression) $4);
5839 current_variable.AddDeclarator (d);
5840 current_block.AddLocalName (li);
5841 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5845 const_variable_initializer
5848 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5850 | ASSIGN constant_initializer_expr
5852 current_variable.Initializer = (Expression) $2;
5856 opt_const_declarators
5863 | const_declarators const_declarator
5867 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5869 var lt = (LocatedToken) $2;
5870 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5871 var d = new BlockVariableDeclarator (li, (Expression) $4);
5872 current_variable.AddDeclarator (d);
5873 current_block.AddLocalName (li);
5874 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5878 block_variable_initializer
5879 : variable_initializer
5880 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5882 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5883 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5885 | STACKALLOC simple_type
5887 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5888 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5892 expression_statement
5893 : statement_expression SEMICOLON
5896 lbag.AddStatement ($$, GetLocation ($2));
5898 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5899 | statement_expression CLOSE_BRACE
5902 report.Error (1002, GetLocation ($2), "; expected");
5903 lexer.putback ('}');
5907 interactive_expression_statement
5908 : interactive_statement_expression SEMICOLON { $$ = $1; }
5909 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5913 // We have to do the wrapping here and not in the case above,
5914 // because statement_expression is used for example in for_statement
5916 statement_expression
5919 ExpressionStatement s = $1 as ExpressionStatement;
5921 var expr = $1 as Expression;
5922 $$ = new StatementErrorExpression (expr);
5924 $$ = new StatementExpression (s);
5929 interactive_statement_expression
5932 Expression expr = (Expression) $1;
5933 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5937 Error_SyntaxError (yyToken);
5938 $$ = new EmptyStatement (GetLocation ($1));
5948 : IF open_parens_any boolean_expression CLOSE_PARENS
5951 if ($5 is EmptyStatement)
5952 Warning_EmptyStatement (GetLocation ($5));
5954 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5955 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5957 | IF open_parens_any boolean_expression CLOSE_PARENS
5958 embedded_statement ELSE embedded_statement
5960 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5961 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5963 if ($5 is EmptyStatement)
5964 Warning_EmptyStatement (GetLocation ($5));
5965 if ($7 is EmptyStatement)
5966 Warning_EmptyStatement (GetLocation ($7));
5968 | IF open_parens_any boolean_expression error
5970 Error_SyntaxError (yyToken);
5972 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5973 lbag.AddStatement ($$, GetLocation ($2));
5978 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5980 start_block (GetLocation ($5));
5982 opt_switch_sections CLOSE_BRACE
5984 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5985 end_block (GetLocation ($8));
5986 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5988 | SWITCH open_parens_any expression error
5990 Error_SyntaxError (yyToken);
5992 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5993 lbag.AddStatement ($$, GetLocation ($2));
6000 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6007 | switch_sections switch_section
6010 Error_SyntaxError (yyToken);
6015 : switch_labels statement_list
6021 var label = (SwitchLabel) $1;
6022 label.SectionStart = true;
6023 current_block.AddStatement (label);
6025 | switch_labels switch_label
6027 current_block.AddStatement ((Statement) $2);
6032 : CASE constant_expression COLON
6034 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6035 lbag.AddLocation ($$, GetLocation ($3));
6037 | CASE constant_expression error
6039 Error_SyntaxError (yyToken);
6040 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6043 | CASE pattern_expr_invocation COLON
6045 if (lang_version != LanguageVersion.Experimental)
6046 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6048 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6049 PatternMatching = true
6051 lbag.AddLocation ($$, GetLocation ($3));
6056 $$ = new SwitchLabel (null, GetLocation ($1));
6068 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6070 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6071 Warning_EmptyStatement (GetLocation ($5));
6073 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6074 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6076 | WHILE open_parens_any boolean_expression error
6078 Error_SyntaxError (yyToken);
6080 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6081 lbag.AddStatement ($$, GetLocation ($2));
6086 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6088 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6089 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6091 | DO embedded_statement error
6093 Error_SyntaxError (yyToken);
6094 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6096 | DO embedded_statement WHILE open_parens_any boolean_expression error
6098 Error_SyntaxError (yyToken);
6100 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6101 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6106 : FOR open_parens_any
6108 start_block (GetLocation ($2));
6109 current_block.IsCompilerGenerated = true;
6110 For f = new For (GetLocation ($1));
6111 current_block.AddStatement (f);
6120 // Has to use be extra rule to recover started block
6122 : opt_for_initializer SEMICOLON
6124 ((For) $0).Initializer = (Statement) $1;
6126 // Pass the "For" object to the iterator_part4
6127 oob_stack.Push ($0);
6129 for_condition_and_iterator_part
6132 var locations = (Tuple<Location,Location>) $4;
6134 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6135 Warning_EmptyStatement (GetLocation ($5));
6138 f.Statement = (Statement) $5;
6139 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6141 $$ = end_block (GetLocation ($2));
6145 Error_SyntaxError (yyToken);
6146 $$ = end_block (current_block.StartLocation);
6150 for_condition_and_iterator_part
6151 : opt_for_condition SEMICOLON
6153 For f = (For) oob_stack.Peek ();
6154 f.Condition = (BooleanExpression) $1;
6157 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6160 // Handle errors in the case of opt_for_condition being followed by
6161 // a close parenthesis
6162 | opt_for_condition close_parens_close_brace {
6163 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6164 For f = (For) oob_stack.Peek ();
6165 f.Condition = (BooleanExpression) $1;
6166 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6171 : opt_for_iterator CLOSE_PARENS {
6172 For f = (For) oob_stack.Peek ();
6173 f.Iterator = (Statement) $1;
6174 $$ = GetLocation ($2);
6176 | opt_for_iterator CLOSE_BRACE {
6177 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6178 For f = (For) oob_stack.Peek ();
6179 f.Iterator = (Statement) $1;
6180 $$ = GetLocation ($2);
6184 close_parens_close_brace
6186 | CLOSE_BRACE { lexer.putback ('}'); }
6190 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6195 : variable_type identifier_inside_body
6197 var lt = (LocatedToken) $2;
6198 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6199 current_block.AddLocalName (li);
6200 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6202 opt_local_variable_initializer opt_variable_declarators
6204 $$ = current_variable;
6206 lbag.AddLocation (current_variable, PopLocation ());
6208 current_variable = null;
6210 | statement_expression_list
6214 : /* empty */ { $$ = null; }
6215 | boolean_expression
6219 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6224 : statement_expression_list
6227 statement_expression_list
6228 : statement_expression
6229 | statement_expression_list COMMA statement_expression
6231 var sl = $1 as StatementList;
6233 sl = new StatementList ((Statement) $1, (Statement) $3);
6234 lbag.AddStatement (sl, GetLocation ($2));
6236 sl.Add ((Statement) $3);
6237 lbag.AppendTo (sl, GetLocation ($2));
6245 : FOREACH open_parens_any type error
6247 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6249 start_block (GetLocation ($2));
6250 current_block.IsCompilerGenerated = true;
6252 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6253 current_block.AddStatement (f);
6255 lbag.AddStatement (f, GetLocation ($2));
6256 $$ = end_block (GetLocation ($4));
6258 | FOREACH open_parens_any type identifier_inside_body error
6260 Error_SyntaxError (yyToken);
6262 start_block (GetLocation ($2));
6263 current_block.IsCompilerGenerated = true;
6265 var lt = (LocatedToken) $4;
6266 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6267 current_block.AddLocalName (li);
6269 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6270 current_block.AddStatement (f);
6272 lbag.AddStatement (f, GetLocation ($2));
6273 $$ = end_block (GetLocation ($5));
6275 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6277 start_block (GetLocation ($2));
6278 current_block.IsCompilerGenerated = true;
6280 var lt = (LocatedToken) $4;
6281 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6282 current_block.AddLocalName (li);
6287 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6288 Warning_EmptyStatement (GetLocation ($9));
6290 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6291 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6292 end_block (GetLocation ($7));
6300 | continue_statement
6310 $$ = new Break (GetLocation ($1));
6311 lbag.AddStatement ($$, GetLocation ($2));
6316 : CONTINUE SEMICOLON
6318 $$ = new Continue (GetLocation ($1));
6319 lbag.AddStatement ($$, GetLocation ($2));
6323 Error_SyntaxError (yyToken);
6324 $$ = new Continue (GetLocation ($1));
6329 : GOTO identifier_inside_body SEMICOLON
6331 var lt = (LocatedToken) $2;
6332 $$ = new Goto (lt.Value, GetLocation ($1));
6333 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6335 | GOTO CASE constant_expression SEMICOLON
6337 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6338 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6340 | GOTO DEFAULT SEMICOLON
6342 $$ = new GotoDefault (GetLocation ($1));
6343 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6348 : RETURN opt_expression SEMICOLON
6350 $$ = new Return ((Expression) $2, GetLocation ($1));
6351 lbag.AddStatement ($$, GetLocation ($3));
6353 | RETURN expression error
6355 Error_SyntaxError (yyToken);
6356 $$ = new Return ((Expression) $2, GetLocation ($1));
6360 Error_SyntaxError (yyToken);
6361 $$ = new Return (null, GetLocation ($1));
6366 : THROW opt_expression SEMICOLON
6368 $$ = new Throw ((Expression) $2, GetLocation ($1));
6369 lbag.AddStatement ($$, GetLocation ($3));
6371 | THROW expression error
6373 Error_SyntaxError (yyToken);
6374 $$ = new Throw ((Expression) $2, GetLocation ($1));
6378 Error_SyntaxError (yyToken);
6379 $$ = new Throw (null, GetLocation ($1));
6384 : identifier_inside_body RETURN opt_expression SEMICOLON
6386 var lt = (LocatedToken) $1;
6387 string s = lt.Value;
6389 report.Error (1003, lt.Location, "; expected");
6390 } else if ($3 == null) {
6391 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6392 } else if (lang_version == LanguageVersion.ISO_1){
6393 FeatureIsNotAvailable (lt.Location, "iterators");
6396 current_block.Explicit.RegisterIteratorYield ();
6397 $$ = new Yield ((Expression) $3, lt.Location);
6398 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6400 | identifier_inside_body RETURN expression error
6402 Error_SyntaxError (yyToken);
6404 var lt = (LocatedToken) $1;
6405 string s = lt.Value;
6407 report.Error (1003, lt.Location, "; expected");
6408 } else if ($3 == null) {
6409 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6410 } else if (lang_version == LanguageVersion.ISO_1){
6411 FeatureIsNotAvailable (lt.Location, "iterators");
6414 current_block.Explicit.RegisterIteratorYield ();
6415 $$ = new Yield ((Expression) $3, lt.Location);
6416 lbag.AddStatement ($$, GetLocation ($2));
6418 | identifier_inside_body BREAK SEMICOLON
6420 var lt = (LocatedToken) $1;
6421 string s = lt.Value;
6423 report.Error (1003, lt.Location, "; expected");
6424 } else if (lang_version == LanguageVersion.ISO_1){
6425 FeatureIsNotAvailable (lt.Location, "iterators");
6428 current_block.ParametersBlock.TopBlock.IsIterator = true;
6429 $$ = new YieldBreak (lt.Location);
6430 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6440 : TRY block catch_clauses
6442 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6444 | TRY block FINALLY block
6446 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6447 lbag.AddStatement ($$, GetLocation ($3));
6449 | TRY block catch_clauses FINALLY block
6451 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6452 lbag.AddStatement ($$, GetLocation ($4));
6456 Error_SyntaxError (1524, yyToken);
6457 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6464 var l = new List<Catch> (2);
6469 | catch_clauses catch_clause
6471 var l = (List<Catch>) $1;
6473 Catch c = (Catch) $2;
6474 var prev_catch = l [l.Count - 1];
6475 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6476 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6486 | identifier_inside_body
6490 : CATCH opt_catch_filter block
6492 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6493 c.Filter = (CatchFilterExpression) $2;
6496 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6498 start_block (GetLocation ($2));
6499 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6500 c.TypeExpression = (FullNamedExpression) $3;
6503 var lt = (LocatedToken) $4;
6504 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6505 current_block.AddLocalName (c.Variable);
6508 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6510 lexer.parsing_catch_when = true;
6512 opt_catch_filter_or_error
6514 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6517 | CATCH open_parens_any error
6519 if (yyToken == Token.CLOSE_PARENS) {
6520 report.Error (1015, lexer.Location,
6521 "A type that derives from `System.Exception', `object', or `string' expected");
6523 Error_SyntaxError (yyToken);
6526 $$ = new Catch (null, GetLocation ($1));
6530 opt_catch_filter_or_error
6531 : opt_catch_filter block_prepared
6537 end_block (Location.Null);
6538 Error_SyntaxError (yyToken);
6545 lexer.parsing_catch_when = false;
6549 lexer.parsing_catch_when = false;
6551 open_parens_any expression CLOSE_PARENS
6553 if (lang_version <= LanguageVersion.V_5)
6554 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6556 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6557 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6564 $$ = new Checked ((Block) $2, GetLocation ($1));
6571 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6578 if (!settings.Unsafe)
6579 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6581 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6586 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6588 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6589 Warning_EmptyStatement (GetLocation ($5));
6591 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6592 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6594 | LOCK open_parens_any expression error
6596 Error_SyntaxError (yyToken);
6598 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6599 lbag.AddStatement ($$, GetLocation ($2));
6604 : FIXED open_parens_any variable_type identifier_inside_body
6606 start_block (GetLocation ($2));
6608 current_block.IsCompilerGenerated = true;
6609 var lt = (LocatedToken) $4;
6610 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6611 current_block.AddLocalName (li);
6612 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6614 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6616 $$ = current_variable;
6617 current_variable = null;
6621 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6622 Warning_EmptyStatement (GetLocation ($10));
6624 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6625 current_block.AddStatement (f);
6626 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6627 $$ = end_block (GetLocation ($8));
6632 : USING open_parens_any variable_type identifier_inside_body
6634 start_block (GetLocation ($2));
6636 current_block.IsCompilerGenerated = true;
6637 var lt = (LocatedToken) $4;
6638 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6639 current_block.AddLocalName (li);
6640 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6642 using_initialization CLOSE_PARENS
6644 $$ = current_variable;
6645 current_variable = null;
6649 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6650 Warning_EmptyStatement (GetLocation ($9));
6652 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6653 current_block.AddStatement (u);
6654 $$ = end_block (GetLocation ($7));
6656 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6658 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6659 Warning_EmptyStatement (GetLocation ($5));
6661 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6662 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6664 | USING open_parens_any expression error
6666 Error_SyntaxError (yyToken);
6668 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6669 lbag.AddStatement ($$, GetLocation ($2));
6673 using_initialization
6674 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6677 // It has to be here for the parent to safely restore artificial block
6678 Error_SyntaxError (yyToken);
6682 using_or_fixed_variable_initializer
6685 Error_MissingInitializer (lexer.Location);
6687 | ASSIGN variable_initializer
6689 current_variable.Initializer = (Expression) $2;
6690 $$ = current_variable;
6698 : first_from_clause query_body
6700 lexer.query_parsing = false;
6702 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6704 from.Tail.Next = (Linq.AQueryClause)$2;
6707 current_block.SetEndLocation (lexer.Location);
6708 current_block = current_block.Parent;
6710 | nested_from_clause query_body
6712 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6714 from.Tail.Next = (Linq.AQueryClause)$2;
6717 current_block.SetEndLocation (lexer.Location);
6718 current_block = current_block.Parent;
6721 // Bubble up COMPLETE_COMPLETION productions
6722 | first_from_clause COMPLETE_COMPLETION {
6723 lexer.query_parsing = false;
6726 current_block.SetEndLocation (lexer.Location);
6727 current_block = current_block.Parent;
6729 | nested_from_clause COMPLETE_COMPLETION {
6731 current_block.SetEndLocation (lexer.Location);
6732 current_block = current_block.Parent;
6737 : FROM_FIRST identifier_inside_body IN expression
6739 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6741 var lt = (LocatedToken) $2;
6742 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6743 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6744 lbag.AddLocation (clause, GetLocation ($3));
6745 $$ = new Linq.QueryExpression (clause);
6747 | FROM_FIRST type identifier_inside_body IN expression
6749 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6751 var lt = (LocatedToken) $3;
6752 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6753 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6754 IdentifierType = (FullNamedExpression)$2
6756 lbag.AddLocation (clause, GetLocation ($4));
6757 $$ = new Linq.QueryExpression (clause);
6762 : FROM identifier_inside_body IN expression
6764 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6766 var lt = (LocatedToken) $2;
6767 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6768 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6769 lbag.AddLocation (clause, GetLocation ($3));
6770 $$ = new Linq.QueryExpression (clause);
6772 | FROM type identifier_inside_body IN expression
6774 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6776 var lt = (LocatedToken) $3;
6777 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6778 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6779 IdentifierType = (FullNamedExpression)$2
6781 lbag.AddLocation (clause, GetLocation ($4));
6782 $$ = new Linq.QueryExpression (clause);
6787 : FROM identifier_inside_body IN
6789 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6793 var lt = (LocatedToken) $2;
6794 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6795 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6797 current_block.SetEndLocation (lexer.Location);
6798 current_block = current_block.Parent;
6800 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6801 lbag.AddLocation ($$, GetLocation ($3));
6803 | FROM type identifier_inside_body IN
6805 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6809 var lt = (LocatedToken) $3;
6810 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6812 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6813 IdentifierType = (FullNamedExpression)$2
6816 current_block.SetEndLocation (lexer.Location);
6817 current_block = current_block.Parent;
6819 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6821 lbag.AddLocation ($$, GetLocation ($4));
6826 : query_body_clauses select_or_group_clause opt_query_continuation
6828 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6831 head.Next = (Linq.AQueryClause)$3;
6834 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6835 clause.Tail.Next = head;
6841 | select_or_group_clause opt_query_continuation
6843 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6846 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6847 clause.Tail.Next = head;
6853 | query_body_clauses COMPLETE_COMPLETION
6854 | query_body_clauses error
6856 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6861 Error_SyntaxError (yyToken);
6866 select_or_group_clause
6869 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6873 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6875 current_block.SetEndLocation (lexer.Location);
6876 current_block = current_block.Parent;
6880 if (linq_clause_blocks == null)
6881 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6883 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6884 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6888 current_block.SetEndLocation (lexer.Location);
6889 current_block = current_block.Parent;
6891 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6895 var obj = (object[]) $5;
6897 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6898 lbag.AddLocation ($$, (Location) obj[1]);
6900 current_block.SetEndLocation (lexer.Location);
6901 current_block = current_block.Parent;
6906 : BY expression_or_error
6908 $$ = new object[] { $2, GetLocation ($1) };
6912 Error_SyntaxError (yyToken);
6913 $$ = new object[2] { null, Location.Null };
6919 | query_body_clauses query_body_clause
6921 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6935 : LET identifier_inside_body ASSIGN
6937 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6941 var lt = (LocatedToken) $2;
6942 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6943 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6944 lbag.AddLocation ($$, GetLocation ($3));
6946 current_block.SetEndLocation (lexer.Location);
6947 current_block = current_block.Parent;
6949 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6956 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6960 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6962 current_block.SetEndLocation (lexer.Location);
6963 current_block = current_block.Parent;
6968 : JOIN identifier_inside_body IN
6970 if (linq_clause_blocks == null)
6971 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6973 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6974 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6976 expression_or_error ON
6978 current_block.SetEndLocation (lexer.Location);
6979 current_block = current_block.Parent;
6981 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6982 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6984 expression_or_error EQUALS
6986 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6987 current_block.SetEndLocation (lexer.Location);
6988 current_block = current_block.Parent;
6990 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6992 expression_or_error opt_join_into
6994 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6995 current_block.SetEndLocation (lexer.Location);
6997 var outer_selector = linq_clause_blocks.Pop ();
6998 var block = linq_clause_blocks.Pop ();
7000 var lt = (LocatedToken) $2;
7001 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7002 Linq.RangeVariable into;
7006 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7007 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7010 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7012 var parent = block.Parent;
7013 while (parent is Linq.QueryBlock) {
7014 parent = parent.Parent;
7016 current_block.Parent = parent;
7018 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7020 lt = (LocatedToken) $12;
7021 into = new Linq.RangeVariable (lt.Value, lt.Location);
7023 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7024 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7027 current_block = block.Parent;
7028 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7030 | JOIN type identifier_inside_body IN
7032 if (linq_clause_blocks == null)
7033 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7035 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7036 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7038 expression_or_error ON
7040 current_block.SetEndLocation (lexer.Location);
7041 current_block = current_block.Parent;
7043 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7044 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7046 expression_or_error EQUALS
7048 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7049 current_block.SetEndLocation (lexer.Location);
7050 current_block = current_block.Parent;
7052 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7054 expression_or_error opt_join_into
7056 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7057 current_block.SetEndLocation (lexer.Location);
7059 var outer_selector = linq_clause_blocks.Pop ();
7060 var block = linq_clause_blocks.Pop ();
7062 var lt = (LocatedToken) $3;
7063 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7064 Linq.RangeVariable into;
7068 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7069 IdentifierType = (FullNamedExpression)$2
7071 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7074 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7076 var parent = block.Parent;
7077 while (parent is Linq.QueryBlock) {
7078 parent = parent.Parent;
7080 current_block.Parent = parent;
7082 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7084 lt = (LocatedToken) $13;
7085 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7087 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7088 IdentifierType = (FullNamedExpression)$2
7092 current_block = block.Parent;
7093 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7099 | INTO identifier_inside_body
7108 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7112 current_block.SetEndLocation (lexer.Location);
7113 current_block = current_block.Parent;
7123 current_block.SetEndLocation (lexer.Location);
7124 current_block = current_block.Parent;
7126 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7130 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7137 | orderings_then_by COMMA
7139 current_block.SetEndLocation (lexer.Location);
7140 current_block = current_block.Parent;
7142 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7146 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7154 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7156 | expression ASCENDING
7158 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7159 lbag.AddLocation ($$, GetLocation ($2));
7161 | expression DESCENDING
7163 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7164 lbag.AddLocation ($$, GetLocation ($2));
7171 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7173 | expression ASCENDING
7175 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7176 lbag.AddLocation ($$, GetLocation ($2));
7178 | expression DESCENDING
7180 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7181 lbag.AddLocation ($$, GetLocation ($2));
7186 opt_query_continuation
7188 | INTO identifier_inside_body
7190 // query continuation block is not linked with query block but with block
7191 // before. This means each query can use same range variable names for
7192 // different identifiers.
7194 current_block.SetEndLocation (GetLocation ($1));
7195 current_block = current_block.Parent;
7197 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7199 if (linq_clause_blocks == null)
7200 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7202 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7206 var current_block = linq_clause_blocks.Pop ();
7207 var lt = (LocatedToken) $2;
7208 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7209 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7210 next = (Linq.AQueryClause)$4
7216 // Support for using the compiler as an interactive parser
7218 // The INTERACTIVE_PARSER token is first sent to parse our
7219 // productions; If the result is a Statement, the parsing
7220 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7221 // to setup the blocks in advance.
7223 // This setup is here so that in the future we can add
7224 // support for other constructs (type parsing, namespaces, etc)
7225 // that do not require a block to be setup in advance
7229 : EVAL_STATEMENT_PARSER EOF
7230 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7231 | EVAL_STATEMENT_PARSER
7233 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7235 // (ref object retval)
7236 Parameter [] mpar = new Parameter [1];
7237 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7239 ParametersCompiled pars = new ParametersCompiled (mpar);
7240 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7241 if (settings.Unsafe)
7242 mods |= Modifiers.UNSAFE;
7244 current_local_parameters = pars;
7245 var method = new InteractiveMethod (
7247 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7251 current_type.AddMember (method);
7252 oob_stack.Push (method);
7254 interactive_async = false;
7256 ++lexer.parsing_block;
7257 start_block (lexer.Location);
7259 interactive_statement_list opt_COMPLETE_COMPLETION
7261 --lexer.parsing_block;
7262 var method = (InteractiveMethod) oob_stack.Pop ();
7263 method.Block = (ToplevelBlock) end_block(lexer.Location);
7265 if (interactive_async == true) {
7266 method.ChangeToAsync ();
7269 InteractiveResult = (Class) pop_current_class ();
7270 current_local_parameters = null;
7272 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7275 interactive_compilation_unit
7276 : opt_extern_alias_directives opt_using_directives
7277 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7280 opt_COMPLETE_COMPLETION
7282 | COMPLETE_COMPLETION
7285 close_brace_or_complete_completion
7287 | COMPLETE_COMPLETION
7291 // XML documentation code references micro parser
7293 documentation_parsing
7296 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7301 : doc_type_declaration_name opt_doc_method_sig
7303 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7305 | builtin_types opt_doc_method_sig
7307 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7308 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7311 | VOID opt_doc_method_sig
7313 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7314 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7317 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7319 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7320 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7321 var lt = (LocatedToken) $3;
7322 $$ = new MemberName (lt.Value);
7324 | doc_type_declaration_name DOT THIS
7326 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7328 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7330 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7332 opt_doc_parameters CLOSE_BRACKET
7334 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7335 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7337 | EXPLICIT OPERATOR type opt_doc_method_sig
7339 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7340 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7341 module.DocumentationBuilder.ParsedParameters = p;
7342 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7345 | IMPLICIT OPERATOR type opt_doc_method_sig
7347 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7348 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7349 module.DocumentationBuilder.ParsedParameters = p;
7350 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7353 | OPERATOR overloadable_operator opt_doc_method_sig
7355 var p = (List<DocumentationParameter>)$3;
7356 module.DocumentationBuilder.ParsedParameters = p;
7357 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7362 doc_type_declaration_name
7363 : type_declaration_name
7364 | doc_type_declaration_name DOT type_declaration_name
7366 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7374 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7376 opt_doc_parameters CLOSE_PARENS
7385 $$ = new List<DocumentationParameter> (0);
7393 var parameters = new List<DocumentationParameter> ();
7394 parameters.Add ((DocumentationParameter) $1);
7397 | doc_parameters COMMA doc_parameter
7399 var parameters = $1 as List<DocumentationParameter>;
7400 parameters.Add ((DocumentationParameter) $3);
7406 : opt_parameter_modifier parameter_type
7409 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7411 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7418 // A class used to hold info about an operator declarator
7420 class OperatorDeclaration {
7421 public readonly Operator.OpType optype;
7422 public readonly FullNamedExpression ret_type;
7423 public readonly Location location;
7425 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7428 this.ret_type = ret_type;
7429 this.location = location;
7433 void Error_ExpectingTypeName (Expression expr)
7435 if (expr is Invocation){
7436 report.Error (1002, expr.Location, "Expecting `;'");
7438 expr.Error_InvalidExpressionStatement (report);
7442 void Error_ParameterModifierNotValid (string modifier, Location loc)
7444 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7448 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7450 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7451 Parameter.GetModifierSignature (mod));
7454 void Error_TypeExpected (Location loc)
7456 report.Error (1031, loc, "Type expected");
7459 void Error_UnsafeCodeNotAllowed (Location loc)
7461 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7464 void Warning_EmptyStatement (Location loc)
7466 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7469 void Error_NamedArgumentExpected (NamedArgument a)
7471 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7474 void Error_MissingInitializer (Location loc)
7476 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7479 object Error_AwaitAsIdentifier (object token)
7482 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7483 return new LocatedToken ("await", GetLocation (token));
7489 void push_current_container (TypeDefinition tc, object partial_token)
7491 if (module.Evaluator != null){
7492 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7496 undo.AddTypeContainer (current_container, tc);
7499 if (partial_token != null)
7500 current_container.AddPartial (tc);
7502 current_container.AddTypeContainer (tc);
7504 ++lexer.parsing_declaration;
7505 current_container = tc;
7509 TypeContainer pop_current_class ()
7511 var retval = current_container;
7513 current_container = current_container.Parent;
7514 current_type = current_type.Parent as TypeDefinition;
7519 [System.Diagnostics.Conditional ("FULL_AST")]
7520 void StoreModifierLocation (object token, Location loc)
7525 if (mod_locations == null)
7526 mod_locations = new List<Tuple<Modifiers, Location>> ();
7528 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7531 [System.Diagnostics.Conditional ("FULL_AST")]
7532 void PushLocation (Location loc)
7534 if (location_stack == null)
7535 location_stack = new Stack<Location> ();
7537 location_stack.Push (loc);
7540 Location PopLocation ()
7542 if (location_stack == null)
7543 return Location.Null;
7545 return location_stack.Pop ();
7548 string CheckAttributeTarget (int token, string a, Location l)
7551 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7555 if (!Tokenizer.IsValidIdentifier (a)) {
7556 Error_SyntaxError (token);
7558 report.Warning (658, 1, l,
7559 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7562 return string.Empty;
7565 static bool IsUnaryOperator (Operator.OpType op)
7569 case Operator.OpType.LogicalNot:
7570 case Operator.OpType.OnesComplement:
7571 case Operator.OpType.Increment:
7572 case Operator.OpType.Decrement:
7573 case Operator.OpType.True:
7574 case Operator.OpType.False:
7575 case Operator.OpType.UnaryPlus:
7576 case Operator.OpType.UnaryNegation:
7582 void syntax_error (Location l, string msg)
7584 report.Error (1003, l, "Syntax error, " + msg);
7589 public Tokenizer Lexer {
7595 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7596 : this (reader, file, file.Compiler.Report, session)
7600 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7603 current_container = current_namespace = file;
7605 this.module = file.Module;
7606 this.compiler = file.Compiler;
7607 this.settings = compiler.Settings;
7608 this.report = report;
7610 lang_version = settings.Version;
7611 yacc_verbose_flag = settings.VerboseParserFlag;
7612 doc_support = settings.DocumentationFile != null;
7613 lexer = new Tokenizer (reader, file, session, report);
7614 oob_stack = new Stack<object> ();
7615 lbag = session.LocationsBag;
7616 use_global_stacks = session.UseJayGlobalArrays;
7617 parameters_bucket = session.ParametersStack;
7620 public void parse ()
7622 eof_token = Token.EOF;
7625 if (yacc_verbose_flag > 1)
7626 yyparse (lexer, new yydebug.yyDebugSimple ());
7630 Tokenizer tokenizer = lexer as Tokenizer;
7631 tokenizer.cleanup ();
7632 } catch (Exception e){
7633 if (e is yyParser.yyUnexpectedEof) {
7634 Error_SyntaxError (yyToken);
7635 UnexpectedEOF = true;
7639 if (e is yyParser.yyException) {
7640 if (report.Errors == 0)
7641 report.Error (-25, lexer.Location, "Parsing error");
7643 // Used by compiler-tester to test internal errors
7644 if (yacc_verbose_flag > 0 || e is FatalException)
7647 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7652 void CheckToken (int error, int yyToken, string msg, Location loc)
7654 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7655 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7657 report.Error (error, loc, msg);
7660 string ConsumeStoredComment ()
7662 string s = tmpComment;
7664 Lexer.doc_state = XmlCommentState.Allowed;
7668 void FeatureIsNotAvailable (Location loc, string feature)
7670 report.FeatureIsNotAvailable (compiler, loc, feature);
7673 Location GetLocation (object obj)
7675 var lt = obj as LocatedToken;
7679 var mn = obj as MemberName;
7683 var expr = obj as Expression;
7685 return expr.Location;
7687 return lexer.Location;
7690 void start_block (Location loc)
7692 if (current_block == null) {
7693 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7694 parsing_anonymous_method = false;
7695 } else if (parsing_anonymous_method) {
7696 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7697 parsing_anonymous_method = false;
7699 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7704 end_block (Location loc)
7706 Block retval = current_block.Explicit;
7707 retval.SetEndLocation (loc);
7708 current_block = retval.Parent;
7712 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7714 oob_stack.Push (current_anonymous_method);
7715 oob_stack.Push (current_local_parameters);
7716 oob_stack.Push (current_variable);
7717 oob_stack.Push (async_block);
7719 current_local_parameters = parameters;
7721 if (lang_version <= LanguageVersion.ISO_2)
7722 FeatureIsNotAvailable (loc, "lambda expressions");
7724 current_anonymous_method = new LambdaExpression (loc);
7726 if (lang_version == LanguageVersion.ISO_1)
7727 FeatureIsNotAvailable (loc, "anonymous methods");
7729 current_anonymous_method = new AnonymousMethodExpression (loc);
7732 async_block = isAsync;
7733 // Force the next block to be created as a ToplevelBlock
7734 parsing_anonymous_method = true;
7738 * Completes the anonymous method processing, if lambda_expr is null, this
7739 * means that we have a Statement instead of an Expression embedded
7741 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7743 AnonymousMethodExpression retval;
7746 anon_block.IsAsync = true;
7748 current_anonymous_method.Block = anon_block;
7749 retval = current_anonymous_method;
7751 async_block = (bool) oob_stack.Pop ();
7752 current_variable = (BlockVariable) oob_stack.Pop ();
7753 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7754 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7759 void Error_SyntaxError (int token)
7761 Error_SyntaxError (0, token);
7764 void Error_SyntaxError (int error_code, int token)
7766 Error_SyntaxError (error_code, token, "Unexpected symbol");
7769 void Error_SyntaxError (int error_code, int token, string msg)
7771 Lexer.CompleteOnEOF = false;
7773 // An error message has been reported by tokenizer
7774 if (token == Token.ERROR)
7777 // Avoid duplicit error message after unterminated string literals
7778 if (token == Token.LITERAL && lexer.Location.Column == 0)
7781 string symbol = GetSymbolName (token);
7782 string expecting = GetExpecting ();
7783 var loc = lexer.Location - symbol.Length;
7785 if (error_code == 0) {
7786 if (expecting == "`identifier'") {
7787 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7788 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7793 expecting = "identifier";
7794 } else if (expecting == "`)'") {
7801 if (string.IsNullOrEmpty (expecting))
7802 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7804 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7807 string GetExpecting ()
7809 int [] tokens = yyExpectingTokens (yyExpectingState);
7810 var names = new List<string> (tokens.Length);
7811 bool has_type = false;
7812 bool has_identifier = false;
7813 for (int i = 0; i < tokens.Length; i++){
7814 int token = tokens [i];
7815 has_identifier |= token == Token.IDENTIFIER;
7817 string name = GetTokenName (token);
7818 if (name == "<internal>")
7821 has_type |= name == "type";
7822 if (names.Contains (name))
7829 // Too many tokens to enumerate
7831 if (names.Count > 8)
7834 if (has_type && has_identifier)
7835 names.Remove ("identifier");
7837 if (names.Count == 1)
7838 return "`" + GetTokenName (tokens [0]) + "'";
7840 StringBuilder sb = new StringBuilder ();
7842 int count = names.Count;
7843 for (int i = 0; i < count; i++){
7844 bool last = i + 1 == count;
7848 sb.Append (names [i]);
7849 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7851 return sb.ToString ();
7855 string GetSymbolName (int token)
7859 return ((Constant)lexer.Value).GetValue ().ToString ();
7860 case Token.IDENTIFIER:
7861 return ((LocatedToken)lexer.Value).Value;
7903 case Token.BITWISE_AND:
7905 case Token.BITWISE_OR:
7919 case Token.OP_SHIFT_LEFT:
7921 case Token.OP_SHIFT_RIGHT:
7941 case Token.OP_COALESCING:
7943 case Token.OP_MULT_ASSIGN:
7945 case Token.OP_DIV_ASSIGN:
7947 case Token.OP_MOD_ASSIGN:
7949 case Token.OP_ADD_ASSIGN:
7951 case Token.OP_SUB_ASSIGN:
7953 case Token.OP_SHIFT_LEFT_ASSIGN:
7955 case Token.OP_SHIFT_RIGHT_ASSIGN:
7957 case Token.OP_AND_ASSIGN:
7959 case Token.OP_XOR_ASSIGN:
7961 case Token.OP_OR_ASSIGN:
7965 return GetTokenName (token);
7968 static string GetTokenName (int token)
7971 case Token.ABSTRACT:
7993 case Token.CONTINUE:
7997 case Token.DELEGATE:
8007 case Token.EXPLICIT:
8010 case Token.EXTERN_ALIAS:
8026 case Token.IMPLICIT:
8030 case Token.INTERFACE:
8032 case Token.INTERNAL:
8038 case Token.NAMESPACE:
8044 case Token.OPERATOR:
8048 case Token.OVERRIDE:
8054 case Token.PROTECTED:
8058 case Token.READONLY:
8070 case Token.STACKALLOC:
8071 return "stackalloc";
8088 case Token.UNCHECKED:
8096 case Token.VOLATILE:
8104 case Token.REFVALUE:
8105 return "__refvalue";
8115 case Token.FROM_FIRST:
8133 case Token.ASCENDING:
8135 case Token.DESCENDING:
8136 return "descending";
8143 case Token.OPEN_BRACE:
8145 case Token.CLOSE_BRACE:
8147 case Token.OPEN_BRACKET:
8148 case Token.OPEN_BRACKET_EXPR:
8150 case Token.CLOSE_BRACKET:
8152 case Token.OPEN_PARENS_CAST:
8153 case Token.OPEN_PARENS_LAMBDA:
8154 case Token.OPEN_PARENS:
8156 case Token.CLOSE_PARENS:
8162 case Token.DEFAULT_COLON:
8166 case Token.SEMICOLON:
8172 case Token.INTERPOLATED_STRING_END:
8174 case Token.INTERPOLATED_STRING:
8183 case Token.BITWISE_AND:
8184 case Token.BITWISE_OR:
8191 case Token.OP_SHIFT_LEFT:
8192 case Token.OP_SHIFT_RIGHT:
8200 case Token.OP_COALESCING:
8201 case Token.OP_MULT_ASSIGN:
8202 case Token.OP_DIV_ASSIGN:
8203 case Token.OP_MOD_ASSIGN:
8204 case Token.OP_ADD_ASSIGN:
8205 case Token.OP_SUB_ASSIGN:
8206 case Token.OP_SHIFT_LEFT_ASSIGN:
8207 case Token.OP_SHIFT_RIGHT_ASSIGN:
8208 case Token.OP_AND_ASSIGN:
8209 case Token.OP_XOR_ASSIGN:
8210 case Token.OP_OR_ASSIGN:
8211 case Token.INTERR_OPERATOR:
8212 return "<operator>";
8234 case Token.OP_GENERICS_LT:
8235 case Token.GENERIC_DIMENSION:
8237 case Token.OP_GENERICS_GT:
8240 case Token.INTERR_NULLABLE:
8242 case Token.DOUBLE_COLON:
8246 case Token.IDENTIFIER:
8248 return "identifier";
8251 return "end-of-file";
8253 // All of these are internal.
8256 case Token.FIRST_KEYWORD:
8257 case Token.EVAL_COMPILATION_UNIT_PARSER:
8258 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8259 case Token.EVAL_STATEMENT_PARSER:
8260 case Token.LAST_KEYWORD:
8261 case Token.GENERATE_COMPLETION:
8262 case Token.COMPLETE_COMPLETION:
8263 return "<internal>";
8265 // A bit more robust.
8267 return yyNames [token];