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;
2182 if ((Operator.OpType) $3 == Operator.OpType.Is)
2183 valid_param_mod |= ParameterModifierType.Out;
2185 opt_formal_parameter_list CLOSE_PARENS
2187 valid_param_mod = 0;
2189 Location loc = GetLocation ($2);
2190 Operator.OpType op = (Operator.OpType) $3;
2191 current_local_parameters = (ParametersCompiled)$6;
2193 int p_count = current_local_parameters.Count;
2195 if (op == Operator.OpType.Addition)
2196 op = Operator.OpType.UnaryPlus;
2197 else if (op == Operator.OpType.Subtraction)
2198 op = Operator.OpType.UnaryNegation;
2201 if (IsUnaryOperator (op)) {
2203 report.Error (1020, loc, "Overloadable binary operator expected");
2204 } else if (p_count != 1) {
2205 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2206 Operator.GetName (op));
2208 } else if (op == Operator.OpType.Is) {
2209 // TODO: Special checks for is operator
2212 report.Error (1019, loc, "Overloadable unary operator expected");
2213 } else if (p_count != 2) {
2214 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2215 Operator.GetName (op));
2220 tmpComment = Lexer.consume_doc_comment ();
2221 Lexer.doc_state = XmlCommentState.NotAllowed;
2224 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2225 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2227 | conversion_operator_declarator
2230 overloadable_operator
2232 : BANG { $$ = Operator.OpType.LogicalNot; }
2233 | TILDE { $$ = Operator.OpType.OnesComplement; }
2234 | OP_INC { $$ = Operator.OpType.Increment; }
2235 | OP_DEC { $$ = Operator.OpType.Decrement; }
2236 | TRUE { $$ = Operator.OpType.True; }
2237 | FALSE { $$ = Operator.OpType.False; }
2238 // Unary and binary:
2239 | PLUS { $$ = Operator.OpType.Addition; }
2240 | MINUS { $$ = Operator.OpType.Subtraction; }
2242 | STAR { $$ = Operator.OpType.Multiply; }
2243 | DIV { $$ = Operator.OpType.Division; }
2244 | PERCENT { $$ = Operator.OpType.Modulus; }
2245 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2246 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2247 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2248 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2249 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2250 | OP_EQ { $$ = Operator.OpType.Equality; }
2251 | OP_NE { $$ = Operator.OpType.Inequality; }
2252 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2253 | OP_LT { $$ = Operator.OpType.LessThan; }
2254 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2255 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2258 if (lang_version != LanguageVersion.Experimental)
2259 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2261 $$ = Operator.OpType.Is;
2265 conversion_operator_declarator
2266 : IMPLICIT OPERATOR type OPEN_PARENS
2268 valid_param_mod = ParameterModifierType.DefaultValue;
2270 opt_formal_parameter_list CLOSE_PARENS
2272 valid_param_mod = 0;
2274 Location loc = GetLocation ($2);
2275 current_local_parameters = (ParametersCompiled)$6;
2277 if (current_local_parameters.Count != 1) {
2278 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2282 tmpComment = Lexer.consume_doc_comment ();
2283 Lexer.doc_state = XmlCommentState.NotAllowed;
2286 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2287 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2289 | EXPLICIT OPERATOR type OPEN_PARENS
2291 valid_param_mod = ParameterModifierType.DefaultValue;
2293 opt_formal_parameter_list CLOSE_PARENS
2295 valid_param_mod = 0;
2297 Location loc = GetLocation ($2);
2298 current_local_parameters = (ParametersCompiled)$6;
2300 if (current_local_parameters.Count != 1) {
2301 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2305 tmpComment = Lexer.consume_doc_comment ();
2306 Lexer.doc_state = XmlCommentState.NotAllowed;
2309 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2310 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2314 Error_SyntaxError (yyToken);
2315 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2316 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2320 Error_SyntaxError (yyToken);
2321 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2322 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2326 constructor_declaration
2327 : constructor_declarator
2330 Constructor c = (Constructor) $1;
2331 c.Block = (ToplevelBlock) $2;
2334 c.DocComment = ConsumeStoredComment ();
2336 current_local_parameters = null;
2338 Lexer.doc_state = XmlCommentState.Allowed;
2342 constructor_declarator
2348 tmpComment = Lexer.consume_doc_comment ();
2349 Lexer.doc_state = XmlCommentState.Allowed;
2352 valid_param_mod = ParameterModifierType.All;
2354 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2356 valid_param_mod = 0;
2357 current_local_parameters = (ParametersCompiled) $6;
2359 var lt = (LocatedToken) $3;
2360 var mods = (Modifiers) $2;
2361 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2363 if (lt.Value != current_container.MemberName.Name) {
2364 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2365 } else if ((mods & Modifiers.STATIC) != 0) {
2366 if ((mods & Modifiers.AccessibilityMask) != 0){
2367 report.Error (515, c.Location,
2368 "`{0}': static constructor cannot have an access modifier",
2369 c.GetSignatureForError ());
2373 current_type.AddConstructor (c);
2374 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2378 // start block here, so possible anonymous methods inside
2379 // constructor initializer can get correct parent block
2381 start_block (lexer.Location);
2383 opt_constructor_initializer
2386 var c = (Constructor) $8;
2387 c.Initializer = (ConstructorInitializer) $9;
2390 report.Error (514, c.Location,
2391 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2392 c.GetSignatureForError ());
2402 | SEMICOLON { current_block = null; $$ = null; }
2405 opt_constructor_initializer
2407 | constructor_initializer
2410 constructor_initializer
2411 : COLON BASE OPEN_PARENS
2413 ++lexer.parsing_block;
2415 opt_argument_list CLOSE_PARENS
2417 --lexer.parsing_block;
2418 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2419 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2421 | COLON THIS OPEN_PARENS
2423 ++lexer.parsing_block;
2425 opt_argument_list CLOSE_PARENS
2427 --lexer.parsing_block;
2428 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2429 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2433 Error_SyntaxError (yyToken);
2434 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2435 lbag.AddLocation ($$, GetLocation ($1));
2439 Error_SyntaxError (yyToken);
2444 destructor_declaration
2445 : opt_attributes opt_modifiers TILDE
2448 tmpComment = Lexer.consume_doc_comment ();
2449 Lexer.doc_state = XmlCommentState.NotAllowed;
2452 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2454 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2456 var lt = (LocatedToken) $5;
2457 if (lt.Value != current_container.MemberName.Name){
2458 report.Error (574, lt.Location, "Name of destructor must match name of class");
2459 } else if (current_container.Kind != MemberKind.Class){
2460 report.Error (575, lt.Location, "Only class types can contain destructor");
2463 Destructor d = new Destructor (current_type, (Modifiers) $2,
2464 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2466 d.DocComment = ConsumeStoredComment ();
2468 d.Block = (ToplevelBlock) $8;
2469 current_type.AddMember (d);
2470 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2472 current_local_parameters = null;
2479 EVENT type member_declaration_name
2481 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2482 current_type.AddMember (current_event_field);
2484 if (current_event_field.MemberName.ExplicitInterface != null) {
2485 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2486 current_event_field.GetSignatureForError ());
2489 $$ = current_event_field;
2491 opt_event_initializer
2492 opt_event_declarators
2496 current_event_field.DocComment = Lexer.consume_doc_comment ();
2497 Lexer.doc_state = XmlCommentState.Allowed;
2500 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2501 current_event_field = null;
2505 EVENT type member_declaration_name
2508 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2509 current_type.AddMember (current_event);
2510 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2512 lexer.EventParsing = true;
2514 event_accessor_declarations
2516 if (current_container.Kind == MemberKind.Interface)
2517 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2519 lexer.EventParsing = false;
2524 current_event.DocComment = Lexer.consume_doc_comment ();
2525 Lexer.doc_state = XmlCommentState.Allowed;
2528 lbag.AppendToMember (current_event, GetLocation ($9));
2529 current_event = null;
2530 current_local_parameters = null;
2536 Error_SyntaxError (yyToken);
2538 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2542 opt_event_initializer
2546 ++lexer.parsing_block;
2548 event_variable_initializer
2550 --lexer.parsing_block;
2551 current_event_field.Initializer = (Expression) $3;
2555 opt_event_declarators
2563 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2565 | event_declarators event_declarator
2567 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2574 var lt = (LocatedToken) $2;
2575 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2576 lbag.AddLocation ($$, GetLocation ($1));
2578 | COMMA IDENTIFIER ASSIGN
2580 ++lexer.parsing_block;
2582 event_variable_initializer
2584 --lexer.parsing_block;
2585 var lt = (LocatedToken) $2;
2586 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2587 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2591 event_variable_initializer
2593 if (current_container.Kind == MemberKind.Interface) {
2594 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2595 current_event_field.GetSignatureForError ());
2598 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2599 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2600 current_event_field.GetSignatureForError ());
2603 variable_initializer
2609 event_accessor_declarations
2610 : add_accessor_declaration remove_accessor_declaration
2611 | remove_accessor_declaration add_accessor_declaration
2612 | add_accessor_declaration
2614 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2615 current_event.GetSignatureForError ());
2617 | remove_accessor_declaration
2619 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2620 current_event.GetSignatureForError ());
2624 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2629 add_accessor_declaration
2630 : opt_attributes opt_modifiers ADD
2632 if ($2 != ModifierNone) {
2633 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2636 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2637 current_local_parameters = current_event.Add.ParameterInfo;
2639 lbag.AddMember (current_event.Add, mod_locations);
2640 lexer.EventParsing = false;
2642 event_accessor_block
2644 lexer.EventParsing = true;
2646 current_event.Add.Block = (ToplevelBlock) $5;
2648 if (current_container.Kind == MemberKind.Interface) {
2649 report.Error (531, current_event.Add.Block.StartLocation,
2650 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2653 current_local_parameters = null;
2657 remove_accessor_declaration
2658 : opt_attributes opt_modifiers REMOVE
2660 if ($2 != ModifierNone) {
2661 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2664 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2665 current_local_parameters = current_event.Remove.ParameterInfo;
2667 lbag.AddMember (current_event.Remove, mod_locations);
2668 lexer.EventParsing = false;
2670 event_accessor_block
2672 lexer.EventParsing = true;
2674 current_event.Remove.Block = (ToplevelBlock) $5;
2676 if (current_container.Kind == MemberKind.Interface) {
2677 report.Error (531, current_event.Remove.Block.StartLocation,
2678 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2681 current_local_parameters = null;
2685 event_accessor_block
2688 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2694 attributes_without_members
2695 : attribute_sections CLOSE_BRACE
2697 current_type.UnattachedAttributes = (Attributes) $1;
2698 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2699 lexer.putback ('}');
2703 // For full ast try to recover incomplete ambiguous member
2704 // declaration in form on class X { public int }
2706 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2708 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2710 lexer.putback ('}');
2712 lexer.parsing_generic_declaration = false;
2713 FullNamedExpression type = (FullNamedExpression) $3;
2714 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2715 current_type.AddField (current_field);
2723 ENUM type_declaration_name
2727 enumTypeComment = Lexer.consume_doc_comment ();
2732 Lexer.doc_state = XmlCommentState.Allowed;
2734 MemberName name = (MemberName) $4;
2735 if (name.IsGeneric) {
2736 report.Error (1675, name.Location, "Enums cannot have type parameters");
2739 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2741 opt_enum_member_declarations
2743 lexer.parsing_modifiers = true;
2745 // here will be evaluated after CLOSE_BLACE is consumed.
2747 Lexer.doc_state = XmlCommentState.Allowed;
2749 CLOSE_BRACE opt_semicolon
2752 current_container.DocComment = enumTypeComment;
2754 --lexer.parsing_declaration;
2757 // em.DocComment = ev.DocComment;
2759 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2760 $$ = pop_current_class ();
2772 Error_TypeExpected (GetLocation ($1));
2777 opt_enum_member_declarations
2779 | enum_member_declarations
2780 | enum_member_declarations COMMA
2782 lbag.AddLocation ($1, GetLocation ($2));
2786 enum_member_declarations
2787 : enum_member_declaration
2788 | enum_member_declarations COMMA enum_member_declaration
2790 lbag.AddLocation ($1, GetLocation ($2));
2795 enum_member_declaration
2796 : opt_attributes IDENTIFIER
2798 var lt = (LocatedToken) $2;
2799 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2800 ((Enum) current_type).AddEnumMember (em);
2803 em.DocComment = Lexer.consume_doc_comment ();
2804 Lexer.doc_state = XmlCommentState.Allowed;
2809 | opt_attributes IDENTIFIER
2811 ++lexer.parsing_block;
2813 tmpComment = Lexer.consume_doc_comment ();
2814 Lexer.doc_state = XmlCommentState.NotAllowed;
2817 ASSIGN constant_expression
2819 --lexer.parsing_block;
2821 var lt = (LocatedToken) $2;
2822 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2823 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2824 ((Enum) current_type).AddEnumMember (em);
2827 em.DocComment = ConsumeStoredComment ();
2831 | opt_attributes IDENTIFIER error
2833 Error_SyntaxError (yyToken);
2835 var lt = (LocatedToken) $2;
2836 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2837 ((Enum) current_type).AddEnumMember (em);
2840 em.DocComment = Lexer.consume_doc_comment ();
2841 Lexer.doc_state = XmlCommentState.Allowed;
2846 | attributes_without_members
2849 delegate_declaration
2853 member_type type_declaration_name
2856 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2858 opt_formal_parameter_list CLOSE_PARENS
2860 valid_param_mod = 0;
2862 ParametersCompiled p = (ParametersCompiled) $8;
2864 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2866 p.CheckParameters (del);
2868 current_container.AddTypeContainer (del);
2870 current_delegate = del;
2871 lexer.ConstraintsParsing = true;
2873 opt_type_parameter_constraints_clauses
2875 lexer.ConstraintsParsing = false;
2880 current_delegate.DocComment = Lexer.consume_doc_comment ();
2881 Lexer.doc_state = XmlCommentState.Allowed;
2885 current_delegate.SetConstraints ((List<Constraints>) $11);
2886 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2888 $$ = current_delegate;
2890 current_delegate = null;
2898 if (lang_version < LanguageVersion.ISO_2)
2899 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2901 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2905 namespace_or_type_expr
2907 | qualified_alias_member IDENTIFIER opt_type_argument_list
2909 var lt1 = (LocatedToken) $1;
2910 var lt2 = (LocatedToken) $2;
2912 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2913 lbag.AddLocation ($$, GetLocation ($2));
2915 | qualified_alias_member IDENTIFIER generic_dimension
2917 var lt1 = (LocatedToken) $1;
2918 var lt2 = (LocatedToken) $2;
2920 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2921 lbag.AddLocation ($$, GetLocation ($2));
2927 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2929 var lt = (LocatedToken) $3;
2930 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2931 lbag.AddLocation ($$, GetLocation ($2));
2933 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2935 var lt = (LocatedToken) $3;
2936 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2937 lbag.AddLocation ($$, GetLocation ($2));
2942 : IDENTIFIER opt_type_argument_list
2944 var lt = (LocatedToken) $1;
2945 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2947 | IDENTIFIER generic_dimension
2949 var lt = (LocatedToken) $1;
2950 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2955 // Generics arguments (any type, without attributes)
2957 opt_type_argument_list
2959 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2961 if (lang_version < LanguageVersion.ISO_2)
2962 FeatureIsNotAvailable (GetLocation ($1), "generics");
2966 | OP_GENERICS_LT error
2968 Error_TypeExpected (lexer.Location);
2969 $$ = new TypeArguments ();
2976 TypeArguments type_args = new TypeArguments ();
2977 type_args.Add ((FullNamedExpression) $1);
2980 | type_arguments COMMA type
2982 TypeArguments type_args = (TypeArguments) $1;
2983 type_args.Add ((FullNamedExpression) $3);
2989 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2991 type_declaration_name
2994 lexer.parsing_generic_declaration = true;
2996 opt_type_parameter_list
2998 lexer.parsing_generic_declaration = false;
2999 var lt = (LocatedToken) $1;
3000 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3004 member_declaration_name
3005 : method_declaration_name
3007 MemberName mn = (MemberName)$1;
3008 if (mn.TypeParameters != null)
3009 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3010 mn.GetSignatureForError ()));
3014 method_declaration_name
3015 : type_declaration_name
3016 | explicit_interface IDENTIFIER opt_type_parameter_list
3018 lexer.parsing_generic_declaration = false;
3019 var lt = (LocatedToken) $2;
3020 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3024 indexer_declaration_name
3027 lexer.parsing_generic_declaration = false;
3028 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3030 | explicit_interface THIS
3032 lexer.parsing_generic_declaration = false;
3033 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3038 : IDENTIFIER opt_type_argument_list DOT
3040 var lt = (LocatedToken) $1;
3041 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3042 lbag.AddLocation ($$, GetLocation ($3));
3044 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3046 var lt1 = (LocatedToken) $1;
3047 var lt2 = (LocatedToken) $2;
3049 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3050 lbag.AddLocation ($$, GetLocation ($4));
3052 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3054 var lt = (LocatedToken) $2;
3055 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3056 lbag.AddLocation ($$, GetLocation ($4));
3060 opt_type_parameter_list
3062 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3064 if (lang_version < LanguageVersion.ISO_2)
3065 FeatureIsNotAvailable (GetLocation ($1), "generics");
3068 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3075 var tparams = new TypeParameters ();
3076 tparams.Add ((TypeParameter)$1);
3079 | type_parameters COMMA type_parameter
3081 var tparams = (TypeParameters) $1;
3082 tparams.Add ((TypeParameter)$3);
3084 lbag.AddLocation ($3, GetLocation ($3));
3089 : opt_attributes opt_type_parameter_variance IDENTIFIER
3091 var lt = (LocatedToken)$3;
3092 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3096 if (GetTokenName (yyToken) == "type")
3097 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3099 Error_SyntaxError (yyToken);
3101 $$ = new TypeParameter (MemberName.Null, null, null);
3106 // All types where void is allowed
3109 : type_expression_or_array
3112 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3119 lexer.parsing_generic_declaration = true;
3124 // A type which does not allow `void' to be used
3127 : type_expression_or_array
3137 : type_expression_or_array
3140 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3141 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3145 type_expression_or_array
3147 | type_expression rank_specifiers
3149 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3154 : namespace_or_type_expr opt_nullable
3157 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3159 var sn = $1 as SimpleName;
3160 if (sn != null && sn.Name == "var")
3161 $$ = new VarExpr (sn.Location);
3166 | namespace_or_type_expr pointer_stars
3168 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3170 | builtin_type_expression
3176 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3177 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3181 builtin_type_expression
3182 : builtin_types opt_nullable
3185 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3187 | builtin_types pointer_stars
3189 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3191 | VOID pointer_stars
3193 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3200 var types = new List<FullNamedExpression> (2);
3201 types.Add ((FullNamedExpression) $1);
3204 | type_list COMMA base_type_name
3206 var types = (List<FullNamedExpression>) $1;
3207 types.Add ((FullNamedExpression) $3);
3215 if ($1 is ComposedCast) {
3216 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3223 * replaces all the productions for isolating the various
3224 * simple types, but we need this to reuse it easily in variable_type
3227 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3228 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3229 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3230 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3231 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3232 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3237 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3238 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3239 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3240 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3241 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3242 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3243 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3244 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3245 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3249 // Expressions, section 7.5
3254 : type_name_expression
3256 | array_creation_expression
3257 | parenthesized_expression
3258 | default_value_expression
3259 | invocation_expression
3263 | post_increment_expression
3264 | post_decrement_expression
3265 | object_or_delegate_creation_expression
3266 | anonymous_type_expression
3269 | checked_expression
3270 | unchecked_expression
3271 | pointer_member_access
3272 | anonymous_method_expression
3273 | undocumented_expressions
3276 type_name_expression
3278 | IDENTIFIER GENERATE_COMPLETION {
3279 var lt = (LocatedToken) $1;
3280 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3288 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3292 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3293 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3298 // Here is the trick, tokenizer may think that parens is a special but
3299 // parser is interested in open parens only, so we merge them.
3300 // Consider: if (a)foo ();
3308 // Use this production to accept closing parenthesis or
3309 // performing completion
3313 | COMPLETE_COMPLETION
3317 parenthesized_expression
3318 : OPEN_PARENS expression CLOSE_PARENS
3320 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3321 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3323 | OPEN_PARENS expression COMPLETE_COMPLETION
3325 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3330 : primary_expression DOT identifier_inside_body opt_type_argument_list
3332 var lt = (LocatedToken) $3;
3333 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3334 lbag.AddLocation ($$, GetLocation ($2));
3336 | primary_expression DOT identifier_inside_body generic_dimension
3338 var lt = (LocatedToken) $3;
3339 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3340 lbag.AddLocation ($$, GetLocation ($2));
3342 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3344 if (lang_version < LanguageVersion.V_6)
3345 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3347 var lt = (LocatedToken) $4;
3348 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3349 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3351 | builtin_types DOT identifier_inside_body opt_type_argument_list
3353 var lt = (LocatedToken) $3;
3354 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3355 lbag.AddLocation ($$, GetLocation ($2));
3357 | BASE DOT identifier_inside_body opt_type_argument_list
3359 var lt = (LocatedToken) $3;
3360 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3361 lbag.AddLocation ($$, GetLocation ($2));
3363 | AWAIT DOT identifier_inside_body opt_type_argument_list
3365 var lt = (LocatedToken) $3;
3366 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3367 lbag.AddLocation ($$, GetLocation ($2));
3369 | qualified_alias_member identifier_inside_body opt_type_argument_list
3371 var lt1 = (LocatedToken) $1;
3372 var lt2 = (LocatedToken) $2;
3374 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3375 lbag.AddLocation ($$, GetLocation ($2));
3377 | qualified_alias_member identifier_inside_body generic_dimension
3379 var lt1 = (LocatedToken) $1;
3380 var lt2 = (LocatedToken) $2;
3382 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3383 lbag.AddLocation ($$, GetLocation ($2));
3385 | primary_expression DOT GENERATE_COMPLETION {
3386 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3388 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3389 var lt = (LocatedToken) $3;
3390 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3392 | builtin_types DOT GENERATE_COMPLETION
3394 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3396 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3397 var lt = (LocatedToken) $3;
3398 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3402 invocation_expression
3403 : primary_expression open_parens_any opt_argument_list close_parens
3405 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3406 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3408 | primary_expression open_parens_any argument_list error
3410 Error_SyntaxError (yyToken);
3412 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3413 lbag.AddLocation ($$, GetLocation ($2));
3415 | primary_expression open_parens_any error
3417 Error_SyntaxError (yyToken);
3419 $$ = new Invocation ((Expression) $1, null);
3420 lbag.AddLocation ($$, GetLocation ($2));
3424 opt_object_or_collection_initializer
3425 : /* empty */ { $$ = null; }
3426 | object_or_collection_initializer
3429 object_or_collection_initializer
3430 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3433 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3435 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3437 lbag.AddLocation ($$, GetLocation ($3));
3439 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3441 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3442 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3446 opt_member_initializer_list
3447 : /* empty */ { $$ = null; }
3448 | member_initializer_list
3454 member_initializer_list
3455 : member_initializer
3457 var a = new List<Expression> ();
3458 a.Add ((Expression) $1);
3461 | member_initializer_list COMMA member_initializer
3463 var a = (List<Expression>)$1;
3464 a.Add ((Expression) $3);
3467 | member_initializer_list error {
3468 Error_SyntaxError (yyToken);
3474 : IDENTIFIER ASSIGN initializer_value
3476 var lt = (LocatedToken) $1;
3477 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3478 lbag.AddLocation ($$, GetLocation ($2));
3480 | AWAIT ASSIGN initializer_value
3482 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3483 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3484 lbag.AddLocation ($$, GetLocation ($2));
3486 | GENERATE_COMPLETION
3488 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3490 | non_assignment_expression opt_COMPLETE_COMPLETION {
3491 CompletionSimpleName csn = $1 as CompletionSimpleName;
3493 $$ = new CollectionElementInitializer ((Expression)$1);
3495 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3497 | OPEN_BRACE expression_list CLOSE_BRACE
3500 $$ = new CollectionElementInitializer (GetLocation ($1));
3502 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3504 lbag.AddLocation ($$, GetLocation ($3));
3506 | OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET ASSIGN initializer_value
3508 if (lang_version < LanguageVersion.V_6)
3509 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3511 $$ = new DictionaryElementInitializer ((List<Expression>)$2, (Expression) $5, GetLocation ($1));
3512 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3514 | OPEN_BRACE CLOSE_BRACE
3516 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3517 $$ = new CollectionElementInitializer (GetLocation ($1));
3518 lbag.AddLocation ($$, GetLocation ($2));
3524 | object_or_collection_initializer
3528 : /* empty */ { $$ = null; }
3533 : argument_or_named_argument
3535 Arguments list = new Arguments (4);
3536 list.Add ((Argument) $1);
3539 | argument_list COMMA argument
3541 Arguments list = (Arguments) $1;
3542 if (list [list.Count - 1] is NamedArgument)
3543 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3545 list.Add ((Argument) $3);
3548 | argument_list COMMA named_argument
3550 Arguments list = (Arguments) $1;
3551 NamedArgument a = (NamedArgument) $3;
3552 for (int i = 0; i < list.Count; ++i) {
3553 NamedArgument na = list [i] as NamedArgument;
3554 if (na != null && na.Name == a.Name)
3555 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3562 | argument_list COMMA error
3564 if (lexer.putback_char == -1)
3565 lexer.putback (')'); // TODO: Wrong but what can I do
3566 Error_SyntaxError (yyToken);
3571 report.Error (839, GetLocation ($1), "An argument is missing");
3579 $$ = new Argument ((Expression) $1);
3581 | non_simple_argument
3584 argument_or_named_argument
3590 : REF variable_reference
3592 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3593 lbag.AddLocation ($$, GetLocation ($1));
3595 | OUT variable_reference
3597 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3598 lbag.AddLocation ($$, GetLocation ($1));
3600 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3602 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3603 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3605 | ARGLIST OPEN_PARENS CLOSE_PARENS
3607 $$ = new Argument (new Arglist (GetLocation ($1)));
3608 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3617 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3619 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3620 lbag.AddLocation ($$, GetLocation ($4));
3622 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3624 if (lang_version < LanguageVersion.V_6)
3625 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3627 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3628 ConditionalAccess = true
3631 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3633 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3635 Error_SyntaxError (yyToken);
3636 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3638 | primary_expression OPEN_BRACKET_EXPR error
3640 Error_SyntaxError (yyToken);
3641 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3646 : expression_or_error
3648 var list = new List<Expression> (4);
3649 list.Add ((Expression) $1);
3652 | expression_list COMMA expression_or_error
3654 var list = (List<Expression>) $1;
3655 list.Add ((Expression) $3);
3660 expression_list_arguments
3661 : expression_list_argument
3663 Arguments args = new Arguments (4);
3664 args.Add ((Argument) $1);
3667 | expression_list_arguments COMMA expression_list_argument
3669 Arguments args = (Arguments) $1;
3670 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3671 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3673 args.Add ((Argument) $3);
3678 expression_list_argument
3681 $$ = new Argument ((Expression) $1);
3689 $$ = new This (GetLocation ($1));
3694 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3696 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3697 lbag.AddLocation ($$, GetLocation ($4));
3699 | BASE OPEN_BRACKET error
3701 Error_SyntaxError (yyToken);
3702 $$ = new ElementAccess (null, null, GetLocation ($2));
3706 post_increment_expression
3707 : primary_expression OP_INC
3709 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3713 post_decrement_expression
3714 : primary_expression OP_DEC
3716 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3720 object_or_delegate_creation_expression
3721 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3724 if (lang_version <= LanguageVersion.ISO_2)
3725 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3727 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3729 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3732 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3734 | NEW new_expr_type object_or_collection_initializer
3736 if (lang_version <= LanguageVersion.ISO_2)
3737 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3739 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3743 array_creation_expression
3744 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3746 opt_array_initializer
3748 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3749 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3750 Next = (ComposedTypeSpecifier) $6
3751 }, (ArrayInitializer) $7, GetLocation ($1));
3752 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3754 | NEW new_expr_type rank_specifiers opt_array_initializer
3757 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3759 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3761 | NEW rank_specifier array_initializer
3763 if (lang_version <= LanguageVersion.ISO_2)
3764 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3766 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3768 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3770 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3771 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3773 | NEW new_expr_type error
3775 Error_SyntaxError (yyToken);
3776 // It can be any of new expression, create the most common one
3777 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3783 ++lexer.parsing_type;
3787 --lexer.parsing_type;
3792 anonymous_type_expression
3793 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3795 if (lang_version <= LanguageVersion.ISO_2)
3796 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3798 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3800 // TODO: lbag comma location
3801 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3803 | NEW OPEN_BRACE GENERATE_COMPLETION
3805 $$ = new EmptyCompletion ();
3809 anonymous_type_parameters_opt_comma
3810 : anonymous_type_parameters_opt
3811 | anonymous_type_parameters COMMA
3814 anonymous_type_parameters_opt
3816 | anonymous_type_parameters
3819 anonymous_type_parameters
3820 : anonymous_type_parameter
3822 var a = new List<AnonymousTypeParameter> (4);
3823 a.Add ((AnonymousTypeParameter) $1);
3826 | anonymous_type_parameters COMMA anonymous_type_parameter
3828 var a = (List<AnonymousTypeParameter>) $1;
3829 a.Add ((AnonymousTypeParameter) $3);
3832 | COMPLETE_COMPLETION
3834 $$ = new EmptyCompletion ();
3836 | anonymous_type_parameter COMPLETE_COMPLETION
3842 anonymous_type_parameter
3843 : identifier_inside_body ASSIGN variable_initializer
3845 var lt = (LocatedToken)$1;
3846 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3847 lbag.AddLocation ($$, GetLocation ($2));
3849 | identifier_inside_body
3851 var lt = (LocatedToken)$1;
3852 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3853 lt.Value, lt.Location);
3857 MemberAccess ma = (MemberAccess) $1;
3858 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3862 report.Error (746, lexer.Location,
3863 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3875 | rank_specifier rank_specifiers
3877 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3883 : OPEN_BRACKET CLOSE_BRACKET
3885 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3886 lbag.AddLocation ($$, GetLocation ($2));
3888 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3890 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3891 lbag.AddLocation ($$, GetLocation ($3));
3900 | dim_separators COMMA
3902 $$ = ((int) $1) + 1;
3906 opt_array_initializer
3918 : OPEN_BRACE CLOSE_BRACE
3920 var ai = new ArrayInitializer (0, GetLocation ($1));
3921 ai.VariableDeclaration = current_variable;
3922 lbag.AddLocation (ai, GetLocation ($2));
3925 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3927 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3928 ai.VariableDeclaration = current_variable;
3930 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3932 lbag.AddLocation (ai, GetLocation ($4));
3938 variable_initializer_list
3939 : variable_initializer
3941 var list = new List<Expression> (4);
3942 list.Add ((Expression) $1);
3945 | variable_initializer_list COMMA variable_initializer
3947 var list = (List<Expression>) $1;
3948 list.Add ((Expression) $3);
3954 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
3956 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
3957 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3961 typeof_type_expression
3965 Error_TypeExpected (lexer.Location);
3973 if (lang_version < LanguageVersion.ISO_2)
3974 FeatureIsNotAvailable (GetLocation ($1), "generics");
3980 qualified_alias_member
3981 : IDENTIFIER DOUBLE_COLON
3983 var lt = (LocatedToken) $1;
3984 if (lang_version == LanguageVersion.ISO_1)
3985 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3992 : SIZEOF open_parens_any type CLOSE_PARENS
3994 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3995 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3997 | SIZEOF open_parens_any type error
3999 Error_SyntaxError (yyToken);
4001 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4002 lbag.AddLocation ($$, GetLocation ($2));
4007 : CHECKED open_parens_any expression CLOSE_PARENS
4009 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4010 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4014 Error_SyntaxError (yyToken);
4016 $$ = new CheckedExpr (null, GetLocation ($1));
4020 unchecked_expression
4021 : UNCHECKED open_parens_any expression CLOSE_PARENS
4023 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4024 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4028 Error_SyntaxError (yyToken);
4030 $$ = new UnCheckedExpr (null, GetLocation ($1));
4034 pointer_member_access
4035 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4037 var lt = (LocatedToken) $3;
4038 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4042 anonymous_method_expression
4043 : DELEGATE opt_anonymous_method_signature
4045 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4049 $$ = end_anonymous ((ParametersBlock) $4);
4051 | ASYNC DELEGATE opt_anonymous_method_signature
4053 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4057 $$ = end_anonymous ((ParametersBlock) $5);
4061 opt_anonymous_method_signature
4064 $$ = ParametersCompiled.Undefined;
4066 | anonymous_method_signature
4069 anonymous_method_signature
4072 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4074 opt_formal_parameter_list CLOSE_PARENS
4076 valid_param_mod = 0;
4081 default_value_expression
4082 : DEFAULT open_parens_any type CLOSE_PARENS
4084 if (lang_version < LanguageVersion.ISO_2)
4085 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4087 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4088 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4093 : primary_expression
4094 | BANG prefixed_unary_expression
4096 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4098 | TILDE prefixed_unary_expression
4100 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4102 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4104 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4105 lbag.AddLocation ($$, GetLocation ($3));
4107 | AWAIT prefixed_unary_expression
4110 if (current_anonymous_method is LambdaExpression) {
4111 report.Error (4034, GetLocation ($1),
4112 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4113 } else if (current_anonymous_method != null) {
4114 report.Error (4035, GetLocation ($1),
4115 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4116 } else if (interactive_async != null) {
4117 current_block.Explicit.RegisterAsyncAwait ();
4118 interactive_async = true;
4120 report.Error (4033, GetLocation ($1),
4121 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4124 current_block.Explicit.RegisterAsyncAwait ();
4127 $$ = new Await ((Expression) $2, GetLocation ($1));
4131 Error_SyntaxError (yyToken);
4133 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4137 Error_SyntaxError (yyToken);
4139 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4141 | OPEN_PARENS_CAST type CLOSE_PARENS error
4143 Error_SyntaxError (yyToken);
4145 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4146 lbag.AddLocation ($$, GetLocation ($3));
4150 Error_SyntaxError (yyToken);
4152 $$ = new Await (null, GetLocation ($1));
4157 // The idea to split this out is from Rhys' grammar
4158 // to solve the problem with casts.
4160 prefixed_unary_expression
4162 | PLUS prefixed_unary_expression
4164 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4166 | MINUS prefixed_unary_expression
4168 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4170 | OP_INC prefixed_unary_expression
4172 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4174 | OP_DEC prefixed_unary_expression
4176 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4178 | STAR prefixed_unary_expression
4180 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4182 | BITWISE_AND prefixed_unary_expression
4184 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4188 Error_SyntaxError (yyToken);
4190 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4194 Error_SyntaxError (yyToken);
4196 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4200 Error_SyntaxError (yyToken);
4202 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4206 Error_SyntaxError (yyToken);
4208 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4212 Error_SyntaxError (yyToken);
4214 $$ = new Indirection (null, GetLocation ($1));
4218 Error_SyntaxError (yyToken);
4220 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4224 multiplicative_expression
4225 : prefixed_unary_expression
4226 | multiplicative_expression STAR prefixed_unary_expression
4228 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4229 lbag.AddLocation ($$, GetLocation ($2));
4231 | multiplicative_expression DIV prefixed_unary_expression
4233 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4234 lbag.AddLocation ($$, GetLocation ($2));
4236 | multiplicative_expression PERCENT prefixed_unary_expression
4238 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4239 lbag.AddLocation ($$, GetLocation ($2));
4241 | multiplicative_expression STAR error
4243 Error_SyntaxError (yyToken);
4245 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4246 lbag.AddLocation ($$, GetLocation ($2));
4248 | multiplicative_expression DIV error
4250 Error_SyntaxError (yyToken);
4252 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4253 lbag.AddLocation ($$, GetLocation ($2));
4255 | multiplicative_expression PERCENT error
4257 Error_SyntaxError (yyToken);
4259 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4260 lbag.AddLocation ($$, GetLocation ($2));
4265 : multiplicative_expression
4266 | additive_expression PLUS multiplicative_expression
4268 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4269 lbag.AddLocation ($$, GetLocation ($2));
4271 | additive_expression MINUS multiplicative_expression
4273 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4274 lbag.AddLocation ($$, GetLocation ($2));
4276 | additive_expression PLUS error
4278 Error_SyntaxError (yyToken);
4280 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4281 lbag.AddLocation ($$, GetLocation ($2));
4283 | additive_expression MINUS error
4285 Error_SyntaxError (yyToken);
4287 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4288 lbag.AddLocation ($$, GetLocation ($2));
4290 | additive_expression AS type
4292 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4294 | additive_expression IS pattern_type_expr opt_identifier
4296 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4298 if (lang_version != LanguageVersion.Experimental)
4299 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4301 var lt = (LocatedToken) $4;
4302 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4303 current_block.AddLocalName (is_expr.Variable);
4308 | additive_expression IS pattern_expr
4310 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4311 if (lang_version != LanguageVersion.Experimental)
4312 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4316 | additive_expression AS error
4318 Error_SyntaxError (yyToken);
4320 $$ = new As ((Expression) $1, null, GetLocation ($2));
4322 | additive_expression IS error
4324 Error_SyntaxError (yyToken);
4326 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4330 var lt = (LocatedToken) $1;
4331 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4335 var lt = (LocatedToken) $1;
4336 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4346 | PLUS prefixed_unary_expression
4348 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4350 | MINUS prefixed_unary_expression
4352 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4355 | default_value_expression
4358 $$ = new WildcardPattern (GetLocation ($1));
4360 | pattern_expr_invocation
4363 pattern_expr_invocation
4364 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4366 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4372 | pattern_type_expr opt_identifier
4375 var lt = (LocatedToken) $2;
4376 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4377 current_block.AddLocalName (variable);
4385 $$ = new Arguments (0);
4393 Arguments args = new Arguments (4);
4394 args.Add ((Argument) $1);
4397 | pattern_list COMMA pattern_argument
4399 Arguments args = (Arguments) $1;
4400 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4401 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4403 args.Add ((Argument) $3);
4411 $$ = new Argument ((Expression) $1);
4413 | IDENTIFIER COLON pattern
4415 var lt = (LocatedToken) $1;
4416 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4421 : additive_expression
4422 | shift_expression OP_SHIFT_LEFT additive_expression
4424 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4425 lbag.AddLocation ($$, GetLocation ($2));
4427 | shift_expression OP_SHIFT_RIGHT additive_expression
4429 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4430 lbag.AddLocation ($$, GetLocation ($2));
4432 | shift_expression OP_SHIFT_LEFT error
4434 Error_SyntaxError (yyToken);
4436 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4437 lbag.AddLocation ($$, GetLocation ($2));
4439 | shift_expression OP_SHIFT_RIGHT error
4441 Error_SyntaxError (yyToken);
4443 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4444 lbag.AddLocation ($$, GetLocation ($2));
4448 relational_expression
4450 | relational_expression OP_LT shift_expression
4452 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4453 lbag.AddLocation ($$, GetLocation ($2));
4455 | relational_expression OP_GT shift_expression
4457 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4458 lbag.AddLocation ($$, GetLocation ($2));
4460 | relational_expression OP_LE shift_expression
4462 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4463 lbag.AddLocation ($$, GetLocation ($2));
4465 | relational_expression OP_GE shift_expression
4467 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4468 lbag.AddLocation ($$, GetLocation ($2));
4470 | relational_expression OP_LT error
4472 Error_SyntaxError (yyToken);
4474 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4475 lbag.AddLocation ($$, GetLocation ($2));
4477 | relational_expression OP_GT error
4479 Error_SyntaxError (yyToken);
4481 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4482 lbag.AddLocation ($$, GetLocation ($2));
4484 | relational_expression OP_LE error
4486 Error_SyntaxError (yyToken);
4488 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4489 lbag.AddLocation ($$, GetLocation ($2));
4491 | relational_expression OP_GE error
4493 Error_SyntaxError (yyToken);
4495 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4496 lbag.AddLocation ($$, GetLocation ($2));
4501 : relational_expression
4502 | equality_expression OP_EQ relational_expression
4504 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4505 lbag.AddLocation ($$, GetLocation ($2));
4507 | equality_expression OP_NE relational_expression
4509 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4510 lbag.AddLocation ($$, GetLocation ($2));
4512 | equality_expression OP_EQ error
4514 Error_SyntaxError (yyToken);
4516 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4517 lbag.AddLocation ($$, GetLocation ($2));
4519 | equality_expression OP_NE error
4521 Error_SyntaxError (yyToken);
4523 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4524 lbag.AddLocation ($$, GetLocation ($2));
4529 : equality_expression
4530 | and_expression BITWISE_AND equality_expression
4532 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4533 lbag.AddLocation ($$, GetLocation ($2));
4535 | and_expression BITWISE_AND error
4537 Error_SyntaxError (yyToken);
4539 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4540 lbag.AddLocation ($$, GetLocation ($2));
4544 exclusive_or_expression
4546 | exclusive_or_expression CARRET and_expression
4548 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4549 lbag.AddLocation ($$, GetLocation ($2));
4551 | exclusive_or_expression CARRET error
4553 Error_SyntaxError (yyToken);
4555 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4556 lbag.AddLocation ($$, GetLocation ($2));
4560 inclusive_or_expression
4561 : exclusive_or_expression
4562 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4564 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4565 lbag.AddLocation ($$, GetLocation ($2));
4567 | inclusive_or_expression BITWISE_OR error
4569 Error_SyntaxError (yyToken);
4571 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4572 lbag.AddLocation ($$, GetLocation ($2));
4576 conditional_and_expression
4577 : inclusive_or_expression
4578 | conditional_and_expression OP_AND inclusive_or_expression
4580 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4581 lbag.AddLocation ($$, GetLocation ($2));
4583 | conditional_and_expression OP_AND error
4585 Error_SyntaxError (yyToken);
4587 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4588 lbag.AddLocation ($$, GetLocation ($2));
4592 conditional_or_expression
4593 : conditional_and_expression
4594 | conditional_or_expression OP_OR conditional_and_expression
4596 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4597 lbag.AddLocation ($$, GetLocation ($2));
4599 | conditional_or_expression OP_OR error
4601 Error_SyntaxError (yyToken);
4603 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4604 lbag.AddLocation ($$, GetLocation ($2));
4608 null_coalescing_expression
4609 : conditional_or_expression
4610 | conditional_or_expression OP_COALESCING null_coalescing_expression
4612 if (lang_version < LanguageVersion.ISO_2)
4613 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4615 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4616 lbag.AddLocation ($$, GetLocation ($2));
4620 conditional_expression
4621 : null_coalescing_expression
4622 | null_coalescing_expression INTERR expression COLON expression
4624 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4625 lbag.AddLocation ($$, GetLocation ($4));
4627 | null_coalescing_expression INTERR expression error
4629 Error_SyntaxError (yyToken);
4631 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4633 | null_coalescing_expression INTERR expression COLON error
4635 Error_SyntaxError (yyToken);
4637 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4638 lbag.AddLocation ($$, GetLocation ($4));
4640 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4642 Error_SyntaxError (Token.CLOSE_BRACE);
4644 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4645 lbag.AddLocation ($$, GetLocation ($4));
4646 lexer.putback ('}');
4650 assignment_expression
4651 : prefixed_unary_expression ASSIGN expression
4653 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4654 lbag.AddLocation ($$, GetLocation ($2));
4656 | prefixed_unary_expression OP_MULT_ASSIGN expression
4658 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4659 lbag.AddLocation ($$, GetLocation ($2));
4661 | prefixed_unary_expression OP_DIV_ASSIGN expression
4663 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4664 lbag.AddLocation ($$, GetLocation ($2));
4666 | prefixed_unary_expression OP_MOD_ASSIGN expression
4668 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4669 lbag.AddLocation ($$, GetLocation ($2));
4671 | prefixed_unary_expression OP_ADD_ASSIGN expression
4673 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4674 lbag.AddLocation ($$, GetLocation ($2));
4676 | prefixed_unary_expression OP_SUB_ASSIGN expression
4678 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4679 lbag.AddLocation ($$, GetLocation ($2));
4681 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4683 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4684 lbag.AddLocation ($$, GetLocation ($2));
4686 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4688 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4689 lbag.AddLocation ($$, GetLocation ($2));
4691 | prefixed_unary_expression OP_AND_ASSIGN expression
4693 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4694 lbag.AddLocation ($$, GetLocation ($2));
4696 | prefixed_unary_expression OP_OR_ASSIGN expression
4698 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4699 lbag.AddLocation ($$, GetLocation ($2));
4701 | prefixed_unary_expression OP_XOR_ASSIGN expression
4703 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4704 lbag.AddLocation ($$, GetLocation ($2));
4708 lambda_parameter_list
4711 var pars = new List<Parameter> (4);
4712 pars.Add ((Parameter) $1);
4716 | lambda_parameter_list COMMA lambda_parameter
4718 var pars = (List<Parameter>) $1;
4719 Parameter p = (Parameter)$3;
4720 if (pars[0].GetType () != p.GetType ()) {
4721 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4730 : parameter_modifier parameter_type identifier_inside_body
4732 var lt = (LocatedToken) $3;
4734 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4736 | parameter_type identifier_inside_body
4738 var lt = (LocatedToken) $2;
4740 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4744 var lt = (LocatedToken) $1;
4745 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4749 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4750 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4754 opt_lambda_parameter_list
4755 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4756 | lambda_parameter_list {
4757 var pars_list = (List<Parameter>) $1;
4758 $$ = new ParametersCompiled (pars_list.ToArray ());
4762 lambda_expression_body
4764 start_block (Location.Null);
4766 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4768 Block b = end_block (Location.Null);
4769 b.IsCompilerGenerated = true;
4770 b.AddStatement (new ContextualReturn ((Expression) $2));
4776 // Handles only cases like foo = x.FirstOrDefault (l => );
4777 // where we must restore current_variable
4778 Block b = end_block (Location.Null);
4779 b.IsCompilerGenerated = true;
4781 Error_SyntaxError (yyToken);
4790 Error_SyntaxError (yyToken);
4798 var lt = (LocatedToken) $1;
4799 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4800 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4802 lambda_expression_body
4804 $$ = end_anonymous ((ParametersBlock) $4);
4805 lbag.AddLocation ($$, GetLocation ($2));
4809 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4810 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4811 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4813 lambda_expression_body
4815 $$ = end_anonymous ((ParametersBlock) $4);
4816 lbag.AddLocation ($$, GetLocation ($2));
4818 | ASYNC identifier_inside_body ARROW
4820 var lt = (LocatedToken) $2;
4821 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4822 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4824 lambda_expression_body
4826 $$ = end_anonymous ((ParametersBlock) $5);
4827 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4829 | OPEN_PARENS_LAMBDA
4831 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4833 opt_lambda_parameter_list CLOSE_PARENS ARROW
4835 valid_param_mod = 0;
4836 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4838 lambda_expression_body
4840 $$ = end_anonymous ((ParametersBlock) $7);
4841 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4843 | ASYNC OPEN_PARENS_LAMBDA
4845 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4847 opt_lambda_parameter_list CLOSE_PARENS ARROW
4849 valid_param_mod = 0;
4850 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4852 lambda_expression_body
4854 $$ = end_anonymous ((ParametersBlock) $8);
4855 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4860 : assignment_expression
4861 | non_assignment_expression
4864 non_assignment_expression
4865 : conditional_expression
4870 $$ = new ArglistAccess (GetLocation ($1));
4874 undocumented_expressions
4875 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4877 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4878 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4880 | REFTYPE open_parens_any expression CLOSE_PARENS
4882 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4883 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4885 | MAKEREF open_parens_any expression CLOSE_PARENS
4887 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4888 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4899 $$ = new BooleanExpression ((Expression) $1);
4903 opt_primary_parameters
4908 | primary_parameters
4912 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4916 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4917 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4919 if (lang_version < LanguageVersion.V_6)
4920 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
4924 opt_primary_parameters_with_class_base
4933 | primary_parameters
4937 | primary_parameters class_base
4941 | primary_parameters class_base OPEN_PARENS
4943 ++lexer.parsing_block;
4944 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
4946 opt_argument_list CLOSE_PARENS
4948 lbag.AppendToMember (current_container, GetLocation ($6));
4949 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
4950 --lexer.parsing_block;
4966 type_declaration_name
4968 lexer.ConstraintsParsing = true;
4970 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4971 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4972 FeatureIsNotAvailable (c.Location, "static classes");
4975 push_current_container (c, $3);
4976 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4978 opt_primary_parameters_with_class_base
4979 opt_type_parameter_constraints_clauses
4981 valid_param_mod = 0;
4982 lexer.ConstraintsParsing = false;
4985 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4988 current_container.SetConstraints ((List<Constraints>) $9);
4989 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4992 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4993 Lexer.doc_state = XmlCommentState.Allowed;
4996 lexer.parsing_modifiers = true;
4998 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5000 --lexer.parsing_declaration;
5002 Lexer.doc_state = XmlCommentState.Allowed;
5007 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5009 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5011 $$ = pop_current_class ();
5019 { $$ = $1; } // location
5025 mod_locations = null;
5027 lexer.parsing_modifiers = false;
5031 lexer.parsing_modifiers = false;
5037 | modifiers modifier
5039 var m1 = (Modifiers) $1;
5040 var m2 = (Modifiers) $2;
5042 if ((m1 & m2) != 0) {
5043 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5044 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5045 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5046 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5047 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5048 "More than one protection modifier specified");
5059 StoreModifierLocation ($$, GetLocation ($1));
5061 if (current_container.Kind == MemberKind.Namespace)
5062 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5066 $$ = Modifiers.PUBLIC;
5067 StoreModifierLocation ($$, GetLocation ($1));
5071 $$ = Modifiers.PROTECTED;
5072 StoreModifierLocation ($$, GetLocation ($1));
5076 $$ = Modifiers.INTERNAL;
5077 StoreModifierLocation ($$, GetLocation ($1));
5081 $$ = Modifiers.PRIVATE;
5082 StoreModifierLocation ($$, GetLocation ($1));
5086 $$ = Modifiers.ABSTRACT;
5087 StoreModifierLocation ($$, GetLocation ($1));
5091 $$ = Modifiers.SEALED;
5092 StoreModifierLocation ($$, GetLocation ($1));
5096 $$ = Modifiers.STATIC;
5097 StoreModifierLocation ($$, GetLocation ($1));
5101 $$ = Modifiers.READONLY;
5102 StoreModifierLocation ($$, GetLocation ($1));
5106 $$ = Modifiers.VIRTUAL;
5107 StoreModifierLocation ($$, GetLocation ($1));
5111 $$ = Modifiers.OVERRIDE;
5112 StoreModifierLocation ($$, GetLocation ($1));
5116 $$ = Modifiers.EXTERN;
5117 StoreModifierLocation ($$, GetLocation ($1));
5121 $$ = Modifiers.VOLATILE;
5122 StoreModifierLocation ($$, GetLocation ($1));
5126 $$ = Modifiers.UNSAFE;
5127 StoreModifierLocation ($$, GetLocation ($1));
5128 if (!settings.Unsafe)
5129 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5133 $$ = Modifiers.ASYNC;
5134 StoreModifierLocation ($$, GetLocation ($1));
5146 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5148 | COLON type_list error
5150 Error_SyntaxError (yyToken);
5152 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5156 opt_type_parameter_constraints_clauses
5158 | type_parameter_constraints_clauses
5164 type_parameter_constraints_clauses
5165 : type_parameter_constraints_clause
5167 var constraints = new List<Constraints> (1);
5168 constraints.Add ((Constraints) $1);
5171 | type_parameter_constraints_clauses type_parameter_constraints_clause
5173 var constraints = (List<Constraints>) $1;
5174 Constraints new_constraint = (Constraints)$2;
5176 foreach (Constraints c in constraints) {
5177 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5178 report.Error (409, new_constraint.Location,
5179 "A constraint clause has already been specified for type parameter `{0}'",
5180 new_constraint.TypeParameter.Value);
5184 constraints.Add (new_constraint);
5189 type_parameter_constraints_clause
5190 : WHERE IDENTIFIER COLON type_parameter_constraints
5192 var lt = (LocatedToken) $2;
5193 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5194 lbag.AddLocation ($$, GetLocation ($3));
5196 | WHERE IDENTIFIER error
5198 Error_SyntaxError (yyToken);
5200 var lt = (LocatedToken) $2;
5201 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5205 type_parameter_constraints
5206 : type_parameter_constraint
5208 var constraints = new List<FullNamedExpression> (1);
5209 constraints.Add ((FullNamedExpression) $1);
5212 | type_parameter_constraints COMMA type_parameter_constraint
5214 var constraints = (List<FullNamedExpression>) $1;
5215 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5216 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5217 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5220 prev = $3 as SpecialContraintExpr;
5222 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5223 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5225 prev = constraints [0] as SpecialContraintExpr;
5226 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5227 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5232 constraints.Add ((FullNamedExpression) $3);
5237 type_parameter_constraint
5240 if ($1 is ComposedCast)
5241 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5245 | NEW OPEN_PARENS CLOSE_PARENS
5247 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5248 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5252 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5256 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5260 opt_type_parameter_variance
5265 | type_parameter_variance
5267 if (lang_version <= LanguageVersion.V_3)
5268 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5274 type_parameter_variance
5277 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5281 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5290 // A block is "contained" on the following places:
5292 // property_declaration as part of the accessor body (get/set)
5293 // operator_declaration
5294 // constructor_declaration
5295 // destructor_declaration
5296 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5301 ++lexer.parsing_block;
5302 start_block (GetLocation ($1));
5304 opt_statement_list block_end
5313 --lexer.parsing_block;
5314 $$ = end_block (GetLocation ($1));
5316 | COMPLETE_COMPLETION
5318 --lexer.parsing_block;
5319 $$ = end_block (lexer.Location);
5327 ++lexer.parsing_block;
5328 current_block.StartLocation = GetLocation ($1);
5330 opt_statement_list CLOSE_BRACE
5332 --lexer.parsing_block;
5333 $$ = end_block (GetLocation ($4));
5344 | statement_list statement
5348 : block_variable_declaration
5350 current_block.AddStatement ((Statement) $1);
5352 | valid_declaration_statement
5354 current_block.AddStatement ((Statement) $1);
5359 Error_SyntaxError (yyToken);
5365 // The interactive_statement and its derivatives are only
5366 // used to provide a special version of `expression_statement'
5367 // that has a side effect of assigning the expression to
5370 interactive_statement_list
5371 : interactive_statement
5372 | interactive_statement_list interactive_statement
5375 interactive_statement
5376 : block_variable_declaration
5378 current_block.AddStatement ((Statement) $1);
5380 | interactive_valid_declaration_statement
5382 current_block.AddStatement ((Statement) $1);
5387 valid_declaration_statement
5390 | expression_statement
5391 | selection_statement
5392 | iteration_statement
5396 | unchecked_statement
5403 interactive_valid_declaration_statement
5406 | interactive_expression_statement
5407 | selection_statement
5408 | iteration_statement
5412 | unchecked_statement
5420 : valid_declaration_statement
5421 | block_variable_declaration
5423 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5428 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5433 Error_SyntaxError (yyToken);
5434 $$ = new EmptyStatement (GetLocation ($1));
5441 // Uses lexer.Location because semicolon location is not kept in quick mode
5442 $$ = new EmptyStatement (lexer.Location);
5447 : identifier_inside_body COLON
5449 var lt = (LocatedToken) $1;
5450 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5451 lbag.AddLocation (labeled, GetLocation ($2));
5452 current_block.AddLabel (labeled);
5453 current_block.AddStatement (labeled);
5459 : variable_type_simple
5460 | variable_type_simple rank_specifiers
5463 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5465 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5470 * The following is from Rhys' grammar:
5471 * > Types in local variable declarations must be recognized as
5472 * > expressions to prevent reduce/reduce errors in the grammar.
5473 * > The expressions are converted into types during semantic analysis.
5475 variable_type_simple
5476 : type_name_expression opt_nullable
5478 // Ok, the above "primary_expression" is there to get rid of
5479 // both reduce/reduce and shift/reduces in the grammar, it should
5480 // really just be "type_name". If you use type_name, a reduce/reduce
5481 // creeps up. If you use namespace_or_type_name (which is all we need
5482 // really) two shift/reduces appear.
5485 // So the super-trick is that primary_expression
5486 // can only be either a SimpleName or a MemberAccess.
5487 // The MemberAccess case arises when you have a fully qualified type-name like :
5489 // SimpleName is when you have
5492 var expr = (ATypeNameExpression) $1;
5494 if (expr.Name == "var" && expr is SimpleName)
5495 $$ = new VarExpr (expr.Location);
5499 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5502 | type_name_expression pointer_stars
5504 var expr = (ATypeNameExpression) $1;
5505 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5507 | builtin_type_expression
5513 | pointer_star pointer_stars
5515 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5523 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5527 identifier_inside_body
5531 $$ = Error_AwaitAsIdentifier ($1);
5535 block_variable_declaration
5536 : variable_type identifier_inside_body
5538 var lt = (LocatedToken) $2;
5539 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5540 current_block.AddLocalName (li);
5541 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5543 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5545 $$ = current_variable;
5546 current_variable = null;
5548 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5550 lbag.AddLocation ($$, GetLocation ($6));
5552 | CONST variable_type identifier_inside_body
5554 var lt = (LocatedToken) $3;
5555 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5556 current_block.AddLocalName (li);
5557 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5559 const_variable_initializer opt_const_declarators SEMICOLON
5561 $$ = current_variable;
5562 current_variable = null;
5563 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5567 opt_local_variable_initializer
5569 | ASSIGN block_variable_initializer
5571 current_variable.Initializer = (Expression) $2;
5572 PushLocation (GetLocation ($1));
5573 $$ = current_variable;
5577 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5578 report.Error (650, lexer.Location,
5579 "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");
5581 Error_SyntaxError (yyToken);
5586 opt_variable_declarators
5588 | variable_declarators
5591 opt_using_or_fixed_variable_declarators
5593 | variable_declarators
5595 foreach (var d in current_variable.Declarators) {
5596 if (d.Initializer == null)
5597 Error_MissingInitializer (d.Variable.Location);
5602 variable_declarators
5603 : variable_declarator
5604 | variable_declarators variable_declarator
5608 : COMMA identifier_inside_body
5610 var lt = (LocatedToken) $2;
5611 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5612 var d = new BlockVariableDeclarator (li, null);
5613 current_variable.AddDeclarator (d);
5614 current_block.AddLocalName (li);
5615 lbag.AddLocation (d, GetLocation ($1));
5617 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5619 var lt = (LocatedToken) $2;
5620 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5621 var d = new BlockVariableDeclarator (li, (Expression) $4);
5622 current_variable.AddDeclarator (d);
5623 current_block.AddLocalName (li);
5624 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5628 const_variable_initializer
5631 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5633 | ASSIGN constant_initializer_expr
5635 current_variable.Initializer = (Expression) $2;
5639 opt_const_declarators
5646 | const_declarators const_declarator
5650 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5652 var lt = (LocatedToken) $2;
5653 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5654 var d = new BlockVariableDeclarator (li, (Expression) $4);
5655 current_variable.AddDeclarator (d);
5656 current_block.AddLocalName (li);
5657 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5661 block_variable_initializer
5662 : variable_initializer
5663 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5665 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5666 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5668 | STACKALLOC simple_type
5670 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5671 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5675 expression_statement
5676 : statement_expression SEMICOLON
5679 lbag.AddStatement ($$, GetLocation ($2));
5681 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5682 | statement_expression CLOSE_BRACE
5685 report.Error (1002, GetLocation ($2), "; expected");
5686 lexer.putback ('}');
5690 interactive_expression_statement
5691 : interactive_statement_expression SEMICOLON { $$ = $1; }
5692 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5696 // We have to do the wrapping here and not in the case above,
5697 // because statement_expression is used for example in for_statement
5699 statement_expression
5702 ExpressionStatement s = $1 as ExpressionStatement;
5704 var expr = $1 as Expression;
5705 $$ = new StatementErrorExpression (expr);
5707 $$ = new StatementExpression (s);
5712 interactive_statement_expression
5715 Expression expr = (Expression) $1;
5716 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5720 Error_SyntaxError (yyToken);
5721 $$ = new EmptyStatement (GetLocation ($1));
5731 : IF open_parens_any boolean_expression CLOSE_PARENS
5734 if ($5 is EmptyStatement)
5735 Warning_EmptyStatement (GetLocation ($5));
5737 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5738 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5740 | IF open_parens_any boolean_expression CLOSE_PARENS
5741 embedded_statement ELSE embedded_statement
5743 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5744 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5746 if ($5 is EmptyStatement)
5747 Warning_EmptyStatement (GetLocation ($5));
5748 if ($7 is EmptyStatement)
5749 Warning_EmptyStatement (GetLocation ($7));
5751 | IF open_parens_any boolean_expression error
5753 Error_SyntaxError (yyToken);
5755 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5756 lbag.AddStatement ($$, GetLocation ($2));
5761 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5763 start_block (GetLocation ($5));
5765 opt_switch_sections CLOSE_BRACE
5767 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5768 end_block (GetLocation ($8));
5769 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5771 | SWITCH open_parens_any expression error
5773 Error_SyntaxError (yyToken);
5775 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5776 lbag.AddStatement ($$, GetLocation ($2));
5783 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5790 | switch_sections switch_section
5793 Error_SyntaxError (yyToken);
5798 : switch_labels statement_list
5804 var label = (SwitchLabel) $1;
5805 label.SectionStart = true;
5806 current_block.AddStatement (label);
5808 | switch_labels switch_label
5810 current_block.AddStatement ((Statement) $2);
5815 : CASE constant_expression COLON
5817 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5818 lbag.AddLocation ($$, GetLocation ($3));
5820 | CASE constant_expression error
5822 Error_SyntaxError (yyToken);
5823 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5825 | CASE pattern_expr_invocation COLON
5827 if (lang_version != LanguageVersion.Experimental)
5828 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
5830 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
5831 PatternMatching = true
5833 lbag.AddLocation ($$, GetLocation ($3));
5837 $$ = new SwitchLabel (null, GetLocation ($1));
5849 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5851 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5852 Warning_EmptyStatement (GetLocation ($5));
5854 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5855 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5857 | WHILE open_parens_any boolean_expression error
5859 Error_SyntaxError (yyToken);
5861 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5862 lbag.AddStatement ($$, GetLocation ($2));
5867 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5869 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5870 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5872 | DO embedded_statement error
5874 Error_SyntaxError (yyToken);
5875 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5877 | DO embedded_statement WHILE open_parens_any boolean_expression error
5879 Error_SyntaxError (yyToken);
5881 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5882 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5887 : FOR open_parens_any
5889 start_block (GetLocation ($2));
5890 current_block.IsCompilerGenerated = true;
5891 For f = new For (GetLocation ($1));
5892 current_block.AddStatement (f);
5901 // Has to use be extra rule to recover started block
5903 : opt_for_initializer SEMICOLON
5905 ((For) $0).Initializer = (Statement) $1;
5907 // Pass the "For" object to the iterator_part4
5908 oob_stack.Push ($0);
5910 for_condition_and_iterator_part
5913 var locations = (Tuple<Location,Location>) $4;
5915 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5916 Warning_EmptyStatement (GetLocation ($5));
5919 f.Statement = (Statement) $5;
5920 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5922 $$ = end_block (GetLocation ($2));
5926 Error_SyntaxError (yyToken);
5927 $$ = end_block (current_block.StartLocation);
5931 for_condition_and_iterator_part
5932 : opt_for_condition SEMICOLON
5934 For f = (For) oob_stack.Peek ();
5935 f.Condition = (BooleanExpression) $1;
5938 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5941 // Handle errors in the case of opt_for_condition being followed by
5942 // a close parenthesis
5943 | opt_for_condition close_parens_close_brace {
5944 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5945 For f = (For) oob_stack.Peek ();
5946 f.Condition = (BooleanExpression) $1;
5947 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5952 : opt_for_iterator CLOSE_PARENS {
5953 For f = (For) oob_stack.Peek ();
5954 f.Iterator = (Statement) $1;
5955 $$ = GetLocation ($2);
5957 | opt_for_iterator CLOSE_BRACE {
5958 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5959 For f = (For) oob_stack.Peek ();
5960 f.Iterator = (Statement) $1;
5961 $$ = GetLocation ($2);
5965 close_parens_close_brace
5967 | CLOSE_BRACE { lexer.putback ('}'); }
5971 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5976 : variable_type identifier_inside_body
5978 var lt = (LocatedToken) $2;
5979 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5980 current_block.AddLocalName (li);
5981 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5983 opt_local_variable_initializer opt_variable_declarators
5985 $$ = current_variable;
5987 lbag.AddLocation (current_variable, PopLocation ());
5989 current_variable = null;
5991 | statement_expression_list
5995 : /* empty */ { $$ = null; }
5996 | boolean_expression
6000 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6005 : statement_expression_list
6008 statement_expression_list
6009 : statement_expression
6010 | statement_expression_list COMMA statement_expression
6012 var sl = $1 as StatementList;
6014 sl = new StatementList ((Statement) $1, (Statement) $3);
6015 lbag.AddStatement (sl, GetLocation ($2));
6017 sl.Add ((Statement) $3);
6018 lbag.AppendTo (sl, GetLocation ($2));
6026 : FOREACH open_parens_any type error
6028 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6030 start_block (GetLocation ($2));
6031 current_block.IsCompilerGenerated = true;
6033 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6034 current_block.AddStatement (f);
6036 lbag.AddStatement (f, GetLocation ($2));
6037 $$ = end_block (GetLocation ($4));
6039 | FOREACH open_parens_any type identifier_inside_body error
6041 Error_SyntaxError (yyToken);
6043 start_block (GetLocation ($2));
6044 current_block.IsCompilerGenerated = true;
6046 var lt = (LocatedToken) $4;
6047 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6048 current_block.AddLocalName (li);
6050 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6051 current_block.AddStatement (f);
6053 lbag.AddStatement (f, GetLocation ($2));
6054 $$ = end_block (GetLocation ($5));
6056 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6058 start_block (GetLocation ($2));
6059 current_block.IsCompilerGenerated = true;
6061 var lt = (LocatedToken) $4;
6062 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6063 current_block.AddLocalName (li);
6068 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6069 Warning_EmptyStatement (GetLocation ($9));
6071 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6072 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6073 end_block (GetLocation ($7));
6081 | continue_statement
6091 $$ = new Break (GetLocation ($1));
6092 lbag.AddStatement ($$, GetLocation ($2));
6097 : CONTINUE SEMICOLON
6099 $$ = new Continue (GetLocation ($1));
6100 lbag.AddStatement ($$, GetLocation ($2));
6104 Error_SyntaxError (yyToken);
6105 $$ = new Continue (GetLocation ($1));
6110 : GOTO identifier_inside_body SEMICOLON
6112 var lt = (LocatedToken) $2;
6113 $$ = new Goto (lt.Value, GetLocation ($1));
6114 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6116 | GOTO CASE constant_expression SEMICOLON
6118 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6119 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6121 | GOTO DEFAULT SEMICOLON
6123 $$ = new GotoDefault (GetLocation ($1));
6124 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6129 : RETURN opt_expression SEMICOLON
6131 $$ = new Return ((Expression) $2, GetLocation ($1));
6132 lbag.AddStatement ($$, GetLocation ($3));
6134 | RETURN expression error
6136 Error_SyntaxError (yyToken);
6137 $$ = new Return ((Expression) $2, GetLocation ($1));
6141 Error_SyntaxError (yyToken);
6142 $$ = new Return (null, GetLocation ($1));
6147 : THROW opt_expression SEMICOLON
6149 $$ = new Throw ((Expression) $2, GetLocation ($1));
6150 lbag.AddStatement ($$, GetLocation ($3));
6152 | THROW expression error
6154 Error_SyntaxError (yyToken);
6155 $$ = new Throw ((Expression) $2, GetLocation ($1));
6159 Error_SyntaxError (yyToken);
6160 $$ = new Throw (null, GetLocation ($1));
6165 : identifier_inside_body RETURN opt_expression SEMICOLON
6167 var lt = (LocatedToken) $1;
6168 string s = lt.Value;
6170 report.Error (1003, lt.Location, "; expected");
6171 } else if ($3 == null) {
6172 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6173 } else if (lang_version == LanguageVersion.ISO_1){
6174 FeatureIsNotAvailable (lt.Location, "iterators");
6177 current_block.Explicit.RegisterIteratorYield ();
6178 $$ = new Yield ((Expression) $3, lt.Location);
6179 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6181 | identifier_inside_body RETURN expression error
6183 Error_SyntaxError (yyToken);
6185 var lt = (LocatedToken) $1;
6186 string s = lt.Value;
6188 report.Error (1003, lt.Location, "; expected");
6189 } else if ($3 == null) {
6190 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6191 } else if (lang_version == LanguageVersion.ISO_1){
6192 FeatureIsNotAvailable (lt.Location, "iterators");
6195 current_block.Explicit.RegisterIteratorYield ();
6196 $$ = new Yield ((Expression) $3, lt.Location);
6197 lbag.AddStatement ($$, GetLocation ($2));
6199 | identifier_inside_body BREAK SEMICOLON
6201 var lt = (LocatedToken) $1;
6202 string s = lt.Value;
6204 report.Error (1003, lt.Location, "; expected");
6205 } else if (lang_version == LanguageVersion.ISO_1){
6206 FeatureIsNotAvailable (lt.Location, "iterators");
6209 current_block.ParametersBlock.TopBlock.IsIterator = true;
6210 $$ = new YieldBreak (lt.Location);
6211 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6221 : TRY block catch_clauses
6223 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6225 | TRY block FINALLY block
6227 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6228 lbag.AddStatement ($$, GetLocation ($3));
6230 | TRY block catch_clauses FINALLY block
6232 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6233 lbag.AddStatement ($$, GetLocation ($4));
6237 Error_SyntaxError (1524, yyToken);
6238 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6245 var l = new List<Catch> (2);
6250 | catch_clauses catch_clause
6252 var l = (List<Catch>) $1;
6254 Catch c = (Catch) $2;
6255 var prev_catch = l [l.Count - 1];
6256 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6257 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6267 | identifier_inside_body
6271 : CATCH opt_catch_filter block
6273 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6274 c.Filter = (CatchFilterExpression) $2;
6277 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6279 start_block (GetLocation ($2));
6280 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6281 c.TypeExpression = (FullNamedExpression) $3;
6284 var lt = (LocatedToken) $4;
6285 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6286 current_block.AddLocalName (c.Variable);
6289 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6292 opt_catch_filter block_prepared
6294 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6297 | CATCH open_parens_any error
6299 if (yyToken == Token.CLOSE_PARENS) {
6300 report.Error (1015, lexer.Location,
6301 "A type that derives from `System.Exception', `object', or `string' expected");
6303 Error_SyntaxError (yyToken);
6306 $$ = new Catch (null, GetLocation ($1));
6308 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6310 Error_SyntaxError (yyToken);
6312 // Required otherwise missing block could not be detected because
6313 // start_block is run early
6314 var c = new Catch (null, GetLocation ($1));
6315 c.TypeExpression = (FullNamedExpression) $3;
6318 var lt = (LocatedToken) $4;
6319 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6322 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6330 | IF open_parens_any expression CLOSE_PARENS
6332 if (lang_version <= LanguageVersion.V_5)
6333 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6335 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6336 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6343 $$ = new Checked ((Block) $2, GetLocation ($1));
6350 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6357 if (!settings.Unsafe)
6358 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6360 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6365 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6367 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6368 Warning_EmptyStatement (GetLocation ($5));
6370 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6371 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6373 | LOCK open_parens_any expression error
6375 Error_SyntaxError (yyToken);
6377 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6378 lbag.AddStatement ($$, GetLocation ($2));
6383 : FIXED open_parens_any variable_type identifier_inside_body
6385 start_block (GetLocation ($2));
6387 current_block.IsCompilerGenerated = true;
6388 var lt = (LocatedToken) $4;
6389 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6390 current_block.AddLocalName (li);
6391 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6393 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6395 $$ = current_variable;
6396 current_variable = null;
6400 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6401 Warning_EmptyStatement (GetLocation ($10));
6403 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6404 current_block.AddStatement (f);
6405 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6406 $$ = end_block (GetLocation ($8));
6411 : USING open_parens_any variable_type identifier_inside_body
6413 start_block (GetLocation ($2));
6415 current_block.IsCompilerGenerated = true;
6416 var lt = (LocatedToken) $4;
6417 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6418 current_block.AddLocalName (li);
6419 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6421 using_initialization CLOSE_PARENS
6423 $$ = current_variable;
6424 current_variable = null;
6428 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6429 Warning_EmptyStatement (GetLocation ($9));
6431 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6432 current_block.AddStatement (u);
6433 $$ = end_block (GetLocation ($7));
6435 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6437 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6438 Warning_EmptyStatement (GetLocation ($5));
6440 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6441 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6443 | USING open_parens_any expression error
6445 Error_SyntaxError (yyToken);
6447 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6448 lbag.AddStatement ($$, GetLocation ($2));
6452 using_initialization
6453 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6456 // It has to be here for the parent to safely restore artificial block
6457 Error_SyntaxError (yyToken);
6461 using_or_fixed_variable_initializer
6464 Error_MissingInitializer (lexer.Location);
6466 | ASSIGN variable_initializer
6468 current_variable.Initializer = (Expression) $2;
6469 $$ = current_variable;
6477 : first_from_clause query_body
6479 lexer.query_parsing = false;
6481 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6483 from.Tail.Next = (Linq.AQueryClause)$2;
6486 current_block.SetEndLocation (lexer.Location);
6487 current_block = current_block.Parent;
6489 | nested_from_clause query_body
6491 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6493 from.Tail.Next = (Linq.AQueryClause)$2;
6496 current_block.SetEndLocation (lexer.Location);
6497 current_block = current_block.Parent;
6500 // Bubble up COMPLETE_COMPLETION productions
6501 | first_from_clause COMPLETE_COMPLETION {
6502 lexer.query_parsing = false;
6505 current_block.SetEndLocation (lexer.Location);
6506 current_block = current_block.Parent;
6508 | nested_from_clause COMPLETE_COMPLETION {
6510 current_block.SetEndLocation (lexer.Location);
6511 current_block = current_block.Parent;
6516 : FROM_FIRST identifier_inside_body IN expression
6518 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6520 var lt = (LocatedToken) $2;
6521 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6522 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6523 lbag.AddLocation (clause, GetLocation ($3));
6524 $$ = new Linq.QueryExpression (clause);
6526 | FROM_FIRST type identifier_inside_body IN expression
6528 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6530 var lt = (LocatedToken) $3;
6531 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6532 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6533 IdentifierType = (FullNamedExpression)$2
6535 lbag.AddLocation (clause, GetLocation ($4));
6536 $$ = new Linq.QueryExpression (clause);
6541 : FROM identifier_inside_body IN expression
6543 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6545 var lt = (LocatedToken) $2;
6546 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6547 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6548 lbag.AddLocation (clause, GetLocation ($3));
6549 $$ = new Linq.QueryExpression (clause);
6551 | FROM type identifier_inside_body IN expression
6553 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6555 var lt = (LocatedToken) $3;
6556 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6557 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6558 IdentifierType = (FullNamedExpression)$2
6560 lbag.AddLocation (clause, GetLocation ($4));
6561 $$ = new Linq.QueryExpression (clause);
6566 : FROM identifier_inside_body IN
6568 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6572 var lt = (LocatedToken) $2;
6573 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6574 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6576 current_block.SetEndLocation (lexer.Location);
6577 current_block = current_block.Parent;
6579 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6580 lbag.AddLocation ($$, GetLocation ($3));
6582 | FROM type identifier_inside_body IN
6584 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6588 var lt = (LocatedToken) $3;
6589 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6591 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6592 IdentifierType = (FullNamedExpression)$2
6595 current_block.SetEndLocation (lexer.Location);
6596 current_block = current_block.Parent;
6598 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6600 lbag.AddLocation ($$, GetLocation ($4));
6605 : query_body_clauses select_or_group_clause opt_query_continuation
6607 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6610 head.Next = (Linq.AQueryClause)$3;
6613 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6614 clause.Tail.Next = head;
6620 | select_or_group_clause opt_query_continuation
6622 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6625 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6626 clause.Tail.Next = head;
6632 | query_body_clauses COMPLETE_COMPLETION
6633 | query_body_clauses error
6635 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6640 Error_SyntaxError (yyToken);
6645 select_or_group_clause
6648 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6652 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6654 current_block.SetEndLocation (lexer.Location);
6655 current_block = current_block.Parent;
6659 if (linq_clause_blocks == null)
6660 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6662 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6663 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6667 current_block.SetEndLocation (lexer.Location);
6668 current_block = current_block.Parent;
6670 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6674 var obj = (object[]) $5;
6676 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6677 lbag.AddLocation ($$, (Location) obj[1]);
6679 current_block.SetEndLocation (lexer.Location);
6680 current_block = current_block.Parent;
6685 : BY expression_or_error
6687 $$ = new object[] { $2, GetLocation ($1) };
6691 Error_SyntaxError (yyToken);
6692 $$ = new object[2] { null, Location.Null };
6698 | query_body_clauses query_body_clause
6700 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6714 : LET identifier_inside_body ASSIGN
6716 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6720 var lt = (LocatedToken) $2;
6721 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6722 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6723 lbag.AddLocation ($$, GetLocation ($3));
6725 current_block.SetEndLocation (lexer.Location);
6726 current_block = current_block.Parent;
6728 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6735 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6739 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6741 current_block.SetEndLocation (lexer.Location);
6742 current_block = current_block.Parent;
6747 : JOIN identifier_inside_body IN
6749 if (linq_clause_blocks == null)
6750 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6752 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6753 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6755 expression_or_error ON
6757 current_block.SetEndLocation (lexer.Location);
6758 current_block = current_block.Parent;
6760 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6761 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6763 expression_or_error EQUALS
6765 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6766 current_block.SetEndLocation (lexer.Location);
6767 current_block = current_block.Parent;
6769 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6771 expression_or_error opt_join_into
6773 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6774 current_block.SetEndLocation (lexer.Location);
6776 var outer_selector = linq_clause_blocks.Pop ();
6777 var block = linq_clause_blocks.Pop ();
6779 var lt = (LocatedToken) $2;
6780 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6781 Linq.RangeVariable into;
6785 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6786 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6789 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6791 var parent = block.Parent;
6792 while (parent is Linq.QueryBlock) {
6793 parent = parent.Parent;
6795 current_block.Parent = parent;
6797 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6799 lt = (LocatedToken) $12;
6800 into = new Linq.RangeVariable (lt.Value, lt.Location);
6802 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6803 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6806 current_block = block.Parent;
6807 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6809 | JOIN type identifier_inside_body IN
6811 if (linq_clause_blocks == null)
6812 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6814 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6815 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6817 expression_or_error ON
6819 current_block.SetEndLocation (lexer.Location);
6820 current_block = current_block.Parent;
6822 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6823 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6825 expression_or_error EQUALS
6827 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6828 current_block.SetEndLocation (lexer.Location);
6829 current_block = current_block.Parent;
6831 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6833 expression_or_error opt_join_into
6835 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6836 current_block.SetEndLocation (lexer.Location);
6838 var outer_selector = linq_clause_blocks.Pop ();
6839 var block = linq_clause_blocks.Pop ();
6841 var lt = (LocatedToken) $3;
6842 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6843 Linq.RangeVariable into;
6847 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6848 IdentifierType = (FullNamedExpression)$2
6850 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6853 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6855 var parent = block.Parent;
6856 while (parent is Linq.QueryBlock) {
6857 parent = parent.Parent;
6859 current_block.Parent = parent;
6861 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6863 lt = (LocatedToken) $13;
6864 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6866 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6867 IdentifierType = (FullNamedExpression)$2
6871 current_block = block.Parent;
6872 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6878 | INTO identifier_inside_body
6887 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6891 current_block.SetEndLocation (lexer.Location);
6892 current_block = current_block.Parent;
6902 current_block.SetEndLocation (lexer.Location);
6903 current_block = current_block.Parent;
6905 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6909 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6916 | orderings_then_by COMMA
6918 current_block.SetEndLocation (lexer.Location);
6919 current_block = current_block.Parent;
6921 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6925 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6933 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6935 | expression ASCENDING
6937 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6938 lbag.AddLocation ($$, GetLocation ($2));
6940 | expression DESCENDING
6942 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6943 lbag.AddLocation ($$, GetLocation ($2));
6950 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6952 | expression ASCENDING
6954 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6955 lbag.AddLocation ($$, GetLocation ($2));
6957 | expression DESCENDING
6959 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6960 lbag.AddLocation ($$, GetLocation ($2));
6965 opt_query_continuation
6967 | INTO identifier_inside_body
6969 // query continuation block is not linked with query block but with block
6970 // before. This means each query can use same range variable names for
6971 // different identifiers.
6973 current_block.SetEndLocation (GetLocation ($1));
6974 current_block = current_block.Parent;
6976 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6978 if (linq_clause_blocks == null)
6979 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6981 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6985 var current_block = linq_clause_blocks.Pop ();
6986 var lt = (LocatedToken) $2;
6987 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6988 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6989 next = (Linq.AQueryClause)$4
6995 // Support for using the compiler as an interactive parser
6997 // The INTERACTIVE_PARSER token is first sent to parse our
6998 // productions; If the result is a Statement, the parsing
6999 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7000 // to setup the blocks in advance.
7002 // This setup is here so that in the future we can add
7003 // support for other constructs (type parsing, namespaces, etc)
7004 // that do not require a block to be setup in advance
7008 : EVAL_STATEMENT_PARSER EOF
7009 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7010 | EVAL_STATEMENT_PARSER
7012 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7014 // (ref object retval)
7015 Parameter [] mpar = new Parameter [1];
7016 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7018 ParametersCompiled pars = new ParametersCompiled (mpar);
7019 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7020 if (settings.Unsafe)
7021 mods |= Modifiers.UNSAFE;
7023 current_local_parameters = pars;
7024 var method = new InteractiveMethod (
7026 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7030 current_type.AddMember (method);
7031 oob_stack.Push (method);
7033 interactive_async = false;
7035 ++lexer.parsing_block;
7036 start_block (lexer.Location);
7038 interactive_statement_list opt_COMPLETE_COMPLETION
7040 --lexer.parsing_block;
7041 var method = (InteractiveMethod) oob_stack.Pop ();
7042 method.Block = (ToplevelBlock) end_block(lexer.Location);
7044 if (interactive_async == true) {
7045 method.ChangeToAsync ();
7048 InteractiveResult = (Class) pop_current_class ();
7049 current_local_parameters = null;
7051 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7054 interactive_compilation_unit
7055 : opt_extern_alias_directives opt_using_directives
7056 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7059 opt_COMPLETE_COMPLETION
7061 | COMPLETE_COMPLETION
7064 close_brace_or_complete_completion
7066 | COMPLETE_COMPLETION
7070 // XML documentation code references micro parser
7072 documentation_parsing
7075 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7080 : doc_type_declaration_name opt_doc_method_sig
7082 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7084 | builtin_types opt_doc_method_sig
7086 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7087 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7090 | VOID opt_doc_method_sig
7092 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7093 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7096 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7098 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7099 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7100 var lt = (LocatedToken) $3;
7101 $$ = new MemberName (lt.Value);
7103 | doc_type_declaration_name DOT THIS
7105 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7107 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7109 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7111 opt_doc_parameters CLOSE_BRACKET
7113 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7114 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7116 | EXPLICIT OPERATOR type opt_doc_method_sig
7118 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7119 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7120 module.DocumentationBuilder.ParsedParameters = p;
7121 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7124 | IMPLICIT OPERATOR type opt_doc_method_sig
7126 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7127 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7128 module.DocumentationBuilder.ParsedParameters = p;
7129 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7132 | OPERATOR overloadable_operator opt_doc_method_sig
7134 var p = (List<DocumentationParameter>)$3;
7135 module.DocumentationBuilder.ParsedParameters = p;
7136 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7141 doc_type_declaration_name
7142 : type_declaration_name
7143 | doc_type_declaration_name DOT type_declaration_name
7145 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7153 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7155 opt_doc_parameters CLOSE_PARENS
7164 $$ = new List<DocumentationParameter> (0);
7172 var parameters = new List<DocumentationParameter> ();
7173 parameters.Add ((DocumentationParameter) $1);
7176 | doc_parameters COMMA doc_parameter
7178 var parameters = $1 as List<DocumentationParameter>;
7179 parameters.Add ((DocumentationParameter) $3);
7185 : opt_parameter_modifier parameter_type
7188 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7190 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7197 // A class used to hold info about an operator declarator
7199 class OperatorDeclaration {
7200 public readonly Operator.OpType optype;
7201 public readonly FullNamedExpression ret_type;
7202 public readonly Location location;
7204 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7207 this.ret_type = ret_type;
7208 this.location = location;
7212 void Error_ExpectingTypeName (Expression expr)
7214 if (expr is Invocation){
7215 report.Error (1002, expr.Location, "Expecting `;'");
7217 expr.Error_InvalidExpressionStatement (report);
7221 void Error_ParameterModifierNotValid (string modifier, Location loc)
7223 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7227 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7229 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7230 Parameter.GetModifierSignature (mod));
7233 void Error_TypeExpected (Location loc)
7235 report.Error (1031, loc, "Type expected");
7238 void Error_UnsafeCodeNotAllowed (Location loc)
7240 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7243 void Warning_EmptyStatement (Location loc)
7245 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7248 void Error_NamedArgumentExpected (NamedArgument a)
7250 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7253 void Error_MissingInitializer (Location loc)
7255 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7258 object Error_AwaitAsIdentifier (object token)
7261 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7262 return new LocatedToken ("await", GetLocation (token));
7268 void push_current_container (TypeDefinition tc, object partial_token)
7270 if (module.Evaluator != null){
7271 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7275 undo.AddTypeContainer (current_container, tc);
7278 if (partial_token != null)
7279 current_container.AddPartial (tc);
7281 current_container.AddTypeContainer (tc);
7283 ++lexer.parsing_declaration;
7284 current_container = tc;
7288 TypeContainer pop_current_class ()
7290 var retval = current_container;
7292 current_container = current_container.Parent;
7293 current_type = current_type.Parent as TypeDefinition;
7298 [System.Diagnostics.Conditional ("FULL_AST")]
7299 void StoreModifierLocation (object token, Location loc)
7304 if (mod_locations == null)
7305 mod_locations = new List<Tuple<Modifiers, Location>> ();
7307 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7310 [System.Diagnostics.Conditional ("FULL_AST")]
7311 void PushLocation (Location loc)
7313 if (location_stack == null)
7314 location_stack = new Stack<Location> ();
7316 location_stack.Push (loc);
7319 Location PopLocation ()
7321 if (location_stack == null)
7322 return Location.Null;
7324 return location_stack.Pop ();
7327 string CheckAttributeTarget (int token, string a, Location l)
7330 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7334 if (!Tokenizer.IsValidIdentifier (a)) {
7335 Error_SyntaxError (token);
7337 report.Warning (658, 1, l,
7338 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7341 return string.Empty;
7344 static bool IsUnaryOperator (Operator.OpType op)
7348 case Operator.OpType.LogicalNot:
7349 case Operator.OpType.OnesComplement:
7350 case Operator.OpType.Increment:
7351 case Operator.OpType.Decrement:
7352 case Operator.OpType.True:
7353 case Operator.OpType.False:
7354 case Operator.OpType.UnaryPlus:
7355 case Operator.OpType.UnaryNegation:
7361 void syntax_error (Location l, string msg)
7363 report.Error (1003, l, "Syntax error, " + msg);
7368 public Tokenizer Lexer {
7374 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7375 : this (reader, file, file.Compiler.Report, session)
7379 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7382 current_container = current_namespace = file;
7384 this.module = file.Module;
7385 this.compiler = file.Compiler;
7386 this.settings = compiler.Settings;
7387 this.report = report;
7389 lang_version = settings.Version;
7390 yacc_verbose_flag = settings.VerboseParserFlag;
7391 doc_support = settings.DocumentationFile != null;
7392 lexer = new Tokenizer (reader, file, session, report);
7393 oob_stack = new Stack<object> ();
7394 lbag = session.LocationsBag;
7395 use_global_stacks = session.UseJayGlobalArrays;
7396 parameters_bucket = session.ParametersStack;
7399 public void parse ()
7401 eof_token = Token.EOF;
7404 if (yacc_verbose_flag > 1)
7405 yyparse (lexer, new yydebug.yyDebugSimple ());
7409 Tokenizer tokenizer = lexer as Tokenizer;
7410 tokenizer.cleanup ();
7411 } catch (Exception e){
7412 if (e is yyParser.yyUnexpectedEof) {
7413 Error_SyntaxError (yyToken);
7414 UnexpectedEOF = true;
7418 if (e is yyParser.yyException) {
7419 if (report.Errors == 0)
7420 report.Error (-25, lexer.Location, "Parsing error");
7422 // Used by compiler-tester to test internal errors
7423 if (yacc_verbose_flag > 0 || e is FatalException)
7426 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7431 void CheckToken (int error, int yyToken, string msg, Location loc)
7433 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7434 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7436 report.Error (error, loc, msg);
7439 string ConsumeStoredComment ()
7441 string s = tmpComment;
7443 Lexer.doc_state = XmlCommentState.Allowed;
7447 void FeatureIsNotAvailable (Location loc, string feature)
7449 report.FeatureIsNotAvailable (compiler, loc, feature);
7452 Location GetLocation (object obj)
7454 var lt = obj as LocatedToken;
7458 var mn = obj as MemberName;
7462 var expr = obj as Expression;
7464 return expr.Location;
7466 return lexer.Location;
7469 void start_block (Location loc)
7471 if (current_block == null) {
7472 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7473 parsing_anonymous_method = false;
7474 } else if (parsing_anonymous_method) {
7475 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7476 parsing_anonymous_method = false;
7478 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7483 end_block (Location loc)
7485 Block retval = current_block.Explicit;
7486 retval.SetEndLocation (loc);
7487 current_block = retval.Parent;
7491 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7493 oob_stack.Push (current_anonymous_method);
7494 oob_stack.Push (current_local_parameters);
7495 oob_stack.Push (current_variable);
7496 oob_stack.Push (async_block);
7498 current_local_parameters = parameters;
7500 if (lang_version <= LanguageVersion.ISO_2)
7501 FeatureIsNotAvailable (loc, "lambda expressions");
7503 current_anonymous_method = new LambdaExpression (loc);
7505 if (lang_version == LanguageVersion.ISO_1)
7506 FeatureIsNotAvailable (loc, "anonymous methods");
7508 current_anonymous_method = new AnonymousMethodExpression (loc);
7511 async_block = isAsync;
7512 // Force the next block to be created as a ToplevelBlock
7513 parsing_anonymous_method = true;
7517 * Completes the anonymous method processing, if lambda_expr is null, this
7518 * means that we have a Statement instead of an Expression embedded
7520 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7522 AnonymousMethodExpression retval;
7525 anon_block.IsAsync = true;
7527 current_anonymous_method.Block = anon_block;
7528 retval = current_anonymous_method;
7530 async_block = (bool) oob_stack.Pop ();
7531 current_variable = (BlockVariable) oob_stack.Pop ();
7532 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7533 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7538 void Error_SyntaxError (int token)
7540 Error_SyntaxError (0, token);
7543 void Error_SyntaxError (int error_code, int token)
7545 Error_SyntaxError (error_code, token, "Unexpected symbol");
7548 void Error_SyntaxError (int error_code, int token, string msg)
7550 Lexer.CompleteOnEOF = false;
7552 // An error message has been reported by tokenizer
7553 if (token == Token.ERROR)
7556 // Avoid duplicit error message after unterminated string literals
7557 if (token == Token.LITERAL && lexer.Location.Column == 0)
7560 string symbol = GetSymbolName (token);
7561 string expecting = GetExpecting ();
7562 var loc = lexer.Location - symbol.Length;
7564 if (error_code == 0) {
7565 if (expecting == "`identifier'") {
7566 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7567 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7572 expecting = "identifier";
7573 } else if (expecting == "`)'") {
7580 if (string.IsNullOrEmpty (expecting))
7581 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7583 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7586 string GetExpecting ()
7588 int [] tokens = yyExpectingTokens (yyExpectingState);
7589 var names = new List<string> (tokens.Length);
7590 bool has_type = false;
7591 bool has_identifier = false;
7592 for (int i = 0; i < tokens.Length; i++){
7593 int token = tokens [i];
7594 has_identifier |= token == Token.IDENTIFIER;
7596 string name = GetTokenName (token);
7597 if (name == "<internal>")
7600 has_type |= name == "type";
7601 if (names.Contains (name))
7608 // Too many tokens to enumerate
7610 if (names.Count > 8)
7613 if (has_type && has_identifier)
7614 names.Remove ("identifier");
7616 if (names.Count == 1)
7617 return "`" + GetTokenName (tokens [0]) + "'";
7619 StringBuilder sb = new StringBuilder ();
7621 int count = names.Count;
7622 for (int i = 0; i < count; i++){
7623 bool last = i + 1 == count;
7627 sb.Append (names [i]);
7628 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7630 return sb.ToString ();
7634 string GetSymbolName (int token)
7638 return ((Constant)lexer.Value).GetValue ().ToString ();
7639 case Token.IDENTIFIER:
7640 return ((LocatedToken)lexer.Value).Value;
7682 case Token.BITWISE_AND:
7684 case Token.BITWISE_OR:
7698 case Token.OP_SHIFT_LEFT:
7700 case Token.OP_SHIFT_RIGHT:
7720 case Token.OP_COALESCING:
7722 case Token.OP_MULT_ASSIGN:
7724 case Token.OP_DIV_ASSIGN:
7726 case Token.OP_MOD_ASSIGN:
7728 case Token.OP_ADD_ASSIGN:
7730 case Token.OP_SUB_ASSIGN:
7732 case Token.OP_SHIFT_LEFT_ASSIGN:
7734 case Token.OP_SHIFT_RIGHT_ASSIGN:
7736 case Token.OP_AND_ASSIGN:
7738 case Token.OP_XOR_ASSIGN:
7740 case Token.OP_OR_ASSIGN:
7744 return GetTokenName (token);
7747 static string GetTokenName (int token)
7750 case Token.ABSTRACT:
7772 case Token.CONTINUE:
7776 case Token.DELEGATE:
7786 case Token.EXPLICIT:
7789 case Token.EXTERN_ALIAS:
7805 case Token.IMPLICIT:
7809 case Token.INTERFACE:
7811 case Token.INTERNAL:
7817 case Token.NAMESPACE:
7823 case Token.OPERATOR:
7827 case Token.OVERRIDE:
7833 case Token.PROTECTED:
7837 case Token.READONLY:
7849 case Token.STACKALLOC:
7850 return "stackalloc";
7867 case Token.UNCHECKED:
7875 case Token.VOLATILE:
7883 case Token.REFVALUE:
7884 return "__refvalue";
7894 case Token.FROM_FIRST:
7912 case Token.ASCENDING:
7914 case Token.DESCENDING:
7915 return "descending";
7922 case Token.OPEN_BRACE:
7924 case Token.CLOSE_BRACE:
7926 case Token.OPEN_BRACKET:
7927 case Token.OPEN_BRACKET_EXPR:
7929 case Token.CLOSE_BRACKET:
7931 case Token.OPEN_PARENS_CAST:
7932 case Token.OPEN_PARENS_LAMBDA:
7933 case Token.OPEN_PARENS:
7935 case Token.CLOSE_PARENS:
7941 case Token.DEFAULT_COLON:
7945 case Token.SEMICOLON:
7956 case Token.BITWISE_AND:
7957 case Token.BITWISE_OR:
7964 case Token.OP_SHIFT_LEFT:
7965 case Token.OP_SHIFT_RIGHT:
7973 case Token.OP_COALESCING:
7974 case Token.OP_MULT_ASSIGN:
7975 case Token.OP_DIV_ASSIGN:
7976 case Token.OP_MOD_ASSIGN:
7977 case Token.OP_ADD_ASSIGN:
7978 case Token.OP_SUB_ASSIGN:
7979 case Token.OP_SHIFT_LEFT_ASSIGN:
7980 case Token.OP_SHIFT_RIGHT_ASSIGN:
7981 case Token.OP_AND_ASSIGN:
7982 case Token.OP_XOR_ASSIGN:
7983 case Token.OP_OR_ASSIGN:
7984 case Token.INTERR_OPERATOR:
7985 return "<operator>";
8007 case Token.OP_GENERICS_LT:
8008 case Token.GENERIC_DIMENSION:
8010 case Token.OP_GENERICS_GT:
8013 case Token.INTERR_NULLABLE:
8015 case Token.DOUBLE_COLON:
8019 case Token.IDENTIFIER:
8021 return "identifier";
8024 return "end-of-file";
8026 // All of these are internal.
8029 case Token.FIRST_KEYWORD:
8030 case Token.EVAL_COMPILATION_UNIT_PARSER:
8031 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8032 case Token.EVAL_STATEMENT_PARSER:
8033 case Token.LAST_KEYWORD:
8034 case Token.GENERATE_COMPLETION:
8035 case Token.COMPLETE_COMPLETION:
8036 return "<internal>";
8038 // A bit more robust.
8040 return yyNames [token];