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 /* C# keywords which are not really keywords */
268 /* C# single character operators/punctuation. */
296 /* C# multi-character operators. */
301 %token OP_SHIFT_RIGHT
308 %token OP_MULT_ASSIGN
313 %token OP_SHIFT_LEFT_ASSIGN
314 %token OP_SHIFT_RIGHT_ASSIGN
321 /* Generics <,> tokens */
322 %token OP_GENERICS_LT
323 %token OP_GENERICS_LT_DECL
324 %token OP_GENERICS_GT
329 %token OPEN_PARENS_LAMBDA
330 %token OPEN_PARENS_CAST
331 %token GENERIC_DIMENSION
333 %token OPEN_BRACKET_EXPR
335 // Make the parser go into eval mode parsing (statements and compilation units).
336 %token EVAL_STATEMENT_PARSER
337 %token EVAL_COMPILATION_UNIT_PARSER
338 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
343 // This token is generated to trigger the completion engine at this point
345 %token GENERATE_COMPLETION
348 // This token is return repeatedly after the first GENERATE_COMPLETION
349 // token is produced and before the final EOF
351 %token COMPLETE_COMPLETION
353 /* Add precedence rules to solve dangling else s/r conflict */
357 /* Define the operator tokens and their precedences */
365 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
367 %left STAR DIV PERCENT
368 %right BANG CARRET UMINUS
369 %nonassoc OP_INC OP_DEC
371 %left OPEN_BRACKET OPEN_BRACE
374 %start compilation_unit
378 : outer_declaration opt_EOF
380 Lexer.check_incorrect_doc_comment ();
382 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
383 | documentation_parsing
387 : opt_extern_alias_directives opt_using_directives
388 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
391 Attributes attrs = (Attributes) $4;
392 report.Error (1730, attrs.Attrs [0].Location,
393 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
395 current_namespace.UnattachedAttributes = attrs;
398 | opt_extern_alias_directives opt_using_directives attribute_sections
400 module.AddAttributes ((Attributes) $3, current_namespace);
404 if (yyToken == Token.EXTERN_ALIAS)
405 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
407 Error_SyntaxError (yyToken);
416 extern_alias_directives
417 : extern_alias_directive
418 | extern_alias_directives extern_alias_directive
421 extern_alias_directive
422 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
424 var lt = (LocatedToken) $2;
427 syntax_error (lt.Location, "`alias' expected");
429 if (lang_version == LanguageVersion.ISO_1)
430 FeatureIsNotAvailable (lt.Location, "external alias");
432 lt = (LocatedToken) $3;
433 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
434 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
437 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
438 current_namespace.AddUsing (na);
440 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
445 Error_SyntaxError (yyToken);
451 | using_directives using_directive
458 Lexer.doc_state = XmlCommentState.Allowed;
463 : USING namespace_or_type_expr SEMICOLON
465 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
466 current_namespace.AddUsing (un);
468 lbag.AddLocation (un, GetLocation ($3));
470 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
472 var lt = (LocatedToken) $2;
473 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
474 report.Warning (440, 2, lt.Location,
475 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
478 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
479 current_namespace.AddUsing (un);
481 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
485 Error_SyntaxError (yyToken);
491 // Strictly speaking, namespaces don't have attributes but
492 // we parse global attributes along with namespace declarations and then
495 namespace_declaration
496 : opt_attributes NAMESPACE namespace_name
498 Attributes attrs = (Attributes) $1;
499 var name = (MemberName) $3;
501 bool valid_global_attrs = true;
502 if ((current_namespace.DeclarationFound || current_namespace != file)) {
503 valid_global_attrs = false;
505 foreach (var a in attrs.Attrs) {
506 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
509 valid_global_attrs = false;
514 if (!valid_global_attrs)
515 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
518 module.AddAttributes (attrs, current_namespace);
520 var ns = new NamespaceContainer (name, current_namespace);
521 current_namespace.AddTypeContainer (ns);
522 current_container = current_namespace = ns;
527 Lexer.doc_state = XmlCommentState.Allowed;
529 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
532 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
534 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
536 current_container = current_namespace = current_namespace.Parent;
538 | opt_attributes NAMESPACE namespace_name
540 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
542 var name = (MemberName) $3;
543 var ns = new NamespaceContainer (name, current_namespace);
544 lbag.AddLocation (ns, GetLocation ($2));
545 current_namespace.AddTypeContainer (ns);
554 Error_SyntaxError (yyToken);
562 var lt = (LocatedToken) $1;
563 $$ = new MemberName (lt.Value, lt.Location);
565 | namespace_name DOT IDENTIFIER
567 var lt = (LocatedToken) $3;
568 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
569 lbag.AddLocation ($$, GetLocation ($2));
573 Error_SyntaxError (yyToken);
574 $$ = new MemberName ("<invalid>", lexer.Location);
593 opt_extern_alias_directives
595 | extern_alias_directives
598 opt_namespace_or_type_declarations
600 | namespace_or_type_declarations
603 namespace_or_type_declarations
604 : namespace_or_type_declaration
605 | namespace_or_type_declarations namespace_or_type_declaration
608 namespace_or_type_declaration
612 TypeContainer ds = (TypeContainer)$1;
614 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
615 report.Error (1527, ds.Location,
616 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
619 // Here is a trick, for explicit attributes we don't know where they belong to until
620 // we parse succeeding declaration hence we parse them as normal and re-attach them
621 // when we know whether they are global (assembly:, module:) or local (type:).
622 if (ds.OptAttributes != null) {
623 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
626 current_namespace.DeclarationFound = true;
628 | namespace_declaration
630 current_namespace.DeclarationFound = true;
632 | attribute_sections CLOSE_BRACE {
633 current_namespace.UnattachedAttributes = (Attributes) $1;
634 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
642 | interface_declaration
644 | delegate_declaration
646 // Enable this when we have handled all errors, because this acts as a generic fallback
649 // Console.WriteLine ("Token=" + yyToken);
650 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
666 var sect = (List<Attribute>) $1;
667 $$ = new Attributes (sect);
669 | attribute_sections attribute_section
671 Attributes attrs = $1 as Attributes;
672 var sect = (List<Attribute>) $2;
674 attrs = new Attributes (sect);
675 else if (sect != null)
676 attrs.AddAttributes (sect);
684 PushLocation (GetLocation ($1));
685 lexer.parsing_attribute_section = true;
687 attribute_section_cont
689 lexer.parsing_attribute_section = false;
694 attribute_section_cont
695 : attribute_target COLON
697 current_attr_target = (string) $1;
698 if (current_attr_target == "assembly" || current_attr_target == "module") {
699 Lexer.check_incorrect_doc_comment ();
702 attribute_list opt_comma CLOSE_BRACKET
704 // when attribute target is invalid
705 if (current_attr_target == string.Empty)
706 $$ = new List<Attribute> (0);
710 lbag.InsertLocation ($$, 0, PopLocation ());
712 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
714 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
717 current_attr_target = null;
718 lexer.parsing_attribute_section = false;
720 | attribute_list opt_comma CLOSE_BRACKET
724 lbag.InsertLocation ($$, 0, PopLocation ());
726 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
728 lbag.AddLocation ($$, GetLocation($3));
733 Error_SyntaxError (yyToken);
735 var lt = (LocatedToken) $1;
736 var tne = new SimpleName (lt.Value, null, lt.Location);
738 $$ = new List<Attribute> () {
739 new Attribute (null, tne, null, GetLocation ($1), false)
744 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
745 Error_SyntaxError (yyToken);
754 var lt = (LocatedToken) $1;
755 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
757 | EVENT { $$ = "event"; }
758 | RETURN { $$ = "return"; }
764 $$ = new List<Attribute> (4) { (Attribute) $1 };
766 | attribute_list COMMA attribute
768 var attrs = (List<Attribute>) $1;
770 attrs.Add ((Attribute) $3);
771 lbag.AppendTo (attrs, GetLocation ($2));
781 ++lexer.parsing_block;
783 opt_attribute_arguments
785 --lexer.parsing_block;
787 var tne = (ATypeNameExpression) $1;
788 if (tne.HasTypeArguments) {
789 report.Error (404, tne.Location, "Attributes cannot be generic");
792 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
797 : namespace_or_type_expr
800 opt_attribute_arguments
801 : /* empty */ { $$ = null; }
802 | OPEN_PARENS attribute_arguments CLOSE_PARENS
810 : /* empty */ { $$ = null; }
811 | positional_or_named_argument
813 Arguments a = new Arguments (4);
814 a.Add ((Argument) $1);
815 $$ = new Arguments [] { a, null };
817 | named_attribute_argument
819 Arguments a = new Arguments (4);
820 a.Add ((Argument) $1);
821 $$ = new Arguments [] { null, a };
823 | attribute_arguments COMMA positional_or_named_argument
825 Arguments[] o = (Arguments[]) $1;
827 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
828 o [0] = new Arguments (4);
831 Arguments args = ((Arguments) o [0]);
832 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
833 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
835 args.Add ((Argument) $3);
837 | attribute_arguments COMMA named_attribute_argument
839 Arguments[] o = (Arguments[]) $1;
841 o [1] = new Arguments (4);
844 ((Arguments) o [1]).Add ((Argument) $3);
848 positional_or_named_argument
851 $$ = new Argument ((Expression) $1);
856 Error_SyntaxError (yyToken);
861 named_attribute_argument
864 ++lexer.parsing_block;
868 --lexer.parsing_block;
869 var lt = (LocatedToken) $1;
870 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
871 lbag.AddLocation ($$, GetLocation($2));
876 : identifier_inside_body COLON opt_named_modifier named_argument_expr
878 if (lang_version <= LanguageVersion.V_3)
879 FeatureIsNotAvailable (GetLocation ($1), "named argument");
881 // Avoid boxing in common case (no modifier)
882 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
884 var lt = (LocatedToken) $1;
885 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
886 lbag.AddLocation ($$, GetLocation($2));
891 : expression_or_error
892 | declaration_expression
896 : /* empty */ { $$ = null; }
899 $$ = Argument.AType.Ref;
903 $$ = Argument.AType.Out;
907 opt_class_member_declarations
909 | class_member_declarations
912 class_member_declarations
913 : class_member_declaration
915 lexer.parsing_modifiers = true;
916 lexer.parsing_block = 0;
918 | class_member_declarations class_member_declaration
920 lexer.parsing_modifiers = true;
921 lexer.parsing_block = 0;
925 class_member_declaration
926 : constant_declaration
929 | property_declaration
931 | indexer_declaration
932 | operator_declaration
933 | constructor_declaration
934 | primary_constructor_body
935 | destructor_declaration
937 | attributes_without_members
941 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
942 GetSymbolName (yyToken));
944 lexer.parsing_generic_declaration = false;
948 primary_constructor_body
951 current_local_parameters = current_type.PrimaryConstructorParameters;
952 if (current_local_parameters == null) {
953 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
954 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
957 ++lexer.parsing_block;
958 start_block (GetLocation ($1));
960 opt_statement_list block_end
962 current_local_parameters = null;
963 var t = current_type as ClassOrStruct;
965 var b = (ToplevelBlock) $4;
966 if (t.PrimaryConstructorBlock != null) {
967 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
969 t.PrimaryConstructorBlock = b;
982 type_declaration_name
984 lexer.ConstraintsParsing = true;
985 valid_param_mod = ParameterModifierType.PrimaryConstructor;
986 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
988 opt_primary_parameters
990 opt_type_parameter_constraints_clauses
993 lexer.ConstraintsParsing = false;
996 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
999 current_container.SetConstraints ((List<Constraints>) $10);
1002 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1004 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1006 lexer.parsing_modifiers = true;
1011 Lexer.doc_state = XmlCommentState.Allowed;
1013 opt_class_member_declarations CLOSE_BRACE
1015 --lexer.parsing_declaration;
1017 Lexer.doc_state = XmlCommentState.Allowed;
1022 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1024 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1026 $$ = pop_current_class ();
1028 | opt_attributes opt_modifiers opt_partial STRUCT error
1030 Error_SyntaxError (yyToken);
1034 constant_declaration
1037 CONST type IDENTIFIER
1039 var lt = (LocatedToken) $5;
1040 var mod = (Modifiers) $2;
1041 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1042 current_type.AddMember (current_field);
1044 if ((mod & Modifiers.STATIC) != 0) {
1045 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1050 constant_initializer opt_constant_declarators SEMICOLON
1053 current_field.DocComment = Lexer.consume_doc_comment ();
1054 Lexer.doc_state = XmlCommentState.Allowed;
1057 current_field.Initializer = (ConstInitializer) $7;
1058 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1059 current_field = null;
1065 Error_SyntaxError (yyToken);
1067 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1071 opt_constant_declarators
1073 | constant_declarators
1076 constant_declarators
1077 : constant_declarator
1079 current_field.AddDeclarator ((FieldDeclarator) $1);
1081 | constant_declarators constant_declarator
1083 current_field.AddDeclarator ((FieldDeclarator) $2);
1088 : COMMA IDENTIFIER constant_initializer
1090 var lt = (LocatedToken) $2;
1091 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1092 lbag.AddLocation ($$, GetLocation ($1));
1096 constant_initializer
1099 ++lexer.parsing_block;
1101 constant_initializer_expr
1103 --lexer.parsing_block;
1104 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1108 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1113 constant_initializer_expr
1114 : constant_expression
1121 member_type IDENTIFIER
1123 lexer.parsing_generic_declaration = false;
1125 FullNamedExpression type = (FullNamedExpression) $3;
1126 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1127 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1129 var lt = (LocatedToken) $4;
1130 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1131 current_type.AddField (current_field);
1134 opt_field_initializer
1135 opt_field_declarators
1139 current_field.DocComment = Lexer.consume_doc_comment ();
1140 Lexer.doc_state = XmlCommentState.Allowed;
1143 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1145 current_field = null;
1149 FIXED simple_type IDENTIFIER
1151 if (lang_version < LanguageVersion.ISO_2)
1152 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1154 var lt = (LocatedToken) $5;
1155 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1156 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1158 current_type.AddField (current_field);
1160 fixed_field_size opt_fixed_field_declarators SEMICOLON
1163 current_field.DocComment = Lexer.consume_doc_comment ();
1164 Lexer.doc_state = XmlCommentState.Allowed;
1167 current_field.Initializer = (ConstInitializer) $7;
1168 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1170 current_field = null;
1174 FIXED simple_type error
1177 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1181 opt_field_initializer
1185 ++lexer.parsing_block;
1186 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1187 start_block (GetLocation ($1));
1189 variable_initializer
1191 --lexer.parsing_block;
1192 current_field.Initializer = (Expression) $3;
1193 lbag.AppendToMember (current_field, GetLocation ($1));
1194 end_block (lexer.Location);
1195 current_local_parameters = null;
1199 opt_field_declarators
1207 current_field.AddDeclarator ((FieldDeclarator) $1);
1209 | field_declarators field_declarator
1211 current_field.AddDeclarator ((FieldDeclarator) $2);
1218 var lt = (LocatedToken) $2;
1219 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1220 lbag.AddLocation ($$, GetLocation ($1));
1222 | COMMA IDENTIFIER ASSIGN
1224 ++lexer.parsing_block;
1226 variable_initializer
1228 --lexer.parsing_block;
1229 var lt = (LocatedToken) $2;
1230 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1231 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1235 opt_fixed_field_declarators
1237 | fixed_field_declarators
1240 fixed_field_declarators
1241 : fixed_field_declarator
1243 current_field.AddDeclarator ((FieldDeclarator) $1);
1245 | fixed_field_declarators fixed_field_declarator
1247 current_field.AddDeclarator ((FieldDeclarator) $2);
1251 fixed_field_declarator
1252 : COMMA IDENTIFIER fixed_field_size
1254 var lt = (LocatedToken) $2;
1255 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1256 lbag.AddLocation ($$, GetLocation ($1));
1263 ++lexer.parsing_block;
1265 expression CLOSE_BRACKET
1267 --lexer.parsing_block;
1268 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1269 lbag.AddLocation ($$, GetLocation ($4));
1271 | OPEN_BRACKET error
1273 report.Error (443, lexer.Location, "Value or constant expected");
1278 variable_initializer
1283 // It has to be here for the parent to safely restore artificial block
1284 Error_SyntaxError (yyToken);
1293 Lexer.doc_state = XmlCommentState.NotAllowed;
1295 // Was added earlier in the case of body being eof for full ast
1297 method_body_expression_block
1299 Method method = (Method) $1;
1300 method.Block = (ToplevelBlock) $3;
1301 async_block = false;
1303 if (method.Block == null) {
1304 method.ParameterInfo.CheckParameters (method);
1306 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1307 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1308 method.GetSignatureForError ());
1311 if (current_container.Kind == MemberKind.Interface) {
1312 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1313 method.GetSignatureForError ());
1317 current_local_parameters = null;
1320 Lexer.doc_state = XmlCommentState.Allowed;
1328 method_declaration_name OPEN_PARENS
1330 valid_param_mod = ParameterModifierType.All;
1332 opt_formal_parameter_list CLOSE_PARENS
1334 valid_param_mod = 0;
1335 MemberName name = (MemberName) $4;
1336 current_local_parameters = (ParametersCompiled) $7;
1338 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1339 name, current_local_parameters, (Attributes) $1);
1341 current_type.AddMember (method);
1343 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1346 method.DocComment = Lexer.consume_doc_comment ();
1348 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1352 lexer.ConstraintsParsing = true;
1354 opt_type_parameter_constraints_clauses
1356 lexer.ConstraintsParsing = false;
1359 var method = (Method) $9;
1360 method.SetConstraints ((List<Constraints>) $10);
1370 lexer.parsing_generic_declaration = true;
1372 method_declaration_name
1375 lexer.parsing_generic_declaration = false;
1376 valid_param_mod = ParameterModifierType.All;
1378 opt_formal_parameter_list CLOSE_PARENS
1380 lexer.ConstraintsParsing = true;
1382 opt_type_parameter_constraints_clauses
1384 lexer.ConstraintsParsing = false;
1385 valid_param_mod = 0;
1387 MemberName name = (MemberName) $6;
1388 current_local_parameters = (ParametersCompiled) $9;
1390 var modifiers = (Modifiers) $2;
1391 modifiers |= Modifiers.PARTIAL;
1393 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1394 modifiers, name, current_local_parameters, (Attributes) $1);
1396 current_type.AddMember (method);
1398 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1401 method.SetConstraints ((List<Constraints>) $12);
1404 method.DocComment = Lexer.consume_doc_comment ();
1406 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1407 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1413 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1415 MemberName name = (MemberName) $5;
1416 report.Error (1585, name.Location,
1417 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1419 var method = Method.Create (current_type, (FullNamedExpression) $3,
1420 0, name, (ParametersCompiled) $7, (Attributes) $1);
1422 current_type.AddMember (method);
1424 current_local_parameters = (ParametersCompiled) $7;
1427 method.DocComment = Lexer.consume_doc_comment ();
1434 method_declaration_name error
1436 Error_SyntaxError (yyToken);
1437 current_local_parameters = ParametersCompiled.Undefined;
1439 MemberName name = (MemberName) $4;
1440 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1441 name, current_local_parameters, (Attributes) $1);
1443 current_type.AddMember (method);
1446 method.DocComment = Lexer.consume_doc_comment ();
1452 method_body_expression_block
1459 | SEMICOLON { $$ = null; }
1465 if (lang_version < LanguageVersion.V_6) {
1466 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1469 ++lexer.parsing_block;
1470 start_block (GetLocation ($1));
1472 expression SEMICOLON
1474 lexer.parsing_block = 0;
1475 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1476 var b = end_block (GetLocation ($4));
1477 b.IsCompilerGenerated = true;
1482 opt_formal_parameter_list
1483 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1484 | formal_parameter_list
1487 formal_parameter_list
1490 var pars_list = (List<Parameter>) $1;
1491 $$ = new ParametersCompiled (pars_list.ToArray ());
1493 | fixed_parameters COMMA parameter_array
1495 var pars_list = (List<Parameter>) $1;
1496 pars_list.Add ((Parameter) $3);
1498 $$ = new ParametersCompiled (pars_list.ToArray ());
1500 | fixed_parameters COMMA arglist_modifier
1502 var pars_list = (List<Parameter>) $1;
1503 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1504 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1506 | parameter_array COMMA error
1509 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1511 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1513 | fixed_parameters COMMA parameter_array COMMA error
1516 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1518 var pars_list = (List<Parameter>) $1;
1519 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1521 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1523 | arglist_modifier COMMA error
1525 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1527 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1529 | fixed_parameters COMMA ARGLIST COMMA error
1531 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1533 var pars_list = (List<Parameter>) $1;
1534 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1536 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1540 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1544 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1548 Error_SyntaxError (yyToken);
1549 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1556 parameters_bucket.Clear ();
1557 Parameter p = (Parameter) $1;
1558 parameters_bucket.Add (p);
1560 default_parameter_used = p.HasDefaultValue;
1561 $$ = parameters_bucket;
1563 | fixed_parameters COMMA fixed_parameter
1565 var pars = (List<Parameter>) $1;
1566 Parameter p = (Parameter) $3;
1568 if (p.HasExtensionMethodModifier)
1569 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1570 else if (!p.HasDefaultValue && default_parameter_used)
1571 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1573 default_parameter_used |= p.HasDefaultValue;
1576 lbag.AddLocation (p, GetLocation ($2));
1585 opt_parameter_modifier
1587 identifier_inside_body
1589 var lt = (LocatedToken) $4;
1590 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1593 opt_parameter_modifier
1595 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1597 var lt = (LocatedToken) $4;
1598 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1599 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1601 | attribute_sections error
1603 Error_SyntaxError (yyToken);
1604 Location l = GetLocation ($2);
1605 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1608 opt_parameter_modifier
1612 Error_SyntaxError (yyToken);
1613 Location l = GetLocation ($4);
1614 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1617 opt_parameter_modifier
1619 identifier_inside_body
1622 ++lexer.parsing_block;
1626 --lexer.parsing_block;
1627 if (lang_version <= LanguageVersion.V_3) {
1628 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1631 Parameter.Modifier mod = (Parameter.Modifier) $2;
1632 if (mod != Parameter.Modifier.NONE) {
1634 case Parameter.Modifier.REF:
1635 case Parameter.Modifier.OUT:
1636 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1637 Parameter.GetModifierSignature (mod));
1640 case Parameter.Modifier.This:
1641 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1642 Parameter.GetModifierSignature (mod));
1645 throw new NotImplementedException (mod.ToString ());
1648 mod = Parameter.Modifier.NONE;
1651 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1652 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1654 var lt = (LocatedToken) $4;
1655 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1656 lbag.AddLocation ($$, GetLocation ($5));
1659 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1663 opt_parameter_modifier
1664 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1665 | parameter_modifiers
1669 : parameter_modifier
1673 | parameter_modifiers parameter_modifier
1675 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1676 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1677 if (((Parameter.Modifier)$1 & p2) == p2) {
1678 Error_DuplicateParameterModifier (lexer.Location, p2);
1680 switch (mod & ~Parameter.Modifier.This) {
1681 case Parameter.Modifier.REF:
1682 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1684 case Parameter.Modifier.OUT:
1685 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1688 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1699 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1700 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1702 $$ = Parameter.Modifier.REF;
1706 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1707 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1709 $$ = Parameter.Modifier.OUT;
1713 if ((valid_param_mod & ParameterModifierType.This) == 0)
1714 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1716 if (lang_version <= LanguageVersion.ISO_2)
1717 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1719 $$ = Parameter.Modifier.This;
1724 : opt_attributes params_modifier type IDENTIFIER
1726 var lt = (LocatedToken) $4;
1727 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1729 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1731 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1733 var lt = (LocatedToken) $4;
1734 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1736 | opt_attributes params_modifier type error
1738 Error_SyntaxError (yyToken);
1740 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1747 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1748 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1750 | PARAMS parameter_modifier
1752 Parameter.Modifier mod = (Parameter.Modifier)$2;
1753 if ((mod & Parameter.Modifier.This) != 0) {
1754 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1756 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1759 | PARAMS params_modifier
1761 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1768 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1769 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1773 property_declaration
1777 member_declaration_name
1779 lexer.parsing_generic_declaration = false;
1781 tmpComment = Lexer.consume_doc_comment ();
1785 var type = (FullNamedExpression) $3;
1786 current_property = new Property (current_type, type, (Modifiers) $2,
1787 (MemberName) $4, (Attributes) $1);
1789 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1790 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1792 current_type.AddMember (current_property);
1793 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1795 lexer.PropertyParsing = true;
1797 accessor_declarations
1799 lexer.PropertyParsing = false;
1802 current_property.DocComment = ConsumeStoredComment ();
1806 lbag.AppendToMember (current_property, GetLocation ($10));
1807 lexer.parsing_modifiers = true;
1809 opt_property_initializer
1811 current_property = null;
1816 member_declaration_name
1818 lexer.parsing_generic_declaration = false;
1820 tmpComment = Lexer.consume_doc_comment ();
1821 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1825 var type = (FullNamedExpression) $3;
1826 var property = new Property (current_type, type, (Modifiers) $2,
1827 (MemberName) $4, (Attributes) $1);
1829 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1830 property.Get.Block = (ToplevelBlock) $6;
1832 if (current_container.Kind == MemberKind.Interface) {
1833 report.Error (531, property.Get.Block.StartLocation,
1834 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1837 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1838 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1840 current_type.AddMember (property);
1842 current_local_parameters = null;
1846 opt_property_initializer
1850 ++lexer.parsing_block;
1851 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1852 start_block (GetLocation ($1));
1854 property_initializer SEMICOLON
1856 --lexer.parsing_block;
1857 ((Property)current_property).Initializer = (Expression) $3;
1858 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1859 end_block (GetLocation ($4));
1860 current_local_parameters = null;
1864 property_initializer
1870 : opt_attributes opt_modifiers
1871 member_type indexer_declaration_name OPEN_BRACKET
1873 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1875 opt_formal_parameter_list CLOSE_BRACKET
1877 valid_param_mod = 0;
1878 var type = (FullNamedExpression) $3;
1879 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1881 current_property = indexer;
1883 current_type.AddIndexer (indexer);
1884 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1886 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1887 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1889 if (indexer.ParameterInfo.IsEmpty) {
1890 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1894 tmpComment = Lexer.consume_doc_comment ();
1895 Lexer.doc_state = XmlCommentState.Allowed;
1898 lexer.PropertyParsing = true;
1899 current_local_parameters = (ParametersCompiled) $7;
1903 lexer.PropertyParsing = false;
1904 current_local_parameters = null;
1906 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1907 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1910 current_property.DocComment = ConsumeStoredComment ();
1912 current_property = null;
1917 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1919 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1923 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1924 current_property.Get.Block = (ToplevelBlock) $1;
1928 accessor_declarations
1929 : get_accessor_declaration
1930 | get_accessor_declaration accessor_declarations
1931 | set_accessor_declaration
1932 | set_accessor_declaration accessor_declarations
1935 if (yyToken == Token.CLOSE_BRACE) {
1936 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1938 if (yyToken == Token.SEMICOLON)
1939 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1941 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1946 get_accessor_declaration
1947 : opt_attributes opt_modifiers GET
1949 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1950 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1953 if (current_property.Get != null) {
1954 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1957 if (current_property is Indexer) {
1958 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1959 (Attributes) $1, GetLocation ($3));
1961 current_property.Get = new Property.GetMethod (current_property,
1962 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1965 current_local_parameters = current_property.Get.ParameterInfo;
1966 lbag.AddMember (current_property.Get, mod_locations);
1967 lexer.PropertyParsing = false;
1972 current_property.Get.Block = (ToplevelBlock) $5;
1974 if (current_container.Kind == MemberKind.Interface) {
1975 report.Error (531, current_property.Get.Block.StartLocation,
1976 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1980 current_local_parameters = null;
1981 lexer.PropertyParsing = true;
1984 if (Lexer.doc_state == XmlCommentState.Error)
1985 Lexer.doc_state = XmlCommentState.NotAllowed;
1989 set_accessor_declaration
1990 : opt_attributes opt_modifiers SET
1992 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1993 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1996 if (current_property.Set != null) {
1997 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2000 if (current_property is Indexer) {
2001 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2002 ParametersCompiled.MergeGenerated (compiler,
2003 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2004 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2006 (Attributes) $1, GetLocation ($3));
2008 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2009 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2010 (Attributes) $1, GetLocation ($3));
2013 current_local_parameters = current_property.Set.ParameterInfo;
2014 lbag.AddMember (current_property.Set, mod_locations);
2015 lexer.PropertyParsing = false;
2020 current_property.Set.Block = (ToplevelBlock) $5;
2022 if (current_container.Kind == MemberKind.Interface) {
2023 report.Error (531, current_property.Set.Block.StartLocation,
2024 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2028 current_local_parameters = null;
2029 lexer.PropertyParsing = true;
2032 && Lexer.doc_state == XmlCommentState.Error)
2033 Lexer.doc_state = XmlCommentState.NotAllowed;
2046 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2051 interface_declaration
2058 type_declaration_name
2060 lexer.ConstraintsParsing = true;
2061 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2062 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2065 opt_type_parameter_constraints_clauses
2067 lexer.ConstraintsParsing = false;
2070 current_container.SetConstraints ((List<Constraints>) $9);
2073 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2074 Lexer.doc_state = XmlCommentState.Allowed;
2077 lexer.parsing_modifiers = true;
2079 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2081 --lexer.parsing_declaration;
2083 Lexer.doc_state = XmlCommentState.Allowed;
2088 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2090 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2092 $$ = pop_current_class ();
2094 | opt_attributes opt_modifiers opt_partial INTERFACE error
2096 Error_SyntaxError (yyToken);
2100 opt_interface_member_declarations
2102 | interface_member_declarations
2105 interface_member_declarations
2106 : interface_member_declaration
2108 lexer.parsing_modifiers = true;
2109 lexer.parsing_block = 0;
2111 | interface_member_declarations interface_member_declaration
2113 lexer.parsing_modifiers = true;
2114 lexer.parsing_block = 0;
2118 interface_member_declaration
2119 : constant_declaration
2121 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2125 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2127 | method_declaration
2128 | property_declaration
2130 | indexer_declaration
2131 | operator_declaration
2133 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2135 | constructor_declaration
2137 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2141 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2145 operator_declaration
2146 : opt_attributes opt_modifiers operator_declarator
2149 method_body_expression_block
2151 OperatorDeclaration decl = (OperatorDeclaration) $3;
2153 Operator op = new Operator (
2154 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2155 current_local_parameters,
2156 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2158 if (op.Block == null)
2159 op.ParameterInfo.CheckParameters (op);
2162 op.DocComment = tmpComment;
2163 Lexer.doc_state = XmlCommentState.Allowed;
2166 // Note again, checking is done in semantic analysis
2167 current_type.AddOperator (op);
2169 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2172 current_local_parameters = null;
2177 : type_expression_or_array
2180 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2181 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2186 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2188 valid_param_mod = ParameterModifierType.DefaultValue;
2189 if ((Operator.OpType) $3 == Operator.OpType.Is)
2190 valid_param_mod |= ParameterModifierType.Out;
2192 opt_formal_parameter_list CLOSE_PARENS
2194 valid_param_mod = 0;
2196 Location loc = GetLocation ($2);
2197 Operator.OpType op = (Operator.OpType) $3;
2198 current_local_parameters = (ParametersCompiled)$6;
2200 int p_count = current_local_parameters.Count;
2202 if (op == Operator.OpType.Addition)
2203 op = Operator.OpType.UnaryPlus;
2204 else if (op == Operator.OpType.Subtraction)
2205 op = Operator.OpType.UnaryNegation;
2208 if (IsUnaryOperator (op)) {
2210 report.Error (1020, loc, "Overloadable binary operator expected");
2211 } else if (p_count != 1) {
2212 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2213 Operator.GetName (op));
2215 } else if (op == Operator.OpType.Is) {
2216 // TODO: Special checks for is operator
2219 report.Error (1019, loc, "Overloadable unary operator expected");
2220 } else if (p_count != 2) {
2221 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2222 Operator.GetName (op));
2227 tmpComment = Lexer.consume_doc_comment ();
2228 Lexer.doc_state = XmlCommentState.NotAllowed;
2231 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2232 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2234 | conversion_operator_declarator
2237 overloadable_operator
2239 : BANG { $$ = Operator.OpType.LogicalNot; }
2240 | TILDE { $$ = Operator.OpType.OnesComplement; }
2241 | OP_INC { $$ = Operator.OpType.Increment; }
2242 | OP_DEC { $$ = Operator.OpType.Decrement; }
2243 | TRUE { $$ = Operator.OpType.True; }
2244 | FALSE { $$ = Operator.OpType.False; }
2245 // Unary and binary:
2246 | PLUS { $$ = Operator.OpType.Addition; }
2247 | MINUS { $$ = Operator.OpType.Subtraction; }
2249 | STAR { $$ = Operator.OpType.Multiply; }
2250 | DIV { $$ = Operator.OpType.Division; }
2251 | PERCENT { $$ = Operator.OpType.Modulus; }
2252 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2253 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2254 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2255 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2256 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2257 | OP_EQ { $$ = Operator.OpType.Equality; }
2258 | OP_NE { $$ = Operator.OpType.Inequality; }
2259 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2260 | OP_LT { $$ = Operator.OpType.LessThan; }
2261 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2262 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2265 if (lang_version != LanguageVersion.Experimental)
2266 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2268 $$ = Operator.OpType.Is;
2272 conversion_operator_declarator
2273 : IMPLICIT OPERATOR type OPEN_PARENS
2275 valid_param_mod = ParameterModifierType.DefaultValue;
2277 opt_formal_parameter_list CLOSE_PARENS
2279 valid_param_mod = 0;
2281 Location loc = GetLocation ($2);
2282 current_local_parameters = (ParametersCompiled)$6;
2284 if (current_local_parameters.Count != 1) {
2285 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2289 tmpComment = Lexer.consume_doc_comment ();
2290 Lexer.doc_state = XmlCommentState.NotAllowed;
2293 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2294 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2296 | EXPLICIT OPERATOR type OPEN_PARENS
2298 valid_param_mod = ParameterModifierType.DefaultValue;
2300 opt_formal_parameter_list CLOSE_PARENS
2302 valid_param_mod = 0;
2304 Location loc = GetLocation ($2);
2305 current_local_parameters = (ParametersCompiled)$6;
2307 if (current_local_parameters.Count != 1) {
2308 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2312 tmpComment = Lexer.consume_doc_comment ();
2313 Lexer.doc_state = XmlCommentState.NotAllowed;
2316 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2317 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2321 Error_SyntaxError (yyToken);
2322 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2323 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2327 Error_SyntaxError (yyToken);
2328 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2329 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2333 constructor_declaration
2334 : constructor_declarator
2337 Constructor c = (Constructor) $1;
2338 c.Block = (ToplevelBlock) $2;
2341 c.DocComment = ConsumeStoredComment ();
2343 current_local_parameters = null;
2345 Lexer.doc_state = XmlCommentState.Allowed;
2349 constructor_declarator
2355 tmpComment = Lexer.consume_doc_comment ();
2356 Lexer.doc_state = XmlCommentState.Allowed;
2359 valid_param_mod = ParameterModifierType.All;
2361 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2363 valid_param_mod = 0;
2364 current_local_parameters = (ParametersCompiled) $6;
2366 var lt = (LocatedToken) $3;
2367 var mods = (Modifiers) $2;
2368 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2370 if (lt.Value != current_container.MemberName.Name) {
2371 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2372 } else if ((mods & Modifiers.STATIC) != 0) {
2373 if (!current_local_parameters.IsEmpty) {
2374 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2375 c.GetSignatureForError ());
2378 if ((mods & Modifiers.AccessibilityMask) != 0){
2379 report.Error (515, c.Location,
2380 "`{0}': static constructor cannot have an access modifier",
2381 c.GetSignatureForError ());
2384 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2385 if (lang_version < LanguageVersion.V_6)
2386 FeatureIsNotAvailable (GetLocation ($3), "struct parameterless instance constructor");
2388 if ((mods & Modifiers.PUBLIC) == 0) {
2389 report.Error (8075, c.Location, "`{0}': Structs parameterless instance constructor must be public", c.GetSignatureForError ());
2394 current_type.AddConstructor (c);
2395 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2399 // start block here, so possible anonymous methods inside
2400 // constructor initializer can get correct parent block
2402 start_block (lexer.Location);
2404 opt_constructor_initializer
2407 var c = (Constructor) $8;
2408 c.Initializer = (ConstructorInitializer) $9;
2411 report.Error (514, c.Location,
2412 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2413 c.GetSignatureForError ());
2423 | SEMICOLON { current_block = null; $$ = null; }
2426 opt_constructor_initializer
2428 | constructor_initializer
2431 constructor_initializer
2432 : COLON BASE OPEN_PARENS
2434 ++lexer.parsing_block;
2436 opt_argument_list CLOSE_PARENS
2438 --lexer.parsing_block;
2439 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2440 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2442 | COLON THIS OPEN_PARENS
2444 ++lexer.parsing_block;
2446 opt_argument_list CLOSE_PARENS
2448 --lexer.parsing_block;
2449 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2450 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2454 Error_SyntaxError (yyToken);
2455 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2456 lbag.AddLocation ($$, GetLocation ($1));
2460 Error_SyntaxError (yyToken);
2465 destructor_declaration
2466 : opt_attributes opt_modifiers TILDE
2469 tmpComment = Lexer.consume_doc_comment ();
2470 Lexer.doc_state = XmlCommentState.NotAllowed;
2473 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2475 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2477 var lt = (LocatedToken) $5;
2478 if (lt.Value != current_container.MemberName.Name){
2479 report.Error (574, lt.Location, "Name of destructor must match name of class");
2480 } else if (current_container.Kind != MemberKind.Class){
2481 report.Error (575, lt.Location, "Only class types can contain destructor");
2484 Destructor d = new Destructor (current_type, (Modifiers) $2,
2485 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2487 d.DocComment = ConsumeStoredComment ();
2489 d.Block = (ToplevelBlock) $8;
2490 current_type.AddMember (d);
2491 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2493 current_local_parameters = null;
2500 EVENT type member_declaration_name
2502 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2503 current_type.AddMember (current_event_field);
2505 if (current_event_field.MemberName.ExplicitInterface != null) {
2506 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2507 current_event_field.GetSignatureForError ());
2510 $$ = current_event_field;
2512 opt_event_initializer
2513 opt_event_declarators
2517 current_event_field.DocComment = Lexer.consume_doc_comment ();
2518 Lexer.doc_state = XmlCommentState.Allowed;
2521 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2522 current_event_field = null;
2526 EVENT type member_declaration_name
2529 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2530 current_type.AddMember (current_event);
2531 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2533 lexer.EventParsing = true;
2535 event_accessor_declarations
2537 if (current_container.Kind == MemberKind.Interface)
2538 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2540 lexer.EventParsing = false;
2545 current_event.DocComment = Lexer.consume_doc_comment ();
2546 Lexer.doc_state = XmlCommentState.Allowed;
2549 lbag.AppendToMember (current_event, GetLocation ($9));
2550 current_event = null;
2551 current_local_parameters = null;
2557 Error_SyntaxError (yyToken);
2559 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2563 opt_event_initializer
2567 ++lexer.parsing_block;
2569 event_variable_initializer
2571 --lexer.parsing_block;
2572 current_event_field.Initializer = (Expression) $3;
2576 opt_event_declarators
2584 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2586 | event_declarators event_declarator
2588 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2595 var lt = (LocatedToken) $2;
2596 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2597 lbag.AddLocation ($$, GetLocation ($1));
2599 | COMMA IDENTIFIER ASSIGN
2601 ++lexer.parsing_block;
2603 event_variable_initializer
2605 --lexer.parsing_block;
2606 var lt = (LocatedToken) $2;
2607 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2608 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2612 event_variable_initializer
2614 if (current_container.Kind == MemberKind.Interface) {
2615 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2616 current_event_field.GetSignatureForError ());
2619 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2620 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2621 current_event_field.GetSignatureForError ());
2624 variable_initializer
2630 event_accessor_declarations
2631 : add_accessor_declaration remove_accessor_declaration
2632 | remove_accessor_declaration add_accessor_declaration
2633 | add_accessor_declaration
2635 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2636 current_event.GetSignatureForError ());
2638 | remove_accessor_declaration
2640 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2641 current_event.GetSignatureForError ());
2645 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2650 add_accessor_declaration
2651 : opt_attributes opt_modifiers ADD
2653 if ($2 != ModifierNone) {
2654 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2657 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2658 current_local_parameters = current_event.Add.ParameterInfo;
2660 lbag.AddMember (current_event.Add, mod_locations);
2661 lexer.EventParsing = false;
2663 event_accessor_block
2665 lexer.EventParsing = true;
2667 current_event.Add.Block = (ToplevelBlock) $5;
2669 if (current_container.Kind == MemberKind.Interface) {
2670 report.Error (531, current_event.Add.Block.StartLocation,
2671 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2674 current_local_parameters = null;
2678 remove_accessor_declaration
2679 : opt_attributes opt_modifiers REMOVE
2681 if ($2 != ModifierNone) {
2682 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2685 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2686 current_local_parameters = current_event.Remove.ParameterInfo;
2688 lbag.AddMember (current_event.Remove, mod_locations);
2689 lexer.EventParsing = false;
2691 event_accessor_block
2693 lexer.EventParsing = true;
2695 current_event.Remove.Block = (ToplevelBlock) $5;
2697 if (current_container.Kind == MemberKind.Interface) {
2698 report.Error (531, current_event.Remove.Block.StartLocation,
2699 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2702 current_local_parameters = null;
2706 event_accessor_block
2709 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2715 attributes_without_members
2716 : attribute_sections CLOSE_BRACE
2718 current_type.UnattachedAttributes = (Attributes) $1;
2719 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2720 lexer.putback ('}');
2724 // For full ast try to recover incomplete ambiguous member
2725 // declaration in form on class X { public int }
2727 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2729 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2731 lexer.putback ('}');
2733 lexer.parsing_generic_declaration = false;
2734 FullNamedExpression type = (FullNamedExpression) $3;
2735 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2736 current_type.AddField (current_field);
2744 ENUM type_declaration_name
2748 enumTypeComment = Lexer.consume_doc_comment ();
2753 Lexer.doc_state = XmlCommentState.Allowed;
2755 MemberName name = (MemberName) $4;
2756 if (name.IsGeneric) {
2757 report.Error (1675, name.Location, "Enums cannot have type parameters");
2760 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2762 opt_enum_member_declarations
2764 lexer.parsing_modifiers = true;
2766 // here will be evaluated after CLOSE_BLACE is consumed.
2768 Lexer.doc_state = XmlCommentState.Allowed;
2770 CLOSE_BRACE opt_semicolon
2773 current_container.DocComment = enumTypeComment;
2775 --lexer.parsing_declaration;
2778 // em.DocComment = ev.DocComment;
2780 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2781 $$ = pop_current_class ();
2793 Error_TypeExpected (GetLocation ($1));
2798 opt_enum_member_declarations
2800 | enum_member_declarations
2801 | enum_member_declarations COMMA
2803 lbag.AddLocation ($1, GetLocation ($2));
2807 enum_member_declarations
2808 : enum_member_declaration
2809 | enum_member_declarations COMMA enum_member_declaration
2811 lbag.AddLocation ($1, GetLocation ($2));
2816 enum_member_declaration
2817 : opt_attributes IDENTIFIER
2819 var lt = (LocatedToken) $2;
2820 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2821 ((Enum) current_type).AddEnumMember (em);
2824 em.DocComment = Lexer.consume_doc_comment ();
2825 Lexer.doc_state = XmlCommentState.Allowed;
2830 | opt_attributes IDENTIFIER
2832 ++lexer.parsing_block;
2834 tmpComment = Lexer.consume_doc_comment ();
2835 Lexer.doc_state = XmlCommentState.NotAllowed;
2838 ASSIGN constant_expression
2840 --lexer.parsing_block;
2842 var lt = (LocatedToken) $2;
2843 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2844 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2845 ((Enum) current_type).AddEnumMember (em);
2848 em.DocComment = ConsumeStoredComment ();
2852 | opt_attributes IDENTIFIER error
2854 Error_SyntaxError (yyToken);
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 | attributes_without_members
2870 delegate_declaration
2874 member_type type_declaration_name
2877 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2879 opt_formal_parameter_list CLOSE_PARENS
2881 valid_param_mod = 0;
2883 ParametersCompiled p = (ParametersCompiled) $8;
2885 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2887 p.CheckParameters (del);
2889 current_container.AddTypeContainer (del);
2891 current_delegate = del;
2892 lexer.ConstraintsParsing = true;
2894 opt_type_parameter_constraints_clauses
2896 lexer.ConstraintsParsing = false;
2901 current_delegate.DocComment = Lexer.consume_doc_comment ();
2902 Lexer.doc_state = XmlCommentState.Allowed;
2906 current_delegate.SetConstraints ((List<Constraints>) $11);
2907 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2909 $$ = current_delegate;
2911 current_delegate = null;
2919 if (lang_version < LanguageVersion.ISO_2)
2920 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2922 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2926 namespace_or_type_expr
2928 | qualified_alias_member IDENTIFIER opt_type_argument_list
2930 var lt1 = (LocatedToken) $1;
2931 var lt2 = (LocatedToken) $2;
2933 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2934 lbag.AddLocation ($$, GetLocation ($2));
2936 | qualified_alias_member IDENTIFIER generic_dimension
2938 var lt1 = (LocatedToken) $1;
2939 var lt2 = (LocatedToken) $2;
2941 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2942 lbag.AddLocation ($$, GetLocation ($2));
2948 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2950 var lt = (LocatedToken) $3;
2951 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2952 lbag.AddLocation ($$, GetLocation ($2));
2954 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2956 var lt = (LocatedToken) $3;
2957 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2958 lbag.AddLocation ($$, GetLocation ($2));
2963 : IDENTIFIER opt_type_argument_list
2965 var lt = (LocatedToken) $1;
2966 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2968 | IDENTIFIER generic_dimension
2970 var lt = (LocatedToken) $1;
2971 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2976 // Generics arguments (any type, without attributes)
2978 opt_type_argument_list
2980 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2982 if (lang_version < LanguageVersion.ISO_2)
2983 FeatureIsNotAvailable (GetLocation ($1), "generics");
2987 | OP_GENERICS_LT error
2989 Error_TypeExpected (lexer.Location);
2990 $$ = new TypeArguments ();
2997 TypeArguments type_args = new TypeArguments ();
2998 type_args.Add ((FullNamedExpression) $1);
3001 | type_arguments COMMA type
3003 TypeArguments type_args = (TypeArguments) $1;
3004 type_args.Add ((FullNamedExpression) $3);
3010 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3012 type_declaration_name
3015 lexer.parsing_generic_declaration = true;
3017 opt_type_parameter_list
3019 lexer.parsing_generic_declaration = false;
3020 var lt = (LocatedToken) $1;
3021 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3025 member_declaration_name
3026 : method_declaration_name
3028 MemberName mn = (MemberName)$1;
3029 if (mn.TypeParameters != null)
3030 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3031 mn.GetSignatureForError ()));
3035 method_declaration_name
3036 : type_declaration_name
3037 | explicit_interface IDENTIFIER opt_type_parameter_list
3039 lexer.parsing_generic_declaration = false;
3040 var lt = (LocatedToken) $2;
3041 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3045 indexer_declaration_name
3048 lexer.parsing_generic_declaration = false;
3049 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3051 | explicit_interface THIS
3053 lexer.parsing_generic_declaration = false;
3054 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3059 : IDENTIFIER opt_type_argument_list DOT
3061 var lt = (LocatedToken) $1;
3062 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3063 lbag.AddLocation ($$, GetLocation ($3));
3065 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3067 var lt1 = (LocatedToken) $1;
3068 var lt2 = (LocatedToken) $2;
3070 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3071 lbag.AddLocation ($$, GetLocation ($4));
3073 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3075 var lt = (LocatedToken) $2;
3076 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3077 lbag.AddLocation ($$, GetLocation ($4));
3081 opt_type_parameter_list
3083 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3085 if (lang_version < LanguageVersion.ISO_2)
3086 FeatureIsNotAvailable (GetLocation ($1), "generics");
3089 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3096 var tparams = new TypeParameters ();
3097 tparams.Add ((TypeParameter)$1);
3100 | type_parameters COMMA type_parameter
3102 var tparams = (TypeParameters) $1;
3103 tparams.Add ((TypeParameter)$3);
3105 lbag.AddLocation ($3, GetLocation ($3));
3110 : opt_attributes opt_type_parameter_variance IDENTIFIER
3112 var lt = (LocatedToken)$3;
3113 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3117 if (GetTokenName (yyToken) == "type")
3118 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3120 Error_SyntaxError (yyToken);
3122 $$ = new TypeParameter (MemberName.Null, null, null);
3127 // All types where void is allowed
3130 : type_expression_or_array
3133 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3140 lexer.parsing_generic_declaration = true;
3145 // A type which does not allow `void' to be used
3148 : type_expression_or_array
3158 : type_expression_or_array
3161 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3162 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3166 type_expression_or_array
3168 | type_expression rank_specifiers
3170 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3175 : namespace_or_type_expr opt_nullable
3178 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3180 var sn = $1 as SimpleName;
3181 if (sn != null && sn.Name == "var")
3182 $$ = new VarExpr (sn.Location);
3187 | namespace_or_type_expr pointer_stars
3189 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3191 | builtin_type_expression
3197 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3198 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3202 builtin_type_expression
3203 : builtin_types opt_nullable
3206 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3208 | builtin_types pointer_stars
3210 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3212 | VOID pointer_stars
3214 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3221 var types = new List<FullNamedExpression> (2);
3222 types.Add ((FullNamedExpression) $1);
3225 | type_list COMMA base_type_name
3227 var types = (List<FullNamedExpression>) $1;
3228 types.Add ((FullNamedExpression) $3);
3236 if ($1 is ComposedCast) {
3237 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3244 * replaces all the productions for isolating the various
3245 * simple types, but we need this to reuse it easily in variable_type
3248 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3249 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3250 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3251 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3252 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3253 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3258 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3259 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3260 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3261 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3262 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3263 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3264 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3265 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3266 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3270 // Expressions, section 7.5
3275 : type_name_expression
3277 | array_creation_expression
3278 | parenthesized_expression
3279 | default_value_expression
3280 | invocation_expression
3284 | post_increment_expression
3285 | post_decrement_expression
3286 | object_or_delegate_creation_expression
3287 | anonymous_type_expression
3290 | checked_expression
3291 | unchecked_expression
3292 | pointer_member_access
3293 | anonymous_method_expression
3294 | undocumented_expressions
3297 type_name_expression
3299 | IDENTIFIER GENERATE_COMPLETION {
3300 var lt = (LocatedToken) $1;
3301 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3309 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3313 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3314 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3319 // Here is the trick, tokenizer may think that parens is a special but
3320 // parser is interested in open parens only, so we merge them.
3321 // Consider: if (a)foo ();
3329 // Use this production to accept closing parenthesis or
3330 // performing completion
3334 | COMPLETE_COMPLETION
3338 parenthesized_expression
3339 : OPEN_PARENS expression CLOSE_PARENS
3341 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3342 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3344 | OPEN_PARENS expression COMPLETE_COMPLETION
3346 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3351 : primary_expression DOT identifier_inside_body opt_type_argument_list
3353 var lt = (LocatedToken) $3;
3354 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3355 lbag.AddLocation ($$, GetLocation ($2));
3357 | primary_expression DOT identifier_inside_body generic_dimension
3359 var lt = (LocatedToken) $3;
3360 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3361 lbag.AddLocation ($$, GetLocation ($2));
3363 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3365 if (lang_version < LanguageVersion.V_6)
3366 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3368 var lt = (LocatedToken) $4;
3369 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3370 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3372 | builtin_types DOT identifier_inside_body opt_type_argument_list
3374 var lt = (LocatedToken) $3;
3375 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3376 lbag.AddLocation ($$, GetLocation ($2));
3378 | BASE DOT identifier_inside_body opt_type_argument_list
3380 var lt = (LocatedToken) $3;
3381 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3382 lbag.AddLocation ($$, GetLocation ($2));
3384 | AWAIT DOT identifier_inside_body opt_type_argument_list
3386 var lt = (LocatedToken) $3;
3387 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3388 lbag.AddLocation ($$, GetLocation ($2));
3390 | qualified_alias_member identifier_inside_body opt_type_argument_list
3392 var lt1 = (LocatedToken) $1;
3393 var lt2 = (LocatedToken) $2;
3395 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3396 lbag.AddLocation ($$, GetLocation ($2));
3398 | qualified_alias_member identifier_inside_body generic_dimension
3400 var lt1 = (LocatedToken) $1;
3401 var lt2 = (LocatedToken) $2;
3403 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3404 lbag.AddLocation ($$, GetLocation ($2));
3406 | primary_expression DOT GENERATE_COMPLETION {
3407 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3409 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3410 var lt = (LocatedToken) $3;
3411 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3413 | builtin_types DOT GENERATE_COMPLETION
3415 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3417 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3418 var lt = (LocatedToken) $3;
3419 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3423 invocation_expression
3424 : primary_expression open_parens_any opt_argument_list close_parens
3426 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3427 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3429 | primary_expression open_parens_any argument_list error
3431 Error_SyntaxError (yyToken);
3433 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3434 lbag.AddLocation ($$, GetLocation ($2));
3436 | primary_expression open_parens_any error
3438 Error_SyntaxError (yyToken);
3440 $$ = new Invocation ((Expression) $1, null);
3441 lbag.AddLocation ($$, GetLocation ($2));
3445 opt_object_or_collection_initializer
3446 : /* empty */ { $$ = null; }
3447 | object_or_collection_initializer
3450 object_or_collection_initializer
3451 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3454 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3456 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3458 lbag.AddLocation ($$, GetLocation ($3));
3460 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3462 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3463 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3467 opt_member_initializer_list
3468 : /* empty */ { $$ = null; }
3469 | member_initializer_list
3475 member_initializer_list
3476 : member_initializer
3478 var a = new List<Expression> ();
3479 a.Add ((Expression) $1);
3482 | member_initializer_list COMMA member_initializer
3484 var a = (List<Expression>)$1;
3485 a.Add ((Expression) $3);
3488 | member_initializer_list error {
3489 Error_SyntaxError (yyToken);
3495 : IDENTIFIER ASSIGN initializer_value
3497 var lt = (LocatedToken) $1;
3498 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3499 lbag.AddLocation ($$, GetLocation ($2));
3501 | AWAIT ASSIGN initializer_value
3503 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3504 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3505 lbag.AddLocation ($$, GetLocation ($2));
3507 | GENERATE_COMPLETION
3509 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3511 | non_assignment_expression opt_COMPLETE_COMPLETION {
3512 CompletionSimpleName csn = $1 as CompletionSimpleName;
3514 $$ = new CollectionElementInitializer ((Expression)$1);
3516 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3518 | OPEN_BRACE expression_list CLOSE_BRACE
3521 $$ = new CollectionElementInitializer (GetLocation ($1));
3523 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3525 lbag.AddLocation ($$, GetLocation ($3));
3527 | OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET ASSIGN initializer_value
3529 if (lang_version < LanguageVersion.V_6)
3530 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3532 $$ = new DictionaryElementInitializer ((List<Expression>)$2, (Expression) $5, GetLocation ($1));
3533 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3535 | OPEN_BRACE CLOSE_BRACE
3537 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3538 $$ = new CollectionElementInitializer (GetLocation ($1));
3539 lbag.AddLocation ($$, GetLocation ($2));
3545 | object_or_collection_initializer
3549 : /* empty */ { $$ = null; }
3554 : argument_or_named_argument
3556 Arguments list = new Arguments (4);
3557 list.Add ((Argument) $1);
3560 | argument_list COMMA argument
3562 Arguments list = (Arguments) $1;
3563 if (list [list.Count - 1] is NamedArgument)
3564 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3566 list.Add ((Argument) $3);
3569 | argument_list COMMA named_argument
3571 Arguments list = (Arguments) $1;
3572 NamedArgument a = (NamedArgument) $3;
3573 for (int i = 0; i < list.Count; ++i) {
3574 NamedArgument na = list [i] as NamedArgument;
3575 if (na != null && na.Name == a.Name)
3576 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3583 | argument_list COMMA error
3585 if (lexer.putback_char == -1)
3586 lexer.putback (')'); // TODO: Wrong but what can I do
3587 Error_SyntaxError (yyToken);
3592 report.Error (839, GetLocation ($1), "An argument is missing");
3600 $$ = new Argument ((Expression) $1);
3602 | non_simple_argument
3605 argument_or_named_argument
3611 : REF variable_reference
3613 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3614 lbag.AddLocation ($$, GetLocation ($1));
3616 | REF declaration_expression
3618 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3620 | OUT variable_reference
3622 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3623 lbag.AddLocation ($$, GetLocation ($1));
3625 | OUT declaration_expression
3627 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3629 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3631 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3632 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3634 | ARGLIST OPEN_PARENS CLOSE_PARENS
3636 $$ = new Argument (new Arglist (GetLocation ($1)));
3637 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3641 declaration_expression
3642 : OPEN_PARENS declaration_expression CLOSE_PARENS
3644 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3645 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3648 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3650 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3651 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3653 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3655 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3656 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3659 | variable_type identifier_inside_body
3661 if (lang_version != LanguageVersion.Experimental)
3662 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3664 var lt = (LocatedToken) $2;
3665 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3666 current_block.AddLocalName (lv);
3667 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3669 | variable_type identifier_inside_body ASSIGN expression
3671 if (lang_version != LanguageVersion.Experimental)
3672 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3674 var lt = (LocatedToken) $2;
3675 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3676 current_block.AddLocalName (lv);
3677 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3678 Initializer = (Expression) $4
3688 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3690 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3691 lbag.AddLocation ($$, GetLocation ($4));
3693 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3695 if (lang_version < LanguageVersion.V_6)
3696 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3698 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3699 ConditionalAccess = true
3702 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3704 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3706 Error_SyntaxError (yyToken);
3707 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3709 | primary_expression OPEN_BRACKET_EXPR error
3711 Error_SyntaxError (yyToken);
3712 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3717 : expression_or_error
3719 var list = new List<Expression> (4);
3720 list.Add ((Expression) $1);
3723 | expression_list COMMA expression_or_error
3725 var list = (List<Expression>) $1;
3726 list.Add ((Expression) $3);
3731 expression_list_arguments
3732 : expression_list_argument
3734 Arguments args = new Arguments (4);
3735 args.Add ((Argument) $1);
3738 | expression_list_arguments COMMA expression_list_argument
3740 Arguments args = (Arguments) $1;
3741 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3742 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3744 args.Add ((Argument) $3);
3749 expression_list_argument
3752 $$ = new Argument ((Expression) $1);
3760 $$ = new This (GetLocation ($1));
3765 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3767 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3768 lbag.AddLocation ($$, GetLocation ($4));
3770 | BASE OPEN_BRACKET error
3772 Error_SyntaxError (yyToken);
3773 $$ = new ElementAccess (null, null, GetLocation ($2));
3777 post_increment_expression
3778 : primary_expression OP_INC
3780 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3784 post_decrement_expression
3785 : primary_expression OP_DEC
3787 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3791 object_or_delegate_creation_expression
3792 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3795 if (lang_version <= LanguageVersion.ISO_2)
3796 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3798 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3800 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3803 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3805 | NEW new_expr_type object_or_collection_initializer
3807 if (lang_version <= LanguageVersion.ISO_2)
3808 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3810 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3814 array_creation_expression
3815 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3817 opt_array_initializer
3819 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3820 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3821 Next = (ComposedTypeSpecifier) $6
3822 }, (ArrayInitializer) $7, GetLocation ($1));
3823 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3825 | NEW new_expr_type rank_specifiers opt_array_initializer
3828 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3830 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3832 | NEW rank_specifier array_initializer
3834 if (lang_version <= LanguageVersion.ISO_2)
3835 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3837 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3839 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3841 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3842 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3844 | NEW new_expr_type error
3846 Error_SyntaxError (yyToken);
3847 // It can be any of new expression, create the most common one
3848 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3854 ++lexer.parsing_type;
3858 --lexer.parsing_type;
3863 anonymous_type_expression
3864 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3866 if (lang_version <= LanguageVersion.ISO_2)
3867 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3869 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3871 // TODO: lbag comma location
3872 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3874 | NEW OPEN_BRACE GENERATE_COMPLETION
3876 $$ = new EmptyCompletion ();
3880 anonymous_type_parameters_opt_comma
3881 : anonymous_type_parameters_opt
3882 | anonymous_type_parameters COMMA
3885 anonymous_type_parameters_opt
3887 | anonymous_type_parameters
3890 anonymous_type_parameters
3891 : anonymous_type_parameter
3893 var a = new List<AnonymousTypeParameter> (4);
3894 a.Add ((AnonymousTypeParameter) $1);
3897 | anonymous_type_parameters COMMA anonymous_type_parameter
3899 var a = (List<AnonymousTypeParameter>) $1;
3900 a.Add ((AnonymousTypeParameter) $3);
3903 | COMPLETE_COMPLETION
3905 $$ = new EmptyCompletion ();
3907 | anonymous_type_parameter COMPLETE_COMPLETION
3913 anonymous_type_parameter
3914 : identifier_inside_body ASSIGN variable_initializer
3916 var lt = (LocatedToken)$1;
3917 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3918 lbag.AddLocation ($$, GetLocation ($2));
3920 | identifier_inside_body
3922 var lt = (LocatedToken)$1;
3923 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3924 lt.Value, lt.Location);
3928 MemberAccess ma = (MemberAccess) $1;
3929 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3933 report.Error (746, lexer.Location,
3934 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3946 | rank_specifier rank_specifiers
3948 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3954 : OPEN_BRACKET CLOSE_BRACKET
3956 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3957 lbag.AddLocation ($$, GetLocation ($2));
3959 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3961 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3962 lbag.AddLocation ($$, GetLocation ($3));
3971 | dim_separators COMMA
3973 $$ = ((int) $1) + 1;
3977 opt_array_initializer
3989 : OPEN_BRACE CLOSE_BRACE
3991 var ai = new ArrayInitializer (0, GetLocation ($1));
3992 ai.VariableDeclaration = current_variable;
3993 lbag.AddLocation (ai, GetLocation ($2));
3996 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3998 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3999 ai.VariableDeclaration = current_variable;
4001 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4003 lbag.AddLocation (ai, GetLocation ($4));
4009 variable_initializer_list
4010 : variable_initializer
4012 var list = new List<Expression> (4);
4013 list.Add ((Expression) $1);
4016 | variable_initializer_list COMMA variable_initializer
4018 var list = (List<Expression>) $1;
4019 list.Add ((Expression) $3);
4025 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4027 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4028 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4032 typeof_type_expression
4036 Error_TypeExpected (lexer.Location);
4044 if (lang_version < LanguageVersion.ISO_2)
4045 FeatureIsNotAvailable (GetLocation ($1), "generics");
4051 qualified_alias_member
4052 : IDENTIFIER DOUBLE_COLON
4054 var lt = (LocatedToken) $1;
4055 if (lang_version == LanguageVersion.ISO_1)
4056 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4063 : SIZEOF open_parens_any type CLOSE_PARENS
4065 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4066 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4068 | SIZEOF open_parens_any type error
4070 Error_SyntaxError (yyToken);
4072 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4073 lbag.AddLocation ($$, GetLocation ($2));
4078 : CHECKED open_parens_any expression CLOSE_PARENS
4080 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4081 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4085 Error_SyntaxError (yyToken);
4087 $$ = new CheckedExpr (null, GetLocation ($1));
4091 unchecked_expression
4092 : UNCHECKED open_parens_any expression CLOSE_PARENS
4094 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4095 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4099 Error_SyntaxError (yyToken);
4101 $$ = new UnCheckedExpr (null, GetLocation ($1));
4105 pointer_member_access
4106 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4108 var lt = (LocatedToken) $3;
4109 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4113 anonymous_method_expression
4114 : DELEGATE opt_anonymous_method_signature
4116 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4120 $$ = end_anonymous ((ParametersBlock) $4);
4122 | ASYNC DELEGATE opt_anonymous_method_signature
4124 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4128 $$ = end_anonymous ((ParametersBlock) $5);
4132 opt_anonymous_method_signature
4135 $$ = ParametersCompiled.Undefined;
4137 | anonymous_method_signature
4140 anonymous_method_signature
4143 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4145 opt_formal_parameter_list CLOSE_PARENS
4147 valid_param_mod = 0;
4152 default_value_expression
4153 : DEFAULT open_parens_any type CLOSE_PARENS
4155 if (lang_version < LanguageVersion.ISO_2)
4156 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4158 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4159 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4164 : primary_expression
4165 | BANG prefixed_unary_expression
4167 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4169 | TILDE prefixed_unary_expression
4171 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4173 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4175 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4176 lbag.AddLocation ($$, GetLocation ($3));
4178 | AWAIT prefixed_unary_expression
4181 if (current_anonymous_method is LambdaExpression) {
4182 report.Error (4034, GetLocation ($1),
4183 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4184 } else if (current_anonymous_method != null) {
4185 report.Error (4035, GetLocation ($1),
4186 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4187 } else if (interactive_async != null) {
4188 current_block.Explicit.RegisterAsyncAwait ();
4189 interactive_async = true;
4191 report.Error (4033, GetLocation ($1),
4192 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4195 current_block.Explicit.RegisterAsyncAwait ();
4198 $$ = new Await ((Expression) $2, GetLocation ($1));
4202 Error_SyntaxError (yyToken);
4204 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4208 Error_SyntaxError (yyToken);
4210 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4212 | OPEN_PARENS_CAST type CLOSE_PARENS error
4214 Error_SyntaxError (yyToken);
4216 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4217 lbag.AddLocation ($$, GetLocation ($3));
4221 Error_SyntaxError (yyToken);
4223 $$ = new Await (null, GetLocation ($1));
4228 // The idea to split this out is from Rhys' grammar
4229 // to solve the problem with casts.
4231 prefixed_unary_expression
4233 | PLUS prefixed_unary_expression
4235 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4237 | MINUS prefixed_unary_expression
4239 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4241 | OP_INC prefixed_unary_expression
4243 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4245 | OP_DEC prefixed_unary_expression
4247 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4249 | STAR prefixed_unary_expression
4251 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4253 | BITWISE_AND prefixed_unary_expression
4255 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4259 Error_SyntaxError (yyToken);
4261 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4265 Error_SyntaxError (yyToken);
4267 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4271 Error_SyntaxError (yyToken);
4273 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4277 Error_SyntaxError (yyToken);
4279 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4283 Error_SyntaxError (yyToken);
4285 $$ = new Indirection (null, GetLocation ($1));
4289 Error_SyntaxError (yyToken);
4291 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4295 multiplicative_expression
4296 : prefixed_unary_expression
4297 | multiplicative_expression STAR prefixed_unary_expression
4299 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4300 lbag.AddLocation ($$, GetLocation ($2));
4302 | multiplicative_expression DIV prefixed_unary_expression
4304 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4305 lbag.AddLocation ($$, GetLocation ($2));
4307 | multiplicative_expression PERCENT prefixed_unary_expression
4309 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4310 lbag.AddLocation ($$, GetLocation ($2));
4312 | multiplicative_expression STAR error
4314 Error_SyntaxError (yyToken);
4316 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4317 lbag.AddLocation ($$, GetLocation ($2));
4319 | multiplicative_expression DIV error
4321 Error_SyntaxError (yyToken);
4323 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4324 lbag.AddLocation ($$, GetLocation ($2));
4326 | multiplicative_expression PERCENT error
4328 Error_SyntaxError (yyToken);
4330 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4331 lbag.AddLocation ($$, GetLocation ($2));
4336 : multiplicative_expression
4337 | additive_expression PLUS multiplicative_expression
4339 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4340 lbag.AddLocation ($$, GetLocation ($2));
4342 | additive_expression MINUS multiplicative_expression
4344 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4345 lbag.AddLocation ($$, GetLocation ($2));
4347 | additive_expression PLUS error
4349 Error_SyntaxError (yyToken);
4351 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4352 lbag.AddLocation ($$, GetLocation ($2));
4354 | additive_expression MINUS error
4356 Error_SyntaxError (yyToken);
4358 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4359 lbag.AddLocation ($$, GetLocation ($2));
4361 | additive_expression AS type
4363 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4365 | additive_expression IS pattern_type_expr opt_identifier
4367 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4369 if (lang_version != LanguageVersion.Experimental)
4370 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4372 var lt = (LocatedToken) $4;
4373 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4374 current_block.AddLocalName (is_expr.Variable);
4379 | additive_expression IS pattern_expr
4381 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4382 if (lang_version != LanguageVersion.Experimental)
4383 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4387 | additive_expression AS error
4389 Error_SyntaxError (yyToken);
4391 $$ = new As ((Expression) $1, null, GetLocation ($2));
4393 | additive_expression IS error
4395 Error_SyntaxError (yyToken);
4397 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4401 var lt = (LocatedToken) $1;
4402 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4406 var lt = (LocatedToken) $1;
4407 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4417 | PLUS prefixed_unary_expression
4419 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4421 | MINUS prefixed_unary_expression
4423 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4426 | default_value_expression
4427 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4429 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4430 lbag.AddLocation ($$, GetLocation ($3));
4434 $$ = new WildcardPattern (GetLocation ($1));
4436 | pattern_expr_invocation
4440 pattern_expr_invocation
4441 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4443 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4448 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4450 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4454 pattern_property_list
4455 : pattern_property_entry
4457 var list = new List<PropertyPatternMember> ();
4458 list.Add ((PropertyPatternMember) $1);
4461 | pattern_property_list COMMA pattern_property_entry
4463 var list = (List<PropertyPatternMember>) $1;
4464 list.Add ((PropertyPatternMember) $3);
4469 pattern_property_entry
4470 : identifier_inside_body IS pattern
4472 var lt = (LocatedToken) $1;
4473 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4479 | pattern_type_expr opt_identifier
4482 var lt = (LocatedToken) $2;
4483 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4484 current_block.AddLocalName (variable);
4492 $$ = new Arguments (0);
4500 Arguments args = new Arguments (4);
4501 args.Add ((Argument) $1);
4504 | pattern_list COMMA pattern_argument
4506 Arguments args = (Arguments) $1;
4507 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4508 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4510 args.Add ((Argument) $3);
4518 $$ = new Argument ((Expression) $1);
4520 | IDENTIFIER COLON pattern
4522 var lt = (LocatedToken) $1;
4523 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4528 : additive_expression
4529 | shift_expression OP_SHIFT_LEFT additive_expression
4531 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4532 lbag.AddLocation ($$, GetLocation ($2));
4534 | shift_expression OP_SHIFT_RIGHT additive_expression
4536 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4537 lbag.AddLocation ($$, GetLocation ($2));
4539 | shift_expression OP_SHIFT_LEFT error
4541 Error_SyntaxError (yyToken);
4543 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4544 lbag.AddLocation ($$, GetLocation ($2));
4546 | shift_expression OP_SHIFT_RIGHT error
4548 Error_SyntaxError (yyToken);
4550 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4551 lbag.AddLocation ($$, GetLocation ($2));
4555 relational_expression
4557 | relational_expression OP_LT shift_expression
4559 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4560 lbag.AddLocation ($$, GetLocation ($2));
4562 | relational_expression OP_GT shift_expression
4564 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4565 lbag.AddLocation ($$, GetLocation ($2));
4567 | relational_expression OP_LE shift_expression
4569 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4570 lbag.AddLocation ($$, GetLocation ($2));
4572 | relational_expression OP_GE shift_expression
4574 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4575 lbag.AddLocation ($$, GetLocation ($2));
4577 | relational_expression OP_LT error
4579 Error_SyntaxError (yyToken);
4581 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4582 lbag.AddLocation ($$, GetLocation ($2));
4584 | relational_expression OP_GT error
4586 Error_SyntaxError (yyToken);
4588 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4589 lbag.AddLocation ($$, GetLocation ($2));
4591 | relational_expression OP_LE error
4593 Error_SyntaxError (yyToken);
4595 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4596 lbag.AddLocation ($$, GetLocation ($2));
4598 | relational_expression OP_GE error
4600 Error_SyntaxError (yyToken);
4602 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4603 lbag.AddLocation ($$, GetLocation ($2));
4608 : relational_expression
4609 | equality_expression OP_EQ relational_expression
4611 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4612 lbag.AddLocation ($$, GetLocation ($2));
4614 | equality_expression OP_NE relational_expression
4616 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4617 lbag.AddLocation ($$, GetLocation ($2));
4619 | equality_expression OP_EQ error
4621 Error_SyntaxError (yyToken);
4623 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4624 lbag.AddLocation ($$, GetLocation ($2));
4626 | equality_expression OP_NE error
4628 Error_SyntaxError (yyToken);
4630 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4631 lbag.AddLocation ($$, GetLocation ($2));
4636 : equality_expression
4637 | and_expression BITWISE_AND equality_expression
4639 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4640 lbag.AddLocation ($$, GetLocation ($2));
4642 | and_expression BITWISE_AND error
4644 Error_SyntaxError (yyToken);
4646 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4647 lbag.AddLocation ($$, GetLocation ($2));
4651 exclusive_or_expression
4653 | exclusive_or_expression CARRET and_expression
4655 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4656 lbag.AddLocation ($$, GetLocation ($2));
4658 | exclusive_or_expression CARRET error
4660 Error_SyntaxError (yyToken);
4662 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4663 lbag.AddLocation ($$, GetLocation ($2));
4667 inclusive_or_expression
4668 : exclusive_or_expression
4669 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4671 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4672 lbag.AddLocation ($$, GetLocation ($2));
4674 | inclusive_or_expression BITWISE_OR error
4676 Error_SyntaxError (yyToken);
4678 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4679 lbag.AddLocation ($$, GetLocation ($2));
4683 conditional_and_expression
4684 : inclusive_or_expression
4685 | conditional_and_expression OP_AND inclusive_or_expression
4687 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4688 lbag.AddLocation ($$, GetLocation ($2));
4690 | conditional_and_expression OP_AND error
4692 Error_SyntaxError (yyToken);
4694 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4695 lbag.AddLocation ($$, GetLocation ($2));
4699 conditional_or_expression
4700 : conditional_and_expression
4701 | conditional_or_expression OP_OR conditional_and_expression
4703 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4704 lbag.AddLocation ($$, GetLocation ($2));
4706 | conditional_or_expression OP_OR error
4708 Error_SyntaxError (yyToken);
4710 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4711 lbag.AddLocation ($$, GetLocation ($2));
4715 null_coalescing_expression
4716 : conditional_or_expression
4717 | conditional_or_expression OP_COALESCING null_coalescing_expression
4719 if (lang_version < LanguageVersion.ISO_2)
4720 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4722 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4723 lbag.AddLocation ($$, GetLocation ($2));
4727 conditional_expression
4728 : null_coalescing_expression
4729 | null_coalescing_expression INTERR expression COLON expression
4731 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4732 lbag.AddLocation ($$, GetLocation ($4));
4734 | null_coalescing_expression INTERR expression error
4736 Error_SyntaxError (yyToken);
4738 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4740 | null_coalescing_expression INTERR expression COLON error
4742 Error_SyntaxError (yyToken);
4744 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4745 lbag.AddLocation ($$, GetLocation ($4));
4747 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4749 Error_SyntaxError (Token.CLOSE_BRACE);
4751 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4752 lbag.AddLocation ($$, GetLocation ($4));
4753 lexer.putback ('}');
4757 assignment_expression
4758 : prefixed_unary_expression ASSIGN expression
4760 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4761 lbag.AddLocation ($$, GetLocation ($2));
4763 | prefixed_unary_expression OP_MULT_ASSIGN expression
4765 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4766 lbag.AddLocation ($$, GetLocation ($2));
4768 | prefixed_unary_expression OP_DIV_ASSIGN expression
4770 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4771 lbag.AddLocation ($$, GetLocation ($2));
4773 | prefixed_unary_expression OP_MOD_ASSIGN expression
4775 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4776 lbag.AddLocation ($$, GetLocation ($2));
4778 | prefixed_unary_expression OP_ADD_ASSIGN expression
4780 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4781 lbag.AddLocation ($$, GetLocation ($2));
4783 | prefixed_unary_expression OP_SUB_ASSIGN expression
4785 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4786 lbag.AddLocation ($$, GetLocation ($2));
4788 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4790 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4791 lbag.AddLocation ($$, GetLocation ($2));
4793 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4795 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4796 lbag.AddLocation ($$, GetLocation ($2));
4798 | prefixed_unary_expression OP_AND_ASSIGN expression
4800 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4801 lbag.AddLocation ($$, GetLocation ($2));
4803 | prefixed_unary_expression OP_OR_ASSIGN expression
4805 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4806 lbag.AddLocation ($$, GetLocation ($2));
4808 | prefixed_unary_expression OP_XOR_ASSIGN expression
4810 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4811 lbag.AddLocation ($$, GetLocation ($2));
4815 lambda_parameter_list
4818 var pars = new List<Parameter> (4);
4819 pars.Add ((Parameter) $1);
4823 | lambda_parameter_list COMMA lambda_parameter
4825 var pars = (List<Parameter>) $1;
4826 Parameter p = (Parameter)$3;
4827 if (pars[0].GetType () != p.GetType ()) {
4828 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4837 : parameter_modifier parameter_type identifier_inside_body
4839 var lt = (LocatedToken) $3;
4841 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4843 | parameter_type identifier_inside_body
4845 var lt = (LocatedToken) $2;
4847 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4851 var lt = (LocatedToken) $1;
4852 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4856 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4857 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4861 opt_lambda_parameter_list
4862 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4863 | lambda_parameter_list {
4864 var pars_list = (List<Parameter>) $1;
4865 $$ = new ParametersCompiled (pars_list.ToArray ());
4869 lambda_expression_body
4871 start_block (Location.Null);
4873 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4875 Block b = end_block (Location.Null);
4876 b.IsCompilerGenerated = true;
4877 b.AddStatement (new ContextualReturn ((Expression) $2));
4883 // Handles only cases like foo = x.FirstOrDefault (l => );
4884 // where we must restore current_variable
4885 Block b = end_block (Location.Null);
4886 b.IsCompilerGenerated = true;
4888 Error_SyntaxError (yyToken);
4897 Error_SyntaxError (yyToken);
4905 var lt = (LocatedToken) $1;
4906 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4907 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4909 lambda_expression_body
4911 $$ = end_anonymous ((ParametersBlock) $4);
4912 lbag.AddLocation ($$, GetLocation ($2));
4916 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4917 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4918 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4920 lambda_expression_body
4922 $$ = end_anonymous ((ParametersBlock) $4);
4923 lbag.AddLocation ($$, GetLocation ($2));
4925 | ASYNC identifier_inside_body ARROW
4927 var lt = (LocatedToken) $2;
4928 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4929 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4931 lambda_expression_body
4933 $$ = end_anonymous ((ParametersBlock) $5);
4934 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4936 | OPEN_PARENS_LAMBDA
4938 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4940 opt_lambda_parameter_list CLOSE_PARENS ARROW
4942 valid_param_mod = 0;
4943 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4945 lambda_expression_body
4947 $$ = end_anonymous ((ParametersBlock) $7);
4948 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4950 | ASYNC OPEN_PARENS_LAMBDA
4952 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4954 opt_lambda_parameter_list CLOSE_PARENS ARROW
4956 valid_param_mod = 0;
4957 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4959 lambda_expression_body
4961 $$ = end_anonymous ((ParametersBlock) $8);
4962 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4967 : assignment_expression
4968 | non_assignment_expression
4971 non_assignment_expression
4972 : conditional_expression
4977 $$ = new ArglistAccess (GetLocation ($1));
4981 undocumented_expressions
4982 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4984 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4985 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4987 | REFTYPE open_parens_any expression CLOSE_PARENS
4989 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4990 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4992 | MAKEREF open_parens_any expression CLOSE_PARENS
4994 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4995 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5006 $$ = new BooleanExpression ((Expression) $1);
5010 opt_primary_parameters
5015 | primary_parameters
5019 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5023 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5024 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5026 if (lang_version != LanguageVersion.Experimental)
5027 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5031 opt_primary_parameters_with_class_base
5040 | primary_parameters
5044 | primary_parameters class_base
5048 | primary_parameters class_base OPEN_PARENS
5050 ++lexer.parsing_block;
5051 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5053 opt_argument_list CLOSE_PARENS
5055 lbag.AppendToMember (current_container, GetLocation ($6));
5056 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5057 --lexer.parsing_block;
5073 type_declaration_name
5075 lexer.ConstraintsParsing = true;
5077 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5078 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5079 FeatureIsNotAvailable (c.Location, "static classes");
5082 push_current_container (c, $3);
5083 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5085 opt_primary_parameters_with_class_base
5086 opt_type_parameter_constraints_clauses
5088 valid_param_mod = 0;
5089 lexer.ConstraintsParsing = false;
5092 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5095 current_container.SetConstraints ((List<Constraints>) $9);
5096 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5099 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5100 Lexer.doc_state = XmlCommentState.Allowed;
5103 lexer.parsing_modifiers = true;
5105 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5107 --lexer.parsing_declaration;
5109 Lexer.doc_state = XmlCommentState.Allowed;
5114 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5116 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5118 $$ = pop_current_class ();
5126 { $$ = $1; } // location
5132 mod_locations = null;
5134 lexer.parsing_modifiers = false;
5138 lexer.parsing_modifiers = false;
5144 | modifiers modifier
5146 var m1 = (Modifiers) $1;
5147 var m2 = (Modifiers) $2;
5149 if ((m1 & m2) != 0) {
5150 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5151 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5152 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5153 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5154 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5155 "More than one protection modifier specified");
5166 StoreModifierLocation ($$, GetLocation ($1));
5168 if (current_container.Kind == MemberKind.Namespace)
5169 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5173 $$ = Modifiers.PUBLIC;
5174 StoreModifierLocation ($$, GetLocation ($1));
5178 $$ = Modifiers.PROTECTED;
5179 StoreModifierLocation ($$, GetLocation ($1));
5183 $$ = Modifiers.INTERNAL;
5184 StoreModifierLocation ($$, GetLocation ($1));
5188 $$ = Modifiers.PRIVATE;
5189 StoreModifierLocation ($$, GetLocation ($1));
5193 $$ = Modifiers.ABSTRACT;
5194 StoreModifierLocation ($$, GetLocation ($1));
5198 $$ = Modifiers.SEALED;
5199 StoreModifierLocation ($$, GetLocation ($1));
5203 $$ = Modifiers.STATIC;
5204 StoreModifierLocation ($$, GetLocation ($1));
5208 $$ = Modifiers.READONLY;
5209 StoreModifierLocation ($$, GetLocation ($1));
5213 $$ = Modifiers.VIRTUAL;
5214 StoreModifierLocation ($$, GetLocation ($1));
5218 $$ = Modifiers.OVERRIDE;
5219 StoreModifierLocation ($$, GetLocation ($1));
5223 $$ = Modifiers.EXTERN;
5224 StoreModifierLocation ($$, GetLocation ($1));
5228 $$ = Modifiers.VOLATILE;
5229 StoreModifierLocation ($$, GetLocation ($1));
5233 $$ = Modifiers.UNSAFE;
5234 StoreModifierLocation ($$, GetLocation ($1));
5235 if (!settings.Unsafe)
5236 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5240 $$ = Modifiers.ASYNC;
5241 StoreModifierLocation ($$, GetLocation ($1));
5253 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5255 | COLON type_list error
5257 Error_SyntaxError (yyToken);
5259 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5263 opt_type_parameter_constraints_clauses
5265 | type_parameter_constraints_clauses
5271 type_parameter_constraints_clauses
5272 : type_parameter_constraints_clause
5274 var constraints = new List<Constraints> (1);
5275 constraints.Add ((Constraints) $1);
5278 | type_parameter_constraints_clauses type_parameter_constraints_clause
5280 var constraints = (List<Constraints>) $1;
5281 Constraints new_constraint = (Constraints)$2;
5283 foreach (Constraints c in constraints) {
5284 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5285 report.Error (409, new_constraint.Location,
5286 "A constraint clause has already been specified for type parameter `{0}'",
5287 new_constraint.TypeParameter.Value);
5291 constraints.Add (new_constraint);
5296 type_parameter_constraints_clause
5297 : WHERE IDENTIFIER COLON type_parameter_constraints
5299 var lt = (LocatedToken) $2;
5300 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5301 lbag.AddLocation ($$, GetLocation ($3));
5303 | WHERE IDENTIFIER error
5305 Error_SyntaxError (yyToken);
5307 var lt = (LocatedToken) $2;
5308 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5312 type_parameter_constraints
5313 : type_parameter_constraint
5315 var constraints = new List<FullNamedExpression> (1);
5316 constraints.Add ((FullNamedExpression) $1);
5319 | type_parameter_constraints COMMA type_parameter_constraint
5321 var constraints = (List<FullNamedExpression>) $1;
5322 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5323 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5324 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5327 prev = $3 as SpecialContraintExpr;
5329 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5330 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5332 prev = constraints [0] as SpecialContraintExpr;
5333 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5334 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5339 constraints.Add ((FullNamedExpression) $3);
5344 type_parameter_constraint
5347 if ($1 is ComposedCast)
5348 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5352 | NEW OPEN_PARENS CLOSE_PARENS
5354 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5355 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5359 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5363 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5367 opt_type_parameter_variance
5372 | type_parameter_variance
5374 if (lang_version <= LanguageVersion.V_3)
5375 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5381 type_parameter_variance
5384 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5388 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5397 // A block is "contained" on the following places:
5399 // property_declaration as part of the accessor body (get/set)
5400 // operator_declaration
5401 // constructor_declaration
5402 // destructor_declaration
5403 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5408 ++lexer.parsing_block;
5409 start_block (GetLocation ($1));
5411 opt_statement_list block_end
5420 --lexer.parsing_block;
5421 $$ = end_block (GetLocation ($1));
5423 | COMPLETE_COMPLETION
5425 --lexer.parsing_block;
5426 $$ = end_block (lexer.Location);
5434 ++lexer.parsing_block;
5435 current_block.StartLocation = GetLocation ($1);
5437 opt_statement_list CLOSE_BRACE
5439 --lexer.parsing_block;
5440 $$ = end_block (GetLocation ($4));
5451 | statement_list statement
5455 : block_variable_declaration
5457 current_block.AddStatement ((Statement) $1);
5459 | valid_declaration_statement
5461 current_block.AddStatement ((Statement) $1);
5466 Error_SyntaxError (yyToken);
5472 // The interactive_statement and its derivatives are only
5473 // used to provide a special version of `expression_statement'
5474 // that has a side effect of assigning the expression to
5477 interactive_statement_list
5478 : interactive_statement
5479 | interactive_statement_list interactive_statement
5482 interactive_statement
5483 : block_variable_declaration
5485 current_block.AddStatement ((Statement) $1);
5487 | interactive_valid_declaration_statement
5489 current_block.AddStatement ((Statement) $1);
5494 valid_declaration_statement
5497 | expression_statement
5498 | selection_statement
5499 | iteration_statement
5503 | unchecked_statement
5510 interactive_valid_declaration_statement
5513 | interactive_expression_statement
5514 | selection_statement
5515 | iteration_statement
5519 | unchecked_statement
5527 : valid_declaration_statement
5528 | block_variable_declaration
5530 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5535 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5540 Error_SyntaxError (yyToken);
5541 $$ = new EmptyStatement (GetLocation ($1));
5548 // Uses lexer.Location because semicolon location is not kept in quick mode
5549 $$ = new EmptyStatement (lexer.Location);
5554 : identifier_inside_body COLON
5556 var lt = (LocatedToken) $1;
5557 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5558 lbag.AddLocation (labeled, GetLocation ($2));
5559 current_block.AddLabel (labeled);
5560 current_block.AddStatement (labeled);
5566 : variable_type_simple
5567 | variable_type_simple rank_specifiers
5570 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5572 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5577 * The following is from Rhys' grammar:
5578 * > Types in local variable declarations must be recognized as
5579 * > expressions to prevent reduce/reduce errors in the grammar.
5580 * > The expressions are converted into types during semantic analysis.
5582 variable_type_simple
5583 : type_name_expression opt_nullable
5585 // Ok, the above "primary_expression" is there to get rid of
5586 // both reduce/reduce and shift/reduces in the grammar, it should
5587 // really just be "type_name". If you use type_name, a reduce/reduce
5588 // creeps up. If you use namespace_or_type_name (which is all we need
5589 // really) two shift/reduces appear.
5592 // So the super-trick is that primary_expression
5593 // can only be either a SimpleName or a MemberAccess.
5594 // The MemberAccess case arises when you have a fully qualified type-name like :
5596 // SimpleName is when you have
5599 var expr = (ATypeNameExpression) $1;
5601 if (expr.Name == "var" && expr is SimpleName)
5602 $$ = new VarExpr (expr.Location);
5606 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5609 | type_name_expression pointer_stars
5611 var expr = (ATypeNameExpression) $1;
5612 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5614 | builtin_type_expression
5620 | pointer_star pointer_stars
5622 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5630 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5634 identifier_inside_body
5638 $$ = Error_AwaitAsIdentifier ($1);
5642 block_variable_declaration
5643 : variable_type identifier_inside_body
5645 var lt = (LocatedToken) $2;
5646 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5647 current_block.AddLocalName (li);
5648 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5650 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5652 $$ = current_variable;
5653 current_variable = null;
5655 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5657 lbag.AddLocation ($$, GetLocation ($6));
5659 | CONST variable_type identifier_inside_body
5661 var lt = (LocatedToken) $3;
5662 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5663 current_block.AddLocalName (li);
5664 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5666 const_variable_initializer opt_const_declarators SEMICOLON
5668 $$ = current_variable;
5669 current_variable = null;
5670 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5674 opt_local_variable_initializer
5676 | ASSIGN block_variable_initializer
5678 current_variable.Initializer = (Expression) $2;
5679 PushLocation (GetLocation ($1));
5680 $$ = current_variable;
5684 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5685 report.Error (650, lexer.Location,
5686 "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");
5688 Error_SyntaxError (yyToken);
5693 opt_variable_declarators
5695 | variable_declarators
5698 opt_using_or_fixed_variable_declarators
5700 | variable_declarators
5702 foreach (var d in current_variable.Declarators) {
5703 if (d.Initializer == null)
5704 Error_MissingInitializer (d.Variable.Location);
5709 variable_declarators
5710 : variable_declarator
5711 | variable_declarators variable_declarator
5715 : COMMA identifier_inside_body
5717 var lt = (LocatedToken) $2;
5718 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5719 var d = new BlockVariableDeclarator (li, null);
5720 current_variable.AddDeclarator (d);
5721 current_block.AddLocalName (li);
5722 lbag.AddLocation (d, GetLocation ($1));
5724 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5726 var lt = (LocatedToken) $2;
5727 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5728 var d = new BlockVariableDeclarator (li, (Expression) $4);
5729 current_variable.AddDeclarator (d);
5730 current_block.AddLocalName (li);
5731 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5735 const_variable_initializer
5738 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5740 | ASSIGN constant_initializer_expr
5742 current_variable.Initializer = (Expression) $2;
5746 opt_const_declarators
5753 | const_declarators const_declarator
5757 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5759 var lt = (LocatedToken) $2;
5760 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5761 var d = new BlockVariableDeclarator (li, (Expression) $4);
5762 current_variable.AddDeclarator (d);
5763 current_block.AddLocalName (li);
5764 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5768 block_variable_initializer
5769 : variable_initializer
5770 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5772 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5773 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5775 | STACKALLOC simple_type
5777 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5778 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5782 expression_statement
5783 : statement_expression SEMICOLON
5786 lbag.AddStatement ($$, GetLocation ($2));
5788 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5789 | statement_expression CLOSE_BRACE
5792 report.Error (1002, GetLocation ($2), "; expected");
5793 lexer.putback ('}');
5797 interactive_expression_statement
5798 : interactive_statement_expression SEMICOLON { $$ = $1; }
5799 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5803 // We have to do the wrapping here and not in the case above,
5804 // because statement_expression is used for example in for_statement
5806 statement_expression
5809 ExpressionStatement s = $1 as ExpressionStatement;
5811 var expr = $1 as Expression;
5812 $$ = new StatementErrorExpression (expr);
5814 $$ = new StatementExpression (s);
5819 interactive_statement_expression
5822 Expression expr = (Expression) $1;
5823 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5827 Error_SyntaxError (yyToken);
5828 $$ = new EmptyStatement (GetLocation ($1));
5838 : IF open_parens_any boolean_expression CLOSE_PARENS
5841 if ($5 is EmptyStatement)
5842 Warning_EmptyStatement (GetLocation ($5));
5844 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5845 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5847 | IF open_parens_any boolean_expression CLOSE_PARENS
5848 embedded_statement ELSE embedded_statement
5850 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5851 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5853 if ($5 is EmptyStatement)
5854 Warning_EmptyStatement (GetLocation ($5));
5855 if ($7 is EmptyStatement)
5856 Warning_EmptyStatement (GetLocation ($7));
5858 | IF open_parens_any boolean_expression error
5860 Error_SyntaxError (yyToken);
5862 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5863 lbag.AddStatement ($$, GetLocation ($2));
5868 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5870 start_block (GetLocation ($5));
5872 opt_switch_sections CLOSE_BRACE
5874 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5875 end_block (GetLocation ($8));
5876 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5878 | SWITCH open_parens_any expression error
5880 Error_SyntaxError (yyToken);
5882 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5883 lbag.AddStatement ($$, GetLocation ($2));
5890 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5897 | switch_sections switch_section
5900 Error_SyntaxError (yyToken);
5905 : switch_labels statement_list
5911 var label = (SwitchLabel) $1;
5912 label.SectionStart = true;
5913 current_block.AddStatement (label);
5915 | switch_labels switch_label
5917 current_block.AddStatement ((Statement) $2);
5922 : CASE constant_expression COLON
5924 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5925 lbag.AddLocation ($$, GetLocation ($3));
5927 | CASE constant_expression error
5929 Error_SyntaxError (yyToken);
5930 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5932 | CASE pattern_expr_invocation COLON
5934 if (lang_version != LanguageVersion.Experimental)
5935 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
5937 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
5938 PatternMatching = true
5940 lbag.AddLocation ($$, GetLocation ($3));
5944 $$ = new SwitchLabel (null, GetLocation ($1));
5956 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5958 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5959 Warning_EmptyStatement (GetLocation ($5));
5961 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5962 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5964 | WHILE open_parens_any boolean_expression error
5966 Error_SyntaxError (yyToken);
5968 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5969 lbag.AddStatement ($$, GetLocation ($2));
5974 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5976 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5977 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5979 | DO embedded_statement error
5981 Error_SyntaxError (yyToken);
5982 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5984 | DO embedded_statement WHILE open_parens_any boolean_expression error
5986 Error_SyntaxError (yyToken);
5988 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5989 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5994 : FOR open_parens_any
5996 start_block (GetLocation ($2));
5997 current_block.IsCompilerGenerated = true;
5998 For f = new For (GetLocation ($1));
5999 current_block.AddStatement (f);
6008 // Has to use be extra rule to recover started block
6010 : opt_for_initializer SEMICOLON
6012 ((For) $0).Initializer = (Statement) $1;
6014 // Pass the "For" object to the iterator_part4
6015 oob_stack.Push ($0);
6017 for_condition_and_iterator_part
6020 var locations = (Tuple<Location,Location>) $4;
6022 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6023 Warning_EmptyStatement (GetLocation ($5));
6026 f.Statement = (Statement) $5;
6027 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6029 $$ = end_block (GetLocation ($2));
6033 Error_SyntaxError (yyToken);
6034 $$ = end_block (current_block.StartLocation);
6038 for_condition_and_iterator_part
6039 : opt_for_condition SEMICOLON
6041 For f = (For) oob_stack.Peek ();
6042 f.Condition = (BooleanExpression) $1;
6045 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6048 // Handle errors in the case of opt_for_condition being followed by
6049 // a close parenthesis
6050 | opt_for_condition close_parens_close_brace {
6051 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6052 For f = (For) oob_stack.Peek ();
6053 f.Condition = (BooleanExpression) $1;
6054 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6059 : opt_for_iterator CLOSE_PARENS {
6060 For f = (For) oob_stack.Peek ();
6061 f.Iterator = (Statement) $1;
6062 $$ = GetLocation ($2);
6064 | opt_for_iterator CLOSE_BRACE {
6065 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6066 For f = (For) oob_stack.Peek ();
6067 f.Iterator = (Statement) $1;
6068 $$ = GetLocation ($2);
6072 close_parens_close_brace
6074 | CLOSE_BRACE { lexer.putback ('}'); }
6078 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6083 : variable_type identifier_inside_body
6085 var lt = (LocatedToken) $2;
6086 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6087 current_block.AddLocalName (li);
6088 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6090 opt_local_variable_initializer opt_variable_declarators
6092 $$ = current_variable;
6094 lbag.AddLocation (current_variable, PopLocation ());
6096 current_variable = null;
6098 | statement_expression_list
6102 : /* empty */ { $$ = null; }
6103 | boolean_expression
6107 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6112 : statement_expression_list
6115 statement_expression_list
6116 : statement_expression
6117 | statement_expression_list COMMA statement_expression
6119 var sl = $1 as StatementList;
6121 sl = new StatementList ((Statement) $1, (Statement) $3);
6122 lbag.AddStatement (sl, GetLocation ($2));
6124 sl.Add ((Statement) $3);
6125 lbag.AppendTo (sl, GetLocation ($2));
6133 : FOREACH open_parens_any type error
6135 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6137 start_block (GetLocation ($2));
6138 current_block.IsCompilerGenerated = true;
6140 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6141 current_block.AddStatement (f);
6143 lbag.AddStatement (f, GetLocation ($2));
6144 $$ = end_block (GetLocation ($4));
6146 | FOREACH open_parens_any type identifier_inside_body error
6148 Error_SyntaxError (yyToken);
6150 start_block (GetLocation ($2));
6151 current_block.IsCompilerGenerated = true;
6153 var lt = (LocatedToken) $4;
6154 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6155 current_block.AddLocalName (li);
6157 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6158 current_block.AddStatement (f);
6160 lbag.AddStatement (f, GetLocation ($2));
6161 $$ = end_block (GetLocation ($5));
6163 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6165 start_block (GetLocation ($2));
6166 current_block.IsCompilerGenerated = true;
6168 var lt = (LocatedToken) $4;
6169 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6170 current_block.AddLocalName (li);
6175 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6176 Warning_EmptyStatement (GetLocation ($9));
6178 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6179 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6180 end_block (GetLocation ($7));
6188 | continue_statement
6198 $$ = new Break (GetLocation ($1));
6199 lbag.AddStatement ($$, GetLocation ($2));
6204 : CONTINUE SEMICOLON
6206 $$ = new Continue (GetLocation ($1));
6207 lbag.AddStatement ($$, GetLocation ($2));
6211 Error_SyntaxError (yyToken);
6212 $$ = new Continue (GetLocation ($1));
6217 : GOTO identifier_inside_body SEMICOLON
6219 var lt = (LocatedToken) $2;
6220 $$ = new Goto (lt.Value, GetLocation ($1));
6221 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6223 | GOTO CASE constant_expression SEMICOLON
6225 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6226 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6228 | GOTO DEFAULT SEMICOLON
6230 $$ = new GotoDefault (GetLocation ($1));
6231 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6236 : RETURN opt_expression SEMICOLON
6238 $$ = new Return ((Expression) $2, GetLocation ($1));
6239 lbag.AddStatement ($$, GetLocation ($3));
6241 | RETURN expression error
6243 Error_SyntaxError (yyToken);
6244 $$ = new Return ((Expression) $2, GetLocation ($1));
6248 Error_SyntaxError (yyToken);
6249 $$ = new Return (null, GetLocation ($1));
6254 : THROW opt_expression SEMICOLON
6256 $$ = new Throw ((Expression) $2, GetLocation ($1));
6257 lbag.AddStatement ($$, GetLocation ($3));
6259 | THROW expression error
6261 Error_SyntaxError (yyToken);
6262 $$ = new Throw ((Expression) $2, GetLocation ($1));
6266 Error_SyntaxError (yyToken);
6267 $$ = new Throw (null, GetLocation ($1));
6272 : identifier_inside_body RETURN opt_expression SEMICOLON
6274 var lt = (LocatedToken) $1;
6275 string s = lt.Value;
6277 report.Error (1003, lt.Location, "; expected");
6278 } else if ($3 == null) {
6279 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6280 } else if (lang_version == LanguageVersion.ISO_1){
6281 FeatureIsNotAvailable (lt.Location, "iterators");
6284 current_block.Explicit.RegisterIteratorYield ();
6285 $$ = new Yield ((Expression) $3, lt.Location);
6286 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6288 | identifier_inside_body RETURN expression error
6290 Error_SyntaxError (yyToken);
6292 var lt = (LocatedToken) $1;
6293 string s = lt.Value;
6295 report.Error (1003, lt.Location, "; expected");
6296 } else if ($3 == null) {
6297 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6298 } else if (lang_version == LanguageVersion.ISO_1){
6299 FeatureIsNotAvailable (lt.Location, "iterators");
6302 current_block.Explicit.RegisterIteratorYield ();
6303 $$ = new Yield ((Expression) $3, lt.Location);
6304 lbag.AddStatement ($$, GetLocation ($2));
6306 | identifier_inside_body BREAK SEMICOLON
6308 var lt = (LocatedToken) $1;
6309 string s = lt.Value;
6311 report.Error (1003, lt.Location, "; expected");
6312 } else if (lang_version == LanguageVersion.ISO_1){
6313 FeatureIsNotAvailable (lt.Location, "iterators");
6316 current_block.ParametersBlock.TopBlock.IsIterator = true;
6317 $$ = new YieldBreak (lt.Location);
6318 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6328 : TRY block catch_clauses
6330 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6332 | TRY block FINALLY block
6334 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6335 lbag.AddStatement ($$, GetLocation ($3));
6337 | TRY block catch_clauses FINALLY block
6339 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6340 lbag.AddStatement ($$, GetLocation ($4));
6344 Error_SyntaxError (1524, yyToken);
6345 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6352 var l = new List<Catch> (2);
6357 | catch_clauses catch_clause
6359 var l = (List<Catch>) $1;
6361 Catch c = (Catch) $2;
6362 var prev_catch = l [l.Count - 1];
6363 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6364 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6374 | identifier_inside_body
6378 : CATCH opt_catch_filter block
6380 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6381 c.Filter = (CatchFilterExpression) $2;
6384 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6386 start_block (GetLocation ($2));
6387 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6388 c.TypeExpression = (FullNamedExpression) $3;
6391 var lt = (LocatedToken) $4;
6392 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6393 current_block.AddLocalName (c.Variable);
6396 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6399 opt_catch_filter block_prepared
6401 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6404 | CATCH open_parens_any error
6406 if (yyToken == Token.CLOSE_PARENS) {
6407 report.Error (1015, lexer.Location,
6408 "A type that derives from `System.Exception', `object', or `string' expected");
6410 Error_SyntaxError (yyToken);
6413 $$ = new Catch (null, GetLocation ($1));
6415 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6417 Error_SyntaxError (yyToken);
6419 // Required otherwise missing block could not be detected because
6420 // start_block is run early
6421 var c = new Catch (null, GetLocation ($1));
6422 c.TypeExpression = (FullNamedExpression) $3;
6425 var lt = (LocatedToken) $4;
6426 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6429 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6437 | IF open_parens_any expression CLOSE_PARENS
6439 if (lang_version <= LanguageVersion.V_5)
6440 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6442 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6443 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6450 $$ = new Checked ((Block) $2, GetLocation ($1));
6457 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6464 if (!settings.Unsafe)
6465 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6467 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6472 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6474 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6475 Warning_EmptyStatement (GetLocation ($5));
6477 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6478 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6480 | LOCK open_parens_any expression error
6482 Error_SyntaxError (yyToken);
6484 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6485 lbag.AddStatement ($$, GetLocation ($2));
6490 : FIXED open_parens_any variable_type identifier_inside_body
6492 start_block (GetLocation ($2));
6494 current_block.IsCompilerGenerated = true;
6495 var lt = (LocatedToken) $4;
6496 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6497 current_block.AddLocalName (li);
6498 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6500 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6502 $$ = current_variable;
6503 current_variable = null;
6507 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6508 Warning_EmptyStatement (GetLocation ($10));
6510 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6511 current_block.AddStatement (f);
6512 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6513 $$ = end_block (GetLocation ($8));
6518 : USING open_parens_any variable_type identifier_inside_body
6520 start_block (GetLocation ($2));
6522 current_block.IsCompilerGenerated = true;
6523 var lt = (LocatedToken) $4;
6524 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6525 current_block.AddLocalName (li);
6526 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6528 using_initialization CLOSE_PARENS
6530 $$ = current_variable;
6531 current_variable = null;
6535 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6536 Warning_EmptyStatement (GetLocation ($9));
6538 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6539 current_block.AddStatement (u);
6540 $$ = end_block (GetLocation ($7));
6542 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6544 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6545 Warning_EmptyStatement (GetLocation ($5));
6547 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6548 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6550 | USING open_parens_any expression error
6552 Error_SyntaxError (yyToken);
6554 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6555 lbag.AddStatement ($$, GetLocation ($2));
6559 using_initialization
6560 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6563 // It has to be here for the parent to safely restore artificial block
6564 Error_SyntaxError (yyToken);
6568 using_or_fixed_variable_initializer
6571 Error_MissingInitializer (lexer.Location);
6573 | ASSIGN variable_initializer
6575 current_variable.Initializer = (Expression) $2;
6576 $$ = current_variable;
6584 : first_from_clause query_body
6586 lexer.query_parsing = false;
6588 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6590 from.Tail.Next = (Linq.AQueryClause)$2;
6593 current_block.SetEndLocation (lexer.Location);
6594 current_block = current_block.Parent;
6596 | nested_from_clause query_body
6598 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6600 from.Tail.Next = (Linq.AQueryClause)$2;
6603 current_block.SetEndLocation (lexer.Location);
6604 current_block = current_block.Parent;
6607 // Bubble up COMPLETE_COMPLETION productions
6608 | first_from_clause COMPLETE_COMPLETION {
6609 lexer.query_parsing = false;
6612 current_block.SetEndLocation (lexer.Location);
6613 current_block = current_block.Parent;
6615 | nested_from_clause COMPLETE_COMPLETION {
6617 current_block.SetEndLocation (lexer.Location);
6618 current_block = current_block.Parent;
6623 : FROM_FIRST identifier_inside_body IN expression
6625 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6627 var lt = (LocatedToken) $2;
6628 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6629 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6630 lbag.AddLocation (clause, GetLocation ($3));
6631 $$ = new Linq.QueryExpression (clause);
6633 | FROM_FIRST type identifier_inside_body IN expression
6635 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6637 var lt = (LocatedToken) $3;
6638 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6639 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6640 IdentifierType = (FullNamedExpression)$2
6642 lbag.AddLocation (clause, GetLocation ($4));
6643 $$ = new Linq.QueryExpression (clause);
6648 : FROM identifier_inside_body IN expression
6650 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6652 var lt = (LocatedToken) $2;
6653 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6654 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6655 lbag.AddLocation (clause, GetLocation ($3));
6656 $$ = new Linq.QueryExpression (clause);
6658 | FROM type identifier_inside_body IN expression
6660 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6662 var lt = (LocatedToken) $3;
6663 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6664 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6665 IdentifierType = (FullNamedExpression)$2
6667 lbag.AddLocation (clause, GetLocation ($4));
6668 $$ = new Linq.QueryExpression (clause);
6673 : FROM identifier_inside_body IN
6675 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6679 var lt = (LocatedToken) $2;
6680 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6681 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6683 current_block.SetEndLocation (lexer.Location);
6684 current_block = current_block.Parent;
6686 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6687 lbag.AddLocation ($$, GetLocation ($3));
6689 | FROM type identifier_inside_body IN
6691 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6695 var lt = (LocatedToken) $3;
6696 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6698 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6699 IdentifierType = (FullNamedExpression)$2
6702 current_block.SetEndLocation (lexer.Location);
6703 current_block = current_block.Parent;
6705 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6707 lbag.AddLocation ($$, GetLocation ($4));
6712 : query_body_clauses select_or_group_clause opt_query_continuation
6714 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6717 head.Next = (Linq.AQueryClause)$3;
6720 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6721 clause.Tail.Next = head;
6727 | select_or_group_clause opt_query_continuation
6729 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6732 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6733 clause.Tail.Next = head;
6739 | query_body_clauses COMPLETE_COMPLETION
6740 | query_body_clauses error
6742 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6747 Error_SyntaxError (yyToken);
6752 select_or_group_clause
6755 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6759 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6761 current_block.SetEndLocation (lexer.Location);
6762 current_block = current_block.Parent;
6766 if (linq_clause_blocks == null)
6767 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6769 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6770 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6774 current_block.SetEndLocation (lexer.Location);
6775 current_block = current_block.Parent;
6777 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6781 var obj = (object[]) $5;
6783 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6784 lbag.AddLocation ($$, (Location) obj[1]);
6786 current_block.SetEndLocation (lexer.Location);
6787 current_block = current_block.Parent;
6792 : BY expression_or_error
6794 $$ = new object[] { $2, GetLocation ($1) };
6798 Error_SyntaxError (yyToken);
6799 $$ = new object[2] { null, Location.Null };
6805 | query_body_clauses query_body_clause
6807 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6821 : LET identifier_inside_body ASSIGN
6823 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6827 var lt = (LocatedToken) $2;
6828 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6829 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6830 lbag.AddLocation ($$, GetLocation ($3));
6832 current_block.SetEndLocation (lexer.Location);
6833 current_block = current_block.Parent;
6835 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6842 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6846 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6848 current_block.SetEndLocation (lexer.Location);
6849 current_block = current_block.Parent;
6854 : JOIN identifier_inside_body IN
6856 if (linq_clause_blocks == null)
6857 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6859 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6860 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6862 expression_or_error ON
6864 current_block.SetEndLocation (lexer.Location);
6865 current_block = current_block.Parent;
6867 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6868 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6870 expression_or_error EQUALS
6872 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6873 current_block.SetEndLocation (lexer.Location);
6874 current_block = current_block.Parent;
6876 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6878 expression_or_error opt_join_into
6880 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6881 current_block.SetEndLocation (lexer.Location);
6883 var outer_selector = linq_clause_blocks.Pop ();
6884 var block = linq_clause_blocks.Pop ();
6886 var lt = (LocatedToken) $2;
6887 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6888 Linq.RangeVariable into;
6892 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6893 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6896 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6898 var parent = block.Parent;
6899 while (parent is Linq.QueryBlock) {
6900 parent = parent.Parent;
6902 current_block.Parent = parent;
6904 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6906 lt = (LocatedToken) $12;
6907 into = new Linq.RangeVariable (lt.Value, lt.Location);
6909 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6910 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6913 current_block = block.Parent;
6914 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6916 | JOIN type identifier_inside_body IN
6918 if (linq_clause_blocks == null)
6919 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6921 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6922 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6924 expression_or_error ON
6926 current_block.SetEndLocation (lexer.Location);
6927 current_block = current_block.Parent;
6929 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6930 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6932 expression_or_error EQUALS
6934 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6935 current_block.SetEndLocation (lexer.Location);
6936 current_block = current_block.Parent;
6938 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6940 expression_or_error opt_join_into
6942 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6943 current_block.SetEndLocation (lexer.Location);
6945 var outer_selector = linq_clause_blocks.Pop ();
6946 var block = linq_clause_blocks.Pop ();
6948 var lt = (LocatedToken) $3;
6949 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6950 Linq.RangeVariable into;
6954 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6955 IdentifierType = (FullNamedExpression)$2
6957 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6960 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6962 var parent = block.Parent;
6963 while (parent is Linq.QueryBlock) {
6964 parent = parent.Parent;
6966 current_block.Parent = parent;
6968 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6970 lt = (LocatedToken) $13;
6971 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6973 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6974 IdentifierType = (FullNamedExpression)$2
6978 current_block = block.Parent;
6979 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6985 | INTO identifier_inside_body
6994 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6998 current_block.SetEndLocation (lexer.Location);
6999 current_block = current_block.Parent;
7009 current_block.SetEndLocation (lexer.Location);
7010 current_block = current_block.Parent;
7012 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7016 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7023 | orderings_then_by COMMA
7025 current_block.SetEndLocation (lexer.Location);
7026 current_block = current_block.Parent;
7028 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7032 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7040 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7042 | expression ASCENDING
7044 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7045 lbag.AddLocation ($$, GetLocation ($2));
7047 | expression DESCENDING
7049 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7050 lbag.AddLocation ($$, GetLocation ($2));
7057 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7059 | expression ASCENDING
7061 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7062 lbag.AddLocation ($$, GetLocation ($2));
7064 | expression DESCENDING
7066 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7067 lbag.AddLocation ($$, GetLocation ($2));
7072 opt_query_continuation
7074 | INTO identifier_inside_body
7076 // query continuation block is not linked with query block but with block
7077 // before. This means each query can use same range variable names for
7078 // different identifiers.
7080 current_block.SetEndLocation (GetLocation ($1));
7081 current_block = current_block.Parent;
7083 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7085 if (linq_clause_blocks == null)
7086 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7088 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7092 var current_block = linq_clause_blocks.Pop ();
7093 var lt = (LocatedToken) $2;
7094 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7095 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7096 next = (Linq.AQueryClause)$4
7102 // Support for using the compiler as an interactive parser
7104 // The INTERACTIVE_PARSER token is first sent to parse our
7105 // productions; If the result is a Statement, the parsing
7106 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7107 // to setup the blocks in advance.
7109 // This setup is here so that in the future we can add
7110 // support for other constructs (type parsing, namespaces, etc)
7111 // that do not require a block to be setup in advance
7115 : EVAL_STATEMENT_PARSER EOF
7116 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7117 | EVAL_STATEMENT_PARSER
7119 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7121 // (ref object retval)
7122 Parameter [] mpar = new Parameter [1];
7123 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7125 ParametersCompiled pars = new ParametersCompiled (mpar);
7126 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7127 if (settings.Unsafe)
7128 mods |= Modifiers.UNSAFE;
7130 current_local_parameters = pars;
7131 var method = new InteractiveMethod (
7133 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7137 current_type.AddMember (method);
7138 oob_stack.Push (method);
7140 interactive_async = false;
7142 ++lexer.parsing_block;
7143 start_block (lexer.Location);
7145 interactive_statement_list opt_COMPLETE_COMPLETION
7147 --lexer.parsing_block;
7148 var method = (InteractiveMethod) oob_stack.Pop ();
7149 method.Block = (ToplevelBlock) end_block(lexer.Location);
7151 if (interactive_async == true) {
7152 method.ChangeToAsync ();
7155 InteractiveResult = (Class) pop_current_class ();
7156 current_local_parameters = null;
7158 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7161 interactive_compilation_unit
7162 : opt_extern_alias_directives opt_using_directives
7163 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7166 opt_COMPLETE_COMPLETION
7168 | COMPLETE_COMPLETION
7171 close_brace_or_complete_completion
7173 | COMPLETE_COMPLETION
7177 // XML documentation code references micro parser
7179 documentation_parsing
7182 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7187 : doc_type_declaration_name opt_doc_method_sig
7189 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7191 | builtin_types opt_doc_method_sig
7193 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7194 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7197 | VOID opt_doc_method_sig
7199 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7200 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7203 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7205 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7206 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7207 var lt = (LocatedToken) $3;
7208 $$ = new MemberName (lt.Value);
7210 | doc_type_declaration_name DOT THIS
7212 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7214 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7216 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7218 opt_doc_parameters CLOSE_BRACKET
7220 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7221 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7223 | EXPLICIT OPERATOR type opt_doc_method_sig
7225 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7226 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7227 module.DocumentationBuilder.ParsedParameters = p;
7228 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7231 | IMPLICIT OPERATOR type opt_doc_method_sig
7233 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7234 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7235 module.DocumentationBuilder.ParsedParameters = p;
7236 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7239 | OPERATOR overloadable_operator opt_doc_method_sig
7241 var p = (List<DocumentationParameter>)$3;
7242 module.DocumentationBuilder.ParsedParameters = p;
7243 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7248 doc_type_declaration_name
7249 : type_declaration_name
7250 | doc_type_declaration_name DOT type_declaration_name
7252 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7260 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7262 opt_doc_parameters CLOSE_PARENS
7271 $$ = new List<DocumentationParameter> (0);
7279 var parameters = new List<DocumentationParameter> ();
7280 parameters.Add ((DocumentationParameter) $1);
7283 | doc_parameters COMMA doc_parameter
7285 var parameters = $1 as List<DocumentationParameter>;
7286 parameters.Add ((DocumentationParameter) $3);
7292 : opt_parameter_modifier parameter_type
7295 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7297 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7304 // A class used to hold info about an operator declarator
7306 class OperatorDeclaration {
7307 public readonly Operator.OpType optype;
7308 public readonly FullNamedExpression ret_type;
7309 public readonly Location location;
7311 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7314 this.ret_type = ret_type;
7315 this.location = location;
7319 void Error_ExpectingTypeName (Expression expr)
7321 if (expr is Invocation){
7322 report.Error (1002, expr.Location, "Expecting `;'");
7324 expr.Error_InvalidExpressionStatement (report);
7328 void Error_ParameterModifierNotValid (string modifier, Location loc)
7330 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7334 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7336 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7337 Parameter.GetModifierSignature (mod));
7340 void Error_TypeExpected (Location loc)
7342 report.Error (1031, loc, "Type expected");
7345 void Error_UnsafeCodeNotAllowed (Location loc)
7347 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7350 void Warning_EmptyStatement (Location loc)
7352 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7355 void Error_NamedArgumentExpected (NamedArgument a)
7357 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7360 void Error_MissingInitializer (Location loc)
7362 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7365 object Error_AwaitAsIdentifier (object token)
7368 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7369 return new LocatedToken ("await", GetLocation (token));
7375 void push_current_container (TypeDefinition tc, object partial_token)
7377 if (module.Evaluator != null){
7378 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7382 undo.AddTypeContainer (current_container, tc);
7385 if (partial_token != null)
7386 current_container.AddPartial (tc);
7388 current_container.AddTypeContainer (tc);
7390 ++lexer.parsing_declaration;
7391 current_container = tc;
7395 TypeContainer pop_current_class ()
7397 var retval = current_container;
7399 current_container = current_container.Parent;
7400 current_type = current_type.Parent as TypeDefinition;
7405 [System.Diagnostics.Conditional ("FULL_AST")]
7406 void StoreModifierLocation (object token, Location loc)
7411 if (mod_locations == null)
7412 mod_locations = new List<Tuple<Modifiers, Location>> ();
7414 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7417 [System.Diagnostics.Conditional ("FULL_AST")]
7418 void PushLocation (Location loc)
7420 if (location_stack == null)
7421 location_stack = new Stack<Location> ();
7423 location_stack.Push (loc);
7426 Location PopLocation ()
7428 if (location_stack == null)
7429 return Location.Null;
7431 return location_stack.Pop ();
7434 string CheckAttributeTarget (int token, string a, Location l)
7437 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7441 if (!Tokenizer.IsValidIdentifier (a)) {
7442 Error_SyntaxError (token);
7444 report.Warning (658, 1, l,
7445 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7448 return string.Empty;
7451 static bool IsUnaryOperator (Operator.OpType op)
7455 case Operator.OpType.LogicalNot:
7456 case Operator.OpType.OnesComplement:
7457 case Operator.OpType.Increment:
7458 case Operator.OpType.Decrement:
7459 case Operator.OpType.True:
7460 case Operator.OpType.False:
7461 case Operator.OpType.UnaryPlus:
7462 case Operator.OpType.UnaryNegation:
7468 void syntax_error (Location l, string msg)
7470 report.Error (1003, l, "Syntax error, " + msg);
7475 public Tokenizer Lexer {
7481 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7482 : this (reader, file, file.Compiler.Report, session)
7486 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7489 current_container = current_namespace = file;
7491 this.module = file.Module;
7492 this.compiler = file.Compiler;
7493 this.settings = compiler.Settings;
7494 this.report = report;
7496 lang_version = settings.Version;
7497 yacc_verbose_flag = settings.VerboseParserFlag;
7498 doc_support = settings.DocumentationFile != null;
7499 lexer = new Tokenizer (reader, file, session, report);
7500 oob_stack = new Stack<object> ();
7501 lbag = session.LocationsBag;
7502 use_global_stacks = session.UseJayGlobalArrays;
7503 parameters_bucket = session.ParametersStack;
7506 public void parse ()
7508 eof_token = Token.EOF;
7511 if (yacc_verbose_flag > 1)
7512 yyparse (lexer, new yydebug.yyDebugSimple ());
7516 Tokenizer tokenizer = lexer as Tokenizer;
7517 tokenizer.cleanup ();
7518 } catch (Exception e){
7519 if (e is yyParser.yyUnexpectedEof) {
7520 Error_SyntaxError (yyToken);
7521 UnexpectedEOF = true;
7525 if (e is yyParser.yyException) {
7526 if (report.Errors == 0)
7527 report.Error (-25, lexer.Location, "Parsing error");
7529 // Used by compiler-tester to test internal errors
7530 if (yacc_verbose_flag > 0 || e is FatalException)
7533 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7538 void CheckToken (int error, int yyToken, string msg, Location loc)
7540 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7541 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7543 report.Error (error, loc, msg);
7546 string ConsumeStoredComment ()
7548 string s = tmpComment;
7550 Lexer.doc_state = XmlCommentState.Allowed;
7554 void FeatureIsNotAvailable (Location loc, string feature)
7556 report.FeatureIsNotAvailable (compiler, loc, feature);
7559 Location GetLocation (object obj)
7561 var lt = obj as LocatedToken;
7565 var mn = obj as MemberName;
7569 var expr = obj as Expression;
7571 return expr.Location;
7573 return lexer.Location;
7576 void start_block (Location loc)
7578 if (current_block == null) {
7579 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7580 parsing_anonymous_method = false;
7581 } else if (parsing_anonymous_method) {
7582 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7583 parsing_anonymous_method = false;
7585 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7590 end_block (Location loc)
7592 Block retval = current_block.Explicit;
7593 retval.SetEndLocation (loc);
7594 current_block = retval.Parent;
7598 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7600 oob_stack.Push (current_anonymous_method);
7601 oob_stack.Push (current_local_parameters);
7602 oob_stack.Push (current_variable);
7603 oob_stack.Push (async_block);
7605 current_local_parameters = parameters;
7607 if (lang_version <= LanguageVersion.ISO_2)
7608 FeatureIsNotAvailable (loc, "lambda expressions");
7610 current_anonymous_method = new LambdaExpression (loc);
7612 if (lang_version == LanguageVersion.ISO_1)
7613 FeatureIsNotAvailable (loc, "anonymous methods");
7615 current_anonymous_method = new AnonymousMethodExpression (loc);
7618 async_block = isAsync;
7619 // Force the next block to be created as a ToplevelBlock
7620 parsing_anonymous_method = true;
7624 * Completes the anonymous method processing, if lambda_expr is null, this
7625 * means that we have a Statement instead of an Expression embedded
7627 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7629 AnonymousMethodExpression retval;
7632 anon_block.IsAsync = true;
7634 current_anonymous_method.Block = anon_block;
7635 retval = current_anonymous_method;
7637 async_block = (bool) oob_stack.Pop ();
7638 current_variable = (BlockVariable) oob_stack.Pop ();
7639 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7640 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7645 void Error_SyntaxError (int token)
7647 Error_SyntaxError (0, token);
7650 void Error_SyntaxError (int error_code, int token)
7652 Error_SyntaxError (error_code, token, "Unexpected symbol");
7655 void Error_SyntaxError (int error_code, int token, string msg)
7657 Lexer.CompleteOnEOF = false;
7659 // An error message has been reported by tokenizer
7660 if (token == Token.ERROR)
7663 // Avoid duplicit error message after unterminated string literals
7664 if (token == Token.LITERAL && lexer.Location.Column == 0)
7667 string symbol = GetSymbolName (token);
7668 string expecting = GetExpecting ();
7669 var loc = lexer.Location - symbol.Length;
7671 if (error_code == 0) {
7672 if (expecting == "`identifier'") {
7673 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7674 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7679 expecting = "identifier";
7680 } else if (expecting == "`)'") {
7687 if (string.IsNullOrEmpty (expecting))
7688 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7690 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7693 string GetExpecting ()
7695 int [] tokens = yyExpectingTokens (yyExpectingState);
7696 var names = new List<string> (tokens.Length);
7697 bool has_type = false;
7698 bool has_identifier = false;
7699 for (int i = 0; i < tokens.Length; i++){
7700 int token = tokens [i];
7701 has_identifier |= token == Token.IDENTIFIER;
7703 string name = GetTokenName (token);
7704 if (name == "<internal>")
7707 has_type |= name == "type";
7708 if (names.Contains (name))
7715 // Too many tokens to enumerate
7717 if (names.Count > 8)
7720 if (has_type && has_identifier)
7721 names.Remove ("identifier");
7723 if (names.Count == 1)
7724 return "`" + GetTokenName (tokens [0]) + "'";
7726 StringBuilder sb = new StringBuilder ();
7728 int count = names.Count;
7729 for (int i = 0; i < count; i++){
7730 bool last = i + 1 == count;
7734 sb.Append (names [i]);
7735 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7737 return sb.ToString ();
7741 string GetSymbolName (int token)
7745 return ((Constant)lexer.Value).GetValue ().ToString ();
7746 case Token.IDENTIFIER:
7747 return ((LocatedToken)lexer.Value).Value;
7789 case Token.BITWISE_AND:
7791 case Token.BITWISE_OR:
7805 case Token.OP_SHIFT_LEFT:
7807 case Token.OP_SHIFT_RIGHT:
7827 case Token.OP_COALESCING:
7829 case Token.OP_MULT_ASSIGN:
7831 case Token.OP_DIV_ASSIGN:
7833 case Token.OP_MOD_ASSIGN:
7835 case Token.OP_ADD_ASSIGN:
7837 case Token.OP_SUB_ASSIGN:
7839 case Token.OP_SHIFT_LEFT_ASSIGN:
7841 case Token.OP_SHIFT_RIGHT_ASSIGN:
7843 case Token.OP_AND_ASSIGN:
7845 case Token.OP_XOR_ASSIGN:
7847 case Token.OP_OR_ASSIGN:
7851 return GetTokenName (token);
7854 static string GetTokenName (int token)
7857 case Token.ABSTRACT:
7879 case Token.CONTINUE:
7883 case Token.DELEGATE:
7893 case Token.EXPLICIT:
7896 case Token.EXTERN_ALIAS:
7912 case Token.IMPLICIT:
7916 case Token.INTERFACE:
7918 case Token.INTERNAL:
7924 case Token.NAMESPACE:
7930 case Token.OPERATOR:
7934 case Token.OVERRIDE:
7940 case Token.PROTECTED:
7944 case Token.READONLY:
7956 case Token.STACKALLOC:
7957 return "stackalloc";
7974 case Token.UNCHECKED:
7982 case Token.VOLATILE:
7990 case Token.REFVALUE:
7991 return "__refvalue";
8001 case Token.FROM_FIRST:
8019 case Token.ASCENDING:
8021 case Token.DESCENDING:
8022 return "descending";
8029 case Token.OPEN_BRACE:
8031 case Token.CLOSE_BRACE:
8033 case Token.OPEN_BRACKET:
8034 case Token.OPEN_BRACKET_EXPR:
8036 case Token.CLOSE_BRACKET:
8038 case Token.OPEN_PARENS_CAST:
8039 case Token.OPEN_PARENS_LAMBDA:
8040 case Token.OPEN_PARENS:
8042 case Token.CLOSE_PARENS:
8048 case Token.DEFAULT_COLON:
8052 case Token.SEMICOLON:
8063 case Token.BITWISE_AND:
8064 case Token.BITWISE_OR:
8071 case Token.OP_SHIFT_LEFT:
8072 case Token.OP_SHIFT_RIGHT:
8080 case Token.OP_COALESCING:
8081 case Token.OP_MULT_ASSIGN:
8082 case Token.OP_DIV_ASSIGN:
8083 case Token.OP_MOD_ASSIGN:
8084 case Token.OP_ADD_ASSIGN:
8085 case Token.OP_SUB_ASSIGN:
8086 case Token.OP_SHIFT_LEFT_ASSIGN:
8087 case Token.OP_SHIFT_RIGHT_ASSIGN:
8088 case Token.OP_AND_ASSIGN:
8089 case Token.OP_XOR_ASSIGN:
8090 case Token.OP_OR_ASSIGN:
8091 case Token.INTERR_OPERATOR:
8092 return "<operator>";
8114 case Token.OP_GENERICS_LT:
8115 case Token.GENERIC_DIMENSION:
8117 case Token.OP_GENERICS_GT:
8120 case Token.INTERR_NULLABLE:
8122 case Token.DOUBLE_COLON:
8126 case Token.IDENTIFIER:
8128 return "identifier";
8131 return "end-of-file";
8133 // All of these are internal.
8136 case Token.FIRST_KEYWORD:
8137 case Token.EVAL_COMPILATION_UNIT_PARSER:
8138 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8139 case Token.EVAL_STATEMENT_PARSER:
8140 case Token.LAST_KEYWORD:
8141 case Token.GENERATE_COMPLETION:
8142 case Token.COMPLETE_COMPLETION:
8143 return "<internal>";
8145 // A bit more robust.
8147 return yyNames [token];