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
404 Attributes attrs = (Attributes) $3;
406 foreach (var a in attrs.Attrs) {
407 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
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;
1899 property_initializer
1905 : opt_attributes opt_modifiers
1906 member_type indexer_declaration_name OPEN_BRACKET
1908 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1910 opt_formal_parameter_list CLOSE_BRACKET
1912 valid_param_mod = 0;
1913 var type = (FullNamedExpression) $3;
1914 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1916 current_property = indexer;
1918 current_type.AddIndexer (indexer);
1919 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1921 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1922 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1924 if (indexer.ParameterInfo.IsEmpty) {
1925 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1929 tmpComment = Lexer.consume_doc_comment ();
1930 Lexer.doc_state = XmlCommentState.Allowed;
1933 lexer.PropertyParsing = true;
1934 current_local_parameters = (ParametersCompiled) $7;
1938 lexer.PropertyParsing = false;
1939 current_local_parameters = null;
1941 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1942 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1945 current_property.DocComment = ConsumeStoredComment ();
1947 current_property = null;
1952 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1954 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1958 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1959 current_property.Get.Block = (ToplevelBlock) $1;
1963 accessor_declarations
1964 : get_accessor_declaration
1965 | get_accessor_declaration accessor_declarations
1966 | set_accessor_declaration
1967 | set_accessor_declaration accessor_declarations
1970 if (yyToken == Token.CLOSE_BRACE) {
1971 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1973 if (yyToken == Token.SEMICOLON)
1974 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1976 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1981 get_accessor_declaration
1982 : opt_attributes opt_modifiers GET
1984 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1985 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1988 if (current_property.Get != null) {
1989 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1992 if (current_property is Indexer) {
1993 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1994 (Attributes) $1, GetLocation ($3));
1996 current_property.Get = new Property.GetMethod (current_property,
1997 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2000 current_local_parameters = current_property.Get.ParameterInfo;
2001 lbag.AddMember (current_property.Get, mod_locations);
2002 lexer.PropertyParsing = false;
2007 current_property.Get.Block = (ToplevelBlock) $5;
2009 if (current_container.Kind == MemberKind.Interface) {
2010 report.Error (531, current_property.Get.Block.StartLocation,
2011 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2015 current_local_parameters = null;
2016 lexer.PropertyParsing = true;
2019 if (Lexer.doc_state == XmlCommentState.Error)
2020 Lexer.doc_state = XmlCommentState.NotAllowed;
2024 set_accessor_declaration
2025 : opt_attributes opt_modifiers SET
2027 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2028 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2031 if (current_property.Set != null) {
2032 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2035 if (current_property is Indexer) {
2036 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2037 ParametersCompiled.MergeGenerated (compiler,
2038 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2039 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2041 (Attributes) $1, GetLocation ($3));
2043 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2044 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2045 (Attributes) $1, GetLocation ($3));
2048 current_local_parameters = current_property.Set.ParameterInfo;
2049 lbag.AddMember (current_property.Set, mod_locations);
2050 lexer.PropertyParsing = false;
2055 current_property.Set.Block = (ToplevelBlock) $5;
2057 if (current_container.Kind == MemberKind.Interface) {
2058 report.Error (531, current_property.Set.Block.StartLocation,
2059 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2063 current_local_parameters = null;
2064 lexer.PropertyParsing = true;
2067 && Lexer.doc_state == XmlCommentState.Error)
2068 Lexer.doc_state = XmlCommentState.NotAllowed;
2081 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2086 interface_declaration
2093 type_declaration_name
2095 lexer.ConstraintsParsing = true;
2096 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2097 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2100 opt_type_parameter_constraints_clauses
2102 lexer.ConstraintsParsing = false;
2105 current_container.SetConstraints ((List<Constraints>) $9);
2108 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2109 Lexer.doc_state = XmlCommentState.Allowed;
2112 lexer.parsing_modifiers = true;
2114 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2116 --lexer.parsing_declaration;
2118 Lexer.doc_state = XmlCommentState.Allowed;
2123 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2125 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2127 $$ = pop_current_class ();
2129 | opt_attributes opt_modifiers opt_partial INTERFACE error
2131 Error_SyntaxError (yyToken);
2135 opt_interface_member_declarations
2137 | interface_member_declarations
2140 interface_member_declarations
2141 : interface_member_declaration
2143 lexer.parsing_modifiers = true;
2144 lexer.parsing_block = 0;
2146 | interface_member_declarations interface_member_declaration
2148 lexer.parsing_modifiers = true;
2149 lexer.parsing_block = 0;
2153 interface_member_declaration
2154 : constant_declaration
2156 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2160 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2162 | method_declaration
2163 | property_declaration
2165 | indexer_declaration
2166 | operator_declaration
2168 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2170 | constructor_declaration
2172 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2176 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2180 operator_declaration
2181 : opt_attributes opt_modifiers operator_declarator
2184 method_body_expression_block
2186 OperatorDeclaration decl = (OperatorDeclaration) $3;
2188 Operator op = new Operator (
2189 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2190 current_local_parameters,
2191 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2193 if (op.Block == null)
2194 op.ParameterInfo.CheckParameters (op);
2197 op.DocComment = tmpComment;
2198 Lexer.doc_state = XmlCommentState.Allowed;
2201 // Note again, checking is done in semantic analysis
2202 current_type.AddOperator (op);
2204 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2207 current_local_parameters = null;
2212 : type_expression_or_array
2215 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2216 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2221 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2223 valid_param_mod = ParameterModifierType.DefaultValue;
2224 if ((Operator.OpType) $3 == Operator.OpType.Is)
2225 valid_param_mod |= ParameterModifierType.Out;
2227 opt_formal_parameter_list CLOSE_PARENS
2229 valid_param_mod = 0;
2231 Location loc = GetLocation ($2);
2232 Operator.OpType op = (Operator.OpType) $3;
2233 current_local_parameters = (ParametersCompiled)$6;
2235 int p_count = current_local_parameters.Count;
2237 if (op == Operator.OpType.Addition)
2238 op = Operator.OpType.UnaryPlus;
2239 else if (op == Operator.OpType.Subtraction)
2240 op = Operator.OpType.UnaryNegation;
2243 if (IsUnaryOperator (op)) {
2245 report.Error (1020, loc, "Overloadable binary operator expected");
2246 } else if (p_count != 1) {
2247 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2248 Operator.GetName (op));
2250 } else if (op == Operator.OpType.Is) {
2251 // TODO: Special checks for is operator
2254 report.Error (1019, loc, "Overloadable unary operator expected");
2255 } else if (p_count != 2) {
2256 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2257 Operator.GetName (op));
2262 tmpComment = Lexer.consume_doc_comment ();
2263 Lexer.doc_state = XmlCommentState.NotAllowed;
2266 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2267 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2269 | conversion_operator_declarator
2272 overloadable_operator
2274 : BANG { $$ = Operator.OpType.LogicalNot; }
2275 | TILDE { $$ = Operator.OpType.OnesComplement; }
2276 | OP_INC { $$ = Operator.OpType.Increment; }
2277 | OP_DEC { $$ = Operator.OpType.Decrement; }
2278 | TRUE { $$ = Operator.OpType.True; }
2279 | FALSE { $$ = Operator.OpType.False; }
2280 // Unary and binary:
2281 | PLUS { $$ = Operator.OpType.Addition; }
2282 | MINUS { $$ = Operator.OpType.Subtraction; }
2284 | STAR { $$ = Operator.OpType.Multiply; }
2285 | DIV { $$ = Operator.OpType.Division; }
2286 | PERCENT { $$ = Operator.OpType.Modulus; }
2287 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2288 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2289 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2290 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2291 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2292 | OP_EQ { $$ = Operator.OpType.Equality; }
2293 | OP_NE { $$ = Operator.OpType.Inequality; }
2294 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2295 | OP_LT { $$ = Operator.OpType.LessThan; }
2296 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2297 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2300 if (lang_version != LanguageVersion.Experimental)
2301 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2303 $$ = Operator.OpType.Is;
2307 conversion_operator_declarator
2308 : IMPLICIT OPERATOR type OPEN_PARENS
2310 valid_param_mod = ParameterModifierType.DefaultValue;
2312 opt_formal_parameter_list CLOSE_PARENS
2314 valid_param_mod = 0;
2316 Location loc = GetLocation ($2);
2317 current_local_parameters = (ParametersCompiled)$6;
2319 if (current_local_parameters.Count != 1) {
2320 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2324 tmpComment = Lexer.consume_doc_comment ();
2325 Lexer.doc_state = XmlCommentState.NotAllowed;
2328 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2329 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2331 | EXPLICIT OPERATOR type OPEN_PARENS
2333 valid_param_mod = ParameterModifierType.DefaultValue;
2335 opt_formal_parameter_list CLOSE_PARENS
2337 valid_param_mod = 0;
2339 Location loc = GetLocation ($2);
2340 current_local_parameters = (ParametersCompiled)$6;
2342 if (current_local_parameters.Count != 1) {
2343 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2347 tmpComment = Lexer.consume_doc_comment ();
2348 Lexer.doc_state = XmlCommentState.NotAllowed;
2351 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2352 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2356 Error_SyntaxError (yyToken);
2357 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2358 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2362 Error_SyntaxError (yyToken);
2363 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2364 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2368 constructor_declaration
2369 : constructor_declarator
2372 Constructor c = (Constructor) $1;
2373 c.Block = (ToplevelBlock) $2;
2376 c.DocComment = ConsumeStoredComment ();
2378 current_local_parameters = null;
2380 Lexer.doc_state = XmlCommentState.Allowed;
2384 constructor_declarator
2390 tmpComment = Lexer.consume_doc_comment ();
2391 Lexer.doc_state = XmlCommentState.Allowed;
2394 valid_param_mod = ParameterModifierType.All;
2396 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2398 valid_param_mod = 0;
2399 current_local_parameters = (ParametersCompiled) $6;
2401 var lt = (LocatedToken) $3;
2402 var mods = (Modifiers) $2;
2403 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2405 if (lt.Value != current_container.MemberName.Name) {
2406 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2407 } else if ((mods & Modifiers.STATIC) != 0) {
2408 if (!current_local_parameters.IsEmpty) {
2409 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2410 c.GetSignatureForError ());
2413 if ((mods & Modifiers.AccessibilityMask) != 0){
2414 report.Error (515, c.Location,
2415 "`{0}': static constructor cannot have an access modifier",
2416 c.GetSignatureForError ());
2419 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2420 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2424 current_type.AddConstructor (c);
2425 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2429 // start block here, so possible anonymous methods inside
2430 // constructor initializer can get correct parent block
2432 start_block (lexer.Location);
2434 opt_constructor_initializer
2437 var c = (Constructor) $8;
2438 c.Initializer = (ConstructorInitializer) $9;
2441 report.Error (514, c.Location,
2442 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2443 c.GetSignatureForError ());
2453 | SEMICOLON { current_block = null; $$ = null; }
2456 opt_constructor_initializer
2458 | constructor_initializer
2461 constructor_initializer
2462 : COLON BASE OPEN_PARENS
2464 ++lexer.parsing_block;
2466 opt_argument_list CLOSE_PARENS
2468 --lexer.parsing_block;
2469 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2470 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2472 | COLON THIS OPEN_PARENS
2474 ++lexer.parsing_block;
2476 opt_argument_list CLOSE_PARENS
2478 --lexer.parsing_block;
2479 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2480 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2484 Error_SyntaxError (yyToken);
2485 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2486 lbag.AddLocation ($$, GetLocation ($1));
2490 Error_SyntaxError (yyToken);
2495 destructor_declaration
2496 : opt_attributes opt_modifiers TILDE
2499 tmpComment = Lexer.consume_doc_comment ();
2500 Lexer.doc_state = XmlCommentState.NotAllowed;
2503 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2505 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2507 var lt = (LocatedToken) $5;
2508 if (lt.Value != current_container.MemberName.Name){
2509 report.Error (574, lt.Location, "Name of destructor must match name of class");
2510 } else if (current_container.Kind != MemberKind.Class){
2511 report.Error (575, lt.Location, "Only class types can contain destructor");
2514 Destructor d = new Destructor (current_type, (Modifiers) $2,
2515 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2517 d.DocComment = ConsumeStoredComment ();
2519 d.Block = (ToplevelBlock) $8;
2520 current_type.AddMember (d);
2521 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2523 current_local_parameters = null;
2530 EVENT type member_declaration_name
2532 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2533 current_type.AddMember (current_event_field);
2535 if (current_event_field.MemberName.ExplicitInterface != null) {
2536 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2537 current_event_field.GetSignatureForError ());
2540 $$ = current_event_field;
2542 opt_event_initializer
2543 opt_event_declarators
2547 current_event_field.DocComment = Lexer.consume_doc_comment ();
2548 Lexer.doc_state = XmlCommentState.Allowed;
2551 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2552 current_event_field = null;
2556 EVENT type member_declaration_name
2559 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2560 current_type.AddMember (current_event);
2561 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2563 lexer.EventParsing = true;
2565 event_accessor_declarations
2567 if (current_container.Kind == MemberKind.Interface)
2568 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2570 lexer.EventParsing = false;
2575 current_event.DocComment = Lexer.consume_doc_comment ();
2576 Lexer.doc_state = XmlCommentState.Allowed;
2579 lbag.AppendToMember (current_event, GetLocation ($9));
2580 current_event = null;
2581 current_local_parameters = null;
2587 Error_SyntaxError (yyToken);
2589 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2593 opt_event_initializer
2597 ++lexer.parsing_block;
2599 event_variable_initializer
2601 --lexer.parsing_block;
2602 current_event_field.Initializer = (Expression) $3;
2606 opt_event_declarators
2614 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2616 | event_declarators event_declarator
2618 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2625 var lt = (LocatedToken) $2;
2626 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2627 lbag.AddLocation ($$, GetLocation ($1));
2629 | COMMA IDENTIFIER ASSIGN
2631 ++lexer.parsing_block;
2633 event_variable_initializer
2635 --lexer.parsing_block;
2636 var lt = (LocatedToken) $2;
2637 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2638 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2642 event_variable_initializer
2644 if (current_container.Kind == MemberKind.Interface) {
2645 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2646 current_event_field.GetSignatureForError ());
2649 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2650 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2651 current_event_field.GetSignatureForError ());
2654 variable_initializer
2660 event_accessor_declarations
2661 : add_accessor_declaration remove_accessor_declaration
2662 | remove_accessor_declaration add_accessor_declaration
2663 | add_accessor_declaration
2665 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2666 current_event.GetSignatureForError ());
2668 | remove_accessor_declaration
2670 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2671 current_event.GetSignatureForError ());
2675 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2680 add_accessor_declaration
2681 : opt_attributes opt_modifiers ADD
2683 if ($2 != ModifierNone) {
2684 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2687 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2688 current_local_parameters = current_event.Add.ParameterInfo;
2690 lbag.AddMember (current_event.Add, mod_locations);
2691 lexer.EventParsing = false;
2693 event_accessor_block
2695 lexer.EventParsing = true;
2697 current_event.Add.Block = (ToplevelBlock) $5;
2699 if (current_container.Kind == MemberKind.Interface) {
2700 report.Error (531, current_event.Add.Block.StartLocation,
2701 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2704 current_local_parameters = null;
2708 remove_accessor_declaration
2709 : opt_attributes opt_modifiers REMOVE
2711 if ($2 != ModifierNone) {
2712 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2715 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2716 current_local_parameters = current_event.Remove.ParameterInfo;
2718 lbag.AddMember (current_event.Remove, mod_locations);
2719 lexer.EventParsing = false;
2721 event_accessor_block
2723 lexer.EventParsing = true;
2725 current_event.Remove.Block = (ToplevelBlock) $5;
2727 if (current_container.Kind == MemberKind.Interface) {
2728 report.Error (531, current_event.Remove.Block.StartLocation,
2729 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2732 current_local_parameters = null;
2736 event_accessor_block
2739 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2745 attributes_without_members
2746 : attribute_sections CLOSE_BRACE
2748 current_type.UnattachedAttributes = (Attributes) $1;
2749 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2750 lexer.putback ('}');
2754 // For full ast try to recover incomplete ambiguous member
2755 // declaration in form on class X { public int }
2757 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2759 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2761 lexer.putback ('}');
2763 lexer.parsing_generic_declaration = false;
2764 FullNamedExpression type = (FullNamedExpression) $3;
2765 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2766 current_type.AddField (current_field);
2774 ENUM type_declaration_name
2778 enumTypeComment = Lexer.consume_doc_comment ();
2783 Lexer.doc_state = XmlCommentState.Allowed;
2785 MemberName name = (MemberName) $4;
2786 if (name.IsGeneric) {
2787 report.Error (1675, name.Location, "Enums cannot have type parameters");
2790 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2792 opt_enum_member_declarations
2794 lexer.parsing_modifiers = true;
2796 // here will be evaluated after CLOSE_BLACE is consumed.
2798 Lexer.doc_state = XmlCommentState.Allowed;
2800 CLOSE_BRACE opt_semicolon
2803 current_container.DocComment = enumTypeComment;
2805 --lexer.parsing_declaration;
2808 // em.DocComment = ev.DocComment;
2810 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2811 $$ = pop_current_class ();
2823 Error_TypeExpected (GetLocation ($1));
2828 opt_enum_member_declarations
2830 | enum_member_declarations
2831 | enum_member_declarations COMMA
2833 lbag.AddLocation ($1, GetLocation ($2));
2837 enum_member_declarations
2838 : enum_member_declaration
2839 | enum_member_declarations COMMA enum_member_declaration
2841 lbag.AddLocation ($1, GetLocation ($2));
2846 enum_member_declaration
2847 : opt_attributes IDENTIFIER
2849 var lt = (LocatedToken) $2;
2850 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2851 ((Enum) current_type).AddEnumMember (em);
2854 em.DocComment = Lexer.consume_doc_comment ();
2855 Lexer.doc_state = XmlCommentState.Allowed;
2860 | opt_attributes IDENTIFIER
2862 ++lexer.parsing_block;
2864 tmpComment = Lexer.consume_doc_comment ();
2865 Lexer.doc_state = XmlCommentState.NotAllowed;
2868 ASSIGN constant_expression
2870 --lexer.parsing_block;
2872 var lt = (LocatedToken) $2;
2873 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2874 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2875 ((Enum) current_type).AddEnumMember (em);
2878 em.DocComment = ConsumeStoredComment ();
2882 | opt_attributes IDENTIFIER error
2884 Error_SyntaxError (yyToken);
2886 var lt = (LocatedToken) $2;
2887 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2888 ((Enum) current_type).AddEnumMember (em);
2891 em.DocComment = Lexer.consume_doc_comment ();
2892 Lexer.doc_state = XmlCommentState.Allowed;
2897 | attributes_without_members
2900 delegate_declaration
2904 member_type type_declaration_name
2907 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2909 opt_formal_parameter_list CLOSE_PARENS
2911 valid_param_mod = 0;
2913 ParametersCompiled p = (ParametersCompiled) $8;
2915 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2917 p.CheckParameters (del);
2919 current_container.AddTypeContainer (del);
2921 current_delegate = del;
2922 lexer.ConstraintsParsing = true;
2924 opt_type_parameter_constraints_clauses
2926 lexer.ConstraintsParsing = false;
2931 current_delegate.DocComment = Lexer.consume_doc_comment ();
2932 Lexer.doc_state = XmlCommentState.Allowed;
2936 current_delegate.SetConstraints ((List<Constraints>) $11);
2937 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2939 $$ = current_delegate;
2941 current_delegate = null;
2949 if (lang_version < LanguageVersion.ISO_2)
2950 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2952 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2956 namespace_or_type_expr
2958 | qualified_alias_member IDENTIFIER opt_type_argument_list
2960 var lt1 = (LocatedToken) $1;
2961 var lt2 = (LocatedToken) $2;
2963 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2964 lbag.AddLocation ($$, GetLocation ($2));
2966 | qualified_alias_member IDENTIFIER generic_dimension
2968 var lt1 = (LocatedToken) $1;
2969 var lt2 = (LocatedToken) $2;
2971 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2972 lbag.AddLocation ($$, GetLocation ($2));
2978 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2980 var lt = (LocatedToken) $3;
2981 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2982 lbag.AddLocation ($$, GetLocation ($2));
2984 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2986 var lt = (LocatedToken) $3;
2987 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2988 lbag.AddLocation ($$, GetLocation ($2));
2993 : IDENTIFIER opt_type_argument_list
2995 var lt = (LocatedToken) $1;
2996 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2998 | IDENTIFIER generic_dimension
3000 var lt = (LocatedToken) $1;
3001 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3006 // Generics arguments (any type, without attributes)
3008 opt_type_argument_list
3010 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3012 if (lang_version < LanguageVersion.ISO_2)
3013 FeatureIsNotAvailable (GetLocation ($1), "generics");
3017 | OP_GENERICS_LT error
3019 Error_TypeExpected (lexer.Location);
3020 $$ = new TypeArguments ();
3027 TypeArguments type_args = new TypeArguments ();
3028 type_args.Add ((FullNamedExpression) $1);
3031 | type_arguments COMMA type
3033 TypeArguments type_args = (TypeArguments) $1;
3034 type_args.Add ((FullNamedExpression) $3);
3040 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3042 type_declaration_name
3045 lexer.parsing_generic_declaration = true;
3047 opt_type_parameter_list
3049 lexer.parsing_generic_declaration = false;
3050 var lt = (LocatedToken) $1;
3051 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3055 member_declaration_name
3056 : method_declaration_name
3058 MemberName mn = (MemberName)$1;
3059 if (mn.TypeParameters != null)
3060 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3061 mn.GetSignatureForError ()));
3065 method_declaration_name
3066 : type_declaration_name
3067 | explicit_interface IDENTIFIER opt_type_parameter_list
3069 lexer.parsing_generic_declaration = false;
3070 var lt = (LocatedToken) $2;
3071 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3075 indexer_declaration_name
3078 lexer.parsing_generic_declaration = false;
3079 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3081 | explicit_interface THIS
3083 lexer.parsing_generic_declaration = false;
3084 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3089 : IDENTIFIER opt_type_argument_list DOT
3091 var lt = (LocatedToken) $1;
3092 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3093 lbag.AddLocation ($$, GetLocation ($3));
3095 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3097 var lt1 = (LocatedToken) $1;
3098 var lt2 = (LocatedToken) $2;
3100 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3101 lbag.AddLocation ($$, GetLocation ($4));
3103 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3105 var lt = (LocatedToken) $2;
3106 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3107 lbag.AddLocation ($$, GetLocation ($4));
3111 opt_type_parameter_list
3113 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3115 if (lang_version < LanguageVersion.ISO_2)
3116 FeatureIsNotAvailable (GetLocation ($1), "generics");
3119 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3126 var tparams = new TypeParameters ();
3127 tparams.Add ((TypeParameter)$1);
3130 | type_parameters COMMA type_parameter
3132 var tparams = (TypeParameters) $1;
3133 tparams.Add ((TypeParameter)$3);
3135 lbag.AddLocation ($3, GetLocation ($3));
3140 : opt_attributes opt_type_parameter_variance IDENTIFIER
3142 var lt = (LocatedToken)$3;
3143 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3147 if (GetTokenName (yyToken) == "type")
3148 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3150 Error_SyntaxError (yyToken);
3152 $$ = new TypeParameter (MemberName.Null, null, null);
3157 // All types where void is allowed
3160 : type_expression_or_array
3163 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3170 lexer.parsing_generic_declaration = true;
3175 // A type which does not allow `void' to be used
3178 : type_expression_or_array
3188 : type_expression_or_array
3191 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3192 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3196 type_expression_or_array
3198 | type_expression rank_specifiers
3200 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3205 : namespace_or_type_expr opt_nullable
3208 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3210 var sn = $1 as SimpleName;
3211 if (sn != null && sn.Name == "var")
3212 $$ = new VarExpr (sn.Location);
3217 | namespace_or_type_expr pointer_stars
3219 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3221 | builtin_type_expression
3227 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3228 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3232 builtin_type_expression
3233 : builtin_types opt_nullable
3236 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3238 | builtin_types pointer_stars
3240 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3242 | VOID pointer_stars
3244 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3251 var types = new List<FullNamedExpression> (2);
3252 types.Add ((FullNamedExpression) $1);
3255 | type_list COMMA base_type_name
3257 var types = (List<FullNamedExpression>) $1;
3258 types.Add ((FullNamedExpression) $3);
3266 if ($1 is ComposedCast) {
3267 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3274 * replaces all the productions for isolating the various
3275 * simple types, but we need this to reuse it easily in variable_type
3278 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3279 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3280 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3281 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3282 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3283 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3288 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3289 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3290 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3291 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3292 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3293 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3294 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3295 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3296 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3300 // Expressions, section 7.5
3305 : type_name_expression
3307 | array_creation_expression
3308 | parenthesized_expression
3309 | default_value_expression
3310 | invocation_expression
3314 | post_increment_expression
3315 | post_decrement_expression
3316 | object_or_delegate_creation_expression
3317 | anonymous_type_expression
3320 | checked_expression
3321 | unchecked_expression
3322 | pointer_member_access
3323 | anonymous_method_expression
3324 | undocumented_expressions
3325 | interpolated_string
3328 type_name_expression
3330 | IDENTIFIER GENERATE_COMPLETION {
3331 var lt = (LocatedToken) $1;
3332 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3340 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3344 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3345 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3349 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3351 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3353 | INTERPOLATED_STRING_END
3355 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3362 var list = new List<Expression> ();
3363 list.Add ((InterpolatedStringInsert) $1);
3366 | interpolations INTERPOLATED_STRING interpolation
3368 var list = (List<Expression>) $1;
3369 list.Add ((StringLiteral) $2);
3370 list.Add ((InterpolatedStringInsert) $3);
3378 $$ = new InterpolatedStringInsert ((Expression) $1);
3380 | expression COMMA expression
3382 $$ = new InterpolatedStringInsert ((Expression) $1) {
3383 Alignment = (Expression)$3
3388 lexer.parsing_interpolation_format = true;
3392 lexer.parsing_interpolation_format = false;
3394 $$ = new InterpolatedStringInsert ((Expression) $1) {
3398 | expression COMMA expression COLON
3400 lexer.parsing_interpolation_format = true;
3404 lexer.parsing_interpolation_format = false;
3406 $$ = new InterpolatedStringInsert ((Expression) $1) {
3407 Alignment = (Expression)$3,
3408 Format = (string) $6
3415 // Here is the trick, tokenizer may think that parens is a special but
3416 // parser is interested in open parens only, so we merge them.
3417 // Consider: if (a)foo ();
3425 // Use this production to accept closing parenthesis or
3426 // performing completion
3430 | COMPLETE_COMPLETION
3434 parenthesized_expression
3435 : OPEN_PARENS expression CLOSE_PARENS
3437 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3438 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3440 | OPEN_PARENS expression COMPLETE_COMPLETION
3442 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3447 : primary_expression DOT identifier_inside_body opt_type_argument_list
3449 var lt = (LocatedToken) $3;
3450 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3451 lbag.AddLocation ($$, GetLocation ($2));
3453 | primary_expression DOT identifier_inside_body generic_dimension
3455 var lt = (LocatedToken) $3;
3456 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3457 lbag.AddLocation ($$, GetLocation ($2));
3459 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3461 if (lang_version < LanguageVersion.V_6)
3462 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3464 var lt = (LocatedToken) $4;
3465 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3466 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3468 | builtin_types DOT identifier_inside_body opt_type_argument_list
3470 var lt = (LocatedToken) $3;
3471 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3472 lbag.AddLocation ($$, GetLocation ($2));
3474 | BASE DOT identifier_inside_body opt_type_argument_list
3476 var lt = (LocatedToken) $3;
3477 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3478 lbag.AddLocation ($$, GetLocation ($2));
3480 | AWAIT DOT identifier_inside_body opt_type_argument_list
3482 var lt = (LocatedToken) $3;
3483 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3484 lbag.AddLocation ($$, GetLocation ($2));
3486 | qualified_alias_member identifier_inside_body opt_type_argument_list
3488 var lt1 = (LocatedToken) $1;
3489 var lt2 = (LocatedToken) $2;
3491 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3492 lbag.AddLocation ($$, GetLocation ($2));
3494 | qualified_alias_member identifier_inside_body generic_dimension
3496 var lt1 = (LocatedToken) $1;
3497 var lt2 = (LocatedToken) $2;
3499 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3500 lbag.AddLocation ($$, GetLocation ($2));
3502 | primary_expression DOT GENERATE_COMPLETION {
3503 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3505 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3506 var lt = (LocatedToken) $3;
3507 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3509 | builtin_types DOT GENERATE_COMPLETION
3511 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3513 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3514 var lt = (LocatedToken) $3;
3515 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3519 invocation_expression
3520 : primary_expression open_parens_any opt_argument_list close_parens
3522 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3523 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3525 | primary_expression open_parens_any argument_list error
3527 Error_SyntaxError (yyToken);
3529 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3530 lbag.AddLocation ($$, GetLocation ($2));
3532 | primary_expression open_parens_any error
3534 Error_SyntaxError (yyToken);
3536 $$ = new Invocation ((Expression) $1, null);
3537 lbag.AddLocation ($$, GetLocation ($2));
3541 opt_object_or_collection_initializer
3542 : /* empty */ { $$ = null; }
3543 | object_or_collection_initializer
3546 object_or_collection_initializer
3547 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3550 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3552 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3554 lbag.AddLocation ($$, GetLocation ($3));
3556 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3558 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3559 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3563 opt_member_initializer_list
3564 : /* empty */ { $$ = null; }
3565 | member_initializer_list
3571 member_initializer_list
3572 : member_initializer
3574 var a = new List<Expression> ();
3575 a.Add ((Expression) $1);
3578 | member_initializer_list COMMA member_initializer
3580 var a = (List<Expression>)$1;
3581 a.Add ((Expression) $3);
3584 | member_initializer_list error {
3585 Error_SyntaxError (yyToken);
3591 : IDENTIFIER ASSIGN initializer_value
3593 var lt = (LocatedToken) $1;
3594 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3595 lbag.AddLocation ($$, GetLocation ($2));
3597 | AWAIT ASSIGN initializer_value
3599 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3600 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3601 lbag.AddLocation ($$, GetLocation ($2));
3603 | GENERATE_COMPLETION
3605 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3607 | non_assignment_expression opt_COMPLETE_COMPLETION {
3608 CompletionSimpleName csn = $1 as CompletionSimpleName;
3610 $$ = new CollectionElementInitializer ((Expression)$1);
3612 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3614 | OPEN_BRACE expression_list CLOSE_BRACE
3617 $$ = new CollectionElementInitializer (GetLocation ($1));
3619 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3621 lbag.AddLocation ($$, GetLocation ($3));
3623 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3625 if (lang_version < LanguageVersion.V_6)
3626 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3628 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3629 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3631 | OPEN_BRACE CLOSE_BRACE
3633 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3634 $$ = new CollectionElementInitializer (GetLocation ($1));
3635 lbag.AddLocation ($$, GetLocation ($2));
3641 | object_or_collection_initializer
3645 : /* empty */ { $$ = null; }
3650 : argument_or_named_argument
3652 Arguments list = new Arguments (4);
3653 list.Add ((Argument) $1);
3656 | argument_list COMMA argument
3658 Arguments list = (Arguments) $1;
3659 if (list [list.Count - 1] is NamedArgument)
3660 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3662 list.Add ((Argument) $3);
3665 | argument_list COMMA named_argument
3667 Arguments list = (Arguments) $1;
3668 NamedArgument a = (NamedArgument) $3;
3669 for (int i = 0; i < list.Count; ++i) {
3670 NamedArgument na = list [i] as NamedArgument;
3671 if (na != null && na.Name == a.Name)
3672 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3679 | argument_list COMMA error
3681 if (lexer.putback_char == -1)
3682 lexer.putback (')'); // TODO: Wrong but what can I do
3683 Error_SyntaxError (yyToken);
3688 report.Error (839, GetLocation ($1), "An argument is missing");
3696 $$ = new Argument ((Expression) $1);
3698 | non_simple_argument
3701 argument_or_named_argument
3707 : REF variable_reference
3709 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3710 lbag.AddLocation ($$, GetLocation ($1));
3712 | REF declaration_expression
3714 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3716 | OUT variable_reference
3718 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3719 lbag.AddLocation ($$, GetLocation ($1));
3721 | OUT declaration_expression
3723 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3725 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3727 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3728 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3730 | ARGLIST OPEN_PARENS CLOSE_PARENS
3732 $$ = new Argument (new Arglist (GetLocation ($1)));
3733 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3737 declaration_expression
3738 : OPEN_PARENS declaration_expression CLOSE_PARENS
3740 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3741 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3744 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3746 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3747 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3749 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3751 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3752 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3755 | variable_type identifier_inside_body
3757 if (lang_version != LanguageVersion.Experimental)
3758 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3760 var lt = (LocatedToken) $2;
3761 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3762 current_block.AddLocalName (lv);
3763 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3765 | variable_type identifier_inside_body ASSIGN expression
3767 if (lang_version != LanguageVersion.Experimental)
3768 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3770 var lt = (LocatedToken) $2;
3771 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3772 current_block.AddLocalName (lv);
3773 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3774 Initializer = (Expression) $4
3784 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3786 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3787 lbag.AddLocation ($$, GetLocation ($4));
3789 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3791 if (lang_version < LanguageVersion.V_6)
3792 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3794 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3795 ConditionalAccess = true
3798 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3800 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3802 Error_SyntaxError (yyToken);
3803 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3805 | primary_expression OPEN_BRACKET_EXPR error
3807 Error_SyntaxError (yyToken);
3808 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3813 : expression_or_error
3815 var list = new List<Expression> (4);
3816 list.Add ((Expression) $1);
3819 | expression_list COMMA expression_or_error
3821 var list = (List<Expression>) $1;
3822 list.Add ((Expression) $3);
3827 expression_list_arguments
3828 : expression_list_argument
3830 Arguments args = new Arguments (4);
3831 args.Add ((Argument) $1);
3834 | expression_list_arguments COMMA expression_list_argument
3836 Arguments args = (Arguments) $1;
3837 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3838 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3840 args.Add ((Argument) $3);
3845 expression_list_argument
3848 $$ = new Argument ((Expression) $1);
3856 $$ = new This (GetLocation ($1));
3861 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3863 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3864 lbag.AddLocation ($$, GetLocation ($4));
3866 | BASE OPEN_BRACKET error
3868 Error_SyntaxError (yyToken);
3869 $$ = new ElementAccess (null, null, GetLocation ($2));
3873 post_increment_expression
3874 : primary_expression OP_INC
3876 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3880 post_decrement_expression
3881 : primary_expression OP_DEC
3883 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3887 object_or_delegate_creation_expression
3888 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3891 if (lang_version <= LanguageVersion.ISO_2)
3892 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3894 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3896 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3899 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3901 | NEW new_expr_type object_or_collection_initializer
3903 if (lang_version <= LanguageVersion.ISO_2)
3904 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3906 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3910 array_creation_expression
3911 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3913 opt_array_initializer
3915 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3916 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3917 Next = (ComposedTypeSpecifier) $6
3918 }, (ArrayInitializer) $7, GetLocation ($1));
3919 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3921 | NEW new_expr_type rank_specifiers opt_array_initializer
3924 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3926 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3928 | NEW rank_specifier array_initializer
3930 if (lang_version <= LanguageVersion.ISO_2)
3931 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3933 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3935 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3937 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3938 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3940 | NEW new_expr_type error
3942 Error_SyntaxError (yyToken);
3943 // It can be any of new expression, create the most common one
3944 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3950 ++lexer.parsing_type;
3954 --lexer.parsing_type;
3959 anonymous_type_expression
3960 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3962 if (lang_version <= LanguageVersion.ISO_2)
3963 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3965 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3967 // TODO: lbag comma location
3968 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3970 | NEW OPEN_BRACE GENERATE_COMPLETION
3972 $$ = new EmptyCompletion ();
3976 anonymous_type_parameters_opt_comma
3977 : anonymous_type_parameters_opt
3978 | anonymous_type_parameters COMMA
3981 anonymous_type_parameters_opt
3983 | anonymous_type_parameters
3986 anonymous_type_parameters
3987 : anonymous_type_parameter
3989 var a = new List<AnonymousTypeParameter> (4);
3990 a.Add ((AnonymousTypeParameter) $1);
3993 | anonymous_type_parameters COMMA anonymous_type_parameter
3995 var a = (List<AnonymousTypeParameter>) $1;
3996 a.Add ((AnonymousTypeParameter) $3);
3999 | COMPLETE_COMPLETION
4001 $$ = new EmptyCompletion ();
4003 | anonymous_type_parameter COMPLETE_COMPLETION
4009 anonymous_type_parameter
4010 : identifier_inside_body ASSIGN variable_initializer
4012 var lt = (LocatedToken)$1;
4013 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4014 lbag.AddLocation ($$, GetLocation ($2));
4016 | identifier_inside_body
4018 var lt = (LocatedToken)$1;
4019 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4020 lt.Value, lt.Location);
4024 MemberAccess ma = (MemberAccess) $1;
4025 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4029 report.Error (746, lexer.Location,
4030 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4042 | rank_specifier rank_specifiers
4044 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4050 : OPEN_BRACKET CLOSE_BRACKET
4052 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4053 lbag.AddLocation ($$, GetLocation ($2));
4055 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4057 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4058 lbag.AddLocation ($$, GetLocation ($3));
4067 | dim_separators COMMA
4069 $$ = ((int) $1) + 1;
4073 opt_array_initializer
4085 : OPEN_BRACE CLOSE_BRACE
4087 var ai = new ArrayInitializer (0, GetLocation ($1));
4088 ai.VariableDeclaration = current_variable;
4089 lbag.AddLocation (ai, GetLocation ($2));
4092 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4094 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4095 ai.VariableDeclaration = current_variable;
4097 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4099 lbag.AddLocation (ai, GetLocation ($4));
4105 variable_initializer_list
4106 : variable_initializer
4108 var list = new List<Expression> (4);
4109 list.Add ((Expression) $1);
4112 | variable_initializer_list COMMA variable_initializer
4114 var list = (List<Expression>) $1;
4115 list.Add ((Expression) $3);
4121 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4123 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4124 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4128 typeof_type_expression
4132 Error_TypeExpected (lexer.Location);
4140 if (lang_version < LanguageVersion.ISO_2)
4141 FeatureIsNotAvailable (GetLocation ($1), "generics");
4147 qualified_alias_member
4148 : IDENTIFIER DOUBLE_COLON
4150 var lt = (LocatedToken) $1;
4151 if (lang_version == LanguageVersion.ISO_1)
4152 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4159 : SIZEOF open_parens_any type CLOSE_PARENS
4161 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4162 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4164 | SIZEOF open_parens_any type error
4166 Error_SyntaxError (yyToken);
4168 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4169 lbag.AddLocation ($$, GetLocation ($2));
4174 : CHECKED open_parens_any expression CLOSE_PARENS
4176 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4177 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4181 Error_SyntaxError (yyToken);
4183 $$ = new CheckedExpr (null, GetLocation ($1));
4187 unchecked_expression
4188 : UNCHECKED open_parens_any expression CLOSE_PARENS
4190 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4191 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4195 Error_SyntaxError (yyToken);
4197 $$ = new UnCheckedExpr (null, GetLocation ($1));
4201 pointer_member_access
4202 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4204 var lt = (LocatedToken) $3;
4205 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4209 anonymous_method_expression
4210 : DELEGATE opt_anonymous_method_signature
4212 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4216 $$ = end_anonymous ((ParametersBlock) $4);
4218 | ASYNC DELEGATE opt_anonymous_method_signature
4220 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4224 $$ = end_anonymous ((ParametersBlock) $5);
4228 opt_anonymous_method_signature
4231 $$ = ParametersCompiled.Undefined;
4233 | anonymous_method_signature
4236 anonymous_method_signature
4239 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4241 opt_formal_parameter_list CLOSE_PARENS
4243 valid_param_mod = 0;
4248 default_value_expression
4249 : DEFAULT open_parens_any type CLOSE_PARENS
4251 if (lang_version < LanguageVersion.ISO_2)
4252 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4254 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4255 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4260 : primary_expression
4261 | BANG prefixed_unary_expression
4263 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4265 | TILDE prefixed_unary_expression
4267 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4269 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4271 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4272 lbag.AddLocation ($$, GetLocation ($3));
4274 | AWAIT prefixed_unary_expression
4277 if (current_anonymous_method is LambdaExpression) {
4278 report.Error (4034, GetLocation ($1),
4279 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4280 } else if (current_anonymous_method != null) {
4281 report.Error (4035, GetLocation ($1),
4282 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4283 } else if (interactive_async != null) {
4284 current_block.Explicit.RegisterAsyncAwait ();
4285 interactive_async = true;
4287 report.Error (4033, GetLocation ($1),
4288 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4291 current_block.Explicit.RegisterAsyncAwait ();
4294 $$ = new Await ((Expression) $2, GetLocation ($1));
4298 Error_SyntaxError (yyToken);
4300 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4304 Error_SyntaxError (yyToken);
4306 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4308 | OPEN_PARENS_CAST type CLOSE_PARENS error
4310 Error_SyntaxError (yyToken);
4312 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4313 lbag.AddLocation ($$, GetLocation ($3));
4317 Error_SyntaxError (yyToken);
4319 $$ = new Await (null, GetLocation ($1));
4324 // The idea to split this out is from Rhys' grammar
4325 // to solve the problem with casts.
4327 prefixed_unary_expression
4329 | PLUS prefixed_unary_expression
4331 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4333 | MINUS prefixed_unary_expression
4335 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4337 | OP_INC prefixed_unary_expression
4339 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4341 | OP_DEC prefixed_unary_expression
4343 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4345 | STAR prefixed_unary_expression
4347 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4349 | BITWISE_AND prefixed_unary_expression
4351 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4355 Error_SyntaxError (yyToken);
4357 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4361 Error_SyntaxError (yyToken);
4363 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4367 Error_SyntaxError (yyToken);
4369 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4373 Error_SyntaxError (yyToken);
4375 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4379 Error_SyntaxError (yyToken);
4381 $$ = new Indirection (null, GetLocation ($1));
4385 Error_SyntaxError (yyToken);
4387 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4391 multiplicative_expression
4392 : prefixed_unary_expression
4393 | multiplicative_expression STAR prefixed_unary_expression
4395 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4396 lbag.AddLocation ($$, GetLocation ($2));
4398 | multiplicative_expression DIV prefixed_unary_expression
4400 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4401 lbag.AddLocation ($$, GetLocation ($2));
4403 | multiplicative_expression PERCENT prefixed_unary_expression
4405 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4406 lbag.AddLocation ($$, GetLocation ($2));
4408 | multiplicative_expression STAR error
4410 Error_SyntaxError (yyToken);
4412 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4413 lbag.AddLocation ($$, GetLocation ($2));
4415 | multiplicative_expression DIV error
4417 Error_SyntaxError (yyToken);
4419 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4420 lbag.AddLocation ($$, GetLocation ($2));
4422 | multiplicative_expression PERCENT error
4424 Error_SyntaxError (yyToken);
4426 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4427 lbag.AddLocation ($$, GetLocation ($2));
4432 : multiplicative_expression
4433 | additive_expression PLUS multiplicative_expression
4435 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4436 lbag.AddLocation ($$, GetLocation ($2));
4438 | additive_expression MINUS multiplicative_expression
4440 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4441 lbag.AddLocation ($$, GetLocation ($2));
4443 | additive_expression PLUS error
4445 Error_SyntaxError (yyToken);
4447 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4448 lbag.AddLocation ($$, GetLocation ($2));
4450 | additive_expression MINUS error
4452 Error_SyntaxError (yyToken);
4454 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4455 lbag.AddLocation ($$, GetLocation ($2));
4457 | additive_expression AS type
4459 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4461 | additive_expression IS pattern_type_expr opt_identifier
4463 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4465 if (lang_version != LanguageVersion.Experimental)
4466 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4468 var lt = (LocatedToken) $4;
4469 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4470 current_block.AddLocalName (is_expr.Variable);
4475 | additive_expression IS pattern_expr
4477 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4478 if (lang_version != LanguageVersion.Experimental)
4479 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4483 | additive_expression AS error
4485 Error_SyntaxError (yyToken);
4487 $$ = new As ((Expression) $1, null, GetLocation ($2));
4489 | additive_expression IS error
4491 Error_SyntaxError (yyToken);
4493 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4497 var lt = (LocatedToken) $1;
4498 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4502 var lt = (LocatedToken) $1;
4503 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4513 | PLUS prefixed_unary_expression
4515 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4517 | MINUS prefixed_unary_expression
4519 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4522 | default_value_expression
4523 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4525 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4526 lbag.AddLocation ($$, GetLocation ($3));
4530 $$ = new WildcardPattern (GetLocation ($1));
4532 | pattern_expr_invocation
4536 pattern_expr_invocation
4537 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4539 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4544 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4546 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4550 pattern_property_list
4551 : pattern_property_entry
4553 var list = new List<PropertyPatternMember> ();
4554 list.Add ((PropertyPatternMember) $1);
4557 | pattern_property_list COMMA pattern_property_entry
4559 var list = (List<PropertyPatternMember>) $1;
4560 list.Add ((PropertyPatternMember) $3);
4565 pattern_property_entry
4566 : identifier_inside_body IS pattern
4568 var lt = (LocatedToken) $1;
4569 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4575 | pattern_type_expr opt_identifier
4578 var lt = (LocatedToken) $2;
4579 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4580 current_block.AddLocalName (variable);
4588 $$ = new Arguments (0);
4596 Arguments args = new Arguments (4);
4597 args.Add ((Argument) $1);
4600 | pattern_list COMMA pattern_argument
4602 Arguments args = (Arguments) $1;
4603 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4604 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4606 args.Add ((Argument) $3);
4614 $$ = new Argument ((Expression) $1);
4616 | IDENTIFIER COLON pattern
4618 var lt = (LocatedToken) $1;
4619 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4624 : additive_expression
4625 | shift_expression OP_SHIFT_LEFT additive_expression
4627 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4628 lbag.AddLocation ($$, GetLocation ($2));
4630 | shift_expression OP_SHIFT_RIGHT additive_expression
4632 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4633 lbag.AddLocation ($$, GetLocation ($2));
4635 | shift_expression OP_SHIFT_LEFT error
4637 Error_SyntaxError (yyToken);
4639 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4640 lbag.AddLocation ($$, GetLocation ($2));
4642 | shift_expression OP_SHIFT_RIGHT error
4644 Error_SyntaxError (yyToken);
4646 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4647 lbag.AddLocation ($$, GetLocation ($2));
4651 relational_expression
4653 | relational_expression OP_LT shift_expression
4655 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4656 lbag.AddLocation ($$, GetLocation ($2));
4658 | relational_expression OP_GT shift_expression
4660 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4661 lbag.AddLocation ($$, GetLocation ($2));
4663 | relational_expression OP_LE shift_expression
4665 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4666 lbag.AddLocation ($$, GetLocation ($2));
4668 | relational_expression OP_GE shift_expression
4670 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4671 lbag.AddLocation ($$, GetLocation ($2));
4673 | relational_expression OP_LT error
4675 Error_SyntaxError (yyToken);
4677 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4678 lbag.AddLocation ($$, GetLocation ($2));
4680 | relational_expression OP_GT error
4682 Error_SyntaxError (yyToken);
4684 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4685 lbag.AddLocation ($$, GetLocation ($2));
4687 | relational_expression OP_LE error
4689 Error_SyntaxError (yyToken);
4691 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4692 lbag.AddLocation ($$, GetLocation ($2));
4694 | relational_expression OP_GE error
4696 Error_SyntaxError (yyToken);
4698 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4699 lbag.AddLocation ($$, GetLocation ($2));
4704 : relational_expression
4705 | equality_expression OP_EQ relational_expression
4707 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4708 lbag.AddLocation ($$, GetLocation ($2));
4710 | equality_expression OP_NE relational_expression
4712 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4713 lbag.AddLocation ($$, GetLocation ($2));
4715 | equality_expression OP_EQ error
4717 Error_SyntaxError (yyToken);
4719 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4720 lbag.AddLocation ($$, GetLocation ($2));
4722 | equality_expression OP_NE error
4724 Error_SyntaxError (yyToken);
4726 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4727 lbag.AddLocation ($$, GetLocation ($2));
4732 : equality_expression
4733 | and_expression BITWISE_AND equality_expression
4735 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4736 lbag.AddLocation ($$, GetLocation ($2));
4738 | and_expression BITWISE_AND error
4740 Error_SyntaxError (yyToken);
4742 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4743 lbag.AddLocation ($$, GetLocation ($2));
4747 exclusive_or_expression
4749 | exclusive_or_expression CARRET and_expression
4751 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4752 lbag.AddLocation ($$, GetLocation ($2));
4754 | exclusive_or_expression CARRET error
4756 Error_SyntaxError (yyToken);
4758 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4759 lbag.AddLocation ($$, GetLocation ($2));
4763 inclusive_or_expression
4764 : exclusive_or_expression
4765 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4767 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4768 lbag.AddLocation ($$, GetLocation ($2));
4770 | inclusive_or_expression BITWISE_OR error
4772 Error_SyntaxError (yyToken);
4774 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4775 lbag.AddLocation ($$, GetLocation ($2));
4779 conditional_and_expression
4780 : inclusive_or_expression
4781 | conditional_and_expression OP_AND inclusive_or_expression
4783 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4784 lbag.AddLocation ($$, GetLocation ($2));
4786 | conditional_and_expression OP_AND error
4788 Error_SyntaxError (yyToken);
4790 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4791 lbag.AddLocation ($$, GetLocation ($2));
4795 conditional_or_expression
4796 : conditional_and_expression
4797 | conditional_or_expression OP_OR conditional_and_expression
4799 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4800 lbag.AddLocation ($$, GetLocation ($2));
4802 | conditional_or_expression OP_OR error
4804 Error_SyntaxError (yyToken);
4806 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4807 lbag.AddLocation ($$, GetLocation ($2));
4811 null_coalescing_expression
4812 : conditional_or_expression
4813 | conditional_or_expression OP_COALESCING null_coalescing_expression
4815 if (lang_version < LanguageVersion.ISO_2)
4816 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4818 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4819 lbag.AddLocation ($$, GetLocation ($2));
4823 conditional_expression
4824 : null_coalescing_expression
4825 | null_coalescing_expression INTERR expression COLON expression
4827 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4828 lbag.AddLocation ($$, GetLocation ($4));
4830 | null_coalescing_expression INTERR expression error
4832 Error_SyntaxError (yyToken);
4834 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4836 | null_coalescing_expression INTERR expression COLON error
4838 Error_SyntaxError (yyToken);
4840 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4841 lbag.AddLocation ($$, GetLocation ($4));
4843 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4845 Error_SyntaxError (Token.CLOSE_BRACE);
4847 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4848 lbag.AddLocation ($$, GetLocation ($4));
4849 lexer.putback ('}');
4853 assignment_expression
4854 : prefixed_unary_expression ASSIGN expression
4856 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4857 lbag.AddLocation ($$, GetLocation ($2));
4859 | prefixed_unary_expression OP_MULT_ASSIGN expression
4861 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4862 lbag.AddLocation ($$, GetLocation ($2));
4864 | prefixed_unary_expression OP_DIV_ASSIGN expression
4866 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4867 lbag.AddLocation ($$, GetLocation ($2));
4869 | prefixed_unary_expression OP_MOD_ASSIGN expression
4871 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4872 lbag.AddLocation ($$, GetLocation ($2));
4874 | prefixed_unary_expression OP_ADD_ASSIGN expression
4876 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4877 lbag.AddLocation ($$, GetLocation ($2));
4879 | prefixed_unary_expression OP_SUB_ASSIGN expression
4881 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4882 lbag.AddLocation ($$, GetLocation ($2));
4884 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4886 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4887 lbag.AddLocation ($$, GetLocation ($2));
4889 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4891 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4892 lbag.AddLocation ($$, GetLocation ($2));
4894 | prefixed_unary_expression OP_AND_ASSIGN expression
4896 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4897 lbag.AddLocation ($$, GetLocation ($2));
4899 | prefixed_unary_expression OP_OR_ASSIGN expression
4901 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4902 lbag.AddLocation ($$, GetLocation ($2));
4904 | prefixed_unary_expression OP_XOR_ASSIGN expression
4906 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4907 lbag.AddLocation ($$, GetLocation ($2));
4911 lambda_parameter_list
4914 var pars = new List<Parameter> (4);
4915 pars.Add ((Parameter) $1);
4919 | lambda_parameter_list COMMA lambda_parameter
4921 var pars = (List<Parameter>) $1;
4922 Parameter p = (Parameter)$3;
4923 if (pars[0].GetType () != p.GetType ()) {
4924 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4933 : parameter_modifier parameter_type identifier_inside_body
4935 var lt = (LocatedToken) $3;
4937 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4939 | parameter_type identifier_inside_body
4941 var lt = (LocatedToken) $2;
4943 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4947 var lt = (LocatedToken) $1;
4948 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4952 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4953 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4957 opt_lambda_parameter_list
4958 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4959 | lambda_parameter_list {
4960 var pars_list = (List<Parameter>) $1;
4961 $$ = new ParametersCompiled (pars_list.ToArray ());
4965 lambda_expression_body
4967 start_block (Location.Null);
4969 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4971 Block b = end_block (Location.Null);
4972 b.IsCompilerGenerated = true;
4973 b.AddStatement (new ContextualReturn ((Expression) $2));
4979 // Handles only cases like foo = x.FirstOrDefault (l => );
4980 // where we must restore current_variable
4981 Block b = end_block (Location.Null);
4982 b.IsCompilerGenerated = true;
4984 Error_SyntaxError (yyToken);
4993 Error_SyntaxError (yyToken);
5001 var lt = (LocatedToken) $1;
5002 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5003 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5005 lambda_expression_body
5007 $$ = end_anonymous ((ParametersBlock) $4);
5008 lbag.AddLocation ($$, GetLocation ($2));
5012 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5013 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5014 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5016 lambda_expression_body
5018 $$ = end_anonymous ((ParametersBlock) $4);
5019 lbag.AddLocation ($$, GetLocation ($2));
5021 | ASYNC identifier_inside_body ARROW
5023 var lt = (LocatedToken) $2;
5024 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5025 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5027 lambda_expression_body
5029 $$ = end_anonymous ((ParametersBlock) $5);
5030 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5032 | OPEN_PARENS_LAMBDA
5034 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5036 opt_lambda_parameter_list CLOSE_PARENS ARROW
5038 valid_param_mod = 0;
5039 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5041 lambda_expression_body
5043 $$ = end_anonymous ((ParametersBlock) $7);
5044 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5046 | ASYNC 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) $4, true, GetLocation ($1));
5055 lambda_expression_body
5057 $$ = end_anonymous ((ParametersBlock) $8);
5058 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5063 : assignment_expression
5064 | non_assignment_expression
5067 non_assignment_expression
5068 : conditional_expression
5073 $$ = new ArglistAccess (GetLocation ($1));
5077 undocumented_expressions
5078 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5080 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5081 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5083 | REFTYPE open_parens_any expression CLOSE_PARENS
5085 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5086 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5088 | MAKEREF open_parens_any expression CLOSE_PARENS
5090 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5091 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5102 $$ = new BooleanExpression ((Expression) $1);
5106 opt_primary_parameters
5111 | primary_parameters
5115 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5119 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5120 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5122 if (lang_version != LanguageVersion.Experimental)
5123 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5127 opt_primary_parameters_with_class_base
5136 | primary_parameters
5140 | primary_parameters class_base
5144 | primary_parameters class_base OPEN_PARENS
5146 ++lexer.parsing_block;
5147 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5149 opt_argument_list CLOSE_PARENS
5151 lbag.AppendToMember (current_container, GetLocation ($6));
5152 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5153 --lexer.parsing_block;
5169 type_declaration_name
5171 lexer.ConstraintsParsing = true;
5173 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5174 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5175 FeatureIsNotAvailable (c.Location, "static classes");
5178 push_current_container (c, $3);
5179 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5181 opt_primary_parameters_with_class_base
5182 opt_type_parameter_constraints_clauses
5184 valid_param_mod = 0;
5185 lexer.ConstraintsParsing = false;
5188 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5191 current_container.SetConstraints ((List<Constraints>) $9);
5192 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5195 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5196 Lexer.doc_state = XmlCommentState.Allowed;
5199 lexer.parsing_modifiers = true;
5201 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5203 --lexer.parsing_declaration;
5205 Lexer.doc_state = XmlCommentState.Allowed;
5210 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5212 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5214 $$ = pop_current_class ();
5222 { $$ = $1; } // location
5228 mod_locations = null;
5230 lexer.parsing_modifiers = false;
5234 lexer.parsing_modifiers = false;
5240 | modifiers modifier
5242 var m1 = (Modifiers) $1;
5243 var m2 = (Modifiers) $2;
5245 if ((m1 & m2) != 0) {
5246 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5247 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5248 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5249 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5250 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5251 "More than one protection modifier specified");
5262 StoreModifierLocation ($$, GetLocation ($1));
5264 if (current_container.Kind == MemberKind.Namespace)
5265 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5269 $$ = Modifiers.PUBLIC;
5270 StoreModifierLocation ($$, GetLocation ($1));
5274 $$ = Modifiers.PROTECTED;
5275 StoreModifierLocation ($$, GetLocation ($1));
5279 $$ = Modifiers.INTERNAL;
5280 StoreModifierLocation ($$, GetLocation ($1));
5284 $$ = Modifiers.PRIVATE;
5285 StoreModifierLocation ($$, GetLocation ($1));
5289 $$ = Modifiers.ABSTRACT;
5290 StoreModifierLocation ($$, GetLocation ($1));
5294 $$ = Modifiers.SEALED;
5295 StoreModifierLocation ($$, GetLocation ($1));
5299 $$ = Modifiers.STATIC;
5300 StoreModifierLocation ($$, GetLocation ($1));
5304 $$ = Modifiers.READONLY;
5305 StoreModifierLocation ($$, GetLocation ($1));
5309 $$ = Modifiers.VIRTUAL;
5310 StoreModifierLocation ($$, GetLocation ($1));
5314 $$ = Modifiers.OVERRIDE;
5315 StoreModifierLocation ($$, GetLocation ($1));
5319 $$ = Modifiers.EXTERN;
5320 StoreModifierLocation ($$, GetLocation ($1));
5324 $$ = Modifiers.VOLATILE;
5325 StoreModifierLocation ($$, GetLocation ($1));
5329 $$ = Modifiers.UNSAFE;
5330 StoreModifierLocation ($$, GetLocation ($1));
5331 if (!settings.Unsafe)
5332 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5336 $$ = Modifiers.ASYNC;
5337 StoreModifierLocation ($$, GetLocation ($1));
5349 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5351 | COLON type_list error
5353 Error_SyntaxError (yyToken);
5355 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5359 opt_type_parameter_constraints_clauses
5361 | type_parameter_constraints_clauses
5367 type_parameter_constraints_clauses
5368 : type_parameter_constraints_clause
5370 var constraints = new List<Constraints> (1);
5371 constraints.Add ((Constraints) $1);
5374 | type_parameter_constraints_clauses type_parameter_constraints_clause
5376 var constraints = (List<Constraints>) $1;
5377 Constraints new_constraint = (Constraints)$2;
5379 foreach (Constraints c in constraints) {
5380 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5381 report.Error (409, new_constraint.Location,
5382 "A constraint clause has already been specified for type parameter `{0}'",
5383 new_constraint.TypeParameter.Value);
5387 constraints.Add (new_constraint);
5392 type_parameter_constraints_clause
5393 : WHERE IDENTIFIER COLON type_parameter_constraints
5395 var lt = (LocatedToken) $2;
5396 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5397 lbag.AddLocation ($$, GetLocation ($3));
5399 | WHERE IDENTIFIER error
5401 Error_SyntaxError (yyToken);
5403 var lt = (LocatedToken) $2;
5404 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5408 type_parameter_constraints
5409 : type_parameter_constraint
5411 var constraints = new List<FullNamedExpression> (1);
5412 constraints.Add ((FullNamedExpression) $1);
5415 | type_parameter_constraints COMMA type_parameter_constraint
5417 var constraints = (List<FullNamedExpression>) $1;
5418 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5419 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5420 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5423 prev = $3 as SpecialContraintExpr;
5425 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5426 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5428 prev = constraints [0] as SpecialContraintExpr;
5429 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5430 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5435 constraints.Add ((FullNamedExpression) $3);
5440 type_parameter_constraint
5443 if ($1 is ComposedCast)
5444 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5448 | NEW OPEN_PARENS CLOSE_PARENS
5450 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5451 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5455 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5459 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5463 opt_type_parameter_variance
5468 | type_parameter_variance
5470 if (lang_version <= LanguageVersion.V_3)
5471 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5477 type_parameter_variance
5480 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5484 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5493 // A block is "contained" on the following places:
5495 // property_declaration as part of the accessor body (get/set)
5496 // operator_declaration
5497 // constructor_declaration
5498 // destructor_declaration
5499 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5504 ++lexer.parsing_block;
5505 start_block (GetLocation ($1));
5507 opt_statement_list block_end
5516 --lexer.parsing_block;
5517 $$ = end_block (GetLocation ($1));
5519 | COMPLETE_COMPLETION
5521 --lexer.parsing_block;
5522 $$ = end_block (lexer.Location);
5530 ++lexer.parsing_block;
5531 current_block.StartLocation = GetLocation ($1);
5533 opt_statement_list CLOSE_BRACE
5535 --lexer.parsing_block;
5536 $$ = end_block (GetLocation ($4));
5547 | statement_list statement
5551 : block_variable_declaration
5553 current_block.AddStatement ((Statement) $1);
5555 | valid_declaration_statement
5557 current_block.AddStatement ((Statement) $1);
5562 Error_SyntaxError (yyToken);
5568 // The interactive_statement and its derivatives are only
5569 // used to provide a special version of `expression_statement'
5570 // that has a side effect of assigning the expression to
5573 interactive_statement_list
5574 : interactive_statement
5575 | interactive_statement_list interactive_statement
5578 interactive_statement
5579 : block_variable_declaration
5581 current_block.AddStatement ((Statement) $1);
5583 | interactive_valid_declaration_statement
5585 current_block.AddStatement ((Statement) $1);
5590 valid_declaration_statement
5593 | expression_statement
5594 | selection_statement
5595 | iteration_statement
5599 | unchecked_statement
5606 interactive_valid_declaration_statement
5609 | interactive_expression_statement
5610 | selection_statement
5611 | iteration_statement
5615 | unchecked_statement
5623 : valid_declaration_statement
5624 | block_variable_declaration
5626 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5631 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5636 Error_SyntaxError (yyToken);
5637 $$ = new EmptyStatement (GetLocation ($1));
5644 // Uses lexer.Location because semicolon location is not kept in quick mode
5645 $$ = new EmptyStatement (lexer.Location);
5650 : identifier_inside_body COLON
5652 var lt = (LocatedToken) $1;
5653 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5654 lbag.AddLocation (labeled, GetLocation ($2));
5655 current_block.AddLabel (labeled);
5656 current_block.AddStatement (labeled);
5662 : variable_type_simple
5663 | variable_type_simple rank_specifiers
5666 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5668 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5673 * The following is from Rhys' grammar:
5674 * > Types in local variable declarations must be recognized as
5675 * > expressions to prevent reduce/reduce errors in the grammar.
5676 * > The expressions are converted into types during semantic analysis.
5678 variable_type_simple
5679 : type_name_expression opt_nullable
5681 // Ok, the above "primary_expression" is there to get rid of
5682 // both reduce/reduce and shift/reduces in the grammar, it should
5683 // really just be "type_name". If you use type_name, a reduce/reduce
5684 // creeps up. If you use namespace_or_type_name (which is all we need
5685 // really) two shift/reduces appear.
5688 // So the super-trick is that primary_expression
5689 // can only be either a SimpleName or a MemberAccess.
5690 // The MemberAccess case arises when you have a fully qualified type-name like :
5692 // SimpleName is when you have
5695 var expr = (ATypeNameExpression) $1;
5697 if (expr.Name == "var" && expr is SimpleName)
5698 $$ = new VarExpr (expr.Location);
5702 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5705 | type_name_expression pointer_stars
5707 var expr = (ATypeNameExpression) $1;
5708 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5710 | builtin_type_expression
5716 | pointer_star pointer_stars
5718 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5726 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5730 identifier_inside_body
5734 $$ = Error_AwaitAsIdentifier ($1);
5738 block_variable_declaration
5739 : variable_type identifier_inside_body
5741 var lt = (LocatedToken) $2;
5742 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5743 current_block.AddLocalName (li);
5744 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5746 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5748 $$ = current_variable;
5749 current_variable = null;
5751 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5753 lbag.AddLocation ($$, GetLocation ($6));
5755 | CONST variable_type identifier_inside_body
5757 var lt = (LocatedToken) $3;
5758 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5759 current_block.AddLocalName (li);
5760 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5762 const_variable_initializer opt_const_declarators SEMICOLON
5764 $$ = current_variable;
5765 current_variable = null;
5766 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5770 opt_local_variable_initializer
5772 | ASSIGN block_variable_initializer
5774 current_variable.Initializer = (Expression) $2;
5775 PushLocation (GetLocation ($1));
5776 $$ = current_variable;
5780 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5781 report.Error (650, lexer.Location,
5782 "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");
5784 Error_SyntaxError (yyToken);
5789 opt_variable_declarators
5791 | variable_declarators
5794 opt_using_or_fixed_variable_declarators
5796 | variable_declarators
5798 foreach (var d in current_variable.Declarators) {
5799 if (d.Initializer == null)
5800 Error_MissingInitializer (d.Variable.Location);
5805 variable_declarators
5806 : variable_declarator
5807 | variable_declarators variable_declarator
5811 : COMMA identifier_inside_body
5813 var lt = (LocatedToken) $2;
5814 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5815 var d = new BlockVariableDeclarator (li, null);
5816 current_variable.AddDeclarator (d);
5817 current_block.AddLocalName (li);
5818 lbag.AddLocation (d, GetLocation ($1));
5820 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5822 var lt = (LocatedToken) $2;
5823 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5824 var d = new BlockVariableDeclarator (li, (Expression) $4);
5825 current_variable.AddDeclarator (d);
5826 current_block.AddLocalName (li);
5827 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5831 const_variable_initializer
5834 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5836 | ASSIGN constant_initializer_expr
5838 current_variable.Initializer = (Expression) $2;
5842 opt_const_declarators
5849 | const_declarators const_declarator
5853 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5855 var lt = (LocatedToken) $2;
5856 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5857 var d = new BlockVariableDeclarator (li, (Expression) $4);
5858 current_variable.AddDeclarator (d);
5859 current_block.AddLocalName (li);
5860 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5864 block_variable_initializer
5865 : variable_initializer
5866 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5868 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5869 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5871 | STACKALLOC simple_type
5873 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5874 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5878 expression_statement
5879 : statement_expression SEMICOLON
5882 lbag.AddStatement ($$, GetLocation ($2));
5884 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5885 | statement_expression CLOSE_BRACE
5888 report.Error (1002, GetLocation ($2), "; expected");
5889 lexer.putback ('}');
5893 interactive_expression_statement
5894 : interactive_statement_expression SEMICOLON { $$ = $1; }
5895 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5899 // We have to do the wrapping here and not in the case above,
5900 // because statement_expression is used for example in for_statement
5902 statement_expression
5905 ExpressionStatement s = $1 as ExpressionStatement;
5907 var expr = $1 as Expression;
5908 $$ = new StatementErrorExpression (expr);
5910 $$ = new StatementExpression (s);
5915 interactive_statement_expression
5918 Expression expr = (Expression) $1;
5919 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5923 Error_SyntaxError (yyToken);
5924 $$ = new EmptyStatement (GetLocation ($1));
5934 : IF open_parens_any boolean_expression CLOSE_PARENS
5937 if ($5 is EmptyStatement)
5938 Warning_EmptyStatement (GetLocation ($5));
5940 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5941 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5943 | IF open_parens_any boolean_expression CLOSE_PARENS
5944 embedded_statement ELSE embedded_statement
5946 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5947 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5949 if ($5 is EmptyStatement)
5950 Warning_EmptyStatement (GetLocation ($5));
5951 if ($7 is EmptyStatement)
5952 Warning_EmptyStatement (GetLocation ($7));
5954 | IF open_parens_any boolean_expression error
5956 Error_SyntaxError (yyToken);
5958 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5959 lbag.AddStatement ($$, GetLocation ($2));
5964 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5966 start_block (GetLocation ($5));
5968 opt_switch_sections CLOSE_BRACE
5970 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5971 end_block (GetLocation ($8));
5972 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5974 | SWITCH open_parens_any expression error
5976 Error_SyntaxError (yyToken);
5978 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5979 lbag.AddStatement ($$, GetLocation ($2));
5986 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5993 | switch_sections switch_section
5996 Error_SyntaxError (yyToken);
6001 : switch_labels statement_list
6007 var label = (SwitchLabel) $1;
6008 label.SectionStart = true;
6009 current_block.AddStatement (label);
6011 | switch_labels switch_label
6013 current_block.AddStatement ((Statement) $2);
6018 : CASE constant_expression COLON
6020 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6021 lbag.AddLocation ($$, GetLocation ($3));
6023 | CASE constant_expression error
6025 Error_SyntaxError (yyToken);
6026 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6029 | CASE pattern_expr_invocation COLON
6031 if (lang_version != LanguageVersion.Experimental)
6032 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6034 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6035 PatternMatching = true
6037 lbag.AddLocation ($$, GetLocation ($3));
6042 $$ = new SwitchLabel (null, GetLocation ($1));
6054 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6056 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6057 Warning_EmptyStatement (GetLocation ($5));
6059 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6060 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6062 | WHILE open_parens_any boolean_expression error
6064 Error_SyntaxError (yyToken);
6066 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6067 lbag.AddStatement ($$, GetLocation ($2));
6072 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6074 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6075 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6077 | DO embedded_statement error
6079 Error_SyntaxError (yyToken);
6080 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6082 | DO embedded_statement WHILE open_parens_any boolean_expression error
6084 Error_SyntaxError (yyToken);
6086 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6087 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6092 : FOR open_parens_any
6094 start_block (GetLocation ($2));
6095 current_block.IsCompilerGenerated = true;
6096 For f = new For (GetLocation ($1));
6097 current_block.AddStatement (f);
6106 // Has to use be extra rule to recover started block
6108 : opt_for_initializer SEMICOLON
6110 ((For) $0).Initializer = (Statement) $1;
6112 // Pass the "For" object to the iterator_part4
6113 oob_stack.Push ($0);
6115 for_condition_and_iterator_part
6118 var locations = (Tuple<Location,Location>) $4;
6120 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6121 Warning_EmptyStatement (GetLocation ($5));
6124 f.Statement = (Statement) $5;
6125 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6127 $$ = end_block (GetLocation ($2));
6131 Error_SyntaxError (yyToken);
6132 $$ = end_block (current_block.StartLocation);
6136 for_condition_and_iterator_part
6137 : opt_for_condition SEMICOLON
6139 For f = (For) oob_stack.Peek ();
6140 f.Condition = (BooleanExpression) $1;
6143 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6146 // Handle errors in the case of opt_for_condition being followed by
6147 // a close parenthesis
6148 | opt_for_condition close_parens_close_brace {
6149 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6150 For f = (For) oob_stack.Peek ();
6151 f.Condition = (BooleanExpression) $1;
6152 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6157 : opt_for_iterator CLOSE_PARENS {
6158 For f = (For) oob_stack.Peek ();
6159 f.Iterator = (Statement) $1;
6160 $$ = GetLocation ($2);
6162 | opt_for_iterator CLOSE_BRACE {
6163 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6164 For f = (For) oob_stack.Peek ();
6165 f.Iterator = (Statement) $1;
6166 $$ = GetLocation ($2);
6170 close_parens_close_brace
6172 | CLOSE_BRACE { lexer.putback ('}'); }
6176 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6181 : variable_type identifier_inside_body
6183 var lt = (LocatedToken) $2;
6184 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6185 current_block.AddLocalName (li);
6186 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6188 opt_local_variable_initializer opt_variable_declarators
6190 $$ = current_variable;
6192 lbag.AddLocation (current_variable, PopLocation ());
6194 current_variable = null;
6196 | statement_expression_list
6200 : /* empty */ { $$ = null; }
6201 | boolean_expression
6205 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6210 : statement_expression_list
6213 statement_expression_list
6214 : statement_expression
6215 | statement_expression_list COMMA statement_expression
6217 var sl = $1 as StatementList;
6219 sl = new StatementList ((Statement) $1, (Statement) $3);
6220 lbag.AddStatement (sl, GetLocation ($2));
6222 sl.Add ((Statement) $3);
6223 lbag.AppendTo (sl, GetLocation ($2));
6231 : FOREACH open_parens_any type error
6233 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6235 start_block (GetLocation ($2));
6236 current_block.IsCompilerGenerated = true;
6238 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6239 current_block.AddStatement (f);
6241 lbag.AddStatement (f, GetLocation ($2));
6242 $$ = end_block (GetLocation ($4));
6244 | FOREACH open_parens_any type identifier_inside_body error
6246 Error_SyntaxError (yyToken);
6248 start_block (GetLocation ($2));
6249 current_block.IsCompilerGenerated = true;
6251 var lt = (LocatedToken) $4;
6252 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6253 current_block.AddLocalName (li);
6255 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6256 current_block.AddStatement (f);
6258 lbag.AddStatement (f, GetLocation ($2));
6259 $$ = end_block (GetLocation ($5));
6261 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6263 start_block (GetLocation ($2));
6264 current_block.IsCompilerGenerated = true;
6266 var lt = (LocatedToken) $4;
6267 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6268 current_block.AddLocalName (li);
6273 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6274 Warning_EmptyStatement (GetLocation ($9));
6276 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6277 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6278 end_block (GetLocation ($7));
6286 | continue_statement
6296 $$ = new Break (GetLocation ($1));
6297 lbag.AddStatement ($$, GetLocation ($2));
6302 : CONTINUE SEMICOLON
6304 $$ = new Continue (GetLocation ($1));
6305 lbag.AddStatement ($$, GetLocation ($2));
6309 Error_SyntaxError (yyToken);
6310 $$ = new Continue (GetLocation ($1));
6315 : GOTO identifier_inside_body SEMICOLON
6317 var lt = (LocatedToken) $2;
6318 $$ = new Goto (lt.Value, GetLocation ($1));
6319 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6321 | GOTO CASE constant_expression SEMICOLON
6323 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6324 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6326 | GOTO DEFAULT SEMICOLON
6328 $$ = new GotoDefault (GetLocation ($1));
6329 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6334 : RETURN opt_expression SEMICOLON
6336 $$ = new Return ((Expression) $2, GetLocation ($1));
6337 lbag.AddStatement ($$, GetLocation ($3));
6339 | RETURN expression error
6341 Error_SyntaxError (yyToken);
6342 $$ = new Return ((Expression) $2, GetLocation ($1));
6346 Error_SyntaxError (yyToken);
6347 $$ = new Return (null, GetLocation ($1));
6352 : THROW opt_expression SEMICOLON
6354 $$ = new Throw ((Expression) $2, GetLocation ($1));
6355 lbag.AddStatement ($$, GetLocation ($3));
6357 | THROW expression error
6359 Error_SyntaxError (yyToken);
6360 $$ = new Throw ((Expression) $2, GetLocation ($1));
6364 Error_SyntaxError (yyToken);
6365 $$ = new Throw (null, GetLocation ($1));
6370 : identifier_inside_body RETURN opt_expression SEMICOLON
6372 var lt = (LocatedToken) $1;
6373 string s = lt.Value;
6375 report.Error (1003, lt.Location, "; expected");
6376 } else if ($3 == null) {
6377 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6378 } else if (lang_version == LanguageVersion.ISO_1){
6379 FeatureIsNotAvailable (lt.Location, "iterators");
6382 current_block.Explicit.RegisterIteratorYield ();
6383 $$ = new Yield ((Expression) $3, lt.Location);
6384 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6386 | identifier_inside_body RETURN expression error
6388 Error_SyntaxError (yyToken);
6390 var lt = (LocatedToken) $1;
6391 string s = lt.Value;
6393 report.Error (1003, lt.Location, "; expected");
6394 } else if ($3 == null) {
6395 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6396 } else if (lang_version == LanguageVersion.ISO_1){
6397 FeatureIsNotAvailable (lt.Location, "iterators");
6400 current_block.Explicit.RegisterIteratorYield ();
6401 $$ = new Yield ((Expression) $3, lt.Location);
6402 lbag.AddStatement ($$, GetLocation ($2));
6404 | identifier_inside_body BREAK SEMICOLON
6406 var lt = (LocatedToken) $1;
6407 string s = lt.Value;
6409 report.Error (1003, lt.Location, "; expected");
6410 } else if (lang_version == LanguageVersion.ISO_1){
6411 FeatureIsNotAvailable (lt.Location, "iterators");
6414 current_block.ParametersBlock.TopBlock.IsIterator = true;
6415 $$ = new YieldBreak (lt.Location);
6416 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6426 : TRY block catch_clauses
6428 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6430 | TRY block FINALLY block
6432 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6433 lbag.AddStatement ($$, GetLocation ($3));
6435 | TRY block catch_clauses FINALLY block
6437 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6438 lbag.AddStatement ($$, GetLocation ($4));
6442 Error_SyntaxError (1524, yyToken);
6443 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6450 var l = new List<Catch> (2);
6455 | catch_clauses catch_clause
6457 var l = (List<Catch>) $1;
6459 Catch c = (Catch) $2;
6460 var prev_catch = l [l.Count - 1];
6461 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6462 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6472 | identifier_inside_body
6476 : CATCH opt_catch_filter block
6478 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6479 c.Filter = (CatchFilterExpression) $2;
6482 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6484 start_block (GetLocation ($2));
6485 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6486 c.TypeExpression = (FullNamedExpression) $3;
6489 var lt = (LocatedToken) $4;
6490 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6491 current_block.AddLocalName (c.Variable);
6494 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6496 lexer.parsing_catch_when = true;
6498 opt_catch_filter_or_error
6500 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6503 | CATCH open_parens_any error
6505 if (yyToken == Token.CLOSE_PARENS) {
6506 report.Error (1015, lexer.Location,
6507 "A type that derives from `System.Exception', `object', or `string' expected");
6509 Error_SyntaxError (yyToken);
6512 $$ = new Catch (null, GetLocation ($1));
6516 opt_catch_filter_or_error
6517 : opt_catch_filter block_prepared
6523 end_block (Location.Null);
6524 Error_SyntaxError (yyToken);
6531 lexer.parsing_catch_when = false;
6535 lexer.parsing_catch_when = false;
6537 open_parens_any expression CLOSE_PARENS
6539 if (lang_version <= LanguageVersion.V_5)
6540 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6542 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6543 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6550 $$ = new Checked ((Block) $2, GetLocation ($1));
6557 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6564 if (!settings.Unsafe)
6565 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6567 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6572 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6574 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6575 Warning_EmptyStatement (GetLocation ($5));
6577 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6578 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6580 | LOCK open_parens_any expression error
6582 Error_SyntaxError (yyToken);
6584 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6585 lbag.AddStatement ($$, GetLocation ($2));
6590 : FIXED open_parens_any variable_type identifier_inside_body
6592 start_block (GetLocation ($2));
6594 current_block.IsCompilerGenerated = true;
6595 var lt = (LocatedToken) $4;
6596 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6597 current_block.AddLocalName (li);
6598 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6600 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6602 $$ = current_variable;
6603 current_variable = null;
6607 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6608 Warning_EmptyStatement (GetLocation ($10));
6610 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6611 current_block.AddStatement (f);
6612 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6613 $$ = end_block (GetLocation ($8));
6618 : USING open_parens_any variable_type identifier_inside_body
6620 start_block (GetLocation ($2));
6622 current_block.IsCompilerGenerated = true;
6623 var lt = (LocatedToken) $4;
6624 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6625 current_block.AddLocalName (li);
6626 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6628 using_initialization CLOSE_PARENS
6630 $$ = current_variable;
6631 current_variable = null;
6635 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6636 Warning_EmptyStatement (GetLocation ($9));
6638 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6639 current_block.AddStatement (u);
6640 $$ = end_block (GetLocation ($7));
6642 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6644 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6645 Warning_EmptyStatement (GetLocation ($5));
6647 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6648 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6650 | USING open_parens_any expression error
6652 Error_SyntaxError (yyToken);
6654 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6655 lbag.AddStatement ($$, GetLocation ($2));
6659 using_initialization
6660 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6663 // It has to be here for the parent to safely restore artificial block
6664 Error_SyntaxError (yyToken);
6668 using_or_fixed_variable_initializer
6671 Error_MissingInitializer (lexer.Location);
6673 | ASSIGN variable_initializer
6675 current_variable.Initializer = (Expression) $2;
6676 $$ = current_variable;
6684 : first_from_clause query_body
6686 lexer.query_parsing = false;
6688 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6690 from.Tail.Next = (Linq.AQueryClause)$2;
6693 current_block.SetEndLocation (lexer.Location);
6694 current_block = current_block.Parent;
6696 | nested_from_clause query_body
6698 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6700 from.Tail.Next = (Linq.AQueryClause)$2;
6703 current_block.SetEndLocation (lexer.Location);
6704 current_block = current_block.Parent;
6707 // Bubble up COMPLETE_COMPLETION productions
6708 | first_from_clause COMPLETE_COMPLETION {
6709 lexer.query_parsing = false;
6712 current_block.SetEndLocation (lexer.Location);
6713 current_block = current_block.Parent;
6715 | nested_from_clause COMPLETE_COMPLETION {
6717 current_block.SetEndLocation (lexer.Location);
6718 current_block = current_block.Parent;
6723 : FROM_FIRST identifier_inside_body IN expression
6725 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6727 var lt = (LocatedToken) $2;
6728 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6729 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6730 lbag.AddLocation (clause, GetLocation ($3));
6731 $$ = new Linq.QueryExpression (clause);
6733 | FROM_FIRST type identifier_inside_body IN expression
6735 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6737 var lt = (LocatedToken) $3;
6738 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6739 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6740 IdentifierType = (FullNamedExpression)$2
6742 lbag.AddLocation (clause, GetLocation ($4));
6743 $$ = new Linq.QueryExpression (clause);
6748 : FROM identifier_inside_body IN expression
6750 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6752 var lt = (LocatedToken) $2;
6753 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6754 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6755 lbag.AddLocation (clause, GetLocation ($3));
6756 $$ = new Linq.QueryExpression (clause);
6758 | FROM type identifier_inside_body IN expression
6760 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6762 var lt = (LocatedToken) $3;
6763 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6764 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6765 IdentifierType = (FullNamedExpression)$2
6767 lbag.AddLocation (clause, GetLocation ($4));
6768 $$ = new Linq.QueryExpression (clause);
6773 : FROM identifier_inside_body IN
6775 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6779 var lt = (LocatedToken) $2;
6780 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6781 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6783 current_block.SetEndLocation (lexer.Location);
6784 current_block = current_block.Parent;
6786 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6787 lbag.AddLocation ($$, GetLocation ($3));
6789 | FROM type identifier_inside_body IN
6791 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6795 var lt = (LocatedToken) $3;
6796 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6798 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6799 IdentifierType = (FullNamedExpression)$2
6802 current_block.SetEndLocation (lexer.Location);
6803 current_block = current_block.Parent;
6805 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6807 lbag.AddLocation ($$, GetLocation ($4));
6812 : query_body_clauses select_or_group_clause opt_query_continuation
6814 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6817 head.Next = (Linq.AQueryClause)$3;
6820 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6821 clause.Tail.Next = head;
6827 | select_or_group_clause opt_query_continuation
6829 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6832 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6833 clause.Tail.Next = head;
6839 | query_body_clauses COMPLETE_COMPLETION
6840 | query_body_clauses error
6842 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6847 Error_SyntaxError (yyToken);
6852 select_or_group_clause
6855 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6859 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6861 current_block.SetEndLocation (lexer.Location);
6862 current_block = current_block.Parent;
6866 if (linq_clause_blocks == null)
6867 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6869 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6870 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6874 current_block.SetEndLocation (lexer.Location);
6875 current_block = current_block.Parent;
6877 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6881 var obj = (object[]) $5;
6883 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6884 lbag.AddLocation ($$, (Location) obj[1]);
6886 current_block.SetEndLocation (lexer.Location);
6887 current_block = current_block.Parent;
6892 : BY expression_or_error
6894 $$ = new object[] { $2, GetLocation ($1) };
6898 Error_SyntaxError (yyToken);
6899 $$ = new object[2] { null, Location.Null };
6905 | query_body_clauses query_body_clause
6907 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6921 : LET identifier_inside_body ASSIGN
6923 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6927 var lt = (LocatedToken) $2;
6928 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6929 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6930 lbag.AddLocation ($$, GetLocation ($3));
6932 current_block.SetEndLocation (lexer.Location);
6933 current_block = current_block.Parent;
6935 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6942 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6946 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6948 current_block.SetEndLocation (lexer.Location);
6949 current_block = current_block.Parent;
6954 : JOIN identifier_inside_body IN
6956 if (linq_clause_blocks == null)
6957 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6959 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6960 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6962 expression_or_error ON
6964 current_block.SetEndLocation (lexer.Location);
6965 current_block = current_block.Parent;
6967 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6968 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6970 expression_or_error EQUALS
6972 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6973 current_block.SetEndLocation (lexer.Location);
6974 current_block = current_block.Parent;
6976 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6978 expression_or_error opt_join_into
6980 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6981 current_block.SetEndLocation (lexer.Location);
6983 var outer_selector = linq_clause_blocks.Pop ();
6984 var block = linq_clause_blocks.Pop ();
6986 var lt = (LocatedToken) $2;
6987 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6988 Linq.RangeVariable into;
6992 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6993 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6996 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6998 var parent = block.Parent;
6999 while (parent is Linq.QueryBlock) {
7000 parent = parent.Parent;
7002 current_block.Parent = parent;
7004 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7006 lt = (LocatedToken) $12;
7007 into = new Linq.RangeVariable (lt.Value, lt.Location);
7009 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7010 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7013 current_block = block.Parent;
7014 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7016 | JOIN type identifier_inside_body IN
7018 if (linq_clause_blocks == null)
7019 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7021 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7022 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7024 expression_or_error ON
7026 current_block.SetEndLocation (lexer.Location);
7027 current_block = current_block.Parent;
7029 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7030 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7032 expression_or_error EQUALS
7034 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7035 current_block.SetEndLocation (lexer.Location);
7036 current_block = current_block.Parent;
7038 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7040 expression_or_error opt_join_into
7042 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7043 current_block.SetEndLocation (lexer.Location);
7045 var outer_selector = linq_clause_blocks.Pop ();
7046 var block = linq_clause_blocks.Pop ();
7048 var lt = (LocatedToken) $3;
7049 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7050 Linq.RangeVariable into;
7054 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7055 IdentifierType = (FullNamedExpression)$2
7057 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7060 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7062 var parent = block.Parent;
7063 while (parent is Linq.QueryBlock) {
7064 parent = parent.Parent;
7066 current_block.Parent = parent;
7068 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7070 lt = (LocatedToken) $13;
7071 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7073 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7074 IdentifierType = (FullNamedExpression)$2
7078 current_block = block.Parent;
7079 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7085 | INTO identifier_inside_body
7094 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7098 current_block.SetEndLocation (lexer.Location);
7099 current_block = current_block.Parent;
7109 current_block.SetEndLocation (lexer.Location);
7110 current_block = current_block.Parent;
7112 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7116 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7123 | orderings_then_by COMMA
7125 current_block.SetEndLocation (lexer.Location);
7126 current_block = current_block.Parent;
7128 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7132 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7140 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7142 | expression ASCENDING
7144 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7145 lbag.AddLocation ($$, GetLocation ($2));
7147 | expression DESCENDING
7149 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7150 lbag.AddLocation ($$, GetLocation ($2));
7157 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7159 | expression ASCENDING
7161 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7162 lbag.AddLocation ($$, GetLocation ($2));
7164 | expression DESCENDING
7166 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7167 lbag.AddLocation ($$, GetLocation ($2));
7172 opt_query_continuation
7174 | INTO identifier_inside_body
7176 // query continuation block is not linked with query block but with block
7177 // before. This means each query can use same range variable names for
7178 // different identifiers.
7180 current_block.SetEndLocation (GetLocation ($1));
7181 current_block = current_block.Parent;
7183 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7185 if (linq_clause_blocks == null)
7186 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7188 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7192 var current_block = linq_clause_blocks.Pop ();
7193 var lt = (LocatedToken) $2;
7194 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7195 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7196 next = (Linq.AQueryClause)$4
7202 // Support for using the compiler as an interactive parser
7204 // The INTERACTIVE_PARSER token is first sent to parse our
7205 // productions; If the result is a Statement, the parsing
7206 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7207 // to setup the blocks in advance.
7209 // This setup is here so that in the future we can add
7210 // support for other constructs (type parsing, namespaces, etc)
7211 // that do not require a block to be setup in advance
7215 : EVAL_STATEMENT_PARSER EOF
7216 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7217 | EVAL_STATEMENT_PARSER
7219 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7221 // (ref object retval)
7222 Parameter [] mpar = new Parameter [1];
7223 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7225 ParametersCompiled pars = new ParametersCompiled (mpar);
7226 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7227 if (settings.Unsafe)
7228 mods |= Modifiers.UNSAFE;
7230 current_local_parameters = pars;
7231 var method = new InteractiveMethod (
7233 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7237 current_type.AddMember (method);
7238 oob_stack.Push (method);
7240 interactive_async = false;
7242 ++lexer.parsing_block;
7243 start_block (lexer.Location);
7245 interactive_statement_list opt_COMPLETE_COMPLETION
7247 --lexer.parsing_block;
7248 var method = (InteractiveMethod) oob_stack.Pop ();
7249 method.Block = (ToplevelBlock) end_block(lexer.Location);
7251 if (interactive_async == true) {
7252 method.ChangeToAsync ();
7255 InteractiveResult = (Class) pop_current_class ();
7256 current_local_parameters = null;
7258 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7261 interactive_compilation_unit
7262 : opt_extern_alias_directives opt_using_directives
7263 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7266 opt_COMPLETE_COMPLETION
7268 | COMPLETE_COMPLETION
7271 close_brace_or_complete_completion
7273 | COMPLETE_COMPLETION
7277 // XML documentation code references micro parser
7279 documentation_parsing
7282 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7287 : doc_type_declaration_name opt_doc_method_sig
7289 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7291 | builtin_types opt_doc_method_sig
7293 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7294 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7297 | VOID opt_doc_method_sig
7299 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7300 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7303 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7305 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7306 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7307 var lt = (LocatedToken) $3;
7308 $$ = new MemberName (lt.Value);
7310 | doc_type_declaration_name DOT THIS
7312 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7314 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7316 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7318 opt_doc_parameters CLOSE_BRACKET
7320 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7321 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7323 | EXPLICIT OPERATOR type opt_doc_method_sig
7325 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7326 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7327 module.DocumentationBuilder.ParsedParameters = p;
7328 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7331 | IMPLICIT OPERATOR type opt_doc_method_sig
7333 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7334 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7335 module.DocumentationBuilder.ParsedParameters = p;
7336 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7339 | OPERATOR overloadable_operator opt_doc_method_sig
7341 var p = (List<DocumentationParameter>)$3;
7342 module.DocumentationBuilder.ParsedParameters = p;
7343 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7348 doc_type_declaration_name
7349 : type_declaration_name
7350 | doc_type_declaration_name DOT type_declaration_name
7352 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7360 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7362 opt_doc_parameters CLOSE_PARENS
7371 $$ = new List<DocumentationParameter> (0);
7379 var parameters = new List<DocumentationParameter> ();
7380 parameters.Add ((DocumentationParameter) $1);
7383 | doc_parameters COMMA doc_parameter
7385 var parameters = $1 as List<DocumentationParameter>;
7386 parameters.Add ((DocumentationParameter) $3);
7392 : opt_parameter_modifier parameter_type
7395 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7397 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7404 // A class used to hold info about an operator declarator
7406 class OperatorDeclaration {
7407 public readonly Operator.OpType optype;
7408 public readonly FullNamedExpression ret_type;
7409 public readonly Location location;
7411 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7414 this.ret_type = ret_type;
7415 this.location = location;
7419 void Error_ExpectingTypeName (Expression expr)
7421 if (expr is Invocation){
7422 report.Error (1002, expr.Location, "Expecting `;'");
7424 expr.Error_InvalidExpressionStatement (report);
7428 void Error_ParameterModifierNotValid (string modifier, Location loc)
7430 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7434 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7436 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7437 Parameter.GetModifierSignature (mod));
7440 void Error_TypeExpected (Location loc)
7442 report.Error (1031, loc, "Type expected");
7445 void Error_UnsafeCodeNotAllowed (Location loc)
7447 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7450 void Warning_EmptyStatement (Location loc)
7452 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7455 void Error_NamedArgumentExpected (NamedArgument a)
7457 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7460 void Error_MissingInitializer (Location loc)
7462 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7465 object Error_AwaitAsIdentifier (object token)
7468 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7469 return new LocatedToken ("await", GetLocation (token));
7475 void push_current_container (TypeDefinition tc, object partial_token)
7477 if (module.Evaluator != null){
7478 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7482 undo.AddTypeContainer (current_container, tc);
7485 if (partial_token != null)
7486 current_container.AddPartial (tc);
7488 current_container.AddTypeContainer (tc);
7490 ++lexer.parsing_declaration;
7491 current_container = tc;
7495 TypeContainer pop_current_class ()
7497 var retval = current_container;
7499 current_container = current_container.Parent;
7500 current_type = current_type.Parent as TypeDefinition;
7505 [System.Diagnostics.Conditional ("FULL_AST")]
7506 void StoreModifierLocation (object token, Location loc)
7511 if (mod_locations == null)
7512 mod_locations = new List<Tuple<Modifiers, Location>> ();
7514 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7517 [System.Diagnostics.Conditional ("FULL_AST")]
7518 void PushLocation (Location loc)
7520 if (location_stack == null)
7521 location_stack = new Stack<Location> ();
7523 location_stack.Push (loc);
7526 Location PopLocation ()
7528 if (location_stack == null)
7529 return Location.Null;
7531 return location_stack.Pop ();
7534 string CheckAttributeTarget (int token, string a, Location l)
7537 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7541 if (!Tokenizer.IsValidIdentifier (a)) {
7542 Error_SyntaxError (token);
7544 report.Warning (658, 1, l,
7545 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7548 return string.Empty;
7551 static bool IsUnaryOperator (Operator.OpType op)
7555 case Operator.OpType.LogicalNot:
7556 case Operator.OpType.OnesComplement:
7557 case Operator.OpType.Increment:
7558 case Operator.OpType.Decrement:
7559 case Operator.OpType.True:
7560 case Operator.OpType.False:
7561 case Operator.OpType.UnaryPlus:
7562 case Operator.OpType.UnaryNegation:
7568 void syntax_error (Location l, string msg)
7570 report.Error (1003, l, "Syntax error, " + msg);
7575 public Tokenizer Lexer {
7581 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7582 : this (reader, file, file.Compiler.Report, session)
7586 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7589 current_container = current_namespace = file;
7591 this.module = file.Module;
7592 this.compiler = file.Compiler;
7593 this.settings = compiler.Settings;
7594 this.report = report;
7596 lang_version = settings.Version;
7597 yacc_verbose_flag = settings.VerboseParserFlag;
7598 doc_support = settings.DocumentationFile != null;
7599 lexer = new Tokenizer (reader, file, session, report);
7600 oob_stack = new Stack<object> ();
7601 lbag = session.LocationsBag;
7602 use_global_stacks = session.UseJayGlobalArrays;
7603 parameters_bucket = session.ParametersStack;
7606 public void parse ()
7608 eof_token = Token.EOF;
7611 if (yacc_verbose_flag > 1)
7612 yyparse (lexer, new yydebug.yyDebugSimple ());
7616 Tokenizer tokenizer = lexer as Tokenizer;
7617 tokenizer.cleanup ();
7618 } catch (Exception e){
7619 if (e is yyParser.yyUnexpectedEof) {
7620 Error_SyntaxError (yyToken);
7621 UnexpectedEOF = true;
7625 if (e is yyParser.yyException) {
7626 if (report.Errors == 0)
7627 report.Error (-25, lexer.Location, "Parsing error");
7629 // Used by compiler-tester to test internal errors
7630 if (yacc_verbose_flag > 0 || e is FatalException)
7633 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7638 void CheckToken (int error, int yyToken, string msg, Location loc)
7640 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7641 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7643 report.Error (error, loc, msg);
7646 string ConsumeStoredComment ()
7648 string s = tmpComment;
7650 Lexer.doc_state = XmlCommentState.Allowed;
7654 void FeatureIsNotAvailable (Location loc, string feature)
7656 report.FeatureIsNotAvailable (compiler, loc, feature);
7659 Location GetLocation (object obj)
7661 var lt = obj as LocatedToken;
7665 var mn = obj as MemberName;
7669 var expr = obj as Expression;
7671 return expr.Location;
7673 return lexer.Location;
7676 void start_block (Location loc)
7678 if (current_block == null) {
7679 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7680 parsing_anonymous_method = false;
7681 } else if (parsing_anonymous_method) {
7682 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7683 parsing_anonymous_method = false;
7685 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7690 end_block (Location loc)
7692 Block retval = current_block.Explicit;
7693 retval.SetEndLocation (loc);
7694 current_block = retval.Parent;
7698 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7700 oob_stack.Push (current_anonymous_method);
7701 oob_stack.Push (current_local_parameters);
7702 oob_stack.Push (current_variable);
7703 oob_stack.Push (async_block);
7705 current_local_parameters = parameters;
7707 if (lang_version <= LanguageVersion.ISO_2)
7708 FeatureIsNotAvailable (loc, "lambda expressions");
7710 current_anonymous_method = new LambdaExpression (loc);
7712 if (lang_version == LanguageVersion.ISO_1)
7713 FeatureIsNotAvailable (loc, "anonymous methods");
7715 current_anonymous_method = new AnonymousMethodExpression (loc);
7718 async_block = isAsync;
7719 // Force the next block to be created as a ToplevelBlock
7720 parsing_anonymous_method = true;
7724 * Completes the anonymous method processing, if lambda_expr is null, this
7725 * means that we have a Statement instead of an Expression embedded
7727 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7729 AnonymousMethodExpression retval;
7732 anon_block.IsAsync = true;
7734 current_anonymous_method.Block = anon_block;
7735 retval = current_anonymous_method;
7737 async_block = (bool) oob_stack.Pop ();
7738 current_variable = (BlockVariable) oob_stack.Pop ();
7739 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7740 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7745 void Error_SyntaxError (int token)
7747 Error_SyntaxError (0, token);
7750 void Error_SyntaxError (int error_code, int token)
7752 Error_SyntaxError (error_code, token, "Unexpected symbol");
7755 void Error_SyntaxError (int error_code, int token, string msg)
7757 Lexer.CompleteOnEOF = false;
7759 // An error message has been reported by tokenizer
7760 if (token == Token.ERROR)
7763 // Avoid duplicit error message after unterminated string literals
7764 if (token == Token.LITERAL && lexer.Location.Column == 0)
7767 string symbol = GetSymbolName (token);
7768 string expecting = GetExpecting ();
7769 var loc = lexer.Location - symbol.Length;
7771 if (error_code == 0) {
7772 if (expecting == "`identifier'") {
7773 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7774 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7779 expecting = "identifier";
7780 } else if (expecting == "`)'") {
7787 if (string.IsNullOrEmpty (expecting))
7788 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7790 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7793 string GetExpecting ()
7795 int [] tokens = yyExpectingTokens (yyExpectingState);
7796 var names = new List<string> (tokens.Length);
7797 bool has_type = false;
7798 bool has_identifier = false;
7799 for (int i = 0; i < tokens.Length; i++){
7800 int token = tokens [i];
7801 has_identifier |= token == Token.IDENTIFIER;
7803 string name = GetTokenName (token);
7804 if (name == "<internal>")
7807 has_type |= name == "type";
7808 if (names.Contains (name))
7815 // Too many tokens to enumerate
7817 if (names.Count > 8)
7820 if (has_type && has_identifier)
7821 names.Remove ("identifier");
7823 if (names.Count == 1)
7824 return "`" + GetTokenName (tokens [0]) + "'";
7826 StringBuilder sb = new StringBuilder ();
7828 int count = names.Count;
7829 for (int i = 0; i < count; i++){
7830 bool last = i + 1 == count;
7834 sb.Append (names [i]);
7835 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7837 return sb.ToString ();
7841 string GetSymbolName (int token)
7845 return ((Constant)lexer.Value).GetValue ().ToString ();
7846 case Token.IDENTIFIER:
7847 return ((LocatedToken)lexer.Value).Value;
7889 case Token.BITWISE_AND:
7891 case Token.BITWISE_OR:
7905 case Token.OP_SHIFT_LEFT:
7907 case Token.OP_SHIFT_RIGHT:
7927 case Token.OP_COALESCING:
7929 case Token.OP_MULT_ASSIGN:
7931 case Token.OP_DIV_ASSIGN:
7933 case Token.OP_MOD_ASSIGN:
7935 case Token.OP_ADD_ASSIGN:
7937 case Token.OP_SUB_ASSIGN:
7939 case Token.OP_SHIFT_LEFT_ASSIGN:
7941 case Token.OP_SHIFT_RIGHT_ASSIGN:
7943 case Token.OP_AND_ASSIGN:
7945 case Token.OP_XOR_ASSIGN:
7947 case Token.OP_OR_ASSIGN:
7951 return GetTokenName (token);
7954 static string GetTokenName (int token)
7957 case Token.ABSTRACT:
7979 case Token.CONTINUE:
7983 case Token.DELEGATE:
7993 case Token.EXPLICIT:
7996 case Token.EXTERN_ALIAS:
8012 case Token.IMPLICIT:
8016 case Token.INTERFACE:
8018 case Token.INTERNAL:
8024 case Token.NAMESPACE:
8030 case Token.OPERATOR:
8034 case Token.OVERRIDE:
8040 case Token.PROTECTED:
8044 case Token.READONLY:
8056 case Token.STACKALLOC:
8057 return "stackalloc";
8074 case Token.UNCHECKED:
8082 case Token.VOLATILE:
8090 case Token.REFVALUE:
8091 return "__refvalue";
8101 case Token.FROM_FIRST:
8119 case Token.ASCENDING:
8121 case Token.DESCENDING:
8122 return "descending";
8129 case Token.OPEN_BRACE:
8131 case Token.CLOSE_BRACE:
8133 case Token.OPEN_BRACKET:
8134 case Token.OPEN_BRACKET_EXPR:
8136 case Token.CLOSE_BRACKET:
8138 case Token.OPEN_PARENS_CAST:
8139 case Token.OPEN_PARENS_LAMBDA:
8140 case Token.OPEN_PARENS:
8142 case Token.CLOSE_PARENS:
8148 case Token.DEFAULT_COLON:
8152 case Token.SEMICOLON:
8158 case Token.INTERPOLATED_STRING_END:
8160 case Token.INTERPOLATED_STRING:
8169 case Token.BITWISE_AND:
8170 case Token.BITWISE_OR:
8177 case Token.OP_SHIFT_LEFT:
8178 case Token.OP_SHIFT_RIGHT:
8186 case Token.OP_COALESCING:
8187 case Token.OP_MULT_ASSIGN:
8188 case Token.OP_DIV_ASSIGN:
8189 case Token.OP_MOD_ASSIGN:
8190 case Token.OP_ADD_ASSIGN:
8191 case Token.OP_SUB_ASSIGN:
8192 case Token.OP_SHIFT_LEFT_ASSIGN:
8193 case Token.OP_SHIFT_RIGHT_ASSIGN:
8194 case Token.OP_AND_ASSIGN:
8195 case Token.OP_XOR_ASSIGN:
8196 case Token.OP_OR_ASSIGN:
8197 case Token.INTERR_OPERATOR:
8198 return "<operator>";
8220 case Token.OP_GENERICS_LT:
8221 case Token.GENERIC_DIMENSION:
8223 case Token.OP_GENERICS_GT:
8226 case Token.INTERR_NULLABLE:
8228 case Token.DOUBLE_COLON:
8232 case Token.IDENTIFIER:
8234 return "identifier";
8237 return "end-of-file";
8239 // All of these are internal.
8242 case Token.FIRST_KEYWORD:
8243 case Token.EVAL_COMPILATION_UNIT_PARSER:
8244 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8245 case Token.EVAL_STATEMENT_PARSER:
8246 case Token.LAST_KEYWORD:
8247 case Token.GENERATE_COMPLETION:
8248 case Token.COMPLETE_COMPLETION:
8249 return "<internal>";
8251 // A bit more robust.
8253 return yyNames [token];