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 opt_static namespace_or_type_expr SEMICOLON
467 if (lang_version <= LanguageVersion.V_5)
468 FeatureIsNotAvailable (GetLocation ($2), "using static");
470 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
471 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
473 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
474 lbag.AddLocation (uc, GetLocation ($4));
477 current_namespace.AddUsing (uc);
479 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
481 var lt = (LocatedToken) $3;
482 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
483 report.Warning (440, 2, lt.Location,
484 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
488 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
491 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
492 current_namespace.AddUsing (un);
494 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
498 Error_SyntaxError (yyToken);
509 // Strictly speaking, namespaces don't have attributes but
510 // we parse global attributes along with namespace declarations and then
513 namespace_declaration
514 : opt_attributes NAMESPACE namespace_name
516 Attributes attrs = (Attributes) $1;
517 var name = (MemberName) $3;
519 bool valid_global_attrs = true;
520 if ((current_namespace.DeclarationFound || current_namespace != file)) {
521 valid_global_attrs = false;
523 foreach (var a in attrs.Attrs) {
524 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
527 valid_global_attrs = false;
532 if (!valid_global_attrs)
533 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
536 module.AddAttributes (attrs, current_namespace);
538 var ns = new NamespaceContainer (name, current_namespace);
539 current_namespace.AddTypeContainer (ns);
540 current_container = current_namespace = ns;
545 Lexer.doc_state = XmlCommentState.Allowed;
547 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
550 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
552 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
554 current_container = current_namespace = current_namespace.Parent;
556 | opt_attributes NAMESPACE namespace_name
558 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
560 var name = (MemberName) $3;
561 var ns = new NamespaceContainer (name, current_namespace);
562 lbag.AddLocation (ns, GetLocation ($2));
563 current_namespace.AddTypeContainer (ns);
572 Error_SyntaxError (yyToken);
580 var lt = (LocatedToken) $1;
581 $$ = new MemberName (lt.Value, lt.Location);
583 | namespace_name DOT IDENTIFIER
585 var lt = (LocatedToken) $3;
586 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
587 lbag.AddLocation ($$, GetLocation ($2));
591 Error_SyntaxError (yyToken);
592 $$ = new MemberName ("<invalid>", lexer.Location);
611 opt_extern_alias_directives
613 | extern_alias_directives
616 opt_namespace_or_type_declarations
618 | namespace_or_type_declarations
621 namespace_or_type_declarations
622 : namespace_or_type_declaration
623 | namespace_or_type_declarations namespace_or_type_declaration
626 namespace_or_type_declaration
630 TypeContainer ds = (TypeContainer)$1;
632 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
633 report.Error (1527, ds.Location,
634 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
637 // Here is a trick, for explicit attributes we don't know where they belong to until
638 // we parse succeeding declaration hence we parse them as normal and re-attach them
639 // when we know whether they are global (assembly:, module:) or local (type:).
640 if (ds.OptAttributes != null) {
641 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
644 current_namespace.DeclarationFound = true;
646 | namespace_declaration
648 current_namespace.DeclarationFound = true;
650 | attribute_sections CLOSE_BRACE {
651 current_namespace.UnattachedAttributes = (Attributes) $1;
652 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
660 | interface_declaration
662 | delegate_declaration
664 // Enable this when we have handled all errors, because this acts as a generic fallback
667 // Console.WriteLine ("Token=" + yyToken);
668 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
684 var sect = (List<Attribute>) $1;
685 $$ = new Attributes (sect);
687 | attribute_sections attribute_section
689 Attributes attrs = $1 as Attributes;
690 var sect = (List<Attribute>) $2;
692 attrs = new Attributes (sect);
693 else if (sect != null)
694 attrs.AddAttributes (sect);
702 PushLocation (GetLocation ($1));
703 lexer.parsing_attribute_section = true;
705 attribute_section_cont
707 lexer.parsing_attribute_section = false;
712 attribute_section_cont
713 : attribute_target COLON
715 current_attr_target = (string) $1;
716 if (current_attr_target == "assembly" || current_attr_target == "module") {
717 Lexer.check_incorrect_doc_comment ();
720 attribute_list opt_comma CLOSE_BRACKET
722 // when attribute target is invalid
723 if (current_attr_target == string.Empty)
724 $$ = new List<Attribute> (0);
728 lbag.InsertLocation ($$, 0, PopLocation ());
730 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
732 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
735 current_attr_target = null;
736 lexer.parsing_attribute_section = false;
738 | attribute_list opt_comma CLOSE_BRACKET
742 lbag.InsertLocation ($$, 0, PopLocation ());
744 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
746 lbag.AddLocation ($$, GetLocation($3));
751 Error_SyntaxError (yyToken);
753 var lt = (LocatedToken) $1;
754 var tne = new SimpleName (lt.Value, null, lt.Location);
756 $$ = new List<Attribute> () {
757 new Attribute (null, tne, null, GetLocation ($1), false)
762 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
763 Error_SyntaxError (yyToken);
772 var lt = (LocatedToken) $1;
773 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
775 | EVENT { $$ = "event"; }
776 | RETURN { $$ = "return"; }
782 $$ = new List<Attribute> (4) { (Attribute) $1 };
784 | attribute_list COMMA attribute
786 var attrs = (List<Attribute>) $1;
788 attrs.Add ((Attribute) $3);
789 lbag.AppendTo (attrs, GetLocation ($2));
799 ++lexer.parsing_block;
801 opt_attribute_arguments
803 --lexer.parsing_block;
805 var tne = (ATypeNameExpression) $1;
806 if (tne.HasTypeArguments) {
807 report.Error (404, tne.Location, "Attributes cannot be generic");
810 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
815 : namespace_or_type_expr
818 opt_attribute_arguments
819 : /* empty */ { $$ = null; }
820 | OPEN_PARENS attribute_arguments CLOSE_PARENS
828 : /* empty */ { $$ = null; }
829 | positional_or_named_argument
831 Arguments a = new Arguments (4);
832 a.Add ((Argument) $1);
833 $$ = new Arguments [] { a, null };
835 | named_attribute_argument
837 Arguments a = new Arguments (4);
838 a.Add ((Argument) $1);
839 $$ = new Arguments [] { null, a };
841 | attribute_arguments COMMA positional_or_named_argument
843 Arguments[] o = (Arguments[]) $1;
845 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
846 o [0] = new Arguments (4);
849 Arguments args = ((Arguments) o [0]);
850 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
851 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
853 args.Add ((Argument) $3);
855 | attribute_arguments COMMA named_attribute_argument
857 Arguments[] o = (Arguments[]) $1;
859 o [1] = new Arguments (4);
862 ((Arguments) o [1]).Add ((Argument) $3);
866 positional_or_named_argument
869 $$ = new Argument ((Expression) $1);
874 Error_SyntaxError (yyToken);
879 named_attribute_argument
882 ++lexer.parsing_block;
886 --lexer.parsing_block;
887 var lt = (LocatedToken) $1;
888 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
889 lbag.AddLocation ($$, GetLocation($2));
894 : identifier_inside_body COLON opt_named_modifier named_argument_expr
896 if (lang_version <= LanguageVersion.V_3)
897 FeatureIsNotAvailable (GetLocation ($1), "named argument");
899 // Avoid boxing in common case (no modifier)
900 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
902 var lt = (LocatedToken) $1;
903 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
904 lbag.AddLocation ($$, GetLocation($2));
909 : expression_or_error
910 // | declaration_expression
914 : /* empty */ { $$ = null; }
917 $$ = Argument.AType.Ref;
921 $$ = Argument.AType.Out;
925 opt_class_member_declarations
927 | class_member_declarations
930 class_member_declarations
931 : class_member_declaration
933 lexer.parsing_modifiers = true;
934 lexer.parsing_block = 0;
936 | class_member_declarations class_member_declaration
938 lexer.parsing_modifiers = true;
939 lexer.parsing_block = 0;
943 class_member_declaration
944 : constant_declaration
947 | property_declaration
949 | indexer_declaration
950 | operator_declaration
951 | constructor_declaration
952 | primary_constructor_body
953 | destructor_declaration
955 | attributes_without_members
959 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
960 GetSymbolName (yyToken));
962 lexer.parsing_generic_declaration = false;
966 primary_constructor_body
969 current_local_parameters = current_type.PrimaryConstructorParameters;
970 if (current_local_parameters == null) {
971 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
972 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
975 ++lexer.parsing_block;
976 start_block (GetLocation ($1));
978 opt_statement_list block_end
980 current_local_parameters = null;
981 var t = current_type as ClassOrStruct;
983 var b = (ToplevelBlock) $4;
984 if (t.PrimaryConstructorBlock != null) {
985 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
987 t.PrimaryConstructorBlock = b;
1000 type_declaration_name
1002 lexer.ConstraintsParsing = true;
1003 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1004 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1006 opt_primary_parameters
1008 opt_type_parameter_constraints_clauses
1010 valid_param_mod = 0;
1011 lexer.ConstraintsParsing = false;
1014 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
1017 current_container.SetConstraints ((List<Constraints>) $10);
1020 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1022 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1024 lexer.parsing_modifiers = true;
1029 Lexer.doc_state = XmlCommentState.Allowed;
1031 opt_class_member_declarations CLOSE_BRACE
1033 --lexer.parsing_declaration;
1035 Lexer.doc_state = XmlCommentState.Allowed;
1040 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1042 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1044 $$ = pop_current_class ();
1046 | opt_attributes opt_modifiers opt_partial STRUCT error
1048 Error_SyntaxError (yyToken);
1052 constant_declaration
1055 CONST type IDENTIFIER
1057 var lt = (LocatedToken) $5;
1058 var mod = (Modifiers) $2;
1059 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1060 current_type.AddMember (current_field);
1062 if ((mod & Modifiers.STATIC) != 0) {
1063 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1068 constant_initializer opt_constant_declarators SEMICOLON
1071 current_field.DocComment = Lexer.consume_doc_comment ();
1072 Lexer.doc_state = XmlCommentState.Allowed;
1075 current_field.Initializer = (ConstInitializer) $7;
1076 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1077 current_field = null;
1083 Error_SyntaxError (yyToken);
1085 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1089 opt_constant_declarators
1091 | constant_declarators
1094 constant_declarators
1095 : constant_declarator
1097 current_field.AddDeclarator ((FieldDeclarator) $1);
1099 | constant_declarators constant_declarator
1101 current_field.AddDeclarator ((FieldDeclarator) $2);
1106 : COMMA IDENTIFIER constant_initializer
1108 var lt = (LocatedToken) $2;
1109 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1110 lbag.AddLocation ($$, GetLocation ($1));
1114 constant_initializer
1117 ++lexer.parsing_block;
1119 constant_initializer_expr
1121 --lexer.parsing_block;
1122 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1126 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1131 constant_initializer_expr
1132 : constant_expression
1139 member_type IDENTIFIER
1141 lexer.parsing_generic_declaration = false;
1143 FullNamedExpression type = (FullNamedExpression) $3;
1144 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1145 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1147 var lt = (LocatedToken) $4;
1148 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1149 current_type.AddField (current_field);
1152 opt_field_initializer
1153 opt_field_declarators
1157 current_field.DocComment = Lexer.consume_doc_comment ();
1158 Lexer.doc_state = XmlCommentState.Allowed;
1161 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1163 current_field = null;
1167 FIXED simple_type IDENTIFIER
1169 if (lang_version < LanguageVersion.ISO_2)
1170 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1172 var lt = (LocatedToken) $5;
1173 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1174 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1176 current_type.AddField (current_field);
1178 fixed_field_size opt_fixed_field_declarators SEMICOLON
1181 current_field.DocComment = Lexer.consume_doc_comment ();
1182 Lexer.doc_state = XmlCommentState.Allowed;
1185 current_field.Initializer = (ConstInitializer) $7;
1186 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1188 current_field = null;
1192 FIXED simple_type error
1195 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1199 opt_field_initializer
1203 ++lexer.parsing_block;
1204 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1205 start_block (GetLocation ($1));
1207 variable_initializer
1209 --lexer.parsing_block;
1210 current_field.Initializer = (Expression) $3;
1211 lbag.AppendToMember (current_field, GetLocation ($1));
1212 end_block (lexer.Location);
1213 current_local_parameters = null;
1217 opt_field_declarators
1225 current_field.AddDeclarator ((FieldDeclarator) $1);
1227 | field_declarators field_declarator
1229 current_field.AddDeclarator ((FieldDeclarator) $2);
1236 var lt = (LocatedToken) $2;
1237 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1238 lbag.AddLocation ($$, GetLocation ($1));
1240 | COMMA IDENTIFIER ASSIGN
1242 ++lexer.parsing_block;
1244 variable_initializer
1246 --lexer.parsing_block;
1247 var lt = (LocatedToken) $2;
1248 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1249 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1253 opt_fixed_field_declarators
1255 | fixed_field_declarators
1258 fixed_field_declarators
1259 : fixed_field_declarator
1261 current_field.AddDeclarator ((FieldDeclarator) $1);
1263 | fixed_field_declarators fixed_field_declarator
1265 current_field.AddDeclarator ((FieldDeclarator) $2);
1269 fixed_field_declarator
1270 : COMMA IDENTIFIER fixed_field_size
1272 var lt = (LocatedToken) $2;
1273 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1274 lbag.AddLocation ($$, GetLocation ($1));
1281 ++lexer.parsing_block;
1283 expression CLOSE_BRACKET
1285 --lexer.parsing_block;
1286 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1287 lbag.AddLocation ($$, GetLocation ($4));
1289 | OPEN_BRACKET error
1291 report.Error (443, lexer.Location, "Value or constant expected");
1296 variable_initializer
1301 // It has to be here for the parent to safely restore artificial block
1302 Error_SyntaxError (yyToken);
1311 Lexer.doc_state = XmlCommentState.NotAllowed;
1313 // Was added earlier in the case of body being eof for full ast
1315 method_body_expression_block
1317 Method method = (Method) $1;
1318 method.Block = (ToplevelBlock) $3;
1319 async_block = false;
1321 if (method.Block == null) {
1322 method.ParameterInfo.CheckParameters (method);
1324 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1325 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1326 method.GetSignatureForError ());
1329 if (current_container.Kind == MemberKind.Interface) {
1330 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1331 method.GetSignatureForError ());
1335 current_local_parameters = null;
1338 Lexer.doc_state = XmlCommentState.Allowed;
1346 method_declaration_name OPEN_PARENS
1348 valid_param_mod = ParameterModifierType.All;
1350 opt_formal_parameter_list CLOSE_PARENS
1352 valid_param_mod = 0;
1353 MemberName name = (MemberName) $4;
1354 current_local_parameters = (ParametersCompiled) $7;
1356 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1357 name, current_local_parameters, (Attributes) $1);
1359 current_type.AddMember (method);
1361 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1364 method.DocComment = Lexer.consume_doc_comment ();
1366 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1370 lexer.ConstraintsParsing = true;
1372 opt_type_parameter_constraints_clauses
1374 lexer.ConstraintsParsing = false;
1377 var method = (Method) $9;
1378 method.SetConstraints ((List<Constraints>) $10);
1388 lexer.parsing_generic_declaration = true;
1390 method_declaration_name
1393 lexer.parsing_generic_declaration = false;
1394 valid_param_mod = ParameterModifierType.All;
1396 opt_formal_parameter_list CLOSE_PARENS
1398 lexer.ConstraintsParsing = true;
1400 opt_type_parameter_constraints_clauses
1402 lexer.ConstraintsParsing = false;
1403 valid_param_mod = 0;
1405 MemberName name = (MemberName) $6;
1406 current_local_parameters = (ParametersCompiled) $9;
1408 var modifiers = (Modifiers) $2;
1409 modifiers |= Modifiers.PARTIAL;
1411 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1412 modifiers, name, current_local_parameters, (Attributes) $1);
1414 current_type.AddMember (method);
1416 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1419 method.SetConstraints ((List<Constraints>) $12);
1422 method.DocComment = Lexer.consume_doc_comment ();
1424 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1425 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1431 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1433 MemberName name = (MemberName) $5;
1434 report.Error (1585, name.Location,
1435 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1437 var method = Method.Create (current_type, (FullNamedExpression) $3,
1438 0, name, (ParametersCompiled) $7, (Attributes) $1);
1440 current_type.AddMember (method);
1442 current_local_parameters = (ParametersCompiled) $7;
1445 method.DocComment = Lexer.consume_doc_comment ();
1452 method_declaration_name error
1454 Error_SyntaxError (yyToken);
1455 current_local_parameters = ParametersCompiled.Undefined;
1457 MemberName name = (MemberName) $4;
1458 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1459 name, current_local_parameters, (Attributes) $1);
1461 current_type.AddMember (method);
1464 method.DocComment = Lexer.consume_doc_comment ();
1470 method_body_expression_block
1477 | SEMICOLON { $$ = null; }
1483 if (lang_version < LanguageVersion.V_6) {
1484 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1487 ++lexer.parsing_block;
1488 start_block (GetLocation ($1));
1490 expression SEMICOLON
1492 lexer.parsing_block = 0;
1493 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1494 var b = end_block (GetLocation ($4));
1495 b.IsCompilerGenerated = true;
1500 opt_formal_parameter_list
1501 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1502 | formal_parameter_list
1505 formal_parameter_list
1508 var pars_list = (List<Parameter>) $1;
1509 $$ = new ParametersCompiled (pars_list.ToArray ());
1511 | fixed_parameters COMMA parameter_array
1513 var pars_list = (List<Parameter>) $1;
1514 pars_list.Add ((Parameter) $3);
1516 $$ = new ParametersCompiled (pars_list.ToArray ());
1518 | fixed_parameters COMMA arglist_modifier
1520 var pars_list = (List<Parameter>) $1;
1521 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1522 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1524 | parameter_array COMMA error
1527 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1529 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1531 | fixed_parameters COMMA parameter_array COMMA error
1534 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1536 var pars_list = (List<Parameter>) $1;
1537 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1539 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1541 | arglist_modifier COMMA error
1543 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1545 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1547 | fixed_parameters COMMA ARGLIST COMMA error
1549 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1551 var pars_list = (List<Parameter>) $1;
1552 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1554 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1558 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1562 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1566 Error_SyntaxError (yyToken);
1567 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1574 parameters_bucket.Clear ();
1575 Parameter p = (Parameter) $1;
1576 parameters_bucket.Add (p);
1578 default_parameter_used = p.HasDefaultValue;
1579 $$ = parameters_bucket;
1581 | fixed_parameters COMMA fixed_parameter
1583 var pars = (List<Parameter>) $1;
1584 Parameter p = (Parameter) $3;
1586 if (p.HasExtensionMethodModifier)
1587 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1588 else if (!p.HasDefaultValue && default_parameter_used)
1589 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1591 default_parameter_used |= p.HasDefaultValue;
1594 lbag.AddLocation (p, GetLocation ($2));
1603 opt_parameter_modifier
1605 identifier_inside_body
1607 var lt = (LocatedToken) $4;
1608 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1611 opt_parameter_modifier
1613 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1615 var lt = (LocatedToken) $4;
1616 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1617 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1619 | attribute_sections error
1621 Error_SyntaxError (yyToken);
1622 Location l = GetLocation ($2);
1623 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1626 opt_parameter_modifier
1630 Error_SyntaxError (yyToken);
1631 Location l = GetLocation ($4);
1632 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1635 opt_parameter_modifier
1637 identifier_inside_body
1640 ++lexer.parsing_block;
1644 --lexer.parsing_block;
1645 if (lang_version <= LanguageVersion.V_3) {
1646 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1649 Parameter.Modifier mod = (Parameter.Modifier) $2;
1650 if (mod != Parameter.Modifier.NONE) {
1652 case Parameter.Modifier.REF:
1653 case Parameter.Modifier.OUT:
1654 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1655 Parameter.GetModifierSignature (mod));
1658 case Parameter.Modifier.This:
1659 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1660 Parameter.GetModifierSignature (mod));
1663 throw new NotImplementedException (mod.ToString ());
1666 mod = Parameter.Modifier.NONE;
1669 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1670 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1672 var lt = (LocatedToken) $4;
1673 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1674 lbag.AddLocation ($$, GetLocation ($5));
1677 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1681 opt_parameter_modifier
1682 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1683 | parameter_modifiers
1687 : parameter_modifier
1691 | parameter_modifiers parameter_modifier
1693 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1694 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1695 if (((Parameter.Modifier)$1 & p2) == p2) {
1696 Error_DuplicateParameterModifier (lexer.Location, p2);
1698 switch (mod & ~Parameter.Modifier.This) {
1699 case Parameter.Modifier.REF:
1700 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1702 case Parameter.Modifier.OUT:
1703 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1706 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1717 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1718 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1720 $$ = Parameter.Modifier.REF;
1724 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1725 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1727 $$ = Parameter.Modifier.OUT;
1731 if ((valid_param_mod & ParameterModifierType.This) == 0)
1732 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1734 if (lang_version <= LanguageVersion.ISO_2)
1735 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1737 $$ = Parameter.Modifier.This;
1742 : opt_attributes params_modifier type IDENTIFIER
1744 var lt = (LocatedToken) $4;
1745 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1747 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1749 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1751 var lt = (LocatedToken) $4;
1752 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1754 | opt_attributes params_modifier type error
1756 Error_SyntaxError (yyToken);
1758 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1765 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1766 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1768 | PARAMS parameter_modifier
1770 Parameter.Modifier mod = (Parameter.Modifier)$2;
1771 if ((mod & Parameter.Modifier.This) != 0) {
1772 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1774 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1777 | PARAMS params_modifier
1779 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1786 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1787 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1791 property_declaration
1795 member_declaration_name
1797 lexer.parsing_generic_declaration = false;
1799 tmpComment = Lexer.consume_doc_comment ();
1803 var type = (FullNamedExpression) $3;
1804 current_property = new Property (current_type, type, (Modifiers) $2,
1805 (MemberName) $4, (Attributes) $1);
1807 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1808 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1810 current_type.AddMember (current_property);
1811 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1813 lexer.PropertyParsing = true;
1815 accessor_declarations
1817 lexer.PropertyParsing = false;
1820 current_property.DocComment = ConsumeStoredComment ();
1824 lbag.AppendToMember (current_property, GetLocation ($10));
1825 lexer.parsing_modifiers = true;
1827 opt_property_initializer
1829 current_property = null;
1834 member_declaration_name
1836 lexer.parsing_generic_declaration = false;
1838 tmpComment = Lexer.consume_doc_comment ();
1839 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1843 var type = (FullNamedExpression) $3;
1844 var property = new Property (current_type, type, (Modifiers) $2,
1845 (MemberName) $4, (Attributes) $1);
1847 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1848 property.Get.Block = (ToplevelBlock) $6;
1850 if (current_container.Kind == MemberKind.Interface) {
1851 report.Error (531, property.Get.Block.StartLocation,
1852 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1855 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1856 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1858 current_type.AddMember (property);
1860 current_local_parameters = null;
1864 opt_property_initializer
1868 ++lexer.parsing_block;
1869 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1870 start_block (GetLocation ($1));
1872 property_initializer SEMICOLON
1874 --lexer.parsing_block;
1875 ((Property)current_property).Initializer = (Expression) $3;
1876 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1877 end_block (GetLocation ($4));
1878 current_local_parameters = null;
1882 property_initializer
1888 : opt_attributes opt_modifiers
1889 member_type indexer_declaration_name OPEN_BRACKET
1891 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1893 opt_formal_parameter_list CLOSE_BRACKET
1895 valid_param_mod = 0;
1896 var type = (FullNamedExpression) $3;
1897 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1899 current_property = indexer;
1901 current_type.AddIndexer (indexer);
1902 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1904 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1905 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1907 if (indexer.ParameterInfo.IsEmpty) {
1908 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1912 tmpComment = Lexer.consume_doc_comment ();
1913 Lexer.doc_state = XmlCommentState.Allowed;
1916 lexer.PropertyParsing = true;
1917 current_local_parameters = (ParametersCompiled) $7;
1921 lexer.PropertyParsing = false;
1922 current_local_parameters = null;
1924 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1925 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1928 current_property.DocComment = ConsumeStoredComment ();
1930 current_property = null;
1935 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1937 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1941 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1942 current_property.Get.Block = (ToplevelBlock) $1;
1946 accessor_declarations
1947 : get_accessor_declaration
1948 | get_accessor_declaration accessor_declarations
1949 | set_accessor_declaration
1950 | set_accessor_declaration accessor_declarations
1953 if (yyToken == Token.CLOSE_BRACE) {
1954 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1956 if (yyToken == Token.SEMICOLON)
1957 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1959 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1964 get_accessor_declaration
1965 : opt_attributes opt_modifiers GET
1967 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1968 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1971 if (current_property.Get != null) {
1972 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1975 if (current_property is Indexer) {
1976 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1977 (Attributes) $1, GetLocation ($3));
1979 current_property.Get = new Property.GetMethod (current_property,
1980 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1983 current_local_parameters = current_property.Get.ParameterInfo;
1984 lbag.AddMember (current_property.Get, mod_locations);
1985 lexer.PropertyParsing = false;
1990 current_property.Get.Block = (ToplevelBlock) $5;
1992 if (current_container.Kind == MemberKind.Interface) {
1993 report.Error (531, current_property.Get.Block.StartLocation,
1994 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1998 current_local_parameters = null;
1999 lexer.PropertyParsing = true;
2002 if (Lexer.doc_state == XmlCommentState.Error)
2003 Lexer.doc_state = XmlCommentState.NotAllowed;
2007 set_accessor_declaration
2008 : opt_attributes opt_modifiers SET
2010 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2011 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2014 if (current_property.Set != null) {
2015 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2018 if (current_property is Indexer) {
2019 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2020 ParametersCompiled.MergeGenerated (compiler,
2021 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2022 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2024 (Attributes) $1, GetLocation ($3));
2026 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2027 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2028 (Attributes) $1, GetLocation ($3));
2031 current_local_parameters = current_property.Set.ParameterInfo;
2032 lbag.AddMember (current_property.Set, mod_locations);
2033 lexer.PropertyParsing = false;
2038 current_property.Set.Block = (ToplevelBlock) $5;
2040 if (current_container.Kind == MemberKind.Interface) {
2041 report.Error (531, current_property.Set.Block.StartLocation,
2042 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2046 current_local_parameters = null;
2047 lexer.PropertyParsing = true;
2050 && Lexer.doc_state == XmlCommentState.Error)
2051 Lexer.doc_state = XmlCommentState.NotAllowed;
2064 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2069 interface_declaration
2076 type_declaration_name
2078 lexer.ConstraintsParsing = true;
2079 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2080 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2083 opt_type_parameter_constraints_clauses
2085 lexer.ConstraintsParsing = false;
2088 current_container.SetConstraints ((List<Constraints>) $9);
2091 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2092 Lexer.doc_state = XmlCommentState.Allowed;
2095 lexer.parsing_modifiers = true;
2097 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2099 --lexer.parsing_declaration;
2101 Lexer.doc_state = XmlCommentState.Allowed;
2106 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2108 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2110 $$ = pop_current_class ();
2112 | opt_attributes opt_modifiers opt_partial INTERFACE error
2114 Error_SyntaxError (yyToken);
2118 opt_interface_member_declarations
2120 | interface_member_declarations
2123 interface_member_declarations
2124 : interface_member_declaration
2126 lexer.parsing_modifiers = true;
2127 lexer.parsing_block = 0;
2129 | interface_member_declarations interface_member_declaration
2131 lexer.parsing_modifiers = true;
2132 lexer.parsing_block = 0;
2136 interface_member_declaration
2137 : constant_declaration
2139 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2143 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2145 | method_declaration
2146 | property_declaration
2148 | indexer_declaration
2149 | operator_declaration
2151 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2153 | constructor_declaration
2155 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2159 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2163 operator_declaration
2164 : opt_attributes opt_modifiers operator_declarator
2167 method_body_expression_block
2169 OperatorDeclaration decl = (OperatorDeclaration) $3;
2171 Operator op = new Operator (
2172 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2173 current_local_parameters,
2174 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2176 if (op.Block == null)
2177 op.ParameterInfo.CheckParameters (op);
2180 op.DocComment = tmpComment;
2181 Lexer.doc_state = XmlCommentState.Allowed;
2184 // Note again, checking is done in semantic analysis
2185 current_type.AddOperator (op);
2187 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2190 current_local_parameters = null;
2195 : type_expression_or_array
2198 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2199 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2204 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2206 valid_param_mod = ParameterModifierType.DefaultValue;
2207 if ((Operator.OpType) $3 == Operator.OpType.Is)
2208 valid_param_mod |= ParameterModifierType.Out;
2210 opt_formal_parameter_list CLOSE_PARENS
2212 valid_param_mod = 0;
2214 Location loc = GetLocation ($2);
2215 Operator.OpType op = (Operator.OpType) $3;
2216 current_local_parameters = (ParametersCompiled)$6;
2218 int p_count = current_local_parameters.Count;
2220 if (op == Operator.OpType.Addition)
2221 op = Operator.OpType.UnaryPlus;
2222 else if (op == Operator.OpType.Subtraction)
2223 op = Operator.OpType.UnaryNegation;
2226 if (IsUnaryOperator (op)) {
2228 report.Error (1020, loc, "Overloadable binary operator expected");
2229 } else if (p_count != 1) {
2230 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2231 Operator.GetName (op));
2233 } else if (op == Operator.OpType.Is) {
2234 // TODO: Special checks for is operator
2237 report.Error (1019, loc, "Overloadable unary operator expected");
2238 } else if (p_count != 2) {
2239 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2240 Operator.GetName (op));
2245 tmpComment = Lexer.consume_doc_comment ();
2246 Lexer.doc_state = XmlCommentState.NotAllowed;
2249 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2250 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2252 | conversion_operator_declarator
2255 overloadable_operator
2257 : BANG { $$ = Operator.OpType.LogicalNot; }
2258 | TILDE { $$ = Operator.OpType.OnesComplement; }
2259 | OP_INC { $$ = Operator.OpType.Increment; }
2260 | OP_DEC { $$ = Operator.OpType.Decrement; }
2261 | TRUE { $$ = Operator.OpType.True; }
2262 | FALSE { $$ = Operator.OpType.False; }
2263 // Unary and binary:
2264 | PLUS { $$ = Operator.OpType.Addition; }
2265 | MINUS { $$ = Operator.OpType.Subtraction; }
2267 | STAR { $$ = Operator.OpType.Multiply; }
2268 | DIV { $$ = Operator.OpType.Division; }
2269 | PERCENT { $$ = Operator.OpType.Modulus; }
2270 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2271 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2272 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2273 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2274 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2275 | OP_EQ { $$ = Operator.OpType.Equality; }
2276 | OP_NE { $$ = Operator.OpType.Inequality; }
2277 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2278 | OP_LT { $$ = Operator.OpType.LessThan; }
2279 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2280 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2283 if (lang_version != LanguageVersion.Experimental)
2284 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2286 $$ = Operator.OpType.Is;
2290 conversion_operator_declarator
2291 : IMPLICIT OPERATOR type OPEN_PARENS
2293 valid_param_mod = ParameterModifierType.DefaultValue;
2295 opt_formal_parameter_list CLOSE_PARENS
2297 valid_param_mod = 0;
2299 Location loc = GetLocation ($2);
2300 current_local_parameters = (ParametersCompiled)$6;
2302 if (current_local_parameters.Count != 1) {
2303 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2307 tmpComment = Lexer.consume_doc_comment ();
2308 Lexer.doc_state = XmlCommentState.NotAllowed;
2311 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2312 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2314 | EXPLICIT OPERATOR type OPEN_PARENS
2316 valid_param_mod = ParameterModifierType.DefaultValue;
2318 opt_formal_parameter_list CLOSE_PARENS
2320 valid_param_mod = 0;
2322 Location loc = GetLocation ($2);
2323 current_local_parameters = (ParametersCompiled)$6;
2325 if (current_local_parameters.Count != 1) {
2326 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2330 tmpComment = Lexer.consume_doc_comment ();
2331 Lexer.doc_state = XmlCommentState.NotAllowed;
2334 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2335 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2339 Error_SyntaxError (yyToken);
2340 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2341 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2345 Error_SyntaxError (yyToken);
2346 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2347 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2351 constructor_declaration
2352 : constructor_declarator
2355 Constructor c = (Constructor) $1;
2356 c.Block = (ToplevelBlock) $2;
2359 c.DocComment = ConsumeStoredComment ();
2361 current_local_parameters = null;
2363 Lexer.doc_state = XmlCommentState.Allowed;
2367 constructor_declarator
2373 tmpComment = Lexer.consume_doc_comment ();
2374 Lexer.doc_state = XmlCommentState.Allowed;
2377 valid_param_mod = ParameterModifierType.All;
2379 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2381 valid_param_mod = 0;
2382 current_local_parameters = (ParametersCompiled) $6;
2384 var lt = (LocatedToken) $3;
2385 var mods = (Modifiers) $2;
2386 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2388 if (lt.Value != current_container.MemberName.Name) {
2389 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2390 } else if ((mods & Modifiers.STATIC) != 0) {
2391 if (!current_local_parameters.IsEmpty) {
2392 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2393 c.GetSignatureForError ());
2396 if ((mods & Modifiers.AccessibilityMask) != 0){
2397 report.Error (515, c.Location,
2398 "`{0}': static constructor cannot have an access modifier",
2399 c.GetSignatureForError ());
2402 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2403 if (lang_version < LanguageVersion.V_6)
2404 FeatureIsNotAvailable (GetLocation ($3), "struct parameterless instance constructor");
2406 if ((mods & Modifiers.PUBLIC) == 0) {
2407 report.Error (8075, c.Location, "`{0}': Structs parameterless instance constructor must be public", c.GetSignatureForError ());
2412 current_type.AddConstructor (c);
2413 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2417 // start block here, so possible anonymous methods inside
2418 // constructor initializer can get correct parent block
2420 start_block (lexer.Location);
2422 opt_constructor_initializer
2425 var c = (Constructor) $8;
2426 c.Initializer = (ConstructorInitializer) $9;
2429 report.Error (514, c.Location,
2430 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2431 c.GetSignatureForError ());
2441 | SEMICOLON { current_block = null; $$ = null; }
2444 opt_constructor_initializer
2446 | constructor_initializer
2449 constructor_initializer
2450 : COLON BASE OPEN_PARENS
2452 ++lexer.parsing_block;
2454 opt_argument_list CLOSE_PARENS
2456 --lexer.parsing_block;
2457 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2458 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2460 | COLON THIS OPEN_PARENS
2462 ++lexer.parsing_block;
2464 opt_argument_list CLOSE_PARENS
2466 --lexer.parsing_block;
2467 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2468 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2472 Error_SyntaxError (yyToken);
2473 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2474 lbag.AddLocation ($$, GetLocation ($1));
2478 Error_SyntaxError (yyToken);
2483 destructor_declaration
2484 : opt_attributes opt_modifiers TILDE
2487 tmpComment = Lexer.consume_doc_comment ();
2488 Lexer.doc_state = XmlCommentState.NotAllowed;
2491 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2493 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2495 var lt = (LocatedToken) $5;
2496 if (lt.Value != current_container.MemberName.Name){
2497 report.Error (574, lt.Location, "Name of destructor must match name of class");
2498 } else if (current_container.Kind != MemberKind.Class){
2499 report.Error (575, lt.Location, "Only class types can contain destructor");
2502 Destructor d = new Destructor (current_type, (Modifiers) $2,
2503 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2505 d.DocComment = ConsumeStoredComment ();
2507 d.Block = (ToplevelBlock) $8;
2508 current_type.AddMember (d);
2509 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2511 current_local_parameters = null;
2518 EVENT type member_declaration_name
2520 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2521 current_type.AddMember (current_event_field);
2523 if (current_event_field.MemberName.ExplicitInterface != null) {
2524 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2525 current_event_field.GetSignatureForError ());
2528 $$ = current_event_field;
2530 opt_event_initializer
2531 opt_event_declarators
2535 current_event_field.DocComment = Lexer.consume_doc_comment ();
2536 Lexer.doc_state = XmlCommentState.Allowed;
2539 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2540 current_event_field = null;
2544 EVENT type member_declaration_name
2547 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2548 current_type.AddMember (current_event);
2549 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2551 lexer.EventParsing = true;
2553 event_accessor_declarations
2555 if (current_container.Kind == MemberKind.Interface)
2556 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2558 lexer.EventParsing = false;
2563 current_event.DocComment = Lexer.consume_doc_comment ();
2564 Lexer.doc_state = XmlCommentState.Allowed;
2567 lbag.AppendToMember (current_event, GetLocation ($9));
2568 current_event = null;
2569 current_local_parameters = null;
2575 Error_SyntaxError (yyToken);
2577 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2581 opt_event_initializer
2585 ++lexer.parsing_block;
2587 event_variable_initializer
2589 --lexer.parsing_block;
2590 current_event_field.Initializer = (Expression) $3;
2594 opt_event_declarators
2602 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2604 | event_declarators event_declarator
2606 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2613 var lt = (LocatedToken) $2;
2614 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2615 lbag.AddLocation ($$, GetLocation ($1));
2617 | COMMA IDENTIFIER ASSIGN
2619 ++lexer.parsing_block;
2621 event_variable_initializer
2623 --lexer.parsing_block;
2624 var lt = (LocatedToken) $2;
2625 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2626 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2630 event_variable_initializer
2632 if (current_container.Kind == MemberKind.Interface) {
2633 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2634 current_event_field.GetSignatureForError ());
2637 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2638 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2639 current_event_field.GetSignatureForError ());
2642 variable_initializer
2648 event_accessor_declarations
2649 : add_accessor_declaration remove_accessor_declaration
2650 | remove_accessor_declaration add_accessor_declaration
2651 | add_accessor_declaration
2653 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2654 current_event.GetSignatureForError ());
2656 | remove_accessor_declaration
2658 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2659 current_event.GetSignatureForError ());
2663 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2668 add_accessor_declaration
2669 : opt_attributes opt_modifiers ADD
2671 if ($2 != ModifierNone) {
2672 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2675 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2676 current_local_parameters = current_event.Add.ParameterInfo;
2678 lbag.AddMember (current_event.Add, mod_locations);
2679 lexer.EventParsing = false;
2681 event_accessor_block
2683 lexer.EventParsing = true;
2685 current_event.Add.Block = (ToplevelBlock) $5;
2687 if (current_container.Kind == MemberKind.Interface) {
2688 report.Error (531, current_event.Add.Block.StartLocation,
2689 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2692 current_local_parameters = null;
2696 remove_accessor_declaration
2697 : opt_attributes opt_modifiers REMOVE
2699 if ($2 != ModifierNone) {
2700 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2703 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2704 current_local_parameters = current_event.Remove.ParameterInfo;
2706 lbag.AddMember (current_event.Remove, mod_locations);
2707 lexer.EventParsing = false;
2709 event_accessor_block
2711 lexer.EventParsing = true;
2713 current_event.Remove.Block = (ToplevelBlock) $5;
2715 if (current_container.Kind == MemberKind.Interface) {
2716 report.Error (531, current_event.Remove.Block.StartLocation,
2717 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2720 current_local_parameters = null;
2724 event_accessor_block
2727 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2733 attributes_without_members
2734 : attribute_sections CLOSE_BRACE
2736 current_type.UnattachedAttributes = (Attributes) $1;
2737 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2738 lexer.putback ('}');
2742 // For full ast try to recover incomplete ambiguous member
2743 // declaration in form on class X { public int }
2745 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2747 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2749 lexer.putback ('}');
2751 lexer.parsing_generic_declaration = false;
2752 FullNamedExpression type = (FullNamedExpression) $3;
2753 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2754 current_type.AddField (current_field);
2762 ENUM type_declaration_name
2766 enumTypeComment = Lexer.consume_doc_comment ();
2771 Lexer.doc_state = XmlCommentState.Allowed;
2773 MemberName name = (MemberName) $4;
2774 if (name.IsGeneric) {
2775 report.Error (1675, name.Location, "Enums cannot have type parameters");
2778 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2780 opt_enum_member_declarations
2782 lexer.parsing_modifiers = true;
2784 // here will be evaluated after CLOSE_BLACE is consumed.
2786 Lexer.doc_state = XmlCommentState.Allowed;
2788 CLOSE_BRACE opt_semicolon
2791 current_container.DocComment = enumTypeComment;
2793 --lexer.parsing_declaration;
2796 // em.DocComment = ev.DocComment;
2798 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2799 $$ = pop_current_class ();
2811 Error_TypeExpected (GetLocation ($1));
2816 opt_enum_member_declarations
2818 | enum_member_declarations
2819 | enum_member_declarations COMMA
2821 lbag.AddLocation ($1, GetLocation ($2));
2825 enum_member_declarations
2826 : enum_member_declaration
2827 | enum_member_declarations COMMA enum_member_declaration
2829 lbag.AddLocation ($1, GetLocation ($2));
2834 enum_member_declaration
2835 : opt_attributes IDENTIFIER
2837 var lt = (LocatedToken) $2;
2838 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2839 ((Enum) current_type).AddEnumMember (em);
2842 em.DocComment = Lexer.consume_doc_comment ();
2843 Lexer.doc_state = XmlCommentState.Allowed;
2848 | opt_attributes IDENTIFIER
2850 ++lexer.parsing_block;
2852 tmpComment = Lexer.consume_doc_comment ();
2853 Lexer.doc_state = XmlCommentState.NotAllowed;
2856 ASSIGN constant_expression
2858 --lexer.parsing_block;
2860 var lt = (LocatedToken) $2;
2861 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2862 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2863 ((Enum) current_type).AddEnumMember (em);
2866 em.DocComment = ConsumeStoredComment ();
2870 | opt_attributes IDENTIFIER error
2872 Error_SyntaxError (yyToken);
2874 var lt = (LocatedToken) $2;
2875 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2876 ((Enum) current_type).AddEnumMember (em);
2879 em.DocComment = Lexer.consume_doc_comment ();
2880 Lexer.doc_state = XmlCommentState.Allowed;
2885 | attributes_without_members
2888 delegate_declaration
2892 member_type type_declaration_name
2895 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2897 opt_formal_parameter_list CLOSE_PARENS
2899 valid_param_mod = 0;
2901 ParametersCompiled p = (ParametersCompiled) $8;
2903 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2905 p.CheckParameters (del);
2907 current_container.AddTypeContainer (del);
2909 current_delegate = del;
2910 lexer.ConstraintsParsing = true;
2912 opt_type_parameter_constraints_clauses
2914 lexer.ConstraintsParsing = false;
2919 current_delegate.DocComment = Lexer.consume_doc_comment ();
2920 Lexer.doc_state = XmlCommentState.Allowed;
2924 current_delegate.SetConstraints ((List<Constraints>) $11);
2925 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2927 $$ = current_delegate;
2929 current_delegate = null;
2937 if (lang_version < LanguageVersion.ISO_2)
2938 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2940 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2944 namespace_or_type_expr
2946 | qualified_alias_member IDENTIFIER opt_type_argument_list
2948 var lt1 = (LocatedToken) $1;
2949 var lt2 = (LocatedToken) $2;
2951 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2952 lbag.AddLocation ($$, GetLocation ($2));
2954 | qualified_alias_member IDENTIFIER generic_dimension
2956 var lt1 = (LocatedToken) $1;
2957 var lt2 = (LocatedToken) $2;
2959 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2960 lbag.AddLocation ($$, GetLocation ($2));
2966 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2968 var lt = (LocatedToken) $3;
2969 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2970 lbag.AddLocation ($$, GetLocation ($2));
2972 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2974 var lt = (LocatedToken) $3;
2975 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2976 lbag.AddLocation ($$, GetLocation ($2));
2981 : IDENTIFIER opt_type_argument_list
2983 var lt = (LocatedToken) $1;
2984 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2986 | IDENTIFIER generic_dimension
2988 var lt = (LocatedToken) $1;
2989 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2994 // Generics arguments (any type, without attributes)
2996 opt_type_argument_list
2998 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3000 if (lang_version < LanguageVersion.ISO_2)
3001 FeatureIsNotAvailable (GetLocation ($1), "generics");
3005 | OP_GENERICS_LT error
3007 Error_TypeExpected (lexer.Location);
3008 $$ = new TypeArguments ();
3015 TypeArguments type_args = new TypeArguments ();
3016 type_args.Add ((FullNamedExpression) $1);
3019 | type_arguments COMMA type
3021 TypeArguments type_args = (TypeArguments) $1;
3022 type_args.Add ((FullNamedExpression) $3);
3028 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3030 type_declaration_name
3033 lexer.parsing_generic_declaration = true;
3035 opt_type_parameter_list
3037 lexer.parsing_generic_declaration = false;
3038 var lt = (LocatedToken) $1;
3039 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3043 member_declaration_name
3044 : method_declaration_name
3046 MemberName mn = (MemberName)$1;
3047 if (mn.TypeParameters != null)
3048 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3049 mn.GetSignatureForError ()));
3053 method_declaration_name
3054 : type_declaration_name
3055 | explicit_interface IDENTIFIER opt_type_parameter_list
3057 lexer.parsing_generic_declaration = false;
3058 var lt = (LocatedToken) $2;
3059 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3063 indexer_declaration_name
3066 lexer.parsing_generic_declaration = false;
3067 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3069 | explicit_interface THIS
3071 lexer.parsing_generic_declaration = false;
3072 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3077 : IDENTIFIER opt_type_argument_list DOT
3079 var lt = (LocatedToken) $1;
3080 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3081 lbag.AddLocation ($$, GetLocation ($3));
3083 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3085 var lt1 = (LocatedToken) $1;
3086 var lt2 = (LocatedToken) $2;
3088 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3089 lbag.AddLocation ($$, GetLocation ($4));
3091 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3093 var lt = (LocatedToken) $2;
3094 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3095 lbag.AddLocation ($$, GetLocation ($4));
3099 opt_type_parameter_list
3101 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3103 if (lang_version < LanguageVersion.ISO_2)
3104 FeatureIsNotAvailable (GetLocation ($1), "generics");
3107 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3114 var tparams = new TypeParameters ();
3115 tparams.Add ((TypeParameter)$1);
3118 | type_parameters COMMA type_parameter
3120 var tparams = (TypeParameters) $1;
3121 tparams.Add ((TypeParameter)$3);
3123 lbag.AddLocation ($3, GetLocation ($3));
3128 : opt_attributes opt_type_parameter_variance IDENTIFIER
3130 var lt = (LocatedToken)$3;
3131 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3135 if (GetTokenName (yyToken) == "type")
3136 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3138 Error_SyntaxError (yyToken);
3140 $$ = new TypeParameter (MemberName.Null, null, null);
3145 // All types where void is allowed
3148 : type_expression_or_array
3151 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3158 lexer.parsing_generic_declaration = true;
3163 // A type which does not allow `void' to be used
3166 : type_expression_or_array
3176 : type_expression_or_array
3179 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3180 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3184 type_expression_or_array
3186 | type_expression rank_specifiers
3188 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3193 : namespace_or_type_expr opt_nullable
3196 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3198 var sn = $1 as SimpleName;
3199 if (sn != null && sn.Name == "var")
3200 $$ = new VarExpr (sn.Location);
3205 | namespace_or_type_expr pointer_stars
3207 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3209 | builtin_type_expression
3215 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3216 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3220 builtin_type_expression
3221 : builtin_types opt_nullable
3224 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3226 | builtin_types pointer_stars
3228 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3230 | VOID pointer_stars
3232 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3239 var types = new List<FullNamedExpression> (2);
3240 types.Add ((FullNamedExpression) $1);
3243 | type_list COMMA base_type_name
3245 var types = (List<FullNamedExpression>) $1;
3246 types.Add ((FullNamedExpression) $3);
3254 if ($1 is ComposedCast) {
3255 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3262 * replaces all the productions for isolating the various
3263 * simple types, but we need this to reuse it easily in variable_type
3266 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3267 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3268 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3269 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3270 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3271 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3276 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3277 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3278 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3279 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3280 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3281 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3282 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3283 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3284 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3288 // Expressions, section 7.5
3293 : type_name_expression
3295 | array_creation_expression
3296 | parenthesized_expression
3297 | default_value_expression
3298 | invocation_expression
3302 | post_increment_expression
3303 | post_decrement_expression
3304 | object_or_delegate_creation_expression
3305 | anonymous_type_expression
3308 | checked_expression
3309 | unchecked_expression
3310 | pointer_member_access
3311 | anonymous_method_expression
3312 | undocumented_expressions
3315 type_name_expression
3317 | IDENTIFIER GENERATE_COMPLETION {
3318 var lt = (LocatedToken) $1;
3319 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3327 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3331 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3332 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3337 // Here is the trick, tokenizer may think that parens is a special but
3338 // parser is interested in open parens only, so we merge them.
3339 // Consider: if (a)foo ();
3347 // Use this production to accept closing parenthesis or
3348 // performing completion
3352 | COMPLETE_COMPLETION
3356 parenthesized_expression
3357 : OPEN_PARENS expression CLOSE_PARENS
3359 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3360 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3362 | OPEN_PARENS expression COMPLETE_COMPLETION
3364 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3369 : primary_expression DOT identifier_inside_body opt_type_argument_list
3371 var lt = (LocatedToken) $3;
3372 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3373 lbag.AddLocation ($$, GetLocation ($2));
3375 | primary_expression DOT identifier_inside_body generic_dimension
3377 var lt = (LocatedToken) $3;
3378 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3379 lbag.AddLocation ($$, GetLocation ($2));
3381 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3383 if (lang_version < LanguageVersion.V_6)
3384 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3386 var lt = (LocatedToken) $4;
3387 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3388 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3390 | builtin_types DOT identifier_inside_body opt_type_argument_list
3392 var lt = (LocatedToken) $3;
3393 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3394 lbag.AddLocation ($$, GetLocation ($2));
3396 | BASE DOT identifier_inside_body opt_type_argument_list
3398 var lt = (LocatedToken) $3;
3399 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3400 lbag.AddLocation ($$, GetLocation ($2));
3402 | AWAIT DOT identifier_inside_body opt_type_argument_list
3404 var lt = (LocatedToken) $3;
3405 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3406 lbag.AddLocation ($$, GetLocation ($2));
3408 | qualified_alias_member identifier_inside_body opt_type_argument_list
3410 var lt1 = (LocatedToken) $1;
3411 var lt2 = (LocatedToken) $2;
3413 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3414 lbag.AddLocation ($$, GetLocation ($2));
3416 | qualified_alias_member identifier_inside_body generic_dimension
3418 var lt1 = (LocatedToken) $1;
3419 var lt2 = (LocatedToken) $2;
3421 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3422 lbag.AddLocation ($$, GetLocation ($2));
3424 | primary_expression DOT GENERATE_COMPLETION {
3425 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3427 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3428 var lt = (LocatedToken) $3;
3429 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3431 | builtin_types DOT GENERATE_COMPLETION
3433 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3435 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3436 var lt = (LocatedToken) $3;
3437 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3441 invocation_expression
3442 : primary_expression open_parens_any opt_argument_list close_parens
3444 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3445 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3447 | primary_expression open_parens_any argument_list error
3449 Error_SyntaxError (yyToken);
3451 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3452 lbag.AddLocation ($$, GetLocation ($2));
3454 | primary_expression open_parens_any error
3456 Error_SyntaxError (yyToken);
3458 $$ = new Invocation ((Expression) $1, null);
3459 lbag.AddLocation ($$, GetLocation ($2));
3463 opt_object_or_collection_initializer
3464 : /* empty */ { $$ = null; }
3465 | object_or_collection_initializer
3468 object_or_collection_initializer
3469 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3472 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3474 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3476 lbag.AddLocation ($$, GetLocation ($3));
3478 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3480 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3481 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3485 opt_member_initializer_list
3486 : /* empty */ { $$ = null; }
3487 | member_initializer_list
3493 member_initializer_list
3494 : member_initializer
3496 var a = new List<Expression> ();
3497 a.Add ((Expression) $1);
3500 | member_initializer_list COMMA member_initializer
3502 var a = (List<Expression>)$1;
3503 a.Add ((Expression) $3);
3506 | member_initializer_list error {
3507 Error_SyntaxError (yyToken);
3513 : IDENTIFIER ASSIGN initializer_value
3515 var lt = (LocatedToken) $1;
3516 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3517 lbag.AddLocation ($$, GetLocation ($2));
3519 | AWAIT ASSIGN initializer_value
3521 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3522 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3523 lbag.AddLocation ($$, GetLocation ($2));
3525 | GENERATE_COMPLETION
3527 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3529 | non_assignment_expression opt_COMPLETE_COMPLETION {
3530 CompletionSimpleName csn = $1 as CompletionSimpleName;
3532 $$ = new CollectionElementInitializer ((Expression)$1);
3534 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3536 | OPEN_BRACE expression_list CLOSE_BRACE
3539 $$ = new CollectionElementInitializer (GetLocation ($1));
3541 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3543 lbag.AddLocation ($$, GetLocation ($3));
3545 | OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET ASSIGN initializer_value
3547 if (lang_version < LanguageVersion.V_6)
3548 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3550 $$ = new DictionaryElementInitializer ((List<Expression>)$2, (Expression) $5, GetLocation ($1));
3551 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3553 | OPEN_BRACE CLOSE_BRACE
3555 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3556 $$ = new CollectionElementInitializer (GetLocation ($1));
3557 lbag.AddLocation ($$, GetLocation ($2));
3563 | object_or_collection_initializer
3567 : /* empty */ { $$ = null; }
3572 : argument_or_named_argument
3574 Arguments list = new Arguments (4);
3575 list.Add ((Argument) $1);
3578 | argument_list COMMA argument
3580 Arguments list = (Arguments) $1;
3581 if (list [list.Count - 1] is NamedArgument)
3582 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3584 list.Add ((Argument) $3);
3587 | argument_list COMMA named_argument
3589 Arguments list = (Arguments) $1;
3590 NamedArgument a = (NamedArgument) $3;
3591 for (int i = 0; i < list.Count; ++i) {
3592 NamedArgument na = list [i] as NamedArgument;
3593 if (na != null && na.Name == a.Name)
3594 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3601 | argument_list COMMA error
3603 if (lexer.putback_char == -1)
3604 lexer.putback (')'); // TODO: Wrong but what can I do
3605 Error_SyntaxError (yyToken);
3610 report.Error (839, GetLocation ($1), "An argument is missing");
3618 $$ = new Argument ((Expression) $1);
3620 | non_simple_argument
3623 argument_or_named_argument
3629 : REF variable_reference
3631 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3632 lbag.AddLocation ($$, GetLocation ($1));
3634 | REF declaration_expression
3636 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3638 | OUT variable_reference
3640 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3641 lbag.AddLocation ($$, GetLocation ($1));
3643 | OUT declaration_expression
3645 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3647 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3649 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3650 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3652 | ARGLIST OPEN_PARENS CLOSE_PARENS
3654 $$ = new Argument (new Arglist (GetLocation ($1)));
3655 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3659 declaration_expression
3660 : OPEN_PARENS declaration_expression CLOSE_PARENS
3662 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3663 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3666 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3668 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3669 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3671 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3673 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3674 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3677 | variable_type identifier_inside_body
3679 if (lang_version != LanguageVersion.Experimental)
3680 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3682 var lt = (LocatedToken) $2;
3683 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3684 current_block.AddLocalName (lv);
3685 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3687 | variable_type identifier_inside_body ASSIGN expression
3689 if (lang_version != LanguageVersion.Experimental)
3690 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3692 var lt = (LocatedToken) $2;
3693 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3694 current_block.AddLocalName (lv);
3695 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3696 Initializer = (Expression) $4
3706 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3708 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3709 lbag.AddLocation ($$, GetLocation ($4));
3711 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3713 if (lang_version < LanguageVersion.V_6)
3714 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3716 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3717 ConditionalAccess = true
3720 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3722 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3724 Error_SyntaxError (yyToken);
3725 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3727 | primary_expression OPEN_BRACKET_EXPR error
3729 Error_SyntaxError (yyToken);
3730 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3735 : expression_or_error
3737 var list = new List<Expression> (4);
3738 list.Add ((Expression) $1);
3741 | expression_list COMMA expression_or_error
3743 var list = (List<Expression>) $1;
3744 list.Add ((Expression) $3);
3749 expression_list_arguments
3750 : expression_list_argument
3752 Arguments args = new Arguments (4);
3753 args.Add ((Argument) $1);
3756 | expression_list_arguments COMMA expression_list_argument
3758 Arguments args = (Arguments) $1;
3759 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3760 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3762 args.Add ((Argument) $3);
3767 expression_list_argument
3770 $$ = new Argument ((Expression) $1);
3778 $$ = new This (GetLocation ($1));
3783 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3785 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3786 lbag.AddLocation ($$, GetLocation ($4));
3788 | BASE OPEN_BRACKET error
3790 Error_SyntaxError (yyToken);
3791 $$ = new ElementAccess (null, null, GetLocation ($2));
3795 post_increment_expression
3796 : primary_expression OP_INC
3798 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3802 post_decrement_expression
3803 : primary_expression OP_DEC
3805 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3809 object_or_delegate_creation_expression
3810 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3813 if (lang_version <= LanguageVersion.ISO_2)
3814 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3816 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3818 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3821 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3823 | NEW new_expr_type object_or_collection_initializer
3825 if (lang_version <= LanguageVersion.ISO_2)
3826 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3828 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3832 array_creation_expression
3833 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3835 opt_array_initializer
3837 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3838 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3839 Next = (ComposedTypeSpecifier) $6
3840 }, (ArrayInitializer) $7, GetLocation ($1));
3841 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3843 | NEW new_expr_type rank_specifiers opt_array_initializer
3846 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3848 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3850 | NEW rank_specifier array_initializer
3852 if (lang_version <= LanguageVersion.ISO_2)
3853 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3855 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3857 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3859 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3860 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3862 | NEW new_expr_type error
3864 Error_SyntaxError (yyToken);
3865 // It can be any of new expression, create the most common one
3866 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3872 ++lexer.parsing_type;
3876 --lexer.parsing_type;
3881 anonymous_type_expression
3882 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3884 if (lang_version <= LanguageVersion.ISO_2)
3885 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3887 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3889 // TODO: lbag comma location
3890 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3892 | NEW OPEN_BRACE GENERATE_COMPLETION
3894 $$ = new EmptyCompletion ();
3898 anonymous_type_parameters_opt_comma
3899 : anonymous_type_parameters_opt
3900 | anonymous_type_parameters COMMA
3903 anonymous_type_parameters_opt
3905 | anonymous_type_parameters
3908 anonymous_type_parameters
3909 : anonymous_type_parameter
3911 var a = new List<AnonymousTypeParameter> (4);
3912 a.Add ((AnonymousTypeParameter) $1);
3915 | anonymous_type_parameters COMMA anonymous_type_parameter
3917 var a = (List<AnonymousTypeParameter>) $1;
3918 a.Add ((AnonymousTypeParameter) $3);
3921 | COMPLETE_COMPLETION
3923 $$ = new EmptyCompletion ();
3925 | anonymous_type_parameter COMPLETE_COMPLETION
3931 anonymous_type_parameter
3932 : identifier_inside_body ASSIGN variable_initializer
3934 var lt = (LocatedToken)$1;
3935 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3936 lbag.AddLocation ($$, GetLocation ($2));
3938 | identifier_inside_body
3940 var lt = (LocatedToken)$1;
3941 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3942 lt.Value, lt.Location);
3946 MemberAccess ma = (MemberAccess) $1;
3947 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3951 report.Error (746, lexer.Location,
3952 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3964 | rank_specifier rank_specifiers
3966 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3972 : OPEN_BRACKET CLOSE_BRACKET
3974 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3975 lbag.AddLocation ($$, GetLocation ($2));
3977 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3979 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3980 lbag.AddLocation ($$, GetLocation ($3));
3989 | dim_separators COMMA
3991 $$ = ((int) $1) + 1;
3995 opt_array_initializer
4007 : OPEN_BRACE CLOSE_BRACE
4009 var ai = new ArrayInitializer (0, GetLocation ($1));
4010 ai.VariableDeclaration = current_variable;
4011 lbag.AddLocation (ai, GetLocation ($2));
4014 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4016 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4017 ai.VariableDeclaration = current_variable;
4019 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4021 lbag.AddLocation (ai, GetLocation ($4));
4027 variable_initializer_list
4028 : variable_initializer
4030 var list = new List<Expression> (4);
4031 list.Add ((Expression) $1);
4034 | variable_initializer_list COMMA variable_initializer
4036 var list = (List<Expression>) $1;
4037 list.Add ((Expression) $3);
4043 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4045 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4046 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4050 typeof_type_expression
4054 Error_TypeExpected (lexer.Location);
4062 if (lang_version < LanguageVersion.ISO_2)
4063 FeatureIsNotAvailable (GetLocation ($1), "generics");
4069 qualified_alias_member
4070 : IDENTIFIER DOUBLE_COLON
4072 var lt = (LocatedToken) $1;
4073 if (lang_version == LanguageVersion.ISO_1)
4074 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4081 : SIZEOF open_parens_any type CLOSE_PARENS
4083 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4084 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4086 | SIZEOF open_parens_any type error
4088 Error_SyntaxError (yyToken);
4090 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4091 lbag.AddLocation ($$, GetLocation ($2));
4096 : CHECKED open_parens_any expression CLOSE_PARENS
4098 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4099 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4103 Error_SyntaxError (yyToken);
4105 $$ = new CheckedExpr (null, GetLocation ($1));
4109 unchecked_expression
4110 : UNCHECKED open_parens_any expression CLOSE_PARENS
4112 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4113 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4117 Error_SyntaxError (yyToken);
4119 $$ = new UnCheckedExpr (null, GetLocation ($1));
4123 pointer_member_access
4124 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4126 var lt = (LocatedToken) $3;
4127 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4131 anonymous_method_expression
4132 : DELEGATE opt_anonymous_method_signature
4134 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4138 $$ = end_anonymous ((ParametersBlock) $4);
4140 | ASYNC DELEGATE opt_anonymous_method_signature
4142 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4146 $$ = end_anonymous ((ParametersBlock) $5);
4150 opt_anonymous_method_signature
4153 $$ = ParametersCompiled.Undefined;
4155 | anonymous_method_signature
4158 anonymous_method_signature
4161 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4163 opt_formal_parameter_list CLOSE_PARENS
4165 valid_param_mod = 0;
4170 default_value_expression
4171 : DEFAULT open_parens_any type CLOSE_PARENS
4173 if (lang_version < LanguageVersion.ISO_2)
4174 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4176 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4177 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4182 : primary_expression
4183 | BANG prefixed_unary_expression
4185 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4187 | TILDE prefixed_unary_expression
4189 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4191 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4193 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4194 lbag.AddLocation ($$, GetLocation ($3));
4196 | AWAIT prefixed_unary_expression
4199 if (current_anonymous_method is LambdaExpression) {
4200 report.Error (4034, GetLocation ($1),
4201 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4202 } else if (current_anonymous_method != null) {
4203 report.Error (4035, GetLocation ($1),
4204 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4205 } else if (interactive_async != null) {
4206 current_block.Explicit.RegisterAsyncAwait ();
4207 interactive_async = true;
4209 report.Error (4033, GetLocation ($1),
4210 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4213 current_block.Explicit.RegisterAsyncAwait ();
4216 $$ = new Await ((Expression) $2, GetLocation ($1));
4220 Error_SyntaxError (yyToken);
4222 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4226 Error_SyntaxError (yyToken);
4228 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4230 | OPEN_PARENS_CAST type CLOSE_PARENS error
4232 Error_SyntaxError (yyToken);
4234 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4235 lbag.AddLocation ($$, GetLocation ($3));
4239 Error_SyntaxError (yyToken);
4241 $$ = new Await (null, GetLocation ($1));
4246 // The idea to split this out is from Rhys' grammar
4247 // to solve the problem with casts.
4249 prefixed_unary_expression
4251 | PLUS prefixed_unary_expression
4253 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4255 | MINUS prefixed_unary_expression
4257 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4259 | OP_INC prefixed_unary_expression
4261 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4263 | OP_DEC prefixed_unary_expression
4265 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4267 | STAR prefixed_unary_expression
4269 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4271 | BITWISE_AND prefixed_unary_expression
4273 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4277 Error_SyntaxError (yyToken);
4279 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4283 Error_SyntaxError (yyToken);
4285 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4289 Error_SyntaxError (yyToken);
4291 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4295 Error_SyntaxError (yyToken);
4297 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4301 Error_SyntaxError (yyToken);
4303 $$ = new Indirection (null, GetLocation ($1));
4307 Error_SyntaxError (yyToken);
4309 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4313 multiplicative_expression
4314 : prefixed_unary_expression
4315 | multiplicative_expression STAR prefixed_unary_expression
4317 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4318 lbag.AddLocation ($$, GetLocation ($2));
4320 | multiplicative_expression DIV prefixed_unary_expression
4322 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4323 lbag.AddLocation ($$, GetLocation ($2));
4325 | multiplicative_expression PERCENT prefixed_unary_expression
4327 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4328 lbag.AddLocation ($$, GetLocation ($2));
4330 | multiplicative_expression STAR error
4332 Error_SyntaxError (yyToken);
4334 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4335 lbag.AddLocation ($$, GetLocation ($2));
4337 | multiplicative_expression DIV error
4339 Error_SyntaxError (yyToken);
4341 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4342 lbag.AddLocation ($$, GetLocation ($2));
4344 | multiplicative_expression PERCENT error
4346 Error_SyntaxError (yyToken);
4348 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4349 lbag.AddLocation ($$, GetLocation ($2));
4354 : multiplicative_expression
4355 | additive_expression PLUS multiplicative_expression
4357 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4358 lbag.AddLocation ($$, GetLocation ($2));
4360 | additive_expression MINUS multiplicative_expression
4362 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4363 lbag.AddLocation ($$, GetLocation ($2));
4365 | additive_expression PLUS error
4367 Error_SyntaxError (yyToken);
4369 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4370 lbag.AddLocation ($$, GetLocation ($2));
4372 | additive_expression MINUS error
4374 Error_SyntaxError (yyToken);
4376 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4377 lbag.AddLocation ($$, GetLocation ($2));
4379 | additive_expression AS type
4381 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4383 | additive_expression IS pattern_type_expr opt_identifier
4385 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4387 if (lang_version != LanguageVersion.Experimental)
4388 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4390 var lt = (LocatedToken) $4;
4391 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4392 current_block.AddLocalName (is_expr.Variable);
4397 | additive_expression IS pattern_expr
4399 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4400 if (lang_version != LanguageVersion.Experimental)
4401 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4405 | additive_expression AS error
4407 Error_SyntaxError (yyToken);
4409 $$ = new As ((Expression) $1, null, GetLocation ($2));
4411 | additive_expression IS error
4413 Error_SyntaxError (yyToken);
4415 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4419 var lt = (LocatedToken) $1;
4420 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4424 var lt = (LocatedToken) $1;
4425 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4435 | PLUS prefixed_unary_expression
4437 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4439 | MINUS prefixed_unary_expression
4441 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4444 | default_value_expression
4445 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4447 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4448 lbag.AddLocation ($$, GetLocation ($3));
4452 $$ = new WildcardPattern (GetLocation ($1));
4454 | pattern_expr_invocation
4458 pattern_expr_invocation
4459 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4461 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4466 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4468 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4472 pattern_property_list
4473 : pattern_property_entry
4475 var list = new List<PropertyPatternMember> ();
4476 list.Add ((PropertyPatternMember) $1);
4479 | pattern_property_list COMMA pattern_property_entry
4481 var list = (List<PropertyPatternMember>) $1;
4482 list.Add ((PropertyPatternMember) $3);
4487 pattern_property_entry
4488 : identifier_inside_body IS pattern
4490 var lt = (LocatedToken) $1;
4491 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4497 | pattern_type_expr opt_identifier
4500 var lt = (LocatedToken) $2;
4501 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4502 current_block.AddLocalName (variable);
4510 $$ = new Arguments (0);
4518 Arguments args = new Arguments (4);
4519 args.Add ((Argument) $1);
4522 | pattern_list COMMA pattern_argument
4524 Arguments args = (Arguments) $1;
4525 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4526 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4528 args.Add ((Argument) $3);
4536 $$ = new Argument ((Expression) $1);
4538 | IDENTIFIER COLON pattern
4540 var lt = (LocatedToken) $1;
4541 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4546 : additive_expression
4547 | shift_expression OP_SHIFT_LEFT additive_expression
4549 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4550 lbag.AddLocation ($$, GetLocation ($2));
4552 | shift_expression OP_SHIFT_RIGHT additive_expression
4554 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4555 lbag.AddLocation ($$, GetLocation ($2));
4557 | shift_expression OP_SHIFT_LEFT error
4559 Error_SyntaxError (yyToken);
4561 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4562 lbag.AddLocation ($$, GetLocation ($2));
4564 | shift_expression OP_SHIFT_RIGHT error
4566 Error_SyntaxError (yyToken);
4568 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4569 lbag.AddLocation ($$, GetLocation ($2));
4573 relational_expression
4575 | relational_expression OP_LT shift_expression
4577 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4578 lbag.AddLocation ($$, GetLocation ($2));
4580 | relational_expression OP_GT shift_expression
4582 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4583 lbag.AddLocation ($$, GetLocation ($2));
4585 | relational_expression OP_LE shift_expression
4587 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4588 lbag.AddLocation ($$, GetLocation ($2));
4590 | relational_expression OP_GE shift_expression
4592 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4593 lbag.AddLocation ($$, GetLocation ($2));
4595 | relational_expression OP_LT error
4597 Error_SyntaxError (yyToken);
4599 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4600 lbag.AddLocation ($$, GetLocation ($2));
4602 | relational_expression OP_GT error
4604 Error_SyntaxError (yyToken);
4606 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4607 lbag.AddLocation ($$, GetLocation ($2));
4609 | relational_expression OP_LE error
4611 Error_SyntaxError (yyToken);
4613 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4614 lbag.AddLocation ($$, GetLocation ($2));
4616 | relational_expression OP_GE error
4618 Error_SyntaxError (yyToken);
4620 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4621 lbag.AddLocation ($$, GetLocation ($2));
4626 : relational_expression
4627 | equality_expression OP_EQ relational_expression
4629 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4630 lbag.AddLocation ($$, GetLocation ($2));
4632 | equality_expression OP_NE relational_expression
4634 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4635 lbag.AddLocation ($$, GetLocation ($2));
4637 | equality_expression OP_EQ error
4639 Error_SyntaxError (yyToken);
4641 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4642 lbag.AddLocation ($$, GetLocation ($2));
4644 | equality_expression OP_NE error
4646 Error_SyntaxError (yyToken);
4648 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4649 lbag.AddLocation ($$, GetLocation ($2));
4654 : equality_expression
4655 | and_expression BITWISE_AND equality_expression
4657 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4658 lbag.AddLocation ($$, GetLocation ($2));
4660 | and_expression BITWISE_AND error
4662 Error_SyntaxError (yyToken);
4664 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4665 lbag.AddLocation ($$, GetLocation ($2));
4669 exclusive_or_expression
4671 | exclusive_or_expression CARRET and_expression
4673 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4674 lbag.AddLocation ($$, GetLocation ($2));
4676 | exclusive_or_expression CARRET error
4678 Error_SyntaxError (yyToken);
4680 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4681 lbag.AddLocation ($$, GetLocation ($2));
4685 inclusive_or_expression
4686 : exclusive_or_expression
4687 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4689 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4690 lbag.AddLocation ($$, GetLocation ($2));
4692 | inclusive_or_expression BITWISE_OR error
4694 Error_SyntaxError (yyToken);
4696 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4697 lbag.AddLocation ($$, GetLocation ($2));
4701 conditional_and_expression
4702 : inclusive_or_expression
4703 | conditional_and_expression OP_AND inclusive_or_expression
4705 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4706 lbag.AddLocation ($$, GetLocation ($2));
4708 | conditional_and_expression OP_AND error
4710 Error_SyntaxError (yyToken);
4712 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4713 lbag.AddLocation ($$, GetLocation ($2));
4717 conditional_or_expression
4718 : conditional_and_expression
4719 | conditional_or_expression OP_OR conditional_and_expression
4721 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4722 lbag.AddLocation ($$, GetLocation ($2));
4724 | conditional_or_expression OP_OR error
4726 Error_SyntaxError (yyToken);
4728 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4729 lbag.AddLocation ($$, GetLocation ($2));
4733 null_coalescing_expression
4734 : conditional_or_expression
4735 | conditional_or_expression OP_COALESCING null_coalescing_expression
4737 if (lang_version < LanguageVersion.ISO_2)
4738 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4740 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4741 lbag.AddLocation ($$, GetLocation ($2));
4745 conditional_expression
4746 : null_coalescing_expression
4747 | null_coalescing_expression INTERR expression COLON expression
4749 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4750 lbag.AddLocation ($$, GetLocation ($4));
4752 | null_coalescing_expression INTERR expression error
4754 Error_SyntaxError (yyToken);
4756 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4758 | null_coalescing_expression INTERR expression COLON error
4760 Error_SyntaxError (yyToken);
4762 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4763 lbag.AddLocation ($$, GetLocation ($4));
4765 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4767 Error_SyntaxError (Token.CLOSE_BRACE);
4769 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4770 lbag.AddLocation ($$, GetLocation ($4));
4771 lexer.putback ('}');
4775 assignment_expression
4776 : prefixed_unary_expression ASSIGN expression
4778 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4779 lbag.AddLocation ($$, GetLocation ($2));
4781 | prefixed_unary_expression OP_MULT_ASSIGN expression
4783 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4784 lbag.AddLocation ($$, GetLocation ($2));
4786 | prefixed_unary_expression OP_DIV_ASSIGN expression
4788 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4789 lbag.AddLocation ($$, GetLocation ($2));
4791 | prefixed_unary_expression OP_MOD_ASSIGN expression
4793 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4794 lbag.AddLocation ($$, GetLocation ($2));
4796 | prefixed_unary_expression OP_ADD_ASSIGN expression
4798 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4799 lbag.AddLocation ($$, GetLocation ($2));
4801 | prefixed_unary_expression OP_SUB_ASSIGN expression
4803 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4804 lbag.AddLocation ($$, GetLocation ($2));
4806 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4808 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4809 lbag.AddLocation ($$, GetLocation ($2));
4811 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4813 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4814 lbag.AddLocation ($$, GetLocation ($2));
4816 | prefixed_unary_expression OP_AND_ASSIGN expression
4818 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4819 lbag.AddLocation ($$, GetLocation ($2));
4821 | prefixed_unary_expression OP_OR_ASSIGN expression
4823 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4824 lbag.AddLocation ($$, GetLocation ($2));
4826 | prefixed_unary_expression OP_XOR_ASSIGN expression
4828 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4829 lbag.AddLocation ($$, GetLocation ($2));
4833 lambda_parameter_list
4836 var pars = new List<Parameter> (4);
4837 pars.Add ((Parameter) $1);
4841 | lambda_parameter_list COMMA lambda_parameter
4843 var pars = (List<Parameter>) $1;
4844 Parameter p = (Parameter)$3;
4845 if (pars[0].GetType () != p.GetType ()) {
4846 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4855 : parameter_modifier parameter_type identifier_inside_body
4857 var lt = (LocatedToken) $3;
4859 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4861 | parameter_type identifier_inside_body
4863 var lt = (LocatedToken) $2;
4865 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4869 var lt = (LocatedToken) $1;
4870 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4874 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4875 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4879 opt_lambda_parameter_list
4880 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4881 | lambda_parameter_list {
4882 var pars_list = (List<Parameter>) $1;
4883 $$ = new ParametersCompiled (pars_list.ToArray ());
4887 lambda_expression_body
4889 start_block (Location.Null);
4891 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4893 Block b = end_block (Location.Null);
4894 b.IsCompilerGenerated = true;
4895 b.AddStatement (new ContextualReturn ((Expression) $2));
4901 // Handles only cases like foo = x.FirstOrDefault (l => );
4902 // where we must restore current_variable
4903 Block b = end_block (Location.Null);
4904 b.IsCompilerGenerated = true;
4906 Error_SyntaxError (yyToken);
4915 Error_SyntaxError (yyToken);
4923 var lt = (LocatedToken) $1;
4924 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4925 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4927 lambda_expression_body
4929 $$ = end_anonymous ((ParametersBlock) $4);
4930 lbag.AddLocation ($$, GetLocation ($2));
4934 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4935 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4936 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4938 lambda_expression_body
4940 $$ = end_anonymous ((ParametersBlock) $4);
4941 lbag.AddLocation ($$, GetLocation ($2));
4943 | ASYNC identifier_inside_body ARROW
4945 var lt = (LocatedToken) $2;
4946 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4947 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4949 lambda_expression_body
4951 $$ = end_anonymous ((ParametersBlock) $5);
4952 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4954 | OPEN_PARENS_LAMBDA
4956 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4958 opt_lambda_parameter_list CLOSE_PARENS ARROW
4960 valid_param_mod = 0;
4961 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4963 lambda_expression_body
4965 $$ = end_anonymous ((ParametersBlock) $7);
4966 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4968 | ASYNC OPEN_PARENS_LAMBDA
4970 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4972 opt_lambda_parameter_list CLOSE_PARENS ARROW
4974 valid_param_mod = 0;
4975 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4977 lambda_expression_body
4979 $$ = end_anonymous ((ParametersBlock) $8);
4980 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4985 : assignment_expression
4986 | non_assignment_expression
4989 non_assignment_expression
4990 : conditional_expression
4995 $$ = new ArglistAccess (GetLocation ($1));
4999 undocumented_expressions
5000 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5002 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5003 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5005 | REFTYPE open_parens_any expression CLOSE_PARENS
5007 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5008 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5010 | MAKEREF open_parens_any expression CLOSE_PARENS
5012 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5013 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5024 $$ = new BooleanExpression ((Expression) $1);
5028 opt_primary_parameters
5033 | primary_parameters
5037 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5041 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5042 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5044 if (lang_version != LanguageVersion.Experimental)
5045 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5049 opt_primary_parameters_with_class_base
5058 | primary_parameters
5062 | primary_parameters class_base
5066 | primary_parameters class_base OPEN_PARENS
5068 ++lexer.parsing_block;
5069 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5071 opt_argument_list CLOSE_PARENS
5073 lbag.AppendToMember (current_container, GetLocation ($6));
5074 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5075 --lexer.parsing_block;
5091 type_declaration_name
5093 lexer.ConstraintsParsing = true;
5095 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5096 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5097 FeatureIsNotAvailable (c.Location, "static classes");
5100 push_current_container (c, $3);
5101 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5103 opt_primary_parameters_with_class_base
5104 opt_type_parameter_constraints_clauses
5106 valid_param_mod = 0;
5107 lexer.ConstraintsParsing = false;
5110 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5113 current_container.SetConstraints ((List<Constraints>) $9);
5114 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5117 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5118 Lexer.doc_state = XmlCommentState.Allowed;
5121 lexer.parsing_modifiers = true;
5123 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5125 --lexer.parsing_declaration;
5127 Lexer.doc_state = XmlCommentState.Allowed;
5132 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5134 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5136 $$ = pop_current_class ();
5144 { $$ = $1; } // location
5150 mod_locations = null;
5152 lexer.parsing_modifiers = false;
5156 lexer.parsing_modifiers = false;
5162 | modifiers modifier
5164 var m1 = (Modifiers) $1;
5165 var m2 = (Modifiers) $2;
5167 if ((m1 & m2) != 0) {
5168 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5169 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5170 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5171 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5172 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5173 "More than one protection modifier specified");
5184 StoreModifierLocation ($$, GetLocation ($1));
5186 if (current_container.Kind == MemberKind.Namespace)
5187 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5191 $$ = Modifiers.PUBLIC;
5192 StoreModifierLocation ($$, GetLocation ($1));
5196 $$ = Modifiers.PROTECTED;
5197 StoreModifierLocation ($$, GetLocation ($1));
5201 $$ = Modifiers.INTERNAL;
5202 StoreModifierLocation ($$, GetLocation ($1));
5206 $$ = Modifiers.PRIVATE;
5207 StoreModifierLocation ($$, GetLocation ($1));
5211 $$ = Modifiers.ABSTRACT;
5212 StoreModifierLocation ($$, GetLocation ($1));
5216 $$ = Modifiers.SEALED;
5217 StoreModifierLocation ($$, GetLocation ($1));
5221 $$ = Modifiers.STATIC;
5222 StoreModifierLocation ($$, GetLocation ($1));
5226 $$ = Modifiers.READONLY;
5227 StoreModifierLocation ($$, GetLocation ($1));
5231 $$ = Modifiers.VIRTUAL;
5232 StoreModifierLocation ($$, GetLocation ($1));
5236 $$ = Modifiers.OVERRIDE;
5237 StoreModifierLocation ($$, GetLocation ($1));
5241 $$ = Modifiers.EXTERN;
5242 StoreModifierLocation ($$, GetLocation ($1));
5246 $$ = Modifiers.VOLATILE;
5247 StoreModifierLocation ($$, GetLocation ($1));
5251 $$ = Modifiers.UNSAFE;
5252 StoreModifierLocation ($$, GetLocation ($1));
5253 if (!settings.Unsafe)
5254 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5258 $$ = Modifiers.ASYNC;
5259 StoreModifierLocation ($$, GetLocation ($1));
5271 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5273 | COLON type_list error
5275 Error_SyntaxError (yyToken);
5277 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5281 opt_type_parameter_constraints_clauses
5283 | type_parameter_constraints_clauses
5289 type_parameter_constraints_clauses
5290 : type_parameter_constraints_clause
5292 var constraints = new List<Constraints> (1);
5293 constraints.Add ((Constraints) $1);
5296 | type_parameter_constraints_clauses type_parameter_constraints_clause
5298 var constraints = (List<Constraints>) $1;
5299 Constraints new_constraint = (Constraints)$2;
5301 foreach (Constraints c in constraints) {
5302 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5303 report.Error (409, new_constraint.Location,
5304 "A constraint clause has already been specified for type parameter `{0}'",
5305 new_constraint.TypeParameter.Value);
5309 constraints.Add (new_constraint);
5314 type_parameter_constraints_clause
5315 : WHERE IDENTIFIER COLON type_parameter_constraints
5317 var lt = (LocatedToken) $2;
5318 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5319 lbag.AddLocation ($$, GetLocation ($3));
5321 | WHERE IDENTIFIER error
5323 Error_SyntaxError (yyToken);
5325 var lt = (LocatedToken) $2;
5326 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5330 type_parameter_constraints
5331 : type_parameter_constraint
5333 var constraints = new List<FullNamedExpression> (1);
5334 constraints.Add ((FullNamedExpression) $1);
5337 | type_parameter_constraints COMMA type_parameter_constraint
5339 var constraints = (List<FullNamedExpression>) $1;
5340 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5341 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5342 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5345 prev = $3 as SpecialContraintExpr;
5347 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5348 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5350 prev = constraints [0] as SpecialContraintExpr;
5351 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5352 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5357 constraints.Add ((FullNamedExpression) $3);
5362 type_parameter_constraint
5365 if ($1 is ComposedCast)
5366 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5370 | NEW OPEN_PARENS CLOSE_PARENS
5372 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5373 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5377 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5381 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5385 opt_type_parameter_variance
5390 | type_parameter_variance
5392 if (lang_version <= LanguageVersion.V_3)
5393 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5399 type_parameter_variance
5402 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5406 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5415 // A block is "contained" on the following places:
5417 // property_declaration as part of the accessor body (get/set)
5418 // operator_declaration
5419 // constructor_declaration
5420 // destructor_declaration
5421 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5426 ++lexer.parsing_block;
5427 start_block (GetLocation ($1));
5429 opt_statement_list block_end
5438 --lexer.parsing_block;
5439 $$ = end_block (GetLocation ($1));
5441 | COMPLETE_COMPLETION
5443 --lexer.parsing_block;
5444 $$ = end_block (lexer.Location);
5452 ++lexer.parsing_block;
5453 current_block.StartLocation = GetLocation ($1);
5455 opt_statement_list CLOSE_BRACE
5457 --lexer.parsing_block;
5458 $$ = end_block (GetLocation ($4));
5469 | statement_list statement
5473 : block_variable_declaration
5475 current_block.AddStatement ((Statement) $1);
5477 | valid_declaration_statement
5479 current_block.AddStatement ((Statement) $1);
5484 Error_SyntaxError (yyToken);
5490 // The interactive_statement and its derivatives are only
5491 // used to provide a special version of `expression_statement'
5492 // that has a side effect of assigning the expression to
5495 interactive_statement_list
5496 : interactive_statement
5497 | interactive_statement_list interactive_statement
5500 interactive_statement
5501 : block_variable_declaration
5503 current_block.AddStatement ((Statement) $1);
5505 | interactive_valid_declaration_statement
5507 current_block.AddStatement ((Statement) $1);
5512 valid_declaration_statement
5515 | expression_statement
5516 | selection_statement
5517 | iteration_statement
5521 | unchecked_statement
5528 interactive_valid_declaration_statement
5531 | interactive_expression_statement
5532 | selection_statement
5533 | iteration_statement
5537 | unchecked_statement
5545 : valid_declaration_statement
5546 | block_variable_declaration
5548 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5553 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5558 Error_SyntaxError (yyToken);
5559 $$ = new EmptyStatement (GetLocation ($1));
5566 // Uses lexer.Location because semicolon location is not kept in quick mode
5567 $$ = new EmptyStatement (lexer.Location);
5572 : identifier_inside_body COLON
5574 var lt = (LocatedToken) $1;
5575 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5576 lbag.AddLocation (labeled, GetLocation ($2));
5577 current_block.AddLabel (labeled);
5578 current_block.AddStatement (labeled);
5584 : variable_type_simple
5585 | variable_type_simple rank_specifiers
5588 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5590 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5595 * The following is from Rhys' grammar:
5596 * > Types in local variable declarations must be recognized as
5597 * > expressions to prevent reduce/reduce errors in the grammar.
5598 * > The expressions are converted into types during semantic analysis.
5600 variable_type_simple
5601 : type_name_expression opt_nullable
5603 // Ok, the above "primary_expression" is there to get rid of
5604 // both reduce/reduce and shift/reduces in the grammar, it should
5605 // really just be "type_name". If you use type_name, a reduce/reduce
5606 // creeps up. If you use namespace_or_type_name (which is all we need
5607 // really) two shift/reduces appear.
5610 // So the super-trick is that primary_expression
5611 // can only be either a SimpleName or a MemberAccess.
5612 // The MemberAccess case arises when you have a fully qualified type-name like :
5614 // SimpleName is when you have
5617 var expr = (ATypeNameExpression) $1;
5619 if (expr.Name == "var" && expr is SimpleName)
5620 $$ = new VarExpr (expr.Location);
5624 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5627 | type_name_expression pointer_stars
5629 var expr = (ATypeNameExpression) $1;
5630 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5632 | builtin_type_expression
5638 | pointer_star pointer_stars
5640 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5648 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5652 identifier_inside_body
5656 $$ = Error_AwaitAsIdentifier ($1);
5660 block_variable_declaration
5661 : variable_type identifier_inside_body
5663 var lt = (LocatedToken) $2;
5664 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5665 current_block.AddLocalName (li);
5666 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5668 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5670 $$ = current_variable;
5671 current_variable = null;
5673 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5675 lbag.AddLocation ($$, GetLocation ($6));
5677 | CONST variable_type identifier_inside_body
5679 var lt = (LocatedToken) $3;
5680 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5681 current_block.AddLocalName (li);
5682 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5684 const_variable_initializer opt_const_declarators SEMICOLON
5686 $$ = current_variable;
5687 current_variable = null;
5688 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5692 opt_local_variable_initializer
5694 | ASSIGN block_variable_initializer
5696 current_variable.Initializer = (Expression) $2;
5697 PushLocation (GetLocation ($1));
5698 $$ = current_variable;
5702 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5703 report.Error (650, lexer.Location,
5704 "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");
5706 Error_SyntaxError (yyToken);
5711 opt_variable_declarators
5713 | variable_declarators
5716 opt_using_or_fixed_variable_declarators
5718 | variable_declarators
5720 foreach (var d in current_variable.Declarators) {
5721 if (d.Initializer == null)
5722 Error_MissingInitializer (d.Variable.Location);
5727 variable_declarators
5728 : variable_declarator
5729 | variable_declarators variable_declarator
5733 : COMMA identifier_inside_body
5735 var lt = (LocatedToken) $2;
5736 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5737 var d = new BlockVariableDeclarator (li, null);
5738 current_variable.AddDeclarator (d);
5739 current_block.AddLocalName (li);
5740 lbag.AddLocation (d, GetLocation ($1));
5742 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5744 var lt = (LocatedToken) $2;
5745 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5746 var d = new BlockVariableDeclarator (li, (Expression) $4);
5747 current_variable.AddDeclarator (d);
5748 current_block.AddLocalName (li);
5749 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5753 const_variable_initializer
5756 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5758 | ASSIGN constant_initializer_expr
5760 current_variable.Initializer = (Expression) $2;
5764 opt_const_declarators
5771 | const_declarators const_declarator
5775 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5777 var lt = (LocatedToken) $2;
5778 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5779 var d = new BlockVariableDeclarator (li, (Expression) $4);
5780 current_variable.AddDeclarator (d);
5781 current_block.AddLocalName (li);
5782 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5786 block_variable_initializer
5787 : variable_initializer
5788 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5790 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5791 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5793 | STACKALLOC simple_type
5795 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5796 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5800 expression_statement
5801 : statement_expression SEMICOLON
5804 lbag.AddStatement ($$, GetLocation ($2));
5806 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5807 | statement_expression CLOSE_BRACE
5810 report.Error (1002, GetLocation ($2), "; expected");
5811 lexer.putback ('}');
5815 interactive_expression_statement
5816 : interactive_statement_expression SEMICOLON { $$ = $1; }
5817 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5821 // We have to do the wrapping here and not in the case above,
5822 // because statement_expression is used for example in for_statement
5824 statement_expression
5827 ExpressionStatement s = $1 as ExpressionStatement;
5829 var expr = $1 as Expression;
5830 $$ = new StatementErrorExpression (expr);
5832 $$ = new StatementExpression (s);
5837 interactive_statement_expression
5840 Expression expr = (Expression) $1;
5841 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5845 Error_SyntaxError (yyToken);
5846 $$ = new EmptyStatement (GetLocation ($1));
5856 : IF open_parens_any boolean_expression CLOSE_PARENS
5859 if ($5 is EmptyStatement)
5860 Warning_EmptyStatement (GetLocation ($5));
5862 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5863 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5865 | IF open_parens_any boolean_expression CLOSE_PARENS
5866 embedded_statement ELSE embedded_statement
5868 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5869 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5871 if ($5 is EmptyStatement)
5872 Warning_EmptyStatement (GetLocation ($5));
5873 if ($7 is EmptyStatement)
5874 Warning_EmptyStatement (GetLocation ($7));
5876 | IF open_parens_any boolean_expression error
5878 Error_SyntaxError (yyToken);
5880 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5881 lbag.AddStatement ($$, GetLocation ($2));
5886 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5888 start_block (GetLocation ($5));
5890 opt_switch_sections CLOSE_BRACE
5892 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5893 end_block (GetLocation ($8));
5894 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5896 | SWITCH open_parens_any expression error
5898 Error_SyntaxError (yyToken);
5900 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5901 lbag.AddStatement ($$, GetLocation ($2));
5908 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5915 | switch_sections switch_section
5918 Error_SyntaxError (yyToken);
5923 : switch_labels statement_list
5929 var label = (SwitchLabel) $1;
5930 label.SectionStart = true;
5931 current_block.AddStatement (label);
5933 | switch_labels switch_label
5935 current_block.AddStatement ((Statement) $2);
5940 : CASE constant_expression COLON
5942 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5943 lbag.AddLocation ($$, GetLocation ($3));
5945 | CASE constant_expression error
5947 Error_SyntaxError (yyToken);
5948 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5951 | CASE pattern_expr_invocation COLON
5953 if (lang_version != LanguageVersion.Experimental)
5954 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
5956 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
5957 PatternMatching = true
5959 lbag.AddLocation ($$, GetLocation ($3));
5964 $$ = new SwitchLabel (null, GetLocation ($1));
5976 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5978 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5979 Warning_EmptyStatement (GetLocation ($5));
5981 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5982 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5984 | WHILE open_parens_any boolean_expression error
5986 Error_SyntaxError (yyToken);
5988 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5989 lbag.AddStatement ($$, GetLocation ($2));
5994 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5996 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5997 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5999 | DO embedded_statement error
6001 Error_SyntaxError (yyToken);
6002 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6004 | DO embedded_statement WHILE open_parens_any boolean_expression error
6006 Error_SyntaxError (yyToken);
6008 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6009 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6014 : FOR open_parens_any
6016 start_block (GetLocation ($2));
6017 current_block.IsCompilerGenerated = true;
6018 For f = new For (GetLocation ($1));
6019 current_block.AddStatement (f);
6028 // Has to use be extra rule to recover started block
6030 : opt_for_initializer SEMICOLON
6032 ((For) $0).Initializer = (Statement) $1;
6034 // Pass the "For" object to the iterator_part4
6035 oob_stack.Push ($0);
6037 for_condition_and_iterator_part
6040 var locations = (Tuple<Location,Location>) $4;
6042 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6043 Warning_EmptyStatement (GetLocation ($5));
6046 f.Statement = (Statement) $5;
6047 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6049 $$ = end_block (GetLocation ($2));
6053 Error_SyntaxError (yyToken);
6054 $$ = end_block (current_block.StartLocation);
6058 for_condition_and_iterator_part
6059 : opt_for_condition SEMICOLON
6061 For f = (For) oob_stack.Peek ();
6062 f.Condition = (BooleanExpression) $1;
6065 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6068 // Handle errors in the case of opt_for_condition being followed by
6069 // a close parenthesis
6070 | opt_for_condition close_parens_close_brace {
6071 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6072 For f = (For) oob_stack.Peek ();
6073 f.Condition = (BooleanExpression) $1;
6074 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6079 : opt_for_iterator CLOSE_PARENS {
6080 For f = (For) oob_stack.Peek ();
6081 f.Iterator = (Statement) $1;
6082 $$ = GetLocation ($2);
6084 | opt_for_iterator CLOSE_BRACE {
6085 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6086 For f = (For) oob_stack.Peek ();
6087 f.Iterator = (Statement) $1;
6088 $$ = GetLocation ($2);
6092 close_parens_close_brace
6094 | CLOSE_BRACE { lexer.putback ('}'); }
6098 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6103 : variable_type identifier_inside_body
6105 var lt = (LocatedToken) $2;
6106 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6107 current_block.AddLocalName (li);
6108 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6110 opt_local_variable_initializer opt_variable_declarators
6112 $$ = current_variable;
6114 lbag.AddLocation (current_variable, PopLocation ());
6116 current_variable = null;
6118 | statement_expression_list
6122 : /* empty */ { $$ = null; }
6123 | boolean_expression
6127 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6132 : statement_expression_list
6135 statement_expression_list
6136 : statement_expression
6137 | statement_expression_list COMMA statement_expression
6139 var sl = $1 as StatementList;
6141 sl = new StatementList ((Statement) $1, (Statement) $3);
6142 lbag.AddStatement (sl, GetLocation ($2));
6144 sl.Add ((Statement) $3);
6145 lbag.AppendTo (sl, GetLocation ($2));
6153 : FOREACH open_parens_any type error
6155 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6157 start_block (GetLocation ($2));
6158 current_block.IsCompilerGenerated = true;
6160 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6161 current_block.AddStatement (f);
6163 lbag.AddStatement (f, GetLocation ($2));
6164 $$ = end_block (GetLocation ($4));
6166 | FOREACH open_parens_any type identifier_inside_body error
6168 Error_SyntaxError (yyToken);
6170 start_block (GetLocation ($2));
6171 current_block.IsCompilerGenerated = true;
6173 var lt = (LocatedToken) $4;
6174 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6175 current_block.AddLocalName (li);
6177 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6178 current_block.AddStatement (f);
6180 lbag.AddStatement (f, GetLocation ($2));
6181 $$ = end_block (GetLocation ($5));
6183 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6185 start_block (GetLocation ($2));
6186 current_block.IsCompilerGenerated = true;
6188 var lt = (LocatedToken) $4;
6189 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6190 current_block.AddLocalName (li);
6195 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6196 Warning_EmptyStatement (GetLocation ($9));
6198 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6199 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6200 end_block (GetLocation ($7));
6208 | continue_statement
6218 $$ = new Break (GetLocation ($1));
6219 lbag.AddStatement ($$, GetLocation ($2));
6224 : CONTINUE SEMICOLON
6226 $$ = new Continue (GetLocation ($1));
6227 lbag.AddStatement ($$, GetLocation ($2));
6231 Error_SyntaxError (yyToken);
6232 $$ = new Continue (GetLocation ($1));
6237 : GOTO identifier_inside_body SEMICOLON
6239 var lt = (LocatedToken) $2;
6240 $$ = new Goto (lt.Value, GetLocation ($1));
6241 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6243 | GOTO CASE constant_expression SEMICOLON
6245 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6246 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6248 | GOTO DEFAULT SEMICOLON
6250 $$ = new GotoDefault (GetLocation ($1));
6251 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6256 : RETURN opt_expression SEMICOLON
6258 $$ = new Return ((Expression) $2, GetLocation ($1));
6259 lbag.AddStatement ($$, GetLocation ($3));
6261 | RETURN expression error
6263 Error_SyntaxError (yyToken);
6264 $$ = new Return ((Expression) $2, GetLocation ($1));
6268 Error_SyntaxError (yyToken);
6269 $$ = new Return (null, GetLocation ($1));
6274 : THROW opt_expression SEMICOLON
6276 $$ = new Throw ((Expression) $2, GetLocation ($1));
6277 lbag.AddStatement ($$, GetLocation ($3));
6279 | THROW expression error
6281 Error_SyntaxError (yyToken);
6282 $$ = new Throw ((Expression) $2, GetLocation ($1));
6286 Error_SyntaxError (yyToken);
6287 $$ = new Throw (null, GetLocation ($1));
6292 : identifier_inside_body RETURN opt_expression SEMICOLON
6294 var lt = (LocatedToken) $1;
6295 string s = lt.Value;
6297 report.Error (1003, lt.Location, "; expected");
6298 } else if ($3 == null) {
6299 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6300 } else if (lang_version == LanguageVersion.ISO_1){
6301 FeatureIsNotAvailable (lt.Location, "iterators");
6304 current_block.Explicit.RegisterIteratorYield ();
6305 $$ = new Yield ((Expression) $3, lt.Location);
6306 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6308 | identifier_inside_body RETURN expression error
6310 Error_SyntaxError (yyToken);
6312 var lt = (LocatedToken) $1;
6313 string s = lt.Value;
6315 report.Error (1003, lt.Location, "; expected");
6316 } else if ($3 == null) {
6317 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6318 } else if (lang_version == LanguageVersion.ISO_1){
6319 FeatureIsNotAvailable (lt.Location, "iterators");
6322 current_block.Explicit.RegisterIteratorYield ();
6323 $$ = new Yield ((Expression) $3, lt.Location);
6324 lbag.AddStatement ($$, GetLocation ($2));
6326 | identifier_inside_body BREAK SEMICOLON
6328 var lt = (LocatedToken) $1;
6329 string s = lt.Value;
6331 report.Error (1003, lt.Location, "; expected");
6332 } else if (lang_version == LanguageVersion.ISO_1){
6333 FeatureIsNotAvailable (lt.Location, "iterators");
6336 current_block.ParametersBlock.TopBlock.IsIterator = true;
6337 $$ = new YieldBreak (lt.Location);
6338 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6348 : TRY block catch_clauses
6350 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6352 | TRY block FINALLY block
6354 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6355 lbag.AddStatement ($$, GetLocation ($3));
6357 | TRY block catch_clauses FINALLY block
6359 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6360 lbag.AddStatement ($$, GetLocation ($4));
6364 Error_SyntaxError (1524, yyToken);
6365 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6372 var l = new List<Catch> (2);
6377 | catch_clauses catch_clause
6379 var l = (List<Catch>) $1;
6381 Catch c = (Catch) $2;
6382 var prev_catch = l [l.Count - 1];
6383 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6384 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6394 | identifier_inside_body
6398 : CATCH opt_catch_filter block
6400 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6401 c.Filter = (CatchFilterExpression) $2;
6404 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6406 start_block (GetLocation ($2));
6407 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6408 c.TypeExpression = (FullNamedExpression) $3;
6411 var lt = (LocatedToken) $4;
6412 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6413 current_block.AddLocalName (c.Variable);
6416 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6419 opt_catch_filter block_prepared
6421 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6424 | CATCH open_parens_any error
6426 if (yyToken == Token.CLOSE_PARENS) {
6427 report.Error (1015, lexer.Location,
6428 "A type that derives from `System.Exception', `object', or `string' expected");
6430 Error_SyntaxError (yyToken);
6433 $$ = new Catch (null, GetLocation ($1));
6435 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6437 Error_SyntaxError (yyToken);
6439 // Required otherwise missing block could not be detected because
6440 // start_block is run early
6441 var c = new Catch (null, GetLocation ($1));
6442 c.TypeExpression = (FullNamedExpression) $3;
6445 var lt = (LocatedToken) $4;
6446 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6449 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6457 | IF open_parens_any expression CLOSE_PARENS
6459 if (lang_version <= LanguageVersion.V_5)
6460 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6462 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6463 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6470 $$ = new Checked ((Block) $2, GetLocation ($1));
6477 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6484 if (!settings.Unsafe)
6485 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6487 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6492 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6494 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6495 Warning_EmptyStatement (GetLocation ($5));
6497 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6498 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6500 | LOCK open_parens_any expression error
6502 Error_SyntaxError (yyToken);
6504 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6505 lbag.AddStatement ($$, GetLocation ($2));
6510 : FIXED open_parens_any variable_type identifier_inside_body
6512 start_block (GetLocation ($2));
6514 current_block.IsCompilerGenerated = true;
6515 var lt = (LocatedToken) $4;
6516 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6517 current_block.AddLocalName (li);
6518 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6520 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6522 $$ = current_variable;
6523 current_variable = null;
6527 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6528 Warning_EmptyStatement (GetLocation ($10));
6530 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6531 current_block.AddStatement (f);
6532 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6533 $$ = end_block (GetLocation ($8));
6538 : USING open_parens_any variable_type identifier_inside_body
6540 start_block (GetLocation ($2));
6542 current_block.IsCompilerGenerated = true;
6543 var lt = (LocatedToken) $4;
6544 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6545 current_block.AddLocalName (li);
6546 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6548 using_initialization CLOSE_PARENS
6550 $$ = current_variable;
6551 current_variable = null;
6555 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6556 Warning_EmptyStatement (GetLocation ($9));
6558 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6559 current_block.AddStatement (u);
6560 $$ = end_block (GetLocation ($7));
6562 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6564 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6565 Warning_EmptyStatement (GetLocation ($5));
6567 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6568 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6570 | USING open_parens_any expression error
6572 Error_SyntaxError (yyToken);
6574 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6575 lbag.AddStatement ($$, GetLocation ($2));
6579 using_initialization
6580 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6583 // It has to be here for the parent to safely restore artificial block
6584 Error_SyntaxError (yyToken);
6588 using_or_fixed_variable_initializer
6591 Error_MissingInitializer (lexer.Location);
6593 | ASSIGN variable_initializer
6595 current_variable.Initializer = (Expression) $2;
6596 $$ = current_variable;
6604 : first_from_clause query_body
6606 lexer.query_parsing = false;
6608 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6610 from.Tail.Next = (Linq.AQueryClause)$2;
6613 current_block.SetEndLocation (lexer.Location);
6614 current_block = current_block.Parent;
6616 | nested_from_clause query_body
6618 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6620 from.Tail.Next = (Linq.AQueryClause)$2;
6623 current_block.SetEndLocation (lexer.Location);
6624 current_block = current_block.Parent;
6627 // Bubble up COMPLETE_COMPLETION productions
6628 | first_from_clause COMPLETE_COMPLETION {
6629 lexer.query_parsing = false;
6632 current_block.SetEndLocation (lexer.Location);
6633 current_block = current_block.Parent;
6635 | nested_from_clause COMPLETE_COMPLETION {
6637 current_block.SetEndLocation (lexer.Location);
6638 current_block = current_block.Parent;
6643 : FROM_FIRST identifier_inside_body IN expression
6645 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6647 var lt = (LocatedToken) $2;
6648 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6649 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6650 lbag.AddLocation (clause, GetLocation ($3));
6651 $$ = new Linq.QueryExpression (clause);
6653 | FROM_FIRST type identifier_inside_body IN expression
6655 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6657 var lt = (LocatedToken) $3;
6658 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6659 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6660 IdentifierType = (FullNamedExpression)$2
6662 lbag.AddLocation (clause, GetLocation ($4));
6663 $$ = new Linq.QueryExpression (clause);
6668 : FROM identifier_inside_body IN expression
6670 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6672 var lt = (LocatedToken) $2;
6673 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6674 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6675 lbag.AddLocation (clause, GetLocation ($3));
6676 $$ = new Linq.QueryExpression (clause);
6678 | FROM type identifier_inside_body IN expression
6680 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6682 var lt = (LocatedToken) $3;
6683 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6684 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6685 IdentifierType = (FullNamedExpression)$2
6687 lbag.AddLocation (clause, GetLocation ($4));
6688 $$ = new Linq.QueryExpression (clause);
6693 : FROM identifier_inside_body IN
6695 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6699 var lt = (LocatedToken) $2;
6700 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6701 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6703 current_block.SetEndLocation (lexer.Location);
6704 current_block = current_block.Parent;
6706 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6707 lbag.AddLocation ($$, GetLocation ($3));
6709 | FROM type identifier_inside_body IN
6711 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6715 var lt = (LocatedToken) $3;
6716 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6718 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6719 IdentifierType = (FullNamedExpression)$2
6722 current_block.SetEndLocation (lexer.Location);
6723 current_block = current_block.Parent;
6725 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6727 lbag.AddLocation ($$, GetLocation ($4));
6732 : query_body_clauses select_or_group_clause opt_query_continuation
6734 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6737 head.Next = (Linq.AQueryClause)$3;
6740 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6741 clause.Tail.Next = head;
6747 | select_or_group_clause opt_query_continuation
6749 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6752 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6753 clause.Tail.Next = head;
6759 | query_body_clauses COMPLETE_COMPLETION
6760 | query_body_clauses error
6762 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6767 Error_SyntaxError (yyToken);
6772 select_or_group_clause
6775 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6779 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6781 current_block.SetEndLocation (lexer.Location);
6782 current_block = current_block.Parent;
6786 if (linq_clause_blocks == null)
6787 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6789 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6790 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6794 current_block.SetEndLocation (lexer.Location);
6795 current_block = current_block.Parent;
6797 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6801 var obj = (object[]) $5;
6803 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6804 lbag.AddLocation ($$, (Location) obj[1]);
6806 current_block.SetEndLocation (lexer.Location);
6807 current_block = current_block.Parent;
6812 : BY expression_or_error
6814 $$ = new object[] { $2, GetLocation ($1) };
6818 Error_SyntaxError (yyToken);
6819 $$ = new object[2] { null, Location.Null };
6825 | query_body_clauses query_body_clause
6827 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6841 : LET identifier_inside_body ASSIGN
6843 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6847 var lt = (LocatedToken) $2;
6848 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6849 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6850 lbag.AddLocation ($$, GetLocation ($3));
6852 current_block.SetEndLocation (lexer.Location);
6853 current_block = current_block.Parent;
6855 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6862 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6866 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6868 current_block.SetEndLocation (lexer.Location);
6869 current_block = current_block.Parent;
6874 : JOIN identifier_inside_body IN
6876 if (linq_clause_blocks == null)
6877 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6879 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6880 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6882 expression_or_error ON
6884 current_block.SetEndLocation (lexer.Location);
6885 current_block = current_block.Parent;
6887 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6888 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6890 expression_or_error EQUALS
6892 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6893 current_block.SetEndLocation (lexer.Location);
6894 current_block = current_block.Parent;
6896 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6898 expression_or_error opt_join_into
6900 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6901 current_block.SetEndLocation (lexer.Location);
6903 var outer_selector = linq_clause_blocks.Pop ();
6904 var block = linq_clause_blocks.Pop ();
6906 var lt = (LocatedToken) $2;
6907 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6908 Linq.RangeVariable into;
6912 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6913 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6916 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6918 var parent = block.Parent;
6919 while (parent is Linq.QueryBlock) {
6920 parent = parent.Parent;
6922 current_block.Parent = parent;
6924 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6926 lt = (LocatedToken) $12;
6927 into = new Linq.RangeVariable (lt.Value, lt.Location);
6929 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6930 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6933 current_block = block.Parent;
6934 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6936 | JOIN type identifier_inside_body IN
6938 if (linq_clause_blocks == null)
6939 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6941 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6942 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6944 expression_or_error ON
6946 current_block.SetEndLocation (lexer.Location);
6947 current_block = current_block.Parent;
6949 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6950 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6952 expression_or_error EQUALS
6954 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6955 current_block.SetEndLocation (lexer.Location);
6956 current_block = current_block.Parent;
6958 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6960 expression_or_error opt_join_into
6962 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6963 current_block.SetEndLocation (lexer.Location);
6965 var outer_selector = linq_clause_blocks.Pop ();
6966 var block = linq_clause_blocks.Pop ();
6968 var lt = (LocatedToken) $3;
6969 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6970 Linq.RangeVariable into;
6974 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6975 IdentifierType = (FullNamedExpression)$2
6977 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6980 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6982 var parent = block.Parent;
6983 while (parent is Linq.QueryBlock) {
6984 parent = parent.Parent;
6986 current_block.Parent = parent;
6988 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6990 lt = (LocatedToken) $13;
6991 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6993 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6994 IdentifierType = (FullNamedExpression)$2
6998 current_block = block.Parent;
6999 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7005 | INTO identifier_inside_body
7014 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7018 current_block.SetEndLocation (lexer.Location);
7019 current_block = current_block.Parent;
7029 current_block.SetEndLocation (lexer.Location);
7030 current_block = current_block.Parent;
7032 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7036 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7043 | orderings_then_by COMMA
7045 current_block.SetEndLocation (lexer.Location);
7046 current_block = current_block.Parent;
7048 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7052 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7060 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7062 | expression ASCENDING
7064 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7065 lbag.AddLocation ($$, GetLocation ($2));
7067 | expression DESCENDING
7069 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7070 lbag.AddLocation ($$, GetLocation ($2));
7077 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7079 | expression ASCENDING
7081 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7082 lbag.AddLocation ($$, GetLocation ($2));
7084 | expression DESCENDING
7086 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7087 lbag.AddLocation ($$, GetLocation ($2));
7092 opt_query_continuation
7094 | INTO identifier_inside_body
7096 // query continuation block is not linked with query block but with block
7097 // before. This means each query can use same range variable names for
7098 // different identifiers.
7100 current_block.SetEndLocation (GetLocation ($1));
7101 current_block = current_block.Parent;
7103 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7105 if (linq_clause_blocks == null)
7106 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7108 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7112 var current_block = linq_clause_blocks.Pop ();
7113 var lt = (LocatedToken) $2;
7114 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7115 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7116 next = (Linq.AQueryClause)$4
7122 // Support for using the compiler as an interactive parser
7124 // The INTERACTIVE_PARSER token is first sent to parse our
7125 // productions; If the result is a Statement, the parsing
7126 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7127 // to setup the blocks in advance.
7129 // This setup is here so that in the future we can add
7130 // support for other constructs (type parsing, namespaces, etc)
7131 // that do not require a block to be setup in advance
7135 : EVAL_STATEMENT_PARSER EOF
7136 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7137 | EVAL_STATEMENT_PARSER
7139 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7141 // (ref object retval)
7142 Parameter [] mpar = new Parameter [1];
7143 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7145 ParametersCompiled pars = new ParametersCompiled (mpar);
7146 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7147 if (settings.Unsafe)
7148 mods |= Modifiers.UNSAFE;
7150 current_local_parameters = pars;
7151 var method = new InteractiveMethod (
7153 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7157 current_type.AddMember (method);
7158 oob_stack.Push (method);
7160 interactive_async = false;
7162 ++lexer.parsing_block;
7163 start_block (lexer.Location);
7165 interactive_statement_list opt_COMPLETE_COMPLETION
7167 --lexer.parsing_block;
7168 var method = (InteractiveMethod) oob_stack.Pop ();
7169 method.Block = (ToplevelBlock) end_block(lexer.Location);
7171 if (interactive_async == true) {
7172 method.ChangeToAsync ();
7175 InteractiveResult = (Class) pop_current_class ();
7176 current_local_parameters = null;
7178 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7181 interactive_compilation_unit
7182 : opt_extern_alias_directives opt_using_directives
7183 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7186 opt_COMPLETE_COMPLETION
7188 | COMPLETE_COMPLETION
7191 close_brace_or_complete_completion
7193 | COMPLETE_COMPLETION
7197 // XML documentation code references micro parser
7199 documentation_parsing
7202 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7207 : doc_type_declaration_name opt_doc_method_sig
7209 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7211 | builtin_types opt_doc_method_sig
7213 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7214 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7217 | VOID opt_doc_method_sig
7219 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7220 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7223 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7225 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7226 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7227 var lt = (LocatedToken) $3;
7228 $$ = new MemberName (lt.Value);
7230 | doc_type_declaration_name DOT THIS
7232 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7234 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7236 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7238 opt_doc_parameters CLOSE_BRACKET
7240 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7241 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7243 | EXPLICIT OPERATOR type opt_doc_method_sig
7245 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7246 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7247 module.DocumentationBuilder.ParsedParameters = p;
7248 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7251 | IMPLICIT OPERATOR type opt_doc_method_sig
7253 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7254 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7255 module.DocumentationBuilder.ParsedParameters = p;
7256 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7259 | OPERATOR overloadable_operator opt_doc_method_sig
7261 var p = (List<DocumentationParameter>)$3;
7262 module.DocumentationBuilder.ParsedParameters = p;
7263 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7268 doc_type_declaration_name
7269 : type_declaration_name
7270 | doc_type_declaration_name DOT type_declaration_name
7272 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7280 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7282 opt_doc_parameters CLOSE_PARENS
7291 $$ = new List<DocumentationParameter> (0);
7299 var parameters = new List<DocumentationParameter> ();
7300 parameters.Add ((DocumentationParameter) $1);
7303 | doc_parameters COMMA doc_parameter
7305 var parameters = $1 as List<DocumentationParameter>;
7306 parameters.Add ((DocumentationParameter) $3);
7312 : opt_parameter_modifier parameter_type
7315 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7317 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7324 // A class used to hold info about an operator declarator
7326 class OperatorDeclaration {
7327 public readonly Operator.OpType optype;
7328 public readonly FullNamedExpression ret_type;
7329 public readonly Location location;
7331 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7334 this.ret_type = ret_type;
7335 this.location = location;
7339 void Error_ExpectingTypeName (Expression expr)
7341 if (expr is Invocation){
7342 report.Error (1002, expr.Location, "Expecting `;'");
7344 expr.Error_InvalidExpressionStatement (report);
7348 void Error_ParameterModifierNotValid (string modifier, Location loc)
7350 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7354 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7356 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7357 Parameter.GetModifierSignature (mod));
7360 void Error_TypeExpected (Location loc)
7362 report.Error (1031, loc, "Type expected");
7365 void Error_UnsafeCodeNotAllowed (Location loc)
7367 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7370 void Warning_EmptyStatement (Location loc)
7372 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7375 void Error_NamedArgumentExpected (NamedArgument a)
7377 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7380 void Error_MissingInitializer (Location loc)
7382 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7385 object Error_AwaitAsIdentifier (object token)
7388 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7389 return new LocatedToken ("await", GetLocation (token));
7395 void push_current_container (TypeDefinition tc, object partial_token)
7397 if (module.Evaluator != null){
7398 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7402 undo.AddTypeContainer (current_container, tc);
7405 if (partial_token != null)
7406 current_container.AddPartial (tc);
7408 current_container.AddTypeContainer (tc);
7410 ++lexer.parsing_declaration;
7411 current_container = tc;
7415 TypeContainer pop_current_class ()
7417 var retval = current_container;
7419 current_container = current_container.Parent;
7420 current_type = current_type.Parent as TypeDefinition;
7425 [System.Diagnostics.Conditional ("FULL_AST")]
7426 void StoreModifierLocation (object token, Location loc)
7431 if (mod_locations == null)
7432 mod_locations = new List<Tuple<Modifiers, Location>> ();
7434 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7437 [System.Diagnostics.Conditional ("FULL_AST")]
7438 void PushLocation (Location loc)
7440 if (location_stack == null)
7441 location_stack = new Stack<Location> ();
7443 location_stack.Push (loc);
7446 Location PopLocation ()
7448 if (location_stack == null)
7449 return Location.Null;
7451 return location_stack.Pop ();
7454 string CheckAttributeTarget (int token, string a, Location l)
7457 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7461 if (!Tokenizer.IsValidIdentifier (a)) {
7462 Error_SyntaxError (token);
7464 report.Warning (658, 1, l,
7465 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7468 return string.Empty;
7471 static bool IsUnaryOperator (Operator.OpType op)
7475 case Operator.OpType.LogicalNot:
7476 case Operator.OpType.OnesComplement:
7477 case Operator.OpType.Increment:
7478 case Operator.OpType.Decrement:
7479 case Operator.OpType.True:
7480 case Operator.OpType.False:
7481 case Operator.OpType.UnaryPlus:
7482 case Operator.OpType.UnaryNegation:
7488 void syntax_error (Location l, string msg)
7490 report.Error (1003, l, "Syntax error, " + msg);
7495 public Tokenizer Lexer {
7501 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7502 : this (reader, file, file.Compiler.Report, session)
7506 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7509 current_container = current_namespace = file;
7511 this.module = file.Module;
7512 this.compiler = file.Compiler;
7513 this.settings = compiler.Settings;
7514 this.report = report;
7516 lang_version = settings.Version;
7517 yacc_verbose_flag = settings.VerboseParserFlag;
7518 doc_support = settings.DocumentationFile != null;
7519 lexer = new Tokenizer (reader, file, session, report);
7520 oob_stack = new Stack<object> ();
7521 lbag = session.LocationsBag;
7522 use_global_stacks = session.UseJayGlobalArrays;
7523 parameters_bucket = session.ParametersStack;
7526 public void parse ()
7528 eof_token = Token.EOF;
7531 if (yacc_verbose_flag > 1)
7532 yyparse (lexer, new yydebug.yyDebugSimple ());
7536 Tokenizer tokenizer = lexer as Tokenizer;
7537 tokenizer.cleanup ();
7538 } catch (Exception e){
7539 if (e is yyParser.yyUnexpectedEof) {
7540 Error_SyntaxError (yyToken);
7541 UnexpectedEOF = true;
7545 if (e is yyParser.yyException) {
7546 if (report.Errors == 0)
7547 report.Error (-25, lexer.Location, "Parsing error");
7549 // Used by compiler-tester to test internal errors
7550 if (yacc_verbose_flag > 0 || e is FatalException)
7553 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7558 void CheckToken (int error, int yyToken, string msg, Location loc)
7560 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7561 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7563 report.Error (error, loc, msg);
7566 string ConsumeStoredComment ()
7568 string s = tmpComment;
7570 Lexer.doc_state = XmlCommentState.Allowed;
7574 void FeatureIsNotAvailable (Location loc, string feature)
7576 report.FeatureIsNotAvailable (compiler, loc, feature);
7579 Location GetLocation (object obj)
7581 var lt = obj as LocatedToken;
7585 var mn = obj as MemberName;
7589 var expr = obj as Expression;
7591 return expr.Location;
7593 return lexer.Location;
7596 void start_block (Location loc)
7598 if (current_block == null) {
7599 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7600 parsing_anonymous_method = false;
7601 } else if (parsing_anonymous_method) {
7602 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7603 parsing_anonymous_method = false;
7605 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7610 end_block (Location loc)
7612 Block retval = current_block.Explicit;
7613 retval.SetEndLocation (loc);
7614 current_block = retval.Parent;
7618 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7620 oob_stack.Push (current_anonymous_method);
7621 oob_stack.Push (current_local_parameters);
7622 oob_stack.Push (current_variable);
7623 oob_stack.Push (async_block);
7625 current_local_parameters = parameters;
7627 if (lang_version <= LanguageVersion.ISO_2)
7628 FeatureIsNotAvailable (loc, "lambda expressions");
7630 current_anonymous_method = new LambdaExpression (loc);
7632 if (lang_version == LanguageVersion.ISO_1)
7633 FeatureIsNotAvailable (loc, "anonymous methods");
7635 current_anonymous_method = new AnonymousMethodExpression (loc);
7638 async_block = isAsync;
7639 // Force the next block to be created as a ToplevelBlock
7640 parsing_anonymous_method = true;
7644 * Completes the anonymous method processing, if lambda_expr is null, this
7645 * means that we have a Statement instead of an Expression embedded
7647 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7649 AnonymousMethodExpression retval;
7652 anon_block.IsAsync = true;
7654 current_anonymous_method.Block = anon_block;
7655 retval = current_anonymous_method;
7657 async_block = (bool) oob_stack.Pop ();
7658 current_variable = (BlockVariable) oob_stack.Pop ();
7659 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7660 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7665 void Error_SyntaxError (int token)
7667 Error_SyntaxError (0, token);
7670 void Error_SyntaxError (int error_code, int token)
7672 Error_SyntaxError (error_code, token, "Unexpected symbol");
7675 void Error_SyntaxError (int error_code, int token, string msg)
7677 Lexer.CompleteOnEOF = false;
7679 // An error message has been reported by tokenizer
7680 if (token == Token.ERROR)
7683 // Avoid duplicit error message after unterminated string literals
7684 if (token == Token.LITERAL && lexer.Location.Column == 0)
7687 string symbol = GetSymbolName (token);
7688 string expecting = GetExpecting ();
7689 var loc = lexer.Location - symbol.Length;
7691 if (error_code == 0) {
7692 if (expecting == "`identifier'") {
7693 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7694 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7699 expecting = "identifier";
7700 } else if (expecting == "`)'") {
7707 if (string.IsNullOrEmpty (expecting))
7708 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7710 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7713 string GetExpecting ()
7715 int [] tokens = yyExpectingTokens (yyExpectingState);
7716 var names = new List<string> (tokens.Length);
7717 bool has_type = false;
7718 bool has_identifier = false;
7719 for (int i = 0; i < tokens.Length; i++){
7720 int token = tokens [i];
7721 has_identifier |= token == Token.IDENTIFIER;
7723 string name = GetTokenName (token);
7724 if (name == "<internal>")
7727 has_type |= name == "type";
7728 if (names.Contains (name))
7735 // Too many tokens to enumerate
7737 if (names.Count > 8)
7740 if (has_type && has_identifier)
7741 names.Remove ("identifier");
7743 if (names.Count == 1)
7744 return "`" + GetTokenName (tokens [0]) + "'";
7746 StringBuilder sb = new StringBuilder ();
7748 int count = names.Count;
7749 for (int i = 0; i < count; i++){
7750 bool last = i + 1 == count;
7754 sb.Append (names [i]);
7755 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7757 return sb.ToString ();
7761 string GetSymbolName (int token)
7765 return ((Constant)lexer.Value).GetValue ().ToString ();
7766 case Token.IDENTIFIER:
7767 return ((LocatedToken)lexer.Value).Value;
7809 case Token.BITWISE_AND:
7811 case Token.BITWISE_OR:
7825 case Token.OP_SHIFT_LEFT:
7827 case Token.OP_SHIFT_RIGHT:
7847 case Token.OP_COALESCING:
7849 case Token.OP_MULT_ASSIGN:
7851 case Token.OP_DIV_ASSIGN:
7853 case Token.OP_MOD_ASSIGN:
7855 case Token.OP_ADD_ASSIGN:
7857 case Token.OP_SUB_ASSIGN:
7859 case Token.OP_SHIFT_LEFT_ASSIGN:
7861 case Token.OP_SHIFT_RIGHT_ASSIGN:
7863 case Token.OP_AND_ASSIGN:
7865 case Token.OP_XOR_ASSIGN:
7867 case Token.OP_OR_ASSIGN:
7871 return GetTokenName (token);
7874 static string GetTokenName (int token)
7877 case Token.ABSTRACT:
7899 case Token.CONTINUE:
7903 case Token.DELEGATE:
7913 case Token.EXPLICIT:
7916 case Token.EXTERN_ALIAS:
7932 case Token.IMPLICIT:
7936 case Token.INTERFACE:
7938 case Token.INTERNAL:
7944 case Token.NAMESPACE:
7950 case Token.OPERATOR:
7954 case Token.OVERRIDE:
7960 case Token.PROTECTED:
7964 case Token.READONLY:
7976 case Token.STACKALLOC:
7977 return "stackalloc";
7994 case Token.UNCHECKED:
8002 case Token.VOLATILE:
8010 case Token.REFVALUE:
8011 return "__refvalue";
8021 case Token.FROM_FIRST:
8039 case Token.ASCENDING:
8041 case Token.DESCENDING:
8042 return "descending";
8049 case Token.OPEN_BRACE:
8051 case Token.CLOSE_BRACE:
8053 case Token.OPEN_BRACKET:
8054 case Token.OPEN_BRACKET_EXPR:
8056 case Token.CLOSE_BRACKET:
8058 case Token.OPEN_PARENS_CAST:
8059 case Token.OPEN_PARENS_LAMBDA:
8060 case Token.OPEN_PARENS:
8062 case Token.CLOSE_PARENS:
8068 case Token.DEFAULT_COLON:
8072 case Token.SEMICOLON:
8083 case Token.BITWISE_AND:
8084 case Token.BITWISE_OR:
8091 case Token.OP_SHIFT_LEFT:
8092 case Token.OP_SHIFT_RIGHT:
8100 case Token.OP_COALESCING:
8101 case Token.OP_MULT_ASSIGN:
8102 case Token.OP_DIV_ASSIGN:
8103 case Token.OP_MOD_ASSIGN:
8104 case Token.OP_ADD_ASSIGN:
8105 case Token.OP_SUB_ASSIGN:
8106 case Token.OP_SHIFT_LEFT_ASSIGN:
8107 case Token.OP_SHIFT_RIGHT_ASSIGN:
8108 case Token.OP_AND_ASSIGN:
8109 case Token.OP_XOR_ASSIGN:
8110 case Token.OP_OR_ASSIGN:
8111 case Token.INTERR_OPERATOR:
8112 return "<operator>";
8134 case Token.OP_GENERICS_LT:
8135 case Token.GENERIC_DIMENSION:
8137 case Token.OP_GENERICS_GT:
8140 case Token.INTERR_NULLABLE:
8142 case Token.DOUBLE_COLON:
8146 case Token.IDENTIFIER:
8148 return "identifier";
8151 return "end-of-file";
8153 // All of these are internal.
8156 case Token.FIRST_KEYWORD:
8157 case Token.EVAL_COMPILATION_UNIT_PARSER:
8158 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8159 case Token.EVAL_STATEMENT_PARSER:
8160 case Token.LAST_KEYWORD:
8161 case Token.GENERATE_COMPLETION:
8162 case Token.COMPLETE_COMPLETION:
8163 return "<internal>";
8165 // A bit more robust.
8167 return yyNames [token];