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 %token INTERPOLATED_STRING
263 %token INTERPOLATED_STRING_END
265 /* C# keywords which are not really keywords */
271 /* C# single character operators/punctuation. */
299 /* C# multi-character operators. */
304 %token OP_SHIFT_RIGHT
311 %token OP_MULT_ASSIGN
316 %token OP_SHIFT_LEFT_ASSIGN
317 %token OP_SHIFT_RIGHT_ASSIGN
324 /* Generics <,> tokens */
325 %token OP_GENERICS_LT
326 %token OP_GENERICS_LT_DECL
327 %token OP_GENERICS_GT
332 %token OPEN_PARENS_LAMBDA
333 %token OPEN_PARENS_CAST
334 %token GENERIC_DIMENSION
336 %token OPEN_BRACKET_EXPR
338 // Make the parser go into eval mode parsing (statements and compilation units).
339 %token EVAL_STATEMENT_PARSER
340 %token EVAL_COMPILATION_UNIT_PARSER
341 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
346 // This token is generated to trigger the completion engine at this point
348 %token GENERATE_COMPLETION
351 // This token is return repeatedly after the first GENERATE_COMPLETION
352 // token is produced and before the final EOF
354 %token COMPLETE_COMPLETION
356 /* Add precedence rules to solve dangling else s/r conflict */
360 /* Define the operator tokens and their precedences */
368 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
370 %left STAR DIV PERCENT
371 %right BANG CARRET UMINUS
372 %nonassoc OP_INC OP_DEC
374 %left OPEN_BRACKET OPEN_BRACE
377 %start compilation_unit
381 : outer_declaration opt_EOF
383 Lexer.check_incorrect_doc_comment ();
385 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
386 | documentation_parsing
390 : opt_extern_alias_directives opt_using_directives
391 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
394 Attributes attrs = (Attributes) $4;
395 report.Error (1730, attrs.Attrs [0].Location,
396 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
398 current_namespace.UnattachedAttributes = attrs;
401 | opt_extern_alias_directives opt_using_directives attribute_sections
403 module.AddAttributes ((Attributes) $3, current_namespace);
407 if (yyToken == Token.EXTERN_ALIAS)
408 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
410 Error_SyntaxError (yyToken);
419 extern_alias_directives
420 : extern_alias_directive
421 | extern_alias_directives extern_alias_directive
424 extern_alias_directive
425 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
427 var lt = (LocatedToken) $2;
430 syntax_error (lt.Location, "`alias' expected");
432 if (lang_version == LanguageVersion.ISO_1)
433 FeatureIsNotAvailable (lt.Location, "external alias");
435 lt = (LocatedToken) $3;
436 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
437 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
440 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
441 current_namespace.AddUsing (na);
443 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
448 Error_SyntaxError (yyToken);
454 | using_directives using_directive
461 Lexer.doc_state = XmlCommentState.Allowed;
466 : USING opt_static namespace_or_type_expr SEMICOLON
470 if (lang_version <= LanguageVersion.V_5)
471 FeatureIsNotAvailable (GetLocation ($2), "using static");
473 uc = new UsingType ((ATypeNameExpression) $3, GetLocation ($1));
474 lbag.AddLocation (uc, GetLocation ($2), GetLocation ($4));
476 uc = new UsingNamespace ((ATypeNameExpression) $3, GetLocation ($1));
477 lbag.AddLocation (uc, GetLocation ($4));
480 current_namespace.AddUsing (uc);
482 | USING opt_static IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
484 var lt = (LocatedToken) $3;
485 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
486 report.Warning (440, 2, lt.Location,
487 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
491 report.Error (8085, GetLocation ($2), "A `using static' directive cannot be used to declare an alias");
494 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $5, GetLocation ($1));
495 current_namespace.AddUsing (un);
497 lbag.AddLocation (un, GetLocation ($4), GetLocation ($6));
501 Error_SyntaxError (yyToken);
512 // Strictly speaking, namespaces don't have attributes but
513 // we parse global attributes along with namespace declarations and then
516 namespace_declaration
517 : opt_attributes NAMESPACE namespace_name
519 Attributes attrs = (Attributes) $1;
520 var name = (MemberName) $3;
522 bool valid_global_attrs = true;
523 if ((current_namespace.DeclarationFound || current_namespace != file)) {
524 valid_global_attrs = false;
526 foreach (var a in attrs.Attrs) {
527 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
530 valid_global_attrs = false;
535 if (!valid_global_attrs)
536 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
539 module.AddAttributes (attrs, current_namespace);
541 var ns = new NamespaceContainer (name, current_namespace);
542 current_namespace.AddTypeContainer (ns);
543 current_container = current_namespace = ns;
548 Lexer.doc_state = XmlCommentState.Allowed;
550 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
553 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
555 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
557 current_container = current_namespace = current_namespace.Parent;
559 | opt_attributes NAMESPACE namespace_name
561 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
563 var name = (MemberName) $3;
564 var ns = new NamespaceContainer (name, current_namespace);
565 lbag.AddLocation (ns, GetLocation ($2));
566 current_namespace.AddTypeContainer (ns);
575 Error_SyntaxError (yyToken);
583 var lt = (LocatedToken) $1;
584 $$ = new MemberName (lt.Value, lt.Location);
586 | namespace_name DOT IDENTIFIER
588 var lt = (LocatedToken) $3;
589 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
590 lbag.AddLocation ($$, GetLocation ($2));
594 Error_SyntaxError (yyToken);
595 $$ = new MemberName ("<invalid>", lexer.Location);
614 opt_extern_alias_directives
616 | extern_alias_directives
619 opt_namespace_or_type_declarations
621 | namespace_or_type_declarations
624 namespace_or_type_declarations
625 : namespace_or_type_declaration
626 | namespace_or_type_declarations namespace_or_type_declaration
629 namespace_or_type_declaration
633 TypeContainer ds = (TypeContainer)$1;
635 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
636 report.Error (1527, ds.Location,
637 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
640 // Here is a trick, for explicit attributes we don't know where they belong to until
641 // we parse succeeding declaration hence we parse them as normal and re-attach them
642 // when we know whether they are global (assembly:, module:) or local (type:).
643 if (ds.OptAttributes != null) {
644 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
647 current_namespace.DeclarationFound = true;
649 | namespace_declaration
651 current_namespace.DeclarationFound = true;
653 | attribute_sections CLOSE_BRACE {
654 current_namespace.UnattachedAttributes = (Attributes) $1;
655 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
663 | interface_declaration
665 | delegate_declaration
667 // Enable this when we have handled all errors, because this acts as a generic fallback
670 // Console.WriteLine ("Token=" + yyToken);
671 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
687 var sect = (List<Attribute>) $1;
688 $$ = new Attributes (sect);
690 | attribute_sections attribute_section
692 Attributes attrs = $1 as Attributes;
693 var sect = (List<Attribute>) $2;
695 attrs = new Attributes (sect);
696 else if (sect != null)
697 attrs.AddAttributes (sect);
705 PushLocation (GetLocation ($1));
706 lexer.parsing_attribute_section = true;
708 attribute_section_cont
710 lexer.parsing_attribute_section = false;
715 attribute_section_cont
716 : attribute_target COLON
718 current_attr_target = (string) $1;
719 if (current_attr_target == "assembly" || current_attr_target == "module") {
720 Lexer.check_incorrect_doc_comment ();
723 attribute_list opt_comma CLOSE_BRACKET
725 // when attribute target is invalid
726 if (current_attr_target == string.Empty)
727 $$ = new List<Attribute> (0);
731 lbag.InsertLocation ($$, 0, PopLocation ());
733 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
735 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
738 current_attr_target = null;
739 lexer.parsing_attribute_section = false;
741 | attribute_list opt_comma CLOSE_BRACKET
745 lbag.InsertLocation ($$, 0, PopLocation ());
747 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
749 lbag.AddLocation ($$, GetLocation($3));
754 Error_SyntaxError (yyToken);
756 var lt = (LocatedToken) $1;
757 var tne = new SimpleName (lt.Value, null, lt.Location);
759 $$ = new List<Attribute> () {
760 new Attribute (null, tne, null, GetLocation ($1), false)
765 if (CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1)).Length > 0)
766 Error_SyntaxError (yyToken);
775 var lt = (LocatedToken) $1;
776 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
778 | EVENT { $$ = "event"; }
779 | RETURN { $$ = "return"; }
785 $$ = new List<Attribute> (4) { (Attribute) $1 };
787 | attribute_list COMMA attribute
789 var attrs = (List<Attribute>) $1;
791 attrs.Add ((Attribute) $3);
792 lbag.AppendTo (attrs, GetLocation ($2));
802 ++lexer.parsing_block;
804 opt_attribute_arguments
806 --lexer.parsing_block;
808 var tne = (ATypeNameExpression) $1;
809 if (tne.HasTypeArguments) {
810 report.Error (404, tne.Location, "Attributes cannot be generic");
813 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
818 : namespace_or_type_expr
821 opt_attribute_arguments
822 : /* empty */ { $$ = null; }
823 | OPEN_PARENS attribute_arguments CLOSE_PARENS
831 : /* empty */ { $$ = null; }
832 | positional_or_named_argument
834 Arguments a = new Arguments (4);
835 a.Add ((Argument) $1);
836 $$ = new Arguments [] { a, null };
838 | named_attribute_argument
840 Arguments a = new Arguments (4);
841 a.Add ((Argument) $1);
842 $$ = new Arguments [] { null, a };
844 | attribute_arguments COMMA positional_or_named_argument
846 Arguments[] o = (Arguments[]) $1;
848 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
849 o [0] = new Arguments (4);
852 Arguments args = ((Arguments) o [0]);
853 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
854 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
856 args.Add ((Argument) $3);
858 | attribute_arguments COMMA named_attribute_argument
860 Arguments[] o = (Arguments[]) $1;
862 o [1] = new Arguments (4);
865 ((Arguments) o [1]).Add ((Argument) $3);
869 positional_or_named_argument
872 $$ = new Argument ((Expression) $1);
877 Error_SyntaxError (yyToken);
882 named_attribute_argument
885 ++lexer.parsing_block;
889 --lexer.parsing_block;
890 var lt = (LocatedToken) $1;
891 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
892 lbag.AddLocation ($$, GetLocation($2));
897 : identifier_inside_body COLON opt_named_modifier named_argument_expr
899 if (lang_version <= LanguageVersion.V_3)
900 FeatureIsNotAvailable (GetLocation ($1), "named argument");
902 // Avoid boxing in common case (no modifier)
903 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
905 var lt = (LocatedToken) $1;
906 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
907 lbag.AddLocation ($$, GetLocation($2));
912 : expression_or_error
913 // | declaration_expression
917 : /* empty */ { $$ = null; }
920 $$ = Argument.AType.Ref;
924 $$ = Argument.AType.Out;
928 opt_class_member_declarations
930 | class_member_declarations
933 class_member_declarations
934 : class_member_declaration
936 lexer.parsing_modifiers = true;
937 lexer.parsing_block = 0;
939 | class_member_declarations class_member_declaration
941 lexer.parsing_modifiers = true;
942 lexer.parsing_block = 0;
946 class_member_declaration
947 : constant_declaration
950 | property_declaration
952 | indexer_declaration
953 | operator_declaration
954 | constructor_declaration
955 | primary_constructor_body
956 | destructor_declaration
958 | attributes_without_members
962 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
963 GetSymbolName (yyToken));
965 lexer.parsing_generic_declaration = false;
969 primary_constructor_body
972 current_local_parameters = current_type.PrimaryConstructorParameters;
973 if (current_local_parameters == null) {
974 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
975 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
978 ++lexer.parsing_block;
979 start_block (GetLocation ($1));
981 opt_statement_list block_end
983 current_local_parameters = null;
984 var t = current_type as ClassOrStruct;
986 var b = (ToplevelBlock) $4;
987 if (t.PrimaryConstructorBlock != null) {
988 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
990 t.PrimaryConstructorBlock = b;
1003 type_declaration_name
1005 lexer.ConstraintsParsing = true;
1006 valid_param_mod = ParameterModifierType.PrimaryConstructor;
1007 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1009 opt_primary_parameters
1011 opt_type_parameter_constraints_clauses
1013 valid_param_mod = 0;
1014 lexer.ConstraintsParsing = false;
1017 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
1020 current_container.SetConstraints ((List<Constraints>) $10);
1023 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1025 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1027 lexer.parsing_modifiers = true;
1032 Lexer.doc_state = XmlCommentState.Allowed;
1034 opt_class_member_declarations CLOSE_BRACE
1036 --lexer.parsing_declaration;
1038 Lexer.doc_state = XmlCommentState.Allowed;
1043 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1045 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1047 $$ = pop_current_class ();
1049 | opt_attributes opt_modifiers opt_partial STRUCT error
1051 Error_SyntaxError (yyToken);
1055 constant_declaration
1058 CONST type IDENTIFIER
1060 var lt = (LocatedToken) $5;
1061 var mod = (Modifiers) $2;
1062 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1063 current_type.AddMember (current_field);
1065 if ((mod & Modifiers.STATIC) != 0) {
1066 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1071 constant_initializer opt_constant_declarators SEMICOLON
1074 current_field.DocComment = Lexer.consume_doc_comment ();
1075 Lexer.doc_state = XmlCommentState.Allowed;
1078 current_field.Initializer = (ConstInitializer) $7;
1079 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1080 current_field = null;
1086 Error_SyntaxError (yyToken);
1088 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1092 opt_constant_declarators
1094 | constant_declarators
1097 constant_declarators
1098 : constant_declarator
1100 current_field.AddDeclarator ((FieldDeclarator) $1);
1102 | constant_declarators constant_declarator
1104 current_field.AddDeclarator ((FieldDeclarator) $2);
1109 : COMMA IDENTIFIER constant_initializer
1111 var lt = (LocatedToken) $2;
1112 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1113 lbag.AddLocation ($$, GetLocation ($1));
1117 constant_initializer
1120 ++lexer.parsing_block;
1122 constant_initializer_expr
1124 --lexer.parsing_block;
1125 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1129 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1134 constant_initializer_expr
1135 : constant_expression
1142 member_type IDENTIFIER
1144 lexer.parsing_generic_declaration = false;
1146 FullNamedExpression type = (FullNamedExpression) $3;
1147 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1148 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1150 var lt = (LocatedToken) $4;
1151 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1152 current_type.AddField (current_field);
1155 opt_field_initializer
1156 opt_field_declarators
1160 current_field.DocComment = Lexer.consume_doc_comment ();
1161 Lexer.doc_state = XmlCommentState.Allowed;
1164 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1166 current_field = null;
1170 FIXED simple_type IDENTIFIER
1172 if (lang_version < LanguageVersion.ISO_2)
1173 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1175 var lt = (LocatedToken) $5;
1176 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1177 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1179 current_type.AddField (current_field);
1181 fixed_field_size opt_fixed_field_declarators SEMICOLON
1184 current_field.DocComment = Lexer.consume_doc_comment ();
1185 Lexer.doc_state = XmlCommentState.Allowed;
1188 current_field.Initializer = (ConstInitializer) $7;
1189 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1191 current_field = null;
1195 FIXED simple_type error
1198 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1202 opt_field_initializer
1206 ++lexer.parsing_block;
1207 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1208 start_block (GetLocation ($1));
1210 variable_initializer
1212 --lexer.parsing_block;
1213 current_field.Initializer = (Expression) $3;
1214 lbag.AppendToMember (current_field, GetLocation ($1));
1215 end_block (lexer.Location);
1216 current_local_parameters = null;
1220 opt_field_declarators
1228 current_field.AddDeclarator ((FieldDeclarator) $1);
1230 | field_declarators field_declarator
1232 current_field.AddDeclarator ((FieldDeclarator) $2);
1239 var lt = (LocatedToken) $2;
1240 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1241 lbag.AddLocation ($$, GetLocation ($1));
1243 | COMMA IDENTIFIER ASSIGN
1245 ++lexer.parsing_block;
1247 variable_initializer
1249 --lexer.parsing_block;
1250 var lt = (LocatedToken) $2;
1251 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1252 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1256 opt_fixed_field_declarators
1258 | fixed_field_declarators
1261 fixed_field_declarators
1262 : fixed_field_declarator
1264 current_field.AddDeclarator ((FieldDeclarator) $1);
1266 | fixed_field_declarators fixed_field_declarator
1268 current_field.AddDeclarator ((FieldDeclarator) $2);
1272 fixed_field_declarator
1273 : COMMA IDENTIFIER fixed_field_size
1275 var lt = (LocatedToken) $2;
1276 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1277 lbag.AddLocation ($$, GetLocation ($1));
1284 ++lexer.parsing_block;
1286 expression CLOSE_BRACKET
1288 --lexer.parsing_block;
1289 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1290 lbag.AddLocation ($$, GetLocation ($4));
1292 | OPEN_BRACKET error
1294 report.Error (443, lexer.Location, "Value or constant expected");
1299 variable_initializer
1304 // It has to be here for the parent to safely restore artificial block
1305 Error_SyntaxError (yyToken);
1314 Lexer.doc_state = XmlCommentState.NotAllowed;
1316 // Was added earlier in the case of body being eof for full ast
1318 method_body_expression_block
1320 Method method = (Method) $1;
1321 method.Block = (ToplevelBlock) $3;
1322 async_block = false;
1324 if (method.Block == null) {
1325 method.ParameterInfo.CheckParameters (method);
1327 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1328 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1329 method.GetSignatureForError ());
1332 if (current_container.Kind == MemberKind.Interface) {
1333 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1334 method.GetSignatureForError ());
1338 current_local_parameters = null;
1341 Lexer.doc_state = XmlCommentState.Allowed;
1349 method_declaration_name OPEN_PARENS
1351 valid_param_mod = ParameterModifierType.All;
1353 opt_formal_parameter_list CLOSE_PARENS
1355 valid_param_mod = 0;
1356 MemberName name = (MemberName) $4;
1357 current_local_parameters = (ParametersCompiled) $7;
1359 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1360 name, current_local_parameters, (Attributes) $1);
1362 current_type.AddMember (method);
1364 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1367 method.DocComment = Lexer.consume_doc_comment ();
1369 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1373 lexer.ConstraintsParsing = true;
1375 opt_type_parameter_constraints_clauses
1377 lexer.ConstraintsParsing = false;
1380 var method = (Method) $9;
1381 method.SetConstraints ((List<Constraints>) $10);
1391 lexer.parsing_generic_declaration = true;
1393 method_declaration_name
1396 lexer.parsing_generic_declaration = false;
1397 valid_param_mod = ParameterModifierType.All;
1399 opt_formal_parameter_list CLOSE_PARENS
1401 lexer.ConstraintsParsing = true;
1403 opt_type_parameter_constraints_clauses
1405 lexer.ConstraintsParsing = false;
1406 valid_param_mod = 0;
1408 MemberName name = (MemberName) $6;
1409 current_local_parameters = (ParametersCompiled) $9;
1411 var modifiers = (Modifiers) $2;
1412 modifiers |= Modifiers.PARTIAL;
1414 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1415 modifiers, name, current_local_parameters, (Attributes) $1);
1417 current_type.AddMember (method);
1419 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1422 method.SetConstraints ((List<Constraints>) $12);
1425 method.DocComment = Lexer.consume_doc_comment ();
1427 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1428 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1434 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1436 MemberName name = (MemberName) $5;
1437 report.Error (1585, name.Location,
1438 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1440 var method = Method.Create (current_type, (FullNamedExpression) $3,
1441 0, name, (ParametersCompiled) $7, (Attributes) $1);
1443 current_type.AddMember (method);
1445 current_local_parameters = (ParametersCompiled) $7;
1448 method.DocComment = Lexer.consume_doc_comment ();
1455 method_declaration_name error
1457 Error_SyntaxError (yyToken);
1458 current_local_parameters = ParametersCompiled.Undefined;
1460 MemberName name = (MemberName) $4;
1461 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1462 name, current_local_parameters, (Attributes) $1);
1464 current_type.AddMember (method);
1467 method.DocComment = Lexer.consume_doc_comment ();
1473 method_body_expression_block
1480 | SEMICOLON { $$ = null; }
1486 if (lang_version < LanguageVersion.V_6) {
1487 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1490 ++lexer.parsing_block;
1491 start_block (GetLocation ($1));
1493 expression SEMICOLON
1495 lexer.parsing_block = 0;
1496 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1497 var b = end_block (GetLocation ($4));
1498 b.IsCompilerGenerated = true;
1503 opt_formal_parameter_list
1504 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1505 | formal_parameter_list
1508 formal_parameter_list
1511 var pars_list = (List<Parameter>) $1;
1512 $$ = new ParametersCompiled (pars_list.ToArray ());
1514 | fixed_parameters COMMA parameter_array
1516 var pars_list = (List<Parameter>) $1;
1517 pars_list.Add ((Parameter) $3);
1519 $$ = new ParametersCompiled (pars_list.ToArray ());
1521 | fixed_parameters COMMA arglist_modifier
1523 var pars_list = (List<Parameter>) $1;
1524 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1525 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1527 | parameter_array COMMA error
1530 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1532 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1534 | fixed_parameters COMMA parameter_array COMMA error
1537 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1539 var pars_list = (List<Parameter>) $1;
1540 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1542 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1544 | arglist_modifier COMMA error
1546 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1548 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1550 | fixed_parameters COMMA ARGLIST COMMA error
1552 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1554 var pars_list = (List<Parameter>) $1;
1555 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1557 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1561 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1565 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1569 Error_SyntaxError (yyToken);
1570 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1577 parameters_bucket.Clear ();
1578 Parameter p = (Parameter) $1;
1579 parameters_bucket.Add (p);
1581 default_parameter_used = p.HasDefaultValue;
1582 $$ = parameters_bucket;
1584 | fixed_parameters COMMA fixed_parameter
1586 var pars = (List<Parameter>) $1;
1587 Parameter p = (Parameter) $3;
1589 if (p.HasExtensionMethodModifier)
1590 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1591 else if (!p.HasDefaultValue && default_parameter_used)
1592 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1594 default_parameter_used |= p.HasDefaultValue;
1597 lbag.AddLocation (p, GetLocation ($2));
1606 opt_parameter_modifier
1608 identifier_inside_body
1610 var lt = (LocatedToken) $4;
1611 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1614 opt_parameter_modifier
1616 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1618 var lt = (LocatedToken) $4;
1619 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1620 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1622 | attribute_sections error
1624 Error_SyntaxError (yyToken);
1625 Location l = GetLocation ($2);
1626 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1629 opt_parameter_modifier
1633 Error_SyntaxError (yyToken);
1634 Location l = GetLocation ($4);
1635 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1638 opt_parameter_modifier
1640 identifier_inside_body
1643 ++lexer.parsing_block;
1647 --lexer.parsing_block;
1648 if (lang_version <= LanguageVersion.V_3) {
1649 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1652 Parameter.Modifier mod = (Parameter.Modifier) $2;
1653 if (mod != Parameter.Modifier.NONE) {
1655 case Parameter.Modifier.REF:
1656 case Parameter.Modifier.OUT:
1657 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1658 Parameter.GetModifierSignature (mod));
1661 case Parameter.Modifier.This:
1662 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1663 Parameter.GetModifierSignature (mod));
1666 throw new NotImplementedException (mod.ToString ());
1669 mod = Parameter.Modifier.NONE;
1672 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1673 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1675 var lt = (LocatedToken) $4;
1676 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1677 lbag.AddLocation ($$, GetLocation ($5));
1680 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1684 opt_parameter_modifier
1685 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1686 | parameter_modifiers
1690 : parameter_modifier
1694 | parameter_modifiers parameter_modifier
1696 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1697 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1698 if (((Parameter.Modifier)$1 & p2) == p2) {
1699 Error_DuplicateParameterModifier (lexer.Location, p2);
1701 switch (mod & ~Parameter.Modifier.This) {
1702 case Parameter.Modifier.REF:
1703 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1705 case Parameter.Modifier.OUT:
1706 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1709 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1720 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1721 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1723 $$ = Parameter.Modifier.REF;
1727 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1728 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1730 $$ = Parameter.Modifier.OUT;
1734 if ((valid_param_mod & ParameterModifierType.This) == 0)
1735 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1737 if (lang_version <= LanguageVersion.ISO_2)
1738 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1740 $$ = Parameter.Modifier.This;
1745 : opt_attributes params_modifier type IDENTIFIER
1747 var lt = (LocatedToken) $4;
1748 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1750 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1752 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1754 var lt = (LocatedToken) $4;
1755 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1757 | opt_attributes params_modifier type error
1759 Error_SyntaxError (yyToken);
1761 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1768 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1769 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1771 | PARAMS parameter_modifier
1773 Parameter.Modifier mod = (Parameter.Modifier)$2;
1774 if ((mod & Parameter.Modifier.This) != 0) {
1775 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1777 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1780 | PARAMS params_modifier
1782 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1789 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1790 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1794 property_declaration
1798 member_declaration_name
1800 lexer.parsing_generic_declaration = false;
1802 tmpComment = Lexer.consume_doc_comment ();
1806 var type = (FullNamedExpression) $3;
1807 current_property = new Property (current_type, type, (Modifiers) $2,
1808 (MemberName) $4, (Attributes) $1);
1810 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1811 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1813 current_type.AddMember (current_property);
1814 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1816 lexer.PropertyParsing = true;
1818 accessor_declarations
1820 lexer.PropertyParsing = false;
1823 current_property.DocComment = ConsumeStoredComment ();
1827 lbag.AppendToMember (current_property, GetLocation ($10));
1828 lexer.parsing_modifiers = true;
1830 opt_property_initializer
1832 current_property = null;
1837 member_declaration_name
1839 lexer.parsing_generic_declaration = false;
1841 tmpComment = Lexer.consume_doc_comment ();
1842 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1846 var type = (FullNamedExpression) $3;
1847 var property = new Property (current_type, type, (Modifiers) $2,
1848 (MemberName) $4, (Attributes) $1);
1850 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1851 property.Get.Block = (ToplevelBlock) $6;
1853 if (current_container.Kind == MemberKind.Interface) {
1854 report.Error (531, property.Get.Block.StartLocation,
1855 "`{0}': interface members cannot have a definition", property.GetSignatureForError ());
1858 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1859 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1861 current_type.AddMember (property);
1863 current_local_parameters = null;
1867 opt_property_initializer
1871 ++lexer.parsing_block;
1872 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1873 start_block (GetLocation ($1));
1875 property_initializer SEMICOLON
1877 --lexer.parsing_block;
1878 ((Property)current_property).Initializer = (Expression) $3;
1879 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1880 end_block (GetLocation ($4));
1881 current_local_parameters = null;
1885 property_initializer
1891 : opt_attributes opt_modifiers
1892 member_type indexer_declaration_name OPEN_BRACKET
1894 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1896 opt_formal_parameter_list CLOSE_BRACKET
1898 valid_param_mod = 0;
1899 var type = (FullNamedExpression) $3;
1900 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1902 current_property = indexer;
1904 current_type.AddIndexer (indexer);
1905 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1907 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1908 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1910 if (indexer.ParameterInfo.IsEmpty) {
1911 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1915 tmpComment = Lexer.consume_doc_comment ();
1916 Lexer.doc_state = XmlCommentState.Allowed;
1919 lexer.PropertyParsing = true;
1920 current_local_parameters = (ParametersCompiled) $7;
1924 lexer.PropertyParsing = false;
1925 current_local_parameters = null;
1927 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1928 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1931 current_property.DocComment = ConsumeStoredComment ();
1933 current_property = null;
1938 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1940 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1944 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1945 current_property.Get.Block = (ToplevelBlock) $1;
1949 accessor_declarations
1950 : get_accessor_declaration
1951 | get_accessor_declaration accessor_declarations
1952 | set_accessor_declaration
1953 | set_accessor_declaration accessor_declarations
1956 if (yyToken == Token.CLOSE_BRACE) {
1957 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1959 if (yyToken == Token.SEMICOLON)
1960 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1962 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1967 get_accessor_declaration
1968 : opt_attributes opt_modifiers GET
1970 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1971 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1974 if (current_property.Get != null) {
1975 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1978 if (current_property is Indexer) {
1979 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1980 (Attributes) $1, GetLocation ($3));
1982 current_property.Get = new Property.GetMethod (current_property,
1983 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1986 current_local_parameters = current_property.Get.ParameterInfo;
1987 lbag.AddMember (current_property.Get, mod_locations);
1988 lexer.PropertyParsing = false;
1993 current_property.Get.Block = (ToplevelBlock) $5;
1995 if (current_container.Kind == MemberKind.Interface) {
1996 report.Error (531, current_property.Get.Block.StartLocation,
1997 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2001 current_local_parameters = null;
2002 lexer.PropertyParsing = true;
2005 if (Lexer.doc_state == XmlCommentState.Error)
2006 Lexer.doc_state = XmlCommentState.NotAllowed;
2010 set_accessor_declaration
2011 : opt_attributes opt_modifiers SET
2013 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2014 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2017 if (current_property.Set != null) {
2018 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2021 if (current_property is Indexer) {
2022 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2023 ParametersCompiled.MergeGenerated (compiler,
2024 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2025 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2027 (Attributes) $1, GetLocation ($3));
2029 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2030 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2031 (Attributes) $1, GetLocation ($3));
2034 current_local_parameters = current_property.Set.ParameterInfo;
2035 lbag.AddMember (current_property.Set, mod_locations);
2036 lexer.PropertyParsing = false;
2041 current_property.Set.Block = (ToplevelBlock) $5;
2043 if (current_container.Kind == MemberKind.Interface) {
2044 report.Error (531, current_property.Set.Block.StartLocation,
2045 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2049 current_local_parameters = null;
2050 lexer.PropertyParsing = true;
2053 && Lexer.doc_state == XmlCommentState.Error)
2054 Lexer.doc_state = XmlCommentState.NotAllowed;
2067 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2072 interface_declaration
2079 type_declaration_name
2081 lexer.ConstraintsParsing = true;
2082 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2083 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2086 opt_type_parameter_constraints_clauses
2088 lexer.ConstraintsParsing = false;
2091 current_container.SetConstraints ((List<Constraints>) $9);
2094 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2095 Lexer.doc_state = XmlCommentState.Allowed;
2098 lexer.parsing_modifiers = true;
2100 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2102 --lexer.parsing_declaration;
2104 Lexer.doc_state = XmlCommentState.Allowed;
2109 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2111 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2113 $$ = pop_current_class ();
2115 | opt_attributes opt_modifiers opt_partial INTERFACE error
2117 Error_SyntaxError (yyToken);
2121 opt_interface_member_declarations
2123 | interface_member_declarations
2126 interface_member_declarations
2127 : interface_member_declaration
2129 lexer.parsing_modifiers = true;
2130 lexer.parsing_block = 0;
2132 | interface_member_declarations interface_member_declaration
2134 lexer.parsing_modifiers = true;
2135 lexer.parsing_block = 0;
2139 interface_member_declaration
2140 : constant_declaration
2142 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2146 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2148 | method_declaration
2149 | property_declaration
2151 | indexer_declaration
2152 | operator_declaration
2154 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2156 | constructor_declaration
2158 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2162 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2166 operator_declaration
2167 : opt_attributes opt_modifiers operator_declarator
2170 method_body_expression_block
2172 OperatorDeclaration decl = (OperatorDeclaration) $3;
2174 Operator op = new Operator (
2175 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2176 current_local_parameters,
2177 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2179 if (op.Block == null)
2180 op.ParameterInfo.CheckParameters (op);
2183 op.DocComment = tmpComment;
2184 Lexer.doc_state = XmlCommentState.Allowed;
2187 // Note again, checking is done in semantic analysis
2188 current_type.AddOperator (op);
2190 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2193 current_local_parameters = null;
2198 : type_expression_or_array
2201 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2202 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2207 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2209 valid_param_mod = ParameterModifierType.DefaultValue;
2210 if ((Operator.OpType) $3 == Operator.OpType.Is)
2211 valid_param_mod |= ParameterModifierType.Out;
2213 opt_formal_parameter_list CLOSE_PARENS
2215 valid_param_mod = 0;
2217 Location loc = GetLocation ($2);
2218 Operator.OpType op = (Operator.OpType) $3;
2219 current_local_parameters = (ParametersCompiled)$6;
2221 int p_count = current_local_parameters.Count;
2223 if (op == Operator.OpType.Addition)
2224 op = Operator.OpType.UnaryPlus;
2225 else if (op == Operator.OpType.Subtraction)
2226 op = Operator.OpType.UnaryNegation;
2229 if (IsUnaryOperator (op)) {
2231 report.Error (1020, loc, "Overloadable binary operator expected");
2232 } else if (p_count != 1) {
2233 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2234 Operator.GetName (op));
2236 } else if (op == Operator.OpType.Is) {
2237 // TODO: Special checks for is operator
2240 report.Error (1019, loc, "Overloadable unary operator expected");
2241 } else if (p_count != 2) {
2242 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2243 Operator.GetName (op));
2248 tmpComment = Lexer.consume_doc_comment ();
2249 Lexer.doc_state = XmlCommentState.NotAllowed;
2252 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2253 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2255 | conversion_operator_declarator
2258 overloadable_operator
2260 : BANG { $$ = Operator.OpType.LogicalNot; }
2261 | TILDE { $$ = Operator.OpType.OnesComplement; }
2262 | OP_INC { $$ = Operator.OpType.Increment; }
2263 | OP_DEC { $$ = Operator.OpType.Decrement; }
2264 | TRUE { $$ = Operator.OpType.True; }
2265 | FALSE { $$ = Operator.OpType.False; }
2266 // Unary and binary:
2267 | PLUS { $$ = Operator.OpType.Addition; }
2268 | MINUS { $$ = Operator.OpType.Subtraction; }
2270 | STAR { $$ = Operator.OpType.Multiply; }
2271 | DIV { $$ = Operator.OpType.Division; }
2272 | PERCENT { $$ = Operator.OpType.Modulus; }
2273 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2274 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2275 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2276 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2277 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2278 | OP_EQ { $$ = Operator.OpType.Equality; }
2279 | OP_NE { $$ = Operator.OpType.Inequality; }
2280 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2281 | OP_LT { $$ = Operator.OpType.LessThan; }
2282 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2283 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2286 if (lang_version != LanguageVersion.Experimental)
2287 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2289 $$ = Operator.OpType.Is;
2293 conversion_operator_declarator
2294 : IMPLICIT OPERATOR type OPEN_PARENS
2296 valid_param_mod = ParameterModifierType.DefaultValue;
2298 opt_formal_parameter_list CLOSE_PARENS
2300 valid_param_mod = 0;
2302 Location loc = GetLocation ($2);
2303 current_local_parameters = (ParametersCompiled)$6;
2305 if (current_local_parameters.Count != 1) {
2306 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2310 tmpComment = Lexer.consume_doc_comment ();
2311 Lexer.doc_state = XmlCommentState.NotAllowed;
2314 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2315 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2317 | EXPLICIT OPERATOR type OPEN_PARENS
2319 valid_param_mod = ParameterModifierType.DefaultValue;
2321 opt_formal_parameter_list CLOSE_PARENS
2323 valid_param_mod = 0;
2325 Location loc = GetLocation ($2);
2326 current_local_parameters = (ParametersCompiled)$6;
2328 if (current_local_parameters.Count != 1) {
2329 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2333 tmpComment = Lexer.consume_doc_comment ();
2334 Lexer.doc_state = XmlCommentState.NotAllowed;
2337 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2338 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2342 Error_SyntaxError (yyToken);
2343 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2344 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2348 Error_SyntaxError (yyToken);
2349 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2350 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2354 constructor_declaration
2355 : constructor_declarator
2358 Constructor c = (Constructor) $1;
2359 c.Block = (ToplevelBlock) $2;
2362 c.DocComment = ConsumeStoredComment ();
2364 current_local_parameters = null;
2366 Lexer.doc_state = XmlCommentState.Allowed;
2370 constructor_declarator
2376 tmpComment = Lexer.consume_doc_comment ();
2377 Lexer.doc_state = XmlCommentState.Allowed;
2380 valid_param_mod = ParameterModifierType.All;
2382 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2384 valid_param_mod = 0;
2385 current_local_parameters = (ParametersCompiled) $6;
2387 var lt = (LocatedToken) $3;
2388 var mods = (Modifiers) $2;
2389 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2391 if (lt.Value != current_container.MemberName.Name) {
2392 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2393 } else if ((mods & Modifiers.STATIC) != 0) {
2394 if (!current_local_parameters.IsEmpty) {
2395 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2396 c.GetSignatureForError ());
2399 if ((mods & Modifiers.AccessibilityMask) != 0){
2400 report.Error (515, c.Location,
2401 "`{0}': static constructor cannot have an access modifier",
2402 c.GetSignatureForError ());
2405 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2406 if (lang_version < LanguageVersion.V_6)
2407 FeatureIsNotAvailable (GetLocation ($3), "struct parameterless instance constructor");
2409 if ((mods & Modifiers.PUBLIC) == 0) {
2410 report.Error (8075, c.Location, "`{0}': Structs parameterless instance constructor must be public", c.GetSignatureForError ());
2415 current_type.AddConstructor (c);
2416 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2420 // start block here, so possible anonymous methods inside
2421 // constructor initializer can get correct parent block
2423 start_block (lexer.Location);
2425 opt_constructor_initializer
2428 var c = (Constructor) $8;
2429 c.Initializer = (ConstructorInitializer) $9;
2432 report.Error (514, c.Location,
2433 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2434 c.GetSignatureForError ());
2444 | SEMICOLON { current_block = null; $$ = null; }
2447 opt_constructor_initializer
2449 | constructor_initializer
2452 constructor_initializer
2453 : COLON BASE OPEN_PARENS
2455 ++lexer.parsing_block;
2457 opt_argument_list CLOSE_PARENS
2459 --lexer.parsing_block;
2460 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2461 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2463 | COLON THIS OPEN_PARENS
2465 ++lexer.parsing_block;
2467 opt_argument_list CLOSE_PARENS
2469 --lexer.parsing_block;
2470 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2471 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2475 Error_SyntaxError (yyToken);
2476 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2477 lbag.AddLocation ($$, GetLocation ($1));
2481 Error_SyntaxError (yyToken);
2486 destructor_declaration
2487 : opt_attributes opt_modifiers TILDE
2490 tmpComment = Lexer.consume_doc_comment ();
2491 Lexer.doc_state = XmlCommentState.NotAllowed;
2494 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2496 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2498 var lt = (LocatedToken) $5;
2499 if (lt.Value != current_container.MemberName.Name){
2500 report.Error (574, lt.Location, "Name of destructor must match name of class");
2501 } else if (current_container.Kind != MemberKind.Class){
2502 report.Error (575, lt.Location, "Only class types can contain destructor");
2505 Destructor d = new Destructor (current_type, (Modifiers) $2,
2506 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2508 d.DocComment = ConsumeStoredComment ();
2510 d.Block = (ToplevelBlock) $8;
2511 current_type.AddMember (d);
2512 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2514 current_local_parameters = null;
2521 EVENT type member_declaration_name
2523 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2524 current_type.AddMember (current_event_field);
2526 if (current_event_field.MemberName.ExplicitInterface != null) {
2527 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2528 current_event_field.GetSignatureForError ());
2531 $$ = current_event_field;
2533 opt_event_initializer
2534 opt_event_declarators
2538 current_event_field.DocComment = Lexer.consume_doc_comment ();
2539 Lexer.doc_state = XmlCommentState.Allowed;
2542 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2543 current_event_field = null;
2547 EVENT type member_declaration_name
2550 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2551 current_type.AddMember (current_event);
2552 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2554 lexer.EventParsing = true;
2556 event_accessor_declarations
2558 if (current_container.Kind == MemberKind.Interface)
2559 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2561 lexer.EventParsing = false;
2566 current_event.DocComment = Lexer.consume_doc_comment ();
2567 Lexer.doc_state = XmlCommentState.Allowed;
2570 lbag.AppendToMember (current_event, GetLocation ($9));
2571 current_event = null;
2572 current_local_parameters = null;
2578 Error_SyntaxError (yyToken);
2580 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2584 opt_event_initializer
2588 ++lexer.parsing_block;
2590 event_variable_initializer
2592 --lexer.parsing_block;
2593 current_event_field.Initializer = (Expression) $3;
2597 opt_event_declarators
2605 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2607 | event_declarators event_declarator
2609 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2616 var lt = (LocatedToken) $2;
2617 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2618 lbag.AddLocation ($$, GetLocation ($1));
2620 | COMMA IDENTIFIER ASSIGN
2622 ++lexer.parsing_block;
2624 event_variable_initializer
2626 --lexer.parsing_block;
2627 var lt = (LocatedToken) $2;
2628 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2629 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2633 event_variable_initializer
2635 if (current_container.Kind == MemberKind.Interface) {
2636 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2637 current_event_field.GetSignatureForError ());
2640 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2641 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2642 current_event_field.GetSignatureForError ());
2645 variable_initializer
2651 event_accessor_declarations
2652 : add_accessor_declaration remove_accessor_declaration
2653 | remove_accessor_declaration add_accessor_declaration
2654 | add_accessor_declaration
2656 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2657 current_event.GetSignatureForError ());
2659 | remove_accessor_declaration
2661 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2662 current_event.GetSignatureForError ());
2666 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2671 add_accessor_declaration
2672 : opt_attributes opt_modifiers ADD
2674 if ($2 != ModifierNone) {
2675 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2678 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2679 current_local_parameters = current_event.Add.ParameterInfo;
2681 lbag.AddMember (current_event.Add, mod_locations);
2682 lexer.EventParsing = false;
2684 event_accessor_block
2686 lexer.EventParsing = true;
2688 current_event.Add.Block = (ToplevelBlock) $5;
2690 if (current_container.Kind == MemberKind.Interface) {
2691 report.Error (531, current_event.Add.Block.StartLocation,
2692 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2695 current_local_parameters = null;
2699 remove_accessor_declaration
2700 : opt_attributes opt_modifiers REMOVE
2702 if ($2 != ModifierNone) {
2703 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2706 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2707 current_local_parameters = current_event.Remove.ParameterInfo;
2709 lbag.AddMember (current_event.Remove, mod_locations);
2710 lexer.EventParsing = false;
2712 event_accessor_block
2714 lexer.EventParsing = true;
2716 current_event.Remove.Block = (ToplevelBlock) $5;
2718 if (current_container.Kind == MemberKind.Interface) {
2719 report.Error (531, current_event.Remove.Block.StartLocation,
2720 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2723 current_local_parameters = null;
2727 event_accessor_block
2730 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2736 attributes_without_members
2737 : attribute_sections CLOSE_BRACE
2739 current_type.UnattachedAttributes = (Attributes) $1;
2740 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2741 lexer.putback ('}');
2745 // For full ast try to recover incomplete ambiguous member
2746 // declaration in form on class X { public int }
2748 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2750 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2752 lexer.putback ('}');
2754 lexer.parsing_generic_declaration = false;
2755 FullNamedExpression type = (FullNamedExpression) $3;
2756 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2757 current_type.AddField (current_field);
2765 ENUM type_declaration_name
2769 enumTypeComment = Lexer.consume_doc_comment ();
2774 Lexer.doc_state = XmlCommentState.Allowed;
2776 MemberName name = (MemberName) $4;
2777 if (name.IsGeneric) {
2778 report.Error (1675, name.Location, "Enums cannot have type parameters");
2781 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2783 opt_enum_member_declarations
2785 lexer.parsing_modifiers = true;
2787 // here will be evaluated after CLOSE_BLACE is consumed.
2789 Lexer.doc_state = XmlCommentState.Allowed;
2791 CLOSE_BRACE opt_semicolon
2794 current_container.DocComment = enumTypeComment;
2796 --lexer.parsing_declaration;
2799 // em.DocComment = ev.DocComment;
2801 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2802 $$ = pop_current_class ();
2814 Error_TypeExpected (GetLocation ($1));
2819 opt_enum_member_declarations
2821 | enum_member_declarations
2822 | enum_member_declarations COMMA
2824 lbag.AddLocation ($1, GetLocation ($2));
2828 enum_member_declarations
2829 : enum_member_declaration
2830 | enum_member_declarations COMMA enum_member_declaration
2832 lbag.AddLocation ($1, GetLocation ($2));
2837 enum_member_declaration
2838 : opt_attributes IDENTIFIER
2840 var lt = (LocatedToken) $2;
2841 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2842 ((Enum) current_type).AddEnumMember (em);
2845 em.DocComment = Lexer.consume_doc_comment ();
2846 Lexer.doc_state = XmlCommentState.Allowed;
2851 | opt_attributes IDENTIFIER
2853 ++lexer.parsing_block;
2855 tmpComment = Lexer.consume_doc_comment ();
2856 Lexer.doc_state = XmlCommentState.NotAllowed;
2859 ASSIGN constant_expression
2861 --lexer.parsing_block;
2863 var lt = (LocatedToken) $2;
2864 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2865 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2866 ((Enum) current_type).AddEnumMember (em);
2869 em.DocComment = ConsumeStoredComment ();
2873 | opt_attributes IDENTIFIER error
2875 Error_SyntaxError (yyToken);
2877 var lt = (LocatedToken) $2;
2878 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2879 ((Enum) current_type).AddEnumMember (em);
2882 em.DocComment = Lexer.consume_doc_comment ();
2883 Lexer.doc_state = XmlCommentState.Allowed;
2888 | attributes_without_members
2891 delegate_declaration
2895 member_type type_declaration_name
2898 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2900 opt_formal_parameter_list CLOSE_PARENS
2902 valid_param_mod = 0;
2904 ParametersCompiled p = (ParametersCompiled) $8;
2906 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2908 p.CheckParameters (del);
2910 current_container.AddTypeContainer (del);
2912 current_delegate = del;
2913 lexer.ConstraintsParsing = true;
2915 opt_type_parameter_constraints_clauses
2917 lexer.ConstraintsParsing = false;
2922 current_delegate.DocComment = Lexer.consume_doc_comment ();
2923 Lexer.doc_state = XmlCommentState.Allowed;
2927 current_delegate.SetConstraints ((List<Constraints>) $11);
2928 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2930 $$ = current_delegate;
2932 current_delegate = null;
2940 if (lang_version < LanguageVersion.ISO_2)
2941 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2943 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2947 namespace_or_type_expr
2949 | qualified_alias_member IDENTIFIER opt_type_argument_list
2951 var lt1 = (LocatedToken) $1;
2952 var lt2 = (LocatedToken) $2;
2954 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2955 lbag.AddLocation ($$, GetLocation ($2));
2957 | qualified_alias_member IDENTIFIER generic_dimension
2959 var lt1 = (LocatedToken) $1;
2960 var lt2 = (LocatedToken) $2;
2962 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2963 lbag.AddLocation ($$, GetLocation ($2));
2969 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2971 var lt = (LocatedToken) $3;
2972 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2973 lbag.AddLocation ($$, GetLocation ($2));
2975 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2977 var lt = (LocatedToken) $3;
2978 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2979 lbag.AddLocation ($$, GetLocation ($2));
2984 : IDENTIFIER opt_type_argument_list
2986 var lt = (LocatedToken) $1;
2987 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2989 | IDENTIFIER generic_dimension
2991 var lt = (LocatedToken) $1;
2992 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2997 // Generics arguments (any type, without attributes)
2999 opt_type_argument_list
3001 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3003 if (lang_version < LanguageVersion.ISO_2)
3004 FeatureIsNotAvailable (GetLocation ($1), "generics");
3008 | OP_GENERICS_LT error
3010 Error_TypeExpected (lexer.Location);
3011 $$ = new TypeArguments ();
3018 TypeArguments type_args = new TypeArguments ();
3019 type_args.Add ((FullNamedExpression) $1);
3022 | type_arguments COMMA type
3024 TypeArguments type_args = (TypeArguments) $1;
3025 type_args.Add ((FullNamedExpression) $3);
3031 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3033 type_declaration_name
3036 lexer.parsing_generic_declaration = true;
3038 opt_type_parameter_list
3040 lexer.parsing_generic_declaration = false;
3041 var lt = (LocatedToken) $1;
3042 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3046 member_declaration_name
3047 : method_declaration_name
3049 MemberName mn = (MemberName)$1;
3050 if (mn.TypeParameters != null)
3051 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3052 mn.GetSignatureForError ()));
3056 method_declaration_name
3057 : type_declaration_name
3058 | explicit_interface IDENTIFIER opt_type_parameter_list
3060 lexer.parsing_generic_declaration = false;
3061 var lt = (LocatedToken) $2;
3062 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3066 indexer_declaration_name
3069 lexer.parsing_generic_declaration = false;
3070 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3072 | explicit_interface THIS
3074 lexer.parsing_generic_declaration = false;
3075 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3080 : IDENTIFIER opt_type_argument_list DOT
3082 var lt = (LocatedToken) $1;
3083 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3084 lbag.AddLocation ($$, GetLocation ($3));
3086 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3088 var lt1 = (LocatedToken) $1;
3089 var lt2 = (LocatedToken) $2;
3091 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3092 lbag.AddLocation ($$, GetLocation ($4));
3094 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3096 var lt = (LocatedToken) $2;
3097 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3098 lbag.AddLocation ($$, GetLocation ($4));
3102 opt_type_parameter_list
3104 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3106 if (lang_version < LanguageVersion.ISO_2)
3107 FeatureIsNotAvailable (GetLocation ($1), "generics");
3110 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3117 var tparams = new TypeParameters ();
3118 tparams.Add ((TypeParameter)$1);
3121 | type_parameters COMMA type_parameter
3123 var tparams = (TypeParameters) $1;
3124 tparams.Add ((TypeParameter)$3);
3126 lbag.AddLocation ($3, GetLocation ($3));
3131 : opt_attributes opt_type_parameter_variance IDENTIFIER
3133 var lt = (LocatedToken)$3;
3134 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3138 if (GetTokenName (yyToken) == "type")
3139 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3141 Error_SyntaxError (yyToken);
3143 $$ = new TypeParameter (MemberName.Null, null, null);
3148 // All types where void is allowed
3151 : type_expression_or_array
3154 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3161 lexer.parsing_generic_declaration = true;
3166 // A type which does not allow `void' to be used
3169 : type_expression_or_array
3179 : type_expression_or_array
3182 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3183 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3187 type_expression_or_array
3189 | type_expression rank_specifiers
3191 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3196 : namespace_or_type_expr opt_nullable
3199 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3201 var sn = $1 as SimpleName;
3202 if (sn != null && sn.Name == "var")
3203 $$ = new VarExpr (sn.Location);
3208 | namespace_or_type_expr pointer_stars
3210 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3212 | builtin_type_expression
3218 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3219 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3223 builtin_type_expression
3224 : builtin_types opt_nullable
3227 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3229 | builtin_types pointer_stars
3231 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3233 | VOID pointer_stars
3235 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3242 var types = new List<FullNamedExpression> (2);
3243 types.Add ((FullNamedExpression) $1);
3246 | type_list COMMA base_type_name
3248 var types = (List<FullNamedExpression>) $1;
3249 types.Add ((FullNamedExpression) $3);
3257 if ($1 is ComposedCast) {
3258 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3265 * replaces all the productions for isolating the various
3266 * simple types, but we need this to reuse it easily in variable_type
3269 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3270 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3271 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3272 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3273 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3274 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3279 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3280 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3281 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3282 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3283 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3284 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3285 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3286 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3287 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3291 // Expressions, section 7.5
3296 : type_name_expression
3298 | array_creation_expression
3299 | parenthesized_expression
3300 | default_value_expression
3301 | invocation_expression
3305 | post_increment_expression
3306 | post_decrement_expression
3307 | object_or_delegate_creation_expression
3308 | anonymous_type_expression
3311 | checked_expression
3312 | unchecked_expression
3313 | pointer_member_access
3314 | anonymous_method_expression
3315 | undocumented_expressions
3316 | interpolated_string
3319 type_name_expression
3321 | IDENTIFIER GENERATE_COMPLETION {
3322 var lt = (LocatedToken) $1;
3323 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3331 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3335 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3336 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3340 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3342 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3344 | INTERPOLATED_STRING_END
3346 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3353 var list = new List<Expression> ();
3354 list.Add ((InterpolatedStringInsert) $1);
3357 | interpolations INTERPOLATED_STRING interpolation
3359 var list = (List<Expression>) $1;
3360 list.Add ((StringLiteral) $2);
3361 list.Add ((InterpolatedStringInsert) $3);
3369 $$ = new InterpolatedStringInsert ((Expression) $1);
3371 | expression COMMA expression
3373 $$ = new InterpolatedStringInsert ((Expression) $1) {
3374 Alignment = (Expression)$3
3379 lexer.parsing_interpolation_format = true;
3383 lexer.parsing_interpolation_format = false;
3385 $$ = new InterpolatedStringInsert ((Expression) $1) {
3389 | expression COMMA expression COLON
3391 lexer.parsing_interpolation_format = true;
3395 lexer.parsing_interpolation_format = false;
3397 $$ = new InterpolatedStringInsert ((Expression) $1) {
3398 Alignment = (Expression)$3,
3399 Format = (string) $6
3406 // Here is the trick, tokenizer may think that parens is a special but
3407 // parser is interested in open parens only, so we merge them.
3408 // Consider: if (a)foo ();
3416 // Use this production to accept closing parenthesis or
3417 // performing completion
3421 | COMPLETE_COMPLETION
3425 parenthesized_expression
3426 : OPEN_PARENS expression CLOSE_PARENS
3428 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3429 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3431 | OPEN_PARENS expression COMPLETE_COMPLETION
3433 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3438 : primary_expression DOT identifier_inside_body opt_type_argument_list
3440 var lt = (LocatedToken) $3;
3441 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3442 lbag.AddLocation ($$, GetLocation ($2));
3444 | primary_expression DOT identifier_inside_body generic_dimension
3446 var lt = (LocatedToken) $3;
3447 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3448 lbag.AddLocation ($$, GetLocation ($2));
3450 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3452 if (lang_version < LanguageVersion.V_6)
3453 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3455 var lt = (LocatedToken) $4;
3456 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3457 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3459 | builtin_types DOT identifier_inside_body opt_type_argument_list
3461 var lt = (LocatedToken) $3;
3462 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3463 lbag.AddLocation ($$, GetLocation ($2));
3465 | BASE DOT identifier_inside_body opt_type_argument_list
3467 var lt = (LocatedToken) $3;
3468 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3469 lbag.AddLocation ($$, GetLocation ($2));
3471 | AWAIT DOT identifier_inside_body opt_type_argument_list
3473 var lt = (LocatedToken) $3;
3474 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3475 lbag.AddLocation ($$, GetLocation ($2));
3477 | qualified_alias_member identifier_inside_body opt_type_argument_list
3479 var lt1 = (LocatedToken) $1;
3480 var lt2 = (LocatedToken) $2;
3482 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3483 lbag.AddLocation ($$, GetLocation ($2));
3485 | qualified_alias_member identifier_inside_body generic_dimension
3487 var lt1 = (LocatedToken) $1;
3488 var lt2 = (LocatedToken) $2;
3490 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3491 lbag.AddLocation ($$, GetLocation ($2));
3493 | primary_expression DOT GENERATE_COMPLETION {
3494 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3496 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3497 var lt = (LocatedToken) $3;
3498 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3500 | builtin_types DOT GENERATE_COMPLETION
3502 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3504 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3505 var lt = (LocatedToken) $3;
3506 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3510 invocation_expression
3511 : primary_expression open_parens_any opt_argument_list close_parens
3513 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3514 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3516 | primary_expression open_parens_any argument_list error
3518 Error_SyntaxError (yyToken);
3520 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3521 lbag.AddLocation ($$, GetLocation ($2));
3523 | primary_expression open_parens_any error
3525 Error_SyntaxError (yyToken);
3527 $$ = new Invocation ((Expression) $1, null);
3528 lbag.AddLocation ($$, GetLocation ($2));
3532 opt_object_or_collection_initializer
3533 : /* empty */ { $$ = null; }
3534 | object_or_collection_initializer
3537 object_or_collection_initializer
3538 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3541 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3543 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3545 lbag.AddLocation ($$, GetLocation ($3));
3547 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3549 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3550 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3554 opt_member_initializer_list
3555 : /* empty */ { $$ = null; }
3556 | member_initializer_list
3562 member_initializer_list
3563 : member_initializer
3565 var a = new List<Expression> ();
3566 a.Add ((Expression) $1);
3569 | member_initializer_list COMMA member_initializer
3571 var a = (List<Expression>)$1;
3572 a.Add ((Expression) $3);
3575 | member_initializer_list error {
3576 Error_SyntaxError (yyToken);
3582 : IDENTIFIER ASSIGN initializer_value
3584 var lt = (LocatedToken) $1;
3585 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3586 lbag.AddLocation ($$, GetLocation ($2));
3588 | AWAIT ASSIGN initializer_value
3590 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3591 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3592 lbag.AddLocation ($$, GetLocation ($2));
3594 | GENERATE_COMPLETION
3596 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3598 | non_assignment_expression opt_COMPLETE_COMPLETION {
3599 CompletionSimpleName csn = $1 as CompletionSimpleName;
3601 $$ = new CollectionElementInitializer ((Expression)$1);
3603 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3605 | OPEN_BRACE expression_list CLOSE_BRACE
3608 $$ = new CollectionElementInitializer (GetLocation ($1));
3610 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3612 lbag.AddLocation ($$, GetLocation ($3));
3614 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3616 if (lang_version < LanguageVersion.V_6)
3617 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3619 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3620 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3622 | OPEN_BRACE CLOSE_BRACE
3624 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3625 $$ = new CollectionElementInitializer (GetLocation ($1));
3626 lbag.AddLocation ($$, GetLocation ($2));
3632 | object_or_collection_initializer
3636 : /* empty */ { $$ = null; }
3641 : argument_or_named_argument
3643 Arguments list = new Arguments (4);
3644 list.Add ((Argument) $1);
3647 | argument_list COMMA argument
3649 Arguments list = (Arguments) $1;
3650 if (list [list.Count - 1] is NamedArgument)
3651 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3653 list.Add ((Argument) $3);
3656 | argument_list COMMA named_argument
3658 Arguments list = (Arguments) $1;
3659 NamedArgument a = (NamedArgument) $3;
3660 for (int i = 0; i < list.Count; ++i) {
3661 NamedArgument na = list [i] as NamedArgument;
3662 if (na != null && na.Name == a.Name)
3663 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3670 | argument_list COMMA error
3672 if (lexer.putback_char == -1)
3673 lexer.putback (')'); // TODO: Wrong but what can I do
3674 Error_SyntaxError (yyToken);
3679 report.Error (839, GetLocation ($1), "An argument is missing");
3687 $$ = new Argument ((Expression) $1);
3689 | non_simple_argument
3692 argument_or_named_argument
3698 : REF variable_reference
3700 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3701 lbag.AddLocation ($$, GetLocation ($1));
3703 | REF declaration_expression
3705 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3707 | OUT variable_reference
3709 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3710 lbag.AddLocation ($$, GetLocation ($1));
3712 | OUT declaration_expression
3714 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3716 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3718 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3719 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3721 | ARGLIST OPEN_PARENS CLOSE_PARENS
3723 $$ = new Argument (new Arglist (GetLocation ($1)));
3724 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3728 declaration_expression
3729 : OPEN_PARENS declaration_expression CLOSE_PARENS
3731 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3732 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3735 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3737 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3738 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3740 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3742 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3743 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3746 | variable_type identifier_inside_body
3748 if (lang_version != LanguageVersion.Experimental)
3749 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3751 var lt = (LocatedToken) $2;
3752 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3753 current_block.AddLocalName (lv);
3754 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3756 | variable_type identifier_inside_body ASSIGN expression
3758 if (lang_version != LanguageVersion.Experimental)
3759 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3761 var lt = (LocatedToken) $2;
3762 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3763 current_block.AddLocalName (lv);
3764 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3765 Initializer = (Expression) $4
3775 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3777 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3778 lbag.AddLocation ($$, GetLocation ($4));
3780 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3782 if (lang_version < LanguageVersion.V_6)
3783 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3785 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3786 ConditionalAccess = true
3789 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3791 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3793 Error_SyntaxError (yyToken);
3794 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3796 | primary_expression OPEN_BRACKET_EXPR error
3798 Error_SyntaxError (yyToken);
3799 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3804 : expression_or_error
3806 var list = new List<Expression> (4);
3807 list.Add ((Expression) $1);
3810 | expression_list COMMA expression_or_error
3812 var list = (List<Expression>) $1;
3813 list.Add ((Expression) $3);
3818 expression_list_arguments
3819 : expression_list_argument
3821 Arguments args = new Arguments (4);
3822 args.Add ((Argument) $1);
3825 | expression_list_arguments COMMA expression_list_argument
3827 Arguments args = (Arguments) $1;
3828 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3829 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3831 args.Add ((Argument) $3);
3836 expression_list_argument
3839 $$ = new Argument ((Expression) $1);
3847 $$ = new This (GetLocation ($1));
3852 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3854 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3855 lbag.AddLocation ($$, GetLocation ($4));
3857 | BASE OPEN_BRACKET error
3859 Error_SyntaxError (yyToken);
3860 $$ = new ElementAccess (null, null, GetLocation ($2));
3864 post_increment_expression
3865 : primary_expression OP_INC
3867 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3871 post_decrement_expression
3872 : primary_expression OP_DEC
3874 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3878 object_or_delegate_creation_expression
3879 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3882 if (lang_version <= LanguageVersion.ISO_2)
3883 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3885 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3887 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3890 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3892 | NEW new_expr_type object_or_collection_initializer
3894 if (lang_version <= LanguageVersion.ISO_2)
3895 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3897 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3901 array_creation_expression
3902 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3904 opt_array_initializer
3906 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3907 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3908 Next = (ComposedTypeSpecifier) $6
3909 }, (ArrayInitializer) $7, GetLocation ($1));
3910 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3912 | NEW new_expr_type rank_specifiers opt_array_initializer
3915 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3917 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3919 | NEW rank_specifier array_initializer
3921 if (lang_version <= LanguageVersion.ISO_2)
3922 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3924 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3926 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3928 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3929 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3931 | NEW new_expr_type error
3933 Error_SyntaxError (yyToken);
3934 // It can be any of new expression, create the most common one
3935 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3941 ++lexer.parsing_type;
3945 --lexer.parsing_type;
3950 anonymous_type_expression
3951 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3953 if (lang_version <= LanguageVersion.ISO_2)
3954 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3956 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3958 // TODO: lbag comma location
3959 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3961 | NEW OPEN_BRACE GENERATE_COMPLETION
3963 $$ = new EmptyCompletion ();
3967 anonymous_type_parameters_opt_comma
3968 : anonymous_type_parameters_opt
3969 | anonymous_type_parameters COMMA
3972 anonymous_type_parameters_opt
3974 | anonymous_type_parameters
3977 anonymous_type_parameters
3978 : anonymous_type_parameter
3980 var a = new List<AnonymousTypeParameter> (4);
3981 a.Add ((AnonymousTypeParameter) $1);
3984 | anonymous_type_parameters COMMA anonymous_type_parameter
3986 var a = (List<AnonymousTypeParameter>) $1;
3987 a.Add ((AnonymousTypeParameter) $3);
3990 | COMPLETE_COMPLETION
3992 $$ = new EmptyCompletion ();
3994 | anonymous_type_parameter COMPLETE_COMPLETION
4000 anonymous_type_parameter
4001 : identifier_inside_body ASSIGN variable_initializer
4003 var lt = (LocatedToken)$1;
4004 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4005 lbag.AddLocation ($$, GetLocation ($2));
4007 | identifier_inside_body
4009 var lt = (LocatedToken)$1;
4010 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4011 lt.Value, lt.Location);
4015 MemberAccess ma = (MemberAccess) $1;
4016 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4020 report.Error (746, lexer.Location,
4021 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4033 | rank_specifier rank_specifiers
4035 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4041 : OPEN_BRACKET CLOSE_BRACKET
4043 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4044 lbag.AddLocation ($$, GetLocation ($2));
4046 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4048 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4049 lbag.AddLocation ($$, GetLocation ($3));
4058 | dim_separators COMMA
4060 $$ = ((int) $1) + 1;
4064 opt_array_initializer
4076 : OPEN_BRACE CLOSE_BRACE
4078 var ai = new ArrayInitializer (0, GetLocation ($1));
4079 ai.VariableDeclaration = current_variable;
4080 lbag.AddLocation (ai, GetLocation ($2));
4083 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4085 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4086 ai.VariableDeclaration = current_variable;
4088 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4090 lbag.AddLocation (ai, GetLocation ($4));
4096 variable_initializer_list
4097 : variable_initializer
4099 var list = new List<Expression> (4);
4100 list.Add ((Expression) $1);
4103 | variable_initializer_list COMMA variable_initializer
4105 var list = (List<Expression>) $1;
4106 list.Add ((Expression) $3);
4112 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4114 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4115 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4119 typeof_type_expression
4123 Error_TypeExpected (lexer.Location);
4131 if (lang_version < LanguageVersion.ISO_2)
4132 FeatureIsNotAvailable (GetLocation ($1), "generics");
4138 qualified_alias_member
4139 : IDENTIFIER DOUBLE_COLON
4141 var lt = (LocatedToken) $1;
4142 if (lang_version == LanguageVersion.ISO_1)
4143 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4150 : SIZEOF open_parens_any type CLOSE_PARENS
4152 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4153 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4155 | SIZEOF open_parens_any type error
4157 Error_SyntaxError (yyToken);
4159 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4160 lbag.AddLocation ($$, GetLocation ($2));
4165 : CHECKED open_parens_any expression CLOSE_PARENS
4167 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4168 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4172 Error_SyntaxError (yyToken);
4174 $$ = new CheckedExpr (null, GetLocation ($1));
4178 unchecked_expression
4179 : UNCHECKED open_parens_any expression CLOSE_PARENS
4181 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4182 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4186 Error_SyntaxError (yyToken);
4188 $$ = new UnCheckedExpr (null, GetLocation ($1));
4192 pointer_member_access
4193 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4195 var lt = (LocatedToken) $3;
4196 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4200 anonymous_method_expression
4201 : DELEGATE opt_anonymous_method_signature
4203 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4207 $$ = end_anonymous ((ParametersBlock) $4);
4209 | ASYNC DELEGATE opt_anonymous_method_signature
4211 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4215 $$ = end_anonymous ((ParametersBlock) $5);
4219 opt_anonymous_method_signature
4222 $$ = ParametersCompiled.Undefined;
4224 | anonymous_method_signature
4227 anonymous_method_signature
4230 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4232 opt_formal_parameter_list CLOSE_PARENS
4234 valid_param_mod = 0;
4239 default_value_expression
4240 : DEFAULT open_parens_any type CLOSE_PARENS
4242 if (lang_version < LanguageVersion.ISO_2)
4243 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4245 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4246 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4251 : primary_expression
4252 | BANG prefixed_unary_expression
4254 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4256 | TILDE prefixed_unary_expression
4258 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4260 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4262 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4263 lbag.AddLocation ($$, GetLocation ($3));
4265 | AWAIT prefixed_unary_expression
4268 if (current_anonymous_method is LambdaExpression) {
4269 report.Error (4034, GetLocation ($1),
4270 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4271 } else if (current_anonymous_method != null) {
4272 report.Error (4035, GetLocation ($1),
4273 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4274 } else if (interactive_async != null) {
4275 current_block.Explicit.RegisterAsyncAwait ();
4276 interactive_async = true;
4278 report.Error (4033, GetLocation ($1),
4279 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4282 current_block.Explicit.RegisterAsyncAwait ();
4285 $$ = new Await ((Expression) $2, GetLocation ($1));
4289 Error_SyntaxError (yyToken);
4291 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4295 Error_SyntaxError (yyToken);
4297 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4299 | OPEN_PARENS_CAST type CLOSE_PARENS error
4301 Error_SyntaxError (yyToken);
4303 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4304 lbag.AddLocation ($$, GetLocation ($3));
4308 Error_SyntaxError (yyToken);
4310 $$ = new Await (null, GetLocation ($1));
4315 // The idea to split this out is from Rhys' grammar
4316 // to solve the problem with casts.
4318 prefixed_unary_expression
4320 | PLUS prefixed_unary_expression
4322 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4324 | MINUS prefixed_unary_expression
4326 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4328 | OP_INC prefixed_unary_expression
4330 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4332 | OP_DEC prefixed_unary_expression
4334 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4336 | STAR prefixed_unary_expression
4338 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4340 | BITWISE_AND prefixed_unary_expression
4342 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4346 Error_SyntaxError (yyToken);
4348 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4352 Error_SyntaxError (yyToken);
4354 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4358 Error_SyntaxError (yyToken);
4360 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4364 Error_SyntaxError (yyToken);
4366 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4370 Error_SyntaxError (yyToken);
4372 $$ = new Indirection (null, GetLocation ($1));
4376 Error_SyntaxError (yyToken);
4378 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4382 multiplicative_expression
4383 : prefixed_unary_expression
4384 | multiplicative_expression STAR prefixed_unary_expression
4386 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4387 lbag.AddLocation ($$, GetLocation ($2));
4389 | multiplicative_expression DIV prefixed_unary_expression
4391 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4392 lbag.AddLocation ($$, GetLocation ($2));
4394 | multiplicative_expression PERCENT prefixed_unary_expression
4396 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4397 lbag.AddLocation ($$, GetLocation ($2));
4399 | multiplicative_expression STAR error
4401 Error_SyntaxError (yyToken);
4403 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4404 lbag.AddLocation ($$, GetLocation ($2));
4406 | multiplicative_expression DIV error
4408 Error_SyntaxError (yyToken);
4410 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4411 lbag.AddLocation ($$, GetLocation ($2));
4413 | multiplicative_expression PERCENT error
4415 Error_SyntaxError (yyToken);
4417 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4418 lbag.AddLocation ($$, GetLocation ($2));
4423 : multiplicative_expression
4424 | additive_expression PLUS multiplicative_expression
4426 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4427 lbag.AddLocation ($$, GetLocation ($2));
4429 | additive_expression MINUS multiplicative_expression
4431 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4432 lbag.AddLocation ($$, GetLocation ($2));
4434 | additive_expression PLUS error
4436 Error_SyntaxError (yyToken);
4438 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4439 lbag.AddLocation ($$, GetLocation ($2));
4441 | additive_expression MINUS error
4443 Error_SyntaxError (yyToken);
4445 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4446 lbag.AddLocation ($$, GetLocation ($2));
4448 | additive_expression AS type
4450 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4452 | additive_expression IS pattern_type_expr opt_identifier
4454 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4456 if (lang_version != LanguageVersion.Experimental)
4457 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4459 var lt = (LocatedToken) $4;
4460 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4461 current_block.AddLocalName (is_expr.Variable);
4466 | additive_expression IS pattern_expr
4468 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4469 if (lang_version != LanguageVersion.Experimental)
4470 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4474 | additive_expression AS error
4476 Error_SyntaxError (yyToken);
4478 $$ = new As ((Expression) $1, null, GetLocation ($2));
4480 | additive_expression IS error
4482 Error_SyntaxError (yyToken);
4484 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4488 var lt = (LocatedToken) $1;
4489 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4493 var lt = (LocatedToken) $1;
4494 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4504 | PLUS prefixed_unary_expression
4506 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4508 | MINUS prefixed_unary_expression
4510 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4513 | default_value_expression
4514 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4516 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4517 lbag.AddLocation ($$, GetLocation ($3));
4521 $$ = new WildcardPattern (GetLocation ($1));
4523 | pattern_expr_invocation
4527 pattern_expr_invocation
4528 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4530 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4535 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4537 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4541 pattern_property_list
4542 : pattern_property_entry
4544 var list = new List<PropertyPatternMember> ();
4545 list.Add ((PropertyPatternMember) $1);
4548 | pattern_property_list COMMA pattern_property_entry
4550 var list = (List<PropertyPatternMember>) $1;
4551 list.Add ((PropertyPatternMember) $3);
4556 pattern_property_entry
4557 : identifier_inside_body IS pattern
4559 var lt = (LocatedToken) $1;
4560 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4566 | pattern_type_expr opt_identifier
4569 var lt = (LocatedToken) $2;
4570 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4571 current_block.AddLocalName (variable);
4579 $$ = new Arguments (0);
4587 Arguments args = new Arguments (4);
4588 args.Add ((Argument) $1);
4591 | pattern_list COMMA pattern_argument
4593 Arguments args = (Arguments) $1;
4594 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4595 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4597 args.Add ((Argument) $3);
4605 $$ = new Argument ((Expression) $1);
4607 | IDENTIFIER COLON pattern
4609 var lt = (LocatedToken) $1;
4610 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4615 : additive_expression
4616 | shift_expression OP_SHIFT_LEFT additive_expression
4618 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4619 lbag.AddLocation ($$, GetLocation ($2));
4621 | shift_expression OP_SHIFT_RIGHT additive_expression
4623 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4624 lbag.AddLocation ($$, GetLocation ($2));
4626 | shift_expression OP_SHIFT_LEFT error
4628 Error_SyntaxError (yyToken);
4630 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4631 lbag.AddLocation ($$, GetLocation ($2));
4633 | shift_expression OP_SHIFT_RIGHT error
4635 Error_SyntaxError (yyToken);
4637 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4638 lbag.AddLocation ($$, GetLocation ($2));
4642 relational_expression
4644 | relational_expression OP_LT shift_expression
4646 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4647 lbag.AddLocation ($$, GetLocation ($2));
4649 | relational_expression OP_GT shift_expression
4651 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4652 lbag.AddLocation ($$, GetLocation ($2));
4654 | relational_expression OP_LE shift_expression
4656 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4657 lbag.AddLocation ($$, GetLocation ($2));
4659 | relational_expression OP_GE shift_expression
4661 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4662 lbag.AddLocation ($$, GetLocation ($2));
4664 | relational_expression OP_LT error
4666 Error_SyntaxError (yyToken);
4668 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4669 lbag.AddLocation ($$, GetLocation ($2));
4671 | relational_expression OP_GT error
4673 Error_SyntaxError (yyToken);
4675 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4676 lbag.AddLocation ($$, GetLocation ($2));
4678 | relational_expression OP_LE error
4680 Error_SyntaxError (yyToken);
4682 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4683 lbag.AddLocation ($$, GetLocation ($2));
4685 | relational_expression OP_GE error
4687 Error_SyntaxError (yyToken);
4689 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4690 lbag.AddLocation ($$, GetLocation ($2));
4695 : relational_expression
4696 | equality_expression OP_EQ relational_expression
4698 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4699 lbag.AddLocation ($$, GetLocation ($2));
4701 | equality_expression OP_NE relational_expression
4703 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4704 lbag.AddLocation ($$, GetLocation ($2));
4706 | equality_expression OP_EQ error
4708 Error_SyntaxError (yyToken);
4710 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4711 lbag.AddLocation ($$, GetLocation ($2));
4713 | equality_expression OP_NE error
4715 Error_SyntaxError (yyToken);
4717 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4718 lbag.AddLocation ($$, GetLocation ($2));
4723 : equality_expression
4724 | and_expression BITWISE_AND equality_expression
4726 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4727 lbag.AddLocation ($$, GetLocation ($2));
4729 | and_expression BITWISE_AND error
4731 Error_SyntaxError (yyToken);
4733 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4734 lbag.AddLocation ($$, GetLocation ($2));
4738 exclusive_or_expression
4740 | exclusive_or_expression CARRET and_expression
4742 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4743 lbag.AddLocation ($$, GetLocation ($2));
4745 | exclusive_or_expression CARRET error
4747 Error_SyntaxError (yyToken);
4749 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4750 lbag.AddLocation ($$, GetLocation ($2));
4754 inclusive_or_expression
4755 : exclusive_or_expression
4756 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4758 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4759 lbag.AddLocation ($$, GetLocation ($2));
4761 | inclusive_or_expression BITWISE_OR error
4763 Error_SyntaxError (yyToken);
4765 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4766 lbag.AddLocation ($$, GetLocation ($2));
4770 conditional_and_expression
4771 : inclusive_or_expression
4772 | conditional_and_expression OP_AND inclusive_or_expression
4774 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4775 lbag.AddLocation ($$, GetLocation ($2));
4777 | conditional_and_expression OP_AND error
4779 Error_SyntaxError (yyToken);
4781 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4782 lbag.AddLocation ($$, GetLocation ($2));
4786 conditional_or_expression
4787 : conditional_and_expression
4788 | conditional_or_expression OP_OR conditional_and_expression
4790 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4791 lbag.AddLocation ($$, GetLocation ($2));
4793 | conditional_or_expression OP_OR error
4795 Error_SyntaxError (yyToken);
4797 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4798 lbag.AddLocation ($$, GetLocation ($2));
4802 null_coalescing_expression
4803 : conditional_or_expression
4804 | conditional_or_expression OP_COALESCING null_coalescing_expression
4806 if (lang_version < LanguageVersion.ISO_2)
4807 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4809 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4810 lbag.AddLocation ($$, GetLocation ($2));
4814 conditional_expression
4815 : null_coalescing_expression
4816 | null_coalescing_expression INTERR expression COLON expression
4818 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4819 lbag.AddLocation ($$, GetLocation ($4));
4821 | null_coalescing_expression INTERR expression error
4823 Error_SyntaxError (yyToken);
4825 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4827 | null_coalescing_expression INTERR expression COLON error
4829 Error_SyntaxError (yyToken);
4831 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4832 lbag.AddLocation ($$, GetLocation ($4));
4834 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4836 Error_SyntaxError (Token.CLOSE_BRACE);
4838 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4839 lbag.AddLocation ($$, GetLocation ($4));
4840 lexer.putback ('}');
4844 assignment_expression
4845 : prefixed_unary_expression ASSIGN expression
4847 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4848 lbag.AddLocation ($$, GetLocation ($2));
4850 | prefixed_unary_expression OP_MULT_ASSIGN expression
4852 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4853 lbag.AddLocation ($$, GetLocation ($2));
4855 | prefixed_unary_expression OP_DIV_ASSIGN expression
4857 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4858 lbag.AddLocation ($$, GetLocation ($2));
4860 | prefixed_unary_expression OP_MOD_ASSIGN expression
4862 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4863 lbag.AddLocation ($$, GetLocation ($2));
4865 | prefixed_unary_expression OP_ADD_ASSIGN expression
4867 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4868 lbag.AddLocation ($$, GetLocation ($2));
4870 | prefixed_unary_expression OP_SUB_ASSIGN expression
4872 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4873 lbag.AddLocation ($$, GetLocation ($2));
4875 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4877 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4878 lbag.AddLocation ($$, GetLocation ($2));
4880 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4882 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4883 lbag.AddLocation ($$, GetLocation ($2));
4885 | prefixed_unary_expression OP_AND_ASSIGN expression
4887 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4888 lbag.AddLocation ($$, GetLocation ($2));
4890 | prefixed_unary_expression OP_OR_ASSIGN expression
4892 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4893 lbag.AddLocation ($$, GetLocation ($2));
4895 | prefixed_unary_expression OP_XOR_ASSIGN expression
4897 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4898 lbag.AddLocation ($$, GetLocation ($2));
4902 lambda_parameter_list
4905 var pars = new List<Parameter> (4);
4906 pars.Add ((Parameter) $1);
4910 | lambda_parameter_list COMMA lambda_parameter
4912 var pars = (List<Parameter>) $1;
4913 Parameter p = (Parameter)$3;
4914 if (pars[0].GetType () != p.GetType ()) {
4915 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4924 : parameter_modifier parameter_type identifier_inside_body
4926 var lt = (LocatedToken) $3;
4928 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4930 | parameter_type identifier_inside_body
4932 var lt = (LocatedToken) $2;
4934 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4938 var lt = (LocatedToken) $1;
4939 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4943 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4944 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4948 opt_lambda_parameter_list
4949 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4950 | lambda_parameter_list {
4951 var pars_list = (List<Parameter>) $1;
4952 $$ = new ParametersCompiled (pars_list.ToArray ());
4956 lambda_expression_body
4958 start_block (Location.Null);
4960 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4962 Block b = end_block (Location.Null);
4963 b.IsCompilerGenerated = true;
4964 b.AddStatement (new ContextualReturn ((Expression) $2));
4970 // Handles only cases like foo = x.FirstOrDefault (l => );
4971 // where we must restore current_variable
4972 Block b = end_block (Location.Null);
4973 b.IsCompilerGenerated = true;
4975 Error_SyntaxError (yyToken);
4984 Error_SyntaxError (yyToken);
4992 var lt = (LocatedToken) $1;
4993 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4994 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4996 lambda_expression_body
4998 $$ = end_anonymous ((ParametersBlock) $4);
4999 lbag.AddLocation ($$, GetLocation ($2));
5003 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5004 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5005 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5007 lambda_expression_body
5009 $$ = end_anonymous ((ParametersBlock) $4);
5010 lbag.AddLocation ($$, GetLocation ($2));
5012 | ASYNC identifier_inside_body ARROW
5014 var lt = (LocatedToken) $2;
5015 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5016 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5018 lambda_expression_body
5020 $$ = end_anonymous ((ParametersBlock) $5);
5021 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5023 | OPEN_PARENS_LAMBDA
5025 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5027 opt_lambda_parameter_list CLOSE_PARENS ARROW
5029 valid_param_mod = 0;
5030 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5032 lambda_expression_body
5034 $$ = end_anonymous ((ParametersBlock) $7);
5035 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5037 | ASYNC OPEN_PARENS_LAMBDA
5039 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5041 opt_lambda_parameter_list CLOSE_PARENS ARROW
5043 valid_param_mod = 0;
5044 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5046 lambda_expression_body
5048 $$ = end_anonymous ((ParametersBlock) $8);
5049 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5054 : assignment_expression
5055 | non_assignment_expression
5058 non_assignment_expression
5059 : conditional_expression
5064 $$ = new ArglistAccess (GetLocation ($1));
5068 undocumented_expressions
5069 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5071 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5072 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5074 | REFTYPE open_parens_any expression CLOSE_PARENS
5076 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5077 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5079 | MAKEREF open_parens_any expression CLOSE_PARENS
5081 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5082 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5093 $$ = new BooleanExpression ((Expression) $1);
5097 opt_primary_parameters
5102 | primary_parameters
5106 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5110 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5111 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5113 if (lang_version != LanguageVersion.Experimental)
5114 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5118 opt_primary_parameters_with_class_base
5127 | primary_parameters
5131 | primary_parameters class_base
5135 | primary_parameters class_base OPEN_PARENS
5137 ++lexer.parsing_block;
5138 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5140 opt_argument_list CLOSE_PARENS
5142 lbag.AppendToMember (current_container, GetLocation ($6));
5143 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5144 --lexer.parsing_block;
5160 type_declaration_name
5162 lexer.ConstraintsParsing = true;
5164 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5165 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5166 FeatureIsNotAvailable (c.Location, "static classes");
5169 push_current_container (c, $3);
5170 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5172 opt_primary_parameters_with_class_base
5173 opt_type_parameter_constraints_clauses
5175 valid_param_mod = 0;
5176 lexer.ConstraintsParsing = false;
5179 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5182 current_container.SetConstraints ((List<Constraints>) $9);
5183 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5186 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5187 Lexer.doc_state = XmlCommentState.Allowed;
5190 lexer.parsing_modifiers = true;
5192 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5194 --lexer.parsing_declaration;
5196 Lexer.doc_state = XmlCommentState.Allowed;
5201 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5203 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5205 $$ = pop_current_class ();
5213 { $$ = $1; } // location
5219 mod_locations = null;
5221 lexer.parsing_modifiers = false;
5225 lexer.parsing_modifiers = false;
5231 | modifiers modifier
5233 var m1 = (Modifiers) $1;
5234 var m2 = (Modifiers) $2;
5236 if ((m1 & m2) != 0) {
5237 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5238 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5239 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5240 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5241 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5242 "More than one protection modifier specified");
5253 StoreModifierLocation ($$, GetLocation ($1));
5255 if (current_container.Kind == MemberKind.Namespace)
5256 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5260 $$ = Modifiers.PUBLIC;
5261 StoreModifierLocation ($$, GetLocation ($1));
5265 $$ = Modifiers.PROTECTED;
5266 StoreModifierLocation ($$, GetLocation ($1));
5270 $$ = Modifiers.INTERNAL;
5271 StoreModifierLocation ($$, GetLocation ($1));
5275 $$ = Modifiers.PRIVATE;
5276 StoreModifierLocation ($$, GetLocation ($1));
5280 $$ = Modifiers.ABSTRACT;
5281 StoreModifierLocation ($$, GetLocation ($1));
5285 $$ = Modifiers.SEALED;
5286 StoreModifierLocation ($$, GetLocation ($1));
5290 $$ = Modifiers.STATIC;
5291 StoreModifierLocation ($$, GetLocation ($1));
5295 $$ = Modifiers.READONLY;
5296 StoreModifierLocation ($$, GetLocation ($1));
5300 $$ = Modifiers.VIRTUAL;
5301 StoreModifierLocation ($$, GetLocation ($1));
5305 $$ = Modifiers.OVERRIDE;
5306 StoreModifierLocation ($$, GetLocation ($1));
5310 $$ = Modifiers.EXTERN;
5311 StoreModifierLocation ($$, GetLocation ($1));
5315 $$ = Modifiers.VOLATILE;
5316 StoreModifierLocation ($$, GetLocation ($1));
5320 $$ = Modifiers.UNSAFE;
5321 StoreModifierLocation ($$, GetLocation ($1));
5322 if (!settings.Unsafe)
5323 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5327 $$ = Modifiers.ASYNC;
5328 StoreModifierLocation ($$, GetLocation ($1));
5340 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5342 | COLON type_list error
5344 Error_SyntaxError (yyToken);
5346 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5350 opt_type_parameter_constraints_clauses
5352 | type_parameter_constraints_clauses
5358 type_parameter_constraints_clauses
5359 : type_parameter_constraints_clause
5361 var constraints = new List<Constraints> (1);
5362 constraints.Add ((Constraints) $1);
5365 | type_parameter_constraints_clauses type_parameter_constraints_clause
5367 var constraints = (List<Constraints>) $1;
5368 Constraints new_constraint = (Constraints)$2;
5370 foreach (Constraints c in constraints) {
5371 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5372 report.Error (409, new_constraint.Location,
5373 "A constraint clause has already been specified for type parameter `{0}'",
5374 new_constraint.TypeParameter.Value);
5378 constraints.Add (new_constraint);
5383 type_parameter_constraints_clause
5384 : WHERE IDENTIFIER COLON type_parameter_constraints
5386 var lt = (LocatedToken) $2;
5387 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5388 lbag.AddLocation ($$, GetLocation ($3));
5390 | WHERE IDENTIFIER error
5392 Error_SyntaxError (yyToken);
5394 var lt = (LocatedToken) $2;
5395 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5399 type_parameter_constraints
5400 : type_parameter_constraint
5402 var constraints = new List<FullNamedExpression> (1);
5403 constraints.Add ((FullNamedExpression) $1);
5406 | type_parameter_constraints COMMA type_parameter_constraint
5408 var constraints = (List<FullNamedExpression>) $1;
5409 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5410 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5411 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5414 prev = $3 as SpecialContraintExpr;
5416 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5417 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5419 prev = constraints [0] as SpecialContraintExpr;
5420 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5421 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5426 constraints.Add ((FullNamedExpression) $3);
5431 type_parameter_constraint
5434 if ($1 is ComposedCast)
5435 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5439 | NEW OPEN_PARENS CLOSE_PARENS
5441 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5442 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5446 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5450 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5454 opt_type_parameter_variance
5459 | type_parameter_variance
5461 if (lang_version <= LanguageVersion.V_3)
5462 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5468 type_parameter_variance
5471 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5475 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5484 // A block is "contained" on the following places:
5486 // property_declaration as part of the accessor body (get/set)
5487 // operator_declaration
5488 // constructor_declaration
5489 // destructor_declaration
5490 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5495 ++lexer.parsing_block;
5496 start_block (GetLocation ($1));
5498 opt_statement_list block_end
5507 --lexer.parsing_block;
5508 $$ = end_block (GetLocation ($1));
5510 | COMPLETE_COMPLETION
5512 --lexer.parsing_block;
5513 $$ = end_block (lexer.Location);
5521 ++lexer.parsing_block;
5522 current_block.StartLocation = GetLocation ($1);
5524 opt_statement_list CLOSE_BRACE
5526 --lexer.parsing_block;
5527 $$ = end_block (GetLocation ($4));
5538 | statement_list statement
5542 : block_variable_declaration
5544 current_block.AddStatement ((Statement) $1);
5546 | valid_declaration_statement
5548 current_block.AddStatement ((Statement) $1);
5553 Error_SyntaxError (yyToken);
5559 // The interactive_statement and its derivatives are only
5560 // used to provide a special version of `expression_statement'
5561 // that has a side effect of assigning the expression to
5564 interactive_statement_list
5565 : interactive_statement
5566 | interactive_statement_list interactive_statement
5569 interactive_statement
5570 : block_variable_declaration
5572 current_block.AddStatement ((Statement) $1);
5574 | interactive_valid_declaration_statement
5576 current_block.AddStatement ((Statement) $1);
5581 valid_declaration_statement
5584 | expression_statement
5585 | selection_statement
5586 | iteration_statement
5590 | unchecked_statement
5597 interactive_valid_declaration_statement
5600 | interactive_expression_statement
5601 | selection_statement
5602 | iteration_statement
5606 | unchecked_statement
5614 : valid_declaration_statement
5615 | block_variable_declaration
5617 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5622 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5627 Error_SyntaxError (yyToken);
5628 $$ = new EmptyStatement (GetLocation ($1));
5635 // Uses lexer.Location because semicolon location is not kept in quick mode
5636 $$ = new EmptyStatement (lexer.Location);
5641 : identifier_inside_body COLON
5643 var lt = (LocatedToken) $1;
5644 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5645 lbag.AddLocation (labeled, GetLocation ($2));
5646 current_block.AddLabel (labeled);
5647 current_block.AddStatement (labeled);
5653 : variable_type_simple
5654 | variable_type_simple rank_specifiers
5657 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5659 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5664 * The following is from Rhys' grammar:
5665 * > Types in local variable declarations must be recognized as
5666 * > expressions to prevent reduce/reduce errors in the grammar.
5667 * > The expressions are converted into types during semantic analysis.
5669 variable_type_simple
5670 : type_name_expression opt_nullable
5672 // Ok, the above "primary_expression" is there to get rid of
5673 // both reduce/reduce and shift/reduces in the grammar, it should
5674 // really just be "type_name". If you use type_name, a reduce/reduce
5675 // creeps up. If you use namespace_or_type_name (which is all we need
5676 // really) two shift/reduces appear.
5679 // So the super-trick is that primary_expression
5680 // can only be either a SimpleName or a MemberAccess.
5681 // The MemberAccess case arises when you have a fully qualified type-name like :
5683 // SimpleName is when you have
5686 var expr = (ATypeNameExpression) $1;
5688 if (expr.Name == "var" && expr is SimpleName)
5689 $$ = new VarExpr (expr.Location);
5693 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5696 | type_name_expression pointer_stars
5698 var expr = (ATypeNameExpression) $1;
5699 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5701 | builtin_type_expression
5707 | pointer_star pointer_stars
5709 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5717 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5721 identifier_inside_body
5725 $$ = Error_AwaitAsIdentifier ($1);
5729 block_variable_declaration
5730 : variable_type identifier_inside_body
5732 var lt = (LocatedToken) $2;
5733 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5734 current_block.AddLocalName (li);
5735 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5737 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5739 $$ = current_variable;
5740 current_variable = null;
5742 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5744 lbag.AddLocation ($$, GetLocation ($6));
5746 | CONST variable_type identifier_inside_body
5748 var lt = (LocatedToken) $3;
5749 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5750 current_block.AddLocalName (li);
5751 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5753 const_variable_initializer opt_const_declarators SEMICOLON
5755 $$ = current_variable;
5756 current_variable = null;
5757 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5761 opt_local_variable_initializer
5763 | ASSIGN block_variable_initializer
5765 current_variable.Initializer = (Expression) $2;
5766 PushLocation (GetLocation ($1));
5767 $$ = current_variable;
5771 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5772 report.Error (650, lexer.Location,
5773 "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");
5775 Error_SyntaxError (yyToken);
5780 opt_variable_declarators
5782 | variable_declarators
5785 opt_using_or_fixed_variable_declarators
5787 | variable_declarators
5789 foreach (var d in current_variable.Declarators) {
5790 if (d.Initializer == null)
5791 Error_MissingInitializer (d.Variable.Location);
5796 variable_declarators
5797 : variable_declarator
5798 | variable_declarators variable_declarator
5802 : COMMA identifier_inside_body
5804 var lt = (LocatedToken) $2;
5805 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5806 var d = new BlockVariableDeclarator (li, null);
5807 current_variable.AddDeclarator (d);
5808 current_block.AddLocalName (li);
5809 lbag.AddLocation (d, GetLocation ($1));
5811 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5813 var lt = (LocatedToken) $2;
5814 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5815 var d = new BlockVariableDeclarator (li, (Expression) $4);
5816 current_variable.AddDeclarator (d);
5817 current_block.AddLocalName (li);
5818 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5822 const_variable_initializer
5825 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5827 | ASSIGN constant_initializer_expr
5829 current_variable.Initializer = (Expression) $2;
5833 opt_const_declarators
5840 | const_declarators const_declarator
5844 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5846 var lt = (LocatedToken) $2;
5847 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5848 var d = new BlockVariableDeclarator (li, (Expression) $4);
5849 current_variable.AddDeclarator (d);
5850 current_block.AddLocalName (li);
5851 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5855 block_variable_initializer
5856 : variable_initializer
5857 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5859 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5860 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5862 | STACKALLOC simple_type
5864 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5865 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5869 expression_statement
5870 : statement_expression SEMICOLON
5873 lbag.AddStatement ($$, GetLocation ($2));
5875 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5876 | statement_expression CLOSE_BRACE
5879 report.Error (1002, GetLocation ($2), "; expected");
5880 lexer.putback ('}');
5884 interactive_expression_statement
5885 : interactive_statement_expression SEMICOLON { $$ = $1; }
5886 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5890 // We have to do the wrapping here and not in the case above,
5891 // because statement_expression is used for example in for_statement
5893 statement_expression
5896 ExpressionStatement s = $1 as ExpressionStatement;
5898 var expr = $1 as Expression;
5899 $$ = new StatementErrorExpression (expr);
5901 $$ = new StatementExpression (s);
5906 interactive_statement_expression
5909 Expression expr = (Expression) $1;
5910 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5914 Error_SyntaxError (yyToken);
5915 $$ = new EmptyStatement (GetLocation ($1));
5925 : IF open_parens_any boolean_expression CLOSE_PARENS
5928 if ($5 is EmptyStatement)
5929 Warning_EmptyStatement (GetLocation ($5));
5931 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5932 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5934 | IF open_parens_any boolean_expression CLOSE_PARENS
5935 embedded_statement ELSE embedded_statement
5937 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5938 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5940 if ($5 is EmptyStatement)
5941 Warning_EmptyStatement (GetLocation ($5));
5942 if ($7 is EmptyStatement)
5943 Warning_EmptyStatement (GetLocation ($7));
5945 | IF open_parens_any boolean_expression error
5947 Error_SyntaxError (yyToken);
5949 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5950 lbag.AddStatement ($$, GetLocation ($2));
5955 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5957 start_block (GetLocation ($5));
5959 opt_switch_sections CLOSE_BRACE
5961 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5962 end_block (GetLocation ($8));
5963 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5965 | SWITCH open_parens_any expression error
5967 Error_SyntaxError (yyToken);
5969 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5970 lbag.AddStatement ($$, GetLocation ($2));
5977 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5984 | switch_sections switch_section
5987 Error_SyntaxError (yyToken);
5992 : switch_labels statement_list
5998 var label = (SwitchLabel) $1;
5999 label.SectionStart = true;
6000 current_block.AddStatement (label);
6002 | switch_labels switch_label
6004 current_block.AddStatement ((Statement) $2);
6009 : CASE constant_expression COLON
6011 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6012 lbag.AddLocation ($$, GetLocation ($3));
6014 | CASE constant_expression error
6016 Error_SyntaxError (yyToken);
6017 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6020 | CASE pattern_expr_invocation COLON
6022 if (lang_version != LanguageVersion.Experimental)
6023 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6025 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6026 PatternMatching = true
6028 lbag.AddLocation ($$, GetLocation ($3));
6033 $$ = new SwitchLabel (null, GetLocation ($1));
6045 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6047 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6048 Warning_EmptyStatement (GetLocation ($5));
6050 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6051 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6053 | WHILE open_parens_any boolean_expression error
6055 Error_SyntaxError (yyToken);
6057 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6058 lbag.AddStatement ($$, GetLocation ($2));
6063 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6065 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6066 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6068 | DO embedded_statement error
6070 Error_SyntaxError (yyToken);
6071 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6073 | DO embedded_statement WHILE open_parens_any boolean_expression error
6075 Error_SyntaxError (yyToken);
6077 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6078 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6083 : FOR open_parens_any
6085 start_block (GetLocation ($2));
6086 current_block.IsCompilerGenerated = true;
6087 For f = new For (GetLocation ($1));
6088 current_block.AddStatement (f);
6097 // Has to use be extra rule to recover started block
6099 : opt_for_initializer SEMICOLON
6101 ((For) $0).Initializer = (Statement) $1;
6103 // Pass the "For" object to the iterator_part4
6104 oob_stack.Push ($0);
6106 for_condition_and_iterator_part
6109 var locations = (Tuple<Location,Location>) $4;
6111 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6112 Warning_EmptyStatement (GetLocation ($5));
6115 f.Statement = (Statement) $5;
6116 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6118 $$ = end_block (GetLocation ($2));
6122 Error_SyntaxError (yyToken);
6123 $$ = end_block (current_block.StartLocation);
6127 for_condition_and_iterator_part
6128 : opt_for_condition SEMICOLON
6130 For f = (For) oob_stack.Peek ();
6131 f.Condition = (BooleanExpression) $1;
6134 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6137 // Handle errors in the case of opt_for_condition being followed by
6138 // a close parenthesis
6139 | opt_for_condition close_parens_close_brace {
6140 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6141 For f = (For) oob_stack.Peek ();
6142 f.Condition = (BooleanExpression) $1;
6143 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6148 : opt_for_iterator CLOSE_PARENS {
6149 For f = (For) oob_stack.Peek ();
6150 f.Iterator = (Statement) $1;
6151 $$ = GetLocation ($2);
6153 | opt_for_iterator CLOSE_BRACE {
6154 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6155 For f = (For) oob_stack.Peek ();
6156 f.Iterator = (Statement) $1;
6157 $$ = GetLocation ($2);
6161 close_parens_close_brace
6163 | CLOSE_BRACE { lexer.putback ('}'); }
6167 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6172 : variable_type identifier_inside_body
6174 var lt = (LocatedToken) $2;
6175 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6176 current_block.AddLocalName (li);
6177 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6179 opt_local_variable_initializer opt_variable_declarators
6181 $$ = current_variable;
6183 lbag.AddLocation (current_variable, PopLocation ());
6185 current_variable = null;
6187 | statement_expression_list
6191 : /* empty */ { $$ = null; }
6192 | boolean_expression
6196 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6201 : statement_expression_list
6204 statement_expression_list
6205 : statement_expression
6206 | statement_expression_list COMMA statement_expression
6208 var sl = $1 as StatementList;
6210 sl = new StatementList ((Statement) $1, (Statement) $3);
6211 lbag.AddStatement (sl, GetLocation ($2));
6213 sl.Add ((Statement) $3);
6214 lbag.AppendTo (sl, GetLocation ($2));
6222 : FOREACH open_parens_any type error
6224 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6226 start_block (GetLocation ($2));
6227 current_block.IsCompilerGenerated = true;
6229 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6230 current_block.AddStatement (f);
6232 lbag.AddStatement (f, GetLocation ($2));
6233 $$ = end_block (GetLocation ($4));
6235 | FOREACH open_parens_any type identifier_inside_body error
6237 Error_SyntaxError (yyToken);
6239 start_block (GetLocation ($2));
6240 current_block.IsCompilerGenerated = true;
6242 var lt = (LocatedToken) $4;
6243 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6244 current_block.AddLocalName (li);
6246 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6247 current_block.AddStatement (f);
6249 lbag.AddStatement (f, GetLocation ($2));
6250 $$ = end_block (GetLocation ($5));
6252 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6254 start_block (GetLocation ($2));
6255 current_block.IsCompilerGenerated = true;
6257 var lt = (LocatedToken) $4;
6258 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6259 current_block.AddLocalName (li);
6264 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6265 Warning_EmptyStatement (GetLocation ($9));
6267 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6268 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6269 end_block (GetLocation ($7));
6277 | continue_statement
6287 $$ = new Break (GetLocation ($1));
6288 lbag.AddStatement ($$, GetLocation ($2));
6293 : CONTINUE SEMICOLON
6295 $$ = new Continue (GetLocation ($1));
6296 lbag.AddStatement ($$, GetLocation ($2));
6300 Error_SyntaxError (yyToken);
6301 $$ = new Continue (GetLocation ($1));
6306 : GOTO identifier_inside_body SEMICOLON
6308 var lt = (LocatedToken) $2;
6309 $$ = new Goto (lt.Value, GetLocation ($1));
6310 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6312 | GOTO CASE constant_expression SEMICOLON
6314 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6315 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6317 | GOTO DEFAULT SEMICOLON
6319 $$ = new GotoDefault (GetLocation ($1));
6320 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6325 : RETURN opt_expression SEMICOLON
6327 $$ = new Return ((Expression) $2, GetLocation ($1));
6328 lbag.AddStatement ($$, GetLocation ($3));
6330 | RETURN expression error
6332 Error_SyntaxError (yyToken);
6333 $$ = new Return ((Expression) $2, GetLocation ($1));
6337 Error_SyntaxError (yyToken);
6338 $$ = new Return (null, GetLocation ($1));
6343 : THROW opt_expression SEMICOLON
6345 $$ = new Throw ((Expression) $2, GetLocation ($1));
6346 lbag.AddStatement ($$, GetLocation ($3));
6348 | THROW expression error
6350 Error_SyntaxError (yyToken);
6351 $$ = new Throw ((Expression) $2, GetLocation ($1));
6355 Error_SyntaxError (yyToken);
6356 $$ = new Throw (null, GetLocation ($1));
6361 : identifier_inside_body RETURN opt_expression SEMICOLON
6363 var lt = (LocatedToken) $1;
6364 string s = lt.Value;
6366 report.Error (1003, lt.Location, "; expected");
6367 } else if ($3 == null) {
6368 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6369 } else if (lang_version == LanguageVersion.ISO_1){
6370 FeatureIsNotAvailable (lt.Location, "iterators");
6373 current_block.Explicit.RegisterIteratorYield ();
6374 $$ = new Yield ((Expression) $3, lt.Location);
6375 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6377 | identifier_inside_body RETURN expression error
6379 Error_SyntaxError (yyToken);
6381 var lt = (LocatedToken) $1;
6382 string s = lt.Value;
6384 report.Error (1003, lt.Location, "; expected");
6385 } else if ($3 == null) {
6386 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6387 } else if (lang_version == LanguageVersion.ISO_1){
6388 FeatureIsNotAvailable (lt.Location, "iterators");
6391 current_block.Explicit.RegisterIteratorYield ();
6392 $$ = new Yield ((Expression) $3, lt.Location);
6393 lbag.AddStatement ($$, GetLocation ($2));
6395 | identifier_inside_body BREAK SEMICOLON
6397 var lt = (LocatedToken) $1;
6398 string s = lt.Value;
6400 report.Error (1003, lt.Location, "; expected");
6401 } else if (lang_version == LanguageVersion.ISO_1){
6402 FeatureIsNotAvailable (lt.Location, "iterators");
6405 current_block.ParametersBlock.TopBlock.IsIterator = true;
6406 $$ = new YieldBreak (lt.Location);
6407 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6417 : TRY block catch_clauses
6419 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6421 | TRY block FINALLY block
6423 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6424 lbag.AddStatement ($$, GetLocation ($3));
6426 | TRY block catch_clauses FINALLY block
6428 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6429 lbag.AddStatement ($$, GetLocation ($4));
6433 Error_SyntaxError (1524, yyToken);
6434 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6441 var l = new List<Catch> (2);
6446 | catch_clauses catch_clause
6448 var l = (List<Catch>) $1;
6450 Catch c = (Catch) $2;
6451 var prev_catch = l [l.Count - 1];
6452 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6453 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6463 | identifier_inside_body
6467 : CATCH opt_catch_filter block
6469 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6470 c.Filter = (CatchFilterExpression) $2;
6473 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6475 start_block (GetLocation ($2));
6476 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6477 c.TypeExpression = (FullNamedExpression) $3;
6480 var lt = (LocatedToken) $4;
6481 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6482 current_block.AddLocalName (c.Variable);
6485 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6487 lexer.parsing_catch_when = true;
6489 opt_catch_filter_or_error
6491 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6494 | CATCH open_parens_any error
6496 if (yyToken == Token.CLOSE_PARENS) {
6497 report.Error (1015, lexer.Location,
6498 "A type that derives from `System.Exception', `object', or `string' expected");
6500 Error_SyntaxError (yyToken);
6503 $$ = new Catch (null, GetLocation ($1));
6507 opt_catch_filter_or_error
6508 : opt_catch_filter block_prepared
6514 end_block (Location.Null);
6515 Error_SyntaxError (yyToken);
6522 lexer.parsing_catch_when = false;
6526 lexer.parsing_catch_when = false;
6528 open_parens_any expression CLOSE_PARENS
6530 if (lang_version <= LanguageVersion.V_5)
6531 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6533 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6534 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6541 $$ = new Checked ((Block) $2, GetLocation ($1));
6548 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6555 if (!settings.Unsafe)
6556 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6558 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6563 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6565 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6566 Warning_EmptyStatement (GetLocation ($5));
6568 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6569 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6571 | LOCK open_parens_any expression error
6573 Error_SyntaxError (yyToken);
6575 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6576 lbag.AddStatement ($$, GetLocation ($2));
6581 : FIXED open_parens_any variable_type identifier_inside_body
6583 start_block (GetLocation ($2));
6585 current_block.IsCompilerGenerated = true;
6586 var lt = (LocatedToken) $4;
6587 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6588 current_block.AddLocalName (li);
6589 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6591 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6593 $$ = current_variable;
6594 current_variable = null;
6598 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6599 Warning_EmptyStatement (GetLocation ($10));
6601 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6602 current_block.AddStatement (f);
6603 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6604 $$ = end_block (GetLocation ($8));
6609 : USING open_parens_any variable_type identifier_inside_body
6611 start_block (GetLocation ($2));
6613 current_block.IsCompilerGenerated = true;
6614 var lt = (LocatedToken) $4;
6615 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6616 current_block.AddLocalName (li);
6617 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6619 using_initialization CLOSE_PARENS
6621 $$ = current_variable;
6622 current_variable = null;
6626 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6627 Warning_EmptyStatement (GetLocation ($9));
6629 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6630 current_block.AddStatement (u);
6631 $$ = end_block (GetLocation ($7));
6633 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6635 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6636 Warning_EmptyStatement (GetLocation ($5));
6638 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6639 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6641 | USING open_parens_any expression error
6643 Error_SyntaxError (yyToken);
6645 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6646 lbag.AddStatement ($$, GetLocation ($2));
6650 using_initialization
6651 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6654 // It has to be here for the parent to safely restore artificial block
6655 Error_SyntaxError (yyToken);
6659 using_or_fixed_variable_initializer
6662 Error_MissingInitializer (lexer.Location);
6664 | ASSIGN variable_initializer
6666 current_variable.Initializer = (Expression) $2;
6667 $$ = current_variable;
6675 : first_from_clause query_body
6677 lexer.query_parsing = false;
6679 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6681 from.Tail.Next = (Linq.AQueryClause)$2;
6684 current_block.SetEndLocation (lexer.Location);
6685 current_block = current_block.Parent;
6687 | nested_from_clause query_body
6689 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6691 from.Tail.Next = (Linq.AQueryClause)$2;
6694 current_block.SetEndLocation (lexer.Location);
6695 current_block = current_block.Parent;
6698 // Bubble up COMPLETE_COMPLETION productions
6699 | first_from_clause COMPLETE_COMPLETION {
6700 lexer.query_parsing = false;
6703 current_block.SetEndLocation (lexer.Location);
6704 current_block = current_block.Parent;
6706 | nested_from_clause COMPLETE_COMPLETION {
6708 current_block.SetEndLocation (lexer.Location);
6709 current_block = current_block.Parent;
6714 : FROM_FIRST identifier_inside_body IN expression
6716 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6718 var lt = (LocatedToken) $2;
6719 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6720 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6721 lbag.AddLocation (clause, GetLocation ($3));
6722 $$ = new Linq.QueryExpression (clause);
6724 | FROM_FIRST type identifier_inside_body IN expression
6726 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6728 var lt = (LocatedToken) $3;
6729 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6730 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6731 IdentifierType = (FullNamedExpression)$2
6733 lbag.AddLocation (clause, GetLocation ($4));
6734 $$ = new Linq.QueryExpression (clause);
6739 : FROM identifier_inside_body IN expression
6741 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6743 var lt = (LocatedToken) $2;
6744 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6745 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6746 lbag.AddLocation (clause, GetLocation ($3));
6747 $$ = new Linq.QueryExpression (clause);
6749 | FROM type identifier_inside_body IN expression
6751 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6753 var lt = (LocatedToken) $3;
6754 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6755 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6756 IdentifierType = (FullNamedExpression)$2
6758 lbag.AddLocation (clause, GetLocation ($4));
6759 $$ = new Linq.QueryExpression (clause);
6764 : FROM identifier_inside_body IN
6766 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6770 var lt = (LocatedToken) $2;
6771 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6772 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6774 current_block.SetEndLocation (lexer.Location);
6775 current_block = current_block.Parent;
6777 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6778 lbag.AddLocation ($$, GetLocation ($3));
6780 | FROM type identifier_inside_body IN
6782 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6786 var lt = (LocatedToken) $3;
6787 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6789 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6790 IdentifierType = (FullNamedExpression)$2
6793 current_block.SetEndLocation (lexer.Location);
6794 current_block = current_block.Parent;
6796 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6798 lbag.AddLocation ($$, GetLocation ($4));
6803 : query_body_clauses select_or_group_clause opt_query_continuation
6805 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6808 head.Next = (Linq.AQueryClause)$3;
6811 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6812 clause.Tail.Next = head;
6818 | select_or_group_clause opt_query_continuation
6820 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6823 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6824 clause.Tail.Next = head;
6830 | query_body_clauses COMPLETE_COMPLETION
6831 | query_body_clauses error
6833 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6838 Error_SyntaxError (yyToken);
6843 select_or_group_clause
6846 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6850 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6852 current_block.SetEndLocation (lexer.Location);
6853 current_block = current_block.Parent;
6857 if (linq_clause_blocks == null)
6858 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6860 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6861 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6865 current_block.SetEndLocation (lexer.Location);
6866 current_block = current_block.Parent;
6868 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6872 var obj = (object[]) $5;
6874 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6875 lbag.AddLocation ($$, (Location) obj[1]);
6877 current_block.SetEndLocation (lexer.Location);
6878 current_block = current_block.Parent;
6883 : BY expression_or_error
6885 $$ = new object[] { $2, GetLocation ($1) };
6889 Error_SyntaxError (yyToken);
6890 $$ = new object[2] { null, Location.Null };
6896 | query_body_clauses query_body_clause
6898 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6912 : LET identifier_inside_body ASSIGN
6914 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6918 var lt = (LocatedToken) $2;
6919 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6920 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6921 lbag.AddLocation ($$, GetLocation ($3));
6923 current_block.SetEndLocation (lexer.Location);
6924 current_block = current_block.Parent;
6926 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6933 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6937 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6939 current_block.SetEndLocation (lexer.Location);
6940 current_block = current_block.Parent;
6945 : JOIN identifier_inside_body IN
6947 if (linq_clause_blocks == null)
6948 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6950 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6951 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6953 expression_or_error ON
6955 current_block.SetEndLocation (lexer.Location);
6956 current_block = current_block.Parent;
6958 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6959 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6961 expression_or_error EQUALS
6963 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6964 current_block.SetEndLocation (lexer.Location);
6965 current_block = current_block.Parent;
6967 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6969 expression_or_error opt_join_into
6971 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6972 current_block.SetEndLocation (lexer.Location);
6974 var outer_selector = linq_clause_blocks.Pop ();
6975 var block = linq_clause_blocks.Pop ();
6977 var lt = (LocatedToken) $2;
6978 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6979 Linq.RangeVariable into;
6983 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6984 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6987 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6989 var parent = block.Parent;
6990 while (parent is Linq.QueryBlock) {
6991 parent = parent.Parent;
6993 current_block.Parent = parent;
6995 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6997 lt = (LocatedToken) $12;
6998 into = new Linq.RangeVariable (lt.Value, lt.Location);
7000 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
7001 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7004 current_block = block.Parent;
7005 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7007 | JOIN type identifier_inside_body IN
7009 if (linq_clause_blocks == null)
7010 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7012 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7013 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7015 expression_or_error ON
7017 current_block.SetEndLocation (lexer.Location);
7018 current_block = current_block.Parent;
7020 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7021 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7023 expression_or_error EQUALS
7025 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7026 current_block.SetEndLocation (lexer.Location);
7027 current_block = current_block.Parent;
7029 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7031 expression_or_error opt_join_into
7033 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7034 current_block.SetEndLocation (lexer.Location);
7036 var outer_selector = linq_clause_blocks.Pop ();
7037 var block = linq_clause_blocks.Pop ();
7039 var lt = (LocatedToken) $3;
7040 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7041 Linq.RangeVariable into;
7045 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7046 IdentifierType = (FullNamedExpression)$2
7048 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7051 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7053 var parent = block.Parent;
7054 while (parent is Linq.QueryBlock) {
7055 parent = parent.Parent;
7057 current_block.Parent = parent;
7059 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7061 lt = (LocatedToken) $13;
7062 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7064 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7065 IdentifierType = (FullNamedExpression)$2
7069 current_block = block.Parent;
7070 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7076 | INTO identifier_inside_body
7085 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7089 current_block.SetEndLocation (lexer.Location);
7090 current_block = current_block.Parent;
7100 current_block.SetEndLocation (lexer.Location);
7101 current_block = current_block.Parent;
7103 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7107 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7114 | orderings_then_by COMMA
7116 current_block.SetEndLocation (lexer.Location);
7117 current_block = current_block.Parent;
7119 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7123 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7131 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7133 | expression ASCENDING
7135 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7136 lbag.AddLocation ($$, GetLocation ($2));
7138 | expression DESCENDING
7140 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7141 lbag.AddLocation ($$, GetLocation ($2));
7148 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7150 | expression ASCENDING
7152 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7153 lbag.AddLocation ($$, GetLocation ($2));
7155 | expression DESCENDING
7157 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7158 lbag.AddLocation ($$, GetLocation ($2));
7163 opt_query_continuation
7165 | INTO identifier_inside_body
7167 // query continuation block is not linked with query block but with block
7168 // before. This means each query can use same range variable names for
7169 // different identifiers.
7171 current_block.SetEndLocation (GetLocation ($1));
7172 current_block = current_block.Parent;
7174 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7176 if (linq_clause_blocks == null)
7177 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7179 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7183 var current_block = linq_clause_blocks.Pop ();
7184 var lt = (LocatedToken) $2;
7185 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7186 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7187 next = (Linq.AQueryClause)$4
7193 // Support for using the compiler as an interactive parser
7195 // The INTERACTIVE_PARSER token is first sent to parse our
7196 // productions; If the result is a Statement, the parsing
7197 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7198 // to setup the blocks in advance.
7200 // This setup is here so that in the future we can add
7201 // support for other constructs (type parsing, namespaces, etc)
7202 // that do not require a block to be setup in advance
7206 : EVAL_STATEMENT_PARSER EOF
7207 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7208 | EVAL_STATEMENT_PARSER
7210 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7212 // (ref object retval)
7213 Parameter [] mpar = new Parameter [1];
7214 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7216 ParametersCompiled pars = new ParametersCompiled (mpar);
7217 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7218 if (settings.Unsafe)
7219 mods |= Modifiers.UNSAFE;
7221 current_local_parameters = pars;
7222 var method = new InteractiveMethod (
7224 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7228 current_type.AddMember (method);
7229 oob_stack.Push (method);
7231 interactive_async = false;
7233 ++lexer.parsing_block;
7234 start_block (lexer.Location);
7236 interactive_statement_list opt_COMPLETE_COMPLETION
7238 --lexer.parsing_block;
7239 var method = (InteractiveMethod) oob_stack.Pop ();
7240 method.Block = (ToplevelBlock) end_block(lexer.Location);
7242 if (interactive_async == true) {
7243 method.ChangeToAsync ();
7246 InteractiveResult = (Class) pop_current_class ();
7247 current_local_parameters = null;
7249 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7252 interactive_compilation_unit
7253 : opt_extern_alias_directives opt_using_directives
7254 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7257 opt_COMPLETE_COMPLETION
7259 | COMPLETE_COMPLETION
7262 close_brace_or_complete_completion
7264 | COMPLETE_COMPLETION
7268 // XML documentation code references micro parser
7270 documentation_parsing
7273 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7278 : doc_type_declaration_name opt_doc_method_sig
7280 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7282 | builtin_types opt_doc_method_sig
7284 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7285 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7288 | VOID opt_doc_method_sig
7290 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7291 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7294 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7296 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7297 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7298 var lt = (LocatedToken) $3;
7299 $$ = new MemberName (lt.Value);
7301 | doc_type_declaration_name DOT THIS
7303 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7305 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7307 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7309 opt_doc_parameters CLOSE_BRACKET
7311 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7312 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7314 | EXPLICIT OPERATOR type opt_doc_method_sig
7316 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7317 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7318 module.DocumentationBuilder.ParsedParameters = p;
7319 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7322 | IMPLICIT OPERATOR type opt_doc_method_sig
7324 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7325 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7326 module.DocumentationBuilder.ParsedParameters = p;
7327 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7330 | OPERATOR overloadable_operator opt_doc_method_sig
7332 var p = (List<DocumentationParameter>)$3;
7333 module.DocumentationBuilder.ParsedParameters = p;
7334 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7339 doc_type_declaration_name
7340 : type_declaration_name
7341 | doc_type_declaration_name DOT type_declaration_name
7343 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7351 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7353 opt_doc_parameters CLOSE_PARENS
7362 $$ = new List<DocumentationParameter> (0);
7370 var parameters = new List<DocumentationParameter> ();
7371 parameters.Add ((DocumentationParameter) $1);
7374 | doc_parameters COMMA doc_parameter
7376 var parameters = $1 as List<DocumentationParameter>;
7377 parameters.Add ((DocumentationParameter) $3);
7383 : opt_parameter_modifier parameter_type
7386 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7388 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7395 // A class used to hold info about an operator declarator
7397 class OperatorDeclaration {
7398 public readonly Operator.OpType optype;
7399 public readonly FullNamedExpression ret_type;
7400 public readonly Location location;
7402 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7405 this.ret_type = ret_type;
7406 this.location = location;
7410 void Error_ExpectingTypeName (Expression expr)
7412 if (expr is Invocation){
7413 report.Error (1002, expr.Location, "Expecting `;'");
7415 expr.Error_InvalidExpressionStatement (report);
7419 void Error_ParameterModifierNotValid (string modifier, Location loc)
7421 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7425 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7427 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7428 Parameter.GetModifierSignature (mod));
7431 void Error_TypeExpected (Location loc)
7433 report.Error (1031, loc, "Type expected");
7436 void Error_UnsafeCodeNotAllowed (Location loc)
7438 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7441 void Warning_EmptyStatement (Location loc)
7443 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7446 void Error_NamedArgumentExpected (NamedArgument a)
7448 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7451 void Error_MissingInitializer (Location loc)
7453 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7456 object Error_AwaitAsIdentifier (object token)
7459 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7460 return new LocatedToken ("await", GetLocation (token));
7466 void push_current_container (TypeDefinition tc, object partial_token)
7468 if (module.Evaluator != null){
7469 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7473 undo.AddTypeContainer (current_container, tc);
7476 if (partial_token != null)
7477 current_container.AddPartial (tc);
7479 current_container.AddTypeContainer (tc);
7481 ++lexer.parsing_declaration;
7482 current_container = tc;
7486 TypeContainer pop_current_class ()
7488 var retval = current_container;
7490 current_container = current_container.Parent;
7491 current_type = current_type.Parent as TypeDefinition;
7496 [System.Diagnostics.Conditional ("FULL_AST")]
7497 void StoreModifierLocation (object token, Location loc)
7502 if (mod_locations == null)
7503 mod_locations = new List<Tuple<Modifiers, Location>> ();
7505 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7508 [System.Diagnostics.Conditional ("FULL_AST")]
7509 void PushLocation (Location loc)
7511 if (location_stack == null)
7512 location_stack = new Stack<Location> ();
7514 location_stack.Push (loc);
7517 Location PopLocation ()
7519 if (location_stack == null)
7520 return Location.Null;
7522 return location_stack.Pop ();
7525 string CheckAttributeTarget (int token, string a, Location l)
7528 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7532 if (!Tokenizer.IsValidIdentifier (a)) {
7533 Error_SyntaxError (token);
7535 report.Warning (658, 1, l,
7536 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7539 return string.Empty;
7542 static bool IsUnaryOperator (Operator.OpType op)
7546 case Operator.OpType.LogicalNot:
7547 case Operator.OpType.OnesComplement:
7548 case Operator.OpType.Increment:
7549 case Operator.OpType.Decrement:
7550 case Operator.OpType.True:
7551 case Operator.OpType.False:
7552 case Operator.OpType.UnaryPlus:
7553 case Operator.OpType.UnaryNegation:
7559 void syntax_error (Location l, string msg)
7561 report.Error (1003, l, "Syntax error, " + msg);
7566 public Tokenizer Lexer {
7572 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7573 : this (reader, file, file.Compiler.Report, session)
7577 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7580 current_container = current_namespace = file;
7582 this.module = file.Module;
7583 this.compiler = file.Compiler;
7584 this.settings = compiler.Settings;
7585 this.report = report;
7587 lang_version = settings.Version;
7588 yacc_verbose_flag = settings.VerboseParserFlag;
7589 doc_support = settings.DocumentationFile != null;
7590 lexer = new Tokenizer (reader, file, session, report);
7591 oob_stack = new Stack<object> ();
7592 lbag = session.LocationsBag;
7593 use_global_stacks = session.UseJayGlobalArrays;
7594 parameters_bucket = session.ParametersStack;
7597 public void parse ()
7599 eof_token = Token.EOF;
7602 if (yacc_verbose_flag > 1)
7603 yyparse (lexer, new yydebug.yyDebugSimple ());
7607 Tokenizer tokenizer = lexer as Tokenizer;
7608 tokenizer.cleanup ();
7609 } catch (Exception e){
7610 if (e is yyParser.yyUnexpectedEof) {
7611 Error_SyntaxError (yyToken);
7612 UnexpectedEOF = true;
7616 if (e is yyParser.yyException) {
7617 if (report.Errors == 0)
7618 report.Error (-25, lexer.Location, "Parsing error");
7620 // Used by compiler-tester to test internal errors
7621 if (yacc_verbose_flag > 0 || e is FatalException)
7624 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7629 void CheckToken (int error, int yyToken, string msg, Location loc)
7631 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7632 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7634 report.Error (error, loc, msg);
7637 string ConsumeStoredComment ()
7639 string s = tmpComment;
7641 Lexer.doc_state = XmlCommentState.Allowed;
7645 void FeatureIsNotAvailable (Location loc, string feature)
7647 report.FeatureIsNotAvailable (compiler, loc, feature);
7650 Location GetLocation (object obj)
7652 var lt = obj as LocatedToken;
7656 var mn = obj as MemberName;
7660 var expr = obj as Expression;
7662 return expr.Location;
7664 return lexer.Location;
7667 void start_block (Location loc)
7669 if (current_block == null) {
7670 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7671 parsing_anonymous_method = false;
7672 } else if (parsing_anonymous_method) {
7673 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7674 parsing_anonymous_method = false;
7676 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7681 end_block (Location loc)
7683 Block retval = current_block.Explicit;
7684 retval.SetEndLocation (loc);
7685 current_block = retval.Parent;
7689 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7691 oob_stack.Push (current_anonymous_method);
7692 oob_stack.Push (current_local_parameters);
7693 oob_stack.Push (current_variable);
7694 oob_stack.Push (async_block);
7696 current_local_parameters = parameters;
7698 if (lang_version <= LanguageVersion.ISO_2)
7699 FeatureIsNotAvailable (loc, "lambda expressions");
7701 current_anonymous_method = new LambdaExpression (loc);
7703 if (lang_version == LanguageVersion.ISO_1)
7704 FeatureIsNotAvailable (loc, "anonymous methods");
7706 current_anonymous_method = new AnonymousMethodExpression (loc);
7709 async_block = isAsync;
7710 // Force the next block to be created as a ToplevelBlock
7711 parsing_anonymous_method = true;
7715 * Completes the anonymous method processing, if lambda_expr is null, this
7716 * means that we have a Statement instead of an Expression embedded
7718 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7720 AnonymousMethodExpression retval;
7723 anon_block.IsAsync = true;
7725 current_anonymous_method.Block = anon_block;
7726 retval = current_anonymous_method;
7728 async_block = (bool) oob_stack.Pop ();
7729 current_variable = (BlockVariable) oob_stack.Pop ();
7730 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7731 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7736 void Error_SyntaxError (int token)
7738 Error_SyntaxError (0, token);
7741 void Error_SyntaxError (int error_code, int token)
7743 Error_SyntaxError (error_code, token, "Unexpected symbol");
7746 void Error_SyntaxError (int error_code, int token, string msg)
7748 Lexer.CompleteOnEOF = false;
7750 // An error message has been reported by tokenizer
7751 if (token == Token.ERROR)
7754 // Avoid duplicit error message after unterminated string literals
7755 if (token == Token.LITERAL && lexer.Location.Column == 0)
7758 string symbol = GetSymbolName (token);
7759 string expecting = GetExpecting ();
7760 var loc = lexer.Location - symbol.Length;
7762 if (error_code == 0) {
7763 if (expecting == "`identifier'") {
7764 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7765 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7770 expecting = "identifier";
7771 } else if (expecting == "`)'") {
7778 if (string.IsNullOrEmpty (expecting))
7779 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7781 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7784 string GetExpecting ()
7786 int [] tokens = yyExpectingTokens (yyExpectingState);
7787 var names = new List<string> (tokens.Length);
7788 bool has_type = false;
7789 bool has_identifier = false;
7790 for (int i = 0; i < tokens.Length; i++){
7791 int token = tokens [i];
7792 has_identifier |= token == Token.IDENTIFIER;
7794 string name = GetTokenName (token);
7795 if (name == "<internal>")
7798 has_type |= name == "type";
7799 if (names.Contains (name))
7806 // Too many tokens to enumerate
7808 if (names.Count > 8)
7811 if (has_type && has_identifier)
7812 names.Remove ("identifier");
7814 if (names.Count == 1)
7815 return "`" + GetTokenName (tokens [0]) + "'";
7817 StringBuilder sb = new StringBuilder ();
7819 int count = names.Count;
7820 for (int i = 0; i < count; i++){
7821 bool last = i + 1 == count;
7825 sb.Append (names [i]);
7826 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7828 return sb.ToString ();
7832 string GetSymbolName (int token)
7836 return ((Constant)lexer.Value).GetValue ().ToString ();
7837 case Token.IDENTIFIER:
7838 return ((LocatedToken)lexer.Value).Value;
7880 case Token.BITWISE_AND:
7882 case Token.BITWISE_OR:
7896 case Token.OP_SHIFT_LEFT:
7898 case Token.OP_SHIFT_RIGHT:
7918 case Token.OP_COALESCING:
7920 case Token.OP_MULT_ASSIGN:
7922 case Token.OP_DIV_ASSIGN:
7924 case Token.OP_MOD_ASSIGN:
7926 case Token.OP_ADD_ASSIGN:
7928 case Token.OP_SUB_ASSIGN:
7930 case Token.OP_SHIFT_LEFT_ASSIGN:
7932 case Token.OP_SHIFT_RIGHT_ASSIGN:
7934 case Token.OP_AND_ASSIGN:
7936 case Token.OP_XOR_ASSIGN:
7938 case Token.OP_OR_ASSIGN:
7942 return GetTokenName (token);
7945 static string GetTokenName (int token)
7948 case Token.ABSTRACT:
7970 case Token.CONTINUE:
7974 case Token.DELEGATE:
7984 case Token.EXPLICIT:
7987 case Token.EXTERN_ALIAS:
8003 case Token.IMPLICIT:
8007 case Token.INTERFACE:
8009 case Token.INTERNAL:
8015 case Token.NAMESPACE:
8021 case Token.OPERATOR:
8025 case Token.OVERRIDE:
8031 case Token.PROTECTED:
8035 case Token.READONLY:
8047 case Token.STACKALLOC:
8048 return "stackalloc";
8065 case Token.UNCHECKED:
8073 case Token.VOLATILE:
8081 case Token.REFVALUE:
8082 return "__refvalue";
8092 case Token.FROM_FIRST:
8110 case Token.ASCENDING:
8112 case Token.DESCENDING:
8113 return "descending";
8120 case Token.OPEN_BRACE:
8122 case Token.CLOSE_BRACE:
8124 case Token.OPEN_BRACKET:
8125 case Token.OPEN_BRACKET_EXPR:
8127 case Token.CLOSE_BRACKET:
8129 case Token.OPEN_PARENS_CAST:
8130 case Token.OPEN_PARENS_LAMBDA:
8131 case Token.OPEN_PARENS:
8133 case Token.CLOSE_PARENS:
8139 case Token.DEFAULT_COLON:
8143 case Token.SEMICOLON:
8149 case Token.INTERPOLATED_STRING_END:
8151 case Token.INTERPOLATED_STRING:
8160 case Token.BITWISE_AND:
8161 case Token.BITWISE_OR:
8168 case Token.OP_SHIFT_LEFT:
8169 case Token.OP_SHIFT_RIGHT:
8177 case Token.OP_COALESCING:
8178 case Token.OP_MULT_ASSIGN:
8179 case Token.OP_DIV_ASSIGN:
8180 case Token.OP_MOD_ASSIGN:
8181 case Token.OP_ADD_ASSIGN:
8182 case Token.OP_SUB_ASSIGN:
8183 case Token.OP_SHIFT_LEFT_ASSIGN:
8184 case Token.OP_SHIFT_RIGHT_ASSIGN:
8185 case Token.OP_AND_ASSIGN:
8186 case Token.OP_XOR_ASSIGN:
8187 case Token.OP_OR_ASSIGN:
8188 case Token.INTERR_OPERATOR:
8189 return "<operator>";
8211 case Token.OP_GENERICS_LT:
8212 case Token.GENERIC_DIMENSION:
8214 case Token.OP_GENERICS_GT:
8217 case Token.INTERR_NULLABLE:
8219 case Token.DOUBLE_COLON:
8223 case Token.IDENTIFIER:
8225 return "identifier";
8228 return "end-of-file";
8230 // All of these are internal.
8233 case Token.FIRST_KEYWORD:
8234 case Token.EVAL_COMPILATION_UNIT_PARSER:
8235 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8236 case Token.EVAL_STATEMENT_PARSER:
8237 case Token.LAST_KEYWORD:
8238 case Token.GENERATE_COMPLETION:
8239 case Token.COMPLETE_COMPLETION:
8240 return "<internal>";
8242 // A bit more robust.
8244 return yyNames [token];