3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue,
39 PrimaryConstructor = Ref | Out | Params | DefaultValue
42 static readonly object ModifierNone = 0;
44 NamespaceContainer current_namespace;
45 TypeContainer current_container;
46 TypeDefinition current_type;
47 PropertyBase current_property;
48 EventProperty current_event;
49 EventField current_event_field;
50 FieldBase current_field;
53 /// Current block is used to add statements as we find
58 BlockVariable current_variable;
60 Delegate current_delegate;
62 AnonymousMethodExpression current_anonymous_method;
65 /// This is used by the unary_expression code to resolve
66 /// a name against a parameter.
69 // FIXME: This is very ugly and it's very hard to reset it correctly
70 // on all places, especially when some parameters are autogenerated.
71 ParametersCompiled current_local_parameters;
73 bool parsing_anonymous_method;
78 /// An out-of-band stack.
80 Stack<object> oob_stack;
83 /// Controls the verbosity of the errors produced by the parser
85 int yacc_verbose_flag;
88 /// Used by the interactive shell, flags whether EOF was reached
89 /// and an error was produced
91 public bool UnexpectedEOF;
96 readonly CompilationSourceFile file;
99 /// Temporary Xml documentation cache.
100 /// For enum types, we need one more temporary store.
103 string enumTypeComment;
105 /// Current attribute target
106 string current_attr_target;
108 ParameterModifierType valid_param_mod;
110 bool default_parameter_used;
112 /// When using the interactive parser, this holds the
113 /// resulting expression
114 public Class InteractiveResult;
117 // Keeps track of global data changes to undo on parser error
121 bool? interactive_async;
123 Stack<Linq.QueryBlock> linq_clause_blocks;
125 ModuleContainer module;
127 readonly CompilerContext compiler;
128 readonly LanguageVersion lang_version;
129 readonly bool doc_support;
130 readonly CompilerSettings settings;
131 readonly Report report;
134 // Instead of allocating carrier array everytime we
135 // share the bucket for very common constructs which can never
138 List<Parameter> parameters_bucket;
141 // Full AST support members
144 List<Tuple<Modifiers, Location>> mod_locations;
145 Stack<Location> location_stack;
149 %token NONE /* This token is never returned by our lexer */
150 %token ERROR // This is used not by the parser, but by the tokenizer.
154 *These are the C# keywords
253 %token INTERR_NULLABLE
260 %token INTERR_OPERATOR
262 %token INTERPOLATED_STRING
263 %token INTERPOLATED_STRING_END
266 /* C# keywords which are not really keywords */
272 /* C# single character operators/punctuation. */
300 /* C# multi-character operators. */
305 %token OP_SHIFT_RIGHT
312 %token OP_MULT_ASSIGN
317 %token OP_SHIFT_LEFT_ASSIGN
318 %token OP_SHIFT_RIGHT_ASSIGN
325 /* Generics <,> tokens */
326 %token OP_GENERICS_LT
327 %token OP_GENERICS_LT_DECL
328 %token OP_GENERICS_GT
333 %token OPEN_PARENS_LAMBDA
334 %token OPEN_PARENS_CAST
335 %token GENERIC_DIMENSION
337 %token OPEN_BRACKET_EXPR
339 // Make the parser go into eval mode parsing (statements and compilation units).
340 %token EVAL_STATEMENT_PARSER
341 %token EVAL_COMPILATION_UNIT_PARSER
342 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
347 // This token is generated to trigger the completion engine at this point
349 %token GENERATE_COMPLETION
352 // This token is return repeatedly after the first GENERATE_COMPLETION
353 // token is produced and before the final EOF
355 %token COMPLETE_COMPLETION
357 /* Add precedence rules to solve dangling else s/r conflict */
361 /* Define the operator tokens and their precedences */
369 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
371 %left STAR DIV PERCENT
372 %right BANG CARRET UMINUS
373 %nonassoc OP_INC OP_DEC
375 %left OPEN_BRACKET OPEN_BRACE
378 %start compilation_unit
382 : outer_declaration opt_EOF
384 Lexer.check_incorrect_doc_comment ();
386 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
387 | documentation_parsing
391 : opt_extern_alias_directives opt_using_directives
392 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
395 Attributes attrs = (Attributes) $4;
396 report.Error (1730, attrs.Attrs [0].Location,
397 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
399 current_namespace.UnattachedAttributes = attrs;
402 | opt_extern_alias_directives opt_using_directives attribute_sections
404 Attributes attrs = (Attributes) $3;
406 foreach (var a in attrs.Attrs) {
407 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
410 if (a.ExplicitTarget == null)
411 report.Error (-1671, a.Location, "Global attributes must have attribute target specified");
415 module.AddAttributes ((Attributes) $3, current_namespace);
419 if (yyToken == Token.EXTERN_ALIAS)
420 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
422 Error_SyntaxError (yyToken);
431 extern_alias_directives
432 : extern_alias_directive
433 | extern_alias_directives extern_alias_directive
436 extern_alias_directive
437 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
439 var lt = (LocatedToken) $2;
442 syntax_error (lt.Location, "`alias' expected");
444 if (lang_version == LanguageVersion.ISO_1)
445 FeatureIsNotAvailable (lt.Location, "external alias");
447 lt = (LocatedToken) $3;
448 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
449 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
452 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
453 current_namespace.AddUsing (na);
455 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
460 Error_SyntaxError (yyToken);
466 | using_directives using_directive
473 Lexer.doc_state = XmlCommentState.Allowed;
478 : USING opt_static namespace_or_type_expr SEMICOLON
482 if (lang_version <= LanguageVersion.V_5)
483 FeatureIsNotAvailable (GetLocation ($2), "using static");
485 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
486 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
488 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
489 lbag.AddLocation (uc, GetLocation ($4));
492 current_namespace.AddUsing (uc);
494 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
496 var lt = (LocatedToken) $3;
497 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
498 report.Warning (440, 2, lt.Location,
499 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
503 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
506 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
507 current_namespace.AddUsing (un);
509 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
513 Error_SyntaxError (yyToken);
524 // Strictly speaking, namespaces don't have attributes but
525 // we parse global attributes along with namespace declarations and then
528 namespace_declaration
529 : opt_attributes NAMESPACE namespace_name
531 Attributes attrs = (Attributes) $1;
532 var name = (MemberName) $3;
534 bool valid_global_attrs = true;
535 if ((current_namespace.DeclarationFound || current_namespace != file)) {
536 valid_global_attrs = false;
538 foreach (var a in attrs.Attrs) {
539 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
542 valid_global_attrs = false;
547 if (!valid_global_attrs)
548 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
551 module.AddAttributes (attrs, current_namespace);
553 var ns = new NamespaceContainer (name, current_namespace);
554 current_namespace.AddTypeContainer (ns);
555 current_container = current_namespace = ns;
560 Lexer.doc_state = XmlCommentState.Allowed;
562 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
565 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
567 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
569 current_container = current_namespace = current_namespace.Parent;
571 | opt_attributes NAMESPACE namespace_name
573 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
575 var name = (MemberName) $3;
576 var ns = new NamespaceContainer (name, current_namespace);
577 lbag.AddLocation (ns, GetLocation ($2));
578 current_namespace.AddTypeContainer (ns);
587 Error_SyntaxError (yyToken);
595 var lt = (LocatedToken) $1;
596 $$ = new MemberName (lt.Value, lt.Location);
598 | namespace_name DOT IDENTIFIER
600 var lt = (LocatedToken) $3;
601 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
602 lbag.AddLocation ($$, GetLocation ($2));
606 Error_SyntaxError (yyToken);
607 $$ = new MemberName ("<invalid>", lexer.Location);
626 opt_extern_alias_directives
628 | extern_alias_directives
631 opt_namespace_or_type_declarations
633 | namespace_or_type_declarations
636 namespace_or_type_declarations
637 : namespace_or_type_declaration
638 | namespace_or_type_declarations namespace_or_type_declaration
641 namespace_or_type_declaration
645 TypeContainer ds = (TypeContainer)$1;
647 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
648 report.Error (1527, ds.Location,
649 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
652 // Here is a trick, for explicit attributes we don't know where they belong to until
653 // we parse succeeding declaration hence we parse them as normal and re-attach them
654 // when we know whether they are global (assembly:, module:) or local (type:).
655 if (ds.OptAttributes != null) {
656 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
659 current_namespace.DeclarationFound = true;
661 | namespace_declaration
663 current_namespace.DeclarationFound = true;
665 | attribute_sections CLOSE_BRACE {
666 current_namespace.UnattachedAttributes = (Attributes) $1;
667 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
675 | interface_declaration
677 | delegate_declaration
679 // Enable this when we have handled all errors, because this acts as a generic fallback
682 // Console.WriteLine ("Token=" + yyToken);
683 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
699 var sect = (List<Attribute>) $1;
700 $$ = new Attributes (sect);
702 | attribute_sections attribute_section
704 Attributes attrs = $1 as Attributes;
705 var sect = (List<Attribute>) $2;
707 attrs = new Attributes (sect);
708 else if (sect != null)
709 attrs.AddAttributes (sect);
717 PushLocation (GetLocation ($1));
718 lexer.parsing_attribute_section = true;
720 attribute_section_cont
722 lexer.parsing_attribute_section = false;
727 attribute_section_cont
728 : attribute_target COLON
730 current_attr_target = (string) $1;
731 if (current_attr_target == "assembly" || current_attr_target == "module") {
732 Lexer.check_incorrect_doc_comment ();
735 attribute_list opt_comma CLOSE_BRACKET
737 // when attribute target is invalid
738 if (current_attr_target == string.Empty)
739 $$ = new List<Attribute> (0);
743 lbag.InsertLocation ($$, 0, PopLocation ());
745 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
747 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
750 current_attr_target = null;
751 lexer.parsing_attribute_section = false;
753 | attribute_list opt_comma CLOSE_BRACKET
757 lbag.InsertLocation ($$, 0, PopLocation ());
759 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
761 lbag.AddLocation ($$, GetLocation($3));
766 Error_SyntaxError (yyToken);
768 var lt = (LocatedToken) $1;
769 var tne = new SimpleName (lt.Value, null, lt.Location);
771 $$ = new List<Attribute> () {
772 new Attribute (null, tne, null, GetLocation ($1), false)
777 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
778 Error_SyntaxError (yyToken);
787 var lt = (LocatedToken) $1;
788 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
790 | EVENT { $$ = "event"; }
791 | RETURN { $$ = "return"; }
797 $$ = new List<Attribute> (4) { (Attribute) $1 };
799 | attribute_list COMMA attribute
801 var attrs = (List<Attribute>) $1;
803 attrs.Add ((Attribute) $3);
804 lbag.AppendTo (attrs, GetLocation ($2));
814 ++lexer.parsing_block;
816 opt_attribute_arguments
818 --lexer.parsing_block;
820 var tne = (ATypeNameExpression) $1;
821 if (tne.HasTypeArguments) {
822 report.Error (404, tne.Location, "Attributes cannot be generic");
825 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
830 : namespace_or_type_expr
833 opt_attribute_arguments
834 : /* empty */ { $$ = null; }
835 | OPEN_PARENS attribute_arguments CLOSE_PARENS
843 : /* empty */ { $$ = null; }
844 | positional_or_named_argument
846 Arguments a = new Arguments (4);
847 a.Add ((Argument) $1);
848 $$ = new Arguments [] { a, null };
850 | named_attribute_argument
852 Arguments a = new Arguments (4);
853 a.Add ((Argument) $1);
854 $$ = new Arguments [] { null, a };
856 | attribute_arguments COMMA positional_or_named_argument
858 Arguments[] o = (Arguments[]) $1;
860 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
861 o [0] = new Arguments (4);
864 Arguments args = ((Arguments) o [0]);
865 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
866 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
868 args.Add ((Argument) $3);
870 | attribute_arguments COMMA named_attribute_argument
872 Arguments[] o = (Arguments[]) $1;
874 o [1] = new Arguments (4);
877 ((Arguments) o [1]).Add ((Argument) $3);
881 positional_or_named_argument
884 $$ = new Argument ((Expression) $1);
889 Error_SyntaxError (yyToken);
894 named_attribute_argument
897 ++lexer.parsing_block;
901 --lexer.parsing_block;
902 var lt = (LocatedToken) $1;
903 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
904 lbag.AddLocation ($$, GetLocation($2));
909 : identifier_inside_body COLON opt_named_modifier named_argument_expr
911 if (lang_version <= LanguageVersion.V_3)
912 FeatureIsNotAvailable (GetLocation ($1), "named argument");
914 // Avoid boxing in common case (no modifier)
915 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
917 var lt = (LocatedToken) $1;
918 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
919 lbag.AddLocation ($$, GetLocation($2));
924 : expression_or_error
925 // | declaration_expression
929 : /* empty */ { $$ = null; }
932 $$ = Argument.AType.Ref;
936 $$ = Argument.AType.Out;
940 opt_class_member_declarations
942 | class_member_declarations
945 class_member_declarations
946 : class_member_declaration
948 lexer.parsing_modifiers = true;
949 lexer.parsing_block = 0;
951 | class_member_declarations class_member_declaration
953 lexer.parsing_modifiers = true;
954 lexer.parsing_block = 0;
958 class_member_declaration
959 : constant_declaration
962 | property_declaration
964 | indexer_declaration
965 | operator_declaration
966 | constructor_declaration
967 | primary_constructor_body
968 | destructor_declaration
970 | attributes_without_members
974 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
975 GetSymbolName (yyToken));
977 lexer.parsing_generic_declaration = false;
981 primary_constructor_body
984 current_local_parameters = current_type.PrimaryConstructorParameters;
985 if (current_local_parameters == null) {
986 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
987 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
990 ++lexer.parsing_block;
991 start_block (GetLocation ($1));
993 opt_statement_list block_end
995 current_local_parameters = null;
996 var t = current_type as ClassOrStruct;
998 var b = (ToplevelBlock) $4;
999 if (t.PrimaryConstructorBlock != null) {
1000 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
1002 t.PrimaryConstructorBlock = b;
1015 type_declaration_name
1017 lexer.ConstraintsParsing = true;
1018 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1019 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1021 opt_primary_parameters
1023 opt_type_parameter_constraints_clauses
1025 valid_param_mod = 0;
1026 lexer.ConstraintsParsing = false;
1029 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
1032 current_container.SetConstraints ((List<Constraints>) $10);
1035 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1037 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1039 lexer.parsing_modifiers = true;
1044 Lexer.doc_state = XmlCommentState.Allowed;
1046 opt_class_member_declarations CLOSE_BRACE
1048 --lexer.parsing_declaration;
1050 Lexer.doc_state = XmlCommentState.Allowed;
1055 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1057 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1059 $$ = pop_current_class ();
1061 | opt_attributes opt_modifiers opt_partial STRUCT error
1063 Error_SyntaxError (yyToken);
1067 constant_declaration
1070 CONST type IDENTIFIER
1072 var lt = (LocatedToken) $5;
1073 var mod = (Modifiers) $2;
1074 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1075 current_type.AddMember (current_field);
1077 if ((mod & Modifiers.STATIC) != 0) {
1078 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1083 constant_initializer opt_constant_declarators SEMICOLON
1086 current_field.DocComment = Lexer.consume_doc_comment ();
1087 Lexer.doc_state = XmlCommentState.Allowed;
1090 current_field.Initializer = (ConstInitializer) $7;
1091 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1092 current_field = null;
1098 Error_SyntaxError (yyToken);
1100 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1104 opt_constant_declarators
1106 | constant_declarators
1109 constant_declarators
1110 : constant_declarator
1112 current_field.AddDeclarator ((FieldDeclarator) $1);
1114 | constant_declarators constant_declarator
1116 current_field.AddDeclarator ((FieldDeclarator) $2);
1121 : COMMA IDENTIFIER constant_initializer
1123 var lt = (LocatedToken) $2;
1124 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1125 lbag.AddLocation ($$, GetLocation ($1));
1129 constant_initializer
1132 ++lexer.parsing_block;
1134 constant_initializer_expr
1136 --lexer.parsing_block;
1137 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1141 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1146 constant_initializer_expr
1147 : constant_expression
1154 member_type IDENTIFIER
1156 lexer.parsing_generic_declaration = false;
1158 FullNamedExpression type = (FullNamedExpression) $3;
1159 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1160 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1162 var lt = (LocatedToken) $4;
1163 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1164 current_type.AddField (current_field);
1167 opt_field_initializer
1168 opt_field_declarators
1172 current_field.DocComment = Lexer.consume_doc_comment ();
1173 Lexer.doc_state = XmlCommentState.Allowed;
1176 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1178 current_field = null;
1182 FIXED simple_type IDENTIFIER
1184 if (lang_version < LanguageVersion.ISO_2)
1185 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1187 var lt = (LocatedToken) $5;
1188 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1189 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1191 current_type.AddField (current_field);
1193 fixed_field_size opt_fixed_field_declarators SEMICOLON
1196 current_field.DocComment = Lexer.consume_doc_comment ();
1197 Lexer.doc_state = XmlCommentState.Allowed;
1200 current_field.Initializer = (ConstInitializer) $7;
1201 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1203 current_field = null;
1207 FIXED simple_type error
1210 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1214 opt_field_initializer
1218 ++lexer.parsing_block;
1219 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1220 start_block (GetLocation ($1));
1222 variable_initializer
1224 --lexer.parsing_block;
1225 current_field.Initializer = (Expression) $3;
1226 lbag.AppendToMember (current_field, GetLocation ($1));
1227 end_block (lexer.Location);
1228 current_local_parameters = null;
1232 opt_field_declarators
1240 current_field.AddDeclarator ((FieldDeclarator) $1);
1242 | field_declarators field_declarator
1244 current_field.AddDeclarator ((FieldDeclarator) $2);
1251 var lt = (LocatedToken) $2;
1252 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1253 lbag.AddLocation ($$, GetLocation ($1));
1255 | COMMA IDENTIFIER ASSIGN
1257 ++lexer.parsing_block;
1259 variable_initializer
1261 --lexer.parsing_block;
1262 var lt = (LocatedToken) $2;
1263 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1264 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1268 opt_fixed_field_declarators
1270 | fixed_field_declarators
1273 fixed_field_declarators
1274 : fixed_field_declarator
1276 current_field.AddDeclarator ((FieldDeclarator) $1);
1278 | fixed_field_declarators fixed_field_declarator
1280 current_field.AddDeclarator ((FieldDeclarator) $2);
1284 fixed_field_declarator
1285 : COMMA IDENTIFIER fixed_field_size
1287 var lt = (LocatedToken) $2;
1288 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1289 lbag.AddLocation ($$, GetLocation ($1));
1296 ++lexer.parsing_block;
1298 expression CLOSE_BRACKET
1300 --lexer.parsing_block;
1301 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1302 lbag.AddLocation ($$, GetLocation ($4));
1304 | OPEN_BRACKET error
1306 report.Error (443, lexer.Location, "Value or constant expected");
1311 variable_initializer
1316 // It has to be here for the parent to safely restore artificial block
1317 Error_SyntaxError (yyToken);
1326 Lexer.doc_state = XmlCommentState.NotAllowed;
1328 // Was added earlier in the case of body being eof for full ast
1330 method_body_expression_block
1332 Method method = (Method) $1;
1333 method.Block = (ToplevelBlock) $3;
1334 async_block = false;
1336 if (method.Block == null) {
1337 method.ParameterInfo.CheckParameters (method);
1339 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1340 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1341 method.GetSignatureForError ());
1344 if (current_container.Kind == MemberKind.Interface) {
1345 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1346 method.GetSignatureForError ());
1350 current_local_parameters = null;
1353 Lexer.doc_state = XmlCommentState.Allowed;
1361 method_declaration_name OPEN_PARENS
1363 valid_param_mod = ParameterModifierType.All;
1365 opt_formal_parameter_list CLOSE_PARENS
1367 valid_param_mod = 0;
1368 MemberName name = (MemberName) $4;
1369 current_local_parameters = (ParametersCompiled) $7;
1371 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1372 name, current_local_parameters, (Attributes) $1);
1374 current_type.AddMember (method);
1376 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1379 method.DocComment = Lexer.consume_doc_comment ();
1381 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1385 lexer.ConstraintsParsing = true;
1387 opt_type_parameter_constraints_clauses
1389 lexer.ConstraintsParsing = false;
1392 var method = (Method) $9;
1393 method.SetConstraints ((List<Constraints>) $10);
1403 lexer.parsing_generic_declaration = true;
1405 method_declaration_name
1408 lexer.parsing_generic_declaration = false;
1409 valid_param_mod = ParameterModifierType.All;
1411 opt_formal_parameter_list CLOSE_PARENS
1413 lexer.ConstraintsParsing = true;
1415 opt_type_parameter_constraints_clauses
1417 lexer.ConstraintsParsing = false;
1418 valid_param_mod = 0;
1420 MemberName name = (MemberName) $6;
1421 current_local_parameters = (ParametersCompiled) $9;
1423 var modifiers = (Modifiers) $2;
1424 modifiers |= Modifiers.PARTIAL;
1426 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1427 modifiers, name, current_local_parameters, (Attributes) $1);
1429 current_type.AddMember (method);
1431 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1434 method.SetConstraints ((List<Constraints>) $12);
1437 method.DocComment = Lexer.consume_doc_comment ();
1439 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1440 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1446 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1448 MemberName name = (MemberName) $5;
1449 report.Error (1585, name.Location,
1450 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1452 var method = Method.Create (current_type, (FullNamedExpression) $3,
1453 0, name, (ParametersCompiled) $7, (Attributes) $1);
1455 current_type.AddMember (method);
1457 current_local_parameters = (ParametersCompiled) $7;
1460 method.DocComment = Lexer.consume_doc_comment ();
1467 method_declaration_name error
1469 Error_SyntaxError (yyToken);
1470 current_local_parameters = ParametersCompiled.Undefined;
1472 MemberName name = (MemberName) $4;
1473 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1474 name, current_local_parameters, (Attributes) $1);
1476 current_type.AddMember (method);
1479 method.DocComment = Lexer.consume_doc_comment ();
1485 method_body_expression_block
1492 | SEMICOLON { $$ = null; }
1498 if (lang_version < LanguageVersion.V_6) {
1499 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1502 ++lexer.parsing_block;
1503 start_block (GetLocation ($1));
1505 expression SEMICOLON
1507 lexer.parsing_block = 0;
1508 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1509 var b = end_block (GetLocation ($4));
1510 b.IsCompilerGenerated = true;
1515 opt_formal_parameter_list
1516 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1517 | formal_parameter_list
1520 formal_parameter_list
1523 var pars_list = (List<Parameter>) $1;
1524 $$ = new ParametersCompiled (pars_list.ToArray ());
1526 | fixed_parameters COMMA parameter_array
1528 var pars_list = (List<Parameter>) $1;
1529 pars_list.Add ((Parameter) $3);
1531 $$ = new ParametersCompiled (pars_list.ToArray ());
1533 | fixed_parameters COMMA arglist_modifier
1535 var pars_list = (List<Parameter>) $1;
1536 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1537 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1539 | parameter_array COMMA error
1542 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1544 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1546 | fixed_parameters COMMA parameter_array COMMA error
1549 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1551 var pars_list = (List<Parameter>) $1;
1552 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1554 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1556 | arglist_modifier COMMA error
1558 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1560 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1562 | fixed_parameters COMMA ARGLIST COMMA error
1564 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1566 var pars_list = (List<Parameter>) $1;
1567 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1569 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1573 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1577 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1581 Error_SyntaxError (yyToken);
1582 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1589 parameters_bucket.Clear ();
1590 Parameter p = (Parameter) $1;
1591 parameters_bucket.Add (p);
1593 default_parameter_used = p.HasDefaultValue;
1594 $$ = parameters_bucket;
1596 | fixed_parameters COMMA fixed_parameter
1598 var pars = (List<Parameter>) $1;
1599 Parameter p = (Parameter) $3;
1601 if (p.HasExtensionMethodModifier)
1602 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1603 else if (!p.HasDefaultValue && default_parameter_used)
1604 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1606 default_parameter_used |= p.HasDefaultValue;
1609 lbag.AddLocation (p, GetLocation ($2));
1618 opt_parameter_modifier
1620 identifier_inside_body
1622 var lt = (LocatedToken) $4;
1623 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1626 opt_parameter_modifier
1628 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1630 var lt = (LocatedToken) $4;
1631 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1632 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1634 | attribute_sections error
1636 Error_SyntaxError (yyToken);
1637 Location l = GetLocation ($2);
1638 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1641 opt_parameter_modifier
1645 Error_SyntaxError (yyToken);
1646 Location l = GetLocation ($4);
1647 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1650 opt_parameter_modifier
1652 identifier_inside_body
1655 ++lexer.parsing_block;
1659 --lexer.parsing_block;
1660 if (lang_version <= LanguageVersion.V_3) {
1661 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1664 Parameter.Modifier mod = (Parameter.Modifier) $2;
1665 if (mod != Parameter.Modifier.NONE) {
1667 case Parameter.Modifier.REF:
1668 case Parameter.Modifier.OUT:
1669 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1670 Parameter.GetModifierSignature (mod));
1673 case Parameter.Modifier.This:
1674 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1675 Parameter.GetModifierSignature (mod));
1678 throw new NotImplementedException (mod.ToString ());
1681 mod = Parameter.Modifier.NONE;
1684 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1685 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1687 var lt = (LocatedToken) $4;
1688 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1689 lbag.AddLocation ($$, GetLocation ($5));
1692 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1696 opt_parameter_modifier
1697 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1698 | parameter_modifiers
1702 : parameter_modifier
1706 | parameter_modifiers parameter_modifier
1708 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1709 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1710 if (((Parameter.Modifier)$1 & p2) == p2) {
1711 Error_DuplicateParameterModifier (lexer.Location, p2);
1713 switch (mod & ~Parameter.Modifier.This) {
1714 case Parameter.Modifier.REF:
1715 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1717 case Parameter.Modifier.OUT:
1718 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1721 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1732 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1733 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1735 $$ = Parameter.Modifier.REF;
1739 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1740 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1742 $$ = Parameter.Modifier.OUT;
1746 if ((valid_param_mod & ParameterModifierType.This) == 0)
1747 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1749 if (lang_version <= LanguageVersion.ISO_2)
1750 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1752 $$ = Parameter.Modifier.This;
1757 : opt_attributes params_modifier type IDENTIFIER
1759 var lt = (LocatedToken) $4;
1760 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1762 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1764 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1766 var lt = (LocatedToken) $4;
1767 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1769 | opt_attributes params_modifier type error
1771 Error_SyntaxError (yyToken);
1773 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1780 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1781 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1783 | PARAMS parameter_modifier
1785 Parameter.Modifier mod = (Parameter.Modifier)$2;
1786 if ((mod & Parameter.Modifier.This) != 0) {
1787 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1789 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1792 | PARAMS params_modifier
1794 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1801 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1802 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1806 property_declaration
1810 member_declaration_name
1812 lexer.parsing_generic_declaration = false;
1814 tmpComment = Lexer.consume_doc_comment ();
1818 var type = (FullNamedExpression) $3;
1819 current_property = new Property (current_type, type, (Modifiers) $2,
1820 (MemberName) $4, (Attributes) $1);
1822 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1823 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1825 current_type.AddMember (current_property);
1826 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1828 lexer.PropertyParsing = true;
1830 accessor_declarations
1832 lexer.PropertyParsing = false;
1835 current_property.DocComment = ConsumeStoredComment ();
1839 lbag.AppendToMember (current_property, GetLocation ($10));
1840 lexer.parsing_modifiers = true;
1842 opt_property_initializer
1844 current_property = null;
1849 member_declaration_name
1851 lexer.parsing_generic_declaration = false;
1853 tmpComment = Lexer.consume_doc_comment ();
1854 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1858 var type = (FullNamedExpression) $3;
1859 var property = new Property (current_type, type, (Modifiers) $2,
1860 (MemberName) $4, (Attributes) $1);
1862 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1863 property.Get.Block = (ToplevelBlock) $6;
1865 if (current_container.Kind == MemberKind.Interface) {
1866 report.Error (531, property.Get.Block.StartLocation,
1867 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1870 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1871 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1874 property.DocComment = ConsumeStoredComment ();
1876 current_type.AddMember (property);
1878 current_local_parameters = null;
1882 opt_property_initializer
1886 ++lexer.parsing_block;
1887 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1888 start_block (GetLocation ($1));
1890 property_initializer SEMICOLON
1892 --lexer.parsing_block;
1893 ((Property)current_property).Initializer = (Expression) $3;
1894 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1895 end_block (GetLocation ($4));
1896 current_local_parameters = null;
1899 Lexer.doc_state = XmlCommentState.Allowed;
1903 property_initializer
1909 : opt_attributes opt_modifiers
1910 member_type indexer_declaration_name OPEN_BRACKET
1912 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1914 opt_formal_parameter_list CLOSE_BRACKET
1916 valid_param_mod = 0;
1917 var type = (FullNamedExpression) $3;
1918 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1920 current_property = indexer;
1922 current_type.AddIndexer (indexer);
1923 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1925 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1926 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1928 if (indexer.ParameterInfo.IsEmpty) {
1929 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1933 tmpComment = Lexer.consume_doc_comment ();
1934 Lexer.doc_state = XmlCommentState.Allowed;
1937 lexer.PropertyParsing = true;
1938 current_local_parameters = (ParametersCompiled) $7;
1942 lexer.PropertyParsing = false;
1943 current_local_parameters = null;
1945 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1946 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1949 current_property.DocComment = ConsumeStoredComment ();
1951 current_property = null;
1956 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1958 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1962 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1963 current_property.Get.Block = (ToplevelBlock) $1;
1967 accessor_declarations
1968 : get_accessor_declaration
1969 | get_accessor_declaration accessor_declarations
1970 | set_accessor_declaration
1971 | set_accessor_declaration accessor_declarations
1974 if (yyToken == Token.CLOSE_BRACE) {
1975 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1977 if (yyToken == Token.SEMICOLON)
1978 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1980 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1985 get_accessor_declaration
1986 : opt_attributes opt_modifiers GET
1988 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1989 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1992 if (current_property.Get != null) {
1993 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1996 if (current_property is Indexer) {
1997 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1998 (Attributes) $1, GetLocation ($3));
2000 current_property.Get = new Property.GetMethod (current_property,
2001 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
2004 current_local_parameters = current_property.Get.ParameterInfo;
2005 lbag.AddMember (current_property.Get, mod_locations);
2006 lexer.PropertyParsing = false;
2011 current_property.Get.Block = (ToplevelBlock) $5;
2013 if (current_container.Kind == MemberKind.Interface) {
2014 report.Error (531, current_property.Get.Block.StartLocation,
2015 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2019 current_local_parameters = null;
2020 lexer.PropertyParsing = true;
2023 if (Lexer.doc_state == XmlCommentState.Error)
2024 Lexer.doc_state = XmlCommentState.NotAllowed;
2028 set_accessor_declaration
2029 : opt_attributes opt_modifiers SET
2031 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2032 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2035 if (current_property.Set != null) {
2036 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2039 if (current_property is Indexer) {
2040 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2041 ParametersCompiled.MergeGenerated (compiler,
2042 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2043 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2045 (Attributes) $1, GetLocation ($3));
2047 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2048 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2049 (Attributes) $1, GetLocation ($3));
2052 current_local_parameters = current_property.Set.ParameterInfo;
2053 lbag.AddMember (current_property.Set, mod_locations);
2054 lexer.PropertyParsing = false;
2059 current_property.Set.Block = (ToplevelBlock) $5;
2061 if (current_container.Kind == MemberKind.Interface) {
2062 report.Error (531, current_property.Set.Block.StartLocation,
2063 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2067 current_local_parameters = null;
2068 lexer.PropertyParsing = true;
2071 && Lexer.doc_state == XmlCommentState.Error)
2072 Lexer.doc_state = XmlCommentState.NotAllowed;
2086 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2092 interface_declaration
2099 type_declaration_name
2101 lexer.ConstraintsParsing = true;
2102 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2103 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2106 opt_type_parameter_constraints_clauses
2108 lexer.ConstraintsParsing = false;
2111 current_container.SetConstraints ((List<Constraints>) $9);
2114 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2115 Lexer.doc_state = XmlCommentState.Allowed;
2118 lexer.parsing_modifiers = true;
2120 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2122 --lexer.parsing_declaration;
2124 Lexer.doc_state = XmlCommentState.Allowed;
2129 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2131 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2133 $$ = pop_current_class ();
2135 | opt_attributes opt_modifiers opt_partial INTERFACE error
2137 Error_SyntaxError (yyToken);
2141 opt_interface_member_declarations
2143 | interface_member_declarations
2146 interface_member_declarations
2147 : interface_member_declaration
2149 lexer.parsing_modifiers = true;
2150 lexer.parsing_block = 0;
2152 | interface_member_declarations interface_member_declaration
2154 lexer.parsing_modifiers = true;
2155 lexer.parsing_block = 0;
2159 interface_member_declaration
2160 : constant_declaration
2162 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2166 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2168 | method_declaration
2169 | property_declaration
2171 | indexer_declaration
2172 | operator_declaration
2174 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2176 | constructor_declaration
2178 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2182 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2186 operator_declaration
2187 : opt_attributes opt_modifiers operator_declarator
2190 method_body_expression_block
2192 OperatorDeclaration decl = (OperatorDeclaration) $3;
2194 Operator op = new Operator (
2195 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2196 current_local_parameters,
2197 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2199 if (op.Block == null)
2200 op.ParameterInfo.CheckParameters (op);
2203 op.DocComment = tmpComment;
2204 Lexer.doc_state = XmlCommentState.Allowed;
2207 // Note again, checking is done in semantic analysis
2208 current_type.AddOperator (op);
2210 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2213 current_local_parameters = null;
2218 : type_expression_or_array
2221 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2222 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2227 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2229 valid_param_mod = ParameterModifierType.DefaultValue;
2230 if ((Operator.OpType) $3 == Operator.OpType.Is)
2231 valid_param_mod |= ParameterModifierType.Out;
2233 opt_formal_parameter_list CLOSE_PARENS
2235 valid_param_mod = 0;
2237 Location loc = GetLocation ($2);
2238 Operator.OpType op = (Operator.OpType) $3;
2239 current_local_parameters = (ParametersCompiled)$6;
2241 int p_count = current_local_parameters.Count;
2243 if (op == Operator.OpType.Addition)
2244 op = Operator.OpType.UnaryPlus;
2245 else if (op == Operator.OpType.Subtraction)
2246 op = Operator.OpType.UnaryNegation;
2249 if (IsUnaryOperator (op)) {
2251 report.Error (1020, loc, "Overloadable binary operator expected");
2252 } else if (p_count != 1) {
2253 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2254 Operator.GetName (op));
2256 } else if (op == Operator.OpType.Is) {
2257 // TODO: Special checks for is operator
2260 report.Error (1019, loc, "Overloadable unary operator expected");
2261 } else if (p_count != 2) {
2262 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2263 Operator.GetName (op));
2268 tmpComment = Lexer.consume_doc_comment ();
2269 Lexer.doc_state = XmlCommentState.NotAllowed;
2272 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2273 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2275 | conversion_operator_declarator
2278 overloadable_operator
2280 : BANG { $$ = Operator.OpType.LogicalNot; }
2281 | TILDE { $$ = Operator.OpType.OnesComplement; }
2282 | OP_INC { $$ = Operator.OpType.Increment; }
2283 | OP_DEC { $$ = Operator.OpType.Decrement; }
2284 | TRUE { $$ = Operator.OpType.True; }
2285 | FALSE { $$ = Operator.OpType.False; }
2286 // Unary and binary:
2287 | PLUS { $$ = Operator.OpType.Addition; }
2288 | MINUS { $$ = Operator.OpType.Subtraction; }
2290 | STAR { $$ = Operator.OpType.Multiply; }
2291 | DIV { $$ = Operator.OpType.Division; }
2292 | PERCENT { $$ = Operator.OpType.Modulus; }
2293 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2294 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2295 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2296 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2297 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2298 | OP_EQ { $$ = Operator.OpType.Equality; }
2299 | OP_NE { $$ = Operator.OpType.Inequality; }
2300 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2301 | OP_LT { $$ = Operator.OpType.LessThan; }
2302 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2303 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2306 if (lang_version != LanguageVersion.Experimental)
2307 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2309 $$ = Operator.OpType.Is;
2313 conversion_operator_declarator
2314 : IMPLICIT OPERATOR type OPEN_PARENS
2316 valid_param_mod = ParameterModifierType.DefaultValue;
2318 opt_formal_parameter_list CLOSE_PARENS
2320 valid_param_mod = 0;
2322 Location loc = GetLocation ($2);
2323 current_local_parameters = (ParametersCompiled)$6;
2325 if (current_local_parameters.Count != 1) {
2326 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2330 tmpComment = Lexer.consume_doc_comment ();
2331 Lexer.doc_state = XmlCommentState.NotAllowed;
2334 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2335 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2337 | EXPLICIT OPERATOR type OPEN_PARENS
2339 valid_param_mod = ParameterModifierType.DefaultValue;
2341 opt_formal_parameter_list CLOSE_PARENS
2343 valid_param_mod = 0;
2345 Location loc = GetLocation ($2);
2346 current_local_parameters = (ParametersCompiled)$6;
2348 if (current_local_parameters.Count != 1) {
2349 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2353 tmpComment = Lexer.consume_doc_comment ();
2354 Lexer.doc_state = XmlCommentState.NotAllowed;
2357 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2358 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2362 Error_SyntaxError (yyToken);
2363 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2364 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2368 Error_SyntaxError (yyToken);
2369 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2370 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2374 constructor_declaration
2375 : constructor_declarator
2378 Constructor c = (Constructor) $1;
2379 c.Block = (ToplevelBlock) $2;
2382 c.DocComment = ConsumeStoredComment ();
2384 current_local_parameters = null;
2386 Lexer.doc_state = XmlCommentState.Allowed;
2390 constructor_declarator
2396 tmpComment = Lexer.consume_doc_comment ();
2397 Lexer.doc_state = XmlCommentState.Allowed;
2400 valid_param_mod = ParameterModifierType.All;
2402 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2404 valid_param_mod = 0;
2405 current_local_parameters = (ParametersCompiled) $6;
2407 var lt = (LocatedToken) $3;
2408 var mods = (Modifiers) $2;
2409 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2411 if (lt.Value != current_container.MemberName.Name) {
2412 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2413 } else if ((mods & Modifiers.STATIC) != 0) {
2414 if (!current_local_parameters.IsEmpty) {
2415 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2416 c.GetSignatureForError ());
2419 if ((mods & Modifiers.AccessibilityMask) != 0){
2420 report.Error (515, c.Location,
2421 "`{0}': static constructor cannot have an access modifier",
2422 c.GetSignatureForError ());
2425 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2426 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2430 current_type.AddConstructor (c);
2431 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2435 // start block here, so possible anonymous methods inside
2436 // constructor initializer can get correct parent block
2438 start_block (lexer.Location);
2440 opt_constructor_initializer
2443 var c = (Constructor) $8;
2444 c.Initializer = (ConstructorInitializer) $9;
2447 report.Error (514, c.Location,
2448 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2449 c.GetSignatureForError ());
2459 | SEMICOLON { current_block = null; $$ = null; }
2462 opt_constructor_initializer
2464 | constructor_initializer
2467 constructor_initializer
2468 : COLON BASE OPEN_PARENS
2470 ++lexer.parsing_block;
2472 opt_argument_list CLOSE_PARENS
2474 --lexer.parsing_block;
2475 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2476 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2478 | COLON THIS OPEN_PARENS
2480 ++lexer.parsing_block;
2482 opt_argument_list CLOSE_PARENS
2484 --lexer.parsing_block;
2485 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2486 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2490 Error_SyntaxError (yyToken);
2491 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2492 lbag.AddLocation ($$, GetLocation ($1));
2496 Error_SyntaxError (yyToken);
2501 destructor_declaration
2502 : opt_attributes opt_modifiers TILDE
2505 tmpComment = Lexer.consume_doc_comment ();
2506 Lexer.doc_state = XmlCommentState.NotAllowed;
2509 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2511 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2513 var lt = (LocatedToken) $5;
2514 if (lt.Value != current_container.MemberName.Name){
2515 report.Error (574, lt.Location, "Name of destructor must match name of class");
2516 } else if (current_container.Kind != MemberKind.Class){
2517 report.Error (575, lt.Location, "Only class types can contain destructor");
2520 Destructor d = new Destructor (current_type, (Modifiers) $2,
2521 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2523 d.DocComment = ConsumeStoredComment ();
2525 d.Block = (ToplevelBlock) $8;
2526 current_type.AddMember (d);
2527 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2529 current_local_parameters = null;
2536 EVENT type member_declaration_name
2538 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2539 current_type.AddMember (current_event_field);
2541 if (current_event_field.MemberName.ExplicitInterface != null) {
2542 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2543 current_event_field.GetSignatureForError ());
2546 $$ = current_event_field;
2548 opt_event_initializer
2549 opt_event_declarators
2553 current_event_field.DocComment = Lexer.consume_doc_comment ();
2554 Lexer.doc_state = XmlCommentState.Allowed;
2557 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2558 current_event_field = null;
2562 EVENT type member_declaration_name
2565 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2566 current_type.AddMember (current_event);
2567 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2569 lexer.EventParsing = true;
2571 event_accessor_declarations
2573 if (current_container.Kind == MemberKind.Interface)
2574 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2576 lexer.EventParsing = false;
2581 current_event.DocComment = Lexer.consume_doc_comment ();
2582 Lexer.doc_state = XmlCommentState.Allowed;
2585 lbag.AppendToMember (current_event, GetLocation ($9));
2586 current_event = null;
2587 current_local_parameters = null;
2593 Error_SyntaxError (yyToken);
2595 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2599 opt_event_initializer
2603 ++lexer.parsing_block;
2605 event_variable_initializer
2607 --lexer.parsing_block;
2608 current_event_field.Initializer = (Expression) $3;
2612 opt_event_declarators
2620 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2622 | event_declarators event_declarator
2624 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2631 var lt = (LocatedToken) $2;
2632 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2633 lbag.AddLocation ($$, GetLocation ($1));
2635 | COMMA IDENTIFIER ASSIGN
2637 ++lexer.parsing_block;
2639 event_variable_initializer
2641 --lexer.parsing_block;
2642 var lt = (LocatedToken) $2;
2643 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2644 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2648 event_variable_initializer
2650 if (current_container.Kind == MemberKind.Interface) {
2651 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2652 current_event_field.GetSignatureForError ());
2655 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2656 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2657 current_event_field.GetSignatureForError ());
2660 variable_initializer
2666 event_accessor_declarations
2667 : add_accessor_declaration remove_accessor_declaration
2668 | remove_accessor_declaration add_accessor_declaration
2669 | add_accessor_declaration
2671 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2672 current_event.GetSignatureForError ());
2674 | remove_accessor_declaration
2676 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2677 current_event.GetSignatureForError ());
2681 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2686 add_accessor_declaration
2687 : opt_attributes opt_modifiers ADD
2689 if ($2 != ModifierNone) {
2690 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2693 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2694 current_local_parameters = current_event.Add.ParameterInfo;
2696 lbag.AddMember (current_event.Add, mod_locations);
2697 lexer.EventParsing = false;
2699 event_accessor_block
2701 lexer.EventParsing = true;
2703 current_event.Add.Block = (ToplevelBlock) $5;
2705 if (current_container.Kind == MemberKind.Interface) {
2706 report.Error (531, current_event.Add.Block.StartLocation,
2707 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2710 current_local_parameters = null;
2714 remove_accessor_declaration
2715 : opt_attributes opt_modifiers REMOVE
2717 if ($2 != ModifierNone) {
2718 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2721 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2722 current_local_parameters = current_event.Remove.ParameterInfo;
2724 lbag.AddMember (current_event.Remove, mod_locations);
2725 lexer.EventParsing = false;
2727 event_accessor_block
2729 lexer.EventParsing = true;
2731 current_event.Remove.Block = (ToplevelBlock) $5;
2733 if (current_container.Kind == MemberKind.Interface) {
2734 report.Error (531, current_event.Remove.Block.StartLocation,
2735 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2738 current_local_parameters = null;
2742 event_accessor_block
2745 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2752 attributes_without_members
2753 : attribute_sections CLOSE_BRACE
2755 current_type.UnattachedAttributes = (Attributes) $1;
2756 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2757 lexer.putback ('}');
2761 // For full ast try to recover incomplete ambiguous member
2762 // declaration in form on class X { public int }
2764 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2766 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2768 lexer.putback ('}');
2770 lexer.parsing_generic_declaration = false;
2771 FullNamedExpression type = (FullNamedExpression) $3;
2772 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2773 current_type.AddField (current_field);
2781 ENUM type_declaration_name
2785 enumTypeComment = Lexer.consume_doc_comment ();
2790 Lexer.doc_state = XmlCommentState.Allowed;
2792 MemberName name = (MemberName) $4;
2793 if (name.IsGeneric) {
2794 report.Error (1675, name.Location, "Enums cannot have type parameters");
2797 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2799 opt_enum_member_declarations
2801 lexer.parsing_modifiers = true;
2803 // here will be evaluated after CLOSE_BLACE is consumed.
2805 Lexer.doc_state = XmlCommentState.Allowed;
2807 CLOSE_BRACE opt_semicolon
2810 current_container.DocComment = enumTypeComment;
2812 --lexer.parsing_declaration;
2815 // em.DocComment = ev.DocComment;
2817 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2818 $$ = pop_current_class ();
2830 Error_TypeExpected (GetLocation ($1));
2835 opt_enum_member_declarations
2837 | enum_member_declarations
2838 | enum_member_declarations COMMA
2840 lbag.AddLocation ($1, GetLocation ($2));
2844 enum_member_declarations
2845 : enum_member_declaration
2846 | enum_member_declarations COMMA enum_member_declaration
2848 lbag.AddLocation ($1, GetLocation ($2));
2853 enum_member_declaration
2854 : opt_attributes IDENTIFIER
2856 var lt = (LocatedToken) $2;
2857 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2858 ((Enum) current_type).AddEnumMember (em);
2861 em.DocComment = Lexer.consume_doc_comment ();
2862 Lexer.doc_state = XmlCommentState.Allowed;
2867 | opt_attributes IDENTIFIER
2869 ++lexer.parsing_block;
2871 tmpComment = Lexer.consume_doc_comment ();
2872 Lexer.doc_state = XmlCommentState.NotAllowed;
2875 ASSIGN constant_expression
2877 --lexer.parsing_block;
2879 var lt = (LocatedToken) $2;
2880 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2881 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2882 ((Enum) current_type).AddEnumMember (em);
2885 em.DocComment = ConsumeStoredComment ();
2889 | opt_attributes IDENTIFIER error
2891 Error_SyntaxError (yyToken);
2893 var lt = (LocatedToken) $2;
2894 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2895 ((Enum) current_type).AddEnumMember (em);
2898 em.DocComment = Lexer.consume_doc_comment ();
2899 Lexer.doc_state = XmlCommentState.Allowed;
2904 | attributes_without_members
2907 delegate_declaration
2911 member_type type_declaration_name
2914 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2916 opt_formal_parameter_list CLOSE_PARENS
2918 valid_param_mod = 0;
2920 ParametersCompiled p = (ParametersCompiled) $8;
2922 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2924 p.CheckParameters (del);
2926 current_container.AddTypeContainer (del);
2928 current_delegate = del;
2929 lexer.ConstraintsParsing = true;
2931 opt_type_parameter_constraints_clauses
2933 lexer.ConstraintsParsing = false;
2938 current_delegate.DocComment = Lexer.consume_doc_comment ();
2939 Lexer.doc_state = XmlCommentState.Allowed;
2943 current_delegate.SetConstraints ((List<Constraints>) $11);
2944 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2946 $$ = current_delegate;
2948 current_delegate = null;
2956 if (lang_version < LanguageVersion.ISO_2)
2957 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2959 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2963 namespace_or_type_expr
2965 | qualified_alias_member IDENTIFIER opt_type_argument_list
2967 var lt1 = (LocatedToken) $1;
2968 var lt2 = (LocatedToken) $2;
2970 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2971 lbag.AddLocation ($$, GetLocation ($2));
2973 | qualified_alias_member IDENTIFIER generic_dimension
2975 var lt1 = (LocatedToken) $1;
2976 var lt2 = (LocatedToken) $2;
2978 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2979 lbag.AddLocation ($$, GetLocation ($2));
2985 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2987 var lt = (LocatedToken) $3;
2988 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2989 lbag.AddLocation ($$, GetLocation ($2));
2991 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2993 var lt = (LocatedToken) $3;
2994 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2995 lbag.AddLocation ($$, GetLocation ($2));
3000 : IDENTIFIER opt_type_argument_list
3002 var lt = (LocatedToken) $1;
3003 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3005 | IDENTIFIER generic_dimension
3007 var lt = (LocatedToken) $1;
3008 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3013 // Generics arguments (any type, without attributes)
3015 opt_type_argument_list
3017 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3019 if (lang_version < LanguageVersion.ISO_2)
3020 FeatureIsNotAvailable (GetLocation ($1), "generics");
3024 | OP_GENERICS_LT error
3026 Error_TypeExpected (lexer.Location);
3027 $$ = new TypeArguments ();
3034 TypeArguments type_args = new TypeArguments ();
3035 type_args.Add ((FullNamedExpression) $1);
3038 | type_arguments COMMA type
3040 TypeArguments type_args = (TypeArguments) $1;
3041 type_args.Add ((FullNamedExpression) $3);
3047 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3049 type_declaration_name
3052 lexer.parsing_generic_declaration = true;
3054 opt_type_parameter_list
3056 lexer.parsing_generic_declaration = false;
3057 var lt = (LocatedToken) $1;
3058 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3062 member_declaration_name
3063 : method_declaration_name
3065 MemberName mn = (MemberName)$1;
3066 if (mn.TypeParameters != null)
3067 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3068 mn.GetSignatureForError ()));
3072 method_declaration_name
3073 : type_declaration_name
3074 | explicit_interface IDENTIFIER opt_type_parameter_list
3076 lexer.parsing_generic_declaration = false;
3077 var lt = (LocatedToken) $2;
3078 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3082 indexer_declaration_name
3085 lexer.parsing_generic_declaration = false;
3086 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3088 | explicit_interface THIS
3090 lexer.parsing_generic_declaration = false;
3091 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3096 : IDENTIFIER opt_type_argument_list DOT
3098 var lt = (LocatedToken) $1;
3099 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3100 lbag.AddLocation ($$, GetLocation ($3));
3102 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3104 var lt1 = (LocatedToken) $1;
3105 var lt2 = (LocatedToken) $2;
3107 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3108 lbag.AddLocation ($$, GetLocation ($4));
3110 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3112 var lt = (LocatedToken) $2;
3113 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3114 lbag.AddLocation ($$, GetLocation ($4));
3118 opt_type_parameter_list
3120 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3122 if (lang_version < LanguageVersion.ISO_2)
3123 FeatureIsNotAvailable (GetLocation ($1), "generics");
3126 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3133 var tparams = new TypeParameters ();
3134 tparams.Add ((TypeParameter)$1);
3137 | type_parameters COMMA type_parameter
3139 var tparams = (TypeParameters) $1;
3140 tparams.Add ((TypeParameter)$3);
3142 lbag.AddLocation ($3, GetLocation ($3));
3147 : opt_attributes opt_type_parameter_variance IDENTIFIER
3149 var lt = (LocatedToken)$3;
3150 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3154 if (GetTokenName (yyToken) == "type")
3155 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3157 Error_SyntaxError (yyToken);
3159 $$ = new TypeParameter (MemberName.Null, null, null);
3164 // All types where void is allowed
3167 : type_expression_or_array
3170 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3177 lexer.parsing_generic_declaration = true;
3182 // A type which does not allow `void' to be used
3185 : type_expression_or_array
3195 : type_expression_or_array
3198 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3199 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3203 type_expression_or_array
3205 | type_expression rank_specifiers
3207 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3212 : namespace_or_type_expr opt_nullable
3215 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3217 var sn = $1 as SimpleName;
3218 if (sn != null && sn.Name == "var")
3219 $$ = new VarExpr (sn.Location);
3224 | namespace_or_type_expr pointer_stars
3226 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3228 | builtin_type_expression
3234 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3235 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3239 builtin_type_expression
3240 : builtin_types opt_nullable
3243 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3245 | builtin_types pointer_stars
3247 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3249 | VOID pointer_stars
3251 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3258 var types = new List<FullNamedExpression> (2);
3259 types.Add ((FullNamedExpression) $1);
3262 | type_list COMMA base_type_name
3264 var types = (List<FullNamedExpression>) $1;
3265 types.Add ((FullNamedExpression) $3);
3273 if ($1 is ComposedCast) {
3274 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3281 * replaces all the productions for isolating the various
3282 * simple types, but we need this to reuse it easily in variable_type
3285 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3286 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3287 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3288 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3289 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3290 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3295 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3296 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3297 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3298 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3299 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3300 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3301 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3302 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3303 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3307 // Expressions, section 7.5
3312 : type_name_expression
3314 | array_creation_expression
3315 | parenthesized_expression
3316 | default_value_expression
3317 | invocation_expression
3321 | post_increment_expression
3322 | post_decrement_expression
3323 | object_or_delegate_creation_expression
3324 | anonymous_type_expression
3327 | checked_expression
3328 | unchecked_expression
3329 | pointer_member_access
3330 | anonymous_method_expression
3331 | undocumented_expressions
3332 | interpolated_string
3335 type_name_expression
3337 | IDENTIFIER GENERATE_COMPLETION {
3338 var lt = (LocatedToken) $1;
3339 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3347 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3351 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3352 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3356 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3358 if (lang_version < LanguageVersion.V_6)
3359 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3361 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3363 | INTERPOLATED_STRING_END
3365 if (lang_version < LanguageVersion.V_6)
3366 FeatureIsNotAvailable (GetLocation ($1), "interpolated strings");
3368 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3375 var list = new List<Expression> ();
3376 list.Add ((InterpolatedStringInsert) $1);
3379 | interpolations INTERPOLATED_STRING interpolation
3381 var list = (List<Expression>) $1;
3382 list.Add ((StringLiteral) $2);
3383 list.Add ((InterpolatedStringInsert) $3);
3391 $$ = new InterpolatedStringInsert ((Expression) $1);
3393 | expression COMMA expression
3395 $$ = new InterpolatedStringInsert ((Expression) $1) {
3396 Alignment = (Expression)$3
3401 lexer.parsing_interpolation_format = true;
3405 lexer.parsing_interpolation_format = false;
3407 $$ = new InterpolatedStringInsert ((Expression) $1) {
3411 | expression COMMA expression COLON
3413 lexer.parsing_interpolation_format = true;
3417 lexer.parsing_interpolation_format = false;
3419 $$ = new InterpolatedStringInsert ((Expression) $1) {
3420 Alignment = (Expression)$3,
3421 Format = (string) $6
3428 // Here is the trick, tokenizer may think that parens is a special but
3429 // parser is interested in open parens only, so we merge them.
3430 // Consider: if (a)foo ();
3438 // Use this production to accept closing parenthesis or
3439 // performing completion
3443 | COMPLETE_COMPLETION
3447 parenthesized_expression
3448 : OPEN_PARENS expression CLOSE_PARENS
3450 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3451 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3453 | OPEN_PARENS expression COMPLETE_COMPLETION
3455 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3460 : primary_expression DOT identifier_inside_body opt_type_argument_list
3462 var lt = (LocatedToken) $3;
3463 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3464 lbag.AddLocation ($$, GetLocation ($2));
3466 | primary_expression DOT identifier_inside_body generic_dimension
3468 var lt = (LocatedToken) $3;
3469 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3470 lbag.AddLocation ($$, GetLocation ($2));
3472 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3474 if (lang_version < LanguageVersion.V_6)
3475 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3477 var lt = (LocatedToken) $4;
3478 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3479 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3481 | builtin_types DOT identifier_inside_body opt_type_argument_list
3483 var lt = (LocatedToken) $3;
3484 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3485 lbag.AddLocation ($$, GetLocation ($2));
3487 | BASE DOT identifier_inside_body opt_type_argument_list
3489 var lt = (LocatedToken) $3;
3490 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3491 lbag.AddLocation ($$, GetLocation ($2));
3493 | AWAIT DOT identifier_inside_body opt_type_argument_list
3495 var lt = (LocatedToken) $3;
3496 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3497 lbag.AddLocation ($$, GetLocation ($2));
3499 | qualified_alias_member identifier_inside_body opt_type_argument_list
3501 var lt1 = (LocatedToken) $1;
3502 var lt2 = (LocatedToken) $2;
3504 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3505 lbag.AddLocation ($$, GetLocation ($2));
3507 | qualified_alias_member identifier_inside_body generic_dimension
3509 var lt1 = (LocatedToken) $1;
3510 var lt2 = (LocatedToken) $2;
3512 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3513 lbag.AddLocation ($$, GetLocation ($2));
3515 | primary_expression DOT GENERATE_COMPLETION {
3516 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3518 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3519 var lt = (LocatedToken) $3;
3520 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3522 | builtin_types DOT GENERATE_COMPLETION
3524 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3526 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3527 var lt = (LocatedToken) $3;
3528 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3532 invocation_expression
3533 : primary_expression open_parens_any opt_argument_list close_parens
3535 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3536 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3538 | primary_expression open_parens_any argument_list error
3540 Error_SyntaxError (yyToken);
3542 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3543 lbag.AddLocation ($$, GetLocation ($2));
3545 | primary_expression open_parens_any error
3547 Error_SyntaxError (yyToken);
3549 $$ = new Invocation ((Expression) $1, null);
3550 lbag.AddLocation ($$, GetLocation ($2));
3554 opt_object_or_collection_initializer
3555 : /* empty */ { $$ = null; }
3556 | object_or_collection_initializer
3559 object_or_collection_initializer
3560 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3563 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3565 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3567 lbag.AddLocation ($$, GetLocation ($3));
3569 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3571 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3572 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3576 opt_member_initializer_list
3577 : /* empty */ { $$ = null; }
3578 | member_initializer_list
3584 member_initializer_list
3585 : member_initializer
3587 var a = new List<Expression> ();
3588 a.Add ((Expression) $1);
3591 | member_initializer_list COMMA member_initializer
3593 var a = (List<Expression>)$1;
3594 a.Add ((Expression) $3);
3597 | member_initializer_list error {
3598 Error_SyntaxError (yyToken);
3604 : IDENTIFIER ASSIGN initializer_value
3606 var lt = (LocatedToken) $1;
3607 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3608 lbag.AddLocation ($$, GetLocation ($2));
3610 | AWAIT ASSIGN initializer_value
3612 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3613 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3614 lbag.AddLocation ($$, GetLocation ($2));
3616 | GENERATE_COMPLETION
3618 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3620 | non_assignment_expression opt_COMPLETE_COMPLETION {
3621 CompletionSimpleName csn = $1 as CompletionSimpleName;
3623 $$ = new CollectionElementInitializer ((Expression)$1);
3625 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3627 | OPEN_BRACE expression_list CLOSE_BRACE
3630 $$ = new CollectionElementInitializer (GetLocation ($1));
3632 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3634 lbag.AddLocation ($$, GetLocation ($3));
3636 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3638 if (lang_version < LanguageVersion.V_6)
3639 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3641 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3642 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3644 | OPEN_BRACE CLOSE_BRACE
3646 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3647 $$ = new CollectionElementInitializer (GetLocation ($1));
3648 lbag.AddLocation ($$, GetLocation ($2));
3654 | object_or_collection_initializer
3658 : /* empty */ { $$ = null; }
3663 : argument_or_named_argument
3665 Arguments list = new Arguments (4);
3666 list.Add ((Argument) $1);
3669 | argument_list COMMA argument
3671 Arguments list = (Arguments) $1;
3672 if (list [list.Count - 1] is NamedArgument)
3673 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3675 list.Add ((Argument) $3);
3678 | argument_list COMMA named_argument
3680 Arguments list = (Arguments) $1;
3681 NamedArgument a = (NamedArgument) $3;
3682 for (int i = 0; i < list.Count; ++i) {
3683 NamedArgument na = list [i] as NamedArgument;
3684 if (na != null && na.Name == a.Name)
3685 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3692 | argument_list COMMA error
3694 if (lexer.putback_char == -1)
3695 lexer.putback (')'); // TODO: Wrong but what can I do
3696 Error_SyntaxError (yyToken);
3701 report.Error (839, GetLocation ($1), "An argument is missing");
3709 $$ = new Argument ((Expression) $1);
3711 | non_simple_argument
3714 argument_or_named_argument
3720 : REF variable_reference
3722 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3723 lbag.AddLocation ($$, GetLocation ($1));
3725 | REF declaration_expression
3727 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3729 | OUT variable_reference
3731 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3732 lbag.AddLocation ($$, GetLocation ($1));
3734 | OUT declaration_expression
3736 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3738 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3740 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3741 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3743 | ARGLIST OPEN_PARENS CLOSE_PARENS
3745 $$ = new Argument (new Arglist (GetLocation ($1)));
3746 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3750 declaration_expression
3751 : OPEN_PARENS declaration_expression CLOSE_PARENS
3753 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3754 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3757 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3759 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3760 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3762 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3764 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3765 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3768 | variable_type identifier_inside_body
3770 if (lang_version != LanguageVersion.Experimental)
3771 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3773 var lt = (LocatedToken) $2;
3774 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3775 current_block.AddLocalName (lv);
3776 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3778 | variable_type identifier_inside_body ASSIGN expression
3780 if (lang_version != LanguageVersion.Experimental)
3781 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3783 var lt = (LocatedToken) $2;
3784 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3785 current_block.AddLocalName (lv);
3786 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3787 Initializer = (Expression) $4
3797 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3799 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3800 lbag.AddLocation ($$, GetLocation ($4));
3802 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3804 if (lang_version < LanguageVersion.V_6)
3805 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3807 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3808 ConditionalAccess = true
3811 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3813 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3815 Error_SyntaxError (yyToken);
3816 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3818 | primary_expression OPEN_BRACKET_EXPR error
3820 Error_SyntaxError (yyToken);
3821 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3826 : expression_or_error
3828 var list = new List<Expression> (4);
3829 list.Add ((Expression) $1);
3832 | expression_list COMMA expression_or_error
3834 var list = (List<Expression>) $1;
3835 list.Add ((Expression) $3);
3840 expression_list_arguments
3841 : expression_list_argument
3843 Arguments args = new Arguments (4);
3844 args.Add ((Argument) $1);
3847 | expression_list_arguments COMMA expression_list_argument
3849 Arguments args = (Arguments) $1;
3850 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3851 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3853 args.Add ((Argument) $3);
3858 expression_list_argument
3861 $$ = new Argument ((Expression) $1);
3869 $$ = new This (GetLocation ($1));
3874 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3876 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3877 lbag.AddLocation ($$, GetLocation ($4));
3879 | BASE OPEN_BRACKET error
3881 Error_SyntaxError (yyToken);
3882 $$ = new ElementAccess (null, null, GetLocation ($2));
3886 post_increment_expression
3887 : primary_expression OP_INC
3889 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3893 post_decrement_expression
3894 : primary_expression OP_DEC
3896 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3900 object_or_delegate_creation_expression
3901 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3904 if (lang_version <= LanguageVersion.ISO_2)
3905 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3907 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3909 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3912 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3914 | NEW new_expr_type object_or_collection_initializer
3916 if (lang_version <= LanguageVersion.ISO_2)
3917 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3919 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3923 array_creation_expression
3924 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3926 opt_array_initializer
3928 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3929 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3930 Next = (ComposedTypeSpecifier) $6
3931 }, (ArrayInitializer) $7, GetLocation ($1)) {
3932 NoEmptyInterpolation = true
3935 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3937 | NEW new_expr_type rank_specifiers opt_array_initializer
3940 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3942 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1)) {
3943 NoEmptyInterpolation = true
3946 | NEW rank_specifier array_initializer
3948 if (lang_version <= LanguageVersion.ISO_2)
3949 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3951 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3953 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3955 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3956 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3958 | NEW new_expr_type error
3960 Error_SyntaxError (yyToken);
3961 // It can be any of new expression, create the most common one
3962 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3968 ++lexer.parsing_type;
3972 --lexer.parsing_type;
3977 anonymous_type_expression
3978 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3980 if (lang_version <= LanguageVersion.ISO_2)
3981 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3983 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3985 // TODO: lbag comma location
3986 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3988 | NEW OPEN_BRACE GENERATE_COMPLETION
3990 $$ = new EmptyCompletion ();
3994 anonymous_type_parameters_opt_comma
3995 : anonymous_type_parameters_opt
3996 | anonymous_type_parameters COMMA
3999 anonymous_type_parameters_opt
4001 | anonymous_type_parameters
4004 anonymous_type_parameters
4005 : anonymous_type_parameter
4007 var a = new List<AnonymousTypeParameter> (4);
4008 a.Add ((AnonymousTypeParameter) $1);
4011 | anonymous_type_parameters COMMA anonymous_type_parameter
4013 var a = (List<AnonymousTypeParameter>) $1;
4014 a.Add ((AnonymousTypeParameter) $3);
4017 | COMPLETE_COMPLETION
4019 $$ = new EmptyCompletion ();
4021 | anonymous_type_parameter COMPLETE_COMPLETION
4027 anonymous_type_parameter
4028 : identifier_inside_body ASSIGN variable_initializer
4030 var lt = (LocatedToken)$1;
4031 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4032 lbag.AddLocation ($$, GetLocation ($2));
4034 | identifier_inside_body
4036 var lt = (LocatedToken)$1;
4037 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4038 lt.Value, lt.Location);
4042 MemberAccess ma = (MemberAccess) $1;
4043 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4047 report.Error (746, lexer.Location,
4048 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4060 | rank_specifier rank_specifiers
4062 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4068 : OPEN_BRACKET CLOSE_BRACKET
4070 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4071 lbag.AddLocation ($$, GetLocation ($2));
4073 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4075 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4076 lbag.AddLocation ($$, GetLocation ($3));
4085 | dim_separators COMMA
4087 $$ = ((int) $1) + 1;
4091 opt_array_initializer
4103 : OPEN_BRACE CLOSE_BRACE
4105 var ai = new ArrayInitializer (0, GetLocation ($1));
4106 ai.VariableDeclaration = current_variable;
4107 lbag.AddLocation (ai, GetLocation ($2));
4110 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4112 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4113 ai.VariableDeclaration = current_variable;
4115 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4117 lbag.AddLocation (ai, GetLocation ($4));
4123 variable_initializer_list
4124 : variable_initializer
4126 var list = new List<Expression> (4);
4127 list.Add ((Expression) $1);
4130 | variable_initializer_list COMMA variable_initializer
4132 var list = (List<Expression>) $1;
4133 list.Add ((Expression) $3);
4139 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4141 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4142 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4146 typeof_type_expression
4150 Error_TypeExpected (lexer.Location);
4158 if (lang_version < LanguageVersion.ISO_2)
4159 FeatureIsNotAvailable (GetLocation ($1), "generics");
4165 qualified_alias_member
4166 : IDENTIFIER DOUBLE_COLON
4168 var lt = (LocatedToken) $1;
4169 if (lang_version == LanguageVersion.ISO_1)
4170 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4177 : SIZEOF open_parens_any type CLOSE_PARENS
4179 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4180 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4182 | SIZEOF open_parens_any type error
4184 Error_SyntaxError (yyToken);
4186 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4187 lbag.AddLocation ($$, GetLocation ($2));
4192 : CHECKED open_parens_any expression CLOSE_PARENS
4194 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4195 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4199 Error_SyntaxError (yyToken);
4201 $$ = new CheckedExpr (null, GetLocation ($1));
4205 unchecked_expression
4206 : UNCHECKED open_parens_any expression CLOSE_PARENS
4208 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4209 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4213 Error_SyntaxError (yyToken);
4215 $$ = new UnCheckedExpr (null, GetLocation ($1));
4219 pointer_member_access
4220 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4222 var lt = (LocatedToken) $3;
4223 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4227 anonymous_method_expression
4228 : DELEGATE opt_anonymous_method_signature
4230 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4234 $$ = end_anonymous ((ParametersBlock) $4);
4236 | ASYNC DELEGATE opt_anonymous_method_signature
4238 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4242 $$ = end_anonymous ((ParametersBlock) $5);
4246 opt_anonymous_method_signature
4249 $$ = ParametersCompiled.Undefined;
4251 | anonymous_method_signature
4254 anonymous_method_signature
4257 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4259 opt_formal_parameter_list CLOSE_PARENS
4261 valid_param_mod = 0;
4266 default_value_expression
4267 : DEFAULT open_parens_any type CLOSE_PARENS
4269 if (lang_version < LanguageVersion.ISO_2)
4270 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4272 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4273 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4278 : primary_expression
4279 | BANG prefixed_unary_expression
4281 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4283 | TILDE prefixed_unary_expression
4285 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4287 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4289 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4290 lbag.AddLocation ($$, GetLocation ($3));
4292 | AWAIT prefixed_unary_expression
4295 if (current_anonymous_method is LambdaExpression) {
4296 report.Error (4034, GetLocation ($1),
4297 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4298 } else if (current_anonymous_method != null) {
4299 report.Error (4035, GetLocation ($1),
4300 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4301 } else if (interactive_async != null) {
4302 current_block.Explicit.RegisterAsyncAwait ();
4303 interactive_async = true;
4305 report.Error (4033, GetLocation ($1),
4306 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4309 current_block.Explicit.RegisterAsyncAwait ();
4312 $$ = new Await ((Expression) $2, GetLocation ($1));
4314 | THROW_EXPR prefixed_unary_expression
4316 if (lang_version < LanguageVersion.V_7)
4317 FeatureIsNotAvailable (lexer.Location, "throw expression");
4319 $$ = new ThrowExpression ((Expression) $2, GetLocation ($1));
4323 Error_SyntaxError (yyToken);
4325 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4329 Error_SyntaxError (yyToken);
4331 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4333 | OPEN_PARENS_CAST type CLOSE_PARENS error
4335 Error_SyntaxError (yyToken);
4337 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4338 lbag.AddLocation ($$, GetLocation ($3));
4342 Error_SyntaxError (yyToken);
4344 $$ = new Await (null, GetLocation ($1));
4349 // The idea to split this out is from Rhys' grammar
4350 // to solve the problem with casts.
4352 prefixed_unary_expression
4354 | PLUS prefixed_unary_expression
4356 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4358 | MINUS prefixed_unary_expression
4360 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4362 | OP_INC prefixed_unary_expression
4364 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4366 | OP_DEC prefixed_unary_expression
4368 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4370 | STAR prefixed_unary_expression
4372 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4374 | BITWISE_AND prefixed_unary_expression
4376 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4380 Error_SyntaxError (yyToken);
4382 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4386 Error_SyntaxError (yyToken);
4388 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4392 Error_SyntaxError (yyToken);
4394 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4398 Error_SyntaxError (yyToken);
4400 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4404 Error_SyntaxError (yyToken);
4406 $$ = new Indirection (null, GetLocation ($1));
4410 Error_SyntaxError (yyToken);
4412 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4416 multiplicative_expression
4417 : prefixed_unary_expression
4418 | multiplicative_expression STAR prefixed_unary_expression
4420 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4421 lbag.AddLocation ($$, GetLocation ($2));
4423 | multiplicative_expression DIV prefixed_unary_expression
4425 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4426 lbag.AddLocation ($$, GetLocation ($2));
4428 | multiplicative_expression PERCENT prefixed_unary_expression
4430 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4431 lbag.AddLocation ($$, GetLocation ($2));
4433 | multiplicative_expression STAR error
4435 Error_SyntaxError (yyToken);
4437 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4438 lbag.AddLocation ($$, GetLocation ($2));
4440 | multiplicative_expression DIV error
4442 Error_SyntaxError (yyToken);
4444 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4445 lbag.AddLocation ($$, GetLocation ($2));
4447 | multiplicative_expression PERCENT error
4449 Error_SyntaxError (yyToken);
4451 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4452 lbag.AddLocation ($$, GetLocation ($2));
4457 : multiplicative_expression
4458 | additive_expression PLUS multiplicative_expression
4460 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4461 lbag.AddLocation ($$, GetLocation ($2));
4463 | additive_expression MINUS multiplicative_expression
4465 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4466 lbag.AddLocation ($$, GetLocation ($2));
4468 | additive_expression PLUS error
4470 Error_SyntaxError (yyToken);
4472 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4473 lbag.AddLocation ($$, GetLocation ($2));
4475 | additive_expression MINUS error
4477 Error_SyntaxError (yyToken);
4479 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4480 lbag.AddLocation ($$, GetLocation ($2));
4482 | additive_expression AS type
4484 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4486 | additive_expression IS pattern_type_expr opt_identifier
4488 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4490 if (lang_version != LanguageVersion.Experimental)
4491 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4493 var lt = (LocatedToken) $4;
4494 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4495 current_block.AddLocalName (is_expr.Variable);
4500 | additive_expression IS pattern_expr
4502 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4503 if (lang_version != LanguageVersion.Experimental)
4504 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4508 | additive_expression AS error
4510 Error_SyntaxError (yyToken);
4512 $$ = new As ((Expression) $1, null, GetLocation ($2));
4514 | additive_expression IS error
4516 Error_SyntaxError (yyToken);
4518 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4522 var lt = (LocatedToken) $1;
4523 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4527 var lt = (LocatedToken) $1;
4528 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4538 | PLUS prefixed_unary_expression
4540 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4542 | MINUS prefixed_unary_expression
4544 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4547 | default_value_expression
4548 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4550 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4551 lbag.AddLocation ($$, GetLocation ($3));
4555 $$ = new WildcardPattern (GetLocation ($1));
4557 | pattern_expr_invocation
4561 pattern_expr_invocation
4562 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4564 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4569 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4571 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4575 pattern_property_list
4576 : pattern_property_entry
4578 var list = new List<PropertyPatternMember> ();
4579 list.Add ((PropertyPatternMember) $1);
4582 | pattern_property_list COMMA pattern_property_entry
4584 var list = (List<PropertyPatternMember>) $1;
4585 list.Add ((PropertyPatternMember) $3);
4590 pattern_property_entry
4591 : identifier_inside_body IS pattern
4593 var lt = (LocatedToken) $1;
4594 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4600 | pattern_type_expr opt_identifier
4603 var lt = (LocatedToken) $2;
4604 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4605 current_block.AddLocalName (variable);
4613 $$ = new Arguments (0);
4621 Arguments args = new Arguments (4);
4622 args.Add ((Argument) $1);
4625 | pattern_list COMMA pattern_argument
4627 Arguments args = (Arguments) $1;
4628 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4629 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4631 args.Add ((Argument) $3);
4639 $$ = new Argument ((Expression) $1);
4641 | IDENTIFIER COLON pattern
4643 var lt = (LocatedToken) $1;
4644 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4649 : additive_expression
4650 | shift_expression OP_SHIFT_LEFT additive_expression
4652 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4653 lbag.AddLocation ($$, GetLocation ($2));
4655 | shift_expression OP_SHIFT_RIGHT additive_expression
4657 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4658 lbag.AddLocation ($$, GetLocation ($2));
4660 | shift_expression OP_SHIFT_LEFT error
4662 Error_SyntaxError (yyToken);
4664 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4665 lbag.AddLocation ($$, GetLocation ($2));
4667 | shift_expression OP_SHIFT_RIGHT error
4669 Error_SyntaxError (yyToken);
4671 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4672 lbag.AddLocation ($$, GetLocation ($2));
4676 relational_expression
4678 | relational_expression OP_LT shift_expression
4680 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4681 lbag.AddLocation ($$, GetLocation ($2));
4683 | relational_expression OP_GT shift_expression
4685 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4686 lbag.AddLocation ($$, GetLocation ($2));
4688 | relational_expression OP_LE shift_expression
4690 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4691 lbag.AddLocation ($$, GetLocation ($2));
4693 | relational_expression OP_GE shift_expression
4695 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4696 lbag.AddLocation ($$, GetLocation ($2));
4698 | relational_expression OP_LT error
4700 Error_SyntaxError (yyToken);
4702 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4703 lbag.AddLocation ($$, GetLocation ($2));
4705 | relational_expression OP_GT error
4707 Error_SyntaxError (yyToken);
4709 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4710 lbag.AddLocation ($$, GetLocation ($2));
4712 | relational_expression OP_LE error
4714 Error_SyntaxError (yyToken);
4716 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4717 lbag.AddLocation ($$, GetLocation ($2));
4719 | relational_expression OP_GE error
4721 Error_SyntaxError (yyToken);
4723 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4724 lbag.AddLocation ($$, GetLocation ($2));
4729 : relational_expression
4730 | equality_expression OP_EQ relational_expression
4732 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4733 lbag.AddLocation ($$, GetLocation ($2));
4735 | equality_expression OP_NE relational_expression
4737 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4738 lbag.AddLocation ($$, GetLocation ($2));
4740 | equality_expression OP_EQ error
4742 Error_SyntaxError (yyToken);
4744 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4745 lbag.AddLocation ($$, GetLocation ($2));
4747 | equality_expression OP_NE error
4749 Error_SyntaxError (yyToken);
4751 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4752 lbag.AddLocation ($$, GetLocation ($2));
4757 : equality_expression
4758 | and_expression BITWISE_AND equality_expression
4760 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4761 lbag.AddLocation ($$, GetLocation ($2));
4763 | and_expression BITWISE_AND error
4765 Error_SyntaxError (yyToken);
4767 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4768 lbag.AddLocation ($$, GetLocation ($2));
4772 exclusive_or_expression
4774 | exclusive_or_expression CARRET and_expression
4776 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4777 lbag.AddLocation ($$, GetLocation ($2));
4779 | exclusive_or_expression CARRET error
4781 Error_SyntaxError (yyToken);
4783 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4784 lbag.AddLocation ($$, GetLocation ($2));
4788 inclusive_or_expression
4789 : exclusive_or_expression
4790 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4792 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4793 lbag.AddLocation ($$, GetLocation ($2));
4795 | inclusive_or_expression BITWISE_OR error
4797 Error_SyntaxError (yyToken);
4799 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4800 lbag.AddLocation ($$, GetLocation ($2));
4804 conditional_and_expression
4805 : inclusive_or_expression
4806 | conditional_and_expression OP_AND inclusive_or_expression
4808 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4809 lbag.AddLocation ($$, GetLocation ($2));
4811 | conditional_and_expression OP_AND error
4813 Error_SyntaxError (yyToken);
4815 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4816 lbag.AddLocation ($$, GetLocation ($2));
4820 conditional_or_expression
4821 : conditional_and_expression
4822 | conditional_or_expression OP_OR conditional_and_expression
4824 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4825 lbag.AddLocation ($$, GetLocation ($2));
4827 | conditional_or_expression OP_OR error
4829 Error_SyntaxError (yyToken);
4831 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4832 lbag.AddLocation ($$, GetLocation ($2));
4836 null_coalescing_expression
4837 : conditional_or_expression
4838 | conditional_or_expression OP_COALESCING null_coalescing_expression
4840 if (lang_version < LanguageVersion.ISO_2)
4841 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4843 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4844 lbag.AddLocation ($$, GetLocation ($2));
4848 conditional_expression
4849 : null_coalescing_expression
4850 | null_coalescing_expression INTERR expression COLON expression
4852 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4853 lbag.AddLocation ($$, GetLocation ($4));
4855 | null_coalescing_expression INTERR expression COLON THROW prefixed_unary_expression
4857 if (lang_version < LanguageVersion.V_7)
4858 FeatureIsNotAvailable (lexer.Location, "throw expression");
4860 var expr = new ThrowExpression ((Expression) $6, GetLocation ($5));
4861 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, expr, GetLocation ($2));
4862 lbag.AddLocation ($$, GetLocation ($4));
4864 | null_coalescing_expression INTERR expression error
4866 Error_SyntaxError (yyToken);
4868 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4870 | null_coalescing_expression INTERR expression COLON error
4872 Error_SyntaxError (yyToken);
4874 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4875 lbag.AddLocation ($$, GetLocation ($4));
4877 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4879 Error_SyntaxError (Token.CLOSE_BRACE);
4881 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4882 lbag.AddLocation ($$, GetLocation ($4));
4883 lexer.putback ('}');
4887 assignment_expression
4888 : prefixed_unary_expression ASSIGN expression
4890 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4891 lbag.AddLocation ($$, GetLocation ($2));
4893 | prefixed_unary_expression OP_MULT_ASSIGN expression
4895 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4896 lbag.AddLocation ($$, GetLocation ($2));
4898 | prefixed_unary_expression OP_DIV_ASSIGN expression
4900 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4901 lbag.AddLocation ($$, GetLocation ($2));
4903 | prefixed_unary_expression OP_MOD_ASSIGN expression
4905 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4906 lbag.AddLocation ($$, GetLocation ($2));
4908 | prefixed_unary_expression OP_ADD_ASSIGN expression
4910 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4911 lbag.AddLocation ($$, GetLocation ($2));
4913 | prefixed_unary_expression OP_SUB_ASSIGN expression
4915 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4916 lbag.AddLocation ($$, GetLocation ($2));
4918 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4920 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4921 lbag.AddLocation ($$, GetLocation ($2));
4923 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4925 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4926 lbag.AddLocation ($$, GetLocation ($2));
4928 | prefixed_unary_expression OP_AND_ASSIGN expression
4930 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4931 lbag.AddLocation ($$, GetLocation ($2));
4933 | prefixed_unary_expression OP_OR_ASSIGN expression
4935 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4936 lbag.AddLocation ($$, GetLocation ($2));
4938 | prefixed_unary_expression OP_XOR_ASSIGN expression
4940 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4941 lbag.AddLocation ($$, GetLocation ($2));
4945 lambda_parameter_list
4948 var pars = new List<Parameter> (4);
4949 pars.Add ((Parameter) $1);
4953 | lambda_parameter_list COMMA lambda_parameter
4955 var pars = (List<Parameter>) $1;
4956 Parameter p = (Parameter)$3;
4957 if (pars[0].GetType () != p.GetType ()) {
4958 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4967 : parameter_modifier parameter_type identifier_inside_body
4969 var lt = (LocatedToken) $3;
4971 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4973 | parameter_type identifier_inside_body
4975 var lt = (LocatedToken) $2;
4977 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4981 var lt = (LocatedToken) $1;
4982 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4986 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4987 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4991 opt_lambda_parameter_list
4992 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4993 | lambda_parameter_list {
4994 var pars_list = (List<Parameter>) $1;
4995 $$ = new ParametersCompiled (pars_list.ToArray ());
4999 lambda_expression_body
5001 start_block (Location.Null);
5003 expression // All expressions must handle error or current block won't be restored and breaking ast completely
5005 Block b = end_block (Location.Null);
5006 b.IsCompilerGenerated = true;
5007 b.AddStatement (new ContextualReturn ((Expression) $2));
5013 // Handles only cases like foo = x.FirstOrDefault (l => );
5014 // where we must restore current_variable
5015 Block b = end_block (Location.Null);
5016 b.IsCompilerGenerated = true;
5018 Error_SyntaxError (yyToken);
5027 Error_SyntaxError (yyToken);
5035 var lt = (LocatedToken) $1;
5036 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5037 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5039 lambda_expression_body
5041 $$ = end_anonymous ((ParametersBlock) $4);
5042 lbag.AddLocation ($$, GetLocation ($2));
5046 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5047 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5048 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5050 lambda_expression_body
5052 $$ = end_anonymous ((ParametersBlock) $4);
5053 lbag.AddLocation ($$, GetLocation ($2));
5055 | ASYNC identifier_inside_body ARROW
5057 var lt = (LocatedToken) $2;
5058 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5059 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5061 lambda_expression_body
5063 $$ = end_anonymous ((ParametersBlock) $5);
5064 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5066 | OPEN_PARENS_LAMBDA
5068 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5070 opt_lambda_parameter_list CLOSE_PARENS ARROW
5072 valid_param_mod = 0;
5073 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5075 lambda_expression_body
5077 $$ = end_anonymous ((ParametersBlock) $7);
5078 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5080 | ASYNC OPEN_PARENS_LAMBDA
5082 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5084 opt_lambda_parameter_list CLOSE_PARENS ARROW
5086 valid_param_mod = 0;
5087 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5089 lambda_expression_body
5091 $$ = end_anonymous ((ParametersBlock) $8);
5092 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5097 : assignment_expression
5098 | non_assignment_expression
5101 non_assignment_expression
5102 : conditional_expression
5107 $$ = new ArglistAccess (GetLocation ($1));
5111 undocumented_expressions
5112 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5114 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5115 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5117 | REFTYPE open_parens_any expression CLOSE_PARENS
5119 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5120 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5122 | MAKEREF open_parens_any expression CLOSE_PARENS
5124 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5125 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5136 $$ = new BooleanExpression ((Expression) $1);
5140 opt_primary_parameters
5145 | primary_parameters
5149 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5153 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5154 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5156 if (lang_version != LanguageVersion.Experimental)
5157 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5161 opt_primary_parameters_with_class_base
5170 | primary_parameters
5174 | primary_parameters class_base
5178 | primary_parameters class_base OPEN_PARENS
5180 ++lexer.parsing_block;
5181 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5183 opt_argument_list CLOSE_PARENS
5185 lbag.AppendToMember (current_container, GetLocation ($6));
5186 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5187 --lexer.parsing_block;
5203 type_declaration_name
5205 lexer.ConstraintsParsing = true;
5207 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5208 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5209 FeatureIsNotAvailable (c.Location, "static classes");
5212 push_current_container (c, $3);
5213 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5215 opt_primary_parameters_with_class_base
5216 opt_type_parameter_constraints_clauses
5218 valid_param_mod = 0;
5219 lexer.ConstraintsParsing = false;
5222 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5225 current_container.SetConstraints ((List<Constraints>) $9);
5226 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5229 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5230 Lexer.doc_state = XmlCommentState.Allowed;
5233 lexer.parsing_modifiers = true;
5235 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5237 --lexer.parsing_declaration;
5239 Lexer.doc_state = XmlCommentState.Allowed;
5244 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5246 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5248 $$ = pop_current_class ();
5256 { $$ = $1; } // location
5262 mod_locations = null;
5264 lexer.parsing_modifiers = false;
5268 lexer.parsing_modifiers = false;
5274 | modifiers modifier
5276 var m1 = (Modifiers) $1;
5277 var m2 = (Modifiers) $2;
5279 if ((m1 & m2) != 0) {
5280 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5281 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5282 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5283 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5284 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5285 "More than one protection modifier specified");
5296 StoreModifierLocation ($$, GetLocation ($1));
5298 if (current_container.Kind == MemberKind.Namespace)
5299 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5303 $$ = Modifiers.PUBLIC;
5304 StoreModifierLocation ($$, GetLocation ($1));
5308 $$ = Modifiers.PROTECTED;
5309 StoreModifierLocation ($$, GetLocation ($1));
5313 $$ = Modifiers.INTERNAL;
5314 StoreModifierLocation ($$, GetLocation ($1));
5318 $$ = Modifiers.PRIVATE;
5319 StoreModifierLocation ($$, GetLocation ($1));
5323 $$ = Modifiers.ABSTRACT;
5324 StoreModifierLocation ($$, GetLocation ($1));
5328 $$ = Modifiers.SEALED;
5329 StoreModifierLocation ($$, GetLocation ($1));
5333 $$ = Modifiers.STATIC;
5334 StoreModifierLocation ($$, GetLocation ($1));
5338 $$ = Modifiers.READONLY;
5339 StoreModifierLocation ($$, GetLocation ($1));
5343 $$ = Modifiers.VIRTUAL;
5344 StoreModifierLocation ($$, GetLocation ($1));
5348 $$ = Modifiers.OVERRIDE;
5349 StoreModifierLocation ($$, GetLocation ($1));
5353 $$ = Modifiers.EXTERN;
5354 StoreModifierLocation ($$, GetLocation ($1));
5358 $$ = Modifiers.VOLATILE;
5359 StoreModifierLocation ($$, GetLocation ($1));
5363 $$ = Modifiers.UNSAFE;
5364 StoreModifierLocation ($$, GetLocation ($1));
5365 if (!settings.Unsafe)
5366 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5370 $$ = Modifiers.ASYNC;
5371 StoreModifierLocation ($$, GetLocation ($1));
5383 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5385 | COLON type_list error
5387 Error_SyntaxError (yyToken);
5389 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5393 opt_type_parameter_constraints_clauses
5395 | type_parameter_constraints_clauses
5401 type_parameter_constraints_clauses
5402 : type_parameter_constraints_clause
5404 var constraints = new List<Constraints> (1);
5405 constraints.Add ((Constraints) $1);
5408 | type_parameter_constraints_clauses type_parameter_constraints_clause
5410 var constraints = (List<Constraints>) $1;
5411 Constraints new_constraint = (Constraints)$2;
5413 foreach (Constraints c in constraints) {
5414 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5415 report.Error (409, new_constraint.Location,
5416 "A constraint clause has already been specified for type parameter `{0}'",
5417 new_constraint.TypeParameter.Value);
5421 constraints.Add (new_constraint);
5426 type_parameter_constraints_clause
5427 : WHERE IDENTIFIER COLON type_parameter_constraints
5429 var lt = (LocatedToken) $2;
5430 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5431 lbag.AddLocation ($$, GetLocation ($3));
5433 | WHERE IDENTIFIER error
5435 Error_SyntaxError (yyToken);
5437 var lt = (LocatedToken) $2;
5438 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5442 type_parameter_constraints
5443 : type_parameter_constraint
5445 var constraints = new List<FullNamedExpression> (1);
5446 constraints.Add ((FullNamedExpression) $1);
5449 | type_parameter_constraints COMMA type_parameter_constraint
5451 var constraints = (List<FullNamedExpression>) $1;
5452 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5453 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5454 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5457 prev = $3 as SpecialContraintExpr;
5459 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5460 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5462 prev = constraints [0] as SpecialContraintExpr;
5463 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5464 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5469 constraints.Add ((FullNamedExpression) $3);
5474 type_parameter_constraint
5477 if ($1 is ComposedCast)
5478 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5482 | NEW OPEN_PARENS CLOSE_PARENS
5484 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5485 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5489 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5493 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5497 opt_type_parameter_variance
5502 | type_parameter_variance
5504 if (lang_version <= LanguageVersion.V_3)
5505 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5511 type_parameter_variance
5514 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5518 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5527 // A block is "contained" on the following places:
5529 // property_declaration as part of the accessor body (get/set)
5530 // operator_declaration
5531 // constructor_declaration
5532 // destructor_declaration
5533 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5538 ++lexer.parsing_block;
5539 start_block (GetLocation ($1));
5541 opt_statement_list block_end
5550 --lexer.parsing_block;
5551 $$ = end_block (GetLocation ($1));
5553 | COMPLETE_COMPLETION
5555 --lexer.parsing_block;
5556 $$ = end_block (lexer.Location);
5564 ++lexer.parsing_block;
5565 current_block.StartLocation = GetLocation ($1);
5567 opt_statement_list CLOSE_BRACE
5569 --lexer.parsing_block;
5570 $$ = end_block (GetLocation ($4));
5581 | statement_list statement
5585 : block_variable_declaration
5587 current_block.AddStatement ((Statement) $1);
5589 | valid_declaration_statement
5591 current_block.AddStatement ((Statement) $1);
5596 Error_SyntaxError (yyToken);
5602 // The interactive_statement and its derivatives are only
5603 // used to provide a special version of `expression_statement'
5604 // that has a side effect of assigning the expression to
5607 interactive_statement_list
5608 : interactive_statement
5609 | interactive_statement_list interactive_statement
5612 interactive_statement
5613 : block_variable_declaration
5615 current_block.AddStatement ((Statement) $1);
5617 | interactive_valid_declaration_statement
5619 current_block.AddStatement ((Statement) $1);
5624 valid_declaration_statement
5627 | expression_statement
5628 | selection_statement
5629 | iteration_statement
5633 | unchecked_statement
5640 interactive_valid_declaration_statement
5643 | interactive_expression_statement
5644 | selection_statement
5645 | iteration_statement
5649 | unchecked_statement
5657 : valid_declaration_statement
5658 | block_variable_declaration
5660 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5665 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5670 Error_SyntaxError (yyToken);
5671 $$ = new EmptyStatement (GetLocation ($1));
5678 // Uses lexer.Location because semicolon location is not kept in quick mode
5679 $$ = new EmptyStatement (lexer.Location);
5684 : identifier_inside_body COLON
5686 var lt = (LocatedToken) $1;
5687 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5688 lbag.AddLocation (labeled, GetLocation ($2));
5689 current_block.AddLabel (labeled);
5690 current_block.AddStatement (labeled);
5696 : variable_type_simple
5697 | variable_type_simple rank_specifiers
5700 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5702 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5707 * The following is from Rhys' grammar:
5708 * > Types in local variable declarations must be recognized as
5709 * > expressions to prevent reduce/reduce errors in the grammar.
5710 * > The expressions are converted into types during semantic analysis.
5712 variable_type_simple
5713 : type_name_expression opt_nullable
5715 // Ok, the above "primary_expression" is there to get rid of
5716 // both reduce/reduce and shift/reduces in the grammar, it should
5717 // really just be "type_name". If you use type_name, a reduce/reduce
5718 // creeps up. If you use namespace_or_type_name (which is all we need
5719 // really) two shift/reduces appear.
5722 // So the super-trick is that primary_expression
5723 // can only be either a SimpleName or a MemberAccess.
5724 // The MemberAccess case arises when you have a fully qualified type-name like :
5726 // SimpleName is when you have
5729 var expr = (ATypeNameExpression) $1;
5731 if (expr.Name == "var" && expr is SimpleName)
5732 $$ = new VarExpr (expr.Location);
5736 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5739 | type_name_expression pointer_stars
5741 var expr = (ATypeNameExpression) $1;
5742 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5744 | builtin_type_expression
5750 | pointer_star pointer_stars
5752 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5760 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5764 identifier_inside_body
5768 $$ = Error_AwaitAsIdentifier ($1);
5772 block_variable_declaration
5773 : variable_type identifier_inside_body
5775 var lt = (LocatedToken) $2;
5776 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5777 current_block.AddLocalName (li);
5778 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5780 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5782 $$ = current_variable;
5783 current_variable = null;
5785 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5787 lbag.AddLocation ($$, GetLocation ($6));
5789 | CONST variable_type identifier_inside_body
5791 var lt = (LocatedToken) $3;
5792 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5793 current_block.AddLocalName (li);
5794 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5796 const_variable_initializer opt_const_declarators SEMICOLON
5798 $$ = current_variable;
5799 current_variable = null;
5800 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5804 opt_local_variable_initializer
5806 | ASSIGN block_variable_initializer
5808 current_variable.Initializer = (Expression) $2;
5809 PushLocation (GetLocation ($1));
5810 $$ = current_variable;
5814 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5815 report.Error (650, lexer.Location,
5816 "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");
5818 Error_SyntaxError (yyToken);
5823 opt_variable_declarators
5825 | variable_declarators
5828 opt_using_or_fixed_variable_declarators
5830 | variable_declarators
5832 foreach (var d in current_variable.Declarators) {
5833 if (d.Initializer == null)
5834 Error_MissingInitializer (d.Variable.Location);
5839 variable_declarators
5840 : variable_declarator
5841 | variable_declarators variable_declarator
5845 : COMMA identifier_inside_body
5847 var lt = (LocatedToken) $2;
5848 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5849 var d = new BlockVariableDeclarator (li, null);
5850 current_variable.AddDeclarator (d);
5851 current_block.AddLocalName (li);
5852 lbag.AddLocation (d, GetLocation ($1));
5854 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5856 var lt = (LocatedToken) $2;
5857 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5858 var d = new BlockVariableDeclarator (li, (Expression) $4);
5859 current_variable.AddDeclarator (d);
5860 current_block.AddLocalName (li);
5861 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5865 const_variable_initializer
5868 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5870 | ASSIGN constant_initializer_expr
5872 current_variable.Initializer = (Expression) $2;
5876 opt_const_declarators
5883 | const_declarators const_declarator
5887 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5889 var lt = (LocatedToken) $2;
5890 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5891 var d = new BlockVariableDeclarator (li, (Expression) $4);
5892 current_variable.AddDeclarator (d);
5893 current_block.AddLocalName (li);
5894 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5898 block_variable_initializer
5899 : variable_initializer
5900 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5902 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5903 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5905 | STACKALLOC simple_type
5907 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5908 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5912 expression_statement
5913 : statement_expression SEMICOLON
5916 lbag.AddStatement ($$, GetLocation ($2));
5918 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5919 | statement_expression CLOSE_BRACE
5922 report.Error (1002, GetLocation ($2), "; expected");
5923 lexer.putback ('}');
5927 interactive_expression_statement
5928 : interactive_statement_expression SEMICOLON { $$ = $1; }
5929 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5933 // We have to do the wrapping here and not in the case above,
5934 // because statement_expression is used for example in for_statement
5936 statement_expression
5939 ExpressionStatement s = $1 as ExpressionStatement;
5941 var expr = $1 as Expression;
5942 $$ = new StatementErrorExpression (expr);
5944 $$ = new StatementExpression (s);
5949 interactive_statement_expression
5952 Expression expr = (Expression) $1;
5953 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5957 Error_SyntaxError (yyToken);
5958 $$ = new EmptyStatement (GetLocation ($1));
5968 : IF open_parens_any boolean_expression CLOSE_PARENS
5971 if ($5 is EmptyStatement)
5972 Warning_EmptyStatement (GetLocation ($5));
5974 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5975 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5977 | IF open_parens_any boolean_expression CLOSE_PARENS
5978 embedded_statement ELSE embedded_statement
5980 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5981 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5983 if ($5 is EmptyStatement)
5984 Warning_EmptyStatement (GetLocation ($5));
5985 if ($7 is EmptyStatement)
5986 Warning_EmptyStatement (GetLocation ($7));
5988 | IF open_parens_any boolean_expression error
5990 Error_SyntaxError (yyToken);
5992 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5993 lbag.AddStatement ($$, GetLocation ($2));
5998 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
6000 start_block (GetLocation ($5));
6002 opt_switch_sections CLOSE_BRACE
6004 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
6005 end_block (GetLocation ($8));
6006 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6008 | SWITCH open_parens_any expression error
6010 Error_SyntaxError (yyToken);
6012 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
6013 lbag.AddStatement ($$, GetLocation ($2));
6020 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
6027 | switch_sections switch_section
6030 Error_SyntaxError (yyToken);
6035 : switch_labels statement_list
6041 var label = (SwitchLabel) $1;
6042 label.SectionStart = true;
6043 current_block.AddStatement (label);
6045 | switch_labels switch_label
6047 current_block.AddStatement ((Statement) $2);
6052 : CASE constant_expression COLON
6054 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6055 lbag.AddLocation ($$, GetLocation ($3));
6057 | CASE constant_expression error
6059 Error_SyntaxError (yyToken);
6060 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6063 | CASE pattern_expr_invocation COLON
6065 if (lang_version != LanguageVersion.Experimental)
6066 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6068 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6069 PatternMatching = true
6071 lbag.AddLocation ($$, GetLocation ($3));
6076 $$ = new SwitchLabel (null, GetLocation ($1));
6088 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6090 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6091 Warning_EmptyStatement (GetLocation ($5));
6093 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6094 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6096 | WHILE open_parens_any boolean_expression error
6098 Error_SyntaxError (yyToken);
6100 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6101 lbag.AddStatement ($$, GetLocation ($2));
6106 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6108 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6109 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6111 | DO embedded_statement error
6113 Error_SyntaxError (yyToken);
6114 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6116 | DO embedded_statement WHILE open_parens_any boolean_expression error
6118 Error_SyntaxError (yyToken);
6120 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6121 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6126 : FOR open_parens_any
6128 start_block (GetLocation ($2));
6129 current_block.IsCompilerGenerated = true;
6130 For f = new For (GetLocation ($1));
6131 current_block.AddStatement (f);
6140 // Has to use be extra rule to recover started block
6142 : opt_for_initializer SEMICOLON
6144 ((For) $0).Initializer = (Statement) $1;
6146 // Pass the "For" object to the iterator_part4
6147 oob_stack.Push ($0);
6149 for_condition_and_iterator_part
6152 var locations = (Tuple<Location,Location>) $4;
6154 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6155 Warning_EmptyStatement (GetLocation ($5));
6158 f.Statement = (Statement) $5;
6159 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6161 $$ = end_block (GetLocation ($2));
6165 Error_SyntaxError (yyToken);
6166 $$ = end_block (current_block.StartLocation);
6170 for_condition_and_iterator_part
6171 : opt_for_condition SEMICOLON
6173 For f = (For) oob_stack.Peek ();
6174 f.Condition = (BooleanExpression) $1;
6177 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6180 // Handle errors in the case of opt_for_condition being followed by
6181 // a close parenthesis
6182 | opt_for_condition close_parens_close_brace {
6183 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6184 For f = (For) oob_stack.Peek ();
6185 f.Condition = (BooleanExpression) $1;
6186 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6191 : opt_for_iterator CLOSE_PARENS {
6192 For f = (For) oob_stack.Peek ();
6193 f.Iterator = (Statement) $1;
6194 $$ = GetLocation ($2);
6196 | opt_for_iterator CLOSE_BRACE {
6197 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6198 For f = (For) oob_stack.Peek ();
6199 f.Iterator = (Statement) $1;
6200 $$ = GetLocation ($2);
6204 close_parens_close_brace
6206 | CLOSE_BRACE { lexer.putback ('}'); }
6210 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6215 : variable_type identifier_inside_body
6217 var lt = (LocatedToken) $2;
6218 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6219 current_block.AddLocalName (li);
6220 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6222 opt_local_variable_initializer opt_variable_declarators
6224 $$ = current_variable;
6226 lbag.AddLocation (current_variable, PopLocation ());
6228 current_variable = null;
6230 | statement_expression_list
6234 : /* empty */ { $$ = null; }
6235 | boolean_expression
6239 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6244 : statement_expression_list
6247 statement_expression_list
6248 : statement_expression
6249 | statement_expression_list COMMA statement_expression
6251 var sl = $1 as StatementList;
6253 sl = new StatementList ((Statement) $1, (Statement) $3);
6254 lbag.AddStatement (sl, GetLocation ($2));
6256 sl.Add ((Statement) $3);
6257 lbag.AppendTo (sl, GetLocation ($2));
6265 : FOREACH open_parens_any type error
6267 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6269 start_block (GetLocation ($2));
6270 current_block.IsCompilerGenerated = true;
6272 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6273 current_block.AddStatement (f);
6275 lbag.AddStatement (f, GetLocation ($2));
6276 $$ = end_block (GetLocation ($4));
6278 | FOREACH open_parens_any type identifier_inside_body error
6280 Error_SyntaxError (yyToken);
6282 start_block (GetLocation ($2));
6283 current_block.IsCompilerGenerated = true;
6285 var lt = (LocatedToken) $4;
6286 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6287 current_block.AddLocalName (li);
6289 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6290 current_block.AddStatement (f);
6292 lbag.AddStatement (f, GetLocation ($2));
6293 $$ = end_block (GetLocation ($5));
6295 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6297 start_block (GetLocation ($2));
6298 current_block.IsCompilerGenerated = true;
6300 var lt = (LocatedToken) $4;
6301 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6302 current_block.AddLocalName (li);
6307 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6308 Warning_EmptyStatement (GetLocation ($9));
6310 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6311 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6312 end_block (GetLocation ($7));
6320 | continue_statement
6330 $$ = new Break (GetLocation ($1));
6331 lbag.AddStatement ($$, GetLocation ($2));
6336 : CONTINUE SEMICOLON
6338 $$ = new Continue (GetLocation ($1));
6339 lbag.AddStatement ($$, GetLocation ($2));
6343 Error_SyntaxError (yyToken);
6344 $$ = new Continue (GetLocation ($1));
6349 : GOTO identifier_inside_body SEMICOLON
6351 var lt = (LocatedToken) $2;
6352 $$ = new Goto (lt.Value, GetLocation ($1));
6353 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6355 | GOTO CASE constant_expression SEMICOLON
6357 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6358 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6360 | GOTO DEFAULT SEMICOLON
6362 $$ = new GotoDefault (GetLocation ($1));
6363 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6368 : RETURN opt_expression SEMICOLON
6370 $$ = new Return ((Expression) $2, GetLocation ($1));
6371 lbag.AddStatement ($$, GetLocation ($3));
6373 | RETURN expression error
6375 Error_SyntaxError (yyToken);
6376 $$ = new Return ((Expression) $2, GetLocation ($1));
6380 Error_SyntaxError (yyToken);
6381 $$ = new Return (null, GetLocation ($1));
6386 : THROW expression SEMICOLON
6388 $$ = new Throw ((Expression) $2, GetLocation ($1));
6389 lbag.AddStatement ($$, GetLocation ($3));
6393 $$ = new Throw (null, GetLocation ($1));
6394 lbag.AddStatement ($$, GetLocation ($2));
6396 | THROW expression error
6398 Error_SyntaxError (yyToken);
6399 $$ = new Throw ((Expression) $2, GetLocation ($1));
6403 Error_SyntaxError (yyToken);
6404 $$ = new Throw (null, GetLocation ($1));
6409 : identifier_inside_body RETURN opt_expression SEMICOLON
6411 var lt = (LocatedToken) $1;
6412 string s = lt.Value;
6414 report.Error (1003, lt.Location, "; expected");
6415 } else if ($3 == null) {
6416 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6417 } else if (lang_version == LanguageVersion.ISO_1){
6418 FeatureIsNotAvailable (lt.Location, "iterators");
6421 current_block.Explicit.RegisterIteratorYield ();
6422 $$ = new Yield ((Expression) $3, lt.Location);
6423 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6425 | identifier_inside_body RETURN expression error
6427 Error_SyntaxError (yyToken);
6429 var lt = (LocatedToken) $1;
6430 string s = lt.Value;
6432 report.Error (1003, lt.Location, "; expected");
6433 } else if ($3 == null) {
6434 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6435 } else if (lang_version == LanguageVersion.ISO_1){
6436 FeatureIsNotAvailable (lt.Location, "iterators");
6439 current_block.Explicit.RegisterIteratorYield ();
6440 $$ = new Yield ((Expression) $3, lt.Location);
6441 lbag.AddStatement ($$, GetLocation ($2));
6443 | identifier_inside_body BREAK SEMICOLON
6445 var lt = (LocatedToken) $1;
6446 string s = lt.Value;
6448 report.Error (1003, lt.Location, "; expected");
6449 } else if (lang_version == LanguageVersion.ISO_1){
6450 FeatureIsNotAvailable (lt.Location, "iterators");
6453 current_block.ParametersBlock.TopBlock.IsIterator = true;
6454 $$ = new YieldBreak (lt.Location);
6455 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6465 : TRY block catch_clauses
6467 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6469 | TRY block FINALLY block
6471 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6472 lbag.AddStatement ($$, GetLocation ($3));
6474 | TRY block catch_clauses FINALLY block
6476 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6477 lbag.AddStatement ($$, GetLocation ($4));
6481 Error_SyntaxError (1524, yyToken);
6482 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6489 var l = new List<Catch> (2);
6494 | catch_clauses catch_clause
6496 var l = (List<Catch>) $1;
6498 Catch c = (Catch) $2;
6499 var prev_catch = l [l.Count - 1];
6500 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6501 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6511 | identifier_inside_body
6515 : CATCH opt_catch_filter block
6517 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6518 c.Filter = (CatchFilterExpression) $2;
6521 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6523 start_block (GetLocation ($2));
6524 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6525 c.TypeExpression = (FullNamedExpression) $3;
6528 var lt = (LocatedToken) $4;
6529 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6530 current_block.AddLocalName (c.Variable);
6533 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6535 lexer.parsing_catch_when = true;
6537 opt_catch_filter_or_error
6539 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6542 | CATCH open_parens_any error
6544 if (yyToken == Token.CLOSE_PARENS) {
6545 report.Error (1015, lexer.Location,
6546 "A type that derives from `System.Exception', `object', or `string' expected");
6548 Error_SyntaxError (yyToken);
6551 $$ = new Catch (null, GetLocation ($1));
6555 opt_catch_filter_or_error
6556 : opt_catch_filter block_prepared
6562 end_block (Location.Null);
6563 Error_SyntaxError (yyToken);
6570 lexer.parsing_catch_when = false;
6574 lexer.parsing_catch_when = false;
6576 open_parens_any expression CLOSE_PARENS
6578 if (lang_version <= LanguageVersion.V_5)
6579 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6581 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6582 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6589 $$ = new Checked ((Block) $2, GetLocation ($1));
6596 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6603 if (!settings.Unsafe)
6604 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6606 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6611 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6613 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6614 Warning_EmptyStatement (GetLocation ($5));
6616 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6617 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6619 | LOCK open_parens_any expression error
6621 Error_SyntaxError (yyToken);
6623 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6624 lbag.AddStatement ($$, GetLocation ($2));
6629 : FIXED open_parens_any variable_type identifier_inside_body
6631 start_block (GetLocation ($2));
6633 current_block.IsCompilerGenerated = true;
6634 var lt = (LocatedToken) $4;
6635 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6636 current_block.AddLocalName (li);
6637 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6639 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6641 $$ = current_variable;
6642 current_variable = null;
6646 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6647 Warning_EmptyStatement (GetLocation ($10));
6649 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6650 current_block.AddStatement (f);
6651 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6652 $$ = end_block (GetLocation ($8));
6657 : USING open_parens_any variable_type identifier_inside_body
6659 start_block (GetLocation ($2));
6661 current_block.IsCompilerGenerated = true;
6662 var lt = (LocatedToken) $4;
6663 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6664 current_block.AddLocalName (li);
6665 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6667 using_initialization CLOSE_PARENS
6669 $$ = current_variable;
6670 current_variable = null;
6674 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6675 Warning_EmptyStatement (GetLocation ($9));
6677 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6678 current_block.AddStatement (u);
6679 $$ = end_block (GetLocation ($7));
6681 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6683 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6684 Warning_EmptyStatement (GetLocation ($5));
6686 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6687 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6689 | USING open_parens_any expression error
6691 Error_SyntaxError (yyToken);
6693 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6694 lbag.AddStatement ($$, GetLocation ($2));
6698 using_initialization
6699 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6702 // It has to be here for the parent to safely restore artificial block
6703 Error_SyntaxError (yyToken);
6707 using_or_fixed_variable_initializer
6710 Error_MissingInitializer (lexer.Location);
6712 | ASSIGN variable_initializer
6714 current_variable.Initializer = (Expression) $2;
6715 $$ = current_variable;
6723 : first_from_clause query_body
6725 lexer.query_parsing = false;
6727 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6729 from.Tail.Next = (Linq.AQueryClause)$2;
6732 current_block.SetEndLocation (lexer.Location);
6733 current_block = current_block.Parent;
6735 | nested_from_clause query_body
6737 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6739 from.Tail.Next = (Linq.AQueryClause)$2;
6742 current_block.SetEndLocation (lexer.Location);
6743 current_block = current_block.Parent;
6746 // Bubble up COMPLETE_COMPLETION productions
6747 | first_from_clause COMPLETE_COMPLETION {
6748 lexer.query_parsing = false;
6751 current_block.SetEndLocation (lexer.Location);
6752 current_block = current_block.Parent;
6754 | nested_from_clause COMPLETE_COMPLETION {
6756 current_block.SetEndLocation (lexer.Location);
6757 current_block = current_block.Parent;
6762 : FROM_FIRST identifier_inside_body IN expression
6764 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6766 var lt = (LocatedToken) $2;
6767 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6768 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6769 lbag.AddLocation (clause, GetLocation ($3));
6770 $$ = new Linq.QueryExpression (clause);
6772 | FROM_FIRST type identifier_inside_body IN expression
6774 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6776 var lt = (LocatedToken) $3;
6777 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6778 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6779 IdentifierType = (FullNamedExpression)$2
6781 lbag.AddLocation (clause, GetLocation ($4));
6782 $$ = new Linq.QueryExpression (clause);
6787 : FROM identifier_inside_body IN expression
6789 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6791 var lt = (LocatedToken) $2;
6792 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6793 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6794 lbag.AddLocation (clause, GetLocation ($3));
6795 $$ = new Linq.QueryExpression (clause);
6797 | FROM type identifier_inside_body IN expression
6799 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6801 var lt = (LocatedToken) $3;
6802 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6803 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6804 IdentifierType = (FullNamedExpression)$2
6806 lbag.AddLocation (clause, GetLocation ($4));
6807 $$ = new Linq.QueryExpression (clause);
6812 : FROM identifier_inside_body IN
6814 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6818 var lt = (LocatedToken) $2;
6819 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6820 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6822 current_block.SetEndLocation (lexer.Location);
6823 current_block = current_block.Parent;
6825 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6826 lbag.AddLocation ($$, GetLocation ($3));
6828 | FROM type identifier_inside_body IN
6830 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6834 var lt = (LocatedToken) $3;
6835 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6837 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6838 IdentifierType = (FullNamedExpression)$2
6841 current_block.SetEndLocation (lexer.Location);
6842 current_block = current_block.Parent;
6844 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6846 lbag.AddLocation ($$, GetLocation ($4));
6851 : query_body_clauses select_or_group_clause opt_query_continuation
6853 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6856 head.Next = (Linq.AQueryClause)$3;
6859 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6860 clause.Tail.Next = head;
6866 | select_or_group_clause opt_query_continuation
6868 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6871 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6872 clause.Tail.Next = head;
6878 | query_body_clauses COMPLETE_COMPLETION
6879 | query_body_clauses error
6881 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6886 Error_SyntaxError (yyToken);
6891 select_or_group_clause
6894 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6898 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6900 current_block.SetEndLocation (lexer.Location);
6901 current_block = current_block.Parent;
6905 if (linq_clause_blocks == null)
6906 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6908 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6909 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6913 current_block.SetEndLocation (lexer.Location);
6914 current_block = current_block.Parent;
6916 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6920 var obj = (object[]) $5;
6922 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6923 lbag.AddLocation ($$, (Location) obj[1]);
6925 current_block.SetEndLocation (lexer.Location);
6926 current_block = current_block.Parent;
6931 : BY expression_or_error
6933 $$ = new object[] { $2, GetLocation ($1) };
6937 Error_SyntaxError (yyToken);
6938 $$ = new object[2] { null, Location.Null };
6944 | query_body_clauses query_body_clause
6946 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6960 : LET identifier_inside_body ASSIGN
6962 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6966 var lt = (LocatedToken) $2;
6967 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6968 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6969 lbag.AddLocation ($$, GetLocation ($3));
6971 current_block.SetEndLocation (lexer.Location);
6972 current_block = current_block.Parent;
6974 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6981 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6985 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6987 current_block.SetEndLocation (lexer.Location);
6988 current_block = current_block.Parent;
6993 : JOIN identifier_inside_body IN
6995 if (linq_clause_blocks == null)
6996 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6998 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6999 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7001 expression_or_error ON
7003 current_block.SetEndLocation (lexer.Location);
7004 current_block = current_block.Parent;
7006 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7007 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7009 expression_or_error EQUALS
7011 current_block.AddStatement (new ContextualReturn ((Expression) $8));
7012 current_block.SetEndLocation (lexer.Location);
7013 current_block = current_block.Parent;
7015 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7017 expression_or_error opt_join_into
7019 current_block.AddStatement (new ContextualReturn ((Expression) $11));
7020 current_block.SetEndLocation (lexer.Location);
7022 var outer_selector = linq_clause_blocks.Pop ();
7023 var block = linq_clause_blocks.Pop ();
7025 var lt = (LocatedToken) $2;
7026 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7027 Linq.RangeVariable into;
7031 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
7032 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7035 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7037 var parent = block.Parent;
7038 while (parent is Linq.QueryBlock) {
7039 parent = parent.Parent;
7041 current_block.Parent = parent;
7043 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7045 lt = (LocatedToken) $12;
7046 into = new Linq.RangeVariable (lt.Value, lt.Location);
7048 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7049 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7052 current_block = block.Parent;
7053 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7055 | JOIN type identifier_inside_body IN
7057 if (linq_clause_blocks == null)
7058 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7060 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7061 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7063 expression_or_error ON
7065 current_block.SetEndLocation (lexer.Location);
7066 current_block = current_block.Parent;
7068 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7069 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7071 expression_or_error EQUALS
7073 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7074 current_block.SetEndLocation (lexer.Location);
7075 current_block = current_block.Parent;
7077 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7079 expression_or_error opt_join_into
7081 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7082 current_block.SetEndLocation (lexer.Location);
7084 var outer_selector = linq_clause_blocks.Pop ();
7085 var block = linq_clause_blocks.Pop ();
7087 var lt = (LocatedToken) $3;
7088 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7089 Linq.RangeVariable into;
7093 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7094 IdentifierType = (FullNamedExpression)$2
7096 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7099 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7101 var parent = block.Parent;
7102 while (parent is Linq.QueryBlock) {
7103 parent = parent.Parent;
7105 current_block.Parent = parent;
7107 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7109 lt = (LocatedToken) $13;
7110 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7112 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7113 IdentifierType = (FullNamedExpression)$2
7117 current_block = block.Parent;
7118 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7124 | INTO identifier_inside_body
7133 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7137 current_block.SetEndLocation (lexer.Location);
7138 current_block = current_block.Parent;
7148 current_block.SetEndLocation (lexer.Location);
7149 current_block = current_block.Parent;
7151 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7155 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7162 | orderings_then_by COMMA
7164 current_block.SetEndLocation (lexer.Location);
7165 current_block = current_block.Parent;
7167 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7171 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7179 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7181 | expression ASCENDING
7183 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7184 lbag.AddLocation ($$, GetLocation ($2));
7186 | expression DESCENDING
7188 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7189 lbag.AddLocation ($$, GetLocation ($2));
7196 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7198 | expression ASCENDING
7200 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7201 lbag.AddLocation ($$, GetLocation ($2));
7203 | expression DESCENDING
7205 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7206 lbag.AddLocation ($$, GetLocation ($2));
7211 opt_query_continuation
7213 | INTO identifier_inside_body
7215 // query continuation block is not linked with query block but with block
7216 // before. This means each query can use same range variable names for
7217 // different identifiers.
7219 current_block.SetEndLocation (GetLocation ($1));
7220 current_block = current_block.Parent;
7222 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7224 if (linq_clause_blocks == null)
7225 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7227 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7231 var current_block = linq_clause_blocks.Pop ();
7232 var lt = (LocatedToken) $2;
7233 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7234 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7235 next = (Linq.AQueryClause)$4
7241 // Support for using the compiler as an interactive parser
7243 // The INTERACTIVE_PARSER token is first sent to parse our
7244 // productions; If the result is a Statement, the parsing
7245 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7246 // to setup the blocks in advance.
7248 // This setup is here so that in the future we can add
7249 // support for other constructs (type parsing, namespaces, etc)
7250 // that do not require a block to be setup in advance
7254 : EVAL_STATEMENT_PARSER EOF
7255 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7256 | EVAL_STATEMENT_PARSER
7258 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7260 // (ref object retval)
7261 Parameter [] mpar = new Parameter [1];
7262 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7264 ParametersCompiled pars = new ParametersCompiled (mpar);
7265 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7266 if (settings.Unsafe)
7267 mods |= Modifiers.UNSAFE;
7269 current_local_parameters = pars;
7270 var method = new InteractiveMethod (
7272 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7276 current_type.AddMember (method);
7277 oob_stack.Push (method);
7279 interactive_async = false;
7281 ++lexer.parsing_block;
7282 start_block (lexer.Location);
7284 interactive_statement_list opt_COMPLETE_COMPLETION
7286 --lexer.parsing_block;
7287 var method = (InteractiveMethod) oob_stack.Pop ();
7288 method.Block = (ToplevelBlock) end_block(lexer.Location);
7290 if (interactive_async == true) {
7291 method.ChangeToAsync ();
7294 InteractiveResult = (Class) pop_current_class ();
7295 current_local_parameters = null;
7297 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7300 interactive_compilation_unit
7301 : opt_extern_alias_directives opt_using_directives
7302 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7305 opt_COMPLETE_COMPLETION
7307 | COMPLETE_COMPLETION
7310 close_brace_or_complete_completion
7312 | COMPLETE_COMPLETION
7316 // XML documentation code references micro parser
7318 documentation_parsing
7321 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7326 : doc_type_declaration_name opt_doc_method_sig
7328 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7330 | builtin_types opt_doc_method_sig
7332 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7333 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7336 | VOID opt_doc_method_sig
7338 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7339 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7342 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7344 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7345 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7346 var lt = (LocatedToken) $3;
7347 $$ = new MemberName (lt.Value);
7349 | doc_type_declaration_name DOT THIS
7351 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7353 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7355 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7357 opt_doc_parameters CLOSE_BRACKET
7359 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7360 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7362 | EXPLICIT OPERATOR type opt_doc_method_sig
7364 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7365 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7366 module.DocumentationBuilder.ParsedParameters = p;
7367 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7370 | IMPLICIT OPERATOR type opt_doc_method_sig
7372 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7373 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7374 module.DocumentationBuilder.ParsedParameters = p;
7375 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7378 | OPERATOR overloadable_operator opt_doc_method_sig
7380 var p = (List<DocumentationParameter>)$3;
7381 module.DocumentationBuilder.ParsedParameters = p;
7382 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7387 doc_type_declaration_name
7388 : type_declaration_name
7389 | doc_type_declaration_name DOT type_declaration_name
7391 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7399 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7401 opt_doc_parameters CLOSE_PARENS
7410 $$ = new List<DocumentationParameter> (0);
7418 var parameters = new List<DocumentationParameter> ();
7419 parameters.Add ((DocumentationParameter) $1);
7422 | doc_parameters COMMA doc_parameter
7424 var parameters = $1 as List<DocumentationParameter>;
7425 parameters.Add ((DocumentationParameter) $3);
7431 : opt_parameter_modifier parameter_type
7434 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7436 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7443 // A class used to hold info about an operator declarator
7445 class OperatorDeclaration {
7446 public readonly Operator.OpType optype;
7447 public readonly FullNamedExpression ret_type;
7448 public readonly Location location;
7450 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7453 this.ret_type = ret_type;
7454 this.location = location;
7458 void Error_ExpectingTypeName (Expression expr)
7460 if (expr is Invocation){
7461 report.Error (1002, expr.Location, "Expecting `;'");
7463 expr.Error_InvalidExpressionStatement (report);
7467 void Error_ParameterModifierNotValid (string modifier, Location loc)
7469 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7473 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7475 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7476 Parameter.GetModifierSignature (mod));
7479 void Error_TypeExpected (Location loc)
7481 report.Error (1031, loc, "Type expected");
7484 void Error_UnsafeCodeNotAllowed (Location loc)
7486 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7489 void Warning_EmptyStatement (Location loc)
7491 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7494 void Error_NamedArgumentExpected (NamedArgument a)
7496 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7499 void Error_MissingInitializer (Location loc)
7501 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7504 object Error_AwaitAsIdentifier (object token)
7507 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7508 return new LocatedToken ("await", GetLocation (token));
7514 void push_current_container (TypeDefinition tc, object partial_token)
7516 if (module.Evaluator != null){
7517 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7521 undo.AddTypeContainer (current_container, tc);
7524 if (partial_token != null)
7525 current_container.AddPartial (tc);
7527 current_container.AddTypeContainer (tc);
7529 ++lexer.parsing_declaration;
7530 current_container = tc;
7534 TypeContainer pop_current_class ()
7536 var retval = current_container;
7538 current_container = current_container.Parent;
7539 current_type = current_type.Parent as TypeDefinition;
7544 [System.Diagnostics.Conditional ("FULL_AST")]
7545 void StoreModifierLocation (object token, Location loc)
7550 if (mod_locations == null)
7551 mod_locations = new List<Tuple<Modifiers, Location>> ();
7553 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7556 [System.Diagnostics.Conditional ("FULL_AST")]
7557 void PushLocation (Location loc)
7559 if (location_stack == null)
7560 location_stack = new Stack<Location> ();
7562 location_stack.Push (loc);
7565 Location PopLocation ()
7567 if (location_stack == null)
7568 return Location.Null;
7570 return location_stack.Pop ();
7573 string CheckAttributeTarget (int token, string a, Location l)
7576 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7580 if (!Tokenizer.IsValidIdentifier (a)) {
7581 Error_SyntaxError (token);
7583 report.Warning (658, 1, l,
7584 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7587 return string.Empty;
7590 static bool IsUnaryOperator (Operator.OpType op)
7594 case Operator.OpType.LogicalNot:
7595 case Operator.OpType.OnesComplement:
7596 case Operator.OpType.Increment:
7597 case Operator.OpType.Decrement:
7598 case Operator.OpType.True:
7599 case Operator.OpType.False:
7600 case Operator.OpType.UnaryPlus:
7601 case Operator.OpType.UnaryNegation:
7607 void syntax_error (Location l, string msg)
7609 report.Error (1003, l, "Syntax error, " + msg);
7614 public Tokenizer Lexer {
7620 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7621 : this (reader, file, file.Compiler.Report, session)
7625 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7628 current_container = current_namespace = file;
7630 this.module = file.Module;
7631 this.compiler = file.Compiler;
7632 this.settings = compiler.Settings;
7633 this.report = report;
7635 lang_version = settings.Version;
7636 yacc_verbose_flag = settings.VerboseParserFlag;
7637 doc_support = settings.DocumentationFile != null;
7638 lexer = new Tokenizer (reader, file, session, report);
7639 oob_stack = new Stack<object> ();
7640 lbag = session.LocationsBag;
7641 use_global_stacks = session.UseJayGlobalArrays;
7642 parameters_bucket = session.ParametersStack;
7645 public void parse ()
7647 eof_token = Token.EOF;
7650 if (yacc_verbose_flag > 1)
7651 yyparse (lexer, new yydebug.yyDebugSimple ());
7655 Tokenizer tokenizer = lexer as Tokenizer;
7656 tokenizer.cleanup ();
7657 } catch (Exception e){
7658 if (e is yyParser.yyUnexpectedEof) {
7659 Error_SyntaxError (yyToken);
7660 UnexpectedEOF = true;
7664 if (e is yyParser.yyException) {
7665 if (report.Errors == 0)
7666 report.Error (-25, lexer.Location, "Parsing error");
7668 // Used by compiler-tester to test internal errors
7669 if (yacc_verbose_flag > 0 || e is FatalException)
7672 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7677 void CheckToken (int error, int yyToken, string msg, Location loc)
7679 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7680 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7682 report.Error (error, loc, msg);
7685 string ConsumeStoredComment ()
7687 string s = tmpComment;
7689 Lexer.doc_state = XmlCommentState.Allowed;
7693 void FeatureIsNotAvailable (Location loc, string feature)
7695 report.FeatureIsNotAvailable (compiler, loc, feature);
7698 Location GetLocation (object obj)
7700 var lt = obj as LocatedToken;
7704 var mn = obj as MemberName;
7708 var expr = obj as Expression;
7710 return expr.Location;
7712 return lexer.Location;
7715 void start_block (Location loc)
7717 if (current_block == null) {
7718 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7719 parsing_anonymous_method = false;
7720 } else if (parsing_anonymous_method) {
7721 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7722 parsing_anonymous_method = false;
7724 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7729 end_block (Location loc)
7731 Block retval = current_block.Explicit;
7732 retval.SetEndLocation (loc);
7733 current_block = retval.Parent;
7737 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7739 oob_stack.Push (current_anonymous_method);
7740 oob_stack.Push (current_local_parameters);
7741 oob_stack.Push (current_variable);
7742 oob_stack.Push (async_block);
7744 current_local_parameters = parameters;
7746 if (lang_version <= LanguageVersion.ISO_2)
7747 FeatureIsNotAvailable (loc, "lambda expressions");
7749 current_anonymous_method = new LambdaExpression (loc);
7751 if (lang_version == LanguageVersion.ISO_1)
7752 FeatureIsNotAvailable (loc, "anonymous methods");
7754 current_anonymous_method = new AnonymousMethodExpression (loc);
7757 async_block = isAsync;
7758 // Force the next block to be created as a ToplevelBlock
7759 parsing_anonymous_method = true;
7763 * Completes the anonymous method processing, if lambda_expr is null, this
7764 * means that we have a Statement instead of an Expression embedded
7766 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7768 AnonymousMethodExpression retval;
7771 anon_block.IsAsync = true;
7773 current_anonymous_method.Block = anon_block;
7774 retval = current_anonymous_method;
7776 async_block = (bool) oob_stack.Pop ();
7777 current_variable = (BlockVariable) oob_stack.Pop ();
7778 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7779 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7784 void Error_SyntaxError (int token)
7786 Error_SyntaxError (0, token);
7789 void Error_SyntaxError (int error_code, int token)
7791 Error_SyntaxError (error_code, token, "Unexpected symbol");
7794 void Error_SyntaxError (int error_code, int token, string msg)
7796 Lexer.CompleteOnEOF = false;
7798 // An error message has been reported by tokenizer
7799 if (token == Token.ERROR)
7802 // Avoid duplicit error message after unterminated string literals
7803 if (token == Token.LITERAL && lexer.Location.Column == 0)
7806 string symbol = GetSymbolName (token);
7807 string expecting = GetExpecting ();
7808 var loc = lexer.Location - symbol.Length;
7810 if (error_code == 0) {
7811 if (expecting == "`identifier'") {
7812 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7813 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7818 expecting = "identifier";
7819 } else if (expecting == "`)'") {
7826 if (string.IsNullOrEmpty (expecting))
7827 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7829 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7832 string GetExpecting ()
7834 int [] tokens = yyExpectingTokens (yyExpectingState);
7835 var names = new List<string> (tokens.Length);
7836 bool has_type = false;
7837 bool has_identifier = false;
7838 for (int i = 0; i < tokens.Length; i++){
7839 int token = tokens [i];
7840 has_identifier |= token == Token.IDENTIFIER;
7842 string name = GetTokenName (token);
7843 if (name == "<internal>")
7846 has_type |= name == "type";
7847 if (names.Contains (name))
7854 // Too many tokens to enumerate
7856 if (names.Count > 8)
7859 if (has_type && has_identifier)
7860 names.Remove ("identifier");
7862 if (names.Count == 1)
7863 return "`" + GetTokenName (tokens [0]) + "'";
7865 StringBuilder sb = new StringBuilder ();
7867 int count = names.Count;
7868 for (int i = 0; i < count; i++){
7869 bool last = i + 1 == count;
7873 sb.Append (names [i]);
7874 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7876 return sb.ToString ();
7880 string GetSymbolName (int token)
7884 return ((Constant)lexer.Value).GetValue ().ToString ();
7885 case Token.IDENTIFIER:
7886 return ((LocatedToken)lexer.Value).Value;
7928 case Token.BITWISE_AND:
7930 case Token.BITWISE_OR:
7944 case Token.OP_SHIFT_LEFT:
7946 case Token.OP_SHIFT_RIGHT:
7966 case Token.OP_COALESCING:
7968 case Token.OP_MULT_ASSIGN:
7970 case Token.OP_DIV_ASSIGN:
7972 case Token.OP_MOD_ASSIGN:
7974 case Token.OP_ADD_ASSIGN:
7976 case Token.OP_SUB_ASSIGN:
7978 case Token.OP_SHIFT_LEFT_ASSIGN:
7980 case Token.OP_SHIFT_RIGHT_ASSIGN:
7982 case Token.OP_AND_ASSIGN:
7984 case Token.OP_XOR_ASSIGN:
7986 case Token.OP_OR_ASSIGN:
7990 return GetTokenName (token);
7993 static string GetTokenName (int token)
7996 case Token.ABSTRACT:
8018 case Token.CONTINUE:
8022 case Token.DELEGATE:
8032 case Token.EXPLICIT:
8035 case Token.EXTERN_ALIAS:
8051 case Token.IMPLICIT:
8055 case Token.INTERFACE:
8057 case Token.INTERNAL:
8063 case Token.NAMESPACE:
8069 case Token.OPERATOR:
8073 case Token.OVERRIDE:
8079 case Token.PROTECTED:
8083 case Token.READONLY:
8095 case Token.STACKALLOC:
8096 return "stackalloc";
8106 case Token.THROW_EXPR:
8114 case Token.UNCHECKED:
8122 case Token.VOLATILE:
8130 case Token.REFVALUE:
8131 return "__refvalue";
8141 case Token.FROM_FIRST:
8159 case Token.ASCENDING:
8161 case Token.DESCENDING:
8162 return "descending";
8169 case Token.OPEN_BRACE:
8171 case Token.CLOSE_BRACE:
8173 case Token.OPEN_BRACKET:
8174 case Token.OPEN_BRACKET_EXPR:
8176 case Token.CLOSE_BRACKET:
8178 case Token.OPEN_PARENS_CAST:
8179 case Token.OPEN_PARENS_LAMBDA:
8180 case Token.OPEN_PARENS:
8182 case Token.CLOSE_PARENS:
8188 case Token.DEFAULT_COLON:
8192 case Token.SEMICOLON:
8198 case Token.INTERPOLATED_STRING_END:
8200 case Token.INTERPOLATED_STRING:
8209 case Token.BITWISE_AND:
8210 case Token.BITWISE_OR:
8217 case Token.OP_SHIFT_LEFT:
8218 case Token.OP_SHIFT_RIGHT:
8226 case Token.OP_COALESCING:
8227 case Token.OP_MULT_ASSIGN:
8228 case Token.OP_DIV_ASSIGN:
8229 case Token.OP_MOD_ASSIGN:
8230 case Token.OP_ADD_ASSIGN:
8231 case Token.OP_SUB_ASSIGN:
8232 case Token.OP_SHIFT_LEFT_ASSIGN:
8233 case Token.OP_SHIFT_RIGHT_ASSIGN:
8234 case Token.OP_AND_ASSIGN:
8235 case Token.OP_XOR_ASSIGN:
8236 case Token.OP_OR_ASSIGN:
8237 case Token.INTERR_OPERATOR:
8238 return "<operator>";
8260 case Token.OP_GENERICS_LT:
8261 case Token.GENERIC_DIMENSION:
8263 case Token.OP_GENERICS_GT:
8266 case Token.INTERR_NULLABLE:
8268 case Token.DOUBLE_COLON:
8272 case Token.IDENTIFIER:
8274 return "identifier";
8277 return "end-of-file";
8279 // All of these are internal.
8282 case Token.FIRST_KEYWORD:
8283 case Token.EVAL_COMPILATION_UNIT_PARSER:
8284 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8285 case Token.EVAL_STATEMENT_PARSER:
8286 case Token.LAST_KEYWORD:
8287 case Token.GENERATE_COMPLETION:
8288 case Token.COMPLETE_COMPLETION:
8289 return "<internal>";
8291 // A bit more robust.
8293 return yyNames [token];