3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue,
39 PrimaryConstructor = Ref | Out | Params | DefaultValue
42 static readonly object ModifierNone = 0;
44 NamespaceContainer current_namespace;
45 TypeContainer current_container;
46 TypeDefinition current_type;
47 PropertyBase current_property;
48 EventProperty current_event;
49 EventField current_event_field;
50 FieldBase current_field;
53 /// Current block is used to add statements as we find
58 BlockVariable current_variable;
60 Delegate current_delegate;
62 AnonymousMethodExpression current_anonymous_method;
65 /// This is used by the unary_expression code to resolve
66 /// a name against a parameter.
69 // FIXME: This is very ugly and it's very hard to reset it correctly
70 // on all places, especially when some parameters are autogenerated.
71 ParametersCompiled current_local_parameters;
73 bool parsing_anonymous_method;
78 /// An out-of-band stack.
80 Stack<object> oob_stack;
83 /// Controls the verbosity of the errors produced by the parser
85 int yacc_verbose_flag;
88 /// Used by the interactive shell, flags whether EOF was reached
89 /// and an error was produced
91 public bool UnexpectedEOF;
96 readonly CompilationSourceFile file;
99 /// Temporary Xml documentation cache.
100 /// For enum types, we need one more temporary store.
103 string enumTypeComment;
105 /// Current attribute target
106 string current_attr_target;
108 ParameterModifierType valid_param_mod;
110 bool default_parameter_used;
112 /// When using the interactive parser, this holds the
113 /// resulting expression
114 public Class InteractiveResult;
117 // Keeps track of global data changes to undo on parser error
121 bool? interactive_async;
123 Stack<Linq.QueryBlock> linq_clause_blocks;
125 ModuleContainer module;
127 readonly CompilerContext compiler;
128 readonly LanguageVersion lang_version;
129 readonly bool doc_support;
130 readonly CompilerSettings settings;
131 readonly Report report;
134 // Instead of allocating carrier array everytime we
135 // share the bucket for very common constructs which can never
138 List<Parameter> parameters_bucket;
141 // Full AST support members
144 List<Tuple<Modifiers, Location>> mod_locations;
145 Stack<Location> location_stack;
149 %token NONE /* This token is never returned by our lexer */
150 %token ERROR // This is used not by the parser, but by the tokenizer.
154 *These are the C# keywords
253 %token INTERR_NULLABLE
260 %token INTERR_OPERATOR
262 /* C# keywords which are not really keywords */
268 /* C# single character operators/punctuation. */
296 /* C# multi-character operators. */
301 %token OP_SHIFT_RIGHT
308 %token OP_MULT_ASSIGN
313 %token OP_SHIFT_LEFT_ASSIGN
314 %token OP_SHIFT_RIGHT_ASSIGN
321 /* Generics <,> tokens */
322 %token OP_GENERICS_LT
323 %token OP_GENERICS_LT_DECL
324 %token OP_GENERICS_GT
329 %token OPEN_PARENS_LAMBDA
330 %token OPEN_PARENS_CAST
331 %token GENERIC_DIMENSION
333 %token OPEN_BRACKET_EXPR
335 // Make the parser go into eval mode parsing (statements and compilation units).
336 %token EVAL_STATEMENT_PARSER
337 %token EVAL_COMPILATION_UNIT_PARSER
338 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
343 // This token is generated to trigger the completion engine at this point
345 %token GENERATE_COMPLETION
348 // This token is return repeatedly after the first GENERATE_COMPLETION
349 // token is produced and before the final EOF
351 %token COMPLETE_COMPLETION
353 /* Add precedence rules to solve dangling else s/r conflict */
357 /* Define the operator tokens and their precedences */
365 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
367 %left STAR DIV PERCENT
368 %right BANG CARRET UMINUS
369 %nonassoc OP_INC OP_DEC
371 %left OPEN_BRACKET OPEN_BRACE
374 %start compilation_unit
378 : outer_declaration opt_EOF
380 Lexer.check_incorrect_doc_comment ();
382 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
383 | documentation_parsing
387 : opt_extern_alias_directives opt_using_directives
388 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
391 Attributes attrs = (Attributes) $4;
392 report.Error (1730, attrs.Attrs [0].Location,
393 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
395 current_namespace.UnattachedAttributes = attrs;
398 | opt_extern_alias_directives opt_using_directives attribute_sections
400 module.AddAttributes ((Attributes) $3, current_namespace);
404 if (yyToken == Token.EXTERN_ALIAS)
405 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
407 Error_SyntaxError (yyToken);
416 extern_alias_directives
417 : extern_alias_directive
418 | extern_alias_directives extern_alias_directive
421 extern_alias_directive
422 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
424 var lt = (LocatedToken) $2;
427 syntax_error (lt.Location, "`alias' expected");
429 if (lang_version == LanguageVersion.ISO_1)
430 FeatureIsNotAvailable (lt.Location, "external alias");
432 lt = (LocatedToken) $3;
433 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
434 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
437 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
438 current_namespace.AddUsing (na);
440 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
445 Error_SyntaxError (yyToken);
451 | using_directives using_directive
458 Lexer.doc_state = XmlCommentState.Allowed;
463 : USING namespace_or_type_expr SEMICOLON
465 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
466 current_namespace.AddUsing (un);
468 lbag.AddLocation (un, GetLocation ($3));
470 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
472 var lt = (LocatedToken) $2;
473 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
474 report.Warning (440, 2, lt.Location,
475 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
478 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
479 current_namespace.AddUsing (un);
481 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
485 Error_SyntaxError (yyToken);
491 // Strictly speaking, namespaces don't have attributes but
492 // we parse global attributes along with namespace declarations and then
495 namespace_declaration
496 : opt_attributes NAMESPACE namespace_name
498 Attributes attrs = (Attributes) $1;
499 var name = (MemberName) $3;
501 bool valid_global_attrs = true;
502 if ((current_namespace.DeclarationFound || current_namespace != file)) {
503 valid_global_attrs = false;
505 foreach (var a in attrs.Attrs) {
506 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
509 valid_global_attrs = false;
514 if (!valid_global_attrs)
515 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
518 module.AddAttributes (attrs, current_namespace);
520 var ns = new NamespaceContainer (name, current_namespace);
521 current_namespace.AddTypeContainer (ns);
522 current_container = current_namespace = ns;
527 Lexer.doc_state = XmlCommentState.Allowed;
529 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
532 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
534 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
536 current_container = current_namespace = current_namespace.Parent;
538 | opt_attributes NAMESPACE namespace_name
540 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
542 var name = (MemberName) $3;
543 var ns = new NamespaceContainer (name, current_namespace);
544 lbag.AddLocation (ns, GetLocation ($2));
545 current_namespace.AddTypeContainer (ns);
554 Error_SyntaxError (yyToken);
562 var lt = (LocatedToken) $1;
563 $$ = new MemberName (lt.Value, lt.Location);
565 | namespace_name DOT IDENTIFIER
567 var lt = (LocatedToken) $3;
568 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
569 lbag.AddLocation ($$, GetLocation ($2));
573 Error_SyntaxError (yyToken);
574 $$ = new MemberName ("<invalid>", lexer.Location);
593 opt_extern_alias_directives
595 | extern_alias_directives
598 opt_namespace_or_type_declarations
600 | namespace_or_type_declarations
603 namespace_or_type_declarations
604 : namespace_or_type_declaration
605 | namespace_or_type_declarations namespace_or_type_declaration
608 namespace_or_type_declaration
612 TypeContainer ds = (TypeContainer)$1;
614 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
615 report.Error (1527, ds.Location,
616 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
619 // Here is a trick, for explicit attributes we don't know where they belong to until
620 // we parse succeeding declaration hence we parse them as normal and re-attach them
621 // when we know whether they are global (assembly:, module:) or local (type:).
622 if (ds.OptAttributes != null) {
623 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
626 current_namespace.DeclarationFound = true;
628 | namespace_declaration
630 current_namespace.DeclarationFound = true;
632 | attribute_sections CLOSE_BRACE {
633 current_namespace.UnattachedAttributes = (Attributes) $1;
634 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
642 | interface_declaration
644 | delegate_declaration
646 // Enable this when we have handled all errors, because this acts as a generic fallback
649 // Console.WriteLine ("Token=" + yyToken);
650 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
666 var sect = (List<Attribute>) $1;
667 $$ = new Attributes (sect);
669 | attribute_sections attribute_section
671 Attributes attrs = $1 as Attributes;
672 var sect = (List<Attribute>) $2;
674 attrs = new Attributes (sect);
675 else if (sect != null)
676 attrs.AddAttributes (sect);
684 PushLocation (GetLocation ($1));
685 lexer.parsing_attribute_section = true;
687 attribute_section_cont
689 lexer.parsing_attribute_section = false;
694 attribute_section_cont
695 : attribute_target COLON
697 current_attr_target = (string) $1;
698 if (current_attr_target == "assembly" || current_attr_target == "module") {
699 Lexer.check_incorrect_doc_comment ();
702 attribute_list opt_comma CLOSE_BRACKET
704 // when attribute target is invalid
705 if (current_attr_target == string.Empty)
706 $$ = new List<Attribute> (0);
710 lbag.InsertLocation ($$, 0, PopLocation ());
712 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
714 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
717 current_attr_target = null;
718 lexer.parsing_attribute_section = false;
720 | attribute_list opt_comma CLOSE_BRACKET
724 lbag.InsertLocation ($$, 0, PopLocation ());
726 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
728 lbag.AddLocation ($$, GetLocation($3));
733 Error_SyntaxError (yyToken);
735 var lt = (LocatedToken) $1;
736 var tne = new SimpleName (lt.Value, null, lt.Location);
738 $$ = new List<Attribute> () {
739 new Attribute (null, tne, null, GetLocation ($1), false)
744 CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1));
752 var lt = (LocatedToken) $1;
753 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
755 | EVENT { $$ = "event"; }
756 | RETURN { $$ = "return"; }
762 $$ = new List<Attribute> (4) { (Attribute) $1 };
764 | attribute_list COMMA attribute
766 var attrs = (List<Attribute>) $1;
768 attrs.Add ((Attribute) $3);
769 lbag.AppendTo (attrs, GetLocation ($2));
779 ++lexer.parsing_block;
781 opt_attribute_arguments
783 --lexer.parsing_block;
785 var tne = (ATypeNameExpression) $1;
786 if (tne.HasTypeArguments) {
787 report.Error (404, tne.Location, "Attributes cannot be generic");
790 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
795 : namespace_or_type_expr
798 opt_attribute_arguments
799 : /* empty */ { $$ = null; }
800 | OPEN_PARENS attribute_arguments CLOSE_PARENS
808 : /* empty */ { $$ = null; }
809 | positional_or_named_argument
811 Arguments a = new Arguments (4);
812 a.Add ((Argument) $1);
813 $$ = new Arguments [] { a, null };
815 | named_attribute_argument
817 Arguments a = new Arguments (4);
818 a.Add ((Argument) $1);
819 $$ = new Arguments [] { null, a };
821 | attribute_arguments COMMA positional_or_named_argument
823 Arguments[] o = (Arguments[]) $1;
825 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
826 o [0] = new Arguments (4);
829 Arguments args = ((Arguments) o [0]);
830 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
831 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
833 args.Add ((Argument) $3);
835 | attribute_arguments COMMA named_attribute_argument
837 Arguments[] o = (Arguments[]) $1;
839 o [1] = new Arguments (4);
842 ((Arguments) o [1]).Add ((Argument) $3);
846 positional_or_named_argument
849 $$ = new Argument ((Expression) $1);
854 Error_SyntaxError (yyToken);
859 named_attribute_argument
862 ++lexer.parsing_block;
866 --lexer.parsing_block;
867 var lt = (LocatedToken) $1;
868 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
869 lbag.AddLocation ($$, GetLocation($2));
874 : identifier_inside_body COLON opt_named_modifier expression_or_error
876 if (lang_version <= LanguageVersion.V_3)
877 FeatureIsNotAvailable (GetLocation ($1), "named argument");
879 // Avoid boxing in common case (no modifier)
880 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
882 var lt = (LocatedToken) $1;
883 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
884 lbag.AddLocation ($$, GetLocation($2));
889 : /* empty */ { $$ = null; }
892 $$ = Argument.AType.Ref;
896 $$ = Argument.AType.Out;
900 opt_class_member_declarations
902 | class_member_declarations
905 class_member_declarations
906 : class_member_declaration
908 lexer.parsing_modifiers = true;
909 lexer.parsing_block = 0;
911 | class_member_declarations class_member_declaration
913 lexer.parsing_modifiers = true;
914 lexer.parsing_block = 0;
918 class_member_declaration
919 : constant_declaration
922 | property_declaration
924 | indexer_declaration
925 | operator_declaration
926 | constructor_declaration
927 | primary_constructor_body
928 | destructor_declaration
930 | attributes_without_members
934 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
935 GetSymbolName (yyToken));
937 lexer.parsing_generic_declaration = false;
941 primary_constructor_body
944 current_local_parameters = current_type.PrimaryConstructorParameters;
945 if (current_local_parameters == null) {
946 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
947 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
950 ++lexer.parsing_block;
951 start_block (GetLocation ($1));
953 opt_statement_list block_end
955 current_local_parameters = null;
956 var t = current_type as ClassOrStruct;
958 var b = (ToplevelBlock) $4;
959 if (t.PrimaryConstructorBlock != null) {
960 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
962 t.PrimaryConstructorBlock = b;
975 type_declaration_name
977 lexer.ConstraintsParsing = true;
978 valid_param_mod = ParameterModifierType.PrimaryConstructor;
979 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
981 opt_primary_parameters
983 opt_type_parameter_constraints_clauses
986 lexer.ConstraintsParsing = false;
989 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
992 current_container.SetConstraints ((List<Constraints>) $10);
995 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
997 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
999 lexer.parsing_modifiers = true;
1004 Lexer.doc_state = XmlCommentState.Allowed;
1006 opt_class_member_declarations CLOSE_BRACE
1008 --lexer.parsing_declaration;
1010 Lexer.doc_state = XmlCommentState.Allowed;
1015 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1017 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1019 $$ = pop_current_class ();
1021 | opt_attributes opt_modifiers opt_partial STRUCT error
1023 Error_SyntaxError (yyToken);
1027 constant_declaration
1030 CONST type IDENTIFIER
1032 var lt = (LocatedToken) $5;
1033 var mod = (Modifiers) $2;
1034 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1035 current_type.AddMember (current_field);
1037 if ((mod & Modifiers.STATIC) != 0) {
1038 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1043 constant_initializer opt_constant_declarators SEMICOLON
1046 current_field.DocComment = Lexer.consume_doc_comment ();
1047 Lexer.doc_state = XmlCommentState.Allowed;
1050 current_field.Initializer = (ConstInitializer) $7;
1051 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1052 current_field = null;
1058 Error_SyntaxError (yyToken);
1060 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1064 opt_constant_declarators
1066 | constant_declarators
1069 constant_declarators
1070 : constant_declarator
1072 current_field.AddDeclarator ((FieldDeclarator) $1);
1074 | constant_declarators constant_declarator
1076 current_field.AddDeclarator ((FieldDeclarator) $2);
1081 : COMMA IDENTIFIER constant_initializer
1083 var lt = (LocatedToken) $2;
1084 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1085 lbag.AddLocation ($$, GetLocation ($1));
1089 constant_initializer
1092 ++lexer.parsing_block;
1094 constant_initializer_expr
1096 --lexer.parsing_block;
1097 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1101 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1106 constant_initializer_expr
1107 : constant_expression
1114 member_type IDENTIFIER
1116 lexer.parsing_generic_declaration = false;
1118 FullNamedExpression type = (FullNamedExpression) $3;
1119 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1120 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1122 var lt = (LocatedToken) $4;
1123 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1124 current_type.AddField (current_field);
1127 opt_field_initializer
1128 opt_field_declarators
1132 current_field.DocComment = Lexer.consume_doc_comment ();
1133 Lexer.doc_state = XmlCommentState.Allowed;
1136 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1138 current_field = null;
1142 FIXED simple_type IDENTIFIER
1144 if (lang_version < LanguageVersion.ISO_2)
1145 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1147 var lt = (LocatedToken) $5;
1148 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1149 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1151 current_type.AddField (current_field);
1153 fixed_field_size opt_fixed_field_declarators SEMICOLON
1156 current_field.DocComment = Lexer.consume_doc_comment ();
1157 Lexer.doc_state = XmlCommentState.Allowed;
1160 current_field.Initializer = (ConstInitializer) $7;
1161 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1163 current_field = null;
1167 FIXED simple_type error
1170 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1174 opt_field_initializer
1178 ++lexer.parsing_block;
1179 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1180 start_block (GetLocation ($1));
1182 variable_initializer
1184 --lexer.parsing_block;
1185 current_field.Initializer = (Expression) $3;
1186 lbag.AppendToMember (current_field, GetLocation ($1));
1187 end_block (lexer.Location);
1188 current_local_parameters = null;
1192 opt_field_declarators
1200 current_field.AddDeclarator ((FieldDeclarator) $1);
1202 | field_declarators field_declarator
1204 current_field.AddDeclarator ((FieldDeclarator) $2);
1211 var lt = (LocatedToken) $2;
1212 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1213 lbag.AddLocation ($$, GetLocation ($1));
1215 | COMMA IDENTIFIER ASSIGN
1217 ++lexer.parsing_block;
1219 variable_initializer
1221 --lexer.parsing_block;
1222 var lt = (LocatedToken) $2;
1223 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1224 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1228 opt_fixed_field_declarators
1230 | fixed_field_declarators
1233 fixed_field_declarators
1234 : fixed_field_declarator
1236 current_field.AddDeclarator ((FieldDeclarator) $1);
1238 | fixed_field_declarators fixed_field_declarator
1240 current_field.AddDeclarator ((FieldDeclarator) $2);
1244 fixed_field_declarator
1245 : COMMA IDENTIFIER fixed_field_size
1247 var lt = (LocatedToken) $2;
1248 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1249 lbag.AddLocation ($$, GetLocation ($1));
1256 ++lexer.parsing_block;
1258 expression CLOSE_BRACKET
1260 --lexer.parsing_block;
1261 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1262 lbag.AddLocation ($$, GetLocation ($4));
1264 | OPEN_BRACKET error
1266 report.Error (443, lexer.Location, "Value or constant expected");
1271 variable_initializer
1276 // It has to be here for the parent to safely restore artificial block
1277 Error_SyntaxError (yyToken);
1286 Lexer.doc_state = XmlCommentState.NotAllowed;
1288 // Was added earlier in the case of body being eof for full ast
1290 method_body_expression_block
1292 Method method = (Method) $1;
1293 method.Block = (ToplevelBlock) $3;
1294 async_block = false;
1296 if (method.Block == null) {
1297 method.ParameterInfo.CheckParameters (method);
1299 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1300 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1301 method.GetSignatureForError ());
1304 if (current_container.Kind == MemberKind.Interface) {
1305 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1306 method.GetSignatureForError ());
1310 current_local_parameters = null;
1313 Lexer.doc_state = XmlCommentState.Allowed;
1321 method_declaration_name OPEN_PARENS
1323 valid_param_mod = ParameterModifierType.All;
1325 opt_formal_parameter_list CLOSE_PARENS
1327 valid_param_mod = 0;
1328 MemberName name = (MemberName) $4;
1329 current_local_parameters = (ParametersCompiled) $7;
1331 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1332 name, current_local_parameters, (Attributes) $1);
1334 current_type.AddMember (method);
1336 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1339 method.DocComment = Lexer.consume_doc_comment ();
1341 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1345 lexer.ConstraintsParsing = true;
1347 opt_type_parameter_constraints_clauses
1349 lexer.ConstraintsParsing = false;
1352 var method = (Method) $9;
1353 method.SetConstraints ((List<Constraints>) $10);
1363 lexer.parsing_generic_declaration = true;
1365 method_declaration_name
1368 lexer.parsing_generic_declaration = false;
1369 valid_param_mod = ParameterModifierType.All;
1371 opt_formal_parameter_list CLOSE_PARENS
1373 lexer.ConstraintsParsing = true;
1375 opt_type_parameter_constraints_clauses
1377 lexer.ConstraintsParsing = false;
1378 valid_param_mod = 0;
1380 MemberName name = (MemberName) $6;
1381 current_local_parameters = (ParametersCompiled) $9;
1383 var modifiers = (Modifiers) $2;
1384 modifiers |= Modifiers.PARTIAL;
1386 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1387 modifiers, name, current_local_parameters, (Attributes) $1);
1389 current_type.AddMember (method);
1391 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1394 method.SetConstraints ((List<Constraints>) $12);
1397 method.DocComment = Lexer.consume_doc_comment ();
1399 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1400 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1406 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1408 MemberName name = (MemberName) $5;
1409 report.Error (1585, name.Location,
1410 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1412 var method = Method.Create (current_type, (FullNamedExpression) $3,
1413 0, name, (ParametersCompiled) $7, (Attributes) $1);
1415 current_type.AddMember (method);
1417 current_local_parameters = (ParametersCompiled) $7;
1420 method.DocComment = Lexer.consume_doc_comment ();
1427 method_declaration_name error
1429 Error_SyntaxError (yyToken);
1430 current_local_parameters = ParametersCompiled.Undefined;
1432 MemberName name = (MemberName) $4;
1433 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1434 name, current_local_parameters, (Attributes) $1);
1436 current_type.AddMember (method);
1439 method.DocComment = Lexer.consume_doc_comment ();
1445 method_body_expression_block
1452 | SEMICOLON { $$ = null; }
1458 if (lang_version < LanguageVersion.V_6) {
1459 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1462 ++lexer.parsing_block;
1463 start_block (GetLocation ($1));
1465 expression SEMICOLON
1467 lexer.parsing_block = 0;
1468 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1469 var b = end_block (GetLocation ($4));
1470 b.IsCompilerGenerated = true;
1475 opt_formal_parameter_list
1476 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1477 | formal_parameter_list
1480 formal_parameter_list
1483 var pars_list = (List<Parameter>) $1;
1484 $$ = new ParametersCompiled (pars_list.ToArray ());
1486 | fixed_parameters COMMA parameter_array
1488 var pars_list = (List<Parameter>) $1;
1489 pars_list.Add ((Parameter) $3);
1491 $$ = new ParametersCompiled (pars_list.ToArray ());
1493 | fixed_parameters COMMA arglist_modifier
1495 var pars_list = (List<Parameter>) $1;
1496 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1497 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1499 | parameter_array COMMA error
1502 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1504 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1506 | fixed_parameters COMMA parameter_array COMMA error
1509 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1511 var pars_list = (List<Parameter>) $1;
1512 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1514 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1516 | arglist_modifier COMMA error
1518 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1520 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1522 | fixed_parameters COMMA ARGLIST COMMA error
1524 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1526 var pars_list = (List<Parameter>) $1;
1527 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1529 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1533 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1537 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1541 Error_SyntaxError (yyToken);
1542 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1549 parameters_bucket.Clear ();
1550 Parameter p = (Parameter) $1;
1551 parameters_bucket.Add (p);
1553 default_parameter_used = p.HasDefaultValue;
1554 $$ = parameters_bucket;
1556 | fixed_parameters COMMA fixed_parameter
1558 var pars = (List<Parameter>) $1;
1559 Parameter p = (Parameter) $3;
1561 if (p.HasExtensionMethodModifier)
1562 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1563 else if (!p.HasDefaultValue && default_parameter_used)
1564 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1566 default_parameter_used |= p.HasDefaultValue;
1569 lbag.AddLocation (p, GetLocation ($2));
1578 opt_parameter_modifier
1580 identifier_inside_body
1582 var lt = (LocatedToken) $4;
1583 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1586 opt_parameter_modifier
1588 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1590 var lt = (LocatedToken) $4;
1591 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1592 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1594 | attribute_sections error
1596 Error_SyntaxError (yyToken);
1597 Location l = GetLocation ($2);
1598 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1601 opt_parameter_modifier
1605 Error_SyntaxError (yyToken);
1606 Location l = GetLocation ($4);
1607 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1610 opt_parameter_modifier
1612 identifier_inside_body
1615 ++lexer.parsing_block;
1619 --lexer.parsing_block;
1620 if (lang_version <= LanguageVersion.V_3) {
1621 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1624 Parameter.Modifier mod = (Parameter.Modifier) $2;
1625 if (mod != Parameter.Modifier.NONE) {
1627 case Parameter.Modifier.REF:
1628 case Parameter.Modifier.OUT:
1629 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1630 Parameter.GetModifierSignature (mod));
1633 case Parameter.Modifier.This:
1634 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1635 Parameter.GetModifierSignature (mod));
1638 throw new NotImplementedException (mod.ToString ());
1641 mod = Parameter.Modifier.NONE;
1644 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1645 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1647 var lt = (LocatedToken) $4;
1648 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1649 lbag.AddLocation ($$, GetLocation ($5));
1652 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1656 opt_parameter_modifier
1657 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1658 | parameter_modifiers
1662 : parameter_modifier
1666 | parameter_modifiers parameter_modifier
1668 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1669 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1670 if (((Parameter.Modifier)$1 & p2) == p2) {
1671 Error_DuplicateParameterModifier (lexer.Location, p2);
1673 switch (mod & ~Parameter.Modifier.This) {
1674 case Parameter.Modifier.REF:
1675 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1677 case Parameter.Modifier.OUT:
1678 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1681 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1692 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1693 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1695 $$ = Parameter.Modifier.REF;
1699 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1700 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1702 $$ = Parameter.Modifier.OUT;
1706 if ((valid_param_mod & ParameterModifierType.This) == 0)
1707 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1709 if (lang_version <= LanguageVersion.ISO_2)
1710 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1712 $$ = Parameter.Modifier.This;
1717 : opt_attributes params_modifier type IDENTIFIER
1719 var lt = (LocatedToken) $4;
1720 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1722 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1724 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1726 var lt = (LocatedToken) $4;
1727 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1729 | opt_attributes params_modifier type error
1731 Error_SyntaxError (yyToken);
1733 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1740 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1741 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1743 | PARAMS parameter_modifier
1745 Parameter.Modifier mod = (Parameter.Modifier)$2;
1746 if ((mod & Parameter.Modifier.This) != 0) {
1747 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1749 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1752 | PARAMS params_modifier
1754 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1761 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1762 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1766 property_declaration
1770 member_declaration_name
1772 lexer.parsing_generic_declaration = false;
1774 tmpComment = Lexer.consume_doc_comment ();
1778 var type = (FullNamedExpression) $3;
1779 current_property = new Property (current_type, type, (Modifiers) $2,
1780 (MemberName) $4, (Attributes) $1);
1782 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1783 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1785 current_type.AddMember (current_property);
1786 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1788 lexer.PropertyParsing = true;
1790 accessor_declarations
1792 lexer.PropertyParsing = false;
1795 current_property.DocComment = ConsumeStoredComment ();
1799 lbag.AppendToMember (current_property, GetLocation ($10));
1800 lexer.parsing_modifiers = true;
1802 opt_property_initializer
1804 current_property = null;
1809 member_declaration_name
1811 lexer.parsing_generic_declaration = false;
1813 tmpComment = Lexer.consume_doc_comment ();
1814 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1818 var type = (FullNamedExpression) $3;
1819 var property = new Property (current_type, type, (Modifiers) $2,
1820 (MemberName) $4, (Attributes) $1);
1822 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1823 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1825 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1826 property.Get.Block = (ToplevelBlock) $6;
1828 current_type.AddMember (property);
1830 current_local_parameters = null;
1834 opt_property_initializer
1838 ++lexer.parsing_block;
1839 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1840 start_block (GetLocation ($1));
1842 property_initializer SEMICOLON
1844 --lexer.parsing_block;
1845 ((Property)current_property).Initializer = (Expression) $3;
1846 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1847 end_block (GetLocation ($4));
1848 current_local_parameters = null;
1852 property_initializer
1858 : opt_attributes opt_modifiers
1859 member_type indexer_declaration_name OPEN_BRACKET
1861 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1863 opt_formal_parameter_list CLOSE_BRACKET
1865 valid_param_mod = 0;
1866 var type = (FullNamedExpression) $3;
1867 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1869 current_property = indexer;
1871 current_type.AddIndexer (indexer);
1872 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1874 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1875 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1877 if (indexer.ParameterInfo.IsEmpty) {
1878 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1882 tmpComment = Lexer.consume_doc_comment ();
1883 Lexer.doc_state = XmlCommentState.Allowed;
1886 lexer.PropertyParsing = true;
1887 current_local_parameters = (ParametersCompiled) $7;
1891 lexer.PropertyParsing = false;
1892 current_local_parameters = null;
1894 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1895 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1898 current_property.DocComment = ConsumeStoredComment ();
1900 current_property = null;
1905 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1907 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1911 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1912 current_property.Get.Block = (ToplevelBlock) $1;
1916 accessor_declarations
1917 : get_accessor_declaration
1918 | get_accessor_declaration accessor_declarations
1919 | set_accessor_declaration
1920 | set_accessor_declaration accessor_declarations
1923 if (yyToken == Token.CLOSE_BRACE) {
1924 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1926 if (yyToken == Token.SEMICOLON)
1927 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1929 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1934 get_accessor_declaration
1935 : opt_attributes opt_modifiers GET
1937 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1938 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1941 if (current_property.Get != null) {
1942 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1945 if (current_property is Indexer) {
1946 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1947 (Attributes) $1, GetLocation ($3));
1949 current_property.Get = new Property.GetMethod (current_property,
1950 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1953 current_local_parameters = current_property.Get.ParameterInfo;
1954 lbag.AddMember (current_property.Get, mod_locations);
1955 lexer.PropertyParsing = false;
1960 current_property.Get.Block = (ToplevelBlock) $5;
1962 if (current_container.Kind == MemberKind.Interface) {
1963 report.Error (531, current_property.Get.Block.StartLocation,
1964 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1968 current_local_parameters = null;
1969 lexer.PropertyParsing = true;
1972 if (Lexer.doc_state == XmlCommentState.Error)
1973 Lexer.doc_state = XmlCommentState.NotAllowed;
1977 set_accessor_declaration
1978 : opt_attributes opt_modifiers SET
1980 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1981 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1984 if (current_property.Set != null) {
1985 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1988 if (current_property is Indexer) {
1989 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1990 ParametersCompiled.MergeGenerated (compiler,
1991 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1992 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1994 (Attributes) $1, GetLocation ($3));
1996 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1997 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1998 (Attributes) $1, GetLocation ($3));
2001 current_local_parameters = current_property.Set.ParameterInfo;
2002 lbag.AddMember (current_property.Set, mod_locations);
2003 lexer.PropertyParsing = false;
2008 current_property.Set.Block = (ToplevelBlock) $5;
2010 if (current_container.Kind == MemberKind.Interface) {
2011 report.Error (531, current_property.Set.Block.StartLocation,
2012 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2016 current_local_parameters = null;
2017 lexer.PropertyParsing = true;
2020 && Lexer.doc_state == XmlCommentState.Error)
2021 Lexer.doc_state = XmlCommentState.NotAllowed;
2034 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2039 interface_declaration
2046 type_declaration_name
2048 lexer.ConstraintsParsing = true;
2049 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2050 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2053 opt_type_parameter_constraints_clauses
2055 lexer.ConstraintsParsing = false;
2058 current_container.SetConstraints ((List<Constraints>) $9);
2061 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2062 Lexer.doc_state = XmlCommentState.Allowed;
2065 lexer.parsing_modifiers = true;
2067 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2069 --lexer.parsing_declaration;
2071 Lexer.doc_state = XmlCommentState.Allowed;
2076 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2078 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2080 $$ = pop_current_class ();
2082 | opt_attributes opt_modifiers opt_partial INTERFACE error
2084 Error_SyntaxError (yyToken);
2088 opt_interface_member_declarations
2090 | interface_member_declarations
2093 interface_member_declarations
2094 : interface_member_declaration
2096 lexer.parsing_modifiers = true;
2097 lexer.parsing_block = 0;
2099 | interface_member_declarations interface_member_declaration
2101 lexer.parsing_modifiers = true;
2102 lexer.parsing_block = 0;
2106 interface_member_declaration
2107 : constant_declaration
2109 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2113 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2115 | method_declaration
2116 | property_declaration
2118 | indexer_declaration
2119 | operator_declaration
2121 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2123 | constructor_declaration
2125 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2129 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2133 operator_declaration
2134 : opt_attributes opt_modifiers operator_declarator
2137 method_body_expression_block
2139 OperatorDeclaration decl = (OperatorDeclaration) $3;
2141 Operator op = new Operator (
2142 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2143 current_local_parameters,
2144 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2146 if (op.Block == null)
2147 op.ParameterInfo.CheckParameters (op);
2150 op.DocComment = tmpComment;
2151 Lexer.doc_state = XmlCommentState.Allowed;
2154 // Note again, checking is done in semantic analysis
2155 current_type.AddOperator (op);
2157 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2160 current_local_parameters = null;
2165 : type_expression_or_array
2168 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2169 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2174 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2176 valid_param_mod = ParameterModifierType.DefaultValue;
2178 opt_formal_parameter_list CLOSE_PARENS
2180 valid_param_mod = 0;
2182 Location loc = GetLocation ($2);
2183 Operator.OpType op = (Operator.OpType) $3;
2184 current_local_parameters = (ParametersCompiled)$6;
2186 int p_count = current_local_parameters.Count;
2188 if (op == Operator.OpType.Addition)
2189 op = Operator.OpType.UnaryPlus;
2190 else if (op == Operator.OpType.Subtraction)
2191 op = Operator.OpType.UnaryNegation;
2194 if (IsUnaryOperator (op)) {
2196 report.Error (1020, loc, "Overloadable binary operator expected");
2197 } else if (p_count != 1) {
2198 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2199 Operator.GetName (op));
2203 report.Error (1019, loc, "Overloadable unary operator expected");
2204 } else if (p_count != 2) {
2205 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2206 Operator.GetName (op));
2211 tmpComment = Lexer.consume_doc_comment ();
2212 Lexer.doc_state = XmlCommentState.NotAllowed;
2215 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2216 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2218 | conversion_operator_declarator
2221 overloadable_operator
2223 : BANG { $$ = Operator.OpType.LogicalNot; }
2224 | TILDE { $$ = Operator.OpType.OnesComplement; }
2225 | OP_INC { $$ = Operator.OpType.Increment; }
2226 | OP_DEC { $$ = Operator.OpType.Decrement; }
2227 | TRUE { $$ = Operator.OpType.True; }
2228 | FALSE { $$ = Operator.OpType.False; }
2229 // Unary and binary:
2230 | PLUS { $$ = Operator.OpType.Addition; }
2231 | MINUS { $$ = Operator.OpType.Subtraction; }
2233 | STAR { $$ = Operator.OpType.Multiply; }
2234 | DIV { $$ = Operator.OpType.Division; }
2235 | PERCENT { $$ = Operator.OpType.Modulus; }
2236 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2237 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2238 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2239 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2240 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2241 | OP_EQ { $$ = Operator.OpType.Equality; }
2242 | OP_NE { $$ = Operator.OpType.Inequality; }
2243 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2244 | OP_LT { $$ = Operator.OpType.LessThan; }
2245 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2246 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2249 conversion_operator_declarator
2250 : IMPLICIT OPERATOR type OPEN_PARENS
2252 valid_param_mod = ParameterModifierType.DefaultValue;
2254 opt_formal_parameter_list CLOSE_PARENS
2256 valid_param_mod = 0;
2258 Location loc = GetLocation ($2);
2259 current_local_parameters = (ParametersCompiled)$6;
2261 if (current_local_parameters.Count != 1) {
2262 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2266 tmpComment = Lexer.consume_doc_comment ();
2267 Lexer.doc_state = XmlCommentState.NotAllowed;
2270 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2271 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2273 | EXPLICIT OPERATOR type OPEN_PARENS
2275 valid_param_mod = ParameterModifierType.DefaultValue;
2277 opt_formal_parameter_list CLOSE_PARENS
2279 valid_param_mod = 0;
2281 Location loc = GetLocation ($2);
2282 current_local_parameters = (ParametersCompiled)$6;
2284 if (current_local_parameters.Count != 1) {
2285 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2289 tmpComment = Lexer.consume_doc_comment ();
2290 Lexer.doc_state = XmlCommentState.NotAllowed;
2293 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2294 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2298 Error_SyntaxError (yyToken);
2299 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2300 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2304 Error_SyntaxError (yyToken);
2305 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2306 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2310 constructor_declaration
2311 : constructor_declarator
2314 Constructor c = (Constructor) $1;
2315 c.Block = (ToplevelBlock) $2;
2318 c.DocComment = ConsumeStoredComment ();
2320 current_local_parameters = null;
2322 Lexer.doc_state = XmlCommentState.Allowed;
2326 constructor_declarator
2332 tmpComment = Lexer.consume_doc_comment ();
2333 Lexer.doc_state = XmlCommentState.Allowed;
2336 valid_param_mod = ParameterModifierType.All;
2338 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2340 valid_param_mod = 0;
2341 current_local_parameters = (ParametersCompiled) $6;
2343 var lt = (LocatedToken) $3;
2344 var mods = (Modifiers) $2;
2345 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2347 if (lt.Value != current_container.MemberName.Name) {
2348 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2349 } else if ((mods & Modifiers.STATIC) != 0) {
2350 if ((mods & Modifiers.AccessibilityMask) != 0){
2351 report.Error (515, c.Location,
2352 "`{0}': static constructor cannot have an access modifier",
2353 c.GetSignatureForError ());
2357 current_type.AddConstructor (c);
2358 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2362 // start block here, so possible anonymous methods inside
2363 // constructor initializer can get correct parent block
2365 start_block (lexer.Location);
2367 opt_constructor_initializer
2370 var c = (Constructor) $8;
2371 c.Initializer = (ConstructorInitializer) $9;
2374 report.Error (514, c.Location,
2375 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2376 c.GetSignatureForError ());
2386 | SEMICOLON { current_block = null; $$ = null; }
2389 opt_constructor_initializer
2391 | constructor_initializer
2394 constructor_initializer
2395 : COLON BASE OPEN_PARENS
2397 ++lexer.parsing_block;
2399 opt_argument_list CLOSE_PARENS
2401 --lexer.parsing_block;
2402 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2403 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2405 | COLON THIS OPEN_PARENS
2407 ++lexer.parsing_block;
2409 opt_argument_list CLOSE_PARENS
2411 --lexer.parsing_block;
2412 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2413 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2417 Error_SyntaxError (yyToken);
2418 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2419 lbag.AddLocation ($$, GetLocation ($1));
2423 Error_SyntaxError (yyToken);
2428 destructor_declaration
2429 : opt_attributes opt_modifiers TILDE
2432 tmpComment = Lexer.consume_doc_comment ();
2433 Lexer.doc_state = XmlCommentState.NotAllowed;
2436 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2438 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2440 var lt = (LocatedToken) $5;
2441 if (lt.Value != current_container.MemberName.Name){
2442 report.Error (574, lt.Location, "Name of destructor must match name of class");
2443 } else if (current_container.Kind != MemberKind.Class){
2444 report.Error (575, lt.Location, "Only class types can contain destructor");
2447 Destructor d = new Destructor (current_type, (Modifiers) $2,
2448 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2450 d.DocComment = ConsumeStoredComment ();
2452 d.Block = (ToplevelBlock) $8;
2453 current_type.AddMember (d);
2454 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2456 current_local_parameters = null;
2463 EVENT type member_declaration_name
2465 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2466 current_type.AddMember (current_event_field);
2468 if (current_event_field.MemberName.ExplicitInterface != null) {
2469 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2470 current_event_field.GetSignatureForError ());
2473 $$ = current_event_field;
2475 opt_event_initializer
2476 opt_event_declarators
2480 current_event_field.DocComment = Lexer.consume_doc_comment ();
2481 Lexer.doc_state = XmlCommentState.Allowed;
2484 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2485 current_event_field = null;
2489 EVENT type member_declaration_name
2492 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2493 current_type.AddMember (current_event);
2494 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2496 lexer.EventParsing = true;
2498 event_accessor_declarations
2500 if (current_container.Kind == MemberKind.Interface)
2501 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2503 lexer.EventParsing = false;
2508 current_event.DocComment = Lexer.consume_doc_comment ();
2509 Lexer.doc_state = XmlCommentState.Allowed;
2512 lbag.AppendToMember (current_event, GetLocation ($9));
2513 current_event = null;
2514 current_local_parameters = null;
2520 Error_SyntaxError (yyToken);
2522 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2526 opt_event_initializer
2530 ++lexer.parsing_block;
2532 event_variable_initializer
2534 --lexer.parsing_block;
2535 current_event_field.Initializer = (Expression) $3;
2539 opt_event_declarators
2547 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2549 | event_declarators event_declarator
2551 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2558 var lt = (LocatedToken) $2;
2559 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2560 lbag.AddLocation ($$, GetLocation ($1));
2562 | COMMA IDENTIFIER ASSIGN
2564 ++lexer.parsing_block;
2566 event_variable_initializer
2568 --lexer.parsing_block;
2569 var lt = (LocatedToken) $2;
2570 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2571 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2575 event_variable_initializer
2577 if (current_container.Kind == MemberKind.Interface) {
2578 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2579 current_event_field.GetSignatureForError ());
2582 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2583 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2584 current_event_field.GetSignatureForError ());
2587 variable_initializer
2593 event_accessor_declarations
2594 : add_accessor_declaration remove_accessor_declaration
2595 | remove_accessor_declaration add_accessor_declaration
2596 | add_accessor_declaration
2598 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2599 current_event.GetSignatureForError ());
2601 | remove_accessor_declaration
2603 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2604 current_event.GetSignatureForError ());
2608 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2613 add_accessor_declaration
2614 : opt_attributes opt_modifiers ADD
2616 if ($2 != ModifierNone) {
2617 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2620 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2621 current_local_parameters = current_event.Add.ParameterInfo;
2623 lbag.AddMember (current_event.Add, mod_locations);
2624 lexer.EventParsing = false;
2626 event_accessor_block
2628 lexer.EventParsing = true;
2630 current_event.Add.Block = (ToplevelBlock) $5;
2632 if (current_container.Kind == MemberKind.Interface) {
2633 report.Error (531, current_event.Add.Block.StartLocation,
2634 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2637 current_local_parameters = null;
2641 remove_accessor_declaration
2642 : opt_attributes opt_modifiers REMOVE
2644 if ($2 != ModifierNone) {
2645 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2648 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2649 current_local_parameters = current_event.Remove.ParameterInfo;
2651 lbag.AddMember (current_event.Remove, mod_locations);
2652 lexer.EventParsing = false;
2654 event_accessor_block
2656 lexer.EventParsing = true;
2658 current_event.Remove.Block = (ToplevelBlock) $5;
2660 if (current_container.Kind == MemberKind.Interface) {
2661 report.Error (531, current_event.Remove.Block.StartLocation,
2662 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2665 current_local_parameters = null;
2669 event_accessor_block
2672 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2678 attributes_without_members
2679 : attribute_sections CLOSE_BRACE
2681 current_type.UnattachedAttributes = (Attributes) $1;
2682 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2683 lexer.putback ('}');
2687 // For full ast try to recover incomplete ambiguous member
2688 // declaration in form on class X { public int }
2690 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2692 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2694 lexer.putback ('}');
2696 lexer.parsing_generic_declaration = false;
2697 FullNamedExpression type = (FullNamedExpression) $3;
2698 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2699 current_type.AddField (current_field);
2707 ENUM type_declaration_name
2711 enumTypeComment = Lexer.consume_doc_comment ();
2716 Lexer.doc_state = XmlCommentState.Allowed;
2718 MemberName name = (MemberName) $4;
2719 if (name.IsGeneric) {
2720 report.Error (1675, name.Location, "Enums cannot have type parameters");
2723 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2725 opt_enum_member_declarations
2727 lexer.parsing_modifiers = true;
2729 // here will be evaluated after CLOSE_BLACE is consumed.
2731 Lexer.doc_state = XmlCommentState.Allowed;
2733 CLOSE_BRACE opt_semicolon
2736 current_container.DocComment = enumTypeComment;
2738 --lexer.parsing_declaration;
2741 // em.DocComment = ev.DocComment;
2743 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2744 $$ = pop_current_class ();
2752 var te = $2 as TypeExpression;
2753 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2754 Enum.Error_1008 (GetLocation ($2), report);
2760 Error_TypeExpected (GetLocation ($1));
2765 opt_enum_member_declarations
2767 | enum_member_declarations
2768 | enum_member_declarations COMMA
2770 lbag.AddLocation ($1, GetLocation ($2));
2774 enum_member_declarations
2775 : enum_member_declaration
2776 | enum_member_declarations COMMA enum_member_declaration
2778 lbag.AddLocation ($1, GetLocation ($2));
2783 enum_member_declaration
2784 : opt_attributes IDENTIFIER
2786 var lt = (LocatedToken) $2;
2787 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2788 ((Enum) current_type).AddEnumMember (em);
2791 em.DocComment = Lexer.consume_doc_comment ();
2792 Lexer.doc_state = XmlCommentState.Allowed;
2797 | opt_attributes IDENTIFIER
2799 ++lexer.parsing_block;
2801 tmpComment = Lexer.consume_doc_comment ();
2802 Lexer.doc_state = XmlCommentState.NotAllowed;
2805 ASSIGN constant_expression
2807 --lexer.parsing_block;
2809 var lt = (LocatedToken) $2;
2810 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2811 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2812 ((Enum) current_type).AddEnumMember (em);
2815 em.DocComment = ConsumeStoredComment ();
2819 | opt_attributes IDENTIFIER error
2821 Error_SyntaxError (yyToken);
2823 var lt = (LocatedToken) $2;
2824 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2825 ((Enum) current_type).AddEnumMember (em);
2828 em.DocComment = Lexer.consume_doc_comment ();
2829 Lexer.doc_state = XmlCommentState.Allowed;
2834 | attributes_without_members
2837 delegate_declaration
2841 member_type type_declaration_name
2844 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2846 opt_formal_parameter_list CLOSE_PARENS
2848 valid_param_mod = 0;
2850 ParametersCompiled p = (ParametersCompiled) $8;
2852 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2854 p.CheckParameters (del);
2856 current_container.AddTypeContainer (del);
2858 current_delegate = del;
2859 lexer.ConstraintsParsing = true;
2861 opt_type_parameter_constraints_clauses
2863 lexer.ConstraintsParsing = false;
2868 current_delegate.DocComment = Lexer.consume_doc_comment ();
2869 Lexer.doc_state = XmlCommentState.Allowed;
2873 current_delegate.SetConstraints ((List<Constraints>) $11);
2874 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2876 $$ = current_delegate;
2878 current_delegate = null;
2886 if (lang_version < LanguageVersion.ISO_2)
2887 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2889 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2893 namespace_or_type_expr
2895 | qualified_alias_member IDENTIFIER opt_type_argument_list
2897 var lt1 = (LocatedToken) $1;
2898 var lt2 = (LocatedToken) $2;
2900 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2901 lbag.AddLocation ($$, GetLocation ($2));
2903 | qualified_alias_member IDENTIFIER generic_dimension
2905 var lt1 = (LocatedToken) $1;
2906 var lt2 = (LocatedToken) $2;
2908 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2909 lbag.AddLocation ($$, GetLocation ($2));
2915 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2917 var lt = (LocatedToken) $3;
2918 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2919 lbag.AddLocation ($$, GetLocation ($2));
2921 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2923 var lt = (LocatedToken) $3;
2924 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2925 lbag.AddLocation ($$, GetLocation ($2));
2930 : IDENTIFIER opt_type_argument_list
2932 var lt = (LocatedToken) $1;
2933 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2935 | IDENTIFIER generic_dimension
2937 var lt = (LocatedToken) $1;
2938 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2943 // Generics arguments (any type, without attributes)
2945 opt_type_argument_list
2947 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2949 if (lang_version < LanguageVersion.ISO_2)
2950 FeatureIsNotAvailable (GetLocation ($1), "generics");
2954 | OP_GENERICS_LT error
2956 Error_TypeExpected (lexer.Location);
2957 $$ = new TypeArguments ();
2964 TypeArguments type_args = new TypeArguments ();
2965 type_args.Add ((FullNamedExpression) $1);
2968 | type_arguments COMMA type
2970 TypeArguments type_args = (TypeArguments) $1;
2971 type_args.Add ((FullNamedExpression) $3);
2977 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2979 type_declaration_name
2982 lexer.parsing_generic_declaration = true;
2984 opt_type_parameter_list
2986 lexer.parsing_generic_declaration = false;
2987 var lt = (LocatedToken) $1;
2988 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2992 member_declaration_name
2993 : method_declaration_name
2995 MemberName mn = (MemberName)$1;
2996 if (mn.TypeParameters != null)
2997 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2998 mn.GetSignatureForError ()));
3002 method_declaration_name
3003 : type_declaration_name
3004 | explicit_interface IDENTIFIER opt_type_parameter_list
3006 lexer.parsing_generic_declaration = false;
3007 var lt = (LocatedToken) $2;
3008 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3012 indexer_declaration_name
3015 lexer.parsing_generic_declaration = false;
3016 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3018 | explicit_interface THIS
3020 lexer.parsing_generic_declaration = false;
3021 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3026 : IDENTIFIER opt_type_argument_list DOT
3028 var lt = (LocatedToken) $1;
3029 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3030 lbag.AddLocation ($$, GetLocation ($3));
3032 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3034 var lt1 = (LocatedToken) $1;
3035 var lt2 = (LocatedToken) $2;
3037 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3038 lbag.AddLocation ($$, GetLocation ($4));
3040 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3042 var lt = (LocatedToken) $2;
3043 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3044 lbag.AddLocation ($$, GetLocation ($4));
3048 opt_type_parameter_list
3050 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3052 if (lang_version < LanguageVersion.ISO_2)
3053 FeatureIsNotAvailable (GetLocation ($1), "generics");
3056 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3063 var tparams = new TypeParameters ();
3064 tparams.Add ((TypeParameter)$1);
3067 | type_parameters COMMA type_parameter
3069 var tparams = (TypeParameters) $1;
3070 tparams.Add ((TypeParameter)$3);
3072 lbag.AddLocation ($3, GetLocation ($3));
3077 : opt_attributes opt_type_parameter_variance IDENTIFIER
3079 var lt = (LocatedToken)$3;
3080 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3084 if (GetTokenName (yyToken) == "type")
3085 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3087 Error_SyntaxError (yyToken);
3089 $$ = new TypeParameter (MemberName.Null, null, null);
3094 // All types where void is allowed
3097 : type_expression_or_array
3100 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3107 lexer.parsing_generic_declaration = true;
3112 // A type which does not allow `void' to be used
3115 : type_expression_or_array
3118 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3119 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3127 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3128 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3133 : type_expression_or_array
3136 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3137 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3141 type_expression_or_array
3143 | type_expression rank_specifiers
3145 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3150 : namespace_or_type_expr opt_nullable
3153 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3155 var sn = $1 as SimpleName;
3156 if (sn != null && sn.Name == "var")
3157 $$ = new VarExpr (sn.Location);
3162 | namespace_or_type_expr pointer_stars
3164 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3166 | builtin_types opt_nullable
3169 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3171 | builtin_types pointer_stars
3173 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3175 | VOID pointer_stars
3177 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3184 var types = new List<FullNamedExpression> (2);
3185 types.Add ((FullNamedExpression) $1);
3188 | type_list COMMA base_type_name
3190 var types = (List<FullNamedExpression>) $1;
3191 types.Add ((FullNamedExpression) $3);
3199 if ($1 is ComposedCast) {
3200 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3207 * replaces all the productions for isolating the various
3208 * simple types, but we need this to reuse it easily in variable_type
3211 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3212 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3213 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3214 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3215 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3216 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3221 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3222 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3223 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3224 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3225 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3226 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3227 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3228 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3229 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3233 // Expressions, section 7.5
3238 : primary_expression_or_type
3240 | array_creation_expression
3241 | parenthesized_expression
3242 | default_value_expression
3243 | invocation_expression
3247 | post_increment_expression
3248 | post_decrement_expression
3249 | object_or_delegate_creation_expression
3250 | anonymous_type_expression
3253 | checked_expression
3254 | unchecked_expression
3255 | pointer_member_access
3256 | anonymous_method_expression
3257 | undocumented_expressions
3260 primary_expression_or_type
3262 | IDENTIFIER GENERATE_COMPLETION {
3263 var lt = (LocatedToken) $1;
3264 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3272 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3276 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3277 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3282 // Here is the trick, tokenizer may think that parens is a special but
3283 // parser is interested in open parens only, so we merge them.
3284 // Consider: if (a)foo ();
3292 // Use this production to accept closing parenthesis or
3293 // performing completion
3297 | COMPLETE_COMPLETION
3301 parenthesized_expression
3302 : OPEN_PARENS expression CLOSE_PARENS
3304 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3305 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3307 | OPEN_PARENS expression COMPLETE_COMPLETION
3309 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3314 : primary_expression DOT identifier_inside_body opt_type_argument_list
3316 var lt = (LocatedToken) $3;
3317 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3318 lbag.AddLocation ($$, GetLocation ($2));
3320 | primary_expression DOT identifier_inside_body generic_dimension
3322 var lt = (LocatedToken) $3;
3323 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3324 lbag.AddLocation ($$, GetLocation ($2));
3326 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3328 if (lang_version < LanguageVersion.V_6)
3329 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3331 var lt = (LocatedToken) $4;
3332 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3333 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3335 | builtin_types DOT identifier_inside_body opt_type_argument_list
3337 var lt = (LocatedToken) $3;
3338 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3339 lbag.AddLocation ($$, GetLocation ($2));
3341 | BASE DOT identifier_inside_body opt_type_argument_list
3343 var lt = (LocatedToken) $3;
3344 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3345 lbag.AddLocation ($$, GetLocation ($2));
3347 | AWAIT DOT identifier_inside_body opt_type_argument_list
3349 var lt = (LocatedToken) $3;
3350 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3351 lbag.AddLocation ($$, GetLocation ($2));
3353 | qualified_alias_member identifier_inside_body opt_type_argument_list
3355 var lt1 = (LocatedToken) $1;
3356 var lt2 = (LocatedToken) $2;
3358 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3359 lbag.AddLocation ($$, GetLocation ($2));
3361 | qualified_alias_member identifier_inside_body generic_dimension
3363 var lt1 = (LocatedToken) $1;
3364 var lt2 = (LocatedToken) $2;
3366 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3367 lbag.AddLocation ($$, GetLocation ($2));
3369 | primary_expression DOT GENERATE_COMPLETION {
3370 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3372 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3373 var lt = (LocatedToken) $3;
3374 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3376 | builtin_types DOT GENERATE_COMPLETION
3378 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3380 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3381 var lt = (LocatedToken) $3;
3382 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3386 invocation_expression
3387 : primary_expression open_parens_any opt_argument_list close_parens
3389 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3390 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3392 | primary_expression open_parens_any argument_list error
3394 Error_SyntaxError (yyToken);
3396 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3397 lbag.AddLocation ($$, GetLocation ($2));
3399 | primary_expression open_parens_any error
3401 Error_SyntaxError (yyToken);
3403 $$ = new Invocation ((Expression) $1, null);
3404 lbag.AddLocation ($$, GetLocation ($2));
3408 opt_object_or_collection_initializer
3409 : /* empty */ { $$ = null; }
3410 | object_or_collection_initializer
3413 object_or_collection_initializer
3414 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3417 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3419 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3421 lbag.AddLocation ($$, GetLocation ($3));
3423 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3425 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3426 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3430 opt_member_initializer_list
3431 : /* empty */ { $$ = null; }
3432 | member_initializer_list
3438 member_initializer_list
3439 : member_initializer
3441 var a = new List<Expression> ();
3442 a.Add ((Expression) $1);
3445 | member_initializer_list COMMA member_initializer
3447 var a = (List<Expression>)$1;
3448 a.Add ((Expression) $3);
3451 | member_initializer_list error {
3452 Error_SyntaxError (yyToken);
3458 : IDENTIFIER ASSIGN initializer_value
3460 var lt = (LocatedToken) $1;
3461 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3462 lbag.AddLocation ($$, GetLocation ($2));
3464 | AWAIT ASSIGN initializer_value
3466 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3467 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3468 lbag.AddLocation ($$, GetLocation ($2));
3470 | GENERATE_COMPLETION
3472 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3474 | non_assignment_expression opt_COMPLETE_COMPLETION {
3475 CompletionSimpleName csn = $1 as CompletionSimpleName;
3477 $$ = new CollectionElementInitializer ((Expression)$1);
3479 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3481 | OPEN_BRACE expression_list CLOSE_BRACE
3484 $$ = new CollectionElementInitializer (GetLocation ($1));
3486 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3488 lbag.AddLocation ($$, GetLocation ($3));
3490 | OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET ASSIGN initializer_value
3492 if (lang_version < LanguageVersion.V_6)
3493 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3495 $$ = new DictionaryElementInitializer ((List<Expression>)$2, (Expression) $5, GetLocation ($1));
3496 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3498 | OPEN_BRACE CLOSE_BRACE
3500 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3501 $$ = new CollectionElementInitializer (GetLocation ($1));
3502 lbag.AddLocation ($$, GetLocation ($2));
3508 | object_or_collection_initializer
3512 : /* empty */ { $$ = null; }
3517 : argument_or_named_argument
3519 Arguments list = new Arguments (4);
3520 list.Add ((Argument) $1);
3523 | argument_list COMMA argument
3525 Arguments list = (Arguments) $1;
3526 if (list [list.Count - 1] is NamedArgument)
3527 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3529 list.Add ((Argument) $3);
3532 | argument_list COMMA named_argument
3534 Arguments list = (Arguments) $1;
3535 NamedArgument a = (NamedArgument) $3;
3536 for (int i = 0; i < list.Count; ++i) {
3537 NamedArgument na = list [i] as NamedArgument;
3538 if (na != null && na.Name == a.Name)
3539 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3546 | argument_list COMMA error
3548 if (lexer.putback_char == -1)
3549 lexer.putback (')'); // TODO: Wrong but what can I do
3550 Error_SyntaxError (yyToken);
3555 report.Error (839, GetLocation ($1), "An argument is missing");
3563 $$ = new Argument ((Expression) $1);
3565 | non_simple_argument
3568 argument_or_named_argument
3574 : REF variable_reference
3576 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3577 lbag.AddLocation ($$, GetLocation ($1));
3579 | OUT variable_reference
3581 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3582 lbag.AddLocation ($$, GetLocation ($1));
3584 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3586 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3587 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3589 | ARGLIST OPEN_PARENS CLOSE_PARENS
3591 $$ = new Argument (new Arglist (GetLocation ($1)));
3592 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3601 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3603 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3604 lbag.AddLocation ($$, GetLocation ($4));
3606 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3608 if (lang_version < LanguageVersion.V_6)
3609 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3611 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3612 ConditionalAccess = true
3615 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3617 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3619 Error_SyntaxError (yyToken);
3620 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3622 | primary_expression OPEN_BRACKET_EXPR error
3624 Error_SyntaxError (yyToken);
3625 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3630 : expression_or_error
3632 var list = new List<Expression> (4);
3633 list.Add ((Expression) $1);
3636 | expression_list COMMA expression_or_error
3638 var list = (List<Expression>) $1;
3639 list.Add ((Expression) $3);
3644 expression_list_arguments
3645 : expression_list_argument
3647 Arguments args = new Arguments (4);
3648 args.Add ((Argument) $1);
3651 | expression_list_arguments COMMA expression_list_argument
3653 Arguments args = (Arguments) $1;
3654 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3655 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3657 args.Add ((Argument) $3);
3662 expression_list_argument
3665 $$ = new Argument ((Expression) $1);
3673 $$ = new This (GetLocation ($1));
3678 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3680 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3681 lbag.AddLocation ($$, GetLocation ($4));
3683 | BASE OPEN_BRACKET error
3685 Error_SyntaxError (yyToken);
3686 $$ = new ElementAccess (null, null, GetLocation ($2));
3690 post_increment_expression
3691 : primary_expression OP_INC
3693 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3697 post_decrement_expression
3698 : primary_expression OP_DEC
3700 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3704 object_or_delegate_creation_expression
3705 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3708 if (lang_version <= LanguageVersion.ISO_2)
3709 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3711 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3713 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3716 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3718 | NEW new_expr_type object_or_collection_initializer
3720 if (lang_version <= LanguageVersion.ISO_2)
3721 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3723 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3727 array_creation_expression
3728 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3730 opt_array_initializer
3732 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3733 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3734 Next = (ComposedTypeSpecifier) $6
3735 }, (ArrayInitializer) $7, GetLocation ($1));
3736 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3738 | NEW new_expr_type rank_specifiers opt_array_initializer
3741 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3743 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3745 | NEW rank_specifier array_initializer
3747 if (lang_version <= LanguageVersion.ISO_2)
3748 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3750 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3752 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3754 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3755 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3757 | NEW new_expr_type error
3759 Error_SyntaxError (yyToken);
3760 // It can be any of new expression, create the most common one
3761 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3767 ++lexer.parsing_type;
3771 --lexer.parsing_type;
3776 anonymous_type_expression
3777 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3779 if (lang_version <= LanguageVersion.ISO_2)
3780 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3782 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3784 // TODO: lbag comma location
3785 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3787 | NEW OPEN_BRACE GENERATE_COMPLETION
3789 $$ = new EmptyCompletion ();
3793 anonymous_type_parameters_opt_comma
3794 : anonymous_type_parameters_opt
3795 | anonymous_type_parameters COMMA
3798 anonymous_type_parameters_opt
3800 | anonymous_type_parameters
3803 anonymous_type_parameters
3804 : anonymous_type_parameter
3806 var a = new List<AnonymousTypeParameter> (4);
3807 a.Add ((AnonymousTypeParameter) $1);
3810 | anonymous_type_parameters COMMA anonymous_type_parameter
3812 var a = (List<AnonymousTypeParameter>) $1;
3813 a.Add ((AnonymousTypeParameter) $3);
3816 | COMPLETE_COMPLETION
3818 $$ = new EmptyCompletion ();
3820 | anonymous_type_parameter COMPLETE_COMPLETION
3826 anonymous_type_parameter
3827 : identifier_inside_body ASSIGN variable_initializer
3829 var lt = (LocatedToken)$1;
3830 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3831 lbag.AddLocation ($$, GetLocation ($2));
3833 | identifier_inside_body
3835 var lt = (LocatedToken)$1;
3836 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3837 lt.Value, lt.Location);
3841 MemberAccess ma = (MemberAccess) $1;
3842 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3846 report.Error (746, lexer.Location,
3847 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3859 | rank_specifier rank_specifiers
3861 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3867 : OPEN_BRACKET CLOSE_BRACKET
3869 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3870 lbag.AddLocation ($$, GetLocation ($2));
3872 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3874 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3875 lbag.AddLocation ($$, GetLocation ($3));
3884 | dim_separators COMMA
3886 $$ = ((int) $1) + 1;
3890 opt_array_initializer
3902 : OPEN_BRACE CLOSE_BRACE
3904 var ai = new ArrayInitializer (0, GetLocation ($1));
3905 ai.VariableDeclaration = current_variable;
3906 lbag.AddLocation (ai, GetLocation ($2));
3909 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3911 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3912 ai.VariableDeclaration = current_variable;
3914 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3916 lbag.AddLocation (ai, GetLocation ($4));
3922 variable_initializer_list
3923 : variable_initializer
3925 var list = new List<Expression> (4);
3926 list.Add ((Expression) $1);
3929 | variable_initializer_list COMMA variable_initializer
3931 var list = (List<Expression>) $1;
3932 list.Add ((Expression) $3);
3938 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
3940 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
3941 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3945 typeof_type_expression
3949 Error_TypeExpected (lexer.Location);
3957 if (lang_version < LanguageVersion.ISO_2)
3958 FeatureIsNotAvailable (GetLocation ($1), "generics");
3964 qualified_alias_member
3965 : IDENTIFIER DOUBLE_COLON
3967 var lt = (LocatedToken) $1;
3968 if (lang_version == LanguageVersion.ISO_1)
3969 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3976 : SIZEOF open_parens_any type CLOSE_PARENS
3978 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3979 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3981 | SIZEOF open_parens_any type error
3983 Error_SyntaxError (yyToken);
3985 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3986 lbag.AddLocation ($$, GetLocation ($2));
3991 : CHECKED open_parens_any expression CLOSE_PARENS
3993 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3994 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3998 Error_SyntaxError (yyToken);
4000 $$ = new CheckedExpr (null, GetLocation ($1));
4004 unchecked_expression
4005 : UNCHECKED open_parens_any expression CLOSE_PARENS
4007 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4008 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4012 Error_SyntaxError (yyToken);
4014 $$ = new UnCheckedExpr (null, GetLocation ($1));
4018 pointer_member_access
4019 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4021 var lt = (LocatedToken) $3;
4022 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4026 anonymous_method_expression
4027 : DELEGATE opt_anonymous_method_signature
4029 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4033 $$ = end_anonymous ((ParametersBlock) $4);
4035 | ASYNC DELEGATE opt_anonymous_method_signature
4037 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4041 $$ = end_anonymous ((ParametersBlock) $5);
4045 opt_anonymous_method_signature
4048 $$ = ParametersCompiled.Undefined;
4050 | anonymous_method_signature
4053 anonymous_method_signature
4056 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4058 opt_formal_parameter_list CLOSE_PARENS
4060 valid_param_mod = 0;
4065 default_value_expression
4066 : DEFAULT open_parens_any type CLOSE_PARENS
4068 if (lang_version < LanguageVersion.ISO_2)
4069 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4071 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4072 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4077 : primary_expression
4078 | BANG prefixed_unary_expression
4080 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4082 | TILDE prefixed_unary_expression
4084 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4086 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4088 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4089 lbag.AddLocation ($$, GetLocation ($3));
4091 | AWAIT prefixed_unary_expression
4094 if (current_anonymous_method is LambdaExpression) {
4095 report.Error (4034, GetLocation ($1),
4096 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4097 } else if (current_anonymous_method != null) {
4098 report.Error (4035, GetLocation ($1),
4099 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4100 } else if (interactive_async != null) {
4101 current_block.Explicit.RegisterAsyncAwait ();
4102 interactive_async = true;
4104 report.Error (4033, GetLocation ($1),
4105 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4108 current_block.Explicit.RegisterAsyncAwait ();
4111 $$ = new Await ((Expression) $2, GetLocation ($1));
4115 Error_SyntaxError (yyToken);
4117 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4121 Error_SyntaxError (yyToken);
4123 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4125 | OPEN_PARENS_CAST type CLOSE_PARENS error
4127 Error_SyntaxError (yyToken);
4129 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4130 lbag.AddLocation ($$, GetLocation ($3));
4134 Error_SyntaxError (yyToken);
4136 $$ = new Await (null, GetLocation ($1));
4141 // The idea to split this out is from Rhys' grammar
4142 // to solve the problem with casts.
4144 prefixed_unary_expression
4146 | PLUS prefixed_unary_expression
4148 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4150 | MINUS prefixed_unary_expression
4152 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4154 | OP_INC prefixed_unary_expression
4156 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4158 | OP_DEC prefixed_unary_expression
4160 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4162 | STAR prefixed_unary_expression
4164 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4166 | BITWISE_AND prefixed_unary_expression
4168 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4172 Error_SyntaxError (yyToken);
4174 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4178 Error_SyntaxError (yyToken);
4180 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4184 Error_SyntaxError (yyToken);
4186 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4190 Error_SyntaxError (yyToken);
4192 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4196 Error_SyntaxError (yyToken);
4198 $$ = new Indirection (null, GetLocation ($1));
4202 Error_SyntaxError (yyToken);
4204 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4208 multiplicative_expression
4209 : prefixed_unary_expression
4210 | multiplicative_expression STAR prefixed_unary_expression
4212 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4213 lbag.AddLocation ($$, GetLocation ($2));
4215 | multiplicative_expression DIV prefixed_unary_expression
4217 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4218 lbag.AddLocation ($$, GetLocation ($2));
4220 | multiplicative_expression PERCENT prefixed_unary_expression
4222 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4223 lbag.AddLocation ($$, GetLocation ($2));
4225 | multiplicative_expression STAR error
4227 Error_SyntaxError (yyToken);
4229 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4230 lbag.AddLocation ($$, GetLocation ($2));
4232 | multiplicative_expression DIV error
4234 Error_SyntaxError (yyToken);
4236 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4237 lbag.AddLocation ($$, GetLocation ($2));
4239 | multiplicative_expression PERCENT error
4241 Error_SyntaxError (yyToken);
4243 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4244 lbag.AddLocation ($$, GetLocation ($2));
4249 : multiplicative_expression
4250 | additive_expression PLUS multiplicative_expression
4252 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4253 lbag.AddLocation ($$, GetLocation ($2));
4255 | additive_expression MINUS multiplicative_expression
4257 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4258 lbag.AddLocation ($$, GetLocation ($2));
4260 | additive_expression AS type
4262 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4264 | additive_expression IS type
4266 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4268 | additive_expression PLUS error
4270 Error_SyntaxError (yyToken);
4272 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4273 lbag.AddLocation ($$, GetLocation ($2));
4275 | additive_expression MINUS error
4277 Error_SyntaxError (yyToken);
4279 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4280 lbag.AddLocation ($$, GetLocation ($2));
4282 | additive_expression AS error
4284 Error_SyntaxError (yyToken);
4286 $$ = new As ((Expression) $1, null, GetLocation ($2));
4288 | additive_expression IS error
4290 Error_SyntaxError (yyToken);
4292 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4296 var lt = (LocatedToken) $1;
4297 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4301 var lt = (LocatedToken) $1;
4302 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4307 : additive_expression
4308 | shift_expression OP_SHIFT_LEFT additive_expression
4310 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4311 lbag.AddLocation ($$, GetLocation ($2));
4313 | shift_expression OP_SHIFT_RIGHT additive_expression
4315 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4316 lbag.AddLocation ($$, GetLocation ($2));
4318 | shift_expression OP_SHIFT_LEFT error
4320 Error_SyntaxError (yyToken);
4322 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4323 lbag.AddLocation ($$, GetLocation ($2));
4325 | shift_expression OP_SHIFT_RIGHT error
4327 Error_SyntaxError (yyToken);
4329 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4330 lbag.AddLocation ($$, GetLocation ($2));
4334 relational_expression
4336 | relational_expression OP_LT shift_expression
4338 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4339 lbag.AddLocation ($$, GetLocation ($2));
4341 | relational_expression OP_GT shift_expression
4343 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4344 lbag.AddLocation ($$, GetLocation ($2));
4346 | relational_expression OP_LE shift_expression
4348 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4349 lbag.AddLocation ($$, GetLocation ($2));
4351 | relational_expression OP_GE shift_expression
4353 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4354 lbag.AddLocation ($$, GetLocation ($2));
4356 | relational_expression OP_LT error
4358 Error_SyntaxError (yyToken);
4360 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4361 lbag.AddLocation ($$, GetLocation ($2));
4363 | relational_expression OP_GT error
4365 Error_SyntaxError (yyToken);
4367 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4368 lbag.AddLocation ($$, GetLocation ($2));
4370 | relational_expression OP_LE error
4372 Error_SyntaxError (yyToken);
4374 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4375 lbag.AddLocation ($$, GetLocation ($2));
4377 | relational_expression OP_GE error
4379 Error_SyntaxError (yyToken);
4381 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4382 lbag.AddLocation ($$, GetLocation ($2));
4387 : relational_expression
4388 | equality_expression OP_EQ relational_expression
4390 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4391 lbag.AddLocation ($$, GetLocation ($2));
4393 | equality_expression OP_NE relational_expression
4395 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4396 lbag.AddLocation ($$, GetLocation ($2));
4398 | equality_expression OP_EQ error
4400 Error_SyntaxError (yyToken);
4402 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4403 lbag.AddLocation ($$, GetLocation ($2));
4405 | equality_expression OP_NE error
4407 Error_SyntaxError (yyToken);
4409 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4410 lbag.AddLocation ($$, GetLocation ($2));
4415 : equality_expression
4416 | and_expression BITWISE_AND equality_expression
4418 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4419 lbag.AddLocation ($$, GetLocation ($2));
4421 | and_expression BITWISE_AND error
4423 Error_SyntaxError (yyToken);
4425 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4426 lbag.AddLocation ($$, GetLocation ($2));
4430 exclusive_or_expression
4432 | exclusive_or_expression CARRET and_expression
4434 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4435 lbag.AddLocation ($$, GetLocation ($2));
4437 | exclusive_or_expression CARRET error
4439 Error_SyntaxError (yyToken);
4441 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4442 lbag.AddLocation ($$, GetLocation ($2));
4446 inclusive_or_expression
4447 : exclusive_or_expression
4448 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4450 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4451 lbag.AddLocation ($$, GetLocation ($2));
4453 | inclusive_or_expression BITWISE_OR error
4455 Error_SyntaxError (yyToken);
4457 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4458 lbag.AddLocation ($$, GetLocation ($2));
4462 conditional_and_expression
4463 : inclusive_or_expression
4464 | conditional_and_expression OP_AND inclusive_or_expression
4466 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4467 lbag.AddLocation ($$, GetLocation ($2));
4469 | conditional_and_expression OP_AND error
4471 Error_SyntaxError (yyToken);
4473 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4474 lbag.AddLocation ($$, GetLocation ($2));
4478 conditional_or_expression
4479 : conditional_and_expression
4480 | conditional_or_expression OP_OR conditional_and_expression
4482 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4483 lbag.AddLocation ($$, GetLocation ($2));
4485 | conditional_or_expression OP_OR error
4487 Error_SyntaxError (yyToken);
4489 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4490 lbag.AddLocation ($$, GetLocation ($2));
4494 null_coalescing_expression
4495 : conditional_or_expression
4496 | conditional_or_expression OP_COALESCING null_coalescing_expression
4498 if (lang_version < LanguageVersion.ISO_2)
4499 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4501 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4502 lbag.AddLocation ($$, GetLocation ($2));
4506 conditional_expression
4507 : null_coalescing_expression
4508 | null_coalescing_expression INTERR expression COLON expression
4510 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4511 lbag.AddLocation ($$, GetLocation ($4));
4513 | null_coalescing_expression INTERR expression error
4515 Error_SyntaxError (yyToken);
4517 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4519 | null_coalescing_expression INTERR expression COLON error
4521 Error_SyntaxError (yyToken);
4523 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4524 lbag.AddLocation ($$, GetLocation ($4));
4526 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4528 Error_SyntaxError (Token.CLOSE_BRACE);
4530 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4531 lbag.AddLocation ($$, GetLocation ($4));
4532 lexer.putback ('}');
4536 assignment_expression
4537 : prefixed_unary_expression ASSIGN expression
4539 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4540 lbag.AddLocation ($$, GetLocation ($2));
4542 | prefixed_unary_expression OP_MULT_ASSIGN expression
4544 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4545 lbag.AddLocation ($$, GetLocation ($2));
4547 | prefixed_unary_expression OP_DIV_ASSIGN expression
4549 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4550 lbag.AddLocation ($$, GetLocation ($2));
4552 | prefixed_unary_expression OP_MOD_ASSIGN expression
4554 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4555 lbag.AddLocation ($$, GetLocation ($2));
4557 | prefixed_unary_expression OP_ADD_ASSIGN expression
4559 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4560 lbag.AddLocation ($$, GetLocation ($2));
4562 | prefixed_unary_expression OP_SUB_ASSIGN expression
4564 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4565 lbag.AddLocation ($$, GetLocation ($2));
4567 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4569 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4570 lbag.AddLocation ($$, GetLocation ($2));
4572 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4574 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4575 lbag.AddLocation ($$, GetLocation ($2));
4577 | prefixed_unary_expression OP_AND_ASSIGN expression
4579 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4580 lbag.AddLocation ($$, GetLocation ($2));
4582 | prefixed_unary_expression OP_OR_ASSIGN expression
4584 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4585 lbag.AddLocation ($$, GetLocation ($2));
4587 | prefixed_unary_expression OP_XOR_ASSIGN expression
4589 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4590 lbag.AddLocation ($$, GetLocation ($2));
4594 lambda_parameter_list
4597 var pars = new List<Parameter> (4);
4598 pars.Add ((Parameter) $1);
4602 | lambda_parameter_list COMMA lambda_parameter
4604 var pars = (List<Parameter>) $1;
4605 Parameter p = (Parameter)$3;
4606 if (pars[0].GetType () != p.GetType ()) {
4607 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4616 : parameter_modifier parameter_type identifier_inside_body
4618 var lt = (LocatedToken) $3;
4620 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4622 | parameter_type identifier_inside_body
4624 var lt = (LocatedToken) $2;
4626 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4630 var lt = (LocatedToken) $1;
4631 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4635 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4636 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4640 opt_lambda_parameter_list
4641 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4642 | lambda_parameter_list {
4643 var pars_list = (List<Parameter>) $1;
4644 $$ = new ParametersCompiled (pars_list.ToArray ());
4648 lambda_expression_body
4650 start_block (Location.Null);
4652 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4654 Block b = end_block (Location.Null);
4655 b.IsCompilerGenerated = true;
4656 b.AddStatement (new ContextualReturn ((Expression) $2));
4662 // Handles only cases like foo = x.FirstOrDefault (l => );
4663 // where we must restore current_variable
4664 Block b = end_block (Location.Null);
4665 b.IsCompilerGenerated = true;
4667 Error_SyntaxError (yyToken);
4676 Error_SyntaxError (yyToken);
4684 var lt = (LocatedToken) $1;
4685 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4686 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4688 lambda_expression_body
4690 $$ = end_anonymous ((ParametersBlock) $4);
4691 lbag.AddLocation ($$, GetLocation ($2));
4695 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4696 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4697 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4699 lambda_expression_body
4701 $$ = end_anonymous ((ParametersBlock) $4);
4702 lbag.AddLocation ($$, GetLocation ($2));
4704 | ASYNC identifier_inside_body ARROW
4706 var lt = (LocatedToken) $2;
4707 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4708 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4710 lambda_expression_body
4712 $$ = end_anonymous ((ParametersBlock) $5);
4713 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4715 | OPEN_PARENS_LAMBDA
4717 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4719 opt_lambda_parameter_list CLOSE_PARENS ARROW
4721 valid_param_mod = 0;
4722 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4724 lambda_expression_body
4726 $$ = end_anonymous ((ParametersBlock) $7);
4727 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4729 | ASYNC OPEN_PARENS_LAMBDA
4731 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4733 opt_lambda_parameter_list CLOSE_PARENS ARROW
4735 valid_param_mod = 0;
4736 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4738 lambda_expression_body
4740 $$ = end_anonymous ((ParametersBlock) $8);
4741 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4746 : assignment_expression
4747 | non_assignment_expression
4750 non_assignment_expression
4751 : conditional_expression
4756 $$ = new ArglistAccess (GetLocation ($1));
4760 undocumented_expressions
4761 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4763 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4764 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4766 | REFTYPE open_parens_any expression CLOSE_PARENS
4768 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4769 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4771 | MAKEREF open_parens_any expression CLOSE_PARENS
4773 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4774 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4785 $$ = new BooleanExpression ((Expression) $1);
4789 opt_primary_parameters
4794 | primary_parameters
4798 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4802 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4803 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4805 if (lang_version < LanguageVersion.V_6)
4806 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
4810 opt_primary_parameters_with_class_base
4819 | primary_parameters
4823 | primary_parameters class_base
4827 | primary_parameters class_base OPEN_PARENS
4829 ++lexer.parsing_block;
4830 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
4832 opt_argument_list CLOSE_PARENS
4834 lbag.AppendToMember (current_container, GetLocation ($6));
4835 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
4836 --lexer.parsing_block;
4852 type_declaration_name
4854 lexer.ConstraintsParsing = true;
4856 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4857 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4858 FeatureIsNotAvailable (c.Location, "static classes");
4861 push_current_container (c, $3);
4862 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4864 opt_primary_parameters_with_class_base
4865 opt_type_parameter_constraints_clauses
4867 valid_param_mod = 0;
4868 lexer.ConstraintsParsing = false;
4871 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4874 current_container.SetConstraints ((List<Constraints>) $9);
4875 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4878 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4879 Lexer.doc_state = XmlCommentState.Allowed;
4882 lexer.parsing_modifiers = true;
4884 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4886 --lexer.parsing_declaration;
4888 Lexer.doc_state = XmlCommentState.Allowed;
4893 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4895 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4897 $$ = pop_current_class ();
4905 { $$ = $1; } // location
4911 mod_locations = null;
4913 lexer.parsing_modifiers = false;
4917 lexer.parsing_modifiers = false;
4923 | modifiers modifier
4925 var m1 = (Modifiers) $1;
4926 var m2 = (Modifiers) $2;
4928 if ((m1 & m2) != 0) {
4929 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4930 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4931 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4932 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4933 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4934 "More than one protection modifier specified");
4945 StoreModifierLocation ($$, GetLocation ($1));
4947 if (current_container.Kind == MemberKind.Namespace)
4948 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4952 $$ = Modifiers.PUBLIC;
4953 StoreModifierLocation ($$, GetLocation ($1));
4957 $$ = Modifiers.PROTECTED;
4958 StoreModifierLocation ($$, GetLocation ($1));
4962 $$ = Modifiers.INTERNAL;
4963 StoreModifierLocation ($$, GetLocation ($1));
4967 $$ = Modifiers.PRIVATE;
4968 StoreModifierLocation ($$, GetLocation ($1));
4972 $$ = Modifiers.ABSTRACT;
4973 StoreModifierLocation ($$, GetLocation ($1));
4977 $$ = Modifiers.SEALED;
4978 StoreModifierLocation ($$, GetLocation ($1));
4982 $$ = Modifiers.STATIC;
4983 StoreModifierLocation ($$, GetLocation ($1));
4987 $$ = Modifiers.READONLY;
4988 StoreModifierLocation ($$, GetLocation ($1));
4992 $$ = Modifiers.VIRTUAL;
4993 StoreModifierLocation ($$, GetLocation ($1));
4997 $$ = Modifiers.OVERRIDE;
4998 StoreModifierLocation ($$, GetLocation ($1));
5002 $$ = Modifiers.EXTERN;
5003 StoreModifierLocation ($$, GetLocation ($1));
5007 $$ = Modifiers.VOLATILE;
5008 StoreModifierLocation ($$, GetLocation ($1));
5012 $$ = Modifiers.UNSAFE;
5013 StoreModifierLocation ($$, GetLocation ($1));
5014 if (!settings.Unsafe)
5015 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5019 $$ = Modifiers.ASYNC;
5020 StoreModifierLocation ($$, GetLocation ($1));
5032 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5034 | COLON type_list error
5036 Error_SyntaxError (yyToken);
5038 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5042 opt_type_parameter_constraints_clauses
5044 | type_parameter_constraints_clauses
5050 type_parameter_constraints_clauses
5051 : type_parameter_constraints_clause
5053 var constraints = new List<Constraints> (1);
5054 constraints.Add ((Constraints) $1);
5057 | type_parameter_constraints_clauses type_parameter_constraints_clause
5059 var constraints = (List<Constraints>) $1;
5060 Constraints new_constraint = (Constraints)$2;
5062 foreach (Constraints c in constraints) {
5063 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5064 report.Error (409, new_constraint.Location,
5065 "A constraint clause has already been specified for type parameter `{0}'",
5066 new_constraint.TypeParameter.Value);
5070 constraints.Add (new_constraint);
5075 type_parameter_constraints_clause
5076 : WHERE IDENTIFIER COLON type_parameter_constraints
5078 var lt = (LocatedToken) $2;
5079 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5080 lbag.AddLocation ($$, GetLocation ($3));
5082 | WHERE IDENTIFIER error
5084 Error_SyntaxError (yyToken);
5086 var lt = (LocatedToken) $2;
5087 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5091 type_parameter_constraints
5092 : type_parameter_constraint
5094 var constraints = new List<FullNamedExpression> (1);
5095 constraints.Add ((FullNamedExpression) $1);
5098 | type_parameter_constraints COMMA type_parameter_constraint
5100 var constraints = (List<FullNamedExpression>) $1;
5101 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5102 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5103 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5106 prev = $3 as SpecialContraintExpr;
5108 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5109 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5111 prev = constraints [0] as SpecialContraintExpr;
5112 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5113 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5118 constraints.Add ((FullNamedExpression) $3);
5123 type_parameter_constraint
5126 if ($1 is ComposedCast)
5127 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5131 | NEW OPEN_PARENS CLOSE_PARENS
5133 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5134 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5138 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5142 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5146 opt_type_parameter_variance
5151 | type_parameter_variance
5153 if (lang_version <= LanguageVersion.V_3)
5154 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5160 type_parameter_variance
5163 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5167 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5176 // A block is "contained" on the following places:
5178 // property_declaration as part of the accessor body (get/set)
5179 // operator_declaration
5180 // constructor_declaration
5181 // destructor_declaration
5182 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5187 ++lexer.parsing_block;
5188 start_block (GetLocation ($1));
5190 opt_statement_list block_end
5199 --lexer.parsing_block;
5200 $$ = end_block (GetLocation ($1));
5202 | COMPLETE_COMPLETION
5204 --lexer.parsing_block;
5205 $$ = end_block (lexer.Location);
5213 ++lexer.parsing_block;
5214 current_block.StartLocation = GetLocation ($1);
5216 opt_statement_list CLOSE_BRACE
5218 --lexer.parsing_block;
5219 $$ = end_block (GetLocation ($4));
5230 | statement_list statement
5234 : block_variable_declaration
5236 current_block.AddStatement ((Statement) $1);
5238 | valid_declaration_statement
5240 current_block.AddStatement ((Statement) $1);
5245 Error_SyntaxError (yyToken);
5251 // The interactive_statement and its derivatives are only
5252 // used to provide a special version of `expression_statement'
5253 // that has a side effect of assigning the expression to
5256 interactive_statement_list
5257 : interactive_statement
5258 | interactive_statement_list interactive_statement
5261 interactive_statement
5262 : block_variable_declaration
5264 current_block.AddStatement ((Statement) $1);
5266 | interactive_valid_declaration_statement
5268 current_block.AddStatement ((Statement) $1);
5273 valid_declaration_statement
5276 | expression_statement
5277 | selection_statement
5278 | iteration_statement
5282 | unchecked_statement
5289 interactive_valid_declaration_statement
5292 | interactive_expression_statement
5293 | selection_statement
5294 | iteration_statement
5298 | unchecked_statement
5306 : valid_declaration_statement
5307 | block_variable_declaration
5309 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5314 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5319 Error_SyntaxError (yyToken);
5320 $$ = new EmptyStatement (GetLocation ($1));
5327 // Uses lexer.Location because semicolon location is not kept in quick mode
5328 $$ = new EmptyStatement (lexer.Location);
5333 : identifier_inside_body COLON
5335 var lt = (LocatedToken) $1;
5336 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5337 lbag.AddLocation (labeled, GetLocation ($2));
5338 current_block.AddLabel (labeled);
5339 current_block.AddStatement (labeled);
5345 : variable_type_simple
5346 | variable_type_simple rank_specifiers
5349 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5351 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5356 * The following is from Rhys' grammar:
5357 * > Types in local variable declarations must be recognized as
5358 * > expressions to prevent reduce/reduce errors in the grammar.
5359 * > The expressions are converted into types during semantic analysis.
5361 variable_type_simple
5362 : primary_expression_or_type opt_nullable
5364 // Ok, the above "primary_expression" is there to get rid of
5365 // both reduce/reduce and shift/reduces in the grammar, it should
5366 // really just be "type_name". If you use type_name, a reduce/reduce
5367 // creeps up. If you use namespace_or_type_name (which is all we need
5368 // really) two shift/reduces appear.
5371 // So the super-trick is that primary_expression
5372 // can only be either a SimpleName or a MemberAccess.
5373 // The MemberAccess case arises when you have a fully qualified type-name like :
5375 // SimpleName is when you have
5378 Expression expr = (Expression) $1;
5380 SimpleName sn = expr as SimpleName;
5381 if (sn != null && sn.Name == "var")
5382 $$ = new VarExpr (sn.Location);
5385 } else if (expr is ATypeNameExpression) {
5386 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5388 Error_ExpectingTypeName (expr);
5392 | primary_expression_or_type pointer_stars
5394 ATypeNameExpression expr = $1 as ATypeNameExpression;
5397 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5399 Error_ExpectingTypeName ((Expression)$1);
5403 | builtin_types opt_nullable
5408 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5410 | builtin_types pointer_stars
5412 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5414 | VOID pointer_stars
5416 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5420 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5421 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5427 | pointer_star pointer_stars
5429 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5437 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5441 identifier_inside_body
5445 $$ = Error_AwaitAsIdentifier ($1);
5449 block_variable_declaration
5450 : variable_type identifier_inside_body
5452 var lt = (LocatedToken) $2;
5453 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5454 current_block.AddLocalName (li);
5455 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5457 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5459 $$ = current_variable;
5460 current_variable = null;
5462 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5464 lbag.AddLocation ($$, GetLocation ($6));
5466 | CONST variable_type identifier_inside_body
5468 var lt = (LocatedToken) $3;
5469 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5470 current_block.AddLocalName (li);
5471 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5473 const_variable_initializer opt_const_declarators SEMICOLON
5475 $$ = current_variable;
5476 current_variable = null;
5477 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5481 opt_local_variable_initializer
5483 | ASSIGN block_variable_initializer
5485 current_variable.Initializer = (Expression) $2;
5486 PushLocation (GetLocation ($1));
5487 $$ = current_variable;
5491 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5492 report.Error (650, lexer.Location,
5493 "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");
5495 Error_SyntaxError (yyToken);
5500 opt_variable_declarators
5502 | variable_declarators
5505 opt_using_or_fixed_variable_declarators
5507 | variable_declarators
5509 foreach (var d in current_variable.Declarators) {
5510 if (d.Initializer == null)
5511 Error_MissingInitializer (d.Variable.Location);
5516 variable_declarators
5517 : variable_declarator
5518 | variable_declarators variable_declarator
5522 : COMMA identifier_inside_body
5524 var lt = (LocatedToken) $2;
5525 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5526 var d = new BlockVariableDeclarator (li, null);
5527 current_variable.AddDeclarator (d);
5528 current_block.AddLocalName (li);
5529 lbag.AddLocation (d, GetLocation ($1));
5531 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5533 var lt = (LocatedToken) $2;
5534 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5535 var d = new BlockVariableDeclarator (li, (Expression) $4);
5536 current_variable.AddDeclarator (d);
5537 current_block.AddLocalName (li);
5538 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5542 const_variable_initializer
5545 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5547 | ASSIGN constant_initializer_expr
5549 current_variable.Initializer = (Expression) $2;
5553 opt_const_declarators
5560 | const_declarators const_declarator
5564 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5566 var lt = (LocatedToken) $2;
5567 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5568 var d = new BlockVariableDeclarator (li, (Expression) $4);
5569 current_variable.AddDeclarator (d);
5570 current_block.AddLocalName (li);
5571 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5575 block_variable_initializer
5576 : variable_initializer
5577 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5579 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5580 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5582 | STACKALLOC simple_type
5584 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5585 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5589 expression_statement
5590 : statement_expression SEMICOLON
5593 lbag.AddStatement ($$, GetLocation ($2));
5595 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5596 | statement_expression CLOSE_BRACE
5599 report.Error (1002, GetLocation ($2), "; expected");
5600 lexer.putback ('}');
5604 interactive_expression_statement
5605 : interactive_statement_expression SEMICOLON { $$ = $1; }
5606 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5610 // We have to do the wrapping here and not in the case above,
5611 // because statement_expression is used for example in for_statement
5613 statement_expression
5616 ExpressionStatement s = $1 as ExpressionStatement;
5618 var expr = $1 as Expression;
5619 $$ = new StatementErrorExpression (expr);
5621 $$ = new StatementExpression (s);
5626 interactive_statement_expression
5629 Expression expr = (Expression) $1;
5630 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5634 Error_SyntaxError (yyToken);
5635 $$ = new EmptyStatement (GetLocation ($1));
5645 : IF open_parens_any boolean_expression CLOSE_PARENS
5648 if ($5 is EmptyStatement)
5649 Warning_EmptyStatement (GetLocation ($5));
5651 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5652 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5654 | IF open_parens_any boolean_expression CLOSE_PARENS
5655 embedded_statement ELSE embedded_statement
5657 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5658 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5660 if ($5 is EmptyStatement)
5661 Warning_EmptyStatement (GetLocation ($5));
5662 if ($7 is EmptyStatement)
5663 Warning_EmptyStatement (GetLocation ($7));
5665 | IF open_parens_any boolean_expression error
5667 Error_SyntaxError (yyToken);
5669 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5670 lbag.AddStatement ($$, GetLocation ($2));
5675 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5677 start_block (GetLocation ($5));
5679 opt_switch_sections CLOSE_BRACE
5681 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5682 end_block (GetLocation ($8));
5683 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5685 | SWITCH open_parens_any expression error
5687 Error_SyntaxError (yyToken);
5689 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5690 lbag.AddStatement ($$, GetLocation ($2));
5697 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5704 | switch_sections switch_section
5707 Error_SyntaxError (yyToken);
5712 : switch_labels statement_list
5718 var label = (SwitchLabel) $1;
5719 label.SectionStart = true;
5720 current_block.AddStatement (label);
5722 | switch_labels switch_label
5724 current_block.AddStatement ((Statement) $2);
5729 : CASE constant_expression COLON
5731 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5732 lbag.AddLocation ($$, GetLocation ($3));
5734 | CASE constant_expression error
5736 Error_SyntaxError (yyToken);
5737 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5741 $$ = new SwitchLabel (null, GetLocation ($1));
5753 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5755 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5756 Warning_EmptyStatement (GetLocation ($5));
5758 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5759 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5761 | WHILE open_parens_any boolean_expression error
5763 Error_SyntaxError (yyToken);
5765 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5766 lbag.AddStatement ($$, GetLocation ($2));
5771 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5773 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5774 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5776 | DO embedded_statement error
5778 Error_SyntaxError (yyToken);
5779 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5781 | DO embedded_statement WHILE open_parens_any boolean_expression error
5783 Error_SyntaxError (yyToken);
5785 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5786 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5791 : FOR open_parens_any
5793 start_block (GetLocation ($2));
5794 current_block.IsCompilerGenerated = true;
5795 For f = new For (GetLocation ($1));
5796 current_block.AddStatement (f);
5805 // Has to use be extra rule to recover started block
5807 : opt_for_initializer SEMICOLON
5809 ((For) $0).Initializer = (Statement) $1;
5811 // Pass the "For" object to the iterator_part4
5812 oob_stack.Push ($0);
5814 for_condition_and_iterator_part
5817 var locations = (Tuple<Location,Location>) $4;
5819 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5820 Warning_EmptyStatement (GetLocation ($5));
5823 f.Statement = (Statement) $5;
5824 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5826 $$ = end_block (GetLocation ($2));
5830 Error_SyntaxError (yyToken);
5831 $$ = end_block (current_block.StartLocation);
5835 for_condition_and_iterator_part
5836 : opt_for_condition SEMICOLON
5838 For f = (For) oob_stack.Peek ();
5839 f.Condition = (BooleanExpression) $1;
5842 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5845 // Handle errors in the case of opt_for_condition being followed by
5846 // a close parenthesis
5847 | opt_for_condition close_parens_close_brace {
5848 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5849 For f = (For) oob_stack.Peek ();
5850 f.Condition = (BooleanExpression) $1;
5851 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5856 : opt_for_iterator CLOSE_PARENS {
5857 For f = (For) oob_stack.Peek ();
5858 f.Iterator = (Statement) $1;
5859 $$ = GetLocation ($2);
5861 | opt_for_iterator CLOSE_BRACE {
5862 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5863 For f = (For) oob_stack.Peek ();
5864 f.Iterator = (Statement) $1;
5865 $$ = GetLocation ($2);
5869 close_parens_close_brace
5871 | CLOSE_BRACE { lexer.putback ('}'); }
5875 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5880 : variable_type identifier_inside_body
5882 var lt = (LocatedToken) $2;
5883 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5884 current_block.AddLocalName (li);
5885 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5887 opt_local_variable_initializer opt_variable_declarators
5889 $$ = current_variable;
5891 lbag.AddLocation (current_variable, PopLocation ());
5893 current_variable = null;
5895 | statement_expression_list
5899 : /* empty */ { $$ = null; }
5900 | boolean_expression
5904 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5909 : statement_expression_list
5912 statement_expression_list
5913 : statement_expression
5914 | statement_expression_list COMMA statement_expression
5916 var sl = $1 as StatementList;
5918 sl = new StatementList ((Statement) $1, (Statement) $3);
5919 lbag.AddStatement (sl, GetLocation ($2));
5921 sl.Add ((Statement) $3);
5922 lbag.AppendTo (sl, GetLocation ($2));
5930 : FOREACH open_parens_any type error
5932 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5934 start_block (GetLocation ($2));
5935 current_block.IsCompilerGenerated = true;
5937 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5938 current_block.AddStatement (f);
5940 lbag.AddStatement (f, GetLocation ($2));
5941 $$ = end_block (GetLocation ($4));
5943 | FOREACH open_parens_any type identifier_inside_body error
5945 Error_SyntaxError (yyToken);
5947 start_block (GetLocation ($2));
5948 current_block.IsCompilerGenerated = true;
5950 var lt = (LocatedToken) $4;
5951 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5952 current_block.AddLocalName (li);
5954 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5955 current_block.AddStatement (f);
5957 lbag.AddStatement (f, GetLocation ($2));
5958 $$ = end_block (GetLocation ($5));
5960 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5962 start_block (GetLocation ($2));
5963 current_block.IsCompilerGenerated = true;
5965 var lt = (LocatedToken) $4;
5966 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5967 current_block.AddLocalName (li);
5972 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5973 Warning_EmptyStatement (GetLocation ($9));
5975 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5976 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5977 end_block (GetLocation ($7));
5985 | continue_statement
5995 $$ = new Break (GetLocation ($1));
5996 lbag.AddStatement ($$, GetLocation ($2));
6001 : CONTINUE SEMICOLON
6003 $$ = new Continue (GetLocation ($1));
6004 lbag.AddStatement ($$, GetLocation ($2));
6008 Error_SyntaxError (yyToken);
6009 $$ = new Continue (GetLocation ($1));
6014 : GOTO identifier_inside_body SEMICOLON
6016 var lt = (LocatedToken) $2;
6017 $$ = new Goto (lt.Value, GetLocation ($1));
6018 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6020 | GOTO CASE constant_expression SEMICOLON
6022 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6023 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6025 | GOTO DEFAULT SEMICOLON
6027 $$ = new GotoDefault (GetLocation ($1));
6028 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6033 : RETURN opt_expression SEMICOLON
6035 $$ = new Return ((Expression) $2, GetLocation ($1));
6036 lbag.AddStatement ($$, GetLocation ($3));
6038 | RETURN expression error
6040 Error_SyntaxError (yyToken);
6041 $$ = new Return ((Expression) $2, GetLocation ($1));
6045 Error_SyntaxError (yyToken);
6046 $$ = new Return (null, GetLocation ($1));
6051 : THROW opt_expression SEMICOLON
6053 $$ = new Throw ((Expression) $2, GetLocation ($1));
6054 lbag.AddStatement ($$, GetLocation ($3));
6056 | THROW expression error
6058 Error_SyntaxError (yyToken);
6059 $$ = new Throw ((Expression) $2, GetLocation ($1));
6063 Error_SyntaxError (yyToken);
6064 $$ = new Throw (null, GetLocation ($1));
6069 : identifier_inside_body RETURN opt_expression SEMICOLON
6071 var lt = (LocatedToken) $1;
6072 string s = lt.Value;
6074 report.Error (1003, lt.Location, "; expected");
6075 } else if ($3 == null) {
6076 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6077 } else if (lang_version == LanguageVersion.ISO_1){
6078 FeatureIsNotAvailable (lt.Location, "iterators");
6081 current_block.Explicit.RegisterIteratorYield ();
6082 $$ = new Yield ((Expression) $3, lt.Location);
6083 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6085 | identifier_inside_body RETURN expression error
6087 Error_SyntaxError (yyToken);
6089 var lt = (LocatedToken) $1;
6090 string s = lt.Value;
6092 report.Error (1003, lt.Location, "; expected");
6093 } else if ($3 == null) {
6094 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6095 } else if (lang_version == LanguageVersion.ISO_1){
6096 FeatureIsNotAvailable (lt.Location, "iterators");
6099 current_block.Explicit.RegisterIteratorYield ();
6100 $$ = new Yield ((Expression) $3, lt.Location);
6101 lbag.AddStatement ($$, GetLocation ($2));
6103 | identifier_inside_body BREAK SEMICOLON
6105 var lt = (LocatedToken) $1;
6106 string s = lt.Value;
6108 report.Error (1003, lt.Location, "; expected");
6109 } else if (lang_version == LanguageVersion.ISO_1){
6110 FeatureIsNotAvailable (lt.Location, "iterators");
6113 current_block.ParametersBlock.TopBlock.IsIterator = true;
6114 $$ = new YieldBreak (lt.Location);
6115 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6125 : TRY block catch_clauses
6127 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6129 | TRY block FINALLY block
6131 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6132 lbag.AddStatement ($$, GetLocation ($3));
6134 | TRY block catch_clauses FINALLY block
6136 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6137 lbag.AddStatement ($$, GetLocation ($4));
6141 Error_SyntaxError (1524, yyToken);
6142 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6149 var l = new List<Catch> (2);
6154 | catch_clauses catch_clause
6156 var l = (List<Catch>) $1;
6158 Catch c = (Catch) $2;
6159 var prev_catch = l [l.Count - 1];
6160 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6161 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6171 | identifier_inside_body
6175 : CATCH opt_catch_filter block
6177 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6178 c.Filter = (CatchFilterExpression) $2;
6181 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6183 start_block (GetLocation ($2));
6184 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6185 c.TypeExpression = (FullNamedExpression) $3;
6188 var lt = (LocatedToken) $4;
6189 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6190 current_block.AddLocalName (c.Variable);
6193 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6196 opt_catch_filter block_prepared
6198 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6201 | CATCH open_parens_any error
6203 if (yyToken == Token.CLOSE_PARENS) {
6204 report.Error (1015, lexer.Location,
6205 "A type that derives from `System.Exception', `object', or `string' expected");
6207 Error_SyntaxError (yyToken);
6210 $$ = new Catch (null, GetLocation ($1));
6212 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6214 Error_SyntaxError (yyToken);
6216 // Required otherwise missing block could not be detected because
6217 // start_block is run early
6218 var c = new Catch (null, GetLocation ($1));
6219 c.TypeExpression = (FullNamedExpression) $3;
6222 var lt = (LocatedToken) $4;
6223 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6226 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6234 | IF open_parens_any expression CLOSE_PARENS
6236 if (lang_version <= LanguageVersion.V_5)
6237 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6239 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6240 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6247 $$ = new Checked ((Block) $2, GetLocation ($1));
6254 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6261 if (!settings.Unsafe)
6262 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6264 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6269 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6271 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6272 Warning_EmptyStatement (GetLocation ($5));
6274 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6275 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6277 | LOCK open_parens_any expression error
6279 Error_SyntaxError (yyToken);
6281 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6282 lbag.AddStatement ($$, GetLocation ($2));
6287 : FIXED open_parens_any variable_type identifier_inside_body
6289 start_block (GetLocation ($2));
6291 current_block.IsCompilerGenerated = true;
6292 var lt = (LocatedToken) $4;
6293 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6294 current_block.AddLocalName (li);
6295 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6297 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6299 $$ = current_variable;
6300 current_variable = null;
6304 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6305 Warning_EmptyStatement (GetLocation ($10));
6307 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6308 current_block.AddStatement (f);
6309 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6310 $$ = end_block (GetLocation ($8));
6315 : USING open_parens_any variable_type identifier_inside_body
6317 start_block (GetLocation ($2));
6319 current_block.IsCompilerGenerated = true;
6320 var lt = (LocatedToken) $4;
6321 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6322 current_block.AddLocalName (li);
6323 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6325 using_initialization CLOSE_PARENS
6327 $$ = current_variable;
6328 current_variable = null;
6332 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6333 Warning_EmptyStatement (GetLocation ($9));
6335 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6336 current_block.AddStatement (u);
6337 $$ = end_block (GetLocation ($7));
6339 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6341 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6342 Warning_EmptyStatement (GetLocation ($5));
6344 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6345 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6347 | USING open_parens_any expression error
6349 Error_SyntaxError (yyToken);
6351 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6352 lbag.AddStatement ($$, GetLocation ($2));
6356 using_initialization
6357 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6360 // It has to be here for the parent to safely restore artificial block
6361 Error_SyntaxError (yyToken);
6365 using_or_fixed_variable_initializer
6368 Error_MissingInitializer (lexer.Location);
6370 | ASSIGN variable_initializer
6372 current_variable.Initializer = (Expression) $2;
6373 $$ = current_variable;
6381 : first_from_clause query_body
6383 lexer.query_parsing = false;
6385 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6387 from.Tail.Next = (Linq.AQueryClause)$2;
6390 current_block.SetEndLocation (lexer.Location);
6391 current_block = current_block.Parent;
6393 | nested_from_clause query_body
6395 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6397 from.Tail.Next = (Linq.AQueryClause)$2;
6400 current_block.SetEndLocation (lexer.Location);
6401 current_block = current_block.Parent;
6404 // Bubble up COMPLETE_COMPLETION productions
6405 | first_from_clause COMPLETE_COMPLETION {
6406 lexer.query_parsing = false;
6409 current_block.SetEndLocation (lexer.Location);
6410 current_block = current_block.Parent;
6412 | nested_from_clause COMPLETE_COMPLETION {
6414 current_block.SetEndLocation (lexer.Location);
6415 current_block = current_block.Parent;
6420 : FROM_FIRST identifier_inside_body IN expression
6422 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6424 var lt = (LocatedToken) $2;
6425 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6426 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6427 lbag.AddLocation (clause, GetLocation ($3));
6428 $$ = new Linq.QueryExpression (clause);
6430 | FROM_FIRST type identifier_inside_body IN expression
6432 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6434 var lt = (LocatedToken) $3;
6435 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6436 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6437 IdentifierType = (FullNamedExpression)$2
6439 lbag.AddLocation (clause, GetLocation ($4));
6440 $$ = new Linq.QueryExpression (clause);
6445 : FROM identifier_inside_body IN expression
6447 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6449 var lt = (LocatedToken) $2;
6450 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6451 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6452 lbag.AddLocation (clause, GetLocation ($3));
6453 $$ = new Linq.QueryExpression (clause);
6455 | FROM type identifier_inside_body IN expression
6457 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6459 var lt = (LocatedToken) $3;
6460 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6461 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6462 IdentifierType = (FullNamedExpression)$2
6464 lbag.AddLocation (clause, GetLocation ($4));
6465 $$ = new Linq.QueryExpression (clause);
6470 : FROM identifier_inside_body IN
6472 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6476 var lt = (LocatedToken) $2;
6477 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6478 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6480 current_block.SetEndLocation (lexer.Location);
6481 current_block = current_block.Parent;
6483 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6484 lbag.AddLocation ($$, GetLocation ($3));
6486 | FROM type identifier_inside_body IN
6488 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6492 var lt = (LocatedToken) $3;
6493 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6495 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6496 IdentifierType = (FullNamedExpression)$2
6499 current_block.SetEndLocation (lexer.Location);
6500 current_block = current_block.Parent;
6502 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6504 lbag.AddLocation ($$, GetLocation ($4));
6509 : query_body_clauses select_or_group_clause opt_query_continuation
6511 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6514 head.Next = (Linq.AQueryClause)$3;
6517 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6518 clause.Tail.Next = head;
6524 | select_or_group_clause opt_query_continuation
6526 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6529 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6530 clause.Tail.Next = head;
6536 | query_body_clauses COMPLETE_COMPLETION
6537 | query_body_clauses error
6539 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6544 Error_SyntaxError (yyToken);
6549 select_or_group_clause
6552 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6556 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6558 current_block.SetEndLocation (lexer.Location);
6559 current_block = current_block.Parent;
6563 if (linq_clause_blocks == null)
6564 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6566 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6567 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6571 current_block.SetEndLocation (lexer.Location);
6572 current_block = current_block.Parent;
6574 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6578 var obj = (object[]) $5;
6580 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6581 lbag.AddLocation ($$, (Location) obj[1]);
6583 current_block.SetEndLocation (lexer.Location);
6584 current_block = current_block.Parent;
6589 : BY expression_or_error
6591 $$ = new object[] { $2, GetLocation ($1) };
6595 Error_SyntaxError (yyToken);
6596 $$ = new object[2] { null, Location.Null };
6602 | query_body_clauses query_body_clause
6604 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6618 : LET identifier_inside_body ASSIGN
6620 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6624 var lt = (LocatedToken) $2;
6625 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6626 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6627 lbag.AddLocation ($$, GetLocation ($3));
6629 current_block.SetEndLocation (lexer.Location);
6630 current_block = current_block.Parent;
6632 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6639 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6643 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6645 current_block.SetEndLocation (lexer.Location);
6646 current_block = current_block.Parent;
6651 : JOIN identifier_inside_body IN
6653 if (linq_clause_blocks == null)
6654 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6656 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6657 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6659 expression_or_error ON
6661 current_block.SetEndLocation (lexer.Location);
6662 current_block = current_block.Parent;
6664 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6665 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6667 expression_or_error EQUALS
6669 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6670 current_block.SetEndLocation (lexer.Location);
6671 current_block = current_block.Parent;
6673 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6675 expression_or_error opt_join_into
6677 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6678 current_block.SetEndLocation (lexer.Location);
6680 var outer_selector = linq_clause_blocks.Pop ();
6681 var block = linq_clause_blocks.Pop ();
6683 var lt = (LocatedToken) $2;
6684 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6685 Linq.RangeVariable into;
6689 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6690 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6693 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6695 var parent = block.Parent;
6696 while (parent is Linq.QueryBlock) {
6697 parent = parent.Parent;
6699 current_block.Parent = parent;
6701 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6703 lt = (LocatedToken) $12;
6704 into = new Linq.RangeVariable (lt.Value, lt.Location);
6706 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6707 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6710 current_block = block.Parent;
6711 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6713 | JOIN type identifier_inside_body IN
6715 if (linq_clause_blocks == null)
6716 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6718 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6719 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6721 expression_or_error ON
6723 current_block.SetEndLocation (lexer.Location);
6724 current_block = current_block.Parent;
6726 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6727 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6729 expression_or_error EQUALS
6731 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6732 current_block.SetEndLocation (lexer.Location);
6733 current_block = current_block.Parent;
6735 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6737 expression_or_error opt_join_into
6739 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6740 current_block.SetEndLocation (lexer.Location);
6742 var outer_selector = linq_clause_blocks.Pop ();
6743 var block = linq_clause_blocks.Pop ();
6745 var lt = (LocatedToken) $3;
6746 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6747 Linq.RangeVariable into;
6751 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6752 IdentifierType = (FullNamedExpression)$2
6754 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6757 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6759 var parent = block.Parent;
6760 while (parent is Linq.QueryBlock) {
6761 parent = parent.Parent;
6763 current_block.Parent = parent;
6765 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6767 lt = (LocatedToken) $13;
6768 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6770 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6771 IdentifierType = (FullNamedExpression)$2
6775 current_block = block.Parent;
6776 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6782 | INTO identifier_inside_body
6791 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6795 current_block.SetEndLocation (lexer.Location);
6796 current_block = current_block.Parent;
6806 current_block.SetEndLocation (lexer.Location);
6807 current_block = current_block.Parent;
6809 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6813 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6820 | orderings_then_by COMMA
6822 current_block.SetEndLocation (lexer.Location);
6823 current_block = current_block.Parent;
6825 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6829 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6837 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6839 | expression ASCENDING
6841 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6842 lbag.AddLocation ($$, GetLocation ($2));
6844 | expression DESCENDING
6846 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6847 lbag.AddLocation ($$, GetLocation ($2));
6854 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6856 | expression ASCENDING
6858 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6859 lbag.AddLocation ($$, GetLocation ($2));
6861 | expression DESCENDING
6863 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6864 lbag.AddLocation ($$, GetLocation ($2));
6869 opt_query_continuation
6871 | INTO identifier_inside_body
6873 // query continuation block is not linked with query block but with block
6874 // before. This means each query can use same range variable names for
6875 // different identifiers.
6877 current_block.SetEndLocation (GetLocation ($1));
6878 current_block = current_block.Parent;
6880 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6882 if (linq_clause_blocks == null)
6883 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6885 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6889 var current_block = linq_clause_blocks.Pop ();
6890 var lt = (LocatedToken) $2;
6891 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6892 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6893 next = (Linq.AQueryClause)$4
6899 // Support for using the compiler as an interactive parser
6901 // The INTERACTIVE_PARSER token is first sent to parse our
6902 // productions; If the result is a Statement, the parsing
6903 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6904 // to setup the blocks in advance.
6906 // This setup is here so that in the future we can add
6907 // support for other constructs (type parsing, namespaces, etc)
6908 // that do not require a block to be setup in advance
6912 : EVAL_STATEMENT_PARSER EOF
6913 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6914 | EVAL_STATEMENT_PARSER
6916 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6918 // (ref object retval)
6919 Parameter [] mpar = new Parameter [1];
6920 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6922 ParametersCompiled pars = new ParametersCompiled (mpar);
6923 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6924 if (settings.Unsafe)
6925 mods |= Modifiers.UNSAFE;
6927 current_local_parameters = pars;
6928 var method = new InteractiveMethod (
6930 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6934 current_type.AddMember (method);
6935 oob_stack.Push (method);
6937 interactive_async = false;
6939 ++lexer.parsing_block;
6940 start_block (lexer.Location);
6942 interactive_statement_list opt_COMPLETE_COMPLETION
6944 --lexer.parsing_block;
6945 var method = (InteractiveMethod) oob_stack.Pop ();
6946 method.Block = (ToplevelBlock) end_block(lexer.Location);
6948 if (interactive_async == true) {
6949 method.ChangeToAsync ();
6952 InteractiveResult = (Class) pop_current_class ();
6953 current_local_parameters = null;
6955 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6958 interactive_compilation_unit
6959 : opt_extern_alias_directives opt_using_directives
6960 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6963 opt_COMPLETE_COMPLETION
6965 | COMPLETE_COMPLETION
6968 close_brace_or_complete_completion
6970 | COMPLETE_COMPLETION
6974 // XML documentation code references micro parser
6976 documentation_parsing
6979 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6984 : doc_type_declaration_name opt_doc_method_sig
6986 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6988 | builtin_types opt_doc_method_sig
6990 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6991 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6994 | VOID opt_doc_method_sig
6996 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
6997 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7000 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7002 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7003 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7004 var lt = (LocatedToken) $3;
7005 $$ = new MemberName (lt.Value);
7007 | doc_type_declaration_name DOT THIS
7009 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7011 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7013 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7015 opt_doc_parameters CLOSE_BRACKET
7017 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7018 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7020 | EXPLICIT OPERATOR type opt_doc_method_sig
7022 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7023 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7024 module.DocumentationBuilder.ParsedParameters = p;
7025 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7028 | IMPLICIT OPERATOR type opt_doc_method_sig
7030 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7031 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7032 module.DocumentationBuilder.ParsedParameters = p;
7033 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7036 | OPERATOR overloadable_operator opt_doc_method_sig
7038 var p = (List<DocumentationParameter>)$3;
7039 module.DocumentationBuilder.ParsedParameters = p;
7040 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7045 doc_type_declaration_name
7046 : type_declaration_name
7047 | doc_type_declaration_name DOT type_declaration_name
7049 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7057 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7059 opt_doc_parameters CLOSE_PARENS
7068 $$ = new List<DocumentationParameter> (0);
7076 var parameters = new List<DocumentationParameter> ();
7077 parameters.Add ((DocumentationParameter) $1);
7080 | doc_parameters COMMA doc_parameter
7082 var parameters = $1 as List<DocumentationParameter>;
7083 parameters.Add ((DocumentationParameter) $3);
7089 : opt_parameter_modifier parameter_type
7092 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7094 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7101 // A class used to hold info about an operator declarator
7103 class OperatorDeclaration {
7104 public readonly Operator.OpType optype;
7105 public readonly FullNamedExpression ret_type;
7106 public readonly Location location;
7108 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7111 this.ret_type = ret_type;
7112 this.location = location;
7116 void Error_ExpectingTypeName (Expression expr)
7118 if (expr is Invocation){
7119 report.Error (1002, expr.Location, "Expecting `;'");
7121 expr.Error_InvalidExpressionStatement (report);
7125 void Error_ParameterModifierNotValid (string modifier, Location loc)
7127 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7131 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7133 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7134 Parameter.GetModifierSignature (mod));
7137 void Error_TypeExpected (Location loc)
7139 report.Error (1031, loc, "Type expected");
7142 void Error_UnsafeCodeNotAllowed (Location loc)
7144 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7147 void Warning_EmptyStatement (Location loc)
7149 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7152 void Error_NamedArgumentExpected (NamedArgument a)
7154 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7157 void Error_MissingInitializer (Location loc)
7159 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7162 object Error_AwaitAsIdentifier (object token)
7165 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7166 return new LocatedToken ("await", GetLocation (token));
7172 void push_current_container (TypeDefinition tc, object partial_token)
7174 if (module.Evaluator != null){
7175 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7179 undo.AddTypeContainer (current_container, tc);
7182 if (partial_token != null)
7183 current_container.AddPartial (tc);
7185 current_container.AddTypeContainer (tc);
7187 ++lexer.parsing_declaration;
7188 current_container = tc;
7192 TypeContainer pop_current_class ()
7194 var retval = current_container;
7196 current_container = current_container.Parent;
7197 current_type = current_type.Parent as TypeDefinition;
7202 [System.Diagnostics.Conditional ("FULL_AST")]
7203 void StoreModifierLocation (object token, Location loc)
7208 if (mod_locations == null)
7209 mod_locations = new List<Tuple<Modifiers, Location>> ();
7211 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7214 [System.Diagnostics.Conditional ("FULL_AST")]
7215 void PushLocation (Location loc)
7217 if (location_stack == null)
7218 location_stack = new Stack<Location> ();
7220 location_stack.Push (loc);
7223 Location PopLocation ()
7225 if (location_stack == null)
7226 return Location.Null;
7228 return location_stack.Pop ();
7231 string CheckAttributeTarget (int token, string a, Location l)
7234 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7238 if (!Tokenizer.IsValidIdentifier (a)) {
7239 Error_SyntaxError (token);
7241 report.Warning (658, 1, l,
7242 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7245 return string.Empty;
7248 static bool IsUnaryOperator (Operator.OpType op)
7252 case Operator.OpType.LogicalNot:
7253 case Operator.OpType.OnesComplement:
7254 case Operator.OpType.Increment:
7255 case Operator.OpType.Decrement:
7256 case Operator.OpType.True:
7257 case Operator.OpType.False:
7258 case Operator.OpType.UnaryPlus:
7259 case Operator.OpType.UnaryNegation:
7265 void syntax_error (Location l, string msg)
7267 report.Error (1003, l, "Syntax error, " + msg);
7272 public Tokenizer Lexer {
7278 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7279 : this (reader, file, file.Compiler.Report, session)
7283 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7286 current_container = current_namespace = file;
7288 this.module = file.Module;
7289 this.compiler = file.Compiler;
7290 this.settings = compiler.Settings;
7291 this.report = report;
7293 lang_version = settings.Version;
7294 yacc_verbose_flag = settings.VerboseParserFlag;
7295 doc_support = settings.DocumentationFile != null;
7296 lexer = new Tokenizer (reader, file, session, report);
7297 oob_stack = new Stack<object> ();
7298 lbag = session.LocationsBag;
7299 use_global_stacks = session.UseJayGlobalArrays;
7300 parameters_bucket = session.ParametersStack;
7303 public void parse ()
7305 eof_token = Token.EOF;
7308 if (yacc_verbose_flag > 1)
7309 yyparse (lexer, new yydebug.yyDebugSimple ());
7313 Tokenizer tokenizer = lexer as Tokenizer;
7314 tokenizer.cleanup ();
7315 } catch (Exception e){
7316 if (e is yyParser.yyUnexpectedEof) {
7317 Error_SyntaxError (yyToken);
7318 UnexpectedEOF = true;
7322 if (e is yyParser.yyException) {
7323 if (report.Errors == 0)
7324 report.Error (-25, lexer.Location, "Parsing error");
7326 // Used by compiler-tester to test internal errors
7327 if (yacc_verbose_flag > 0 || e is FatalException)
7330 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7335 void CheckToken (int error, int yyToken, string msg, Location loc)
7337 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7338 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7340 report.Error (error, loc, msg);
7343 string ConsumeStoredComment ()
7345 string s = tmpComment;
7347 Lexer.doc_state = XmlCommentState.Allowed;
7351 void FeatureIsNotAvailable (Location loc, string feature)
7353 report.FeatureIsNotAvailable (compiler, loc, feature);
7356 Location GetLocation (object obj)
7358 var lt = obj as LocatedToken;
7362 var mn = obj as MemberName;
7366 var expr = obj as Expression;
7368 return expr.Location;
7370 return lexer.Location;
7373 void start_block (Location loc)
7375 if (current_block == null) {
7376 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7377 parsing_anonymous_method = false;
7378 } else if (parsing_anonymous_method) {
7379 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7380 parsing_anonymous_method = false;
7382 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7387 end_block (Location loc)
7389 Block retval = current_block.Explicit;
7390 retval.SetEndLocation (loc);
7391 current_block = retval.Parent;
7395 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7397 oob_stack.Push (current_anonymous_method);
7398 oob_stack.Push (current_local_parameters);
7399 oob_stack.Push (current_variable);
7400 oob_stack.Push (async_block);
7402 current_local_parameters = parameters;
7404 if (lang_version <= LanguageVersion.ISO_2)
7405 FeatureIsNotAvailable (loc, "lambda expressions");
7407 current_anonymous_method = new LambdaExpression (loc);
7409 if (lang_version == LanguageVersion.ISO_1)
7410 FeatureIsNotAvailable (loc, "anonymous methods");
7412 current_anonymous_method = new AnonymousMethodExpression (loc);
7415 async_block = isAsync;
7416 // Force the next block to be created as a ToplevelBlock
7417 parsing_anonymous_method = true;
7421 * Completes the anonymous method processing, if lambda_expr is null, this
7422 * means that we have a Statement instead of an Expression embedded
7424 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7426 AnonymousMethodExpression retval;
7429 anon_block.IsAsync = true;
7431 current_anonymous_method.Block = anon_block;
7432 retval = current_anonymous_method;
7434 async_block = (bool) oob_stack.Pop ();
7435 current_variable = (BlockVariable) oob_stack.Pop ();
7436 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7437 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7442 void Error_SyntaxError (int token)
7444 Error_SyntaxError (0, token);
7447 void Error_SyntaxError (int error_code, int token)
7449 Error_SyntaxError (error_code, token, "Unexpected symbol");
7452 void Error_SyntaxError (int error_code, int token, string msg)
7454 Lexer.CompleteOnEOF = false;
7456 // An error message has been reported by tokenizer
7457 if (token == Token.ERROR)
7460 // Avoid duplicit error message after unterminated string literals
7461 if (token == Token.LITERAL && lexer.Location.Column == 0)
7464 string symbol = GetSymbolName (token);
7465 string expecting = GetExpecting ();
7466 var loc = lexer.Location - symbol.Length;
7468 if (error_code == 0) {
7469 if (expecting == "`identifier'") {
7470 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7471 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7476 expecting = "identifier";
7477 } else if (expecting == "`)'") {
7484 if (string.IsNullOrEmpty (expecting))
7485 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7487 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7490 string GetExpecting ()
7492 int [] tokens = yyExpectingTokens (yyExpectingState);
7493 var names = new List<string> (tokens.Length);
7494 bool has_type = false;
7495 bool has_identifier = false;
7496 for (int i = 0; i < tokens.Length; i++){
7497 int token = tokens [i];
7498 has_identifier |= token == Token.IDENTIFIER;
7500 string name = GetTokenName (token);
7501 if (name == "<internal>")
7504 has_type |= name == "type";
7505 if (names.Contains (name))
7512 // Too many tokens to enumerate
7514 if (names.Count > 8)
7517 if (has_type && has_identifier)
7518 names.Remove ("identifier");
7520 if (names.Count == 1)
7521 return "`" + GetTokenName (tokens [0]) + "'";
7523 StringBuilder sb = new StringBuilder ();
7525 int count = names.Count;
7526 for (int i = 0; i < count; i++){
7527 bool last = i + 1 == count;
7531 sb.Append (names [i]);
7532 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7534 return sb.ToString ();
7538 string GetSymbolName (int token)
7542 return ((Constant)lexer.Value).GetValue ().ToString ();
7543 case Token.IDENTIFIER:
7544 return ((LocatedToken)lexer.Value).Value;
7586 case Token.BITWISE_AND:
7588 case Token.BITWISE_OR:
7602 case Token.OP_SHIFT_LEFT:
7604 case Token.OP_SHIFT_RIGHT:
7624 case Token.OP_COALESCING:
7626 case Token.OP_MULT_ASSIGN:
7628 case Token.OP_DIV_ASSIGN:
7630 case Token.OP_MOD_ASSIGN:
7632 case Token.OP_ADD_ASSIGN:
7634 case Token.OP_SUB_ASSIGN:
7636 case Token.OP_SHIFT_LEFT_ASSIGN:
7638 case Token.OP_SHIFT_RIGHT_ASSIGN:
7640 case Token.OP_AND_ASSIGN:
7642 case Token.OP_XOR_ASSIGN:
7644 case Token.OP_OR_ASSIGN:
7648 return GetTokenName (token);
7651 static string GetTokenName (int token)
7654 case Token.ABSTRACT:
7676 case Token.CONTINUE:
7680 case Token.DELEGATE:
7690 case Token.EXPLICIT:
7693 case Token.EXTERN_ALIAS:
7709 case Token.IMPLICIT:
7713 case Token.INTERFACE:
7715 case Token.INTERNAL:
7721 case Token.NAMESPACE:
7727 case Token.OPERATOR:
7731 case Token.OVERRIDE:
7737 case Token.PROTECTED:
7741 case Token.READONLY:
7753 case Token.STACKALLOC:
7754 return "stackalloc";
7771 case Token.UNCHECKED:
7779 case Token.VOLATILE:
7787 case Token.REFVALUE:
7788 return "__refvalue";
7798 case Token.FROM_FIRST:
7816 case Token.ASCENDING:
7818 case Token.DESCENDING:
7819 return "descending";
7826 case Token.OPEN_BRACE:
7828 case Token.CLOSE_BRACE:
7830 case Token.OPEN_BRACKET:
7831 case Token.OPEN_BRACKET_EXPR:
7833 case Token.CLOSE_BRACKET:
7835 case Token.OPEN_PARENS_CAST:
7836 case Token.OPEN_PARENS_LAMBDA:
7837 case Token.OPEN_PARENS:
7839 case Token.CLOSE_PARENS:
7845 case Token.DEFAULT_COLON:
7849 case Token.SEMICOLON:
7860 case Token.BITWISE_AND:
7861 case Token.BITWISE_OR:
7868 case Token.OP_SHIFT_LEFT:
7869 case Token.OP_SHIFT_RIGHT:
7877 case Token.OP_COALESCING:
7878 case Token.OP_MULT_ASSIGN:
7879 case Token.OP_DIV_ASSIGN:
7880 case Token.OP_MOD_ASSIGN:
7881 case Token.OP_ADD_ASSIGN:
7882 case Token.OP_SUB_ASSIGN:
7883 case Token.OP_SHIFT_LEFT_ASSIGN:
7884 case Token.OP_SHIFT_RIGHT_ASSIGN:
7885 case Token.OP_AND_ASSIGN:
7886 case Token.OP_XOR_ASSIGN:
7887 case Token.OP_OR_ASSIGN:
7888 return "<operator>";
7910 case Token.OP_GENERICS_LT:
7911 case Token.GENERIC_DIMENSION:
7913 case Token.OP_GENERICS_GT:
7916 case Token.INTERR_NULLABLE:
7918 case Token.DOUBLE_COLON:
7922 case Token.IDENTIFIER:
7924 return "identifier";
7927 return "end-of-file";
7929 // All of these are internal.
7932 case Token.FIRST_KEYWORD:
7933 case Token.EVAL_COMPILATION_UNIT_PARSER:
7934 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7935 case Token.EVAL_STATEMENT_PARSER:
7936 case Token.LAST_KEYWORD:
7937 case Token.GENERATE_COMPLETION:
7938 case Token.COMPLETE_COMPLETION:
7939 return "<internal>";
7941 // A bit more robust.
7943 return yyNames [token];