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 CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1));
752 var lt = (LocatedToken) $1;
753 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
755 | EVENT { $$ = "event"; }
756 | RETURN { $$ = "return"; }
762 $$ = new List<Attribute> (4) { (Attribute) $1 };
764 | attribute_list COMMA attribute
766 var attrs = (List<Attribute>) $1;
768 attrs.Add ((Attribute) $3);
769 lbag.AppendTo (attrs, GetLocation ($2));
779 ++lexer.parsing_block;
781 opt_attribute_arguments
783 --lexer.parsing_block;
785 var tne = (ATypeNameExpression) $1;
786 if (tne.HasTypeArguments) {
787 report.Error (404, tne.Location, "Attributes cannot be generic");
790 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
795 : namespace_or_type_expr
798 opt_attribute_arguments
799 : /* empty */ { $$ = null; }
800 | OPEN_PARENS attribute_arguments CLOSE_PARENS
808 : /* empty */ { $$ = null; }
809 | positional_or_named_argument
811 Arguments a = new Arguments (4);
812 a.Add ((Argument) $1);
813 $$ = new Arguments [] { a, null };
815 | named_attribute_argument
817 Arguments a = new Arguments (4);
818 a.Add ((Argument) $1);
819 $$ = new Arguments [] { null, a };
821 | attribute_arguments COMMA positional_or_named_argument
823 Arguments[] o = (Arguments[]) $1;
825 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
826 o [0] = new Arguments (4);
829 Arguments args = ((Arguments) o [0]);
830 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
831 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
833 args.Add ((Argument) $3);
835 | attribute_arguments COMMA named_attribute_argument
837 Arguments[] o = (Arguments[]) $1;
839 o [1] = new Arguments (4);
842 ((Arguments) o [1]).Add ((Argument) $3);
846 positional_or_named_argument
849 $$ = new Argument ((Expression) $1);
854 Error_SyntaxError (yyToken);
859 named_attribute_argument
862 ++lexer.parsing_block;
866 --lexer.parsing_block;
867 var lt = (LocatedToken) $1;
868 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
869 lbag.AddLocation ($$, GetLocation($2));
874 : identifier_inside_body COLON opt_named_modifier named_argument_expr
876 if (lang_version <= LanguageVersion.V_3)
877 FeatureIsNotAvailable (GetLocation ($1), "named argument");
879 // Avoid boxing in common case (no modifier)
880 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
882 var lt = (LocatedToken) $1;
883 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
884 lbag.AddLocation ($$, GetLocation($2));
889 : expression_or_error
890 | declaration_expression
894 : /* empty */ { $$ = null; }
897 $$ = Argument.AType.Ref;
901 $$ = Argument.AType.Out;
905 opt_class_member_declarations
907 | class_member_declarations
910 class_member_declarations
911 : class_member_declaration
913 lexer.parsing_modifiers = true;
914 lexer.parsing_block = 0;
916 | class_member_declarations class_member_declaration
918 lexer.parsing_modifiers = true;
919 lexer.parsing_block = 0;
923 class_member_declaration
924 : constant_declaration
927 | property_declaration
929 | indexer_declaration
930 | operator_declaration
931 | constructor_declaration
932 | primary_constructor_body
933 | destructor_declaration
935 | attributes_without_members
939 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
940 GetSymbolName (yyToken));
942 lexer.parsing_generic_declaration = false;
946 primary_constructor_body
949 current_local_parameters = current_type.PrimaryConstructorParameters;
950 if (current_local_parameters == null) {
951 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
952 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
955 ++lexer.parsing_block;
956 start_block (GetLocation ($1));
958 opt_statement_list block_end
960 current_local_parameters = null;
961 var t = current_type as ClassOrStruct;
963 var b = (ToplevelBlock) $4;
964 if (t.PrimaryConstructorBlock != null) {
965 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
967 t.PrimaryConstructorBlock = b;
980 type_declaration_name
982 lexer.ConstraintsParsing = true;
983 valid_param_mod = ParameterModifierType.PrimaryConstructor;
984 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
986 opt_primary_parameters
988 opt_type_parameter_constraints_clauses
991 lexer.ConstraintsParsing = false;
994 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
997 current_container.SetConstraints ((List<Constraints>) $10);
1000 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1002 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1004 lexer.parsing_modifiers = true;
1009 Lexer.doc_state = XmlCommentState.Allowed;
1011 opt_class_member_declarations CLOSE_BRACE
1013 --lexer.parsing_declaration;
1015 Lexer.doc_state = XmlCommentState.Allowed;
1020 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1022 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1024 $$ = pop_current_class ();
1026 | opt_attributes opt_modifiers opt_partial STRUCT error
1028 Error_SyntaxError (yyToken);
1032 constant_declaration
1035 CONST type IDENTIFIER
1037 var lt = (LocatedToken) $5;
1038 var mod = (Modifiers) $2;
1039 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1040 current_type.AddMember (current_field);
1042 if ((mod & Modifiers.STATIC) != 0) {
1043 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1048 constant_initializer opt_constant_declarators SEMICOLON
1051 current_field.DocComment = Lexer.consume_doc_comment ();
1052 Lexer.doc_state = XmlCommentState.Allowed;
1055 current_field.Initializer = (ConstInitializer) $7;
1056 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1057 current_field = null;
1063 Error_SyntaxError (yyToken);
1065 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1069 opt_constant_declarators
1071 | constant_declarators
1074 constant_declarators
1075 : constant_declarator
1077 current_field.AddDeclarator ((FieldDeclarator) $1);
1079 | constant_declarators constant_declarator
1081 current_field.AddDeclarator ((FieldDeclarator) $2);
1086 : COMMA IDENTIFIER constant_initializer
1088 var lt = (LocatedToken) $2;
1089 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1090 lbag.AddLocation ($$, GetLocation ($1));
1094 constant_initializer
1097 ++lexer.parsing_block;
1099 constant_initializer_expr
1101 --lexer.parsing_block;
1102 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1106 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1111 constant_initializer_expr
1112 : constant_expression
1119 member_type IDENTIFIER
1121 lexer.parsing_generic_declaration = false;
1123 FullNamedExpression type = (FullNamedExpression) $3;
1124 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1125 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1127 var lt = (LocatedToken) $4;
1128 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1129 current_type.AddField (current_field);
1132 opt_field_initializer
1133 opt_field_declarators
1137 current_field.DocComment = Lexer.consume_doc_comment ();
1138 Lexer.doc_state = XmlCommentState.Allowed;
1141 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1143 current_field = null;
1147 FIXED simple_type IDENTIFIER
1149 if (lang_version < LanguageVersion.ISO_2)
1150 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1152 var lt = (LocatedToken) $5;
1153 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1154 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1156 current_type.AddField (current_field);
1158 fixed_field_size opt_fixed_field_declarators SEMICOLON
1161 current_field.DocComment = Lexer.consume_doc_comment ();
1162 Lexer.doc_state = XmlCommentState.Allowed;
1165 current_field.Initializer = (ConstInitializer) $7;
1166 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1168 current_field = null;
1172 FIXED simple_type error
1175 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1179 opt_field_initializer
1183 ++lexer.parsing_block;
1184 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1185 start_block (GetLocation ($1));
1187 variable_initializer
1189 --lexer.parsing_block;
1190 current_field.Initializer = (Expression) $3;
1191 lbag.AppendToMember (current_field, GetLocation ($1));
1192 end_block (lexer.Location);
1193 current_local_parameters = null;
1197 opt_field_declarators
1205 current_field.AddDeclarator ((FieldDeclarator) $1);
1207 | field_declarators field_declarator
1209 current_field.AddDeclarator ((FieldDeclarator) $2);
1216 var lt = (LocatedToken) $2;
1217 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1218 lbag.AddLocation ($$, GetLocation ($1));
1220 | COMMA IDENTIFIER ASSIGN
1222 ++lexer.parsing_block;
1224 variable_initializer
1226 --lexer.parsing_block;
1227 var lt = (LocatedToken) $2;
1228 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1229 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1233 opt_fixed_field_declarators
1235 | fixed_field_declarators
1238 fixed_field_declarators
1239 : fixed_field_declarator
1241 current_field.AddDeclarator ((FieldDeclarator) $1);
1243 | fixed_field_declarators fixed_field_declarator
1245 current_field.AddDeclarator ((FieldDeclarator) $2);
1249 fixed_field_declarator
1250 : COMMA IDENTIFIER fixed_field_size
1252 var lt = (LocatedToken) $2;
1253 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1254 lbag.AddLocation ($$, GetLocation ($1));
1261 ++lexer.parsing_block;
1263 expression CLOSE_BRACKET
1265 --lexer.parsing_block;
1266 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1267 lbag.AddLocation ($$, GetLocation ($4));
1269 | OPEN_BRACKET error
1271 report.Error (443, lexer.Location, "Value or constant expected");
1276 variable_initializer
1281 // It has to be here for the parent to safely restore artificial block
1282 Error_SyntaxError (yyToken);
1291 Lexer.doc_state = XmlCommentState.NotAllowed;
1293 // Was added earlier in the case of body being eof for full ast
1295 method_body_expression_block
1297 Method method = (Method) $1;
1298 method.Block = (ToplevelBlock) $3;
1299 async_block = false;
1301 if (method.Block == null) {
1302 method.ParameterInfo.CheckParameters (method);
1304 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1305 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1306 method.GetSignatureForError ());
1309 if (current_container.Kind == MemberKind.Interface) {
1310 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1311 method.GetSignatureForError ());
1315 current_local_parameters = null;
1318 Lexer.doc_state = XmlCommentState.Allowed;
1326 method_declaration_name OPEN_PARENS
1328 valid_param_mod = ParameterModifierType.All;
1330 opt_formal_parameter_list CLOSE_PARENS
1332 valid_param_mod = 0;
1333 MemberName name = (MemberName) $4;
1334 current_local_parameters = (ParametersCompiled) $7;
1336 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1337 name, current_local_parameters, (Attributes) $1);
1339 current_type.AddMember (method);
1341 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1344 method.DocComment = Lexer.consume_doc_comment ();
1346 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1350 lexer.ConstraintsParsing = true;
1352 opt_type_parameter_constraints_clauses
1354 lexer.ConstraintsParsing = false;
1357 var method = (Method) $9;
1358 method.SetConstraints ((List<Constraints>) $10);
1368 lexer.parsing_generic_declaration = true;
1370 method_declaration_name
1373 lexer.parsing_generic_declaration = false;
1374 valid_param_mod = ParameterModifierType.All;
1376 opt_formal_parameter_list CLOSE_PARENS
1378 lexer.ConstraintsParsing = true;
1380 opt_type_parameter_constraints_clauses
1382 lexer.ConstraintsParsing = false;
1383 valid_param_mod = 0;
1385 MemberName name = (MemberName) $6;
1386 current_local_parameters = (ParametersCompiled) $9;
1388 var modifiers = (Modifiers) $2;
1389 modifiers |= Modifiers.PARTIAL;
1391 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1392 modifiers, name, current_local_parameters, (Attributes) $1);
1394 current_type.AddMember (method);
1396 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1399 method.SetConstraints ((List<Constraints>) $12);
1402 method.DocComment = Lexer.consume_doc_comment ();
1404 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1405 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1411 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1413 MemberName name = (MemberName) $5;
1414 report.Error (1585, name.Location,
1415 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1417 var method = Method.Create (current_type, (FullNamedExpression) $3,
1418 0, name, (ParametersCompiled) $7, (Attributes) $1);
1420 current_type.AddMember (method);
1422 current_local_parameters = (ParametersCompiled) $7;
1425 method.DocComment = Lexer.consume_doc_comment ();
1432 method_declaration_name error
1434 Error_SyntaxError (yyToken);
1435 current_local_parameters = ParametersCompiled.Undefined;
1437 MemberName name = (MemberName) $4;
1438 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1439 name, current_local_parameters, (Attributes) $1);
1441 current_type.AddMember (method);
1444 method.DocComment = Lexer.consume_doc_comment ();
1450 method_body_expression_block
1457 | SEMICOLON { $$ = null; }
1463 if (lang_version < LanguageVersion.V_6) {
1464 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1467 ++lexer.parsing_block;
1468 start_block (GetLocation ($1));
1470 expression SEMICOLON
1472 lexer.parsing_block = 0;
1473 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1474 var b = end_block (GetLocation ($4));
1475 b.IsCompilerGenerated = true;
1480 opt_formal_parameter_list
1481 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1482 | formal_parameter_list
1485 formal_parameter_list
1488 var pars_list = (List<Parameter>) $1;
1489 $$ = new ParametersCompiled (pars_list.ToArray ());
1491 | fixed_parameters COMMA parameter_array
1493 var pars_list = (List<Parameter>) $1;
1494 pars_list.Add ((Parameter) $3);
1496 $$ = new ParametersCompiled (pars_list.ToArray ());
1498 | fixed_parameters COMMA arglist_modifier
1500 var pars_list = (List<Parameter>) $1;
1501 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1502 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1504 | parameter_array COMMA error
1507 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1509 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1511 | fixed_parameters COMMA parameter_array COMMA error
1514 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1516 var pars_list = (List<Parameter>) $1;
1517 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1519 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1521 | arglist_modifier COMMA error
1523 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1525 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1527 | fixed_parameters COMMA ARGLIST COMMA error
1529 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1531 var pars_list = (List<Parameter>) $1;
1532 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1534 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1538 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1542 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1546 Error_SyntaxError (yyToken);
1547 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1554 parameters_bucket.Clear ();
1555 Parameter p = (Parameter) $1;
1556 parameters_bucket.Add (p);
1558 default_parameter_used = p.HasDefaultValue;
1559 $$ = parameters_bucket;
1561 | fixed_parameters COMMA fixed_parameter
1563 var pars = (List<Parameter>) $1;
1564 Parameter p = (Parameter) $3;
1566 if (p.HasExtensionMethodModifier)
1567 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1568 else if (!p.HasDefaultValue && default_parameter_used)
1569 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1571 default_parameter_used |= p.HasDefaultValue;
1574 lbag.AddLocation (p, GetLocation ($2));
1583 opt_parameter_modifier
1585 identifier_inside_body
1587 var lt = (LocatedToken) $4;
1588 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1591 opt_parameter_modifier
1593 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1595 var lt = (LocatedToken) $4;
1596 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1597 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1599 | attribute_sections error
1601 Error_SyntaxError (yyToken);
1602 Location l = GetLocation ($2);
1603 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1606 opt_parameter_modifier
1610 Error_SyntaxError (yyToken);
1611 Location l = GetLocation ($4);
1612 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1615 opt_parameter_modifier
1617 identifier_inside_body
1620 ++lexer.parsing_block;
1624 --lexer.parsing_block;
1625 if (lang_version <= LanguageVersion.V_3) {
1626 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1629 Parameter.Modifier mod = (Parameter.Modifier) $2;
1630 if (mod != Parameter.Modifier.NONE) {
1632 case Parameter.Modifier.REF:
1633 case Parameter.Modifier.OUT:
1634 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1635 Parameter.GetModifierSignature (mod));
1638 case Parameter.Modifier.This:
1639 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1640 Parameter.GetModifierSignature (mod));
1643 throw new NotImplementedException (mod.ToString ());
1646 mod = Parameter.Modifier.NONE;
1649 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1650 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1652 var lt = (LocatedToken) $4;
1653 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1654 lbag.AddLocation ($$, GetLocation ($5));
1657 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1661 opt_parameter_modifier
1662 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1663 | parameter_modifiers
1667 : parameter_modifier
1671 | parameter_modifiers parameter_modifier
1673 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1674 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1675 if (((Parameter.Modifier)$1 & p2) == p2) {
1676 Error_DuplicateParameterModifier (lexer.Location, p2);
1678 switch (mod & ~Parameter.Modifier.This) {
1679 case Parameter.Modifier.REF:
1680 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1682 case Parameter.Modifier.OUT:
1683 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1686 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1697 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1698 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1700 $$ = Parameter.Modifier.REF;
1704 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1705 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1707 $$ = Parameter.Modifier.OUT;
1711 if ((valid_param_mod & ParameterModifierType.This) == 0)
1712 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1714 if (lang_version <= LanguageVersion.ISO_2)
1715 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1717 $$ = Parameter.Modifier.This;
1722 : opt_attributes params_modifier type IDENTIFIER
1724 var lt = (LocatedToken) $4;
1725 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1727 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1729 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1731 var lt = (LocatedToken) $4;
1732 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1734 | opt_attributes params_modifier type error
1736 Error_SyntaxError (yyToken);
1738 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1745 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1746 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1748 | PARAMS parameter_modifier
1750 Parameter.Modifier mod = (Parameter.Modifier)$2;
1751 if ((mod & Parameter.Modifier.This) != 0) {
1752 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1754 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1757 | PARAMS params_modifier
1759 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1766 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1767 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1771 property_declaration
1775 member_declaration_name
1777 lexer.parsing_generic_declaration = false;
1779 tmpComment = Lexer.consume_doc_comment ();
1783 var type = (FullNamedExpression) $3;
1784 current_property = new Property (current_type, type, (Modifiers) $2,
1785 (MemberName) $4, (Attributes) $1);
1787 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1788 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1790 current_type.AddMember (current_property);
1791 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1793 lexer.PropertyParsing = true;
1795 accessor_declarations
1797 lexer.PropertyParsing = false;
1800 current_property.DocComment = ConsumeStoredComment ();
1804 lbag.AppendToMember (current_property, GetLocation ($10));
1805 lexer.parsing_modifiers = true;
1807 opt_property_initializer
1809 current_property = null;
1814 member_declaration_name
1816 lexer.parsing_generic_declaration = false;
1818 tmpComment = Lexer.consume_doc_comment ();
1819 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1823 var type = (FullNamedExpression) $3;
1824 var property = new Property (current_type, type, (Modifiers) $2,
1825 (MemberName) $4, (Attributes) $1);
1827 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1828 property.Get.Block = (ToplevelBlock) $6;
1830 if (current_container.Kind == MemberKind.Interface) {
1831 report.Error (531, property.Get.Block.StartLocation,
1832 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1835 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1836 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1838 current_type.AddMember (property);
1840 current_local_parameters = null;
1844 opt_property_initializer
1848 ++lexer.parsing_block;
1849 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1850 start_block (GetLocation ($1));
1852 property_initializer SEMICOLON
1854 --lexer.parsing_block;
1855 ((Property)current_property).Initializer = (Expression) $3;
1856 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1857 end_block (GetLocation ($4));
1858 current_local_parameters = null;
1862 property_initializer
1868 : opt_attributes opt_modifiers
1869 member_type indexer_declaration_name OPEN_BRACKET
1871 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1873 opt_formal_parameter_list CLOSE_BRACKET
1875 valid_param_mod = 0;
1876 var type = (FullNamedExpression) $3;
1877 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1879 current_property = indexer;
1881 current_type.AddIndexer (indexer);
1882 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1884 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1885 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1887 if (indexer.ParameterInfo.IsEmpty) {
1888 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1892 tmpComment = Lexer.consume_doc_comment ();
1893 Lexer.doc_state = XmlCommentState.Allowed;
1896 lexer.PropertyParsing = true;
1897 current_local_parameters = (ParametersCompiled) $7;
1901 lexer.PropertyParsing = false;
1902 current_local_parameters = null;
1904 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1905 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1908 current_property.DocComment = ConsumeStoredComment ();
1910 current_property = null;
1915 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1917 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1921 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1922 current_property.Get.Block = (ToplevelBlock) $1;
1926 accessor_declarations
1927 : get_accessor_declaration
1928 | get_accessor_declaration accessor_declarations
1929 | set_accessor_declaration
1930 | set_accessor_declaration accessor_declarations
1933 if (yyToken == Token.CLOSE_BRACE) {
1934 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1936 if (yyToken == Token.SEMICOLON)
1937 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1939 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1944 get_accessor_declaration
1945 : opt_attributes opt_modifiers GET
1947 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1948 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1951 if (current_property.Get != null) {
1952 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1955 if (current_property is Indexer) {
1956 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1957 (Attributes) $1, GetLocation ($3));
1959 current_property.Get = new Property.GetMethod (current_property,
1960 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1963 current_local_parameters = current_property.Get.ParameterInfo;
1964 lbag.AddMember (current_property.Get, mod_locations);
1965 lexer.PropertyParsing = false;
1970 current_property.Get.Block = (ToplevelBlock) $5;
1972 if (current_container.Kind == MemberKind.Interface) {
1973 report.Error (531, current_property.Get.Block.StartLocation,
1974 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1978 current_local_parameters = null;
1979 lexer.PropertyParsing = true;
1982 if (Lexer.doc_state == XmlCommentState.Error)
1983 Lexer.doc_state = XmlCommentState.NotAllowed;
1987 set_accessor_declaration
1988 : opt_attributes opt_modifiers SET
1990 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1991 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1994 if (current_property.Set != null) {
1995 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1998 if (current_property is Indexer) {
1999 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2000 ParametersCompiled.MergeGenerated (compiler,
2001 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2002 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2004 (Attributes) $1, GetLocation ($3));
2006 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2007 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2008 (Attributes) $1, GetLocation ($3));
2011 current_local_parameters = current_property.Set.ParameterInfo;
2012 lbag.AddMember (current_property.Set, mod_locations);
2013 lexer.PropertyParsing = false;
2018 current_property.Set.Block = (ToplevelBlock) $5;
2020 if (current_container.Kind == MemberKind.Interface) {
2021 report.Error (531, current_property.Set.Block.StartLocation,
2022 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2026 current_local_parameters = null;
2027 lexer.PropertyParsing = true;
2030 && Lexer.doc_state == XmlCommentState.Error)
2031 Lexer.doc_state = XmlCommentState.NotAllowed;
2044 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2049 interface_declaration
2056 type_declaration_name
2058 lexer.ConstraintsParsing = true;
2059 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2060 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2063 opt_type_parameter_constraints_clauses
2065 lexer.ConstraintsParsing = false;
2068 current_container.SetConstraints ((List<Constraints>) $9);
2071 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2072 Lexer.doc_state = XmlCommentState.Allowed;
2075 lexer.parsing_modifiers = true;
2077 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2079 --lexer.parsing_declaration;
2081 Lexer.doc_state = XmlCommentState.Allowed;
2086 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2088 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2090 $$ = pop_current_class ();
2092 | opt_attributes opt_modifiers opt_partial INTERFACE error
2094 Error_SyntaxError (yyToken);
2098 opt_interface_member_declarations
2100 | interface_member_declarations
2103 interface_member_declarations
2104 : interface_member_declaration
2106 lexer.parsing_modifiers = true;
2107 lexer.parsing_block = 0;
2109 | interface_member_declarations interface_member_declaration
2111 lexer.parsing_modifiers = true;
2112 lexer.parsing_block = 0;
2116 interface_member_declaration
2117 : constant_declaration
2119 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2123 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2125 | method_declaration
2126 | property_declaration
2128 | indexer_declaration
2129 | operator_declaration
2131 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2133 | constructor_declaration
2135 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2139 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2143 operator_declaration
2144 : opt_attributes opt_modifiers operator_declarator
2147 method_body_expression_block
2149 OperatorDeclaration decl = (OperatorDeclaration) $3;
2151 Operator op = new Operator (
2152 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2153 current_local_parameters,
2154 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2156 if (op.Block == null)
2157 op.ParameterInfo.CheckParameters (op);
2160 op.DocComment = tmpComment;
2161 Lexer.doc_state = XmlCommentState.Allowed;
2164 // Note again, checking is done in semantic analysis
2165 current_type.AddOperator (op);
2167 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2170 current_local_parameters = null;
2175 : type_expression_or_array
2178 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2179 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2184 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2186 valid_param_mod = ParameterModifierType.DefaultValue;
2187 if ((Operator.OpType) $3 == Operator.OpType.Is)
2188 valid_param_mod |= ParameterModifierType.Out;
2190 opt_formal_parameter_list CLOSE_PARENS
2192 valid_param_mod = 0;
2194 Location loc = GetLocation ($2);
2195 Operator.OpType op = (Operator.OpType) $3;
2196 current_local_parameters = (ParametersCompiled)$6;
2198 int p_count = current_local_parameters.Count;
2200 if (op == Operator.OpType.Addition)
2201 op = Operator.OpType.UnaryPlus;
2202 else if (op == Operator.OpType.Subtraction)
2203 op = Operator.OpType.UnaryNegation;
2206 if (IsUnaryOperator (op)) {
2208 report.Error (1020, loc, "Overloadable binary operator expected");
2209 } else if (p_count != 1) {
2210 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2211 Operator.GetName (op));
2213 } else if (op == Operator.OpType.Is) {
2214 // TODO: Special checks for is operator
2217 report.Error (1019, loc, "Overloadable unary operator expected");
2218 } else if (p_count != 2) {
2219 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2220 Operator.GetName (op));
2225 tmpComment = Lexer.consume_doc_comment ();
2226 Lexer.doc_state = XmlCommentState.NotAllowed;
2229 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2230 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2232 | conversion_operator_declarator
2235 overloadable_operator
2237 : BANG { $$ = Operator.OpType.LogicalNot; }
2238 | TILDE { $$ = Operator.OpType.OnesComplement; }
2239 | OP_INC { $$ = Operator.OpType.Increment; }
2240 | OP_DEC { $$ = Operator.OpType.Decrement; }
2241 | TRUE { $$ = Operator.OpType.True; }
2242 | FALSE { $$ = Operator.OpType.False; }
2243 // Unary and binary:
2244 | PLUS { $$ = Operator.OpType.Addition; }
2245 | MINUS { $$ = Operator.OpType.Subtraction; }
2247 | STAR { $$ = Operator.OpType.Multiply; }
2248 | DIV { $$ = Operator.OpType.Division; }
2249 | PERCENT { $$ = Operator.OpType.Modulus; }
2250 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2251 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2252 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2253 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2254 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2255 | OP_EQ { $$ = Operator.OpType.Equality; }
2256 | OP_NE { $$ = Operator.OpType.Inequality; }
2257 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2258 | OP_LT { $$ = Operator.OpType.LessThan; }
2259 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2260 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2263 if (lang_version != LanguageVersion.Experimental)
2264 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2266 $$ = Operator.OpType.Is;
2270 conversion_operator_declarator
2271 : IMPLICIT OPERATOR type OPEN_PARENS
2273 valid_param_mod = ParameterModifierType.DefaultValue;
2275 opt_formal_parameter_list CLOSE_PARENS
2277 valid_param_mod = 0;
2279 Location loc = GetLocation ($2);
2280 current_local_parameters = (ParametersCompiled)$6;
2282 if (current_local_parameters.Count != 1) {
2283 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2287 tmpComment = Lexer.consume_doc_comment ();
2288 Lexer.doc_state = XmlCommentState.NotAllowed;
2291 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2292 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2294 | EXPLICIT OPERATOR type OPEN_PARENS
2296 valid_param_mod = ParameterModifierType.DefaultValue;
2298 opt_formal_parameter_list CLOSE_PARENS
2300 valid_param_mod = 0;
2302 Location loc = GetLocation ($2);
2303 current_local_parameters = (ParametersCompiled)$6;
2305 if (current_local_parameters.Count != 1) {
2306 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2310 tmpComment = Lexer.consume_doc_comment ();
2311 Lexer.doc_state = XmlCommentState.NotAllowed;
2314 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2315 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2319 Error_SyntaxError (yyToken);
2320 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2321 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2325 Error_SyntaxError (yyToken);
2326 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2327 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2331 constructor_declaration
2332 : constructor_declarator
2335 Constructor c = (Constructor) $1;
2336 c.Block = (ToplevelBlock) $2;
2339 c.DocComment = ConsumeStoredComment ();
2341 current_local_parameters = null;
2343 Lexer.doc_state = XmlCommentState.Allowed;
2347 constructor_declarator
2353 tmpComment = Lexer.consume_doc_comment ();
2354 Lexer.doc_state = XmlCommentState.Allowed;
2357 valid_param_mod = ParameterModifierType.All;
2359 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2361 valid_param_mod = 0;
2362 current_local_parameters = (ParametersCompiled) $6;
2364 var lt = (LocatedToken) $3;
2365 var mods = (Modifiers) $2;
2366 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2368 if (lt.Value != current_container.MemberName.Name) {
2369 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2370 } else if ((mods & Modifiers.STATIC) != 0) {
2371 if (!current_local_parameters.IsEmpty) {
2372 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2373 c.GetSignatureForError ());
2376 if ((mods & Modifiers.AccessibilityMask) != 0){
2377 report.Error (515, c.Location,
2378 "`{0}': static constructor cannot have an access modifier",
2379 c.GetSignatureForError ());
2382 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2383 if (lang_version < LanguageVersion.V_6)
2384 FeatureIsNotAvailable (GetLocation ($3), "struct parameterless instance constructor");
2386 if ((mods & Modifiers.PUBLIC) == 0) {
2387 report.Error (8075, c.Location, "`{0}': Structs parameterless instance constructor must be public", c.GetSignatureForError ());
2392 current_type.AddConstructor (c);
2393 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2397 // start block here, so possible anonymous methods inside
2398 // constructor initializer can get correct parent block
2400 start_block (lexer.Location);
2402 opt_constructor_initializer
2405 var c = (Constructor) $8;
2406 c.Initializer = (ConstructorInitializer) $9;
2409 report.Error (514, c.Location,
2410 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2411 c.GetSignatureForError ());
2421 | SEMICOLON { current_block = null; $$ = null; }
2424 opt_constructor_initializer
2426 | constructor_initializer
2429 constructor_initializer
2430 : COLON BASE OPEN_PARENS
2432 ++lexer.parsing_block;
2434 opt_argument_list CLOSE_PARENS
2436 --lexer.parsing_block;
2437 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2438 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2440 | COLON THIS OPEN_PARENS
2442 ++lexer.parsing_block;
2444 opt_argument_list CLOSE_PARENS
2446 --lexer.parsing_block;
2447 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2448 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2452 Error_SyntaxError (yyToken);
2453 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2454 lbag.AddLocation ($$, GetLocation ($1));
2458 Error_SyntaxError (yyToken);
2463 destructor_declaration
2464 : opt_attributes opt_modifiers TILDE
2467 tmpComment = Lexer.consume_doc_comment ();
2468 Lexer.doc_state = XmlCommentState.NotAllowed;
2471 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2473 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2475 var lt = (LocatedToken) $5;
2476 if (lt.Value != current_container.MemberName.Name){
2477 report.Error (574, lt.Location, "Name of destructor must match name of class");
2478 } else if (current_container.Kind != MemberKind.Class){
2479 report.Error (575, lt.Location, "Only class types can contain destructor");
2482 Destructor d = new Destructor (current_type, (Modifiers) $2,
2483 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2485 d.DocComment = ConsumeStoredComment ();
2487 d.Block = (ToplevelBlock) $8;
2488 current_type.AddMember (d);
2489 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2491 current_local_parameters = null;
2498 EVENT type member_declaration_name
2500 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2501 current_type.AddMember (current_event_field);
2503 if (current_event_field.MemberName.ExplicitInterface != null) {
2504 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2505 current_event_field.GetSignatureForError ());
2508 $$ = current_event_field;
2510 opt_event_initializer
2511 opt_event_declarators
2515 current_event_field.DocComment = Lexer.consume_doc_comment ();
2516 Lexer.doc_state = XmlCommentState.Allowed;
2519 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2520 current_event_field = null;
2524 EVENT type member_declaration_name
2527 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2528 current_type.AddMember (current_event);
2529 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2531 lexer.EventParsing = true;
2533 event_accessor_declarations
2535 if (current_container.Kind == MemberKind.Interface)
2536 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2538 lexer.EventParsing = false;
2543 current_event.DocComment = Lexer.consume_doc_comment ();
2544 Lexer.doc_state = XmlCommentState.Allowed;
2547 lbag.AppendToMember (current_event, GetLocation ($9));
2548 current_event = null;
2549 current_local_parameters = null;
2555 Error_SyntaxError (yyToken);
2557 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2561 opt_event_initializer
2565 ++lexer.parsing_block;
2567 event_variable_initializer
2569 --lexer.parsing_block;
2570 current_event_field.Initializer = (Expression) $3;
2574 opt_event_declarators
2582 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2584 | event_declarators event_declarator
2586 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2593 var lt = (LocatedToken) $2;
2594 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2595 lbag.AddLocation ($$, GetLocation ($1));
2597 | COMMA IDENTIFIER ASSIGN
2599 ++lexer.parsing_block;
2601 event_variable_initializer
2603 --lexer.parsing_block;
2604 var lt = (LocatedToken) $2;
2605 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2606 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2610 event_variable_initializer
2612 if (current_container.Kind == MemberKind.Interface) {
2613 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2614 current_event_field.GetSignatureForError ());
2617 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2618 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2619 current_event_field.GetSignatureForError ());
2622 variable_initializer
2628 event_accessor_declarations
2629 : add_accessor_declaration remove_accessor_declaration
2630 | remove_accessor_declaration add_accessor_declaration
2631 | add_accessor_declaration
2633 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2634 current_event.GetSignatureForError ());
2636 | remove_accessor_declaration
2638 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2639 current_event.GetSignatureForError ());
2643 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2648 add_accessor_declaration
2649 : opt_attributes opt_modifiers ADD
2651 if ($2 != ModifierNone) {
2652 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2655 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2656 current_local_parameters = current_event.Add.ParameterInfo;
2658 lbag.AddMember (current_event.Add, mod_locations);
2659 lexer.EventParsing = false;
2661 event_accessor_block
2663 lexer.EventParsing = true;
2665 current_event.Add.Block = (ToplevelBlock) $5;
2667 if (current_container.Kind == MemberKind.Interface) {
2668 report.Error (531, current_event.Add.Block.StartLocation,
2669 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2672 current_local_parameters = null;
2676 remove_accessor_declaration
2677 : opt_attributes opt_modifiers REMOVE
2679 if ($2 != ModifierNone) {
2680 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2683 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2684 current_local_parameters = current_event.Remove.ParameterInfo;
2686 lbag.AddMember (current_event.Remove, mod_locations);
2687 lexer.EventParsing = false;
2689 event_accessor_block
2691 lexer.EventParsing = true;
2693 current_event.Remove.Block = (ToplevelBlock) $5;
2695 if (current_container.Kind == MemberKind.Interface) {
2696 report.Error (531, current_event.Remove.Block.StartLocation,
2697 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2700 current_local_parameters = null;
2704 event_accessor_block
2707 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2713 attributes_without_members
2714 : attribute_sections CLOSE_BRACE
2716 current_type.UnattachedAttributes = (Attributes) $1;
2717 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2718 lexer.putback ('}');
2722 // For full ast try to recover incomplete ambiguous member
2723 // declaration in form on class X { public int }
2725 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2727 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2729 lexer.putback ('}');
2731 lexer.parsing_generic_declaration = false;
2732 FullNamedExpression type = (FullNamedExpression) $3;
2733 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2734 current_type.AddField (current_field);
2742 ENUM type_declaration_name
2746 enumTypeComment = Lexer.consume_doc_comment ();
2751 Lexer.doc_state = XmlCommentState.Allowed;
2753 MemberName name = (MemberName) $4;
2754 if (name.IsGeneric) {
2755 report.Error (1675, name.Location, "Enums cannot have type parameters");
2758 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2760 opt_enum_member_declarations
2762 lexer.parsing_modifiers = true;
2764 // here will be evaluated after CLOSE_BLACE is consumed.
2766 Lexer.doc_state = XmlCommentState.Allowed;
2768 CLOSE_BRACE opt_semicolon
2771 current_container.DocComment = enumTypeComment;
2773 --lexer.parsing_declaration;
2776 // em.DocComment = ev.DocComment;
2778 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2779 $$ = pop_current_class ();
2791 Error_TypeExpected (GetLocation ($1));
2796 opt_enum_member_declarations
2798 | enum_member_declarations
2799 | enum_member_declarations COMMA
2801 lbag.AddLocation ($1, GetLocation ($2));
2805 enum_member_declarations
2806 : enum_member_declaration
2807 | enum_member_declarations COMMA enum_member_declaration
2809 lbag.AddLocation ($1, GetLocation ($2));
2814 enum_member_declaration
2815 : opt_attributes IDENTIFIER
2817 var lt = (LocatedToken) $2;
2818 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2819 ((Enum) current_type).AddEnumMember (em);
2822 em.DocComment = Lexer.consume_doc_comment ();
2823 Lexer.doc_state = XmlCommentState.Allowed;
2828 | opt_attributes IDENTIFIER
2830 ++lexer.parsing_block;
2832 tmpComment = Lexer.consume_doc_comment ();
2833 Lexer.doc_state = XmlCommentState.NotAllowed;
2836 ASSIGN constant_expression
2838 --lexer.parsing_block;
2840 var lt = (LocatedToken) $2;
2841 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2842 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2843 ((Enum) current_type).AddEnumMember (em);
2846 em.DocComment = ConsumeStoredComment ();
2850 | opt_attributes IDENTIFIER error
2852 Error_SyntaxError (yyToken);
2854 var lt = (LocatedToken) $2;
2855 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2856 ((Enum) current_type).AddEnumMember (em);
2859 em.DocComment = Lexer.consume_doc_comment ();
2860 Lexer.doc_state = XmlCommentState.Allowed;
2865 | attributes_without_members
2868 delegate_declaration
2872 member_type type_declaration_name
2875 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2877 opt_formal_parameter_list CLOSE_PARENS
2879 valid_param_mod = 0;
2881 ParametersCompiled p = (ParametersCompiled) $8;
2883 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2885 p.CheckParameters (del);
2887 current_container.AddTypeContainer (del);
2889 current_delegate = del;
2890 lexer.ConstraintsParsing = true;
2892 opt_type_parameter_constraints_clauses
2894 lexer.ConstraintsParsing = false;
2899 current_delegate.DocComment = Lexer.consume_doc_comment ();
2900 Lexer.doc_state = XmlCommentState.Allowed;
2904 current_delegate.SetConstraints ((List<Constraints>) $11);
2905 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2907 $$ = current_delegate;
2909 current_delegate = null;
2917 if (lang_version < LanguageVersion.ISO_2)
2918 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2920 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2924 namespace_or_type_expr
2926 | qualified_alias_member IDENTIFIER opt_type_argument_list
2928 var lt1 = (LocatedToken) $1;
2929 var lt2 = (LocatedToken) $2;
2931 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2932 lbag.AddLocation ($$, GetLocation ($2));
2934 | qualified_alias_member IDENTIFIER generic_dimension
2936 var lt1 = (LocatedToken) $1;
2937 var lt2 = (LocatedToken) $2;
2939 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2940 lbag.AddLocation ($$, GetLocation ($2));
2946 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2948 var lt = (LocatedToken) $3;
2949 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2950 lbag.AddLocation ($$, GetLocation ($2));
2952 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2954 var lt = (LocatedToken) $3;
2955 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2956 lbag.AddLocation ($$, GetLocation ($2));
2961 : IDENTIFIER opt_type_argument_list
2963 var lt = (LocatedToken) $1;
2964 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2966 | IDENTIFIER generic_dimension
2968 var lt = (LocatedToken) $1;
2969 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2974 // Generics arguments (any type, without attributes)
2976 opt_type_argument_list
2978 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2980 if (lang_version < LanguageVersion.ISO_2)
2981 FeatureIsNotAvailable (GetLocation ($1), "generics");
2985 | OP_GENERICS_LT error
2987 Error_TypeExpected (lexer.Location);
2988 $$ = new TypeArguments ();
2995 TypeArguments type_args = new TypeArguments ();
2996 type_args.Add ((FullNamedExpression) $1);
2999 | type_arguments COMMA type
3001 TypeArguments type_args = (TypeArguments) $1;
3002 type_args.Add ((FullNamedExpression) $3);
3008 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3010 type_declaration_name
3013 lexer.parsing_generic_declaration = true;
3015 opt_type_parameter_list
3017 lexer.parsing_generic_declaration = false;
3018 var lt = (LocatedToken) $1;
3019 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3023 member_declaration_name
3024 : method_declaration_name
3026 MemberName mn = (MemberName)$1;
3027 if (mn.TypeParameters != null)
3028 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3029 mn.GetSignatureForError ()));
3033 method_declaration_name
3034 : type_declaration_name
3035 | explicit_interface IDENTIFIER opt_type_parameter_list
3037 lexer.parsing_generic_declaration = false;
3038 var lt = (LocatedToken) $2;
3039 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3043 indexer_declaration_name
3046 lexer.parsing_generic_declaration = false;
3047 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3049 | explicit_interface THIS
3051 lexer.parsing_generic_declaration = false;
3052 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3057 : IDENTIFIER opt_type_argument_list DOT
3059 var lt = (LocatedToken) $1;
3060 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3061 lbag.AddLocation ($$, GetLocation ($3));
3063 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3065 var lt1 = (LocatedToken) $1;
3066 var lt2 = (LocatedToken) $2;
3068 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3069 lbag.AddLocation ($$, GetLocation ($4));
3071 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3073 var lt = (LocatedToken) $2;
3074 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3075 lbag.AddLocation ($$, GetLocation ($4));
3079 opt_type_parameter_list
3081 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3083 if (lang_version < LanguageVersion.ISO_2)
3084 FeatureIsNotAvailable (GetLocation ($1), "generics");
3087 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3094 var tparams = new TypeParameters ();
3095 tparams.Add ((TypeParameter)$1);
3098 | type_parameters COMMA type_parameter
3100 var tparams = (TypeParameters) $1;
3101 tparams.Add ((TypeParameter)$3);
3103 lbag.AddLocation ($3, GetLocation ($3));
3108 : opt_attributes opt_type_parameter_variance IDENTIFIER
3110 var lt = (LocatedToken)$3;
3111 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3115 if (GetTokenName (yyToken) == "type")
3116 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3118 Error_SyntaxError (yyToken);
3120 $$ = new TypeParameter (MemberName.Null, null, null);
3125 // All types where void is allowed
3128 : type_expression_or_array
3131 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3138 lexer.parsing_generic_declaration = true;
3143 // A type which does not allow `void' to be used
3146 : type_expression_or_array
3156 : type_expression_or_array
3159 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3160 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3164 type_expression_or_array
3166 | type_expression rank_specifiers
3168 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3173 : namespace_or_type_expr opt_nullable
3176 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3178 var sn = $1 as SimpleName;
3179 if (sn != null && sn.Name == "var")
3180 $$ = new VarExpr (sn.Location);
3185 | namespace_or_type_expr pointer_stars
3187 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3189 | builtin_type_expression
3195 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3196 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3200 builtin_type_expression
3201 : builtin_types opt_nullable
3204 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3206 | builtin_types pointer_stars
3208 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3210 | VOID pointer_stars
3212 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3219 var types = new List<FullNamedExpression> (2);
3220 types.Add ((FullNamedExpression) $1);
3223 | type_list COMMA base_type_name
3225 var types = (List<FullNamedExpression>) $1;
3226 types.Add ((FullNamedExpression) $3);
3234 if ($1 is ComposedCast) {
3235 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3242 * replaces all the productions for isolating the various
3243 * simple types, but we need this to reuse it easily in variable_type
3246 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3247 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3248 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3249 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3250 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3251 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3256 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3257 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3258 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3259 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3260 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3261 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3262 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3263 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3264 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3268 // Expressions, section 7.5
3273 : type_name_expression
3275 | array_creation_expression
3276 | parenthesized_expression
3277 | default_value_expression
3278 | invocation_expression
3282 | post_increment_expression
3283 | post_decrement_expression
3284 | object_or_delegate_creation_expression
3285 | anonymous_type_expression
3288 | checked_expression
3289 | unchecked_expression
3290 | pointer_member_access
3291 | anonymous_method_expression
3292 | undocumented_expressions
3295 type_name_expression
3297 | IDENTIFIER GENERATE_COMPLETION {
3298 var lt = (LocatedToken) $1;
3299 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3307 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3311 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3312 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3317 // Here is the trick, tokenizer may think that parens is a special but
3318 // parser is interested in open parens only, so we merge them.
3319 // Consider: if (a)foo ();
3327 // Use this production to accept closing parenthesis or
3328 // performing completion
3332 | COMPLETE_COMPLETION
3336 parenthesized_expression
3337 : OPEN_PARENS expression CLOSE_PARENS
3339 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3340 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3342 | OPEN_PARENS expression COMPLETE_COMPLETION
3344 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3349 : primary_expression DOT identifier_inside_body opt_type_argument_list
3351 var lt = (LocatedToken) $3;
3352 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3353 lbag.AddLocation ($$, GetLocation ($2));
3355 | primary_expression DOT identifier_inside_body generic_dimension
3357 var lt = (LocatedToken) $3;
3358 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3359 lbag.AddLocation ($$, GetLocation ($2));
3361 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3363 if (lang_version < LanguageVersion.V_6)
3364 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3366 var lt = (LocatedToken) $4;
3367 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3368 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3370 | builtin_types DOT identifier_inside_body opt_type_argument_list
3372 var lt = (LocatedToken) $3;
3373 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3374 lbag.AddLocation ($$, GetLocation ($2));
3376 | BASE DOT identifier_inside_body opt_type_argument_list
3378 var lt = (LocatedToken) $3;
3379 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3380 lbag.AddLocation ($$, GetLocation ($2));
3382 | AWAIT DOT identifier_inside_body opt_type_argument_list
3384 var lt = (LocatedToken) $3;
3385 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3386 lbag.AddLocation ($$, GetLocation ($2));
3388 | qualified_alias_member identifier_inside_body opt_type_argument_list
3390 var lt1 = (LocatedToken) $1;
3391 var lt2 = (LocatedToken) $2;
3393 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3394 lbag.AddLocation ($$, GetLocation ($2));
3396 | qualified_alias_member identifier_inside_body generic_dimension
3398 var lt1 = (LocatedToken) $1;
3399 var lt2 = (LocatedToken) $2;
3401 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3402 lbag.AddLocation ($$, GetLocation ($2));
3404 | primary_expression DOT GENERATE_COMPLETION {
3405 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3407 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3408 var lt = (LocatedToken) $3;
3409 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3411 | builtin_types DOT GENERATE_COMPLETION
3413 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3415 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3416 var lt = (LocatedToken) $3;
3417 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3421 invocation_expression
3422 : primary_expression open_parens_any opt_argument_list close_parens
3424 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3425 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3427 | primary_expression open_parens_any argument_list error
3429 Error_SyntaxError (yyToken);
3431 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3432 lbag.AddLocation ($$, GetLocation ($2));
3434 | primary_expression open_parens_any error
3436 Error_SyntaxError (yyToken);
3438 $$ = new Invocation ((Expression) $1, null);
3439 lbag.AddLocation ($$, GetLocation ($2));
3443 opt_object_or_collection_initializer
3444 : /* empty */ { $$ = null; }
3445 | object_or_collection_initializer
3448 object_or_collection_initializer
3449 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3452 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3454 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3456 lbag.AddLocation ($$, GetLocation ($3));
3458 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3460 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3461 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3465 opt_member_initializer_list
3466 : /* empty */ { $$ = null; }
3467 | member_initializer_list
3473 member_initializer_list
3474 : member_initializer
3476 var a = new List<Expression> ();
3477 a.Add ((Expression) $1);
3480 | member_initializer_list COMMA member_initializer
3482 var a = (List<Expression>)$1;
3483 a.Add ((Expression) $3);
3486 | member_initializer_list error {
3487 Error_SyntaxError (yyToken);
3493 : IDENTIFIER ASSIGN initializer_value
3495 var lt = (LocatedToken) $1;
3496 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3497 lbag.AddLocation ($$, GetLocation ($2));
3499 | AWAIT ASSIGN initializer_value
3501 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3502 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3503 lbag.AddLocation ($$, GetLocation ($2));
3505 | GENERATE_COMPLETION
3507 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3509 | non_assignment_expression opt_COMPLETE_COMPLETION {
3510 CompletionSimpleName csn = $1 as CompletionSimpleName;
3512 $$ = new CollectionElementInitializer ((Expression)$1);
3514 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3516 | OPEN_BRACE expression_list CLOSE_BRACE
3519 $$ = new CollectionElementInitializer (GetLocation ($1));
3521 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3523 lbag.AddLocation ($$, GetLocation ($3));
3525 | OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET ASSIGN initializer_value
3527 if (lang_version < LanguageVersion.V_6)
3528 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3530 $$ = new DictionaryElementInitializer ((List<Expression>)$2, (Expression) $5, GetLocation ($1));
3531 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3533 | OPEN_BRACE CLOSE_BRACE
3535 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3536 $$ = new CollectionElementInitializer (GetLocation ($1));
3537 lbag.AddLocation ($$, GetLocation ($2));
3543 | object_or_collection_initializer
3547 : /* empty */ { $$ = null; }
3552 : argument_or_named_argument
3554 Arguments list = new Arguments (4);
3555 list.Add ((Argument) $1);
3558 | argument_list COMMA argument
3560 Arguments list = (Arguments) $1;
3561 if (list [list.Count - 1] is NamedArgument)
3562 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3564 list.Add ((Argument) $3);
3567 | argument_list COMMA named_argument
3569 Arguments list = (Arguments) $1;
3570 NamedArgument a = (NamedArgument) $3;
3571 for (int i = 0; i < list.Count; ++i) {
3572 NamedArgument na = list [i] as NamedArgument;
3573 if (na != null && na.Name == a.Name)
3574 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3581 | argument_list COMMA error
3583 if (lexer.putback_char == -1)
3584 lexer.putback (')'); // TODO: Wrong but what can I do
3585 Error_SyntaxError (yyToken);
3590 report.Error (839, GetLocation ($1), "An argument is missing");
3598 $$ = new Argument ((Expression) $1);
3600 | non_simple_argument
3603 argument_or_named_argument
3609 : REF variable_reference
3611 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3612 lbag.AddLocation ($$, GetLocation ($1));
3614 | REF declaration_expression
3616 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3618 | OUT variable_reference
3620 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3621 lbag.AddLocation ($$, GetLocation ($1));
3623 | OUT declaration_expression
3625 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3627 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3629 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3630 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3632 | ARGLIST OPEN_PARENS CLOSE_PARENS
3634 $$ = new Argument (new Arglist (GetLocation ($1)));
3635 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3639 declaration_expression
3640 : OPEN_PARENS declaration_expression CLOSE_PARENS
3642 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3643 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3646 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3648 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3649 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3651 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3653 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3654 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3657 | variable_type identifier_inside_body
3659 if (lang_version < LanguageVersion.V_6)
3660 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3662 var lt = (LocatedToken) $2;
3663 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3664 current_block.AddLocalName (lv);
3665 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3667 | variable_type identifier_inside_body ASSIGN expression
3669 if (lang_version < LanguageVersion.V_6)
3670 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3672 var lt = (LocatedToken) $2;
3673 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3674 current_block.AddLocalName (lv);
3675 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3676 Initializer = (Expression) $4
3686 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3688 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3689 lbag.AddLocation ($$, GetLocation ($4));
3691 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3693 if (lang_version < LanguageVersion.V_6)
3694 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3696 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3697 ConditionalAccess = true
3700 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3702 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3704 Error_SyntaxError (yyToken);
3705 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3707 | primary_expression OPEN_BRACKET_EXPR error
3709 Error_SyntaxError (yyToken);
3710 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3715 : expression_or_error
3717 var list = new List<Expression> (4);
3718 list.Add ((Expression) $1);
3721 | expression_list COMMA expression_or_error
3723 var list = (List<Expression>) $1;
3724 list.Add ((Expression) $3);
3729 expression_list_arguments
3730 : expression_list_argument
3732 Arguments args = new Arguments (4);
3733 args.Add ((Argument) $1);
3736 | expression_list_arguments COMMA expression_list_argument
3738 Arguments args = (Arguments) $1;
3739 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3740 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3742 args.Add ((Argument) $3);
3747 expression_list_argument
3750 $$ = new Argument ((Expression) $1);
3758 $$ = new This (GetLocation ($1));
3763 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3765 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3766 lbag.AddLocation ($$, GetLocation ($4));
3768 | BASE OPEN_BRACKET error
3770 Error_SyntaxError (yyToken);
3771 $$ = new ElementAccess (null, null, GetLocation ($2));
3775 post_increment_expression
3776 : primary_expression OP_INC
3778 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3782 post_decrement_expression
3783 : primary_expression OP_DEC
3785 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3789 object_or_delegate_creation_expression
3790 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3793 if (lang_version <= LanguageVersion.ISO_2)
3794 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3796 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3798 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3801 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3803 | NEW new_expr_type object_or_collection_initializer
3805 if (lang_version <= LanguageVersion.ISO_2)
3806 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3808 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3812 array_creation_expression
3813 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3815 opt_array_initializer
3817 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3818 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3819 Next = (ComposedTypeSpecifier) $6
3820 }, (ArrayInitializer) $7, GetLocation ($1));
3821 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3823 | NEW new_expr_type rank_specifiers opt_array_initializer
3826 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3828 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3830 | NEW rank_specifier array_initializer
3832 if (lang_version <= LanguageVersion.ISO_2)
3833 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3835 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3837 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3839 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3840 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3842 | NEW new_expr_type error
3844 Error_SyntaxError (yyToken);
3845 // It can be any of new expression, create the most common one
3846 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3852 ++lexer.parsing_type;
3856 --lexer.parsing_type;
3861 anonymous_type_expression
3862 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3864 if (lang_version <= LanguageVersion.ISO_2)
3865 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3867 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3869 // TODO: lbag comma location
3870 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3872 | NEW OPEN_BRACE GENERATE_COMPLETION
3874 $$ = new EmptyCompletion ();
3878 anonymous_type_parameters_opt_comma
3879 : anonymous_type_parameters_opt
3880 | anonymous_type_parameters COMMA
3883 anonymous_type_parameters_opt
3885 | anonymous_type_parameters
3888 anonymous_type_parameters
3889 : anonymous_type_parameter
3891 var a = new List<AnonymousTypeParameter> (4);
3892 a.Add ((AnonymousTypeParameter) $1);
3895 | anonymous_type_parameters COMMA anonymous_type_parameter
3897 var a = (List<AnonymousTypeParameter>) $1;
3898 a.Add ((AnonymousTypeParameter) $3);
3901 | COMPLETE_COMPLETION
3903 $$ = new EmptyCompletion ();
3905 | anonymous_type_parameter COMPLETE_COMPLETION
3911 anonymous_type_parameter
3912 : identifier_inside_body ASSIGN variable_initializer
3914 var lt = (LocatedToken)$1;
3915 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3916 lbag.AddLocation ($$, GetLocation ($2));
3918 | identifier_inside_body
3920 var lt = (LocatedToken)$1;
3921 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3922 lt.Value, lt.Location);
3926 MemberAccess ma = (MemberAccess) $1;
3927 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3931 report.Error (746, lexer.Location,
3932 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3944 | rank_specifier rank_specifiers
3946 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3952 : OPEN_BRACKET CLOSE_BRACKET
3954 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3955 lbag.AddLocation ($$, GetLocation ($2));
3957 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3959 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3960 lbag.AddLocation ($$, GetLocation ($3));
3969 | dim_separators COMMA
3971 $$ = ((int) $1) + 1;
3975 opt_array_initializer
3987 : OPEN_BRACE CLOSE_BRACE
3989 var ai = new ArrayInitializer (0, GetLocation ($1));
3990 ai.VariableDeclaration = current_variable;
3991 lbag.AddLocation (ai, GetLocation ($2));
3994 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3996 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3997 ai.VariableDeclaration = current_variable;
3999 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4001 lbag.AddLocation (ai, GetLocation ($4));
4007 variable_initializer_list
4008 : variable_initializer
4010 var list = new List<Expression> (4);
4011 list.Add ((Expression) $1);
4014 | variable_initializer_list COMMA variable_initializer
4016 var list = (List<Expression>) $1;
4017 list.Add ((Expression) $3);
4023 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4025 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4026 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4030 typeof_type_expression
4034 Error_TypeExpected (lexer.Location);
4042 if (lang_version < LanguageVersion.ISO_2)
4043 FeatureIsNotAvailable (GetLocation ($1), "generics");
4049 qualified_alias_member
4050 : IDENTIFIER DOUBLE_COLON
4052 var lt = (LocatedToken) $1;
4053 if (lang_version == LanguageVersion.ISO_1)
4054 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4061 : SIZEOF open_parens_any type CLOSE_PARENS
4063 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4064 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4066 | SIZEOF open_parens_any type error
4068 Error_SyntaxError (yyToken);
4070 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4071 lbag.AddLocation ($$, GetLocation ($2));
4076 : CHECKED open_parens_any expression CLOSE_PARENS
4078 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4079 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4083 Error_SyntaxError (yyToken);
4085 $$ = new CheckedExpr (null, GetLocation ($1));
4089 unchecked_expression
4090 : UNCHECKED open_parens_any expression CLOSE_PARENS
4092 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4093 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4097 Error_SyntaxError (yyToken);
4099 $$ = new UnCheckedExpr (null, GetLocation ($1));
4103 pointer_member_access
4104 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4106 var lt = (LocatedToken) $3;
4107 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4111 anonymous_method_expression
4112 : DELEGATE opt_anonymous_method_signature
4114 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4118 $$ = end_anonymous ((ParametersBlock) $4);
4120 | ASYNC DELEGATE opt_anonymous_method_signature
4122 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4126 $$ = end_anonymous ((ParametersBlock) $5);
4130 opt_anonymous_method_signature
4133 $$ = ParametersCompiled.Undefined;
4135 | anonymous_method_signature
4138 anonymous_method_signature
4141 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4143 opt_formal_parameter_list CLOSE_PARENS
4145 valid_param_mod = 0;
4150 default_value_expression
4151 : DEFAULT open_parens_any type CLOSE_PARENS
4153 if (lang_version < LanguageVersion.ISO_2)
4154 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4156 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4157 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4162 : primary_expression
4163 | BANG prefixed_unary_expression
4165 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4167 | TILDE prefixed_unary_expression
4169 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4171 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4173 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4174 lbag.AddLocation ($$, GetLocation ($3));
4176 | AWAIT prefixed_unary_expression
4179 if (current_anonymous_method is LambdaExpression) {
4180 report.Error (4034, GetLocation ($1),
4181 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4182 } else if (current_anonymous_method != null) {
4183 report.Error (4035, GetLocation ($1),
4184 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4185 } else if (interactive_async != null) {
4186 current_block.Explicit.RegisterAsyncAwait ();
4187 interactive_async = true;
4189 report.Error (4033, GetLocation ($1),
4190 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4193 current_block.Explicit.RegisterAsyncAwait ();
4196 $$ = new Await ((Expression) $2, GetLocation ($1));
4200 Error_SyntaxError (yyToken);
4202 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4206 Error_SyntaxError (yyToken);
4208 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4210 | OPEN_PARENS_CAST type CLOSE_PARENS error
4212 Error_SyntaxError (yyToken);
4214 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4215 lbag.AddLocation ($$, GetLocation ($3));
4219 Error_SyntaxError (yyToken);
4221 $$ = new Await (null, GetLocation ($1));
4226 // The idea to split this out is from Rhys' grammar
4227 // to solve the problem with casts.
4229 prefixed_unary_expression
4231 | PLUS prefixed_unary_expression
4233 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4235 | MINUS prefixed_unary_expression
4237 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4239 | OP_INC prefixed_unary_expression
4241 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4243 | OP_DEC prefixed_unary_expression
4245 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4247 | STAR prefixed_unary_expression
4249 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4251 | BITWISE_AND prefixed_unary_expression
4253 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4257 Error_SyntaxError (yyToken);
4259 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4263 Error_SyntaxError (yyToken);
4265 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4269 Error_SyntaxError (yyToken);
4271 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4275 Error_SyntaxError (yyToken);
4277 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4281 Error_SyntaxError (yyToken);
4283 $$ = new Indirection (null, GetLocation ($1));
4287 Error_SyntaxError (yyToken);
4289 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4293 multiplicative_expression
4294 : prefixed_unary_expression
4295 | multiplicative_expression STAR prefixed_unary_expression
4297 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4298 lbag.AddLocation ($$, GetLocation ($2));
4300 | multiplicative_expression DIV prefixed_unary_expression
4302 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4303 lbag.AddLocation ($$, GetLocation ($2));
4305 | multiplicative_expression PERCENT prefixed_unary_expression
4307 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4308 lbag.AddLocation ($$, GetLocation ($2));
4310 | multiplicative_expression STAR error
4312 Error_SyntaxError (yyToken);
4314 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4315 lbag.AddLocation ($$, GetLocation ($2));
4317 | multiplicative_expression DIV error
4319 Error_SyntaxError (yyToken);
4321 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4322 lbag.AddLocation ($$, GetLocation ($2));
4324 | multiplicative_expression PERCENT error
4326 Error_SyntaxError (yyToken);
4328 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4329 lbag.AddLocation ($$, GetLocation ($2));
4334 : multiplicative_expression
4335 | additive_expression PLUS multiplicative_expression
4337 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4338 lbag.AddLocation ($$, GetLocation ($2));
4340 | additive_expression MINUS multiplicative_expression
4342 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4343 lbag.AddLocation ($$, GetLocation ($2));
4345 | additive_expression PLUS error
4347 Error_SyntaxError (yyToken);
4349 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4350 lbag.AddLocation ($$, GetLocation ($2));
4352 | additive_expression MINUS error
4354 Error_SyntaxError (yyToken);
4356 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4357 lbag.AddLocation ($$, GetLocation ($2));
4359 | additive_expression AS type
4361 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4363 | additive_expression IS pattern_type_expr opt_identifier
4365 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4367 if (lang_version != LanguageVersion.Experimental)
4368 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4370 var lt = (LocatedToken) $4;
4371 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4372 current_block.AddLocalName (is_expr.Variable);
4377 | additive_expression IS pattern_expr
4379 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4380 if (lang_version != LanguageVersion.Experimental)
4381 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4385 | additive_expression AS error
4387 Error_SyntaxError (yyToken);
4389 $$ = new As ((Expression) $1, null, GetLocation ($2));
4391 | additive_expression IS error
4393 Error_SyntaxError (yyToken);
4395 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4399 var lt = (LocatedToken) $1;
4400 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4404 var lt = (LocatedToken) $1;
4405 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4415 | PLUS prefixed_unary_expression
4417 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4419 | MINUS prefixed_unary_expression
4421 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4424 | default_value_expression
4425 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4427 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4428 lbag.AddLocation ($$, GetLocation ($3));
4432 $$ = new WildcardPattern (GetLocation ($1));
4434 | pattern_expr_invocation
4438 pattern_expr_invocation
4439 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4441 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4446 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4448 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4452 pattern_property_list
4453 : pattern_property_entry
4455 var list = new List<PropertyPatternMember> ();
4456 list.Add ((PropertyPatternMember) $1);
4459 | pattern_property_list COMMA pattern_property_entry
4461 var list = (List<PropertyPatternMember>) $1;
4462 list.Add ((PropertyPatternMember) $3);
4467 pattern_property_entry
4468 : identifier_inside_body IS pattern
4470 var lt = (LocatedToken) $1;
4471 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4477 | pattern_type_expr opt_identifier
4480 var lt = (LocatedToken) $2;
4481 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4482 current_block.AddLocalName (variable);
4490 $$ = new Arguments (0);
4498 Arguments args = new Arguments (4);
4499 args.Add ((Argument) $1);
4502 | pattern_list COMMA pattern_argument
4504 Arguments args = (Arguments) $1;
4505 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4506 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4508 args.Add ((Argument) $3);
4516 $$ = new Argument ((Expression) $1);
4518 | IDENTIFIER COLON pattern
4520 var lt = (LocatedToken) $1;
4521 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4526 : additive_expression
4527 | shift_expression OP_SHIFT_LEFT additive_expression
4529 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4530 lbag.AddLocation ($$, GetLocation ($2));
4532 | shift_expression OP_SHIFT_RIGHT additive_expression
4534 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4535 lbag.AddLocation ($$, GetLocation ($2));
4537 | shift_expression OP_SHIFT_LEFT error
4539 Error_SyntaxError (yyToken);
4541 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4542 lbag.AddLocation ($$, GetLocation ($2));
4544 | shift_expression OP_SHIFT_RIGHT error
4546 Error_SyntaxError (yyToken);
4548 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4549 lbag.AddLocation ($$, GetLocation ($2));
4553 relational_expression
4555 | relational_expression OP_LT shift_expression
4557 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4558 lbag.AddLocation ($$, GetLocation ($2));
4560 | relational_expression OP_GT shift_expression
4562 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4563 lbag.AddLocation ($$, GetLocation ($2));
4565 | relational_expression OP_LE shift_expression
4567 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4568 lbag.AddLocation ($$, GetLocation ($2));
4570 | relational_expression OP_GE shift_expression
4572 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4573 lbag.AddLocation ($$, GetLocation ($2));
4575 | relational_expression OP_LT error
4577 Error_SyntaxError (yyToken);
4579 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4580 lbag.AddLocation ($$, GetLocation ($2));
4582 | relational_expression OP_GT error
4584 Error_SyntaxError (yyToken);
4586 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4587 lbag.AddLocation ($$, GetLocation ($2));
4589 | relational_expression OP_LE error
4591 Error_SyntaxError (yyToken);
4593 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4594 lbag.AddLocation ($$, GetLocation ($2));
4596 | relational_expression OP_GE error
4598 Error_SyntaxError (yyToken);
4600 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4601 lbag.AddLocation ($$, GetLocation ($2));
4606 : relational_expression
4607 | equality_expression OP_EQ relational_expression
4609 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4610 lbag.AddLocation ($$, GetLocation ($2));
4612 | equality_expression OP_NE relational_expression
4614 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4615 lbag.AddLocation ($$, GetLocation ($2));
4617 | equality_expression OP_EQ error
4619 Error_SyntaxError (yyToken);
4621 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4622 lbag.AddLocation ($$, GetLocation ($2));
4624 | equality_expression OP_NE error
4626 Error_SyntaxError (yyToken);
4628 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4629 lbag.AddLocation ($$, GetLocation ($2));
4634 : equality_expression
4635 | and_expression BITWISE_AND equality_expression
4637 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4638 lbag.AddLocation ($$, GetLocation ($2));
4640 | and_expression BITWISE_AND error
4642 Error_SyntaxError (yyToken);
4644 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4645 lbag.AddLocation ($$, GetLocation ($2));
4649 exclusive_or_expression
4651 | exclusive_or_expression CARRET and_expression
4653 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4654 lbag.AddLocation ($$, GetLocation ($2));
4656 | exclusive_or_expression CARRET error
4658 Error_SyntaxError (yyToken);
4660 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4661 lbag.AddLocation ($$, GetLocation ($2));
4665 inclusive_or_expression
4666 : exclusive_or_expression
4667 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4669 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4670 lbag.AddLocation ($$, GetLocation ($2));
4672 | inclusive_or_expression BITWISE_OR error
4674 Error_SyntaxError (yyToken);
4676 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4677 lbag.AddLocation ($$, GetLocation ($2));
4681 conditional_and_expression
4682 : inclusive_or_expression
4683 | conditional_and_expression OP_AND inclusive_or_expression
4685 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4686 lbag.AddLocation ($$, GetLocation ($2));
4688 | conditional_and_expression OP_AND error
4690 Error_SyntaxError (yyToken);
4692 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4693 lbag.AddLocation ($$, GetLocation ($2));
4697 conditional_or_expression
4698 : conditional_and_expression
4699 | conditional_or_expression OP_OR conditional_and_expression
4701 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4702 lbag.AddLocation ($$, GetLocation ($2));
4704 | conditional_or_expression OP_OR error
4706 Error_SyntaxError (yyToken);
4708 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4709 lbag.AddLocation ($$, GetLocation ($2));
4713 null_coalescing_expression
4714 : conditional_or_expression
4715 | conditional_or_expression OP_COALESCING null_coalescing_expression
4717 if (lang_version < LanguageVersion.ISO_2)
4718 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4720 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4721 lbag.AddLocation ($$, GetLocation ($2));
4725 conditional_expression
4726 : null_coalescing_expression
4727 | null_coalescing_expression INTERR expression COLON expression
4729 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4730 lbag.AddLocation ($$, GetLocation ($4));
4732 | null_coalescing_expression INTERR expression error
4734 Error_SyntaxError (yyToken);
4736 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4738 | null_coalescing_expression INTERR expression COLON error
4740 Error_SyntaxError (yyToken);
4742 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4743 lbag.AddLocation ($$, GetLocation ($4));
4745 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4747 Error_SyntaxError (Token.CLOSE_BRACE);
4749 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4750 lbag.AddLocation ($$, GetLocation ($4));
4751 lexer.putback ('}');
4755 assignment_expression
4756 : prefixed_unary_expression ASSIGN expression
4758 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4759 lbag.AddLocation ($$, GetLocation ($2));
4761 | prefixed_unary_expression OP_MULT_ASSIGN expression
4763 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4764 lbag.AddLocation ($$, GetLocation ($2));
4766 | prefixed_unary_expression OP_DIV_ASSIGN expression
4768 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4769 lbag.AddLocation ($$, GetLocation ($2));
4771 | prefixed_unary_expression OP_MOD_ASSIGN expression
4773 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4774 lbag.AddLocation ($$, GetLocation ($2));
4776 | prefixed_unary_expression OP_ADD_ASSIGN expression
4778 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4779 lbag.AddLocation ($$, GetLocation ($2));
4781 | prefixed_unary_expression OP_SUB_ASSIGN expression
4783 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4784 lbag.AddLocation ($$, GetLocation ($2));
4786 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4788 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4789 lbag.AddLocation ($$, GetLocation ($2));
4791 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4793 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4794 lbag.AddLocation ($$, GetLocation ($2));
4796 | prefixed_unary_expression OP_AND_ASSIGN expression
4798 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4799 lbag.AddLocation ($$, GetLocation ($2));
4801 | prefixed_unary_expression OP_OR_ASSIGN expression
4803 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4804 lbag.AddLocation ($$, GetLocation ($2));
4806 | prefixed_unary_expression OP_XOR_ASSIGN expression
4808 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4809 lbag.AddLocation ($$, GetLocation ($2));
4813 lambda_parameter_list
4816 var pars = new List<Parameter> (4);
4817 pars.Add ((Parameter) $1);
4821 | lambda_parameter_list COMMA lambda_parameter
4823 var pars = (List<Parameter>) $1;
4824 Parameter p = (Parameter)$3;
4825 if (pars[0].GetType () != p.GetType ()) {
4826 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4835 : parameter_modifier parameter_type identifier_inside_body
4837 var lt = (LocatedToken) $3;
4839 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4841 | parameter_type identifier_inside_body
4843 var lt = (LocatedToken) $2;
4845 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4849 var lt = (LocatedToken) $1;
4850 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4854 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4855 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4859 opt_lambda_parameter_list
4860 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4861 | lambda_parameter_list {
4862 var pars_list = (List<Parameter>) $1;
4863 $$ = new ParametersCompiled (pars_list.ToArray ());
4867 lambda_expression_body
4869 start_block (Location.Null);
4871 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4873 Block b = end_block (Location.Null);
4874 b.IsCompilerGenerated = true;
4875 b.AddStatement (new ContextualReturn ((Expression) $2));
4881 // Handles only cases like foo = x.FirstOrDefault (l => );
4882 // where we must restore current_variable
4883 Block b = end_block (Location.Null);
4884 b.IsCompilerGenerated = true;
4886 Error_SyntaxError (yyToken);
4895 Error_SyntaxError (yyToken);
4903 var lt = (LocatedToken) $1;
4904 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4905 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4907 lambda_expression_body
4909 $$ = end_anonymous ((ParametersBlock) $4);
4910 lbag.AddLocation ($$, GetLocation ($2));
4914 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4915 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4916 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4918 lambda_expression_body
4920 $$ = end_anonymous ((ParametersBlock) $4);
4921 lbag.AddLocation ($$, GetLocation ($2));
4923 | ASYNC identifier_inside_body ARROW
4925 var lt = (LocatedToken) $2;
4926 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4927 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4929 lambda_expression_body
4931 $$ = end_anonymous ((ParametersBlock) $5);
4932 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4934 | OPEN_PARENS_LAMBDA
4936 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4938 opt_lambda_parameter_list CLOSE_PARENS ARROW
4940 valid_param_mod = 0;
4941 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4943 lambda_expression_body
4945 $$ = end_anonymous ((ParametersBlock) $7);
4946 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4948 | ASYNC OPEN_PARENS_LAMBDA
4950 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4952 opt_lambda_parameter_list CLOSE_PARENS ARROW
4954 valid_param_mod = 0;
4955 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4957 lambda_expression_body
4959 $$ = end_anonymous ((ParametersBlock) $8);
4960 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4965 : assignment_expression
4966 | non_assignment_expression
4969 non_assignment_expression
4970 : conditional_expression
4975 $$ = new ArglistAccess (GetLocation ($1));
4979 undocumented_expressions
4980 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4982 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4983 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4985 | REFTYPE open_parens_any expression CLOSE_PARENS
4987 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4988 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4990 | MAKEREF open_parens_any expression CLOSE_PARENS
4992 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4993 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5004 $$ = new BooleanExpression ((Expression) $1);
5008 opt_primary_parameters
5013 | primary_parameters
5017 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5021 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5022 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5024 if (lang_version < LanguageVersion.V_6)
5025 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5029 opt_primary_parameters_with_class_base
5038 | primary_parameters
5042 | primary_parameters class_base
5046 | primary_parameters class_base OPEN_PARENS
5048 ++lexer.parsing_block;
5049 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5051 opt_argument_list CLOSE_PARENS
5053 lbag.AppendToMember (current_container, GetLocation ($6));
5054 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5055 --lexer.parsing_block;
5071 type_declaration_name
5073 lexer.ConstraintsParsing = true;
5075 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5076 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5077 FeatureIsNotAvailable (c.Location, "static classes");
5080 push_current_container (c, $3);
5081 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5083 opt_primary_parameters_with_class_base
5084 opt_type_parameter_constraints_clauses
5086 valid_param_mod = 0;
5087 lexer.ConstraintsParsing = false;
5090 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5093 current_container.SetConstraints ((List<Constraints>) $9);
5094 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5097 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5098 Lexer.doc_state = XmlCommentState.Allowed;
5101 lexer.parsing_modifiers = true;
5103 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5105 --lexer.parsing_declaration;
5107 Lexer.doc_state = XmlCommentState.Allowed;
5112 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5114 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5116 $$ = pop_current_class ();
5124 { $$ = $1; } // location
5130 mod_locations = null;
5132 lexer.parsing_modifiers = false;
5136 lexer.parsing_modifiers = false;
5142 | modifiers modifier
5144 var m1 = (Modifiers) $1;
5145 var m2 = (Modifiers) $2;
5147 if ((m1 & m2) != 0) {
5148 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5149 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5150 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5151 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5152 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5153 "More than one protection modifier specified");
5164 StoreModifierLocation ($$, GetLocation ($1));
5166 if (current_container.Kind == MemberKind.Namespace)
5167 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5171 $$ = Modifiers.PUBLIC;
5172 StoreModifierLocation ($$, GetLocation ($1));
5176 $$ = Modifiers.PROTECTED;
5177 StoreModifierLocation ($$, GetLocation ($1));
5181 $$ = Modifiers.INTERNAL;
5182 StoreModifierLocation ($$, GetLocation ($1));
5186 $$ = Modifiers.PRIVATE;
5187 StoreModifierLocation ($$, GetLocation ($1));
5191 $$ = Modifiers.ABSTRACT;
5192 StoreModifierLocation ($$, GetLocation ($1));
5196 $$ = Modifiers.SEALED;
5197 StoreModifierLocation ($$, GetLocation ($1));
5201 $$ = Modifiers.STATIC;
5202 StoreModifierLocation ($$, GetLocation ($1));
5206 $$ = Modifiers.READONLY;
5207 StoreModifierLocation ($$, GetLocation ($1));
5211 $$ = Modifiers.VIRTUAL;
5212 StoreModifierLocation ($$, GetLocation ($1));
5216 $$ = Modifiers.OVERRIDE;
5217 StoreModifierLocation ($$, GetLocation ($1));
5221 $$ = Modifiers.EXTERN;
5222 StoreModifierLocation ($$, GetLocation ($1));
5226 $$ = Modifiers.VOLATILE;
5227 StoreModifierLocation ($$, GetLocation ($1));
5231 $$ = Modifiers.UNSAFE;
5232 StoreModifierLocation ($$, GetLocation ($1));
5233 if (!settings.Unsafe)
5234 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5238 $$ = Modifiers.ASYNC;
5239 StoreModifierLocation ($$, GetLocation ($1));
5251 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5253 | COLON type_list error
5255 Error_SyntaxError (yyToken);
5257 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5261 opt_type_parameter_constraints_clauses
5263 | type_parameter_constraints_clauses
5269 type_parameter_constraints_clauses
5270 : type_parameter_constraints_clause
5272 var constraints = new List<Constraints> (1);
5273 constraints.Add ((Constraints) $1);
5276 | type_parameter_constraints_clauses type_parameter_constraints_clause
5278 var constraints = (List<Constraints>) $1;
5279 Constraints new_constraint = (Constraints)$2;
5281 foreach (Constraints c in constraints) {
5282 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5283 report.Error (409, new_constraint.Location,
5284 "A constraint clause has already been specified for type parameter `{0}'",
5285 new_constraint.TypeParameter.Value);
5289 constraints.Add (new_constraint);
5294 type_parameter_constraints_clause
5295 : WHERE IDENTIFIER COLON type_parameter_constraints
5297 var lt = (LocatedToken) $2;
5298 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5299 lbag.AddLocation ($$, GetLocation ($3));
5301 | WHERE IDENTIFIER error
5303 Error_SyntaxError (yyToken);
5305 var lt = (LocatedToken) $2;
5306 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5310 type_parameter_constraints
5311 : type_parameter_constraint
5313 var constraints = new List<FullNamedExpression> (1);
5314 constraints.Add ((FullNamedExpression) $1);
5317 | type_parameter_constraints COMMA type_parameter_constraint
5319 var constraints = (List<FullNamedExpression>) $1;
5320 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5321 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5322 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5325 prev = $3 as SpecialContraintExpr;
5327 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5328 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5330 prev = constraints [0] as SpecialContraintExpr;
5331 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5332 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5337 constraints.Add ((FullNamedExpression) $3);
5342 type_parameter_constraint
5345 if ($1 is ComposedCast)
5346 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5350 | NEW OPEN_PARENS CLOSE_PARENS
5352 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5353 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5357 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5361 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5365 opt_type_parameter_variance
5370 | type_parameter_variance
5372 if (lang_version <= LanguageVersion.V_3)
5373 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5379 type_parameter_variance
5382 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5386 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5395 // A block is "contained" on the following places:
5397 // property_declaration as part of the accessor body (get/set)
5398 // operator_declaration
5399 // constructor_declaration
5400 // destructor_declaration
5401 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5406 ++lexer.parsing_block;
5407 start_block (GetLocation ($1));
5409 opt_statement_list block_end
5418 --lexer.parsing_block;
5419 $$ = end_block (GetLocation ($1));
5421 | COMPLETE_COMPLETION
5423 --lexer.parsing_block;
5424 $$ = end_block (lexer.Location);
5432 ++lexer.parsing_block;
5433 current_block.StartLocation = GetLocation ($1);
5435 opt_statement_list CLOSE_BRACE
5437 --lexer.parsing_block;
5438 $$ = end_block (GetLocation ($4));
5449 | statement_list statement
5453 : block_variable_declaration
5455 current_block.AddStatement ((Statement) $1);
5457 | valid_declaration_statement
5459 current_block.AddStatement ((Statement) $1);
5464 Error_SyntaxError (yyToken);
5470 // The interactive_statement and its derivatives are only
5471 // used to provide a special version of `expression_statement'
5472 // that has a side effect of assigning the expression to
5475 interactive_statement_list
5476 : interactive_statement
5477 | interactive_statement_list interactive_statement
5480 interactive_statement
5481 : block_variable_declaration
5483 current_block.AddStatement ((Statement) $1);
5485 | interactive_valid_declaration_statement
5487 current_block.AddStatement ((Statement) $1);
5492 valid_declaration_statement
5495 | expression_statement
5496 | selection_statement
5497 | iteration_statement
5501 | unchecked_statement
5508 interactive_valid_declaration_statement
5511 | interactive_expression_statement
5512 | selection_statement
5513 | iteration_statement
5517 | unchecked_statement
5525 : valid_declaration_statement
5526 | block_variable_declaration
5528 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5533 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5538 Error_SyntaxError (yyToken);
5539 $$ = new EmptyStatement (GetLocation ($1));
5546 // Uses lexer.Location because semicolon location is not kept in quick mode
5547 $$ = new EmptyStatement (lexer.Location);
5552 : identifier_inside_body COLON
5554 var lt = (LocatedToken) $1;
5555 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5556 lbag.AddLocation (labeled, GetLocation ($2));
5557 current_block.AddLabel (labeled);
5558 current_block.AddStatement (labeled);
5564 : variable_type_simple
5565 | variable_type_simple rank_specifiers
5568 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5570 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5575 * The following is from Rhys' grammar:
5576 * > Types in local variable declarations must be recognized as
5577 * > expressions to prevent reduce/reduce errors in the grammar.
5578 * > The expressions are converted into types during semantic analysis.
5580 variable_type_simple
5581 : type_name_expression opt_nullable
5583 // Ok, the above "primary_expression" is there to get rid of
5584 // both reduce/reduce and shift/reduces in the grammar, it should
5585 // really just be "type_name". If you use type_name, a reduce/reduce
5586 // creeps up. If you use namespace_or_type_name (which is all we need
5587 // really) two shift/reduces appear.
5590 // So the super-trick is that primary_expression
5591 // can only be either a SimpleName or a MemberAccess.
5592 // The MemberAccess case arises when you have a fully qualified type-name like :
5594 // SimpleName is when you have
5597 var expr = (ATypeNameExpression) $1;
5599 if (expr.Name == "var" && expr is SimpleName)
5600 $$ = new VarExpr (expr.Location);
5604 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5607 | type_name_expression pointer_stars
5609 var expr = (ATypeNameExpression) $1;
5610 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5612 | builtin_type_expression
5618 | pointer_star pointer_stars
5620 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5628 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5632 identifier_inside_body
5636 $$ = Error_AwaitAsIdentifier ($1);
5640 block_variable_declaration
5641 : variable_type identifier_inside_body
5643 var lt = (LocatedToken) $2;
5644 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5645 current_block.AddLocalName (li);
5646 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5648 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5650 $$ = current_variable;
5651 current_variable = null;
5653 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5655 lbag.AddLocation ($$, GetLocation ($6));
5657 | CONST variable_type identifier_inside_body
5659 var lt = (LocatedToken) $3;
5660 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5661 current_block.AddLocalName (li);
5662 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5664 const_variable_initializer opt_const_declarators SEMICOLON
5666 $$ = current_variable;
5667 current_variable = null;
5668 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5672 opt_local_variable_initializer
5674 | ASSIGN block_variable_initializer
5676 current_variable.Initializer = (Expression) $2;
5677 PushLocation (GetLocation ($1));
5678 $$ = current_variable;
5682 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5683 report.Error (650, lexer.Location,
5684 "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");
5686 Error_SyntaxError (yyToken);
5691 opt_variable_declarators
5693 | variable_declarators
5696 opt_using_or_fixed_variable_declarators
5698 | variable_declarators
5700 foreach (var d in current_variable.Declarators) {
5701 if (d.Initializer == null)
5702 Error_MissingInitializer (d.Variable.Location);
5707 variable_declarators
5708 : variable_declarator
5709 | variable_declarators variable_declarator
5713 : COMMA identifier_inside_body
5715 var lt = (LocatedToken) $2;
5716 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5717 var d = new BlockVariableDeclarator (li, null);
5718 current_variable.AddDeclarator (d);
5719 current_block.AddLocalName (li);
5720 lbag.AddLocation (d, GetLocation ($1));
5722 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5724 var lt = (LocatedToken) $2;
5725 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5726 var d = new BlockVariableDeclarator (li, (Expression) $4);
5727 current_variable.AddDeclarator (d);
5728 current_block.AddLocalName (li);
5729 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5733 const_variable_initializer
5736 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5738 | ASSIGN constant_initializer_expr
5740 current_variable.Initializer = (Expression) $2;
5744 opt_const_declarators
5751 | const_declarators const_declarator
5755 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5757 var lt = (LocatedToken) $2;
5758 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5759 var d = new BlockVariableDeclarator (li, (Expression) $4);
5760 current_variable.AddDeclarator (d);
5761 current_block.AddLocalName (li);
5762 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5766 block_variable_initializer
5767 : variable_initializer
5768 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5770 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5771 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5773 | STACKALLOC simple_type
5775 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5776 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5780 expression_statement
5781 : statement_expression SEMICOLON
5784 lbag.AddStatement ($$, GetLocation ($2));
5786 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5787 | statement_expression CLOSE_BRACE
5790 report.Error (1002, GetLocation ($2), "; expected");
5791 lexer.putback ('}');
5795 interactive_expression_statement
5796 : interactive_statement_expression SEMICOLON { $$ = $1; }
5797 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5801 // We have to do the wrapping here and not in the case above,
5802 // because statement_expression is used for example in for_statement
5804 statement_expression
5807 ExpressionStatement s = $1 as ExpressionStatement;
5809 var expr = $1 as Expression;
5810 $$ = new StatementErrorExpression (expr);
5812 $$ = new StatementExpression (s);
5817 interactive_statement_expression
5820 Expression expr = (Expression) $1;
5821 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5825 Error_SyntaxError (yyToken);
5826 $$ = new EmptyStatement (GetLocation ($1));
5836 : IF open_parens_any boolean_expression CLOSE_PARENS
5839 if ($5 is EmptyStatement)
5840 Warning_EmptyStatement (GetLocation ($5));
5842 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5843 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5845 | IF open_parens_any boolean_expression CLOSE_PARENS
5846 embedded_statement ELSE embedded_statement
5848 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5849 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5851 if ($5 is EmptyStatement)
5852 Warning_EmptyStatement (GetLocation ($5));
5853 if ($7 is EmptyStatement)
5854 Warning_EmptyStatement (GetLocation ($7));
5856 | IF open_parens_any boolean_expression error
5858 Error_SyntaxError (yyToken);
5860 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5861 lbag.AddStatement ($$, GetLocation ($2));
5866 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5868 start_block (GetLocation ($5));
5870 opt_switch_sections CLOSE_BRACE
5872 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5873 end_block (GetLocation ($8));
5874 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5876 | SWITCH open_parens_any expression error
5878 Error_SyntaxError (yyToken);
5880 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5881 lbag.AddStatement ($$, GetLocation ($2));
5888 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5895 | switch_sections switch_section
5898 Error_SyntaxError (yyToken);
5903 : switch_labels statement_list
5909 var label = (SwitchLabel) $1;
5910 label.SectionStart = true;
5911 current_block.AddStatement (label);
5913 | switch_labels switch_label
5915 current_block.AddStatement ((Statement) $2);
5920 : CASE constant_expression COLON
5922 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5923 lbag.AddLocation ($$, GetLocation ($3));
5925 | CASE constant_expression error
5927 Error_SyntaxError (yyToken);
5928 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5930 | CASE pattern_expr_invocation COLON
5932 if (lang_version != LanguageVersion.Experimental)
5933 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
5935 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
5936 PatternMatching = true
5938 lbag.AddLocation ($$, GetLocation ($3));
5942 $$ = new SwitchLabel (null, GetLocation ($1));
5954 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5956 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5957 Warning_EmptyStatement (GetLocation ($5));
5959 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5960 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5962 | WHILE open_parens_any boolean_expression error
5964 Error_SyntaxError (yyToken);
5966 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5967 lbag.AddStatement ($$, GetLocation ($2));
5972 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5974 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5975 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5977 | DO embedded_statement error
5979 Error_SyntaxError (yyToken);
5980 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5982 | DO embedded_statement WHILE open_parens_any boolean_expression error
5984 Error_SyntaxError (yyToken);
5986 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5987 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5992 : FOR open_parens_any
5994 start_block (GetLocation ($2));
5995 current_block.IsCompilerGenerated = true;
5996 For f = new For (GetLocation ($1));
5997 current_block.AddStatement (f);
6006 // Has to use be extra rule to recover started block
6008 : opt_for_initializer SEMICOLON
6010 ((For) $0).Initializer = (Statement) $1;
6012 // Pass the "For" object to the iterator_part4
6013 oob_stack.Push ($0);
6015 for_condition_and_iterator_part
6018 var locations = (Tuple<Location,Location>) $4;
6020 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6021 Warning_EmptyStatement (GetLocation ($5));
6024 f.Statement = (Statement) $5;
6025 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6027 $$ = end_block (GetLocation ($2));
6031 Error_SyntaxError (yyToken);
6032 $$ = end_block (current_block.StartLocation);
6036 for_condition_and_iterator_part
6037 : opt_for_condition SEMICOLON
6039 For f = (For) oob_stack.Peek ();
6040 f.Condition = (BooleanExpression) $1;
6043 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6046 // Handle errors in the case of opt_for_condition being followed by
6047 // a close parenthesis
6048 | opt_for_condition close_parens_close_brace {
6049 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6050 For f = (For) oob_stack.Peek ();
6051 f.Condition = (BooleanExpression) $1;
6052 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6057 : opt_for_iterator CLOSE_PARENS {
6058 For f = (For) oob_stack.Peek ();
6059 f.Iterator = (Statement) $1;
6060 $$ = GetLocation ($2);
6062 | opt_for_iterator CLOSE_BRACE {
6063 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6064 For f = (For) oob_stack.Peek ();
6065 f.Iterator = (Statement) $1;
6066 $$ = GetLocation ($2);
6070 close_parens_close_brace
6072 | CLOSE_BRACE { lexer.putback ('}'); }
6076 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6081 : variable_type identifier_inside_body
6083 var lt = (LocatedToken) $2;
6084 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6085 current_block.AddLocalName (li);
6086 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6088 opt_local_variable_initializer opt_variable_declarators
6090 $$ = current_variable;
6092 lbag.AddLocation (current_variable, PopLocation ());
6094 current_variable = null;
6096 | statement_expression_list
6100 : /* empty */ { $$ = null; }
6101 | boolean_expression
6105 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6110 : statement_expression_list
6113 statement_expression_list
6114 : statement_expression
6115 | statement_expression_list COMMA statement_expression
6117 var sl = $1 as StatementList;
6119 sl = new StatementList ((Statement) $1, (Statement) $3);
6120 lbag.AddStatement (sl, GetLocation ($2));
6122 sl.Add ((Statement) $3);
6123 lbag.AppendTo (sl, GetLocation ($2));
6131 : FOREACH open_parens_any type error
6133 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6135 start_block (GetLocation ($2));
6136 current_block.IsCompilerGenerated = true;
6138 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6139 current_block.AddStatement (f);
6141 lbag.AddStatement (f, GetLocation ($2));
6142 $$ = end_block (GetLocation ($4));
6144 | FOREACH open_parens_any type identifier_inside_body error
6146 Error_SyntaxError (yyToken);
6148 start_block (GetLocation ($2));
6149 current_block.IsCompilerGenerated = true;
6151 var lt = (LocatedToken) $4;
6152 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6153 current_block.AddLocalName (li);
6155 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6156 current_block.AddStatement (f);
6158 lbag.AddStatement (f, GetLocation ($2));
6159 $$ = end_block (GetLocation ($5));
6161 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6163 start_block (GetLocation ($2));
6164 current_block.IsCompilerGenerated = true;
6166 var lt = (LocatedToken) $4;
6167 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6168 current_block.AddLocalName (li);
6173 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6174 Warning_EmptyStatement (GetLocation ($9));
6176 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6177 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6178 end_block (GetLocation ($7));
6186 | continue_statement
6196 $$ = new Break (GetLocation ($1));
6197 lbag.AddStatement ($$, GetLocation ($2));
6202 : CONTINUE SEMICOLON
6204 $$ = new Continue (GetLocation ($1));
6205 lbag.AddStatement ($$, GetLocation ($2));
6209 Error_SyntaxError (yyToken);
6210 $$ = new Continue (GetLocation ($1));
6215 : GOTO identifier_inside_body SEMICOLON
6217 var lt = (LocatedToken) $2;
6218 $$ = new Goto (lt.Value, GetLocation ($1));
6219 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6221 | GOTO CASE constant_expression SEMICOLON
6223 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6224 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6226 | GOTO DEFAULT SEMICOLON
6228 $$ = new GotoDefault (GetLocation ($1));
6229 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6234 : RETURN opt_expression SEMICOLON
6236 $$ = new Return ((Expression) $2, GetLocation ($1));
6237 lbag.AddStatement ($$, GetLocation ($3));
6239 | RETURN expression error
6241 Error_SyntaxError (yyToken);
6242 $$ = new Return ((Expression) $2, GetLocation ($1));
6246 Error_SyntaxError (yyToken);
6247 $$ = new Return (null, GetLocation ($1));
6252 : THROW opt_expression SEMICOLON
6254 $$ = new Throw ((Expression) $2, GetLocation ($1));
6255 lbag.AddStatement ($$, GetLocation ($3));
6257 | THROW expression error
6259 Error_SyntaxError (yyToken);
6260 $$ = new Throw ((Expression) $2, GetLocation ($1));
6264 Error_SyntaxError (yyToken);
6265 $$ = new Throw (null, GetLocation ($1));
6270 : identifier_inside_body RETURN opt_expression SEMICOLON
6272 var lt = (LocatedToken) $1;
6273 string s = lt.Value;
6275 report.Error (1003, lt.Location, "; expected");
6276 } else if ($3 == null) {
6277 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6278 } else if (lang_version == LanguageVersion.ISO_1){
6279 FeatureIsNotAvailable (lt.Location, "iterators");
6282 current_block.Explicit.RegisterIteratorYield ();
6283 $$ = new Yield ((Expression) $3, lt.Location);
6284 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6286 | identifier_inside_body RETURN expression error
6288 Error_SyntaxError (yyToken);
6290 var lt = (LocatedToken) $1;
6291 string s = lt.Value;
6293 report.Error (1003, lt.Location, "; expected");
6294 } else if ($3 == null) {
6295 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6296 } else if (lang_version == LanguageVersion.ISO_1){
6297 FeatureIsNotAvailable (lt.Location, "iterators");
6300 current_block.Explicit.RegisterIteratorYield ();
6301 $$ = new Yield ((Expression) $3, lt.Location);
6302 lbag.AddStatement ($$, GetLocation ($2));
6304 | identifier_inside_body BREAK SEMICOLON
6306 var lt = (LocatedToken) $1;
6307 string s = lt.Value;
6309 report.Error (1003, lt.Location, "; expected");
6310 } else if (lang_version == LanguageVersion.ISO_1){
6311 FeatureIsNotAvailable (lt.Location, "iterators");
6314 current_block.ParametersBlock.TopBlock.IsIterator = true;
6315 $$ = new YieldBreak (lt.Location);
6316 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6326 : TRY block catch_clauses
6328 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6330 | TRY block FINALLY block
6332 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6333 lbag.AddStatement ($$, GetLocation ($3));
6335 | TRY block catch_clauses FINALLY block
6337 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6338 lbag.AddStatement ($$, GetLocation ($4));
6342 Error_SyntaxError (1524, yyToken);
6343 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6350 var l = new List<Catch> (2);
6355 | catch_clauses catch_clause
6357 var l = (List<Catch>) $1;
6359 Catch c = (Catch) $2;
6360 var prev_catch = l [l.Count - 1];
6361 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6362 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6372 | identifier_inside_body
6376 : CATCH opt_catch_filter block
6378 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6379 c.Filter = (CatchFilterExpression) $2;
6382 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6384 start_block (GetLocation ($2));
6385 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6386 c.TypeExpression = (FullNamedExpression) $3;
6389 var lt = (LocatedToken) $4;
6390 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6391 current_block.AddLocalName (c.Variable);
6394 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6397 opt_catch_filter block_prepared
6399 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6402 | CATCH open_parens_any error
6404 if (yyToken == Token.CLOSE_PARENS) {
6405 report.Error (1015, lexer.Location,
6406 "A type that derives from `System.Exception', `object', or `string' expected");
6408 Error_SyntaxError (yyToken);
6411 $$ = new Catch (null, GetLocation ($1));
6413 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6415 Error_SyntaxError (yyToken);
6417 // Required otherwise missing block could not be detected because
6418 // start_block is run early
6419 var c = new Catch (null, GetLocation ($1));
6420 c.TypeExpression = (FullNamedExpression) $3;
6423 var lt = (LocatedToken) $4;
6424 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6427 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6435 | IF open_parens_any expression CLOSE_PARENS
6437 if (lang_version <= LanguageVersion.V_5)
6438 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6440 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6441 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6448 $$ = new Checked ((Block) $2, GetLocation ($1));
6455 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6462 if (!settings.Unsafe)
6463 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6465 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6470 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6472 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6473 Warning_EmptyStatement (GetLocation ($5));
6475 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6476 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6478 | LOCK open_parens_any expression error
6480 Error_SyntaxError (yyToken);
6482 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6483 lbag.AddStatement ($$, GetLocation ($2));
6488 : FIXED open_parens_any variable_type identifier_inside_body
6490 start_block (GetLocation ($2));
6492 current_block.IsCompilerGenerated = true;
6493 var lt = (LocatedToken) $4;
6494 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6495 current_block.AddLocalName (li);
6496 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6498 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6500 $$ = current_variable;
6501 current_variable = null;
6505 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6506 Warning_EmptyStatement (GetLocation ($10));
6508 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6509 current_block.AddStatement (f);
6510 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6511 $$ = end_block (GetLocation ($8));
6516 : USING open_parens_any variable_type identifier_inside_body
6518 start_block (GetLocation ($2));
6520 current_block.IsCompilerGenerated = true;
6521 var lt = (LocatedToken) $4;
6522 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6523 current_block.AddLocalName (li);
6524 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6526 using_initialization CLOSE_PARENS
6528 $$ = current_variable;
6529 current_variable = null;
6533 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6534 Warning_EmptyStatement (GetLocation ($9));
6536 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6537 current_block.AddStatement (u);
6538 $$ = end_block (GetLocation ($7));
6540 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6542 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6543 Warning_EmptyStatement (GetLocation ($5));
6545 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6546 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6548 | USING open_parens_any expression error
6550 Error_SyntaxError (yyToken);
6552 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6553 lbag.AddStatement ($$, GetLocation ($2));
6557 using_initialization
6558 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6561 // It has to be here for the parent to safely restore artificial block
6562 Error_SyntaxError (yyToken);
6566 using_or_fixed_variable_initializer
6569 Error_MissingInitializer (lexer.Location);
6571 | ASSIGN variable_initializer
6573 current_variable.Initializer = (Expression) $2;
6574 $$ = current_variable;
6582 : first_from_clause query_body
6584 lexer.query_parsing = false;
6586 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6588 from.Tail.Next = (Linq.AQueryClause)$2;
6591 current_block.SetEndLocation (lexer.Location);
6592 current_block = current_block.Parent;
6594 | nested_from_clause query_body
6596 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6598 from.Tail.Next = (Linq.AQueryClause)$2;
6601 current_block.SetEndLocation (lexer.Location);
6602 current_block = current_block.Parent;
6605 // Bubble up COMPLETE_COMPLETION productions
6606 | first_from_clause COMPLETE_COMPLETION {
6607 lexer.query_parsing = false;
6610 current_block.SetEndLocation (lexer.Location);
6611 current_block = current_block.Parent;
6613 | nested_from_clause COMPLETE_COMPLETION {
6615 current_block.SetEndLocation (lexer.Location);
6616 current_block = current_block.Parent;
6621 : FROM_FIRST identifier_inside_body IN expression
6623 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6625 var lt = (LocatedToken) $2;
6626 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6627 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6628 lbag.AddLocation (clause, GetLocation ($3));
6629 $$ = new Linq.QueryExpression (clause);
6631 | FROM_FIRST type identifier_inside_body IN expression
6633 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6635 var lt = (LocatedToken) $3;
6636 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6637 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6638 IdentifierType = (FullNamedExpression)$2
6640 lbag.AddLocation (clause, GetLocation ($4));
6641 $$ = new Linq.QueryExpression (clause);
6646 : FROM identifier_inside_body IN expression
6648 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6650 var lt = (LocatedToken) $2;
6651 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6652 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6653 lbag.AddLocation (clause, GetLocation ($3));
6654 $$ = new Linq.QueryExpression (clause);
6656 | FROM type identifier_inside_body IN expression
6658 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6660 var lt = (LocatedToken) $3;
6661 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6662 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6663 IdentifierType = (FullNamedExpression)$2
6665 lbag.AddLocation (clause, GetLocation ($4));
6666 $$ = new Linq.QueryExpression (clause);
6671 : FROM identifier_inside_body IN
6673 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6677 var lt = (LocatedToken) $2;
6678 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6679 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6681 current_block.SetEndLocation (lexer.Location);
6682 current_block = current_block.Parent;
6684 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6685 lbag.AddLocation ($$, GetLocation ($3));
6687 | FROM type identifier_inside_body IN
6689 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6693 var lt = (LocatedToken) $3;
6694 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6696 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6697 IdentifierType = (FullNamedExpression)$2
6700 current_block.SetEndLocation (lexer.Location);
6701 current_block = current_block.Parent;
6703 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6705 lbag.AddLocation ($$, GetLocation ($4));
6710 : query_body_clauses select_or_group_clause opt_query_continuation
6712 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6715 head.Next = (Linq.AQueryClause)$3;
6718 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6719 clause.Tail.Next = head;
6725 | select_or_group_clause opt_query_continuation
6727 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6730 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6731 clause.Tail.Next = head;
6737 | query_body_clauses COMPLETE_COMPLETION
6738 | query_body_clauses error
6740 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6745 Error_SyntaxError (yyToken);
6750 select_or_group_clause
6753 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6757 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6759 current_block.SetEndLocation (lexer.Location);
6760 current_block = current_block.Parent;
6764 if (linq_clause_blocks == null)
6765 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6767 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6768 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6772 current_block.SetEndLocation (lexer.Location);
6773 current_block = current_block.Parent;
6775 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6779 var obj = (object[]) $5;
6781 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6782 lbag.AddLocation ($$, (Location) obj[1]);
6784 current_block.SetEndLocation (lexer.Location);
6785 current_block = current_block.Parent;
6790 : BY expression_or_error
6792 $$ = new object[] { $2, GetLocation ($1) };
6796 Error_SyntaxError (yyToken);
6797 $$ = new object[2] { null, Location.Null };
6803 | query_body_clauses query_body_clause
6805 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6819 : LET identifier_inside_body ASSIGN
6821 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6825 var lt = (LocatedToken) $2;
6826 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6827 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6828 lbag.AddLocation ($$, GetLocation ($3));
6830 current_block.SetEndLocation (lexer.Location);
6831 current_block = current_block.Parent;
6833 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6840 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6844 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6846 current_block.SetEndLocation (lexer.Location);
6847 current_block = current_block.Parent;
6852 : JOIN identifier_inside_body IN
6854 if (linq_clause_blocks == null)
6855 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6857 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6858 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6860 expression_or_error ON
6862 current_block.SetEndLocation (lexer.Location);
6863 current_block = current_block.Parent;
6865 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6866 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6868 expression_or_error EQUALS
6870 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6871 current_block.SetEndLocation (lexer.Location);
6872 current_block = current_block.Parent;
6874 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6876 expression_or_error opt_join_into
6878 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6879 current_block.SetEndLocation (lexer.Location);
6881 var outer_selector = linq_clause_blocks.Pop ();
6882 var block = linq_clause_blocks.Pop ();
6884 var lt = (LocatedToken) $2;
6885 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6886 Linq.RangeVariable into;
6890 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6891 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6894 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6896 var parent = block.Parent;
6897 while (parent is Linq.QueryBlock) {
6898 parent = parent.Parent;
6900 current_block.Parent = parent;
6902 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6904 lt = (LocatedToken) $12;
6905 into = new Linq.RangeVariable (lt.Value, lt.Location);
6907 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6908 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6911 current_block = block.Parent;
6912 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6914 | JOIN type identifier_inside_body IN
6916 if (linq_clause_blocks == null)
6917 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6919 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6920 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6922 expression_or_error ON
6924 current_block.SetEndLocation (lexer.Location);
6925 current_block = current_block.Parent;
6927 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6928 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6930 expression_or_error EQUALS
6932 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6933 current_block.SetEndLocation (lexer.Location);
6934 current_block = current_block.Parent;
6936 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6938 expression_or_error opt_join_into
6940 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6941 current_block.SetEndLocation (lexer.Location);
6943 var outer_selector = linq_clause_blocks.Pop ();
6944 var block = linq_clause_blocks.Pop ();
6946 var lt = (LocatedToken) $3;
6947 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6948 Linq.RangeVariable into;
6952 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6953 IdentifierType = (FullNamedExpression)$2
6955 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6958 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6960 var parent = block.Parent;
6961 while (parent is Linq.QueryBlock) {
6962 parent = parent.Parent;
6964 current_block.Parent = parent;
6966 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6968 lt = (LocatedToken) $13;
6969 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6971 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6972 IdentifierType = (FullNamedExpression)$2
6976 current_block = block.Parent;
6977 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6983 | INTO identifier_inside_body
6992 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6996 current_block.SetEndLocation (lexer.Location);
6997 current_block = current_block.Parent;
7007 current_block.SetEndLocation (lexer.Location);
7008 current_block = current_block.Parent;
7010 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7014 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7021 | orderings_then_by COMMA
7023 current_block.SetEndLocation (lexer.Location);
7024 current_block = current_block.Parent;
7026 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7030 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7038 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7040 | expression ASCENDING
7042 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7043 lbag.AddLocation ($$, GetLocation ($2));
7045 | expression DESCENDING
7047 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7048 lbag.AddLocation ($$, GetLocation ($2));
7055 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7057 | expression ASCENDING
7059 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7060 lbag.AddLocation ($$, GetLocation ($2));
7062 | expression DESCENDING
7064 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7065 lbag.AddLocation ($$, GetLocation ($2));
7070 opt_query_continuation
7072 | INTO identifier_inside_body
7074 // query continuation block is not linked with query block but with block
7075 // before. This means each query can use same range variable names for
7076 // different identifiers.
7078 current_block.SetEndLocation (GetLocation ($1));
7079 current_block = current_block.Parent;
7081 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7083 if (linq_clause_blocks == null)
7084 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7086 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7090 var current_block = linq_clause_blocks.Pop ();
7091 var lt = (LocatedToken) $2;
7092 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7093 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7094 next = (Linq.AQueryClause)$4
7100 // Support for using the compiler as an interactive parser
7102 // The INTERACTIVE_PARSER token is first sent to parse our
7103 // productions; If the result is a Statement, the parsing
7104 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7105 // to setup the blocks in advance.
7107 // This setup is here so that in the future we can add
7108 // support for other constructs (type parsing, namespaces, etc)
7109 // that do not require a block to be setup in advance
7113 : EVAL_STATEMENT_PARSER EOF
7114 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7115 | EVAL_STATEMENT_PARSER
7117 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7119 // (ref object retval)
7120 Parameter [] mpar = new Parameter [1];
7121 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7123 ParametersCompiled pars = new ParametersCompiled (mpar);
7124 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7125 if (settings.Unsafe)
7126 mods |= Modifiers.UNSAFE;
7128 current_local_parameters = pars;
7129 var method = new InteractiveMethod (
7131 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7135 current_type.AddMember (method);
7136 oob_stack.Push (method);
7138 interactive_async = false;
7140 ++lexer.parsing_block;
7141 start_block (lexer.Location);
7143 interactive_statement_list opt_COMPLETE_COMPLETION
7145 --lexer.parsing_block;
7146 var method = (InteractiveMethod) oob_stack.Pop ();
7147 method.Block = (ToplevelBlock) end_block(lexer.Location);
7149 if (interactive_async == true) {
7150 method.ChangeToAsync ();
7153 InteractiveResult = (Class) pop_current_class ();
7154 current_local_parameters = null;
7156 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7159 interactive_compilation_unit
7160 : opt_extern_alias_directives opt_using_directives
7161 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7164 opt_COMPLETE_COMPLETION
7166 | COMPLETE_COMPLETION
7169 close_brace_or_complete_completion
7171 | COMPLETE_COMPLETION
7175 // XML documentation code references micro parser
7177 documentation_parsing
7180 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7185 : doc_type_declaration_name opt_doc_method_sig
7187 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7189 | builtin_types opt_doc_method_sig
7191 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7192 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7195 | VOID opt_doc_method_sig
7197 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7198 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7201 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7203 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7204 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7205 var lt = (LocatedToken) $3;
7206 $$ = new MemberName (lt.Value);
7208 | doc_type_declaration_name DOT THIS
7210 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7212 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7214 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7216 opt_doc_parameters CLOSE_BRACKET
7218 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7219 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7221 | EXPLICIT OPERATOR type opt_doc_method_sig
7223 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7224 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7225 module.DocumentationBuilder.ParsedParameters = p;
7226 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7229 | IMPLICIT OPERATOR type opt_doc_method_sig
7231 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7232 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7233 module.DocumentationBuilder.ParsedParameters = p;
7234 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7237 | OPERATOR overloadable_operator opt_doc_method_sig
7239 var p = (List<DocumentationParameter>)$3;
7240 module.DocumentationBuilder.ParsedParameters = p;
7241 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7246 doc_type_declaration_name
7247 : type_declaration_name
7248 | doc_type_declaration_name DOT type_declaration_name
7250 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7258 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7260 opt_doc_parameters CLOSE_PARENS
7269 $$ = new List<DocumentationParameter> (0);
7277 var parameters = new List<DocumentationParameter> ();
7278 parameters.Add ((DocumentationParameter) $1);
7281 | doc_parameters COMMA doc_parameter
7283 var parameters = $1 as List<DocumentationParameter>;
7284 parameters.Add ((DocumentationParameter) $3);
7290 : opt_parameter_modifier parameter_type
7293 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7295 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7302 // A class used to hold info about an operator declarator
7304 class OperatorDeclaration {
7305 public readonly Operator.OpType optype;
7306 public readonly FullNamedExpression ret_type;
7307 public readonly Location location;
7309 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7312 this.ret_type = ret_type;
7313 this.location = location;
7317 void Error_ExpectingTypeName (Expression expr)
7319 if (expr is Invocation){
7320 report.Error (1002, expr.Location, "Expecting `;'");
7322 expr.Error_InvalidExpressionStatement (report);
7326 void Error_ParameterModifierNotValid (string modifier, Location loc)
7328 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7332 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7334 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7335 Parameter.GetModifierSignature (mod));
7338 void Error_TypeExpected (Location loc)
7340 report.Error (1031, loc, "Type expected");
7343 void Error_UnsafeCodeNotAllowed (Location loc)
7345 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7348 void Warning_EmptyStatement (Location loc)
7350 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7353 void Error_NamedArgumentExpected (NamedArgument a)
7355 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7358 void Error_MissingInitializer (Location loc)
7360 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7363 object Error_AwaitAsIdentifier (object token)
7366 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7367 return new LocatedToken ("await", GetLocation (token));
7373 void push_current_container (TypeDefinition tc, object partial_token)
7375 if (module.Evaluator != null){
7376 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7380 undo.AddTypeContainer (current_container, tc);
7383 if (partial_token != null)
7384 current_container.AddPartial (tc);
7386 current_container.AddTypeContainer (tc);
7388 ++lexer.parsing_declaration;
7389 current_container = tc;
7393 TypeContainer pop_current_class ()
7395 var retval = current_container;
7397 current_container = current_container.Parent;
7398 current_type = current_type.Parent as TypeDefinition;
7403 [System.Diagnostics.Conditional ("FULL_AST")]
7404 void StoreModifierLocation (object token, Location loc)
7409 if (mod_locations == null)
7410 mod_locations = new List<Tuple<Modifiers, Location>> ();
7412 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7415 [System.Diagnostics.Conditional ("FULL_AST")]
7416 void PushLocation (Location loc)
7418 if (location_stack == null)
7419 location_stack = new Stack<Location> ();
7421 location_stack.Push (loc);
7424 Location PopLocation ()
7426 if (location_stack == null)
7427 return Location.Null;
7429 return location_stack.Pop ();
7432 string CheckAttributeTarget (int token, string a, Location l)
7435 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7439 if (!Tokenizer.IsValidIdentifier (a)) {
7440 Error_SyntaxError (token);
7442 report.Warning (658, 1, l,
7443 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7446 return string.Empty;
7449 static bool IsUnaryOperator (Operator.OpType op)
7453 case Operator.OpType.LogicalNot:
7454 case Operator.OpType.OnesComplement:
7455 case Operator.OpType.Increment:
7456 case Operator.OpType.Decrement:
7457 case Operator.OpType.True:
7458 case Operator.OpType.False:
7459 case Operator.OpType.UnaryPlus:
7460 case Operator.OpType.UnaryNegation:
7466 void syntax_error (Location l, string msg)
7468 report.Error (1003, l, "Syntax error, " + msg);
7473 public Tokenizer Lexer {
7479 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7480 : this (reader, file, file.Compiler.Report, session)
7484 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7487 current_container = current_namespace = file;
7489 this.module = file.Module;
7490 this.compiler = file.Compiler;
7491 this.settings = compiler.Settings;
7492 this.report = report;
7494 lang_version = settings.Version;
7495 yacc_verbose_flag = settings.VerboseParserFlag;
7496 doc_support = settings.DocumentationFile != null;
7497 lexer = new Tokenizer (reader, file, session, report);
7498 oob_stack = new Stack<object> ();
7499 lbag = session.LocationsBag;
7500 use_global_stacks = session.UseJayGlobalArrays;
7501 parameters_bucket = session.ParametersStack;
7504 public void parse ()
7506 eof_token = Token.EOF;
7509 if (yacc_verbose_flag > 1)
7510 yyparse (lexer, new yydebug.yyDebugSimple ());
7514 Tokenizer tokenizer = lexer as Tokenizer;
7515 tokenizer.cleanup ();
7516 } catch (Exception e){
7517 if (e is yyParser.yyUnexpectedEof) {
7518 Error_SyntaxError (yyToken);
7519 UnexpectedEOF = true;
7523 if (e is yyParser.yyException) {
7524 if (report.Errors == 0)
7525 report.Error (-25, lexer.Location, "Parsing error");
7527 // Used by compiler-tester to test internal errors
7528 if (yacc_verbose_flag > 0 || e is FatalException)
7531 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7536 void CheckToken (int error, int yyToken, string msg, Location loc)
7538 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7539 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7541 report.Error (error, loc, msg);
7544 string ConsumeStoredComment ()
7546 string s = tmpComment;
7548 Lexer.doc_state = XmlCommentState.Allowed;
7552 void FeatureIsNotAvailable (Location loc, string feature)
7554 report.FeatureIsNotAvailable (compiler, loc, feature);
7557 Location GetLocation (object obj)
7559 var lt = obj as LocatedToken;
7563 var mn = obj as MemberName;
7567 var expr = obj as Expression;
7569 return expr.Location;
7571 return lexer.Location;
7574 void start_block (Location loc)
7576 if (current_block == null) {
7577 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7578 parsing_anonymous_method = false;
7579 } else if (parsing_anonymous_method) {
7580 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7581 parsing_anonymous_method = false;
7583 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7588 end_block (Location loc)
7590 Block retval = current_block.Explicit;
7591 retval.SetEndLocation (loc);
7592 current_block = retval.Parent;
7596 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7598 oob_stack.Push (current_anonymous_method);
7599 oob_stack.Push (current_local_parameters);
7600 oob_stack.Push (current_variable);
7601 oob_stack.Push (async_block);
7603 current_local_parameters = parameters;
7605 if (lang_version <= LanguageVersion.ISO_2)
7606 FeatureIsNotAvailable (loc, "lambda expressions");
7608 current_anonymous_method = new LambdaExpression (loc);
7610 if (lang_version == LanguageVersion.ISO_1)
7611 FeatureIsNotAvailable (loc, "anonymous methods");
7613 current_anonymous_method = new AnonymousMethodExpression (loc);
7616 async_block = isAsync;
7617 // Force the next block to be created as a ToplevelBlock
7618 parsing_anonymous_method = true;
7622 * Completes the anonymous method processing, if lambda_expr is null, this
7623 * means that we have a Statement instead of an Expression embedded
7625 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7627 AnonymousMethodExpression retval;
7630 anon_block.IsAsync = true;
7632 current_anonymous_method.Block = anon_block;
7633 retval = current_anonymous_method;
7635 async_block = (bool) oob_stack.Pop ();
7636 current_variable = (BlockVariable) oob_stack.Pop ();
7637 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7638 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7643 void Error_SyntaxError (int token)
7645 Error_SyntaxError (0, token);
7648 void Error_SyntaxError (int error_code, int token)
7650 Error_SyntaxError (error_code, token, "Unexpected symbol");
7653 void Error_SyntaxError (int error_code, int token, string msg)
7655 Lexer.CompleteOnEOF = false;
7657 // An error message has been reported by tokenizer
7658 if (token == Token.ERROR)
7661 // Avoid duplicit error message after unterminated string literals
7662 if (token == Token.LITERAL && lexer.Location.Column == 0)
7665 string symbol = GetSymbolName (token);
7666 string expecting = GetExpecting ();
7667 var loc = lexer.Location - symbol.Length;
7669 if (error_code == 0) {
7670 if (expecting == "`identifier'") {
7671 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7672 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7677 expecting = "identifier";
7678 } else if (expecting == "`)'") {
7685 if (string.IsNullOrEmpty (expecting))
7686 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7688 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7691 string GetExpecting ()
7693 int [] tokens = yyExpectingTokens (yyExpectingState);
7694 var names = new List<string> (tokens.Length);
7695 bool has_type = false;
7696 bool has_identifier = false;
7697 for (int i = 0; i < tokens.Length; i++){
7698 int token = tokens [i];
7699 has_identifier |= token == Token.IDENTIFIER;
7701 string name = GetTokenName (token);
7702 if (name == "<internal>")
7705 has_type |= name == "type";
7706 if (names.Contains (name))
7713 // Too many tokens to enumerate
7715 if (names.Count > 8)
7718 if (has_type && has_identifier)
7719 names.Remove ("identifier");
7721 if (names.Count == 1)
7722 return "`" + GetTokenName (tokens [0]) + "'";
7724 StringBuilder sb = new StringBuilder ();
7726 int count = names.Count;
7727 for (int i = 0; i < count; i++){
7728 bool last = i + 1 == count;
7732 sb.Append (names [i]);
7733 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7735 return sb.ToString ();
7739 string GetSymbolName (int token)
7743 return ((Constant)lexer.Value).GetValue ().ToString ();
7744 case Token.IDENTIFIER:
7745 return ((LocatedToken)lexer.Value).Value;
7787 case Token.BITWISE_AND:
7789 case Token.BITWISE_OR:
7803 case Token.OP_SHIFT_LEFT:
7805 case Token.OP_SHIFT_RIGHT:
7825 case Token.OP_COALESCING:
7827 case Token.OP_MULT_ASSIGN:
7829 case Token.OP_DIV_ASSIGN:
7831 case Token.OP_MOD_ASSIGN:
7833 case Token.OP_ADD_ASSIGN:
7835 case Token.OP_SUB_ASSIGN:
7837 case Token.OP_SHIFT_LEFT_ASSIGN:
7839 case Token.OP_SHIFT_RIGHT_ASSIGN:
7841 case Token.OP_AND_ASSIGN:
7843 case Token.OP_XOR_ASSIGN:
7845 case Token.OP_OR_ASSIGN:
7849 return GetTokenName (token);
7852 static string GetTokenName (int token)
7855 case Token.ABSTRACT:
7877 case Token.CONTINUE:
7881 case Token.DELEGATE:
7891 case Token.EXPLICIT:
7894 case Token.EXTERN_ALIAS:
7910 case Token.IMPLICIT:
7914 case Token.INTERFACE:
7916 case Token.INTERNAL:
7922 case Token.NAMESPACE:
7928 case Token.OPERATOR:
7932 case Token.OVERRIDE:
7938 case Token.PROTECTED:
7942 case Token.READONLY:
7954 case Token.STACKALLOC:
7955 return "stackalloc";
7972 case Token.UNCHECKED:
7980 case Token.VOLATILE:
7988 case Token.REFVALUE:
7989 return "__refvalue";
7999 case Token.FROM_FIRST:
8017 case Token.ASCENDING:
8019 case Token.DESCENDING:
8020 return "descending";
8027 case Token.OPEN_BRACE:
8029 case Token.CLOSE_BRACE:
8031 case Token.OPEN_BRACKET:
8032 case Token.OPEN_BRACKET_EXPR:
8034 case Token.CLOSE_BRACKET:
8036 case Token.OPEN_PARENS_CAST:
8037 case Token.OPEN_PARENS_LAMBDA:
8038 case Token.OPEN_PARENS:
8040 case Token.CLOSE_PARENS:
8046 case Token.DEFAULT_COLON:
8050 case Token.SEMICOLON:
8061 case Token.BITWISE_AND:
8062 case Token.BITWISE_OR:
8069 case Token.OP_SHIFT_LEFT:
8070 case Token.OP_SHIFT_RIGHT:
8078 case Token.OP_COALESCING:
8079 case Token.OP_MULT_ASSIGN:
8080 case Token.OP_DIV_ASSIGN:
8081 case Token.OP_MOD_ASSIGN:
8082 case Token.OP_ADD_ASSIGN:
8083 case Token.OP_SUB_ASSIGN:
8084 case Token.OP_SHIFT_LEFT_ASSIGN:
8085 case Token.OP_SHIFT_RIGHT_ASSIGN:
8086 case Token.OP_AND_ASSIGN:
8087 case Token.OP_XOR_ASSIGN:
8088 case Token.OP_OR_ASSIGN:
8089 case Token.INTERR_OPERATOR:
8090 return "<operator>";
8112 case Token.OP_GENERICS_LT:
8113 case Token.GENERIC_DIMENSION:
8115 case Token.OP_GENERICS_GT:
8118 case Token.INTERR_NULLABLE:
8120 case Token.DOUBLE_COLON:
8124 case Token.IDENTIFIER:
8126 return "identifier";
8129 return "end-of-file";
8131 // All of these are internal.
8134 case Token.FIRST_KEYWORD:
8135 case Token.EVAL_COMPILATION_UNIT_PARSER:
8136 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8137 case Token.EVAL_STATEMENT_PARSER:
8138 case Token.LAST_KEYWORD:
8139 case Token.GENERATE_COMPLETION:
8140 case Token.COMPLETE_COMPLETION:
8141 return "<internal>";
8143 // A bit more robust.
8145 return yyNames [token];