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 expression 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;
1853 : opt_attributes opt_modifiers
1854 member_type indexer_declaration_name OPEN_BRACKET
1856 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1858 opt_formal_parameter_list CLOSE_BRACKET
1860 valid_param_mod = 0;
1861 var type = (FullNamedExpression) $3;
1862 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1864 current_property = indexer;
1866 current_type.AddIndexer (indexer);
1867 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1869 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1870 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1872 if (indexer.ParameterInfo.IsEmpty) {
1873 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1877 tmpComment = Lexer.consume_doc_comment ();
1878 Lexer.doc_state = XmlCommentState.Allowed;
1881 lexer.PropertyParsing = true;
1882 current_local_parameters = (ParametersCompiled) $7;
1886 lexer.PropertyParsing = false;
1887 current_local_parameters = null;
1889 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1890 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1893 current_property.DocComment = ConsumeStoredComment ();
1895 current_property = null;
1900 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1902 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1906 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1907 current_property.Get.Block = (ToplevelBlock) $1;
1911 accessor_declarations
1912 : get_accessor_declaration
1913 | get_accessor_declaration accessor_declarations
1914 | set_accessor_declaration
1915 | set_accessor_declaration accessor_declarations
1918 if (yyToken == Token.CLOSE_BRACE) {
1919 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1921 if (yyToken == Token.SEMICOLON)
1922 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1924 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1929 get_accessor_declaration
1930 : opt_attributes opt_modifiers GET
1932 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1933 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1936 if (current_property.Get != null) {
1937 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1940 if (current_property is Indexer) {
1941 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1942 (Attributes) $1, GetLocation ($3));
1944 current_property.Get = new Property.GetMethod (current_property,
1945 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1948 current_local_parameters = current_property.Get.ParameterInfo;
1949 lbag.AddMember (current_property.Get, mod_locations);
1950 lexer.PropertyParsing = false;
1955 current_property.Get.Block = (ToplevelBlock) $5;
1957 if (current_container.Kind == MemberKind.Interface) {
1958 report.Error (531, current_property.Get.Block.StartLocation,
1959 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1963 current_local_parameters = null;
1964 lexer.PropertyParsing = true;
1967 if (Lexer.doc_state == XmlCommentState.Error)
1968 Lexer.doc_state = XmlCommentState.NotAllowed;
1972 set_accessor_declaration
1973 : opt_attributes opt_modifiers SET
1975 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1976 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1979 if (current_property.Set != null) {
1980 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1983 if (current_property is Indexer) {
1984 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1985 ParametersCompiled.MergeGenerated (compiler,
1986 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1987 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1989 (Attributes) $1, GetLocation ($3));
1991 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1992 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1993 (Attributes) $1, GetLocation ($3));
1996 current_local_parameters = current_property.Set.ParameterInfo;
1997 lbag.AddMember (current_property.Set, mod_locations);
1998 lexer.PropertyParsing = false;
2003 current_property.Set.Block = (ToplevelBlock) $5;
2005 if (current_container.Kind == MemberKind.Interface) {
2006 report.Error (531, current_property.Set.Block.StartLocation,
2007 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2011 current_local_parameters = null;
2012 lexer.PropertyParsing = true;
2015 && Lexer.doc_state == XmlCommentState.Error)
2016 Lexer.doc_state = XmlCommentState.NotAllowed;
2029 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2034 interface_declaration
2041 type_declaration_name
2043 lexer.ConstraintsParsing = true;
2044 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2045 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2048 opt_type_parameter_constraints_clauses
2050 lexer.ConstraintsParsing = false;
2053 current_container.SetConstraints ((List<Constraints>) $9);
2056 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2057 Lexer.doc_state = XmlCommentState.Allowed;
2060 lexer.parsing_modifiers = true;
2062 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2064 --lexer.parsing_declaration;
2066 Lexer.doc_state = XmlCommentState.Allowed;
2071 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2073 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2075 $$ = pop_current_class ();
2077 | opt_attributes opt_modifiers opt_partial INTERFACE error
2079 Error_SyntaxError (yyToken);
2083 opt_interface_member_declarations
2085 | interface_member_declarations
2088 interface_member_declarations
2089 : interface_member_declaration
2091 lexer.parsing_modifiers = true;
2092 lexer.parsing_block = 0;
2094 | interface_member_declarations interface_member_declaration
2096 lexer.parsing_modifiers = true;
2097 lexer.parsing_block = 0;
2101 interface_member_declaration
2102 : constant_declaration
2104 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2108 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2110 | method_declaration
2111 | property_declaration
2113 | indexer_declaration
2114 | operator_declaration
2116 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2118 | constructor_declaration
2120 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2124 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2128 operator_declaration
2129 : opt_attributes opt_modifiers operator_declarator
2132 method_body_expression_block
2134 OperatorDeclaration decl = (OperatorDeclaration) $3;
2136 Operator op = new Operator (
2137 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2138 current_local_parameters,
2139 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2141 if (op.Block == null)
2142 op.ParameterInfo.CheckParameters (op);
2145 op.DocComment = tmpComment;
2146 Lexer.doc_state = XmlCommentState.Allowed;
2149 // Note again, checking is done in semantic analysis
2150 current_type.AddOperator (op);
2152 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2155 current_local_parameters = null;
2160 : type_expression_or_array
2163 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2164 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2169 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2171 valid_param_mod = ParameterModifierType.DefaultValue;
2173 opt_formal_parameter_list CLOSE_PARENS
2175 valid_param_mod = 0;
2177 Location loc = GetLocation ($2);
2178 Operator.OpType op = (Operator.OpType) $3;
2179 current_local_parameters = (ParametersCompiled)$6;
2181 int p_count = current_local_parameters.Count;
2183 if (op == Operator.OpType.Addition)
2184 op = Operator.OpType.UnaryPlus;
2185 else if (op == Operator.OpType.Subtraction)
2186 op = Operator.OpType.UnaryNegation;
2189 if (IsUnaryOperator (op)) {
2191 report.Error (1020, loc, "Overloadable binary operator expected");
2192 } else if (p_count != 1) {
2193 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2194 Operator.GetName (op));
2198 report.Error (1019, loc, "Overloadable unary operator expected");
2199 } else if (p_count != 2) {
2200 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2201 Operator.GetName (op));
2206 tmpComment = Lexer.consume_doc_comment ();
2207 Lexer.doc_state = XmlCommentState.NotAllowed;
2210 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2211 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2213 | conversion_operator_declarator
2216 overloadable_operator
2218 : BANG { $$ = Operator.OpType.LogicalNot; }
2219 | TILDE { $$ = Operator.OpType.OnesComplement; }
2220 | OP_INC { $$ = Operator.OpType.Increment; }
2221 | OP_DEC { $$ = Operator.OpType.Decrement; }
2222 | TRUE { $$ = Operator.OpType.True; }
2223 | FALSE { $$ = Operator.OpType.False; }
2224 // Unary and binary:
2225 | PLUS { $$ = Operator.OpType.Addition; }
2226 | MINUS { $$ = Operator.OpType.Subtraction; }
2228 | STAR { $$ = Operator.OpType.Multiply; }
2229 | DIV { $$ = Operator.OpType.Division; }
2230 | PERCENT { $$ = Operator.OpType.Modulus; }
2231 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2232 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2233 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2234 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2235 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2236 | OP_EQ { $$ = Operator.OpType.Equality; }
2237 | OP_NE { $$ = Operator.OpType.Inequality; }
2238 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2239 | OP_LT { $$ = Operator.OpType.LessThan; }
2240 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2241 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2244 conversion_operator_declarator
2245 : IMPLICIT OPERATOR type OPEN_PARENS
2247 valid_param_mod = ParameterModifierType.DefaultValue;
2249 opt_formal_parameter_list CLOSE_PARENS
2251 valid_param_mod = 0;
2253 Location loc = GetLocation ($2);
2254 current_local_parameters = (ParametersCompiled)$6;
2256 if (current_local_parameters.Count != 1) {
2257 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2261 tmpComment = Lexer.consume_doc_comment ();
2262 Lexer.doc_state = XmlCommentState.NotAllowed;
2265 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2266 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2268 | EXPLICIT OPERATOR type OPEN_PARENS
2270 valid_param_mod = ParameterModifierType.DefaultValue;
2272 opt_formal_parameter_list CLOSE_PARENS
2274 valid_param_mod = 0;
2276 Location loc = GetLocation ($2);
2277 current_local_parameters = (ParametersCompiled)$6;
2279 if (current_local_parameters.Count != 1) {
2280 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2284 tmpComment = Lexer.consume_doc_comment ();
2285 Lexer.doc_state = XmlCommentState.NotAllowed;
2288 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2289 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2293 Error_SyntaxError (yyToken);
2294 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2295 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2299 Error_SyntaxError (yyToken);
2300 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2301 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2305 constructor_declaration
2306 : constructor_declarator
2309 Constructor c = (Constructor) $1;
2310 c.Block = (ToplevelBlock) $2;
2313 c.DocComment = ConsumeStoredComment ();
2315 current_local_parameters = null;
2317 Lexer.doc_state = XmlCommentState.Allowed;
2321 constructor_declarator
2327 tmpComment = Lexer.consume_doc_comment ();
2328 Lexer.doc_state = XmlCommentState.Allowed;
2331 valid_param_mod = ParameterModifierType.All;
2333 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2335 valid_param_mod = 0;
2336 current_local_parameters = (ParametersCompiled) $6;
2338 var lt = (LocatedToken) $3;
2339 var mods = (Modifiers) $2;
2340 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2342 if (lt.Value != current_container.MemberName.Name) {
2343 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2344 } else if ((mods & Modifiers.STATIC) != 0) {
2345 if ((mods & Modifiers.AccessibilityMask) != 0){
2346 report.Error (515, c.Location,
2347 "`{0}': static constructor cannot have an access modifier",
2348 c.GetSignatureForError ());
2352 current_type.AddConstructor (c);
2353 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2357 // start block here, so possible anonymous methods inside
2358 // constructor initializer can get correct parent block
2360 start_block (lexer.Location);
2362 opt_constructor_initializer
2365 var c = (Constructor) $8;
2366 c.Initializer = (ConstructorInitializer) $9;
2369 report.Error (514, c.Location,
2370 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2371 c.GetSignatureForError ());
2381 | SEMICOLON { current_block = null; $$ = null; }
2384 opt_constructor_initializer
2386 | constructor_initializer
2389 constructor_initializer
2390 : COLON BASE OPEN_PARENS
2392 ++lexer.parsing_block;
2394 opt_argument_list CLOSE_PARENS
2396 --lexer.parsing_block;
2397 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2398 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2400 | COLON THIS OPEN_PARENS
2402 ++lexer.parsing_block;
2404 opt_argument_list CLOSE_PARENS
2406 --lexer.parsing_block;
2407 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2408 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2412 Error_SyntaxError (yyToken);
2413 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2414 lbag.AddLocation ($$, GetLocation ($1));
2418 Error_SyntaxError (yyToken);
2423 destructor_declaration
2424 : opt_attributes opt_modifiers TILDE
2427 tmpComment = Lexer.consume_doc_comment ();
2428 Lexer.doc_state = XmlCommentState.NotAllowed;
2431 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2433 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2435 var lt = (LocatedToken) $5;
2436 if (lt.Value != current_container.MemberName.Name){
2437 report.Error (574, lt.Location, "Name of destructor must match name of class");
2438 } else if (current_container.Kind != MemberKind.Class){
2439 report.Error (575, lt.Location, "Only class types can contain destructor");
2442 Destructor d = new Destructor (current_type, (Modifiers) $2,
2443 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2445 d.DocComment = ConsumeStoredComment ();
2447 d.Block = (ToplevelBlock) $8;
2448 current_type.AddMember (d);
2449 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2451 current_local_parameters = null;
2458 EVENT type member_declaration_name
2460 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2461 current_type.AddMember (current_event_field);
2463 if (current_event_field.MemberName.ExplicitInterface != null) {
2464 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2465 current_event_field.GetSignatureForError ());
2468 $$ = current_event_field;
2470 opt_event_initializer
2471 opt_event_declarators
2475 current_event_field.DocComment = Lexer.consume_doc_comment ();
2476 Lexer.doc_state = XmlCommentState.Allowed;
2479 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2480 current_event_field = null;
2484 EVENT type member_declaration_name
2487 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2488 current_type.AddMember (current_event);
2489 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2491 lexer.EventParsing = true;
2493 event_accessor_declarations
2495 if (current_container.Kind == MemberKind.Interface)
2496 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2498 lexer.EventParsing = false;
2503 current_event.DocComment = Lexer.consume_doc_comment ();
2504 Lexer.doc_state = XmlCommentState.Allowed;
2507 lbag.AppendToMember (current_event, GetLocation ($9));
2508 current_event = null;
2509 current_local_parameters = null;
2515 Error_SyntaxError (yyToken);
2517 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2521 opt_event_initializer
2525 ++lexer.parsing_block;
2527 event_variable_initializer
2529 --lexer.parsing_block;
2530 current_event_field.Initializer = (Expression) $3;
2534 opt_event_declarators
2542 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2544 | event_declarators event_declarator
2546 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2553 var lt = (LocatedToken) $2;
2554 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2555 lbag.AddLocation ($$, GetLocation ($1));
2557 | COMMA IDENTIFIER ASSIGN
2559 ++lexer.parsing_block;
2561 event_variable_initializer
2563 --lexer.parsing_block;
2564 var lt = (LocatedToken) $2;
2565 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2566 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2570 event_variable_initializer
2572 if (current_container.Kind == MemberKind.Interface) {
2573 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2574 current_event_field.GetSignatureForError ());
2577 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2578 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2579 current_event_field.GetSignatureForError ());
2582 variable_initializer
2588 event_accessor_declarations
2589 : add_accessor_declaration remove_accessor_declaration
2590 | remove_accessor_declaration add_accessor_declaration
2591 | add_accessor_declaration
2593 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2594 current_event.GetSignatureForError ());
2596 | remove_accessor_declaration
2598 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2599 current_event.GetSignatureForError ());
2603 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2608 add_accessor_declaration
2609 : opt_attributes opt_modifiers ADD
2611 if ($2 != ModifierNone) {
2612 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2615 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2616 current_local_parameters = current_event.Add.ParameterInfo;
2618 lbag.AddMember (current_event.Add, mod_locations);
2619 lexer.EventParsing = false;
2621 event_accessor_block
2623 lexer.EventParsing = true;
2625 current_event.Add.Block = (ToplevelBlock) $5;
2627 if (current_container.Kind == MemberKind.Interface) {
2628 report.Error (531, current_event.Add.Block.StartLocation,
2629 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2632 current_local_parameters = null;
2636 remove_accessor_declaration
2637 : opt_attributes opt_modifiers REMOVE
2639 if ($2 != ModifierNone) {
2640 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2643 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2644 current_local_parameters = current_event.Remove.ParameterInfo;
2646 lbag.AddMember (current_event.Remove, mod_locations);
2647 lexer.EventParsing = false;
2649 event_accessor_block
2651 lexer.EventParsing = true;
2653 current_event.Remove.Block = (ToplevelBlock) $5;
2655 if (current_container.Kind == MemberKind.Interface) {
2656 report.Error (531, current_event.Remove.Block.StartLocation,
2657 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2660 current_local_parameters = null;
2664 event_accessor_block
2667 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2673 attributes_without_members
2674 : attribute_sections CLOSE_BRACE
2676 current_type.UnattachedAttributes = (Attributes) $1;
2677 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2678 lexer.putback ('}');
2682 // For full ast try to recover incomplete ambiguous member
2683 // declaration in form on class X { public int }
2685 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2687 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2689 lexer.putback ('}');
2691 lexer.parsing_generic_declaration = false;
2692 FullNamedExpression type = (FullNamedExpression) $3;
2693 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2694 current_type.AddField (current_field);
2702 ENUM type_declaration_name
2706 enumTypeComment = Lexer.consume_doc_comment ();
2711 Lexer.doc_state = XmlCommentState.Allowed;
2713 MemberName name = (MemberName) $4;
2714 if (name.IsGeneric) {
2715 report.Error (1675, name.Location, "Enums cannot have type parameters");
2718 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2720 opt_enum_member_declarations
2722 lexer.parsing_modifiers = true;
2724 // here will be evaluated after CLOSE_BLACE is consumed.
2726 Lexer.doc_state = XmlCommentState.Allowed;
2728 CLOSE_BRACE opt_semicolon
2731 current_container.DocComment = enumTypeComment;
2733 --lexer.parsing_declaration;
2736 // em.DocComment = ev.DocComment;
2738 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2739 $$ = pop_current_class ();
2747 var te = $2 as TypeExpression;
2748 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2749 Enum.Error_1008 (GetLocation ($2), report);
2755 Error_TypeExpected (GetLocation ($1));
2760 opt_enum_member_declarations
2762 | enum_member_declarations
2763 | enum_member_declarations COMMA
2765 lbag.AddLocation ($1, GetLocation ($2));
2769 enum_member_declarations
2770 : enum_member_declaration
2771 | enum_member_declarations COMMA enum_member_declaration
2773 lbag.AddLocation ($1, GetLocation ($2));
2778 enum_member_declaration
2779 : opt_attributes IDENTIFIER
2781 var lt = (LocatedToken) $2;
2782 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2783 ((Enum) current_type).AddEnumMember (em);
2786 em.DocComment = Lexer.consume_doc_comment ();
2787 Lexer.doc_state = XmlCommentState.Allowed;
2792 | opt_attributes IDENTIFIER
2794 ++lexer.parsing_block;
2796 tmpComment = Lexer.consume_doc_comment ();
2797 Lexer.doc_state = XmlCommentState.NotAllowed;
2800 ASSIGN constant_expression
2802 --lexer.parsing_block;
2804 var lt = (LocatedToken) $2;
2805 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2806 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2807 ((Enum) current_type).AddEnumMember (em);
2810 em.DocComment = ConsumeStoredComment ();
2814 | opt_attributes IDENTIFIER error
2816 Error_SyntaxError (yyToken);
2818 var lt = (LocatedToken) $2;
2819 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2820 ((Enum) current_type).AddEnumMember (em);
2823 em.DocComment = Lexer.consume_doc_comment ();
2824 Lexer.doc_state = XmlCommentState.Allowed;
2829 | attributes_without_members
2832 delegate_declaration
2836 member_type type_declaration_name
2839 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2841 opt_formal_parameter_list CLOSE_PARENS
2843 valid_param_mod = 0;
2845 ParametersCompiled p = (ParametersCompiled) $8;
2847 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2849 p.CheckParameters (del);
2851 current_container.AddTypeContainer (del);
2853 current_delegate = del;
2854 lexer.ConstraintsParsing = true;
2856 opt_type_parameter_constraints_clauses
2858 lexer.ConstraintsParsing = false;
2863 current_delegate.DocComment = Lexer.consume_doc_comment ();
2864 Lexer.doc_state = XmlCommentState.Allowed;
2868 current_delegate.SetConstraints ((List<Constraints>) $11);
2869 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2871 $$ = current_delegate;
2873 current_delegate = null;
2881 if (lang_version < LanguageVersion.ISO_2)
2882 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2884 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2888 namespace_or_type_expr
2890 | qualified_alias_member IDENTIFIER opt_type_argument_list
2892 var lt1 = (LocatedToken) $1;
2893 var lt2 = (LocatedToken) $2;
2895 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2896 lbag.AddLocation ($$, GetLocation ($2));
2902 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2904 var lt = (LocatedToken) $3;
2905 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2906 lbag.AddLocation ($$, GetLocation ($2));
2911 : IDENTIFIER opt_type_argument_list
2913 var lt = (LocatedToken) $1;
2914 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2919 // Generics arguments (any type, without attributes)
2921 opt_type_argument_list
2923 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2925 if (lang_version < LanguageVersion.ISO_2)
2926 FeatureIsNotAvailable (GetLocation ($1), "generics");
2930 | OP_GENERICS_LT error
2932 Error_TypeExpected (lexer.Location);
2933 $$ = new TypeArguments ();
2940 TypeArguments type_args = new TypeArguments ();
2941 type_args.Add ((FullNamedExpression) $1);
2944 | type_arguments COMMA type
2946 TypeArguments type_args = (TypeArguments) $1;
2947 type_args.Add ((FullNamedExpression) $3);
2953 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2955 type_declaration_name
2958 lexer.parsing_generic_declaration = true;
2960 opt_type_parameter_list
2962 lexer.parsing_generic_declaration = false;
2963 var lt = (LocatedToken) $1;
2964 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2968 member_declaration_name
2969 : method_declaration_name
2971 MemberName mn = (MemberName)$1;
2972 if (mn.TypeParameters != null)
2973 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2974 mn.GetSignatureForError ()));
2978 method_declaration_name
2979 : type_declaration_name
2980 | explicit_interface IDENTIFIER opt_type_parameter_list
2982 lexer.parsing_generic_declaration = false;
2983 var lt = (LocatedToken) $2;
2984 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2988 indexer_declaration_name
2991 lexer.parsing_generic_declaration = false;
2992 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2994 | explicit_interface THIS
2996 lexer.parsing_generic_declaration = false;
2997 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3002 : IDENTIFIER opt_type_argument_list DOT
3004 var lt = (LocatedToken) $1;
3005 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3006 lbag.AddLocation ($$, GetLocation ($3));
3008 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3010 var lt1 = (LocatedToken) $1;
3011 var lt2 = (LocatedToken) $2;
3013 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3014 lbag.AddLocation ($$, GetLocation ($4));
3016 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3018 var lt = (LocatedToken) $2;
3019 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3020 lbag.AddLocation ($$, GetLocation ($4));
3024 opt_type_parameter_list
3026 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3028 if (lang_version < LanguageVersion.ISO_2)
3029 FeatureIsNotAvailable (GetLocation ($1), "generics");
3032 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3039 var tparams = new TypeParameters ();
3040 tparams.Add ((TypeParameter)$1);
3043 | type_parameters COMMA type_parameter
3045 var tparams = (TypeParameters) $1;
3046 tparams.Add ((TypeParameter)$3);
3048 lbag.AddLocation ($3, GetLocation ($3));
3053 : opt_attributes opt_type_parameter_variance IDENTIFIER
3055 var lt = (LocatedToken)$3;
3056 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3060 if (GetTokenName (yyToken) == "type")
3061 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3063 Error_SyntaxError (yyToken);
3065 $$ = new TypeParameter (MemberName.Null, null, null);
3070 // All types where void is allowed
3073 : type_expression_or_array
3076 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3083 lexer.parsing_generic_declaration = true;
3088 // A type which does not allow `void' to be used
3091 : type_expression_or_array
3094 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3095 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3103 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3104 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3109 : type_expression_or_array
3112 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3113 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3117 type_expression_or_array
3119 | type_expression rank_specifiers
3121 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3126 : namespace_or_type_expr opt_nullable
3129 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3131 var sn = $1 as SimpleName;
3132 if (sn != null && sn.Name == "var")
3133 $$ = new VarExpr (sn.Location);
3138 | namespace_or_type_expr pointer_stars
3140 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3142 | builtin_types opt_nullable
3145 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3147 | builtin_types pointer_stars
3149 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3151 | VOID pointer_stars
3153 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3160 var types = new List<FullNamedExpression> (2);
3161 types.Add ((FullNamedExpression) $1);
3164 | type_list COMMA base_type_name
3166 var types = (List<FullNamedExpression>) $1;
3167 types.Add ((FullNamedExpression) $3);
3175 if ($1 is ComposedCast) {
3176 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3183 * replaces all the productions for isolating the various
3184 * simple types, but we need this to reuse it easily in variable_type
3187 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3188 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3189 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3190 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3191 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3192 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3197 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3198 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3199 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3200 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3201 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3202 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3203 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3204 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3205 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3209 // Expressions, section 7.5
3214 : primary_expression_or_type
3216 | array_creation_expression
3217 | parenthesized_expression
3218 | default_value_expression
3219 | invocation_expression
3223 | post_increment_expression
3224 | post_decrement_expression
3225 | object_or_delegate_creation_expression
3226 | anonymous_type_expression
3229 | checked_expression
3230 | unchecked_expression
3231 | pointer_member_access
3232 | anonymous_method_expression
3233 | undocumented_expressions
3236 primary_expression_or_type
3237 : IDENTIFIER opt_type_argument_list
3239 var lt = (LocatedToken) $1;
3240 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3242 | IDENTIFIER GENERATE_COMPLETION {
3243 var lt = (LocatedToken) $1;
3244 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3252 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3256 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3257 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3262 // Here is the trick, tokenizer may think that parens is a special but
3263 // parser is interested in open parens only, so we merge them.
3264 // Consider: if (a)foo ();
3272 // Use this production to accept closing parenthesis or
3273 // performing completion
3277 | COMPLETE_COMPLETION
3281 parenthesized_expression
3282 : OPEN_PARENS expression CLOSE_PARENS
3284 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3285 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3287 | OPEN_PARENS expression COMPLETE_COMPLETION
3289 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3294 : primary_expression DOT identifier_inside_body opt_type_argument_list
3296 var lt = (LocatedToken) $3;
3297 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3298 lbag.AddLocation ($$, GetLocation ($2));
3300 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3302 if (lang_version < LanguageVersion.V_6)
3303 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3305 var lt = (LocatedToken) $4;
3306 $$ = new NullMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3307 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3309 | builtin_types DOT identifier_inside_body opt_type_argument_list
3311 var lt = (LocatedToken) $3;
3312 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3313 lbag.AddLocation ($$, GetLocation ($2));
3315 | BASE DOT identifier_inside_body opt_type_argument_list
3317 var lt = (LocatedToken) $3;
3318 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3319 lbag.AddLocation ($$, GetLocation ($2));
3321 | AWAIT DOT identifier_inside_body opt_type_argument_list
3323 var lt = (LocatedToken) $3;
3324 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3325 lbag.AddLocation ($$, GetLocation ($2));
3327 | qualified_alias_member identifier_inside_body opt_type_argument_list
3329 var lt1 = (LocatedToken) $1;
3330 var lt2 = (LocatedToken) $2;
3332 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3333 lbag.AddLocation ($$, GetLocation ($2));
3335 | primary_expression DOT GENERATE_COMPLETION {
3336 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3338 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3339 var lt = (LocatedToken) $3;
3340 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3342 | builtin_types DOT GENERATE_COMPLETION
3344 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3346 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3347 var lt = (LocatedToken) $3;
3348 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3352 invocation_expression
3353 : primary_expression open_parens_any opt_argument_list close_parens
3355 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3356 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3358 | primary_expression open_parens_any argument_list error
3360 Error_SyntaxError (yyToken);
3362 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3363 lbag.AddLocation ($$, GetLocation ($2));
3365 | primary_expression open_parens_any error
3367 Error_SyntaxError (yyToken);
3369 $$ = new Invocation ((Expression) $1, null);
3370 lbag.AddLocation ($$, GetLocation ($2));
3374 opt_object_or_collection_initializer
3375 : /* empty */ { $$ = null; }
3376 | object_or_collection_initializer
3379 object_or_collection_initializer
3380 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3383 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3385 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3387 lbag.AddLocation ($$, GetLocation ($3));
3389 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3391 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3392 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3396 opt_member_initializer_list
3397 : /* empty */ { $$ = null; }
3398 | member_initializer_list
3404 member_initializer_list
3405 : member_initializer
3407 var a = new List<Expression> ();
3408 a.Add ((Expression) $1);
3411 | member_initializer_list COMMA member_initializer
3413 var a = (List<Expression>)$1;
3414 a.Add ((Expression) $3);
3417 | member_initializer_list error {
3418 Error_SyntaxError (yyToken);
3424 : IDENTIFIER ASSIGN initializer_value
3426 var lt = (LocatedToken) $1;
3427 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3428 lbag.AddLocation ($$, GetLocation ($2));
3430 | AWAIT ASSIGN initializer_value
3432 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3433 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3434 lbag.AddLocation ($$, GetLocation ($2));
3436 | GENERATE_COMPLETION
3438 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3440 | non_assignment_expression opt_COMPLETE_COMPLETION {
3441 CompletionSimpleName csn = $1 as CompletionSimpleName;
3443 $$ = new CollectionElementInitializer ((Expression)$1);
3445 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3447 | OPEN_BRACE expression_list CLOSE_BRACE
3450 $$ = new CollectionElementInitializer (GetLocation ($1));
3452 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3454 lbag.AddLocation ($$, GetLocation ($2));
3456 | OPEN_BRACE CLOSE_BRACE
3458 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3459 $$ = new CollectionElementInitializer (GetLocation ($1));
3460 lbag.AddLocation ($$, GetLocation ($2));
3466 | object_or_collection_initializer
3470 : /* empty */ { $$ = null; }
3475 : argument_or_named_argument
3477 Arguments list = new Arguments (4);
3478 list.Add ((Argument) $1);
3481 | argument_list COMMA argument
3483 Arguments list = (Arguments) $1;
3484 if (list [list.Count - 1] is NamedArgument)
3485 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3487 list.Add ((Argument) $3);
3490 | argument_list COMMA named_argument
3492 Arguments list = (Arguments) $1;
3493 NamedArgument a = (NamedArgument) $3;
3494 for (int i = 0; i < list.Count; ++i) {
3495 NamedArgument na = list [i] as NamedArgument;
3496 if (na != null && na.Name == a.Name)
3497 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3504 | argument_list COMMA error
3506 if (lexer.putback_char == -1)
3507 lexer.putback (')'); // TODO: Wrong but what can I do
3508 Error_SyntaxError (yyToken);
3513 report.Error (839, GetLocation ($1), "An argument is missing");
3521 $$ = new Argument ((Expression) $1);
3523 | non_simple_argument
3526 argument_or_named_argument
3532 : REF variable_reference
3534 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3535 lbag.AddLocation ($$, GetLocation ($1));
3537 | OUT variable_reference
3539 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3540 lbag.AddLocation ($$, GetLocation ($1));
3542 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3544 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3545 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3547 | ARGLIST OPEN_PARENS CLOSE_PARENS
3549 $$ = new Argument (new Arglist (GetLocation ($1)));
3550 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3559 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3561 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3562 lbag.AddLocation ($$, GetLocation ($4));
3564 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3566 if (lang_version < LanguageVersion.V_6)
3567 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3569 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3570 NullPropagating = true
3573 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3575 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3577 Error_SyntaxError (yyToken);
3578 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3580 | primary_expression OPEN_BRACKET_EXPR error
3582 Error_SyntaxError (yyToken);
3583 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3588 : expression_or_error
3590 var list = new List<Expression> (4);
3591 list.Add ((Expression) $1);
3594 | expression_list COMMA expression_or_error
3596 var list = (List<Expression>) $1;
3597 list.Add ((Expression) $3);
3602 expression_list_arguments
3603 : expression_list_argument
3605 Arguments args = new Arguments (4);
3606 args.Add ((Argument) $1);
3609 | expression_list_arguments COMMA expression_list_argument
3611 Arguments args = (Arguments) $1;
3612 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3613 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3615 args.Add ((Argument) $3);
3620 expression_list_argument
3623 $$ = new Argument ((Expression) $1);
3631 $$ = new This (GetLocation ($1));
3636 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3638 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3639 lbag.AddLocation ($$, GetLocation ($4));
3641 | BASE OPEN_BRACKET error
3643 Error_SyntaxError (yyToken);
3644 $$ = new ElementAccess (null, null, GetLocation ($2));
3648 post_increment_expression
3649 : primary_expression OP_INC
3651 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3655 post_decrement_expression
3656 : primary_expression OP_DEC
3658 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3662 object_or_delegate_creation_expression
3663 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3666 if (lang_version <= LanguageVersion.ISO_2)
3667 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3669 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3671 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3674 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3676 | NEW new_expr_type object_or_collection_initializer
3678 if (lang_version <= LanguageVersion.ISO_2)
3679 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3681 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3685 array_creation_expression
3686 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3688 opt_array_initializer
3690 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3691 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3692 Next = (ComposedTypeSpecifier) $6
3693 }, (ArrayInitializer) $7, GetLocation ($1));
3694 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3696 | NEW new_expr_type rank_specifiers opt_array_initializer
3699 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3701 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3703 | NEW rank_specifier array_initializer
3705 if (lang_version <= LanguageVersion.ISO_2)
3706 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3708 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3710 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3712 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3713 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3715 | NEW new_expr_type error
3717 Error_SyntaxError (yyToken);
3718 // It can be any of new expression, create the most common one
3719 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3725 ++lexer.parsing_type;
3729 --lexer.parsing_type;
3734 anonymous_type_expression
3735 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3737 if (lang_version <= LanguageVersion.ISO_2)
3738 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3740 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3742 // TODO: lbag comma location
3743 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3745 | NEW OPEN_BRACE GENERATE_COMPLETION
3747 $$ = new EmptyCompletion ();
3751 anonymous_type_parameters_opt_comma
3752 : anonymous_type_parameters_opt
3753 | anonymous_type_parameters COMMA
3756 anonymous_type_parameters_opt
3758 | anonymous_type_parameters
3761 anonymous_type_parameters
3762 : anonymous_type_parameter
3764 var a = new List<AnonymousTypeParameter> (4);
3765 a.Add ((AnonymousTypeParameter) $1);
3768 | anonymous_type_parameters COMMA anonymous_type_parameter
3770 var a = (List<AnonymousTypeParameter>) $1;
3771 a.Add ((AnonymousTypeParameter) $3);
3774 | COMPLETE_COMPLETION
3776 $$ = new EmptyCompletion ();
3778 | anonymous_type_parameter COMPLETE_COMPLETION
3784 anonymous_type_parameter
3785 : identifier_inside_body ASSIGN variable_initializer
3787 var lt = (LocatedToken)$1;
3788 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3789 lbag.AddLocation ($$, GetLocation ($2));
3791 | identifier_inside_body
3793 var lt = (LocatedToken)$1;
3794 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3795 lt.Value, lt.Location);
3799 MemberAccess ma = (MemberAccess) $1;
3800 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3804 report.Error (746, lexer.Location,
3805 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3817 | rank_specifier rank_specifiers
3819 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3825 : OPEN_BRACKET CLOSE_BRACKET
3827 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3828 lbag.AddLocation ($$, GetLocation ($2));
3830 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3832 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3833 lbag.AddLocation ($$, GetLocation ($3));
3842 | dim_separators COMMA
3844 $$ = ((int) $1) + 1;
3848 opt_array_initializer
3860 : OPEN_BRACE CLOSE_BRACE
3862 var ai = new ArrayInitializer (0, GetLocation ($1));
3863 ai.VariableDeclaration = current_variable;
3864 lbag.AddLocation (ai, GetLocation ($2));
3867 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3869 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3870 ai.VariableDeclaration = current_variable;
3872 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3874 lbag.AddLocation (ai, GetLocation ($4));
3880 variable_initializer_list
3881 : variable_initializer
3883 var list = new List<Expression> (4);
3884 list.Add ((Expression) $1);
3887 | variable_initializer_list COMMA variable_initializer
3889 var list = (List<Expression>) $1;
3890 list.Add ((Expression) $3);
3898 lexer.TypeOfParsing = true;
3900 open_parens_any typeof_type_expression CLOSE_PARENS
3902 lexer.TypeOfParsing = false;
3903 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3904 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3908 typeof_type_expression
3913 Error_TypeExpected (lexer.Location);
3919 : identifier_inside_body generic_dimension
3921 var lt = (LocatedToken) $1;
3923 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3925 | qualified_alias_member identifier_inside_body generic_dimension
3927 var lt1 = (LocatedToken) $1;
3928 var lt2 = (LocatedToken) $2;
3930 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3931 lbag.AddLocation ($$, GetLocation ($2));
3933 | unbound_type_name DOT identifier_inside_body
3935 var lt = (LocatedToken) $3;
3937 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3939 | unbound_type_name DOT identifier_inside_body generic_dimension
3941 var lt = (LocatedToken) $3;
3943 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3945 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3947 var tne = (ATypeNameExpression) $1;
3948 if (tne.HasTypeArguments)
3949 Error_TypeExpected (GetLocation ($4));
3951 var lt = (LocatedToken) $3;
3952 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3959 if (lang_version < LanguageVersion.ISO_2)
3960 FeatureIsNotAvailable (GetLocation ($1), "generics");
3966 qualified_alias_member
3967 : IDENTIFIER DOUBLE_COLON
3969 var lt = (LocatedToken) $1;
3970 if (lang_version == LanguageVersion.ISO_1)
3971 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3978 : SIZEOF open_parens_any type CLOSE_PARENS
3980 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3981 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3983 | SIZEOF open_parens_any type error
3985 Error_SyntaxError (yyToken);
3987 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3988 lbag.AddLocation ($$, GetLocation ($2));
3993 : CHECKED open_parens_any expression CLOSE_PARENS
3995 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3996 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4000 Error_SyntaxError (yyToken);
4002 $$ = new CheckedExpr (null, GetLocation ($1));
4006 unchecked_expression
4007 : UNCHECKED open_parens_any expression CLOSE_PARENS
4009 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4010 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4014 Error_SyntaxError (yyToken);
4016 $$ = new UnCheckedExpr (null, GetLocation ($1));
4020 pointer_member_access
4021 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4023 var lt = (LocatedToken) $3;
4024 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4028 anonymous_method_expression
4029 : DELEGATE opt_anonymous_method_signature
4031 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4035 $$ = end_anonymous ((ParametersBlock) $4);
4037 | ASYNC DELEGATE opt_anonymous_method_signature
4039 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4043 $$ = end_anonymous ((ParametersBlock) $5);
4047 opt_anonymous_method_signature
4050 $$ = ParametersCompiled.Undefined;
4052 | anonymous_method_signature
4055 anonymous_method_signature
4058 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4060 opt_formal_parameter_list CLOSE_PARENS
4062 valid_param_mod = 0;
4067 default_value_expression
4068 : DEFAULT open_parens_any type CLOSE_PARENS
4070 if (lang_version < LanguageVersion.ISO_2)
4071 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4073 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4074 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4079 : primary_expression
4080 | BANG prefixed_unary_expression
4082 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4084 | TILDE prefixed_unary_expression
4086 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4088 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4090 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4091 lbag.AddLocation ($$, GetLocation ($3));
4093 | AWAIT prefixed_unary_expression
4096 if (current_anonymous_method is LambdaExpression) {
4097 report.Error (4034, GetLocation ($1),
4098 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4099 } else if (current_anonymous_method != null) {
4100 report.Error (4035, GetLocation ($1),
4101 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4102 } else if (interactive_async != null) {
4103 current_block.Explicit.RegisterAsyncAwait ();
4104 interactive_async = true;
4106 report.Error (4033, GetLocation ($1),
4107 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4110 current_block.Explicit.RegisterAsyncAwait ();
4113 $$ = new Await ((Expression) $2, GetLocation ($1));
4117 Error_SyntaxError (yyToken);
4119 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4123 Error_SyntaxError (yyToken);
4125 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4127 | OPEN_PARENS_CAST type CLOSE_PARENS error
4129 Error_SyntaxError (yyToken);
4131 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4132 lbag.AddLocation ($$, GetLocation ($3));
4136 Error_SyntaxError (yyToken);
4138 $$ = new Await (null, GetLocation ($1));
4143 // The idea to split this out is from Rhys' grammar
4144 // to solve the problem with casts.
4146 prefixed_unary_expression
4148 | PLUS prefixed_unary_expression
4150 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4152 | MINUS prefixed_unary_expression
4154 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4156 | OP_INC prefixed_unary_expression
4158 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4160 | OP_DEC prefixed_unary_expression
4162 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4164 | STAR prefixed_unary_expression
4166 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4168 | BITWISE_AND prefixed_unary_expression
4170 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4174 Error_SyntaxError (yyToken);
4176 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4180 Error_SyntaxError (yyToken);
4182 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4186 Error_SyntaxError (yyToken);
4188 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4192 Error_SyntaxError (yyToken);
4194 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4198 Error_SyntaxError (yyToken);
4200 $$ = new Indirection (null, GetLocation ($1));
4204 Error_SyntaxError (yyToken);
4206 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4210 multiplicative_expression
4211 : prefixed_unary_expression
4212 | multiplicative_expression STAR prefixed_unary_expression
4214 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4215 lbag.AddLocation ($$, GetLocation ($2));
4217 | multiplicative_expression DIV prefixed_unary_expression
4219 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4220 lbag.AddLocation ($$, GetLocation ($2));
4222 | multiplicative_expression PERCENT prefixed_unary_expression
4224 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4225 lbag.AddLocation ($$, GetLocation ($2));
4227 | multiplicative_expression STAR error
4229 Error_SyntaxError (yyToken);
4231 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4232 lbag.AddLocation ($$, GetLocation ($2));
4234 | multiplicative_expression DIV error
4236 Error_SyntaxError (yyToken);
4238 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4239 lbag.AddLocation ($$, GetLocation ($2));
4241 | multiplicative_expression PERCENT error
4243 Error_SyntaxError (yyToken);
4245 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4246 lbag.AddLocation ($$, GetLocation ($2));
4251 : multiplicative_expression
4252 | additive_expression PLUS multiplicative_expression
4254 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4255 lbag.AddLocation ($$, GetLocation ($2));
4257 | additive_expression MINUS multiplicative_expression
4259 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4260 lbag.AddLocation ($$, GetLocation ($2));
4262 | additive_expression AS type
4264 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4266 | additive_expression IS type
4268 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4270 | additive_expression PLUS error
4272 Error_SyntaxError (yyToken);
4274 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4275 lbag.AddLocation ($$, GetLocation ($2));
4277 | additive_expression MINUS error
4279 Error_SyntaxError (yyToken);
4281 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4282 lbag.AddLocation ($$, GetLocation ($2));
4284 | additive_expression AS error
4286 Error_SyntaxError (yyToken);
4288 $$ = new As ((Expression) $1, null, GetLocation ($2));
4290 | additive_expression IS error
4292 Error_SyntaxError (yyToken);
4294 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4298 var lt = (LocatedToken) $1;
4299 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4303 var lt = (LocatedToken) $1;
4304 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4309 : additive_expression
4310 | shift_expression OP_SHIFT_LEFT additive_expression
4312 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4313 lbag.AddLocation ($$, GetLocation ($2));
4315 | shift_expression OP_SHIFT_RIGHT additive_expression
4317 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4318 lbag.AddLocation ($$, GetLocation ($2));
4320 | shift_expression OP_SHIFT_LEFT error
4322 Error_SyntaxError (yyToken);
4324 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4325 lbag.AddLocation ($$, GetLocation ($2));
4327 | shift_expression OP_SHIFT_RIGHT error
4329 Error_SyntaxError (yyToken);
4331 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4332 lbag.AddLocation ($$, GetLocation ($2));
4336 relational_expression
4338 | relational_expression OP_LT shift_expression
4340 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4341 lbag.AddLocation ($$, GetLocation ($2));
4343 | relational_expression OP_GT shift_expression
4345 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4346 lbag.AddLocation ($$, GetLocation ($2));
4348 | relational_expression OP_LE shift_expression
4350 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4351 lbag.AddLocation ($$, GetLocation ($2));
4353 | relational_expression OP_GE shift_expression
4355 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4356 lbag.AddLocation ($$, GetLocation ($2));
4358 | relational_expression OP_LT error
4360 Error_SyntaxError (yyToken);
4362 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4363 lbag.AddLocation ($$, GetLocation ($2));
4365 | relational_expression OP_GT error
4367 Error_SyntaxError (yyToken);
4369 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4370 lbag.AddLocation ($$, GetLocation ($2));
4372 | relational_expression OP_LE error
4374 Error_SyntaxError (yyToken);
4376 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4377 lbag.AddLocation ($$, GetLocation ($2));
4379 | relational_expression OP_GE error
4381 Error_SyntaxError (yyToken);
4383 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4384 lbag.AddLocation ($$, GetLocation ($2));
4389 : relational_expression
4390 | equality_expression OP_EQ relational_expression
4392 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4393 lbag.AddLocation ($$, GetLocation ($2));
4395 | equality_expression OP_NE relational_expression
4397 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4398 lbag.AddLocation ($$, GetLocation ($2));
4400 | equality_expression OP_EQ error
4402 Error_SyntaxError (yyToken);
4404 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4405 lbag.AddLocation ($$, GetLocation ($2));
4407 | equality_expression OP_NE error
4409 Error_SyntaxError (yyToken);
4411 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4412 lbag.AddLocation ($$, GetLocation ($2));
4417 : equality_expression
4418 | and_expression BITWISE_AND equality_expression
4420 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4421 lbag.AddLocation ($$, GetLocation ($2));
4423 | and_expression BITWISE_AND error
4425 Error_SyntaxError (yyToken);
4427 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4428 lbag.AddLocation ($$, GetLocation ($2));
4432 exclusive_or_expression
4434 | exclusive_or_expression CARRET and_expression
4436 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4437 lbag.AddLocation ($$, GetLocation ($2));
4439 | exclusive_or_expression CARRET error
4441 Error_SyntaxError (yyToken);
4443 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4444 lbag.AddLocation ($$, GetLocation ($2));
4448 inclusive_or_expression
4449 : exclusive_or_expression
4450 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4452 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4453 lbag.AddLocation ($$, GetLocation ($2));
4455 | inclusive_or_expression BITWISE_OR error
4457 Error_SyntaxError (yyToken);
4459 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4460 lbag.AddLocation ($$, GetLocation ($2));
4464 conditional_and_expression
4465 : inclusive_or_expression
4466 | conditional_and_expression OP_AND inclusive_or_expression
4468 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4469 lbag.AddLocation ($$, GetLocation ($2));
4471 | conditional_and_expression OP_AND error
4473 Error_SyntaxError (yyToken);
4475 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4476 lbag.AddLocation ($$, GetLocation ($2));
4480 conditional_or_expression
4481 : conditional_and_expression
4482 | conditional_or_expression OP_OR conditional_and_expression
4484 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4485 lbag.AddLocation ($$, GetLocation ($2));
4487 | conditional_or_expression OP_OR error
4489 Error_SyntaxError (yyToken);
4491 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4492 lbag.AddLocation ($$, GetLocation ($2));
4496 null_coalescing_expression
4497 : conditional_or_expression
4498 | conditional_or_expression OP_COALESCING null_coalescing_expression
4500 if (lang_version < LanguageVersion.ISO_2)
4501 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4503 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4504 lbag.AddLocation ($$, GetLocation ($2));
4508 conditional_expression
4509 : null_coalescing_expression
4510 | null_coalescing_expression INTERR expression COLON expression
4512 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4513 lbag.AddLocation ($$, GetLocation ($4));
4515 | null_coalescing_expression INTERR expression error
4517 Error_SyntaxError (yyToken);
4519 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4521 | null_coalescing_expression INTERR expression COLON error
4523 Error_SyntaxError (yyToken);
4525 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4526 lbag.AddLocation ($$, GetLocation ($4));
4528 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4530 Error_SyntaxError (Token.CLOSE_BRACE);
4532 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4533 lbag.AddLocation ($$, GetLocation ($4));
4534 lexer.putback ('}');
4538 assignment_expression
4539 : prefixed_unary_expression ASSIGN expression
4541 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4542 lbag.AddLocation ($$, GetLocation ($2));
4544 | prefixed_unary_expression OP_MULT_ASSIGN expression
4546 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4547 lbag.AddLocation ($$, GetLocation ($2));
4549 | prefixed_unary_expression OP_DIV_ASSIGN expression
4551 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4552 lbag.AddLocation ($$, GetLocation ($2));
4554 | prefixed_unary_expression OP_MOD_ASSIGN expression
4556 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4557 lbag.AddLocation ($$, GetLocation ($2));
4559 | prefixed_unary_expression OP_ADD_ASSIGN expression
4561 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4562 lbag.AddLocation ($$, GetLocation ($2));
4564 | prefixed_unary_expression OP_SUB_ASSIGN expression
4566 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4567 lbag.AddLocation ($$, GetLocation ($2));
4569 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4571 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4572 lbag.AddLocation ($$, GetLocation ($2));
4574 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4576 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4577 lbag.AddLocation ($$, GetLocation ($2));
4579 | prefixed_unary_expression OP_AND_ASSIGN expression
4581 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4582 lbag.AddLocation ($$, GetLocation ($2));
4584 | prefixed_unary_expression OP_OR_ASSIGN expression
4586 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4587 lbag.AddLocation ($$, GetLocation ($2));
4589 | prefixed_unary_expression OP_XOR_ASSIGN expression
4591 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4592 lbag.AddLocation ($$, GetLocation ($2));
4596 lambda_parameter_list
4599 var pars = new List<Parameter> (4);
4600 pars.Add ((Parameter) $1);
4604 | lambda_parameter_list COMMA lambda_parameter
4606 var pars = (List<Parameter>) $1;
4607 Parameter p = (Parameter)$3;
4608 if (pars[0].GetType () != p.GetType ()) {
4609 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4618 : parameter_modifier parameter_type identifier_inside_body
4620 var lt = (LocatedToken) $3;
4622 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4624 | parameter_type identifier_inside_body
4626 var lt = (LocatedToken) $2;
4628 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4632 var lt = (LocatedToken) $1;
4633 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4637 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4638 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4642 opt_lambda_parameter_list
4643 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4644 | lambda_parameter_list {
4645 var pars_list = (List<Parameter>) $1;
4646 $$ = new ParametersCompiled (pars_list.ToArray ());
4650 lambda_expression_body
4652 start_block (Location.Null);
4654 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4656 Block b = end_block (Location.Null);
4657 b.IsCompilerGenerated = true;
4658 b.AddStatement (new ContextualReturn ((Expression) $2));
4664 // Handles only cases like foo = x.FirstOrDefault (l => );
4665 // where we must restore current_variable
4666 Block b = end_block (Location.Null);
4667 b.IsCompilerGenerated = true;
4669 Error_SyntaxError (yyToken);
4678 Error_SyntaxError (yyToken);
4686 var lt = (LocatedToken) $1;
4687 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4688 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4690 lambda_expression_body
4692 $$ = end_anonymous ((ParametersBlock) $4);
4693 lbag.AddLocation ($$, GetLocation ($2));
4697 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4698 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4699 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4701 lambda_expression_body
4703 $$ = end_anonymous ((ParametersBlock) $4);
4704 lbag.AddLocation ($$, GetLocation ($2));
4706 | ASYNC identifier_inside_body ARROW
4708 var lt = (LocatedToken) $2;
4709 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4710 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4712 lambda_expression_body
4714 $$ = end_anonymous ((ParametersBlock) $5);
4715 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4717 | OPEN_PARENS_LAMBDA
4719 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4721 opt_lambda_parameter_list CLOSE_PARENS ARROW
4723 valid_param_mod = 0;
4724 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4726 lambda_expression_body
4728 $$ = end_anonymous ((ParametersBlock) $7);
4729 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4731 | ASYNC OPEN_PARENS_LAMBDA
4733 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4735 opt_lambda_parameter_list CLOSE_PARENS ARROW
4737 valid_param_mod = 0;
4738 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4740 lambda_expression_body
4742 $$ = end_anonymous ((ParametersBlock) $8);
4743 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4748 : assignment_expression
4749 | non_assignment_expression
4752 non_assignment_expression
4753 : conditional_expression
4758 $$ = new ArglistAccess (GetLocation ($1));
4762 undocumented_expressions
4763 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4765 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4766 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4768 | REFTYPE open_parens_any expression CLOSE_PARENS
4770 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4771 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4773 | MAKEREF open_parens_any expression CLOSE_PARENS
4775 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4776 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4787 $$ = new BooleanExpression ((Expression) $1);
4791 opt_primary_parameters
4796 | primary_parameters
4800 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4804 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4805 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4807 if (lang_version < LanguageVersion.V_6)
4808 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
4812 opt_primary_parameters_with_class_base
4821 | primary_parameters
4825 | primary_parameters class_base
4829 | primary_parameters class_base OPEN_PARENS
4831 ++lexer.parsing_block;
4832 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
4834 opt_argument_list CLOSE_PARENS
4836 lbag.AppendToMember (current_container, GetLocation ($6));
4837 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
4838 --lexer.parsing_block;
4854 type_declaration_name
4856 lexer.ConstraintsParsing = true;
4858 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4859 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4860 FeatureIsNotAvailable (c.Location, "static classes");
4863 push_current_container (c, $3);
4864 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4866 opt_primary_parameters_with_class_base
4867 opt_type_parameter_constraints_clauses
4869 valid_param_mod = 0;
4870 lexer.ConstraintsParsing = false;
4873 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4876 current_container.SetConstraints ((List<Constraints>) $9);
4877 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4880 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4881 Lexer.doc_state = XmlCommentState.Allowed;
4884 lexer.parsing_modifiers = true;
4886 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4888 --lexer.parsing_declaration;
4890 Lexer.doc_state = XmlCommentState.Allowed;
4895 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4897 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4899 $$ = pop_current_class ();
4907 { $$ = $1; } // location
4913 mod_locations = null;
4915 lexer.parsing_modifiers = false;
4919 lexer.parsing_modifiers = false;
4925 | modifiers modifier
4927 var m1 = (Modifiers) $1;
4928 var m2 = (Modifiers) $2;
4930 if ((m1 & m2) != 0) {
4931 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4932 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4933 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4934 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4935 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4936 "More than one protection modifier specified");
4947 StoreModifierLocation ($$, GetLocation ($1));
4949 if (current_container.Kind == MemberKind.Namespace)
4950 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4954 $$ = Modifiers.PUBLIC;
4955 StoreModifierLocation ($$, GetLocation ($1));
4959 $$ = Modifiers.PROTECTED;
4960 StoreModifierLocation ($$, GetLocation ($1));
4964 $$ = Modifiers.INTERNAL;
4965 StoreModifierLocation ($$, GetLocation ($1));
4969 $$ = Modifiers.PRIVATE;
4970 StoreModifierLocation ($$, GetLocation ($1));
4974 $$ = Modifiers.ABSTRACT;
4975 StoreModifierLocation ($$, GetLocation ($1));
4979 $$ = Modifiers.SEALED;
4980 StoreModifierLocation ($$, GetLocation ($1));
4984 $$ = Modifiers.STATIC;
4985 StoreModifierLocation ($$, GetLocation ($1));
4989 $$ = Modifiers.READONLY;
4990 StoreModifierLocation ($$, GetLocation ($1));
4994 $$ = Modifiers.VIRTUAL;
4995 StoreModifierLocation ($$, GetLocation ($1));
4999 $$ = Modifiers.OVERRIDE;
5000 StoreModifierLocation ($$, GetLocation ($1));
5004 $$ = Modifiers.EXTERN;
5005 StoreModifierLocation ($$, GetLocation ($1));
5009 $$ = Modifiers.VOLATILE;
5010 StoreModifierLocation ($$, GetLocation ($1));
5014 $$ = Modifiers.UNSAFE;
5015 StoreModifierLocation ($$, GetLocation ($1));
5016 if (!settings.Unsafe)
5017 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5021 $$ = Modifiers.ASYNC;
5022 StoreModifierLocation ($$, GetLocation ($1));
5034 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5036 | COLON type_list error
5038 Error_SyntaxError (yyToken);
5040 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5044 opt_type_parameter_constraints_clauses
5046 | type_parameter_constraints_clauses
5052 type_parameter_constraints_clauses
5053 : type_parameter_constraints_clause
5055 var constraints = new List<Constraints> (1);
5056 constraints.Add ((Constraints) $1);
5059 | type_parameter_constraints_clauses type_parameter_constraints_clause
5061 var constraints = (List<Constraints>) $1;
5062 Constraints new_constraint = (Constraints)$2;
5064 foreach (Constraints c in constraints) {
5065 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5066 report.Error (409, new_constraint.Location,
5067 "A constraint clause has already been specified for type parameter `{0}'",
5068 new_constraint.TypeParameter.Value);
5072 constraints.Add (new_constraint);
5077 type_parameter_constraints_clause
5078 : WHERE IDENTIFIER COLON type_parameter_constraints
5080 var lt = (LocatedToken) $2;
5081 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5082 lbag.AddLocation ($$, GetLocation ($3));
5084 | WHERE IDENTIFIER error
5086 Error_SyntaxError (yyToken);
5088 var lt = (LocatedToken) $2;
5089 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5093 type_parameter_constraints
5094 : type_parameter_constraint
5096 var constraints = new List<FullNamedExpression> (1);
5097 constraints.Add ((FullNamedExpression) $1);
5100 | type_parameter_constraints COMMA type_parameter_constraint
5102 var constraints = (List<FullNamedExpression>) $1;
5103 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5104 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5105 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5108 prev = $3 as SpecialContraintExpr;
5110 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5111 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5113 prev = constraints [0] as SpecialContraintExpr;
5114 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5115 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5120 constraints.Add ((FullNamedExpression) $3);
5125 type_parameter_constraint
5128 if ($1 is ComposedCast)
5129 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5133 | NEW OPEN_PARENS CLOSE_PARENS
5135 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5136 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5140 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5144 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5148 opt_type_parameter_variance
5153 | type_parameter_variance
5155 if (lang_version <= LanguageVersion.V_3)
5156 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5162 type_parameter_variance
5165 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5169 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5178 // A block is "contained" on the following places:
5180 // property_declaration as part of the accessor body (get/set)
5181 // operator_declaration
5182 // constructor_declaration
5183 // destructor_declaration
5184 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5189 ++lexer.parsing_block;
5190 start_block (GetLocation ($1));
5192 opt_statement_list block_end
5201 --lexer.parsing_block;
5202 $$ = end_block (GetLocation ($1));
5204 | COMPLETE_COMPLETION
5206 --lexer.parsing_block;
5207 $$ = end_block (lexer.Location);
5215 ++lexer.parsing_block;
5216 current_block.StartLocation = GetLocation ($1);
5218 opt_statement_list CLOSE_BRACE
5220 --lexer.parsing_block;
5221 $$ = end_block (GetLocation ($4));
5232 | statement_list statement
5236 : block_variable_declaration
5238 current_block.AddStatement ((Statement) $1);
5240 | valid_declaration_statement
5242 current_block.AddStatement ((Statement) $1);
5247 Error_SyntaxError (yyToken);
5253 // The interactive_statement and its derivatives are only
5254 // used to provide a special version of `expression_statement'
5255 // that has a side effect of assigning the expression to
5258 interactive_statement_list
5259 : interactive_statement
5260 | interactive_statement_list interactive_statement
5263 interactive_statement
5264 : block_variable_declaration
5266 current_block.AddStatement ((Statement) $1);
5268 | interactive_valid_declaration_statement
5270 current_block.AddStatement ((Statement) $1);
5275 valid_declaration_statement
5278 | expression_statement
5279 | selection_statement
5280 | iteration_statement
5284 | unchecked_statement
5291 interactive_valid_declaration_statement
5294 | interactive_expression_statement
5295 | selection_statement
5296 | iteration_statement
5300 | unchecked_statement
5308 : valid_declaration_statement
5309 | block_variable_declaration
5311 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5316 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5321 Error_SyntaxError (yyToken);
5322 $$ = new EmptyStatement (GetLocation ($1));
5329 // Uses lexer.Location because semicolon location is not kept in quick mode
5330 $$ = new EmptyStatement (lexer.Location);
5335 : identifier_inside_body COLON
5337 var lt = (LocatedToken) $1;
5338 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5339 lbag.AddLocation (labeled, GetLocation ($2));
5340 current_block.AddLabel (labeled);
5341 current_block.AddStatement (labeled);
5347 : variable_type_simple
5348 | variable_type_simple rank_specifiers
5351 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5353 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5358 * The following is from Rhys' grammar:
5359 * > Types in local variable declarations must be recognized as
5360 * > expressions to prevent reduce/reduce errors in the grammar.
5361 * > The expressions are converted into types during semantic analysis.
5363 variable_type_simple
5364 : primary_expression_or_type opt_nullable
5366 // Ok, the above "primary_expression" is there to get rid of
5367 // both reduce/reduce and shift/reduces in the grammar, it should
5368 // really just be "type_name". If you use type_name, a reduce/reduce
5369 // creeps up. If you use namespace_or_type_name (which is all we need
5370 // really) two shift/reduces appear.
5373 // So the super-trick is that primary_expression
5374 // can only be either a SimpleName or a MemberAccess.
5375 // The MemberAccess case arises when you have a fully qualified type-name like :
5377 // SimpleName is when you have
5380 Expression expr = (Expression) $1;
5382 SimpleName sn = expr as SimpleName;
5383 if (sn != null && sn.Name == "var")
5384 $$ = new VarExpr (sn.Location);
5387 } else if (expr is ATypeNameExpression) {
5388 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5390 Error_ExpectingTypeName (expr);
5394 | primary_expression_or_type pointer_stars
5396 ATypeNameExpression expr = $1 as ATypeNameExpression;
5399 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5401 Error_ExpectingTypeName ((Expression)$1);
5405 | builtin_types opt_nullable
5410 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5412 | builtin_types pointer_stars
5414 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5416 | VOID pointer_stars
5418 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5422 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5423 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5429 | pointer_star pointer_stars
5431 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5439 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5443 identifier_inside_body
5447 $$ = Error_AwaitAsIdentifier ($1);
5451 block_variable_declaration
5452 : variable_type identifier_inside_body
5454 var lt = (LocatedToken) $2;
5455 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5456 current_block.AddLocalName (li);
5457 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5459 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5461 $$ = current_variable;
5462 current_variable = null;
5464 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5466 lbag.AddLocation ($$, GetLocation ($6));
5468 | CONST variable_type identifier_inside_body
5470 var lt = (LocatedToken) $3;
5471 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5472 current_block.AddLocalName (li);
5473 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5475 const_variable_initializer opt_const_declarators SEMICOLON
5477 $$ = current_variable;
5478 current_variable = null;
5479 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5483 opt_local_variable_initializer
5485 | ASSIGN block_variable_initializer
5487 current_variable.Initializer = (Expression) $2;
5488 PushLocation (GetLocation ($1));
5489 $$ = current_variable;
5493 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5494 report.Error (650, lexer.Location,
5495 "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");
5497 Error_SyntaxError (yyToken);
5502 opt_variable_declarators
5504 | variable_declarators
5507 opt_using_or_fixed_variable_declarators
5509 | variable_declarators
5511 foreach (var d in current_variable.Declarators) {
5512 if (d.Initializer == null)
5513 Error_MissingInitializer (d.Variable.Location);
5518 variable_declarators
5519 : variable_declarator
5520 | variable_declarators variable_declarator
5524 : COMMA identifier_inside_body
5526 var lt = (LocatedToken) $2;
5527 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5528 var d = new BlockVariableDeclarator (li, null);
5529 current_variable.AddDeclarator (d);
5530 current_block.AddLocalName (li);
5531 lbag.AddLocation (d, GetLocation ($1));
5533 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5535 var lt = (LocatedToken) $2;
5536 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5537 var d = new BlockVariableDeclarator (li, (Expression) $4);
5538 current_variable.AddDeclarator (d);
5539 current_block.AddLocalName (li);
5540 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5544 const_variable_initializer
5547 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5549 | ASSIGN constant_initializer_expr
5551 current_variable.Initializer = (Expression) $2;
5555 opt_const_declarators
5562 | const_declarators const_declarator
5566 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5568 var lt = (LocatedToken) $2;
5569 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5570 var d = new BlockVariableDeclarator (li, (Expression) $4);
5571 current_variable.AddDeclarator (d);
5572 current_block.AddLocalName (li);
5573 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5577 block_variable_initializer
5578 : variable_initializer
5579 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5581 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5582 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5584 | STACKALLOC simple_type
5586 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5587 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5591 expression_statement
5592 : statement_expression SEMICOLON
5595 lbag.AddStatement ($$, GetLocation ($2));
5597 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5598 | statement_expression CLOSE_BRACE
5601 report.Error (1002, GetLocation ($2), "; expected");
5602 lexer.putback ('}');
5606 interactive_expression_statement
5607 : interactive_statement_expression SEMICOLON { $$ = $1; }
5608 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5612 // We have to do the wrapping here and not in the case above,
5613 // because statement_expression is used for example in for_statement
5615 statement_expression
5618 ExpressionStatement s = $1 as ExpressionStatement;
5620 var expr = $1 as Expression;
5621 $$ = new StatementErrorExpression (expr);
5623 $$ = new StatementExpression (s);
5628 interactive_statement_expression
5631 Expression expr = (Expression) $1;
5632 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5636 Error_SyntaxError (yyToken);
5637 $$ = new EmptyStatement (GetLocation ($1));
5647 : IF open_parens_any boolean_expression CLOSE_PARENS
5650 if ($5 is EmptyStatement)
5651 Warning_EmptyStatement (GetLocation ($5));
5653 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5654 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5656 | IF open_parens_any boolean_expression CLOSE_PARENS
5657 embedded_statement ELSE embedded_statement
5659 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5660 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5662 if ($5 is EmptyStatement)
5663 Warning_EmptyStatement (GetLocation ($5));
5664 if ($7 is EmptyStatement)
5665 Warning_EmptyStatement (GetLocation ($7));
5667 | IF open_parens_any boolean_expression error
5669 Error_SyntaxError (yyToken);
5671 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5672 lbag.AddStatement ($$, GetLocation ($2));
5677 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5679 start_block (GetLocation ($5));
5681 opt_switch_sections CLOSE_BRACE
5683 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5684 end_block (GetLocation ($8));
5685 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5687 | SWITCH open_parens_any expression error
5689 Error_SyntaxError (yyToken);
5691 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5692 lbag.AddStatement ($$, GetLocation ($2));
5699 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5706 | switch_sections switch_section
5709 Error_SyntaxError (yyToken);
5714 : switch_labels statement_list
5720 var label = (SwitchLabel) $1;
5721 label.SectionStart = true;
5722 current_block.AddStatement (label);
5724 | switch_labels switch_label
5726 current_block.AddStatement ((Statement) $2);
5731 : CASE constant_expression COLON
5733 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5734 lbag.AddLocation ($$, GetLocation ($3));
5736 | CASE constant_expression error
5738 Error_SyntaxError (yyToken);
5739 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5743 $$ = new SwitchLabel (null, GetLocation ($1));
5755 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5757 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5758 Warning_EmptyStatement (GetLocation ($5));
5760 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5761 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5763 | WHILE open_parens_any boolean_expression error
5765 Error_SyntaxError (yyToken);
5767 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5768 lbag.AddStatement ($$, GetLocation ($2));
5773 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5775 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5776 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5778 | DO embedded_statement error
5780 Error_SyntaxError (yyToken);
5781 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5783 | DO embedded_statement WHILE open_parens_any boolean_expression error
5785 Error_SyntaxError (yyToken);
5787 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5788 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5793 : FOR open_parens_any
5795 start_block (GetLocation ($2));
5796 current_block.IsCompilerGenerated = true;
5797 For f = new For (GetLocation ($1));
5798 current_block.AddStatement (f);
5807 // Has to use be extra rule to recover started block
5809 : opt_for_initializer SEMICOLON
5811 ((For) $0).Initializer = (Statement) $1;
5813 // Pass the "For" object to the iterator_part4
5814 oob_stack.Push ($0);
5816 for_condition_and_iterator_part
5819 var locations = (Tuple<Location,Location>) $4;
5821 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5822 Warning_EmptyStatement (GetLocation ($5));
5825 f.Statement = (Statement) $5;
5826 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5828 $$ = end_block (GetLocation ($2));
5832 Error_SyntaxError (yyToken);
5833 $$ = end_block (current_block.StartLocation);
5837 for_condition_and_iterator_part
5838 : opt_for_condition SEMICOLON
5840 For f = (For) oob_stack.Peek ();
5841 f.Condition = (BooleanExpression) $1;
5844 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5847 // Handle errors in the case of opt_for_condition being followed by
5848 // a close parenthesis
5849 | opt_for_condition close_parens_close_brace {
5850 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5851 For f = (For) oob_stack.Peek ();
5852 f.Condition = (BooleanExpression) $1;
5853 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5858 : opt_for_iterator CLOSE_PARENS {
5859 For f = (For) oob_stack.Peek ();
5860 f.Iterator = (Statement) $1;
5861 $$ = GetLocation ($2);
5863 | opt_for_iterator CLOSE_BRACE {
5864 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5865 For f = (For) oob_stack.Peek ();
5866 f.Iterator = (Statement) $1;
5867 $$ = GetLocation ($2);
5871 close_parens_close_brace
5873 | CLOSE_BRACE { lexer.putback ('}'); }
5877 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5882 : variable_type identifier_inside_body
5884 var lt = (LocatedToken) $2;
5885 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5886 current_block.AddLocalName (li);
5887 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5889 opt_local_variable_initializer opt_variable_declarators
5891 $$ = current_variable;
5893 lbag.AddLocation (current_variable, PopLocation ());
5895 current_variable = null;
5897 | statement_expression_list
5901 : /* empty */ { $$ = null; }
5902 | boolean_expression
5906 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5911 : statement_expression_list
5914 statement_expression_list
5915 : statement_expression
5916 | statement_expression_list COMMA statement_expression
5918 var sl = $1 as StatementList;
5920 sl = new StatementList ((Statement) $1, (Statement) $3);
5921 lbag.AddStatement (sl, GetLocation ($2));
5923 sl.Add ((Statement) $3);
5924 lbag.AppendTo (sl, GetLocation ($2));
5932 : FOREACH open_parens_any type error
5934 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5936 start_block (GetLocation ($2));
5937 current_block.IsCompilerGenerated = true;
5939 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5940 current_block.AddStatement (f);
5942 lbag.AddStatement (f, GetLocation ($2));
5943 $$ = end_block (GetLocation ($4));
5945 | FOREACH open_parens_any type identifier_inside_body error
5947 Error_SyntaxError (yyToken);
5949 start_block (GetLocation ($2));
5950 current_block.IsCompilerGenerated = true;
5952 var lt = (LocatedToken) $4;
5953 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5954 current_block.AddLocalName (li);
5956 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5957 current_block.AddStatement (f);
5959 lbag.AddStatement (f, GetLocation ($2));
5960 $$ = end_block (GetLocation ($5));
5962 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5964 start_block (GetLocation ($2));
5965 current_block.IsCompilerGenerated = true;
5967 var lt = (LocatedToken) $4;
5968 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5969 current_block.AddLocalName (li);
5974 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5975 Warning_EmptyStatement (GetLocation ($9));
5977 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5978 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5979 end_block (GetLocation ($7));
5987 | continue_statement
5997 $$ = new Break (GetLocation ($1));
5998 lbag.AddStatement ($$, GetLocation ($2));
6003 : CONTINUE SEMICOLON
6005 $$ = new Continue (GetLocation ($1));
6006 lbag.AddStatement ($$, GetLocation ($2));
6010 Error_SyntaxError (yyToken);
6011 $$ = new Continue (GetLocation ($1));
6016 : GOTO identifier_inside_body SEMICOLON
6018 var lt = (LocatedToken) $2;
6019 $$ = new Goto (lt.Value, GetLocation ($1));
6020 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6022 | GOTO CASE constant_expression SEMICOLON
6024 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6025 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6027 | GOTO DEFAULT SEMICOLON
6029 $$ = new GotoDefault (GetLocation ($1));
6030 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6035 : RETURN opt_expression SEMICOLON
6037 $$ = new Return ((Expression) $2, GetLocation ($1));
6038 lbag.AddStatement ($$, GetLocation ($3));
6040 | RETURN expression error
6042 Error_SyntaxError (yyToken);
6043 $$ = new Return ((Expression) $2, GetLocation ($1));
6047 Error_SyntaxError (yyToken);
6048 $$ = new Return (null, GetLocation ($1));
6053 : THROW opt_expression SEMICOLON
6055 $$ = new Throw ((Expression) $2, GetLocation ($1));
6056 lbag.AddStatement ($$, GetLocation ($3));
6058 | THROW expression error
6060 Error_SyntaxError (yyToken);
6061 $$ = new Throw ((Expression) $2, GetLocation ($1));
6065 Error_SyntaxError (yyToken);
6066 $$ = new Throw (null, GetLocation ($1));
6071 : identifier_inside_body RETURN opt_expression SEMICOLON
6073 var lt = (LocatedToken) $1;
6074 string s = lt.Value;
6076 report.Error (1003, lt.Location, "; expected");
6077 } else if ($3 == null) {
6078 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6079 } else if (lang_version == LanguageVersion.ISO_1){
6080 FeatureIsNotAvailable (lt.Location, "iterators");
6083 current_block.Explicit.RegisterIteratorYield ();
6084 $$ = new Yield ((Expression) $3, lt.Location);
6085 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6087 | identifier_inside_body RETURN expression error
6089 Error_SyntaxError (yyToken);
6091 var lt = (LocatedToken) $1;
6092 string s = lt.Value;
6094 report.Error (1003, lt.Location, "; expected");
6095 } else if ($3 == null) {
6096 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6097 } else if (lang_version == LanguageVersion.ISO_1){
6098 FeatureIsNotAvailable (lt.Location, "iterators");
6101 current_block.Explicit.RegisterIteratorYield ();
6102 $$ = new Yield ((Expression) $3, lt.Location);
6103 lbag.AddStatement ($$, GetLocation ($2));
6105 | identifier_inside_body BREAK SEMICOLON
6107 var lt = (LocatedToken) $1;
6108 string s = lt.Value;
6110 report.Error (1003, lt.Location, "; expected");
6111 } else if (lang_version == LanguageVersion.ISO_1){
6112 FeatureIsNotAvailable (lt.Location, "iterators");
6115 current_block.ParametersBlock.TopBlock.IsIterator = true;
6116 $$ = new YieldBreak (lt.Location);
6117 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6127 : TRY block catch_clauses
6129 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6131 | TRY block FINALLY block
6133 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6134 lbag.AddStatement ($$, GetLocation ($3));
6136 | TRY block catch_clauses FINALLY block
6138 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6139 lbag.AddStatement ($$, GetLocation ($4));
6143 Error_SyntaxError (1524, yyToken);
6144 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6151 var l = new List<Catch> (2);
6156 | catch_clauses catch_clause
6158 var l = (List<Catch>) $1;
6160 Catch c = (Catch) $2;
6161 var prev_catch = l [l.Count - 1];
6162 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6163 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6173 | identifier_inside_body
6177 : CATCH opt_catch_filter block
6179 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6180 c.Filter = (CatchFilterExpression) $2;
6183 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6185 start_block (GetLocation ($2));
6186 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6187 c.TypeExpression = (FullNamedExpression) $3;
6190 var lt = (LocatedToken) $4;
6191 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6192 current_block.AddLocalName (c.Variable);
6195 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6198 opt_catch_filter block_prepared
6200 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6203 | CATCH open_parens_any error
6205 if (yyToken == Token.CLOSE_PARENS) {
6206 report.Error (1015, lexer.Location,
6207 "A type that derives from `System.Exception', `object', or `string' expected");
6209 Error_SyntaxError (yyToken);
6212 $$ = new Catch (null, GetLocation ($1));
6214 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6216 Error_SyntaxError (yyToken);
6218 // Required otherwise missing block could not be detected because
6219 // start_block is run early
6220 var c = new Catch (null, GetLocation ($1));
6221 c.TypeExpression = (FullNamedExpression) $3;
6224 var lt = (LocatedToken) $4;
6225 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6228 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6236 | IF open_parens_any expression CLOSE_PARENS
6238 if (lang_version <= LanguageVersion.V_5)
6239 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6241 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6242 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6249 $$ = new Checked ((Block) $2, GetLocation ($1));
6256 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6263 if (!settings.Unsafe)
6264 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6266 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6271 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6273 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6274 Warning_EmptyStatement (GetLocation ($5));
6276 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6277 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6279 | LOCK open_parens_any expression error
6281 Error_SyntaxError (yyToken);
6283 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6284 lbag.AddStatement ($$, GetLocation ($2));
6289 : FIXED open_parens_any variable_type identifier_inside_body
6291 start_block (GetLocation ($2));
6293 current_block.IsCompilerGenerated = true;
6294 var lt = (LocatedToken) $4;
6295 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6296 current_block.AddLocalName (li);
6297 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6299 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6301 $$ = current_variable;
6302 current_variable = null;
6306 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6307 Warning_EmptyStatement (GetLocation ($10));
6309 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6310 current_block.AddStatement (f);
6311 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6312 $$ = end_block (GetLocation ($8));
6317 : USING open_parens_any variable_type identifier_inside_body
6319 start_block (GetLocation ($2));
6321 current_block.IsCompilerGenerated = true;
6322 var lt = (LocatedToken) $4;
6323 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6324 current_block.AddLocalName (li);
6325 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6327 using_initialization CLOSE_PARENS
6329 $$ = current_variable;
6330 current_variable = null;
6334 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6335 Warning_EmptyStatement (GetLocation ($9));
6337 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6338 current_block.AddStatement (u);
6339 $$ = end_block (GetLocation ($7));
6341 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6343 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6344 Warning_EmptyStatement (GetLocation ($5));
6346 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6347 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6349 | USING open_parens_any expression error
6351 Error_SyntaxError (yyToken);
6353 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6354 lbag.AddStatement ($$, GetLocation ($2));
6358 using_initialization
6359 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6362 // It has to be here for the parent to safely restore artificial block
6363 Error_SyntaxError (yyToken);
6367 using_or_fixed_variable_initializer
6370 Error_MissingInitializer (lexer.Location);
6372 | ASSIGN variable_initializer
6374 current_variable.Initializer = (Expression) $2;
6375 $$ = current_variable;
6383 : first_from_clause query_body
6385 lexer.query_parsing = false;
6387 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6389 from.Tail.Next = (Linq.AQueryClause)$2;
6392 current_block.SetEndLocation (lexer.Location);
6393 current_block = current_block.Parent;
6395 | nested_from_clause query_body
6397 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6399 from.Tail.Next = (Linq.AQueryClause)$2;
6402 current_block.SetEndLocation (lexer.Location);
6403 current_block = current_block.Parent;
6406 // Bubble up COMPLETE_COMPLETION productions
6407 | first_from_clause COMPLETE_COMPLETION {
6408 lexer.query_parsing = false;
6411 current_block.SetEndLocation (lexer.Location);
6412 current_block = current_block.Parent;
6414 | nested_from_clause COMPLETE_COMPLETION {
6416 current_block.SetEndLocation (lexer.Location);
6417 current_block = current_block.Parent;
6422 : FROM_FIRST identifier_inside_body IN expression
6424 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6426 var lt = (LocatedToken) $2;
6427 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6428 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6429 lbag.AddLocation (clause, GetLocation ($3));
6430 $$ = new Linq.QueryExpression (clause);
6432 | FROM_FIRST type identifier_inside_body IN expression
6434 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6436 var lt = (LocatedToken) $3;
6437 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6438 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6439 IdentifierType = (FullNamedExpression)$2
6441 lbag.AddLocation (clause, GetLocation ($4));
6442 $$ = new Linq.QueryExpression (clause);
6447 : FROM identifier_inside_body IN expression
6449 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6451 var lt = (LocatedToken) $2;
6452 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6453 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6454 lbag.AddLocation (clause, GetLocation ($3));
6455 $$ = new Linq.QueryExpression (clause);
6457 | FROM type identifier_inside_body IN expression
6459 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6461 var lt = (LocatedToken) $3;
6462 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6463 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6464 IdentifierType = (FullNamedExpression)$2
6466 lbag.AddLocation (clause, GetLocation ($4));
6467 $$ = new Linq.QueryExpression (clause);
6472 : FROM identifier_inside_body IN
6474 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6478 var lt = (LocatedToken) $2;
6479 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6480 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6482 current_block.SetEndLocation (lexer.Location);
6483 current_block = current_block.Parent;
6485 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6486 lbag.AddLocation ($$, GetLocation ($3));
6488 | FROM type identifier_inside_body IN
6490 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6494 var lt = (LocatedToken) $3;
6495 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6497 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6498 IdentifierType = (FullNamedExpression)$2
6501 current_block.SetEndLocation (lexer.Location);
6502 current_block = current_block.Parent;
6504 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6506 lbag.AddLocation ($$, GetLocation ($4));
6511 : query_body_clauses select_or_group_clause opt_query_continuation
6513 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6516 head.Next = (Linq.AQueryClause)$3;
6519 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6520 clause.Tail.Next = head;
6526 | select_or_group_clause opt_query_continuation
6528 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6531 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6532 clause.Tail.Next = head;
6538 | query_body_clauses COMPLETE_COMPLETION
6539 | query_body_clauses error
6541 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6546 Error_SyntaxError (yyToken);
6551 select_or_group_clause
6554 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6558 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6560 current_block.SetEndLocation (lexer.Location);
6561 current_block = current_block.Parent;
6565 if (linq_clause_blocks == null)
6566 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6568 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6569 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6573 current_block.SetEndLocation (lexer.Location);
6574 current_block = current_block.Parent;
6576 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6580 var obj = (object[]) $5;
6582 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6583 lbag.AddLocation ($$, (Location) obj[1]);
6585 current_block.SetEndLocation (lexer.Location);
6586 current_block = current_block.Parent;
6591 : BY expression_or_error
6593 $$ = new object[] { $2, GetLocation ($1) };
6597 Error_SyntaxError (yyToken);
6598 $$ = new object[2] { null, Location.Null };
6604 | query_body_clauses query_body_clause
6606 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6620 : LET identifier_inside_body ASSIGN
6622 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6626 var lt = (LocatedToken) $2;
6627 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6628 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6629 lbag.AddLocation ($$, GetLocation ($3));
6631 current_block.SetEndLocation (lexer.Location);
6632 current_block = current_block.Parent;
6634 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6641 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6645 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6647 current_block.SetEndLocation (lexer.Location);
6648 current_block = current_block.Parent;
6653 : JOIN identifier_inside_body IN
6655 if (linq_clause_blocks == null)
6656 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6658 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6659 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6661 expression_or_error ON
6663 current_block.SetEndLocation (lexer.Location);
6664 current_block = current_block.Parent;
6666 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6667 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6669 expression_or_error EQUALS
6671 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6672 current_block.SetEndLocation (lexer.Location);
6673 current_block = current_block.Parent;
6675 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6677 expression_or_error opt_join_into
6679 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6680 current_block.SetEndLocation (lexer.Location);
6682 var outer_selector = linq_clause_blocks.Pop ();
6683 var block = linq_clause_blocks.Pop ();
6685 var lt = (LocatedToken) $2;
6686 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6687 Linq.RangeVariable into;
6691 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6692 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6695 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6697 var parent = block.Parent;
6698 while (parent is Linq.QueryBlock) {
6699 parent = parent.Parent;
6701 current_block.Parent = parent;
6703 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6705 lt = (LocatedToken) $12;
6706 into = new Linq.RangeVariable (lt.Value, lt.Location);
6708 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6709 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6712 current_block = block.Parent;
6713 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6715 | JOIN type identifier_inside_body IN
6717 if (linq_clause_blocks == null)
6718 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6720 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6721 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6723 expression_or_error ON
6725 current_block.SetEndLocation (lexer.Location);
6726 current_block = current_block.Parent;
6728 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6729 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6731 expression_or_error EQUALS
6733 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6734 current_block.SetEndLocation (lexer.Location);
6735 current_block = current_block.Parent;
6737 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6739 expression_or_error opt_join_into
6741 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6742 current_block.SetEndLocation (lexer.Location);
6744 var outer_selector = linq_clause_blocks.Pop ();
6745 var block = linq_clause_blocks.Pop ();
6747 var lt = (LocatedToken) $3;
6748 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6749 Linq.RangeVariable into;
6753 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6754 IdentifierType = (FullNamedExpression)$2
6756 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6759 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6761 var parent = block.Parent;
6762 while (parent is Linq.QueryBlock) {
6763 parent = parent.Parent;
6765 current_block.Parent = parent;
6767 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6769 lt = (LocatedToken) $13;
6770 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6772 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6773 IdentifierType = (FullNamedExpression)$2
6777 current_block = block.Parent;
6778 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6784 | INTO identifier_inside_body
6793 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6797 current_block.SetEndLocation (lexer.Location);
6798 current_block = current_block.Parent;
6808 current_block.SetEndLocation (lexer.Location);
6809 current_block = current_block.Parent;
6811 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6815 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6822 | orderings_then_by COMMA
6824 current_block.SetEndLocation (lexer.Location);
6825 current_block = current_block.Parent;
6827 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6831 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6839 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6841 | expression ASCENDING
6843 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6844 lbag.AddLocation ($$, GetLocation ($2));
6846 | expression DESCENDING
6848 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6849 lbag.AddLocation ($$, GetLocation ($2));
6856 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6858 | expression ASCENDING
6860 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6861 lbag.AddLocation ($$, GetLocation ($2));
6863 | expression DESCENDING
6865 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6866 lbag.AddLocation ($$, GetLocation ($2));
6871 opt_query_continuation
6873 | INTO identifier_inside_body
6875 // query continuation block is not linked with query block but with block
6876 // before. This means each query can use same range variable names for
6877 // different identifiers.
6879 current_block.SetEndLocation (GetLocation ($1));
6880 current_block = current_block.Parent;
6882 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6884 if (linq_clause_blocks == null)
6885 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6887 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6891 var current_block = linq_clause_blocks.Pop ();
6892 var lt = (LocatedToken) $2;
6893 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6894 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6895 next = (Linq.AQueryClause)$4
6901 // Support for using the compiler as an interactive parser
6903 // The INTERACTIVE_PARSER token is first sent to parse our
6904 // productions; If the result is a Statement, the parsing
6905 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6906 // to setup the blocks in advance.
6908 // This setup is here so that in the future we can add
6909 // support for other constructs (type parsing, namespaces, etc)
6910 // that do not require a block to be setup in advance
6914 : EVAL_STATEMENT_PARSER EOF
6915 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6916 | EVAL_STATEMENT_PARSER
6918 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6920 // (ref object retval)
6921 Parameter [] mpar = new Parameter [1];
6922 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6924 ParametersCompiled pars = new ParametersCompiled (mpar);
6925 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6926 if (settings.Unsafe)
6927 mods |= Modifiers.UNSAFE;
6929 current_local_parameters = pars;
6930 var method = new InteractiveMethod (
6932 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6936 current_type.AddMember (method);
6937 oob_stack.Push (method);
6939 interactive_async = false;
6941 ++lexer.parsing_block;
6942 start_block (lexer.Location);
6944 interactive_statement_list opt_COMPLETE_COMPLETION
6946 --lexer.parsing_block;
6947 var method = (InteractiveMethod) oob_stack.Pop ();
6948 method.Block = (ToplevelBlock) end_block(lexer.Location);
6950 if (interactive_async == true) {
6951 method.ChangeToAsync ();
6954 InteractiveResult = (Class) pop_current_class ();
6955 current_local_parameters = null;
6957 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6960 interactive_compilation_unit
6961 : opt_extern_alias_directives opt_using_directives
6962 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6965 opt_COMPLETE_COMPLETION
6967 | COMPLETE_COMPLETION
6970 close_brace_or_complete_completion
6972 | COMPLETE_COMPLETION
6976 // XML documentation code references micro parser
6978 documentation_parsing
6981 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6986 : doc_type_declaration_name opt_doc_method_sig
6988 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6990 | builtin_types opt_doc_method_sig
6992 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6993 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6996 | VOID opt_doc_method_sig
6998 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
6999 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7002 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7004 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7005 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7006 var lt = (LocatedToken) $3;
7007 $$ = new MemberName (lt.Value);
7009 | doc_type_declaration_name DOT THIS
7011 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7013 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7015 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7017 opt_doc_parameters CLOSE_BRACKET
7019 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7020 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7022 | EXPLICIT OPERATOR type opt_doc_method_sig
7024 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7025 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7026 module.DocumentationBuilder.ParsedParameters = p;
7027 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7030 | IMPLICIT OPERATOR type opt_doc_method_sig
7032 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7033 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7034 module.DocumentationBuilder.ParsedParameters = p;
7035 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7038 | OPERATOR overloadable_operator opt_doc_method_sig
7040 var p = (List<DocumentationParameter>)$3;
7041 module.DocumentationBuilder.ParsedParameters = p;
7042 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7047 doc_type_declaration_name
7048 : type_declaration_name
7049 | doc_type_declaration_name DOT type_declaration_name
7051 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7059 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7061 opt_doc_parameters CLOSE_PARENS
7070 $$ = new List<DocumentationParameter> (0);
7078 var parameters = new List<DocumentationParameter> ();
7079 parameters.Add ((DocumentationParameter) $1);
7082 | doc_parameters COMMA doc_parameter
7084 var parameters = $1 as List<DocumentationParameter>;
7085 parameters.Add ((DocumentationParameter) $3);
7091 : opt_parameter_modifier parameter_type
7094 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7096 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7103 // A class used to hold info about an operator declarator
7105 class OperatorDeclaration {
7106 public readonly Operator.OpType optype;
7107 public readonly FullNamedExpression ret_type;
7108 public readonly Location location;
7110 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7113 this.ret_type = ret_type;
7114 this.location = location;
7118 void Error_ExpectingTypeName (Expression expr)
7120 if (expr is Invocation){
7121 report.Error (1002, expr.Location, "Expecting `;'");
7123 expr.Error_InvalidExpressionStatement (report);
7127 void Error_ParameterModifierNotValid (string modifier, Location loc)
7129 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7133 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7135 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7136 Parameter.GetModifierSignature (mod));
7139 void Error_TypeExpected (Location loc)
7141 report.Error (1031, loc, "Type expected");
7144 void Error_UnsafeCodeNotAllowed (Location loc)
7146 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7149 void Warning_EmptyStatement (Location loc)
7151 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7154 void Error_NamedArgumentExpected (NamedArgument a)
7156 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7159 void Error_MissingInitializer (Location loc)
7161 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7164 object Error_AwaitAsIdentifier (object token)
7167 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7168 return new LocatedToken ("await", GetLocation (token));
7174 void push_current_container (TypeDefinition tc, object partial_token)
7176 if (module.Evaluator != null){
7177 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7181 undo.AddTypeContainer (current_container, tc);
7184 if (partial_token != null)
7185 current_container.AddPartial (tc);
7187 current_container.AddTypeContainer (tc);
7189 ++lexer.parsing_declaration;
7190 current_container = tc;
7194 TypeContainer pop_current_class ()
7196 var retval = current_container;
7198 current_container = current_container.Parent;
7199 current_type = current_type.Parent as TypeDefinition;
7204 [System.Diagnostics.Conditional ("FULL_AST")]
7205 void StoreModifierLocation (object token, Location loc)
7210 if (mod_locations == null)
7211 mod_locations = new List<Tuple<Modifiers, Location>> ();
7213 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7216 [System.Diagnostics.Conditional ("FULL_AST")]
7217 void PushLocation (Location loc)
7219 if (location_stack == null)
7220 location_stack = new Stack<Location> ();
7222 location_stack.Push (loc);
7225 Location PopLocation ()
7227 if (location_stack == null)
7228 return Location.Null;
7230 return location_stack.Pop ();
7233 string CheckAttributeTarget (int token, string a, Location l)
7236 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7240 if (!Tokenizer.IsValidIdentifier (a)) {
7241 Error_SyntaxError (token);
7243 report.Warning (658, 1, l,
7244 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7247 return string.Empty;
7250 static bool IsUnaryOperator (Operator.OpType op)
7254 case Operator.OpType.LogicalNot:
7255 case Operator.OpType.OnesComplement:
7256 case Operator.OpType.Increment:
7257 case Operator.OpType.Decrement:
7258 case Operator.OpType.True:
7259 case Operator.OpType.False:
7260 case Operator.OpType.UnaryPlus:
7261 case Operator.OpType.UnaryNegation:
7267 void syntax_error (Location l, string msg)
7269 report.Error (1003, l, "Syntax error, " + msg);
7274 public Tokenizer Lexer {
7280 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7281 : this (reader, file, file.Compiler.Report, session)
7285 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7288 current_container = current_namespace = file;
7290 this.module = file.Module;
7291 this.compiler = file.Compiler;
7292 this.settings = compiler.Settings;
7293 this.report = report;
7295 lang_version = settings.Version;
7296 yacc_verbose_flag = settings.VerboseParserFlag;
7297 doc_support = settings.DocumentationFile != null;
7298 lexer = new Tokenizer (reader, file, session, report);
7299 oob_stack = new Stack<object> ();
7300 lbag = session.LocationsBag;
7301 use_global_stacks = session.UseJayGlobalArrays;
7302 parameters_bucket = session.ParametersStack;
7305 public void parse ()
7307 eof_token = Token.EOF;
7310 if (yacc_verbose_flag > 1)
7311 yyparse (lexer, new yydebug.yyDebugSimple ());
7315 Tokenizer tokenizer = lexer as Tokenizer;
7316 tokenizer.cleanup ();
7317 } catch (Exception e){
7318 if (e is yyParser.yyUnexpectedEof) {
7319 Error_SyntaxError (yyToken);
7320 UnexpectedEOF = true;
7324 if (e is yyParser.yyException) {
7325 if (report.Errors == 0)
7326 report.Error (-25, lexer.Location, "Parsing error");
7328 // Used by compiler-tester to test internal errors
7329 if (yacc_verbose_flag > 0 || e is FatalException)
7332 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7337 void CheckToken (int error, int yyToken, string msg, Location loc)
7339 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7340 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7342 report.Error (error, loc, msg);
7345 string ConsumeStoredComment ()
7347 string s = tmpComment;
7349 Lexer.doc_state = XmlCommentState.Allowed;
7353 void FeatureIsNotAvailable (Location loc, string feature)
7355 report.FeatureIsNotAvailable (compiler, loc, feature);
7358 Location GetLocation (object obj)
7360 var lt = obj as LocatedToken;
7364 var mn = obj as MemberName;
7368 var expr = obj as Expression;
7370 return expr.Location;
7372 return lexer.Location;
7375 void start_block (Location loc)
7377 if (current_block == null) {
7378 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7379 parsing_anonymous_method = false;
7380 } else if (parsing_anonymous_method) {
7381 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7382 parsing_anonymous_method = false;
7384 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7389 end_block (Location loc)
7391 Block retval = current_block.Explicit;
7392 retval.SetEndLocation (loc);
7393 current_block = retval.Parent;
7397 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7399 oob_stack.Push (current_anonymous_method);
7400 oob_stack.Push (current_local_parameters);
7401 oob_stack.Push (current_variable);
7402 oob_stack.Push (async_block);
7404 current_local_parameters = parameters;
7406 if (lang_version <= LanguageVersion.ISO_2)
7407 FeatureIsNotAvailable (loc, "lambda expressions");
7409 current_anonymous_method = new LambdaExpression (loc);
7411 if (lang_version == LanguageVersion.ISO_1)
7412 FeatureIsNotAvailable (loc, "anonymous methods");
7414 current_anonymous_method = new AnonymousMethodExpression (loc);
7417 async_block = isAsync;
7418 // Force the next block to be created as a ToplevelBlock
7419 parsing_anonymous_method = true;
7423 * Completes the anonymous method processing, if lambda_expr is null, this
7424 * means that we have a Statement instead of an Expression embedded
7426 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7428 AnonymousMethodExpression retval;
7431 anon_block.IsAsync = true;
7433 current_anonymous_method.Block = anon_block;
7434 retval = current_anonymous_method;
7436 async_block = (bool) oob_stack.Pop ();
7437 current_variable = (BlockVariable) oob_stack.Pop ();
7438 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7439 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7444 void Error_SyntaxError (int token)
7446 Error_SyntaxError (0, token);
7449 void Error_SyntaxError (int error_code, int token)
7451 Error_SyntaxError (error_code, token, "Unexpected symbol");
7454 void Error_SyntaxError (int error_code, int token, string msg)
7456 Lexer.CompleteOnEOF = false;
7458 // An error message has been reported by tokenizer
7459 if (token == Token.ERROR)
7462 // Avoid duplicit error message after unterminated string literals
7463 if (token == Token.LITERAL && lexer.Location.Column == 0)
7466 string symbol = GetSymbolName (token);
7467 string expecting = GetExpecting ();
7468 var loc = lexer.Location - symbol.Length;
7470 if (error_code == 0) {
7471 if (expecting == "`identifier'") {
7472 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7473 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7478 expecting = "identifier";
7479 } else if (expecting == "`)'") {
7486 if (string.IsNullOrEmpty (expecting))
7487 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7489 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7492 string GetExpecting ()
7494 int [] tokens = yyExpectingTokens (yyExpectingState);
7495 var names = new List<string> (tokens.Length);
7496 bool has_type = false;
7497 bool has_identifier = false;
7498 for (int i = 0; i < tokens.Length; i++){
7499 int token = tokens [i];
7500 has_identifier |= token == Token.IDENTIFIER;
7502 string name = GetTokenName (token);
7503 if (name == "<internal>")
7506 has_type |= name == "type";
7507 if (names.Contains (name))
7514 // Too many tokens to enumerate
7516 if (names.Count > 8)
7519 if (has_type && has_identifier)
7520 names.Remove ("identifier");
7522 if (names.Count == 1)
7523 return "`" + GetTokenName (tokens [0]) + "'";
7525 StringBuilder sb = new StringBuilder ();
7527 int count = names.Count;
7528 for (int i = 0; i < count; i++){
7529 bool last = i + 1 == count;
7533 sb.Append (names [i]);
7534 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7536 return sb.ToString ();
7540 string GetSymbolName (int token)
7544 return ((Constant)lexer.Value).GetValue ().ToString ();
7545 case Token.IDENTIFIER:
7546 return ((LocatedToken)lexer.Value).Value;
7588 case Token.BITWISE_AND:
7590 case Token.BITWISE_OR:
7604 case Token.OP_SHIFT_LEFT:
7606 case Token.OP_SHIFT_RIGHT:
7626 case Token.OP_COALESCING:
7628 case Token.OP_MULT_ASSIGN:
7630 case Token.OP_DIV_ASSIGN:
7632 case Token.OP_MOD_ASSIGN:
7634 case Token.OP_ADD_ASSIGN:
7636 case Token.OP_SUB_ASSIGN:
7638 case Token.OP_SHIFT_LEFT_ASSIGN:
7640 case Token.OP_SHIFT_RIGHT_ASSIGN:
7642 case Token.OP_AND_ASSIGN:
7644 case Token.OP_XOR_ASSIGN:
7646 case Token.OP_OR_ASSIGN:
7650 return GetTokenName (token);
7653 static string GetTokenName (int token)
7656 case Token.ABSTRACT:
7678 case Token.CONTINUE:
7682 case Token.DELEGATE:
7692 case Token.EXPLICIT:
7695 case Token.EXTERN_ALIAS:
7711 case Token.IMPLICIT:
7715 case Token.INTERFACE:
7717 case Token.INTERNAL:
7723 case Token.NAMESPACE:
7729 case Token.OPERATOR:
7733 case Token.OVERRIDE:
7739 case Token.PROTECTED:
7743 case Token.READONLY:
7755 case Token.STACKALLOC:
7756 return "stackalloc";
7773 case Token.UNCHECKED:
7781 case Token.VOLATILE:
7789 case Token.REFVALUE:
7790 return "__refvalue";
7800 case Token.FROM_FIRST:
7818 case Token.ASCENDING:
7820 case Token.DESCENDING:
7821 return "descending";
7828 case Token.OPEN_BRACE:
7830 case Token.CLOSE_BRACE:
7832 case Token.OPEN_BRACKET:
7833 case Token.OPEN_BRACKET_EXPR:
7835 case Token.CLOSE_BRACKET:
7837 case Token.OPEN_PARENS_CAST:
7838 case Token.OPEN_PARENS_LAMBDA:
7839 case Token.OPEN_PARENS:
7841 case Token.CLOSE_PARENS:
7847 case Token.DEFAULT_COLON:
7851 case Token.SEMICOLON:
7862 case Token.BITWISE_AND:
7863 case Token.BITWISE_OR:
7870 case Token.OP_SHIFT_LEFT:
7871 case Token.OP_SHIFT_RIGHT:
7879 case Token.OP_COALESCING:
7880 case Token.OP_MULT_ASSIGN:
7881 case Token.OP_DIV_ASSIGN:
7882 case Token.OP_MOD_ASSIGN:
7883 case Token.OP_ADD_ASSIGN:
7884 case Token.OP_SUB_ASSIGN:
7885 case Token.OP_SHIFT_LEFT_ASSIGN:
7886 case Token.OP_SHIFT_RIGHT_ASSIGN:
7887 case Token.OP_AND_ASSIGN:
7888 case Token.OP_XOR_ASSIGN:
7889 case Token.OP_OR_ASSIGN:
7890 return "<operator>";
7912 case Token.OP_GENERICS_LT:
7913 case Token.GENERIC_DIMENSION:
7915 case Token.OP_GENERICS_GT:
7918 case Token.INTERR_NULLABLE:
7920 case Token.DOUBLE_COLON:
7924 case Token.IDENTIFIER:
7926 return "identifier";
7929 return "end-of-file";
7931 // All of these are internal.
7934 case Token.FIRST_KEYWORD:
7935 case Token.EVAL_COMPILATION_UNIT_PARSER:
7936 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7937 case Token.EVAL_STATEMENT_PARSER:
7938 case Token.LAST_KEYWORD:
7939 case Token.GENERATE_COMPLETION:
7940 case Token.COMPLETE_COMPLETION:
7941 return "<internal>";
7943 // A bit more robust.
7945 return yyNames [token];