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 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1823 property.Get.Block = (ToplevelBlock) $6;
1825 if (current_container.Kind == MemberKind.Interface) {
1826 report.Error (531, property.Get.Block.StartLocation,
1827 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1830 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1831 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1833 current_type.AddMember (property);
1835 current_local_parameters = null;
1839 opt_property_initializer
1843 ++lexer.parsing_block;
1844 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1845 start_block (GetLocation ($1));
1847 property_initializer SEMICOLON
1849 --lexer.parsing_block;
1850 ((Property)current_property).Initializer = (Expression) $3;
1851 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1852 end_block (GetLocation ($4));
1853 current_local_parameters = null;
1857 property_initializer
1863 : opt_attributes opt_modifiers
1864 member_type indexer_declaration_name OPEN_BRACKET
1866 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1868 opt_formal_parameter_list CLOSE_BRACKET
1870 valid_param_mod = 0;
1871 var type = (FullNamedExpression) $3;
1872 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1874 current_property = indexer;
1876 current_type.AddIndexer (indexer);
1877 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1879 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1880 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1882 if (indexer.ParameterInfo.IsEmpty) {
1883 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1887 tmpComment = Lexer.consume_doc_comment ();
1888 Lexer.doc_state = XmlCommentState.Allowed;
1891 lexer.PropertyParsing = true;
1892 current_local_parameters = (ParametersCompiled) $7;
1896 lexer.PropertyParsing = false;
1897 current_local_parameters = null;
1899 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1900 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1903 current_property.DocComment = ConsumeStoredComment ();
1905 current_property = null;
1910 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1912 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1916 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1917 current_property.Get.Block = (ToplevelBlock) $1;
1921 accessor_declarations
1922 : get_accessor_declaration
1923 | get_accessor_declaration accessor_declarations
1924 | set_accessor_declaration
1925 | set_accessor_declaration accessor_declarations
1928 if (yyToken == Token.CLOSE_BRACE) {
1929 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1931 if (yyToken == Token.SEMICOLON)
1932 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1934 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1939 get_accessor_declaration
1940 : opt_attributes opt_modifiers GET
1942 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1943 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1946 if (current_property.Get != null) {
1947 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1950 if (current_property is Indexer) {
1951 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1952 (Attributes) $1, GetLocation ($3));
1954 current_property.Get = new Property.GetMethod (current_property,
1955 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1958 current_local_parameters = current_property.Get.ParameterInfo;
1959 lbag.AddMember (current_property.Get, mod_locations);
1960 lexer.PropertyParsing = false;
1965 current_property.Get.Block = (ToplevelBlock) $5;
1967 if (current_container.Kind == MemberKind.Interface) {
1968 report.Error (531, current_property.Get.Block.StartLocation,
1969 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1973 current_local_parameters = null;
1974 lexer.PropertyParsing = true;
1977 if (Lexer.doc_state == XmlCommentState.Error)
1978 Lexer.doc_state = XmlCommentState.NotAllowed;
1982 set_accessor_declaration
1983 : opt_attributes opt_modifiers SET
1985 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1986 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1989 if (current_property.Set != null) {
1990 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1993 if (current_property is Indexer) {
1994 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1995 ParametersCompiled.MergeGenerated (compiler,
1996 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1997 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1999 (Attributes) $1, GetLocation ($3));
2001 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2002 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2003 (Attributes) $1, GetLocation ($3));
2006 current_local_parameters = current_property.Set.ParameterInfo;
2007 lbag.AddMember (current_property.Set, mod_locations);
2008 lexer.PropertyParsing = false;
2013 current_property.Set.Block = (ToplevelBlock) $5;
2015 if (current_container.Kind == MemberKind.Interface) {
2016 report.Error (531, current_property.Set.Block.StartLocation,
2017 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2021 current_local_parameters = null;
2022 lexer.PropertyParsing = true;
2025 && Lexer.doc_state == XmlCommentState.Error)
2026 Lexer.doc_state = XmlCommentState.NotAllowed;
2039 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2044 interface_declaration
2051 type_declaration_name
2053 lexer.ConstraintsParsing = true;
2054 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2055 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2058 opt_type_parameter_constraints_clauses
2060 lexer.ConstraintsParsing = false;
2063 current_container.SetConstraints ((List<Constraints>) $9);
2066 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2067 Lexer.doc_state = XmlCommentState.Allowed;
2070 lexer.parsing_modifiers = true;
2072 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2074 --lexer.parsing_declaration;
2076 Lexer.doc_state = XmlCommentState.Allowed;
2081 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2083 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2085 $$ = pop_current_class ();
2087 | opt_attributes opt_modifiers opt_partial INTERFACE error
2089 Error_SyntaxError (yyToken);
2093 opt_interface_member_declarations
2095 | interface_member_declarations
2098 interface_member_declarations
2099 : interface_member_declaration
2101 lexer.parsing_modifiers = true;
2102 lexer.parsing_block = 0;
2104 | interface_member_declarations interface_member_declaration
2106 lexer.parsing_modifiers = true;
2107 lexer.parsing_block = 0;
2111 interface_member_declaration
2112 : constant_declaration
2114 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2118 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2120 | method_declaration
2121 | property_declaration
2123 | indexer_declaration
2124 | operator_declaration
2126 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2128 | constructor_declaration
2130 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2134 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2138 operator_declaration
2139 : opt_attributes opt_modifiers operator_declarator
2142 method_body_expression_block
2144 OperatorDeclaration decl = (OperatorDeclaration) $3;
2146 Operator op = new Operator (
2147 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2148 current_local_parameters,
2149 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2151 if (op.Block == null)
2152 op.ParameterInfo.CheckParameters (op);
2155 op.DocComment = tmpComment;
2156 Lexer.doc_state = XmlCommentState.Allowed;
2159 // Note again, checking is done in semantic analysis
2160 current_type.AddOperator (op);
2162 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2165 current_local_parameters = null;
2170 : type_expression_or_array
2173 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2174 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2179 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2181 valid_param_mod = ParameterModifierType.DefaultValue;
2183 opt_formal_parameter_list CLOSE_PARENS
2185 valid_param_mod = 0;
2187 Location loc = GetLocation ($2);
2188 Operator.OpType op = (Operator.OpType) $3;
2189 current_local_parameters = (ParametersCompiled)$6;
2191 int p_count = current_local_parameters.Count;
2193 if (op == Operator.OpType.Addition)
2194 op = Operator.OpType.UnaryPlus;
2195 else if (op == Operator.OpType.Subtraction)
2196 op = Operator.OpType.UnaryNegation;
2199 if (IsUnaryOperator (op)) {
2201 report.Error (1020, loc, "Overloadable binary operator expected");
2202 } else if (p_count != 1) {
2203 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2204 Operator.GetName (op));
2208 report.Error (1019, loc, "Overloadable unary operator expected");
2209 } else if (p_count != 2) {
2210 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2211 Operator.GetName (op));
2216 tmpComment = Lexer.consume_doc_comment ();
2217 Lexer.doc_state = XmlCommentState.NotAllowed;
2220 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2221 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2223 | conversion_operator_declarator
2226 overloadable_operator
2228 : BANG { $$ = Operator.OpType.LogicalNot; }
2229 | TILDE { $$ = Operator.OpType.OnesComplement; }
2230 | OP_INC { $$ = Operator.OpType.Increment; }
2231 | OP_DEC { $$ = Operator.OpType.Decrement; }
2232 | TRUE { $$ = Operator.OpType.True; }
2233 | FALSE { $$ = Operator.OpType.False; }
2234 // Unary and binary:
2235 | PLUS { $$ = Operator.OpType.Addition; }
2236 | MINUS { $$ = Operator.OpType.Subtraction; }
2238 | STAR { $$ = Operator.OpType.Multiply; }
2239 | DIV { $$ = Operator.OpType.Division; }
2240 | PERCENT { $$ = Operator.OpType.Modulus; }
2241 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2242 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2243 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2244 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2245 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2246 | OP_EQ { $$ = Operator.OpType.Equality; }
2247 | OP_NE { $$ = Operator.OpType.Inequality; }
2248 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2249 | OP_LT { $$ = Operator.OpType.LessThan; }
2250 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2251 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2254 conversion_operator_declarator
2255 : IMPLICIT OPERATOR type OPEN_PARENS
2257 valid_param_mod = ParameterModifierType.DefaultValue;
2259 opt_formal_parameter_list CLOSE_PARENS
2261 valid_param_mod = 0;
2263 Location loc = GetLocation ($2);
2264 current_local_parameters = (ParametersCompiled)$6;
2266 if (current_local_parameters.Count != 1) {
2267 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2271 tmpComment = Lexer.consume_doc_comment ();
2272 Lexer.doc_state = XmlCommentState.NotAllowed;
2275 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2276 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2278 | EXPLICIT OPERATOR type OPEN_PARENS
2280 valid_param_mod = ParameterModifierType.DefaultValue;
2282 opt_formal_parameter_list CLOSE_PARENS
2284 valid_param_mod = 0;
2286 Location loc = GetLocation ($2);
2287 current_local_parameters = (ParametersCompiled)$6;
2289 if (current_local_parameters.Count != 1) {
2290 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2294 tmpComment = Lexer.consume_doc_comment ();
2295 Lexer.doc_state = XmlCommentState.NotAllowed;
2298 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2299 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2303 Error_SyntaxError (yyToken);
2304 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2305 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2309 Error_SyntaxError (yyToken);
2310 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2311 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2315 constructor_declaration
2316 : constructor_declarator
2319 Constructor c = (Constructor) $1;
2320 c.Block = (ToplevelBlock) $2;
2323 c.DocComment = ConsumeStoredComment ();
2325 current_local_parameters = null;
2327 Lexer.doc_state = XmlCommentState.Allowed;
2331 constructor_declarator
2337 tmpComment = Lexer.consume_doc_comment ();
2338 Lexer.doc_state = XmlCommentState.Allowed;
2341 valid_param_mod = ParameterModifierType.All;
2343 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2345 valid_param_mod = 0;
2346 current_local_parameters = (ParametersCompiled) $6;
2348 var lt = (LocatedToken) $3;
2349 var mods = (Modifiers) $2;
2350 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2352 if (lt.Value != current_container.MemberName.Name) {
2353 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2354 } else if ((mods & Modifiers.STATIC) != 0) {
2355 if ((mods & Modifiers.AccessibilityMask) != 0){
2356 report.Error (515, c.Location,
2357 "`{0}': static constructor cannot have an access modifier",
2358 c.GetSignatureForError ());
2362 current_type.AddConstructor (c);
2363 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2367 // start block here, so possible anonymous methods inside
2368 // constructor initializer can get correct parent block
2370 start_block (lexer.Location);
2372 opt_constructor_initializer
2375 var c = (Constructor) $8;
2376 c.Initializer = (ConstructorInitializer) $9;
2379 report.Error (514, c.Location,
2380 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2381 c.GetSignatureForError ());
2391 | SEMICOLON { current_block = null; $$ = null; }
2394 opt_constructor_initializer
2396 | constructor_initializer
2399 constructor_initializer
2400 : COLON BASE OPEN_PARENS
2402 ++lexer.parsing_block;
2404 opt_argument_list CLOSE_PARENS
2406 --lexer.parsing_block;
2407 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2408 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2410 | COLON THIS OPEN_PARENS
2412 ++lexer.parsing_block;
2414 opt_argument_list CLOSE_PARENS
2416 --lexer.parsing_block;
2417 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2418 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2422 Error_SyntaxError (yyToken);
2423 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2424 lbag.AddLocation ($$, GetLocation ($1));
2428 Error_SyntaxError (yyToken);
2433 destructor_declaration
2434 : opt_attributes opt_modifiers TILDE
2437 tmpComment = Lexer.consume_doc_comment ();
2438 Lexer.doc_state = XmlCommentState.NotAllowed;
2441 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2443 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2445 var lt = (LocatedToken) $5;
2446 if (lt.Value != current_container.MemberName.Name){
2447 report.Error (574, lt.Location, "Name of destructor must match name of class");
2448 } else if (current_container.Kind != MemberKind.Class){
2449 report.Error (575, lt.Location, "Only class types can contain destructor");
2452 Destructor d = new Destructor (current_type, (Modifiers) $2,
2453 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2455 d.DocComment = ConsumeStoredComment ();
2457 d.Block = (ToplevelBlock) $8;
2458 current_type.AddMember (d);
2459 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2461 current_local_parameters = null;
2468 EVENT type member_declaration_name
2470 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2471 current_type.AddMember (current_event_field);
2473 if (current_event_field.MemberName.ExplicitInterface != null) {
2474 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2475 current_event_field.GetSignatureForError ());
2478 $$ = current_event_field;
2480 opt_event_initializer
2481 opt_event_declarators
2485 current_event_field.DocComment = Lexer.consume_doc_comment ();
2486 Lexer.doc_state = XmlCommentState.Allowed;
2489 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2490 current_event_field = null;
2494 EVENT type member_declaration_name
2497 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2498 current_type.AddMember (current_event);
2499 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2501 lexer.EventParsing = true;
2503 event_accessor_declarations
2505 if (current_container.Kind == MemberKind.Interface)
2506 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2508 lexer.EventParsing = false;
2513 current_event.DocComment = Lexer.consume_doc_comment ();
2514 Lexer.doc_state = XmlCommentState.Allowed;
2517 lbag.AppendToMember (current_event, GetLocation ($9));
2518 current_event = null;
2519 current_local_parameters = null;
2525 Error_SyntaxError (yyToken);
2527 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2531 opt_event_initializer
2535 ++lexer.parsing_block;
2537 event_variable_initializer
2539 --lexer.parsing_block;
2540 current_event_field.Initializer = (Expression) $3;
2544 opt_event_declarators
2552 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2554 | event_declarators event_declarator
2556 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2563 var lt = (LocatedToken) $2;
2564 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2565 lbag.AddLocation ($$, GetLocation ($1));
2567 | COMMA IDENTIFIER ASSIGN
2569 ++lexer.parsing_block;
2571 event_variable_initializer
2573 --lexer.parsing_block;
2574 var lt = (LocatedToken) $2;
2575 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2576 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2580 event_variable_initializer
2582 if (current_container.Kind == MemberKind.Interface) {
2583 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2584 current_event_field.GetSignatureForError ());
2587 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2588 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2589 current_event_field.GetSignatureForError ());
2592 variable_initializer
2598 event_accessor_declarations
2599 : add_accessor_declaration remove_accessor_declaration
2600 | remove_accessor_declaration add_accessor_declaration
2601 | add_accessor_declaration
2603 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2604 current_event.GetSignatureForError ());
2606 | remove_accessor_declaration
2608 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2609 current_event.GetSignatureForError ());
2613 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2618 add_accessor_declaration
2619 : opt_attributes opt_modifiers ADD
2621 if ($2 != ModifierNone) {
2622 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2625 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2626 current_local_parameters = current_event.Add.ParameterInfo;
2628 lbag.AddMember (current_event.Add, mod_locations);
2629 lexer.EventParsing = false;
2631 event_accessor_block
2633 lexer.EventParsing = true;
2635 current_event.Add.Block = (ToplevelBlock) $5;
2637 if (current_container.Kind == MemberKind.Interface) {
2638 report.Error (531, current_event.Add.Block.StartLocation,
2639 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2642 current_local_parameters = null;
2646 remove_accessor_declaration
2647 : opt_attributes opt_modifiers REMOVE
2649 if ($2 != ModifierNone) {
2650 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2653 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2654 current_local_parameters = current_event.Remove.ParameterInfo;
2656 lbag.AddMember (current_event.Remove, mod_locations);
2657 lexer.EventParsing = false;
2659 event_accessor_block
2661 lexer.EventParsing = true;
2663 current_event.Remove.Block = (ToplevelBlock) $5;
2665 if (current_container.Kind == MemberKind.Interface) {
2666 report.Error (531, current_event.Remove.Block.StartLocation,
2667 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2670 current_local_parameters = null;
2674 event_accessor_block
2677 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2683 attributes_without_members
2684 : attribute_sections CLOSE_BRACE
2686 current_type.UnattachedAttributes = (Attributes) $1;
2687 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2688 lexer.putback ('}');
2692 // For full ast try to recover incomplete ambiguous member
2693 // declaration in form on class X { public int }
2695 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2697 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2699 lexer.putback ('}');
2701 lexer.parsing_generic_declaration = false;
2702 FullNamedExpression type = (FullNamedExpression) $3;
2703 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2704 current_type.AddField (current_field);
2712 ENUM type_declaration_name
2716 enumTypeComment = Lexer.consume_doc_comment ();
2721 Lexer.doc_state = XmlCommentState.Allowed;
2723 MemberName name = (MemberName) $4;
2724 if (name.IsGeneric) {
2725 report.Error (1675, name.Location, "Enums cannot have type parameters");
2728 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2730 opt_enum_member_declarations
2732 lexer.parsing_modifiers = true;
2734 // here will be evaluated after CLOSE_BLACE is consumed.
2736 Lexer.doc_state = XmlCommentState.Allowed;
2738 CLOSE_BRACE opt_semicolon
2741 current_container.DocComment = enumTypeComment;
2743 --lexer.parsing_declaration;
2746 // em.DocComment = ev.DocComment;
2748 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2749 $$ = pop_current_class ();
2761 Error_TypeExpected (GetLocation ($1));
2766 opt_enum_member_declarations
2768 | enum_member_declarations
2769 | enum_member_declarations COMMA
2771 lbag.AddLocation ($1, GetLocation ($2));
2775 enum_member_declarations
2776 : enum_member_declaration
2777 | enum_member_declarations COMMA enum_member_declaration
2779 lbag.AddLocation ($1, GetLocation ($2));
2784 enum_member_declaration
2785 : opt_attributes IDENTIFIER
2787 var lt = (LocatedToken) $2;
2788 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2789 ((Enum) current_type).AddEnumMember (em);
2792 em.DocComment = Lexer.consume_doc_comment ();
2793 Lexer.doc_state = XmlCommentState.Allowed;
2798 | opt_attributes IDENTIFIER
2800 ++lexer.parsing_block;
2802 tmpComment = Lexer.consume_doc_comment ();
2803 Lexer.doc_state = XmlCommentState.NotAllowed;
2806 ASSIGN constant_expression
2808 --lexer.parsing_block;
2810 var lt = (LocatedToken) $2;
2811 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2812 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2813 ((Enum) current_type).AddEnumMember (em);
2816 em.DocComment = ConsumeStoredComment ();
2820 | opt_attributes IDENTIFIER error
2822 Error_SyntaxError (yyToken);
2824 var lt = (LocatedToken) $2;
2825 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2826 ((Enum) current_type).AddEnumMember (em);
2829 em.DocComment = Lexer.consume_doc_comment ();
2830 Lexer.doc_state = XmlCommentState.Allowed;
2835 | attributes_without_members
2838 delegate_declaration
2842 member_type type_declaration_name
2845 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2847 opt_formal_parameter_list CLOSE_PARENS
2849 valid_param_mod = 0;
2851 ParametersCompiled p = (ParametersCompiled) $8;
2853 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2855 p.CheckParameters (del);
2857 current_container.AddTypeContainer (del);
2859 current_delegate = del;
2860 lexer.ConstraintsParsing = true;
2862 opt_type_parameter_constraints_clauses
2864 lexer.ConstraintsParsing = false;
2869 current_delegate.DocComment = Lexer.consume_doc_comment ();
2870 Lexer.doc_state = XmlCommentState.Allowed;
2874 current_delegate.SetConstraints ((List<Constraints>) $11);
2875 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2877 $$ = current_delegate;
2879 current_delegate = null;
2887 if (lang_version < LanguageVersion.ISO_2)
2888 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2890 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2894 namespace_or_type_expr
2896 | qualified_alias_member IDENTIFIER opt_type_argument_list
2898 var lt1 = (LocatedToken) $1;
2899 var lt2 = (LocatedToken) $2;
2901 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2902 lbag.AddLocation ($$, GetLocation ($2));
2904 | qualified_alias_member IDENTIFIER generic_dimension
2906 var lt1 = (LocatedToken) $1;
2907 var lt2 = (LocatedToken) $2;
2909 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2910 lbag.AddLocation ($$, GetLocation ($2));
2916 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2918 var lt = (LocatedToken) $3;
2919 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2920 lbag.AddLocation ($$, GetLocation ($2));
2922 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2924 var lt = (LocatedToken) $3;
2925 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2926 lbag.AddLocation ($$, GetLocation ($2));
2931 : IDENTIFIER opt_type_argument_list
2933 var lt = (LocatedToken) $1;
2934 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2936 | IDENTIFIER generic_dimension
2938 var lt = (LocatedToken) $1;
2939 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2944 // Generics arguments (any type, without attributes)
2946 opt_type_argument_list
2948 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2950 if (lang_version < LanguageVersion.ISO_2)
2951 FeatureIsNotAvailable (GetLocation ($1), "generics");
2955 | OP_GENERICS_LT error
2957 Error_TypeExpected (lexer.Location);
2958 $$ = new TypeArguments ();
2965 TypeArguments type_args = new TypeArguments ();
2966 type_args.Add ((FullNamedExpression) $1);
2969 | type_arguments COMMA type
2971 TypeArguments type_args = (TypeArguments) $1;
2972 type_args.Add ((FullNamedExpression) $3);
2978 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2980 type_declaration_name
2983 lexer.parsing_generic_declaration = true;
2985 opt_type_parameter_list
2987 lexer.parsing_generic_declaration = false;
2988 var lt = (LocatedToken) $1;
2989 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2993 member_declaration_name
2994 : method_declaration_name
2996 MemberName mn = (MemberName)$1;
2997 if (mn.TypeParameters != null)
2998 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2999 mn.GetSignatureForError ()));
3003 method_declaration_name
3004 : type_declaration_name
3005 | explicit_interface IDENTIFIER opt_type_parameter_list
3007 lexer.parsing_generic_declaration = false;
3008 var lt = (LocatedToken) $2;
3009 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3013 indexer_declaration_name
3016 lexer.parsing_generic_declaration = false;
3017 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3019 | explicit_interface THIS
3021 lexer.parsing_generic_declaration = false;
3022 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3027 : IDENTIFIER opt_type_argument_list DOT
3029 var lt = (LocatedToken) $1;
3030 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3031 lbag.AddLocation ($$, GetLocation ($3));
3033 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3035 var lt1 = (LocatedToken) $1;
3036 var lt2 = (LocatedToken) $2;
3038 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3039 lbag.AddLocation ($$, GetLocation ($4));
3041 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3043 var lt = (LocatedToken) $2;
3044 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3045 lbag.AddLocation ($$, GetLocation ($4));
3049 opt_type_parameter_list
3051 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3053 if (lang_version < LanguageVersion.ISO_2)
3054 FeatureIsNotAvailable (GetLocation ($1), "generics");
3057 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3064 var tparams = new TypeParameters ();
3065 tparams.Add ((TypeParameter)$1);
3068 | type_parameters COMMA type_parameter
3070 var tparams = (TypeParameters) $1;
3071 tparams.Add ((TypeParameter)$3);
3073 lbag.AddLocation ($3, GetLocation ($3));
3078 : opt_attributes opt_type_parameter_variance IDENTIFIER
3080 var lt = (LocatedToken)$3;
3081 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3085 if (GetTokenName (yyToken) == "type")
3086 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3088 Error_SyntaxError (yyToken);
3090 $$ = new TypeParameter (MemberName.Null, null, null);
3095 // All types where void is allowed
3098 : type_expression_or_array
3101 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3108 lexer.parsing_generic_declaration = true;
3113 // A type which does not allow `void' to be used
3116 : type_expression_or_array
3119 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3120 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3128 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3129 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3134 : type_expression_or_array
3137 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3138 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3142 type_expression_or_array
3144 | type_expression rank_specifiers
3146 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3151 : namespace_or_type_expr opt_nullable
3154 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3156 var sn = $1 as SimpleName;
3157 if (sn != null && sn.Name == "var")
3158 $$ = new VarExpr (sn.Location);
3163 | namespace_or_type_expr pointer_stars
3165 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3167 | builtin_types opt_nullable
3170 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3172 | builtin_types pointer_stars
3174 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3176 | VOID pointer_stars
3178 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3185 var types = new List<FullNamedExpression> (2);
3186 types.Add ((FullNamedExpression) $1);
3189 | type_list COMMA base_type_name
3191 var types = (List<FullNamedExpression>) $1;
3192 types.Add ((FullNamedExpression) $3);
3200 if ($1 is ComposedCast) {
3201 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3208 * replaces all the productions for isolating the various
3209 * simple types, but we need this to reuse it easily in variable_type
3212 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3213 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3214 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3215 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3216 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3217 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3222 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3223 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3224 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3225 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3226 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3227 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3228 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3229 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3230 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3234 // Expressions, section 7.5
3239 : primary_expression_or_type
3241 | array_creation_expression
3242 | parenthesized_expression
3243 | default_value_expression
3244 | invocation_expression
3248 | post_increment_expression
3249 | post_decrement_expression
3250 | object_or_delegate_creation_expression
3251 | anonymous_type_expression
3254 | checked_expression
3255 | unchecked_expression
3256 | pointer_member_access
3257 | anonymous_method_expression
3258 | undocumented_expressions
3261 primary_expression_or_type
3263 | IDENTIFIER GENERATE_COMPLETION {
3264 var lt = (LocatedToken) $1;
3265 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3273 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3277 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3278 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3283 // Here is the trick, tokenizer may think that parens is a special but
3284 // parser is interested in open parens only, so we merge them.
3285 // Consider: if (a)foo ();
3293 // Use this production to accept closing parenthesis or
3294 // performing completion
3298 | COMPLETE_COMPLETION
3302 parenthesized_expression
3303 : OPEN_PARENS expression CLOSE_PARENS
3305 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3306 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3308 | OPEN_PARENS expression COMPLETE_COMPLETION
3310 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3315 : primary_expression DOT identifier_inside_body opt_type_argument_list
3317 var lt = (LocatedToken) $3;
3318 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3319 lbag.AddLocation ($$, GetLocation ($2));
3321 | primary_expression DOT identifier_inside_body generic_dimension
3323 var lt = (LocatedToken) $3;
3324 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3325 lbag.AddLocation ($$, GetLocation ($2));
3327 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3329 if (lang_version < LanguageVersion.V_6)
3330 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3332 var lt = (LocatedToken) $4;
3333 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3334 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3336 | builtin_types DOT identifier_inside_body opt_type_argument_list
3338 var lt = (LocatedToken) $3;
3339 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3340 lbag.AddLocation ($$, GetLocation ($2));
3342 | BASE DOT identifier_inside_body opt_type_argument_list
3344 var lt = (LocatedToken) $3;
3345 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3346 lbag.AddLocation ($$, GetLocation ($2));
3348 | AWAIT DOT identifier_inside_body opt_type_argument_list
3350 var lt = (LocatedToken) $3;
3351 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3352 lbag.AddLocation ($$, GetLocation ($2));
3354 | qualified_alias_member identifier_inside_body opt_type_argument_list
3356 var lt1 = (LocatedToken) $1;
3357 var lt2 = (LocatedToken) $2;
3359 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3360 lbag.AddLocation ($$, GetLocation ($2));
3362 | qualified_alias_member identifier_inside_body generic_dimension
3364 var lt1 = (LocatedToken) $1;
3365 var lt2 = (LocatedToken) $2;
3367 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3368 lbag.AddLocation ($$, GetLocation ($2));
3370 | primary_expression DOT GENERATE_COMPLETION {
3371 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3373 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3374 var lt = (LocatedToken) $3;
3375 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3377 | builtin_types DOT GENERATE_COMPLETION
3379 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3381 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3382 var lt = (LocatedToken) $3;
3383 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3387 invocation_expression
3388 : primary_expression open_parens_any opt_argument_list close_parens
3390 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3391 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3393 | primary_expression open_parens_any argument_list error
3395 Error_SyntaxError (yyToken);
3397 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3398 lbag.AddLocation ($$, GetLocation ($2));
3400 | primary_expression open_parens_any error
3402 Error_SyntaxError (yyToken);
3404 $$ = new Invocation ((Expression) $1, null);
3405 lbag.AddLocation ($$, GetLocation ($2));
3409 opt_object_or_collection_initializer
3410 : /* empty */ { $$ = null; }
3411 | object_or_collection_initializer
3414 object_or_collection_initializer
3415 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3418 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3420 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3422 lbag.AddLocation ($$, GetLocation ($3));
3424 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3426 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3427 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3431 opt_member_initializer_list
3432 : /* empty */ { $$ = null; }
3433 | member_initializer_list
3439 member_initializer_list
3440 : member_initializer
3442 var a = new List<Expression> ();
3443 a.Add ((Expression) $1);
3446 | member_initializer_list COMMA member_initializer
3448 var a = (List<Expression>)$1;
3449 a.Add ((Expression) $3);
3452 | member_initializer_list error {
3453 Error_SyntaxError (yyToken);
3459 : IDENTIFIER ASSIGN initializer_value
3461 var lt = (LocatedToken) $1;
3462 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3463 lbag.AddLocation ($$, GetLocation ($2));
3465 | AWAIT ASSIGN initializer_value
3467 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3468 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3469 lbag.AddLocation ($$, GetLocation ($2));
3471 | GENERATE_COMPLETION
3473 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3475 | non_assignment_expression opt_COMPLETE_COMPLETION {
3476 CompletionSimpleName csn = $1 as CompletionSimpleName;
3478 $$ = new CollectionElementInitializer ((Expression)$1);
3480 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3482 | OPEN_BRACE expression_list CLOSE_BRACE
3485 $$ = new CollectionElementInitializer (GetLocation ($1));
3487 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3489 lbag.AddLocation ($$, GetLocation ($3));
3491 | OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET ASSIGN initializer_value
3493 if (lang_version < LanguageVersion.V_6)
3494 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3496 $$ = new DictionaryElementInitializer ((List<Expression>)$2, (Expression) $5, GetLocation ($1));
3497 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3499 | OPEN_BRACE CLOSE_BRACE
3501 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3502 $$ = new CollectionElementInitializer (GetLocation ($1));
3503 lbag.AddLocation ($$, GetLocation ($2));
3509 | object_or_collection_initializer
3513 : /* empty */ { $$ = null; }
3518 : argument_or_named_argument
3520 Arguments list = new Arguments (4);
3521 list.Add ((Argument) $1);
3524 | argument_list COMMA argument
3526 Arguments list = (Arguments) $1;
3527 if (list [list.Count - 1] is NamedArgument)
3528 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3530 list.Add ((Argument) $3);
3533 | argument_list COMMA named_argument
3535 Arguments list = (Arguments) $1;
3536 NamedArgument a = (NamedArgument) $3;
3537 for (int i = 0; i < list.Count; ++i) {
3538 NamedArgument na = list [i] as NamedArgument;
3539 if (na != null && na.Name == a.Name)
3540 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3547 | argument_list COMMA error
3549 if (lexer.putback_char == -1)
3550 lexer.putback (')'); // TODO: Wrong but what can I do
3551 Error_SyntaxError (yyToken);
3556 report.Error (839, GetLocation ($1), "An argument is missing");
3564 $$ = new Argument ((Expression) $1);
3566 | non_simple_argument
3569 argument_or_named_argument
3575 : REF variable_reference
3577 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3578 lbag.AddLocation ($$, GetLocation ($1));
3580 | OUT variable_reference
3582 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3583 lbag.AddLocation ($$, GetLocation ($1));
3585 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3587 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3588 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3590 | ARGLIST OPEN_PARENS CLOSE_PARENS
3592 $$ = new Argument (new Arglist (GetLocation ($1)));
3593 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3602 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3604 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3605 lbag.AddLocation ($$, GetLocation ($4));
3607 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3609 if (lang_version < LanguageVersion.V_6)
3610 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3612 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3613 ConditionalAccess = true
3616 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3618 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3620 Error_SyntaxError (yyToken);
3621 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3623 | primary_expression OPEN_BRACKET_EXPR error
3625 Error_SyntaxError (yyToken);
3626 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3631 : expression_or_error
3633 var list = new List<Expression> (4);
3634 list.Add ((Expression) $1);
3637 | expression_list COMMA expression_or_error
3639 var list = (List<Expression>) $1;
3640 list.Add ((Expression) $3);
3645 expression_list_arguments
3646 : expression_list_argument
3648 Arguments args = new Arguments (4);
3649 args.Add ((Argument) $1);
3652 | expression_list_arguments COMMA expression_list_argument
3654 Arguments args = (Arguments) $1;
3655 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3656 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3658 args.Add ((Argument) $3);
3663 expression_list_argument
3666 $$ = new Argument ((Expression) $1);
3674 $$ = new This (GetLocation ($1));
3679 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3681 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3682 lbag.AddLocation ($$, GetLocation ($4));
3684 | BASE OPEN_BRACKET error
3686 Error_SyntaxError (yyToken);
3687 $$ = new ElementAccess (null, null, GetLocation ($2));
3691 post_increment_expression
3692 : primary_expression OP_INC
3694 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3698 post_decrement_expression
3699 : primary_expression OP_DEC
3701 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3705 object_or_delegate_creation_expression
3706 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3709 if (lang_version <= LanguageVersion.ISO_2)
3710 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3712 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3714 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3717 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3719 | NEW new_expr_type object_or_collection_initializer
3721 if (lang_version <= LanguageVersion.ISO_2)
3722 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3724 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3728 array_creation_expression
3729 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3731 opt_array_initializer
3733 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3734 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3735 Next = (ComposedTypeSpecifier) $6
3736 }, (ArrayInitializer) $7, GetLocation ($1));
3737 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3739 | NEW new_expr_type rank_specifiers opt_array_initializer
3742 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3744 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3746 | NEW rank_specifier array_initializer
3748 if (lang_version <= LanguageVersion.ISO_2)
3749 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3751 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3753 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3755 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3756 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3758 | NEW new_expr_type error
3760 Error_SyntaxError (yyToken);
3761 // It can be any of new expression, create the most common one
3762 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3768 ++lexer.parsing_type;
3772 --lexer.parsing_type;
3777 anonymous_type_expression
3778 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3780 if (lang_version <= LanguageVersion.ISO_2)
3781 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3783 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3785 // TODO: lbag comma location
3786 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3788 | NEW OPEN_BRACE GENERATE_COMPLETION
3790 $$ = new EmptyCompletion ();
3794 anonymous_type_parameters_opt_comma
3795 : anonymous_type_parameters_opt
3796 | anonymous_type_parameters COMMA
3799 anonymous_type_parameters_opt
3801 | anonymous_type_parameters
3804 anonymous_type_parameters
3805 : anonymous_type_parameter
3807 var a = new List<AnonymousTypeParameter> (4);
3808 a.Add ((AnonymousTypeParameter) $1);
3811 | anonymous_type_parameters COMMA anonymous_type_parameter
3813 var a = (List<AnonymousTypeParameter>) $1;
3814 a.Add ((AnonymousTypeParameter) $3);
3817 | COMPLETE_COMPLETION
3819 $$ = new EmptyCompletion ();
3821 | anonymous_type_parameter COMPLETE_COMPLETION
3827 anonymous_type_parameter
3828 : identifier_inside_body ASSIGN variable_initializer
3830 var lt = (LocatedToken)$1;
3831 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3832 lbag.AddLocation ($$, GetLocation ($2));
3834 | identifier_inside_body
3836 var lt = (LocatedToken)$1;
3837 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3838 lt.Value, lt.Location);
3842 MemberAccess ma = (MemberAccess) $1;
3843 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3847 report.Error (746, lexer.Location,
3848 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3860 | rank_specifier rank_specifiers
3862 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3868 : OPEN_BRACKET CLOSE_BRACKET
3870 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3871 lbag.AddLocation ($$, GetLocation ($2));
3873 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3875 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3876 lbag.AddLocation ($$, GetLocation ($3));
3885 | dim_separators COMMA
3887 $$ = ((int) $1) + 1;
3891 opt_array_initializer
3903 : OPEN_BRACE CLOSE_BRACE
3905 var ai = new ArrayInitializer (0, GetLocation ($1));
3906 ai.VariableDeclaration = current_variable;
3907 lbag.AddLocation (ai, GetLocation ($2));
3910 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3912 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3913 ai.VariableDeclaration = current_variable;
3915 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3917 lbag.AddLocation (ai, GetLocation ($4));
3923 variable_initializer_list
3924 : variable_initializer
3926 var list = new List<Expression> (4);
3927 list.Add ((Expression) $1);
3930 | variable_initializer_list COMMA variable_initializer
3932 var list = (List<Expression>) $1;
3933 list.Add ((Expression) $3);
3939 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
3941 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
3942 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3946 typeof_type_expression
3950 Error_TypeExpected (lexer.Location);
3958 if (lang_version < LanguageVersion.ISO_2)
3959 FeatureIsNotAvailable (GetLocation ($1), "generics");
3965 qualified_alias_member
3966 : IDENTIFIER DOUBLE_COLON
3968 var lt = (LocatedToken) $1;
3969 if (lang_version == LanguageVersion.ISO_1)
3970 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3977 : SIZEOF open_parens_any type CLOSE_PARENS
3979 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3980 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3982 | SIZEOF open_parens_any type error
3984 Error_SyntaxError (yyToken);
3986 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3987 lbag.AddLocation ($$, GetLocation ($2));
3992 : CHECKED open_parens_any expression CLOSE_PARENS
3994 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3995 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3999 Error_SyntaxError (yyToken);
4001 $$ = new CheckedExpr (null, GetLocation ($1));
4005 unchecked_expression
4006 : UNCHECKED open_parens_any expression CLOSE_PARENS
4008 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4009 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4013 Error_SyntaxError (yyToken);
4015 $$ = new UnCheckedExpr (null, GetLocation ($1));
4019 pointer_member_access
4020 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4022 var lt = (LocatedToken) $3;
4023 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4027 anonymous_method_expression
4028 : DELEGATE opt_anonymous_method_signature
4030 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4034 $$ = end_anonymous ((ParametersBlock) $4);
4036 | ASYNC DELEGATE opt_anonymous_method_signature
4038 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4042 $$ = end_anonymous ((ParametersBlock) $5);
4046 opt_anonymous_method_signature
4049 $$ = ParametersCompiled.Undefined;
4051 | anonymous_method_signature
4054 anonymous_method_signature
4057 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4059 opt_formal_parameter_list CLOSE_PARENS
4061 valid_param_mod = 0;
4066 default_value_expression
4067 : DEFAULT open_parens_any type CLOSE_PARENS
4069 if (lang_version < LanguageVersion.ISO_2)
4070 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4072 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4073 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4078 : primary_expression
4079 | BANG prefixed_unary_expression
4081 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4083 | TILDE prefixed_unary_expression
4085 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4087 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4089 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4090 lbag.AddLocation ($$, GetLocation ($3));
4092 | AWAIT prefixed_unary_expression
4095 if (current_anonymous_method is LambdaExpression) {
4096 report.Error (4034, GetLocation ($1),
4097 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4098 } else if (current_anonymous_method != null) {
4099 report.Error (4035, GetLocation ($1),
4100 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4101 } else if (interactive_async != null) {
4102 current_block.Explicit.RegisterAsyncAwait ();
4103 interactive_async = true;
4105 report.Error (4033, GetLocation ($1),
4106 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4109 current_block.Explicit.RegisterAsyncAwait ();
4112 $$ = new Await ((Expression) $2, GetLocation ($1));
4116 Error_SyntaxError (yyToken);
4118 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4122 Error_SyntaxError (yyToken);
4124 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4126 | OPEN_PARENS_CAST type CLOSE_PARENS error
4128 Error_SyntaxError (yyToken);
4130 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4131 lbag.AddLocation ($$, GetLocation ($3));
4135 Error_SyntaxError (yyToken);
4137 $$ = new Await (null, GetLocation ($1));
4142 // The idea to split this out is from Rhys' grammar
4143 // to solve the problem with casts.
4145 prefixed_unary_expression
4147 | PLUS prefixed_unary_expression
4149 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4151 | MINUS prefixed_unary_expression
4153 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4155 | OP_INC prefixed_unary_expression
4157 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4159 | OP_DEC prefixed_unary_expression
4161 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4163 | STAR prefixed_unary_expression
4165 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4167 | BITWISE_AND prefixed_unary_expression
4169 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4173 Error_SyntaxError (yyToken);
4175 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4179 Error_SyntaxError (yyToken);
4181 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4185 Error_SyntaxError (yyToken);
4187 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4191 Error_SyntaxError (yyToken);
4193 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4197 Error_SyntaxError (yyToken);
4199 $$ = new Indirection (null, GetLocation ($1));
4203 Error_SyntaxError (yyToken);
4205 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4209 multiplicative_expression
4210 : prefixed_unary_expression
4211 | multiplicative_expression STAR prefixed_unary_expression
4213 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4214 lbag.AddLocation ($$, GetLocation ($2));
4216 | multiplicative_expression DIV prefixed_unary_expression
4218 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4219 lbag.AddLocation ($$, GetLocation ($2));
4221 | multiplicative_expression PERCENT prefixed_unary_expression
4223 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4224 lbag.AddLocation ($$, GetLocation ($2));
4226 | multiplicative_expression STAR error
4228 Error_SyntaxError (yyToken);
4230 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4231 lbag.AddLocation ($$, GetLocation ($2));
4233 | multiplicative_expression DIV error
4235 Error_SyntaxError (yyToken);
4237 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4238 lbag.AddLocation ($$, GetLocation ($2));
4240 | multiplicative_expression PERCENT error
4242 Error_SyntaxError (yyToken);
4244 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4245 lbag.AddLocation ($$, GetLocation ($2));
4250 : multiplicative_expression
4251 | additive_expression PLUS multiplicative_expression
4253 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4254 lbag.AddLocation ($$, GetLocation ($2));
4256 | additive_expression MINUS multiplicative_expression
4258 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4259 lbag.AddLocation ($$, GetLocation ($2));
4261 | additive_expression AS type
4263 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4265 | additive_expression IS type opt_identifier
4267 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4269 if (lang_version != LanguageVersion.Experimental)
4270 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4272 var lt = (LocatedToken) $4;
4273 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4274 current_block.AddLocalName (is_expr.Variable);
4279 | additive_expression PLUS error
4281 Error_SyntaxError (yyToken);
4283 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4284 lbag.AddLocation ($$, GetLocation ($2));
4286 | additive_expression MINUS error
4288 Error_SyntaxError (yyToken);
4290 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4291 lbag.AddLocation ($$, GetLocation ($2));
4293 | additive_expression AS error
4295 Error_SyntaxError (yyToken);
4297 $$ = new As ((Expression) $1, null, GetLocation ($2));
4299 | additive_expression IS error
4301 Error_SyntaxError (yyToken);
4303 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4307 var lt = (LocatedToken) $1;
4308 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4312 var lt = (LocatedToken) $1;
4313 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4318 : additive_expression
4319 | shift_expression OP_SHIFT_LEFT additive_expression
4321 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4322 lbag.AddLocation ($$, GetLocation ($2));
4324 | shift_expression OP_SHIFT_RIGHT additive_expression
4326 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4327 lbag.AddLocation ($$, GetLocation ($2));
4329 | shift_expression OP_SHIFT_LEFT error
4331 Error_SyntaxError (yyToken);
4333 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4334 lbag.AddLocation ($$, GetLocation ($2));
4336 | shift_expression OP_SHIFT_RIGHT error
4338 Error_SyntaxError (yyToken);
4340 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4341 lbag.AddLocation ($$, GetLocation ($2));
4345 relational_expression
4347 | relational_expression OP_LT shift_expression
4349 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4350 lbag.AddLocation ($$, GetLocation ($2));
4352 | relational_expression OP_GT shift_expression
4354 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4355 lbag.AddLocation ($$, GetLocation ($2));
4357 | relational_expression OP_LE shift_expression
4359 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4360 lbag.AddLocation ($$, GetLocation ($2));
4362 | relational_expression OP_GE shift_expression
4364 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4365 lbag.AddLocation ($$, GetLocation ($2));
4367 | relational_expression OP_LT error
4369 Error_SyntaxError (yyToken);
4371 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4372 lbag.AddLocation ($$, GetLocation ($2));
4374 | relational_expression OP_GT error
4376 Error_SyntaxError (yyToken);
4378 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4379 lbag.AddLocation ($$, GetLocation ($2));
4381 | relational_expression OP_LE error
4383 Error_SyntaxError (yyToken);
4385 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4386 lbag.AddLocation ($$, GetLocation ($2));
4388 | relational_expression OP_GE error
4390 Error_SyntaxError (yyToken);
4392 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4393 lbag.AddLocation ($$, GetLocation ($2));
4398 : relational_expression
4399 | equality_expression OP_EQ relational_expression
4401 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4402 lbag.AddLocation ($$, GetLocation ($2));
4404 | equality_expression OP_NE relational_expression
4406 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4407 lbag.AddLocation ($$, GetLocation ($2));
4409 | equality_expression OP_EQ error
4411 Error_SyntaxError (yyToken);
4413 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4414 lbag.AddLocation ($$, GetLocation ($2));
4416 | equality_expression OP_NE error
4418 Error_SyntaxError (yyToken);
4420 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4421 lbag.AddLocation ($$, GetLocation ($2));
4426 : equality_expression
4427 | and_expression BITWISE_AND equality_expression
4429 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4430 lbag.AddLocation ($$, GetLocation ($2));
4432 | and_expression BITWISE_AND error
4434 Error_SyntaxError (yyToken);
4436 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4437 lbag.AddLocation ($$, GetLocation ($2));
4441 exclusive_or_expression
4443 | exclusive_or_expression CARRET and_expression
4445 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4446 lbag.AddLocation ($$, GetLocation ($2));
4448 | exclusive_or_expression CARRET error
4450 Error_SyntaxError (yyToken);
4452 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4453 lbag.AddLocation ($$, GetLocation ($2));
4457 inclusive_or_expression
4458 : exclusive_or_expression
4459 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4461 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4462 lbag.AddLocation ($$, GetLocation ($2));
4464 | inclusive_or_expression BITWISE_OR error
4466 Error_SyntaxError (yyToken);
4468 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4469 lbag.AddLocation ($$, GetLocation ($2));
4473 conditional_and_expression
4474 : inclusive_or_expression
4475 | conditional_and_expression OP_AND inclusive_or_expression
4477 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4478 lbag.AddLocation ($$, GetLocation ($2));
4480 | conditional_and_expression OP_AND error
4482 Error_SyntaxError (yyToken);
4484 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4485 lbag.AddLocation ($$, GetLocation ($2));
4489 conditional_or_expression
4490 : conditional_and_expression
4491 | conditional_or_expression OP_OR conditional_and_expression
4493 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4494 lbag.AddLocation ($$, GetLocation ($2));
4496 | conditional_or_expression OP_OR error
4498 Error_SyntaxError (yyToken);
4500 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4501 lbag.AddLocation ($$, GetLocation ($2));
4505 null_coalescing_expression
4506 : conditional_or_expression
4507 | conditional_or_expression OP_COALESCING null_coalescing_expression
4509 if (lang_version < LanguageVersion.ISO_2)
4510 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4512 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4513 lbag.AddLocation ($$, GetLocation ($2));
4517 conditional_expression
4518 : null_coalescing_expression
4519 | null_coalescing_expression INTERR expression COLON expression
4521 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4522 lbag.AddLocation ($$, GetLocation ($4));
4524 | null_coalescing_expression INTERR expression error
4526 Error_SyntaxError (yyToken);
4528 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4530 | null_coalescing_expression INTERR expression COLON error
4532 Error_SyntaxError (yyToken);
4534 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4535 lbag.AddLocation ($$, GetLocation ($4));
4537 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4539 Error_SyntaxError (Token.CLOSE_BRACE);
4541 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4542 lbag.AddLocation ($$, GetLocation ($4));
4543 lexer.putback ('}');
4547 assignment_expression
4548 : prefixed_unary_expression ASSIGN expression
4550 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4551 lbag.AddLocation ($$, GetLocation ($2));
4553 | prefixed_unary_expression OP_MULT_ASSIGN expression
4555 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4556 lbag.AddLocation ($$, GetLocation ($2));
4558 | prefixed_unary_expression OP_DIV_ASSIGN expression
4560 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4561 lbag.AddLocation ($$, GetLocation ($2));
4563 | prefixed_unary_expression OP_MOD_ASSIGN expression
4565 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4566 lbag.AddLocation ($$, GetLocation ($2));
4568 | prefixed_unary_expression OP_ADD_ASSIGN expression
4570 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4571 lbag.AddLocation ($$, GetLocation ($2));
4573 | prefixed_unary_expression OP_SUB_ASSIGN expression
4575 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4576 lbag.AddLocation ($$, GetLocation ($2));
4578 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4580 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4581 lbag.AddLocation ($$, GetLocation ($2));
4583 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4585 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4586 lbag.AddLocation ($$, GetLocation ($2));
4588 | prefixed_unary_expression OP_AND_ASSIGN expression
4590 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4591 lbag.AddLocation ($$, GetLocation ($2));
4593 | prefixed_unary_expression OP_OR_ASSIGN expression
4595 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4596 lbag.AddLocation ($$, GetLocation ($2));
4598 | prefixed_unary_expression OP_XOR_ASSIGN expression
4600 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4601 lbag.AddLocation ($$, GetLocation ($2));
4605 lambda_parameter_list
4608 var pars = new List<Parameter> (4);
4609 pars.Add ((Parameter) $1);
4613 | lambda_parameter_list COMMA lambda_parameter
4615 var pars = (List<Parameter>) $1;
4616 Parameter p = (Parameter)$3;
4617 if (pars[0].GetType () != p.GetType ()) {
4618 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4627 : parameter_modifier parameter_type identifier_inside_body
4629 var lt = (LocatedToken) $3;
4631 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4633 | parameter_type identifier_inside_body
4635 var lt = (LocatedToken) $2;
4637 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4641 var lt = (LocatedToken) $1;
4642 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4646 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4647 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4651 opt_lambda_parameter_list
4652 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4653 | lambda_parameter_list {
4654 var pars_list = (List<Parameter>) $1;
4655 $$ = new ParametersCompiled (pars_list.ToArray ());
4659 lambda_expression_body
4661 start_block (Location.Null);
4663 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4665 Block b = end_block (Location.Null);
4666 b.IsCompilerGenerated = true;
4667 b.AddStatement (new ContextualReturn ((Expression) $2));
4673 // Handles only cases like foo = x.FirstOrDefault (l => );
4674 // where we must restore current_variable
4675 Block b = end_block (Location.Null);
4676 b.IsCompilerGenerated = true;
4678 Error_SyntaxError (yyToken);
4687 Error_SyntaxError (yyToken);
4695 var lt = (LocatedToken) $1;
4696 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4697 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4699 lambda_expression_body
4701 $$ = end_anonymous ((ParametersBlock) $4);
4702 lbag.AddLocation ($$, GetLocation ($2));
4706 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4707 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4708 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4710 lambda_expression_body
4712 $$ = end_anonymous ((ParametersBlock) $4);
4713 lbag.AddLocation ($$, GetLocation ($2));
4715 | ASYNC identifier_inside_body ARROW
4717 var lt = (LocatedToken) $2;
4718 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4719 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4721 lambda_expression_body
4723 $$ = end_anonymous ((ParametersBlock) $5);
4724 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4726 | OPEN_PARENS_LAMBDA
4728 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4730 opt_lambda_parameter_list CLOSE_PARENS ARROW
4732 valid_param_mod = 0;
4733 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4735 lambda_expression_body
4737 $$ = end_anonymous ((ParametersBlock) $7);
4738 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4740 | ASYNC OPEN_PARENS_LAMBDA
4742 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4744 opt_lambda_parameter_list CLOSE_PARENS ARROW
4746 valid_param_mod = 0;
4747 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4749 lambda_expression_body
4751 $$ = end_anonymous ((ParametersBlock) $8);
4752 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4757 : assignment_expression
4758 | non_assignment_expression
4761 non_assignment_expression
4762 : conditional_expression
4767 $$ = new ArglistAccess (GetLocation ($1));
4771 undocumented_expressions
4772 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4774 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4775 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4777 | REFTYPE open_parens_any expression CLOSE_PARENS
4779 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4780 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4782 | MAKEREF open_parens_any expression CLOSE_PARENS
4784 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4785 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4796 $$ = new BooleanExpression ((Expression) $1);
4800 opt_primary_parameters
4805 | primary_parameters
4809 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4813 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4814 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4816 if (lang_version < LanguageVersion.V_6)
4817 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
4821 opt_primary_parameters_with_class_base
4830 | primary_parameters
4834 | primary_parameters class_base
4838 | primary_parameters class_base OPEN_PARENS
4840 ++lexer.parsing_block;
4841 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
4843 opt_argument_list CLOSE_PARENS
4845 lbag.AppendToMember (current_container, GetLocation ($6));
4846 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
4847 --lexer.parsing_block;
4863 type_declaration_name
4865 lexer.ConstraintsParsing = true;
4867 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4868 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4869 FeatureIsNotAvailable (c.Location, "static classes");
4872 push_current_container (c, $3);
4873 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4875 opt_primary_parameters_with_class_base
4876 opt_type_parameter_constraints_clauses
4878 valid_param_mod = 0;
4879 lexer.ConstraintsParsing = false;
4882 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4885 current_container.SetConstraints ((List<Constraints>) $9);
4886 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4889 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4890 Lexer.doc_state = XmlCommentState.Allowed;
4893 lexer.parsing_modifiers = true;
4895 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4897 --lexer.parsing_declaration;
4899 Lexer.doc_state = XmlCommentState.Allowed;
4904 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4906 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4908 $$ = pop_current_class ();
4916 { $$ = $1; } // location
4922 mod_locations = null;
4924 lexer.parsing_modifiers = false;
4928 lexer.parsing_modifiers = false;
4934 | modifiers modifier
4936 var m1 = (Modifiers) $1;
4937 var m2 = (Modifiers) $2;
4939 if ((m1 & m2) != 0) {
4940 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4941 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4942 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4943 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4944 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4945 "More than one protection modifier specified");
4956 StoreModifierLocation ($$, GetLocation ($1));
4958 if (current_container.Kind == MemberKind.Namespace)
4959 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4963 $$ = Modifiers.PUBLIC;
4964 StoreModifierLocation ($$, GetLocation ($1));
4968 $$ = Modifiers.PROTECTED;
4969 StoreModifierLocation ($$, GetLocation ($1));
4973 $$ = Modifiers.INTERNAL;
4974 StoreModifierLocation ($$, GetLocation ($1));
4978 $$ = Modifiers.PRIVATE;
4979 StoreModifierLocation ($$, GetLocation ($1));
4983 $$ = Modifiers.ABSTRACT;
4984 StoreModifierLocation ($$, GetLocation ($1));
4988 $$ = Modifiers.SEALED;
4989 StoreModifierLocation ($$, GetLocation ($1));
4993 $$ = Modifiers.STATIC;
4994 StoreModifierLocation ($$, GetLocation ($1));
4998 $$ = Modifiers.READONLY;
4999 StoreModifierLocation ($$, GetLocation ($1));
5003 $$ = Modifiers.VIRTUAL;
5004 StoreModifierLocation ($$, GetLocation ($1));
5008 $$ = Modifiers.OVERRIDE;
5009 StoreModifierLocation ($$, GetLocation ($1));
5013 $$ = Modifiers.EXTERN;
5014 StoreModifierLocation ($$, GetLocation ($1));
5018 $$ = Modifiers.VOLATILE;
5019 StoreModifierLocation ($$, GetLocation ($1));
5023 $$ = Modifiers.UNSAFE;
5024 StoreModifierLocation ($$, GetLocation ($1));
5025 if (!settings.Unsafe)
5026 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5030 $$ = Modifiers.ASYNC;
5031 StoreModifierLocation ($$, GetLocation ($1));
5043 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5045 | COLON type_list error
5047 Error_SyntaxError (yyToken);
5049 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5053 opt_type_parameter_constraints_clauses
5055 | type_parameter_constraints_clauses
5061 type_parameter_constraints_clauses
5062 : type_parameter_constraints_clause
5064 var constraints = new List<Constraints> (1);
5065 constraints.Add ((Constraints) $1);
5068 | type_parameter_constraints_clauses type_parameter_constraints_clause
5070 var constraints = (List<Constraints>) $1;
5071 Constraints new_constraint = (Constraints)$2;
5073 foreach (Constraints c in constraints) {
5074 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5075 report.Error (409, new_constraint.Location,
5076 "A constraint clause has already been specified for type parameter `{0}'",
5077 new_constraint.TypeParameter.Value);
5081 constraints.Add (new_constraint);
5086 type_parameter_constraints_clause
5087 : WHERE IDENTIFIER COLON type_parameter_constraints
5089 var lt = (LocatedToken) $2;
5090 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5091 lbag.AddLocation ($$, GetLocation ($3));
5093 | WHERE IDENTIFIER error
5095 Error_SyntaxError (yyToken);
5097 var lt = (LocatedToken) $2;
5098 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5102 type_parameter_constraints
5103 : type_parameter_constraint
5105 var constraints = new List<FullNamedExpression> (1);
5106 constraints.Add ((FullNamedExpression) $1);
5109 | type_parameter_constraints COMMA type_parameter_constraint
5111 var constraints = (List<FullNamedExpression>) $1;
5112 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5113 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5114 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5117 prev = $3 as SpecialContraintExpr;
5119 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5120 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5122 prev = constraints [0] as SpecialContraintExpr;
5123 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5124 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5129 constraints.Add ((FullNamedExpression) $3);
5134 type_parameter_constraint
5137 if ($1 is ComposedCast)
5138 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5142 | NEW OPEN_PARENS CLOSE_PARENS
5144 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5145 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5149 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5153 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5157 opt_type_parameter_variance
5162 | type_parameter_variance
5164 if (lang_version <= LanguageVersion.V_3)
5165 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5171 type_parameter_variance
5174 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5178 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5187 // A block is "contained" on the following places:
5189 // property_declaration as part of the accessor body (get/set)
5190 // operator_declaration
5191 // constructor_declaration
5192 // destructor_declaration
5193 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5198 ++lexer.parsing_block;
5199 start_block (GetLocation ($1));
5201 opt_statement_list block_end
5210 --lexer.parsing_block;
5211 $$ = end_block (GetLocation ($1));
5213 | COMPLETE_COMPLETION
5215 --lexer.parsing_block;
5216 $$ = end_block (lexer.Location);
5224 ++lexer.parsing_block;
5225 current_block.StartLocation = GetLocation ($1);
5227 opt_statement_list CLOSE_BRACE
5229 --lexer.parsing_block;
5230 $$ = end_block (GetLocation ($4));
5241 | statement_list statement
5245 : block_variable_declaration
5247 current_block.AddStatement ((Statement) $1);
5249 | valid_declaration_statement
5251 current_block.AddStatement ((Statement) $1);
5256 Error_SyntaxError (yyToken);
5262 // The interactive_statement and its derivatives are only
5263 // used to provide a special version of `expression_statement'
5264 // that has a side effect of assigning the expression to
5267 interactive_statement_list
5268 : interactive_statement
5269 | interactive_statement_list interactive_statement
5272 interactive_statement
5273 : block_variable_declaration
5275 current_block.AddStatement ((Statement) $1);
5277 | interactive_valid_declaration_statement
5279 current_block.AddStatement ((Statement) $1);
5284 valid_declaration_statement
5287 | expression_statement
5288 | selection_statement
5289 | iteration_statement
5293 | unchecked_statement
5300 interactive_valid_declaration_statement
5303 | interactive_expression_statement
5304 | selection_statement
5305 | iteration_statement
5309 | unchecked_statement
5317 : valid_declaration_statement
5318 | block_variable_declaration
5320 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5325 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5330 Error_SyntaxError (yyToken);
5331 $$ = new EmptyStatement (GetLocation ($1));
5338 // Uses lexer.Location because semicolon location is not kept in quick mode
5339 $$ = new EmptyStatement (lexer.Location);
5344 : identifier_inside_body COLON
5346 var lt = (LocatedToken) $1;
5347 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5348 lbag.AddLocation (labeled, GetLocation ($2));
5349 current_block.AddLabel (labeled);
5350 current_block.AddStatement (labeled);
5356 : variable_type_simple
5357 | variable_type_simple rank_specifiers
5360 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5362 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5367 * The following is from Rhys' grammar:
5368 * > Types in local variable declarations must be recognized as
5369 * > expressions to prevent reduce/reduce errors in the grammar.
5370 * > The expressions are converted into types during semantic analysis.
5372 variable_type_simple
5373 : primary_expression_or_type opt_nullable
5375 // Ok, the above "primary_expression" is there to get rid of
5376 // both reduce/reduce and shift/reduces in the grammar, it should
5377 // really just be "type_name". If you use type_name, a reduce/reduce
5378 // creeps up. If you use namespace_or_type_name (which is all we need
5379 // really) two shift/reduces appear.
5382 // So the super-trick is that primary_expression
5383 // can only be either a SimpleName or a MemberAccess.
5384 // The MemberAccess case arises when you have a fully qualified type-name like :
5386 // SimpleName is when you have
5389 Expression expr = (Expression) $1;
5391 SimpleName sn = expr as SimpleName;
5392 if (sn != null && sn.Name == "var")
5393 $$ = new VarExpr (sn.Location);
5396 } else if (expr is ATypeNameExpression) {
5397 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5399 Error_ExpectingTypeName (expr);
5403 | primary_expression_or_type pointer_stars
5405 ATypeNameExpression expr = $1 as ATypeNameExpression;
5408 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5410 Error_ExpectingTypeName ((Expression)$1);
5414 | builtin_types opt_nullable
5419 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5421 | builtin_types pointer_stars
5423 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5425 | VOID pointer_stars
5427 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5431 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5432 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5438 | pointer_star pointer_stars
5440 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5448 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5452 identifier_inside_body
5456 $$ = Error_AwaitAsIdentifier ($1);
5460 block_variable_declaration
5461 : variable_type identifier_inside_body
5463 var lt = (LocatedToken) $2;
5464 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5465 current_block.AddLocalName (li);
5466 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5468 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5470 $$ = current_variable;
5471 current_variable = null;
5473 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5475 lbag.AddLocation ($$, GetLocation ($6));
5477 | CONST variable_type identifier_inside_body
5479 var lt = (LocatedToken) $3;
5480 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5481 current_block.AddLocalName (li);
5482 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5484 const_variable_initializer opt_const_declarators SEMICOLON
5486 $$ = current_variable;
5487 current_variable = null;
5488 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5492 opt_local_variable_initializer
5494 | ASSIGN block_variable_initializer
5496 current_variable.Initializer = (Expression) $2;
5497 PushLocation (GetLocation ($1));
5498 $$ = current_variable;
5502 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5503 report.Error (650, lexer.Location,
5504 "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");
5506 Error_SyntaxError (yyToken);
5511 opt_variable_declarators
5513 | variable_declarators
5516 opt_using_or_fixed_variable_declarators
5518 | variable_declarators
5520 foreach (var d in current_variable.Declarators) {
5521 if (d.Initializer == null)
5522 Error_MissingInitializer (d.Variable.Location);
5527 variable_declarators
5528 : variable_declarator
5529 | variable_declarators variable_declarator
5533 : COMMA identifier_inside_body
5535 var lt = (LocatedToken) $2;
5536 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5537 var d = new BlockVariableDeclarator (li, null);
5538 current_variable.AddDeclarator (d);
5539 current_block.AddLocalName (li);
5540 lbag.AddLocation (d, GetLocation ($1));
5542 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5544 var lt = (LocatedToken) $2;
5545 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5546 var d = new BlockVariableDeclarator (li, (Expression) $4);
5547 current_variable.AddDeclarator (d);
5548 current_block.AddLocalName (li);
5549 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5553 const_variable_initializer
5556 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5558 | ASSIGN constant_initializer_expr
5560 current_variable.Initializer = (Expression) $2;
5564 opt_const_declarators
5571 | const_declarators const_declarator
5575 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5577 var lt = (LocatedToken) $2;
5578 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5579 var d = new BlockVariableDeclarator (li, (Expression) $4);
5580 current_variable.AddDeclarator (d);
5581 current_block.AddLocalName (li);
5582 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5586 block_variable_initializer
5587 : variable_initializer
5588 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5590 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5591 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5593 | STACKALLOC simple_type
5595 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5596 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5600 expression_statement
5601 : statement_expression SEMICOLON
5604 lbag.AddStatement ($$, GetLocation ($2));
5606 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5607 | statement_expression CLOSE_BRACE
5610 report.Error (1002, GetLocation ($2), "; expected");
5611 lexer.putback ('}');
5615 interactive_expression_statement
5616 : interactive_statement_expression SEMICOLON { $$ = $1; }
5617 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5621 // We have to do the wrapping here and not in the case above,
5622 // because statement_expression is used for example in for_statement
5624 statement_expression
5627 ExpressionStatement s = $1 as ExpressionStatement;
5629 var expr = $1 as Expression;
5630 $$ = new StatementErrorExpression (expr);
5632 $$ = new StatementExpression (s);
5637 interactive_statement_expression
5640 Expression expr = (Expression) $1;
5641 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5645 Error_SyntaxError (yyToken);
5646 $$ = new EmptyStatement (GetLocation ($1));
5656 : IF open_parens_any boolean_expression CLOSE_PARENS
5659 if ($5 is EmptyStatement)
5660 Warning_EmptyStatement (GetLocation ($5));
5662 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5663 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5665 | IF open_parens_any boolean_expression CLOSE_PARENS
5666 embedded_statement ELSE embedded_statement
5668 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5669 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5671 if ($5 is EmptyStatement)
5672 Warning_EmptyStatement (GetLocation ($5));
5673 if ($7 is EmptyStatement)
5674 Warning_EmptyStatement (GetLocation ($7));
5676 | IF open_parens_any boolean_expression error
5678 Error_SyntaxError (yyToken);
5680 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5681 lbag.AddStatement ($$, GetLocation ($2));
5686 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5688 start_block (GetLocation ($5));
5690 opt_switch_sections CLOSE_BRACE
5692 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5693 end_block (GetLocation ($8));
5694 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5696 | SWITCH open_parens_any expression error
5698 Error_SyntaxError (yyToken);
5700 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5701 lbag.AddStatement ($$, GetLocation ($2));
5708 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5715 | switch_sections switch_section
5718 Error_SyntaxError (yyToken);
5723 : switch_labels statement_list
5729 var label = (SwitchLabel) $1;
5730 label.SectionStart = true;
5731 current_block.AddStatement (label);
5733 | switch_labels switch_label
5735 current_block.AddStatement ((Statement) $2);
5740 : CASE constant_expression COLON
5742 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5743 lbag.AddLocation ($$, GetLocation ($3));
5745 | CASE constant_expression error
5747 Error_SyntaxError (yyToken);
5748 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5752 $$ = new SwitchLabel (null, GetLocation ($1));
5764 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5766 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5767 Warning_EmptyStatement (GetLocation ($5));
5769 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5770 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5772 | WHILE open_parens_any boolean_expression error
5774 Error_SyntaxError (yyToken);
5776 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5777 lbag.AddStatement ($$, GetLocation ($2));
5782 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5784 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5785 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5787 | DO embedded_statement error
5789 Error_SyntaxError (yyToken);
5790 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5792 | DO embedded_statement WHILE open_parens_any boolean_expression error
5794 Error_SyntaxError (yyToken);
5796 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5797 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5802 : FOR open_parens_any
5804 start_block (GetLocation ($2));
5805 current_block.IsCompilerGenerated = true;
5806 For f = new For (GetLocation ($1));
5807 current_block.AddStatement (f);
5816 // Has to use be extra rule to recover started block
5818 : opt_for_initializer SEMICOLON
5820 ((For) $0).Initializer = (Statement) $1;
5822 // Pass the "For" object to the iterator_part4
5823 oob_stack.Push ($0);
5825 for_condition_and_iterator_part
5828 var locations = (Tuple<Location,Location>) $4;
5830 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5831 Warning_EmptyStatement (GetLocation ($5));
5834 f.Statement = (Statement) $5;
5835 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5837 $$ = end_block (GetLocation ($2));
5841 Error_SyntaxError (yyToken);
5842 $$ = end_block (current_block.StartLocation);
5846 for_condition_and_iterator_part
5847 : opt_for_condition SEMICOLON
5849 For f = (For) oob_stack.Peek ();
5850 f.Condition = (BooleanExpression) $1;
5853 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5856 // Handle errors in the case of opt_for_condition being followed by
5857 // a close parenthesis
5858 | opt_for_condition close_parens_close_brace {
5859 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5860 For f = (For) oob_stack.Peek ();
5861 f.Condition = (BooleanExpression) $1;
5862 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5867 : opt_for_iterator CLOSE_PARENS {
5868 For f = (For) oob_stack.Peek ();
5869 f.Iterator = (Statement) $1;
5870 $$ = GetLocation ($2);
5872 | opt_for_iterator CLOSE_BRACE {
5873 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5874 For f = (For) oob_stack.Peek ();
5875 f.Iterator = (Statement) $1;
5876 $$ = GetLocation ($2);
5880 close_parens_close_brace
5882 | CLOSE_BRACE { lexer.putback ('}'); }
5886 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5891 : variable_type identifier_inside_body
5893 var lt = (LocatedToken) $2;
5894 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5895 current_block.AddLocalName (li);
5896 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5898 opt_local_variable_initializer opt_variable_declarators
5900 $$ = current_variable;
5902 lbag.AddLocation (current_variable, PopLocation ());
5904 current_variable = null;
5906 | statement_expression_list
5910 : /* empty */ { $$ = null; }
5911 | boolean_expression
5915 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5920 : statement_expression_list
5923 statement_expression_list
5924 : statement_expression
5925 | statement_expression_list COMMA statement_expression
5927 var sl = $1 as StatementList;
5929 sl = new StatementList ((Statement) $1, (Statement) $3);
5930 lbag.AddStatement (sl, GetLocation ($2));
5932 sl.Add ((Statement) $3);
5933 lbag.AppendTo (sl, GetLocation ($2));
5941 : FOREACH open_parens_any type error
5943 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5945 start_block (GetLocation ($2));
5946 current_block.IsCompilerGenerated = true;
5948 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5949 current_block.AddStatement (f);
5951 lbag.AddStatement (f, GetLocation ($2));
5952 $$ = end_block (GetLocation ($4));
5954 | FOREACH open_parens_any type identifier_inside_body error
5956 Error_SyntaxError (yyToken);
5958 start_block (GetLocation ($2));
5959 current_block.IsCompilerGenerated = true;
5961 var lt = (LocatedToken) $4;
5962 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5963 current_block.AddLocalName (li);
5965 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5966 current_block.AddStatement (f);
5968 lbag.AddStatement (f, GetLocation ($2));
5969 $$ = end_block (GetLocation ($5));
5971 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5973 start_block (GetLocation ($2));
5974 current_block.IsCompilerGenerated = true;
5976 var lt = (LocatedToken) $4;
5977 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5978 current_block.AddLocalName (li);
5983 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5984 Warning_EmptyStatement (GetLocation ($9));
5986 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5987 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5988 end_block (GetLocation ($7));
5996 | continue_statement
6006 $$ = new Break (GetLocation ($1));
6007 lbag.AddStatement ($$, GetLocation ($2));
6012 : CONTINUE SEMICOLON
6014 $$ = new Continue (GetLocation ($1));
6015 lbag.AddStatement ($$, GetLocation ($2));
6019 Error_SyntaxError (yyToken);
6020 $$ = new Continue (GetLocation ($1));
6025 : GOTO identifier_inside_body SEMICOLON
6027 var lt = (LocatedToken) $2;
6028 $$ = new Goto (lt.Value, GetLocation ($1));
6029 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6031 | GOTO CASE constant_expression SEMICOLON
6033 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6034 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6036 | GOTO DEFAULT SEMICOLON
6038 $$ = new GotoDefault (GetLocation ($1));
6039 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6044 : RETURN opt_expression SEMICOLON
6046 $$ = new Return ((Expression) $2, GetLocation ($1));
6047 lbag.AddStatement ($$, GetLocation ($3));
6049 | RETURN expression error
6051 Error_SyntaxError (yyToken);
6052 $$ = new Return ((Expression) $2, GetLocation ($1));
6056 Error_SyntaxError (yyToken);
6057 $$ = new Return (null, GetLocation ($1));
6062 : THROW opt_expression SEMICOLON
6064 $$ = new Throw ((Expression) $2, GetLocation ($1));
6065 lbag.AddStatement ($$, GetLocation ($3));
6067 | THROW expression error
6069 Error_SyntaxError (yyToken);
6070 $$ = new Throw ((Expression) $2, GetLocation ($1));
6074 Error_SyntaxError (yyToken);
6075 $$ = new Throw (null, GetLocation ($1));
6080 : identifier_inside_body RETURN opt_expression SEMICOLON
6082 var lt = (LocatedToken) $1;
6083 string s = lt.Value;
6085 report.Error (1003, lt.Location, "; expected");
6086 } else if ($3 == null) {
6087 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6088 } else if (lang_version == LanguageVersion.ISO_1){
6089 FeatureIsNotAvailable (lt.Location, "iterators");
6092 current_block.Explicit.RegisterIteratorYield ();
6093 $$ = new Yield ((Expression) $3, lt.Location);
6094 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6096 | identifier_inside_body RETURN expression error
6098 Error_SyntaxError (yyToken);
6100 var lt = (LocatedToken) $1;
6101 string s = lt.Value;
6103 report.Error (1003, lt.Location, "; expected");
6104 } else if ($3 == null) {
6105 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6106 } else if (lang_version == LanguageVersion.ISO_1){
6107 FeatureIsNotAvailable (lt.Location, "iterators");
6110 current_block.Explicit.RegisterIteratorYield ();
6111 $$ = new Yield ((Expression) $3, lt.Location);
6112 lbag.AddStatement ($$, GetLocation ($2));
6114 | identifier_inside_body BREAK SEMICOLON
6116 var lt = (LocatedToken) $1;
6117 string s = lt.Value;
6119 report.Error (1003, lt.Location, "; expected");
6120 } else if (lang_version == LanguageVersion.ISO_1){
6121 FeatureIsNotAvailable (lt.Location, "iterators");
6124 current_block.ParametersBlock.TopBlock.IsIterator = true;
6125 $$ = new YieldBreak (lt.Location);
6126 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6136 : TRY block catch_clauses
6138 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6140 | TRY block FINALLY block
6142 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6143 lbag.AddStatement ($$, GetLocation ($3));
6145 | TRY block catch_clauses FINALLY block
6147 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6148 lbag.AddStatement ($$, GetLocation ($4));
6152 Error_SyntaxError (1524, yyToken);
6153 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6160 var l = new List<Catch> (2);
6165 | catch_clauses catch_clause
6167 var l = (List<Catch>) $1;
6169 Catch c = (Catch) $2;
6170 var prev_catch = l [l.Count - 1];
6171 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6172 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6182 | identifier_inside_body
6186 : CATCH opt_catch_filter block
6188 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6189 c.Filter = (CatchFilterExpression) $2;
6192 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6194 start_block (GetLocation ($2));
6195 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6196 c.TypeExpression = (FullNamedExpression) $3;
6199 var lt = (LocatedToken) $4;
6200 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6201 current_block.AddLocalName (c.Variable);
6204 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6207 opt_catch_filter block_prepared
6209 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6212 | CATCH open_parens_any error
6214 if (yyToken == Token.CLOSE_PARENS) {
6215 report.Error (1015, lexer.Location,
6216 "A type that derives from `System.Exception', `object', or `string' expected");
6218 Error_SyntaxError (yyToken);
6221 $$ = new Catch (null, GetLocation ($1));
6223 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6225 Error_SyntaxError (yyToken);
6227 // Required otherwise missing block could not be detected because
6228 // start_block is run early
6229 var c = new Catch (null, GetLocation ($1));
6230 c.TypeExpression = (FullNamedExpression) $3;
6233 var lt = (LocatedToken) $4;
6234 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6237 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6245 | IF open_parens_any expression CLOSE_PARENS
6247 if (lang_version <= LanguageVersion.V_5)
6248 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6250 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6251 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6258 $$ = new Checked ((Block) $2, GetLocation ($1));
6265 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6272 if (!settings.Unsafe)
6273 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6275 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6280 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6282 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6283 Warning_EmptyStatement (GetLocation ($5));
6285 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6286 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6288 | LOCK open_parens_any expression error
6290 Error_SyntaxError (yyToken);
6292 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6293 lbag.AddStatement ($$, GetLocation ($2));
6298 : FIXED open_parens_any variable_type identifier_inside_body
6300 start_block (GetLocation ($2));
6302 current_block.IsCompilerGenerated = true;
6303 var lt = (LocatedToken) $4;
6304 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6305 current_block.AddLocalName (li);
6306 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6308 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6310 $$ = current_variable;
6311 current_variable = null;
6315 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6316 Warning_EmptyStatement (GetLocation ($10));
6318 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6319 current_block.AddStatement (f);
6320 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6321 $$ = end_block (GetLocation ($8));
6326 : USING open_parens_any variable_type identifier_inside_body
6328 start_block (GetLocation ($2));
6330 current_block.IsCompilerGenerated = true;
6331 var lt = (LocatedToken) $4;
6332 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6333 current_block.AddLocalName (li);
6334 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6336 using_initialization CLOSE_PARENS
6338 $$ = current_variable;
6339 current_variable = null;
6343 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6344 Warning_EmptyStatement (GetLocation ($9));
6346 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6347 current_block.AddStatement (u);
6348 $$ = end_block (GetLocation ($7));
6350 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6352 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6353 Warning_EmptyStatement (GetLocation ($5));
6355 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6356 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6358 | USING open_parens_any expression error
6360 Error_SyntaxError (yyToken);
6362 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6363 lbag.AddStatement ($$, GetLocation ($2));
6367 using_initialization
6368 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6371 // It has to be here for the parent to safely restore artificial block
6372 Error_SyntaxError (yyToken);
6376 using_or_fixed_variable_initializer
6379 Error_MissingInitializer (lexer.Location);
6381 | ASSIGN variable_initializer
6383 current_variable.Initializer = (Expression) $2;
6384 $$ = current_variable;
6392 : first_from_clause query_body
6394 lexer.query_parsing = false;
6396 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6398 from.Tail.Next = (Linq.AQueryClause)$2;
6401 current_block.SetEndLocation (lexer.Location);
6402 current_block = current_block.Parent;
6404 | nested_from_clause query_body
6406 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6408 from.Tail.Next = (Linq.AQueryClause)$2;
6411 current_block.SetEndLocation (lexer.Location);
6412 current_block = current_block.Parent;
6415 // Bubble up COMPLETE_COMPLETION productions
6416 | first_from_clause COMPLETE_COMPLETION {
6417 lexer.query_parsing = false;
6420 current_block.SetEndLocation (lexer.Location);
6421 current_block = current_block.Parent;
6423 | nested_from_clause COMPLETE_COMPLETION {
6425 current_block.SetEndLocation (lexer.Location);
6426 current_block = current_block.Parent;
6431 : FROM_FIRST identifier_inside_body IN expression
6433 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6435 var lt = (LocatedToken) $2;
6436 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6437 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6438 lbag.AddLocation (clause, GetLocation ($3));
6439 $$ = new Linq.QueryExpression (clause);
6441 | FROM_FIRST type identifier_inside_body IN expression
6443 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6445 var lt = (LocatedToken) $3;
6446 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6447 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6448 IdentifierType = (FullNamedExpression)$2
6450 lbag.AddLocation (clause, GetLocation ($4));
6451 $$ = new Linq.QueryExpression (clause);
6456 : FROM identifier_inside_body IN expression
6458 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6460 var lt = (LocatedToken) $2;
6461 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6462 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6463 lbag.AddLocation (clause, GetLocation ($3));
6464 $$ = new Linq.QueryExpression (clause);
6466 | FROM type identifier_inside_body IN expression
6468 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6470 var lt = (LocatedToken) $3;
6471 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6472 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6473 IdentifierType = (FullNamedExpression)$2
6475 lbag.AddLocation (clause, GetLocation ($4));
6476 $$ = new Linq.QueryExpression (clause);
6481 : FROM identifier_inside_body IN
6483 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6487 var lt = (LocatedToken) $2;
6488 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6489 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6491 current_block.SetEndLocation (lexer.Location);
6492 current_block = current_block.Parent;
6494 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6495 lbag.AddLocation ($$, GetLocation ($3));
6497 | FROM type identifier_inside_body IN
6499 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6503 var lt = (LocatedToken) $3;
6504 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6506 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6507 IdentifierType = (FullNamedExpression)$2
6510 current_block.SetEndLocation (lexer.Location);
6511 current_block = current_block.Parent;
6513 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6515 lbag.AddLocation ($$, GetLocation ($4));
6520 : query_body_clauses select_or_group_clause opt_query_continuation
6522 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6525 head.Next = (Linq.AQueryClause)$3;
6528 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6529 clause.Tail.Next = head;
6535 | select_or_group_clause opt_query_continuation
6537 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6540 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6541 clause.Tail.Next = head;
6547 | query_body_clauses COMPLETE_COMPLETION
6548 | query_body_clauses error
6550 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6555 Error_SyntaxError (yyToken);
6560 select_or_group_clause
6563 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6567 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6569 current_block.SetEndLocation (lexer.Location);
6570 current_block = current_block.Parent;
6574 if (linq_clause_blocks == null)
6575 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6577 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6578 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6582 current_block.SetEndLocation (lexer.Location);
6583 current_block = current_block.Parent;
6585 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6589 var obj = (object[]) $5;
6591 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6592 lbag.AddLocation ($$, (Location) obj[1]);
6594 current_block.SetEndLocation (lexer.Location);
6595 current_block = current_block.Parent;
6600 : BY expression_or_error
6602 $$ = new object[] { $2, GetLocation ($1) };
6606 Error_SyntaxError (yyToken);
6607 $$ = new object[2] { null, Location.Null };
6613 | query_body_clauses query_body_clause
6615 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6629 : LET identifier_inside_body ASSIGN
6631 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6635 var lt = (LocatedToken) $2;
6636 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6637 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6638 lbag.AddLocation ($$, GetLocation ($3));
6640 current_block.SetEndLocation (lexer.Location);
6641 current_block = current_block.Parent;
6643 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6650 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6654 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6656 current_block.SetEndLocation (lexer.Location);
6657 current_block = current_block.Parent;
6662 : JOIN identifier_inside_body IN
6664 if (linq_clause_blocks == null)
6665 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6667 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6668 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6670 expression_or_error ON
6672 current_block.SetEndLocation (lexer.Location);
6673 current_block = current_block.Parent;
6675 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6676 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6678 expression_or_error EQUALS
6680 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6681 current_block.SetEndLocation (lexer.Location);
6682 current_block = current_block.Parent;
6684 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6686 expression_or_error opt_join_into
6688 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6689 current_block.SetEndLocation (lexer.Location);
6691 var outer_selector = linq_clause_blocks.Pop ();
6692 var block = linq_clause_blocks.Pop ();
6694 var lt = (LocatedToken) $2;
6695 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6696 Linq.RangeVariable into;
6700 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6701 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6704 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6706 var parent = block.Parent;
6707 while (parent is Linq.QueryBlock) {
6708 parent = parent.Parent;
6710 current_block.Parent = parent;
6712 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6714 lt = (LocatedToken) $12;
6715 into = new Linq.RangeVariable (lt.Value, lt.Location);
6717 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6718 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6721 current_block = block.Parent;
6722 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6724 | JOIN type identifier_inside_body IN
6726 if (linq_clause_blocks == null)
6727 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6729 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6730 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6732 expression_or_error ON
6734 current_block.SetEndLocation (lexer.Location);
6735 current_block = current_block.Parent;
6737 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6738 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6740 expression_or_error EQUALS
6742 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6743 current_block.SetEndLocation (lexer.Location);
6744 current_block = current_block.Parent;
6746 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6748 expression_or_error opt_join_into
6750 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6751 current_block.SetEndLocation (lexer.Location);
6753 var outer_selector = linq_clause_blocks.Pop ();
6754 var block = linq_clause_blocks.Pop ();
6756 var lt = (LocatedToken) $3;
6757 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6758 Linq.RangeVariable into;
6762 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6763 IdentifierType = (FullNamedExpression)$2
6765 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6768 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6770 var parent = block.Parent;
6771 while (parent is Linq.QueryBlock) {
6772 parent = parent.Parent;
6774 current_block.Parent = parent;
6776 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6778 lt = (LocatedToken) $13;
6779 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6781 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6782 IdentifierType = (FullNamedExpression)$2
6786 current_block = block.Parent;
6787 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6793 | INTO identifier_inside_body
6802 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6806 current_block.SetEndLocation (lexer.Location);
6807 current_block = current_block.Parent;
6817 current_block.SetEndLocation (lexer.Location);
6818 current_block = current_block.Parent;
6820 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6824 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6831 | orderings_then_by COMMA
6833 current_block.SetEndLocation (lexer.Location);
6834 current_block = current_block.Parent;
6836 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6840 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6848 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6850 | expression ASCENDING
6852 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6853 lbag.AddLocation ($$, GetLocation ($2));
6855 | expression DESCENDING
6857 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6858 lbag.AddLocation ($$, GetLocation ($2));
6865 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6867 | expression ASCENDING
6869 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6870 lbag.AddLocation ($$, GetLocation ($2));
6872 | expression DESCENDING
6874 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6875 lbag.AddLocation ($$, GetLocation ($2));
6880 opt_query_continuation
6882 | INTO identifier_inside_body
6884 // query continuation block is not linked with query block but with block
6885 // before. This means each query can use same range variable names for
6886 // different identifiers.
6888 current_block.SetEndLocation (GetLocation ($1));
6889 current_block = current_block.Parent;
6891 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6893 if (linq_clause_blocks == null)
6894 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6896 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6900 var current_block = linq_clause_blocks.Pop ();
6901 var lt = (LocatedToken) $2;
6902 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6903 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6904 next = (Linq.AQueryClause)$4
6910 // Support for using the compiler as an interactive parser
6912 // The INTERACTIVE_PARSER token is first sent to parse our
6913 // productions; If the result is a Statement, the parsing
6914 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6915 // to setup the blocks in advance.
6917 // This setup is here so that in the future we can add
6918 // support for other constructs (type parsing, namespaces, etc)
6919 // that do not require a block to be setup in advance
6923 : EVAL_STATEMENT_PARSER EOF
6924 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6925 | EVAL_STATEMENT_PARSER
6927 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6929 // (ref object retval)
6930 Parameter [] mpar = new Parameter [1];
6931 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6933 ParametersCompiled pars = new ParametersCompiled (mpar);
6934 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6935 if (settings.Unsafe)
6936 mods |= Modifiers.UNSAFE;
6938 current_local_parameters = pars;
6939 var method = new InteractiveMethod (
6941 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6945 current_type.AddMember (method);
6946 oob_stack.Push (method);
6948 interactive_async = false;
6950 ++lexer.parsing_block;
6951 start_block (lexer.Location);
6953 interactive_statement_list opt_COMPLETE_COMPLETION
6955 --lexer.parsing_block;
6956 var method = (InteractiveMethod) oob_stack.Pop ();
6957 method.Block = (ToplevelBlock) end_block(lexer.Location);
6959 if (interactive_async == true) {
6960 method.ChangeToAsync ();
6963 InteractiveResult = (Class) pop_current_class ();
6964 current_local_parameters = null;
6966 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6969 interactive_compilation_unit
6970 : opt_extern_alias_directives opt_using_directives
6971 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6974 opt_COMPLETE_COMPLETION
6976 | COMPLETE_COMPLETION
6979 close_brace_or_complete_completion
6981 | COMPLETE_COMPLETION
6985 // XML documentation code references micro parser
6987 documentation_parsing
6990 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6995 : doc_type_declaration_name opt_doc_method_sig
6997 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6999 | builtin_types opt_doc_method_sig
7001 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7002 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7005 | VOID opt_doc_method_sig
7007 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7008 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7011 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7013 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7014 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7015 var lt = (LocatedToken) $3;
7016 $$ = new MemberName (lt.Value);
7018 | doc_type_declaration_name DOT THIS
7020 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7022 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7024 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7026 opt_doc_parameters CLOSE_BRACKET
7028 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7029 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7031 | EXPLICIT OPERATOR type opt_doc_method_sig
7033 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7034 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7035 module.DocumentationBuilder.ParsedParameters = p;
7036 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7039 | IMPLICIT OPERATOR type opt_doc_method_sig
7041 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7042 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7043 module.DocumentationBuilder.ParsedParameters = p;
7044 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7047 | OPERATOR overloadable_operator opt_doc_method_sig
7049 var p = (List<DocumentationParameter>)$3;
7050 module.DocumentationBuilder.ParsedParameters = p;
7051 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7056 doc_type_declaration_name
7057 : type_declaration_name
7058 | doc_type_declaration_name DOT type_declaration_name
7060 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7068 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7070 opt_doc_parameters CLOSE_PARENS
7079 $$ = new List<DocumentationParameter> (0);
7087 var parameters = new List<DocumentationParameter> ();
7088 parameters.Add ((DocumentationParameter) $1);
7091 | doc_parameters COMMA doc_parameter
7093 var parameters = $1 as List<DocumentationParameter>;
7094 parameters.Add ((DocumentationParameter) $3);
7100 : opt_parameter_modifier parameter_type
7103 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7105 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7112 // A class used to hold info about an operator declarator
7114 class OperatorDeclaration {
7115 public readonly Operator.OpType optype;
7116 public readonly FullNamedExpression ret_type;
7117 public readonly Location location;
7119 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7122 this.ret_type = ret_type;
7123 this.location = location;
7127 void Error_ExpectingTypeName (Expression expr)
7129 if (expr is Invocation){
7130 report.Error (1002, expr.Location, "Expecting `;'");
7132 expr.Error_InvalidExpressionStatement (report);
7136 void Error_ParameterModifierNotValid (string modifier, Location loc)
7138 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7142 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7144 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7145 Parameter.GetModifierSignature (mod));
7148 void Error_TypeExpected (Location loc)
7150 report.Error (1031, loc, "Type expected");
7153 void Error_UnsafeCodeNotAllowed (Location loc)
7155 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7158 void Warning_EmptyStatement (Location loc)
7160 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7163 void Error_NamedArgumentExpected (NamedArgument a)
7165 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7168 void Error_MissingInitializer (Location loc)
7170 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7173 object Error_AwaitAsIdentifier (object token)
7176 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7177 return new LocatedToken ("await", GetLocation (token));
7183 void push_current_container (TypeDefinition tc, object partial_token)
7185 if (module.Evaluator != null){
7186 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7190 undo.AddTypeContainer (current_container, tc);
7193 if (partial_token != null)
7194 current_container.AddPartial (tc);
7196 current_container.AddTypeContainer (tc);
7198 ++lexer.parsing_declaration;
7199 current_container = tc;
7203 TypeContainer pop_current_class ()
7205 var retval = current_container;
7207 current_container = current_container.Parent;
7208 current_type = current_type.Parent as TypeDefinition;
7213 [System.Diagnostics.Conditional ("FULL_AST")]
7214 void StoreModifierLocation (object token, Location loc)
7219 if (mod_locations == null)
7220 mod_locations = new List<Tuple<Modifiers, Location>> ();
7222 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7225 [System.Diagnostics.Conditional ("FULL_AST")]
7226 void PushLocation (Location loc)
7228 if (location_stack == null)
7229 location_stack = new Stack<Location> ();
7231 location_stack.Push (loc);
7234 Location PopLocation ()
7236 if (location_stack == null)
7237 return Location.Null;
7239 return location_stack.Pop ();
7242 string CheckAttributeTarget (int token, string a, Location l)
7245 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7249 if (!Tokenizer.IsValidIdentifier (a)) {
7250 Error_SyntaxError (token);
7252 report.Warning (658, 1, l,
7253 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7256 return string.Empty;
7259 static bool IsUnaryOperator (Operator.OpType op)
7263 case Operator.OpType.LogicalNot:
7264 case Operator.OpType.OnesComplement:
7265 case Operator.OpType.Increment:
7266 case Operator.OpType.Decrement:
7267 case Operator.OpType.True:
7268 case Operator.OpType.False:
7269 case Operator.OpType.UnaryPlus:
7270 case Operator.OpType.UnaryNegation:
7276 void syntax_error (Location l, string msg)
7278 report.Error (1003, l, "Syntax error, " + msg);
7283 public Tokenizer Lexer {
7289 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7290 : this (reader, file, file.Compiler.Report, session)
7294 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7297 current_container = current_namespace = file;
7299 this.module = file.Module;
7300 this.compiler = file.Compiler;
7301 this.settings = compiler.Settings;
7302 this.report = report;
7304 lang_version = settings.Version;
7305 yacc_verbose_flag = settings.VerboseParserFlag;
7306 doc_support = settings.DocumentationFile != null;
7307 lexer = new Tokenizer (reader, file, session, report);
7308 oob_stack = new Stack<object> ();
7309 lbag = session.LocationsBag;
7310 use_global_stacks = session.UseJayGlobalArrays;
7311 parameters_bucket = session.ParametersStack;
7314 public void parse ()
7316 eof_token = Token.EOF;
7319 if (yacc_verbose_flag > 1)
7320 yyparse (lexer, new yydebug.yyDebugSimple ());
7324 Tokenizer tokenizer = lexer as Tokenizer;
7325 tokenizer.cleanup ();
7326 } catch (Exception e){
7327 if (e is yyParser.yyUnexpectedEof) {
7328 Error_SyntaxError (yyToken);
7329 UnexpectedEOF = true;
7333 if (e is yyParser.yyException) {
7334 if (report.Errors == 0)
7335 report.Error (-25, lexer.Location, "Parsing error");
7337 // Used by compiler-tester to test internal errors
7338 if (yacc_verbose_flag > 0 || e is FatalException)
7341 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7346 void CheckToken (int error, int yyToken, string msg, Location loc)
7348 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7349 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7351 report.Error (error, loc, msg);
7354 string ConsumeStoredComment ()
7356 string s = tmpComment;
7358 Lexer.doc_state = XmlCommentState.Allowed;
7362 void FeatureIsNotAvailable (Location loc, string feature)
7364 report.FeatureIsNotAvailable (compiler, loc, feature);
7367 Location GetLocation (object obj)
7369 var lt = obj as LocatedToken;
7373 var mn = obj as MemberName;
7377 var expr = obj as Expression;
7379 return expr.Location;
7381 return lexer.Location;
7384 void start_block (Location loc)
7386 if (current_block == null) {
7387 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7388 parsing_anonymous_method = false;
7389 } else if (parsing_anonymous_method) {
7390 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7391 parsing_anonymous_method = false;
7393 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7398 end_block (Location loc)
7400 Block retval = current_block.Explicit;
7401 retval.SetEndLocation (loc);
7402 current_block = retval.Parent;
7406 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7408 oob_stack.Push (current_anonymous_method);
7409 oob_stack.Push (current_local_parameters);
7410 oob_stack.Push (current_variable);
7411 oob_stack.Push (async_block);
7413 current_local_parameters = parameters;
7415 if (lang_version <= LanguageVersion.ISO_2)
7416 FeatureIsNotAvailable (loc, "lambda expressions");
7418 current_anonymous_method = new LambdaExpression (loc);
7420 if (lang_version == LanguageVersion.ISO_1)
7421 FeatureIsNotAvailable (loc, "anonymous methods");
7423 current_anonymous_method = new AnonymousMethodExpression (loc);
7426 async_block = isAsync;
7427 // Force the next block to be created as a ToplevelBlock
7428 parsing_anonymous_method = true;
7432 * Completes the anonymous method processing, if lambda_expr is null, this
7433 * means that we have a Statement instead of an Expression embedded
7435 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7437 AnonymousMethodExpression retval;
7440 anon_block.IsAsync = true;
7442 current_anonymous_method.Block = anon_block;
7443 retval = current_anonymous_method;
7445 async_block = (bool) oob_stack.Pop ();
7446 current_variable = (BlockVariable) oob_stack.Pop ();
7447 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7448 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7453 void Error_SyntaxError (int token)
7455 Error_SyntaxError (0, token);
7458 void Error_SyntaxError (int error_code, int token)
7460 Error_SyntaxError (error_code, token, "Unexpected symbol");
7463 void Error_SyntaxError (int error_code, int token, string msg)
7465 Lexer.CompleteOnEOF = false;
7467 // An error message has been reported by tokenizer
7468 if (token == Token.ERROR)
7471 // Avoid duplicit error message after unterminated string literals
7472 if (token == Token.LITERAL && lexer.Location.Column == 0)
7475 string symbol = GetSymbolName (token);
7476 string expecting = GetExpecting ();
7477 var loc = lexer.Location - symbol.Length;
7479 if (error_code == 0) {
7480 if (expecting == "`identifier'") {
7481 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7482 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7487 expecting = "identifier";
7488 } else if (expecting == "`)'") {
7495 if (string.IsNullOrEmpty (expecting))
7496 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7498 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7501 string GetExpecting ()
7503 int [] tokens = yyExpectingTokens (yyExpectingState);
7504 var names = new List<string> (tokens.Length);
7505 bool has_type = false;
7506 bool has_identifier = false;
7507 for (int i = 0; i < tokens.Length; i++){
7508 int token = tokens [i];
7509 has_identifier |= token == Token.IDENTIFIER;
7511 string name = GetTokenName (token);
7512 if (name == "<internal>")
7515 has_type |= name == "type";
7516 if (names.Contains (name))
7523 // Too many tokens to enumerate
7525 if (names.Count > 8)
7528 if (has_type && has_identifier)
7529 names.Remove ("identifier");
7531 if (names.Count == 1)
7532 return "`" + GetTokenName (tokens [0]) + "'";
7534 StringBuilder sb = new StringBuilder ();
7536 int count = names.Count;
7537 for (int i = 0; i < count; i++){
7538 bool last = i + 1 == count;
7542 sb.Append (names [i]);
7543 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7545 return sb.ToString ();
7549 string GetSymbolName (int token)
7553 return ((Constant)lexer.Value).GetValue ().ToString ();
7554 case Token.IDENTIFIER:
7555 return ((LocatedToken)lexer.Value).Value;
7597 case Token.BITWISE_AND:
7599 case Token.BITWISE_OR:
7613 case Token.OP_SHIFT_LEFT:
7615 case Token.OP_SHIFT_RIGHT:
7635 case Token.OP_COALESCING:
7637 case Token.OP_MULT_ASSIGN:
7639 case Token.OP_DIV_ASSIGN:
7641 case Token.OP_MOD_ASSIGN:
7643 case Token.OP_ADD_ASSIGN:
7645 case Token.OP_SUB_ASSIGN:
7647 case Token.OP_SHIFT_LEFT_ASSIGN:
7649 case Token.OP_SHIFT_RIGHT_ASSIGN:
7651 case Token.OP_AND_ASSIGN:
7653 case Token.OP_XOR_ASSIGN:
7655 case Token.OP_OR_ASSIGN:
7659 return GetTokenName (token);
7662 static string GetTokenName (int token)
7665 case Token.ABSTRACT:
7687 case Token.CONTINUE:
7691 case Token.DELEGATE:
7701 case Token.EXPLICIT:
7704 case Token.EXTERN_ALIAS:
7720 case Token.IMPLICIT:
7724 case Token.INTERFACE:
7726 case Token.INTERNAL:
7732 case Token.NAMESPACE:
7738 case Token.OPERATOR:
7742 case Token.OVERRIDE:
7748 case Token.PROTECTED:
7752 case Token.READONLY:
7764 case Token.STACKALLOC:
7765 return "stackalloc";
7782 case Token.UNCHECKED:
7790 case Token.VOLATILE:
7798 case Token.REFVALUE:
7799 return "__refvalue";
7809 case Token.FROM_FIRST:
7827 case Token.ASCENDING:
7829 case Token.DESCENDING:
7830 return "descending";
7837 case Token.OPEN_BRACE:
7839 case Token.CLOSE_BRACE:
7841 case Token.OPEN_BRACKET:
7842 case Token.OPEN_BRACKET_EXPR:
7844 case Token.CLOSE_BRACKET:
7846 case Token.OPEN_PARENS_CAST:
7847 case Token.OPEN_PARENS_LAMBDA:
7848 case Token.OPEN_PARENS:
7850 case Token.CLOSE_PARENS:
7856 case Token.DEFAULT_COLON:
7860 case Token.SEMICOLON:
7871 case Token.BITWISE_AND:
7872 case Token.BITWISE_OR:
7879 case Token.OP_SHIFT_LEFT:
7880 case Token.OP_SHIFT_RIGHT:
7888 case Token.OP_COALESCING:
7889 case Token.OP_MULT_ASSIGN:
7890 case Token.OP_DIV_ASSIGN:
7891 case Token.OP_MOD_ASSIGN:
7892 case Token.OP_ADD_ASSIGN:
7893 case Token.OP_SUB_ASSIGN:
7894 case Token.OP_SHIFT_LEFT_ASSIGN:
7895 case Token.OP_SHIFT_RIGHT_ASSIGN:
7896 case Token.OP_AND_ASSIGN:
7897 case Token.OP_XOR_ASSIGN:
7898 case Token.OP_OR_ASSIGN:
7899 return "<operator>";
7921 case Token.OP_GENERICS_LT:
7922 case Token.GENERIC_DIMENSION:
7924 case Token.OP_GENERICS_GT:
7927 case Token.INTERR_NULLABLE:
7929 case Token.DOUBLE_COLON:
7933 case Token.IDENTIFIER:
7935 return "identifier";
7938 return "end-of-file";
7940 // All of these are internal.
7943 case Token.FIRST_KEYWORD:
7944 case Token.EVAL_COMPILATION_UNIT_PARSER:
7945 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7946 case Token.EVAL_STATEMENT_PARSER:
7947 case Token.LAST_KEYWORD:
7948 case Token.GENERATE_COMPLETION:
7949 case Token.COMPLETE_COMPLETION:
7950 return "<internal>";
7952 // A bit more robust.
7954 return yyNames [token];