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 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2410 current_type.AddConstructor (c);
2411 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2415 // start block here, so possible anonymous methods inside
2416 // constructor initializer can get correct parent block
2418 start_block (lexer.Location);
2420 opt_constructor_initializer
2423 var c = (Constructor) $8;
2424 c.Initializer = (ConstructorInitializer) $9;
2427 report.Error (514, c.Location,
2428 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2429 c.GetSignatureForError ());
2439 | SEMICOLON { current_block = null; $$ = null; }
2442 opt_constructor_initializer
2444 | constructor_initializer
2447 constructor_initializer
2448 : COLON BASE OPEN_PARENS
2450 ++lexer.parsing_block;
2452 opt_argument_list CLOSE_PARENS
2454 --lexer.parsing_block;
2455 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2456 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2458 | COLON THIS OPEN_PARENS
2460 ++lexer.parsing_block;
2462 opt_argument_list CLOSE_PARENS
2464 --lexer.parsing_block;
2465 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2466 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2470 Error_SyntaxError (yyToken);
2471 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2472 lbag.AddLocation ($$, GetLocation ($1));
2476 Error_SyntaxError (yyToken);
2481 destructor_declaration
2482 : opt_attributes opt_modifiers TILDE
2485 tmpComment = Lexer.consume_doc_comment ();
2486 Lexer.doc_state = XmlCommentState.NotAllowed;
2489 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2491 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2493 var lt = (LocatedToken) $5;
2494 if (lt.Value != current_container.MemberName.Name){
2495 report.Error (574, lt.Location, "Name of destructor must match name of class");
2496 } else if (current_container.Kind != MemberKind.Class){
2497 report.Error (575, lt.Location, "Only class types can contain destructor");
2500 Destructor d = new Destructor (current_type, (Modifiers) $2,
2501 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2503 d.DocComment = ConsumeStoredComment ();
2505 d.Block = (ToplevelBlock) $8;
2506 current_type.AddMember (d);
2507 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2509 current_local_parameters = null;
2516 EVENT type member_declaration_name
2518 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2519 current_type.AddMember (current_event_field);
2521 if (current_event_field.MemberName.ExplicitInterface != null) {
2522 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2523 current_event_field.GetSignatureForError ());
2526 $$ = current_event_field;
2528 opt_event_initializer
2529 opt_event_declarators
2533 current_event_field.DocComment = Lexer.consume_doc_comment ();
2534 Lexer.doc_state = XmlCommentState.Allowed;
2537 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2538 current_event_field = null;
2542 EVENT type member_declaration_name
2545 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2546 current_type.AddMember (current_event);
2547 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2549 lexer.EventParsing = true;
2551 event_accessor_declarations
2553 if (current_container.Kind == MemberKind.Interface)
2554 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2556 lexer.EventParsing = false;
2561 current_event.DocComment = Lexer.consume_doc_comment ();
2562 Lexer.doc_state = XmlCommentState.Allowed;
2565 lbag.AppendToMember (current_event, GetLocation ($9));
2566 current_event = null;
2567 current_local_parameters = null;
2573 Error_SyntaxError (yyToken);
2575 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2579 opt_event_initializer
2583 ++lexer.parsing_block;
2585 event_variable_initializer
2587 --lexer.parsing_block;
2588 current_event_field.Initializer = (Expression) $3;
2592 opt_event_declarators
2600 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2602 | event_declarators event_declarator
2604 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2611 var lt = (LocatedToken) $2;
2612 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2613 lbag.AddLocation ($$, GetLocation ($1));
2615 | COMMA IDENTIFIER ASSIGN
2617 ++lexer.parsing_block;
2619 event_variable_initializer
2621 --lexer.parsing_block;
2622 var lt = (LocatedToken) $2;
2623 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2624 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2628 event_variable_initializer
2630 if (current_container.Kind == MemberKind.Interface) {
2631 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2632 current_event_field.GetSignatureForError ());
2635 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2636 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2637 current_event_field.GetSignatureForError ());
2640 variable_initializer
2646 event_accessor_declarations
2647 : add_accessor_declaration remove_accessor_declaration
2648 | remove_accessor_declaration add_accessor_declaration
2649 | add_accessor_declaration
2651 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2652 current_event.GetSignatureForError ());
2654 | remove_accessor_declaration
2656 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2657 current_event.GetSignatureForError ());
2661 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2666 add_accessor_declaration
2667 : opt_attributes opt_modifiers ADD
2669 if ($2 != ModifierNone) {
2670 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2673 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2674 current_local_parameters = current_event.Add.ParameterInfo;
2676 lbag.AddMember (current_event.Add, mod_locations);
2677 lexer.EventParsing = false;
2679 event_accessor_block
2681 lexer.EventParsing = true;
2683 current_event.Add.Block = (ToplevelBlock) $5;
2685 if (current_container.Kind == MemberKind.Interface) {
2686 report.Error (531, current_event.Add.Block.StartLocation,
2687 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2690 current_local_parameters = null;
2694 remove_accessor_declaration
2695 : opt_attributes opt_modifiers REMOVE
2697 if ($2 != ModifierNone) {
2698 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2701 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2702 current_local_parameters = current_event.Remove.ParameterInfo;
2704 lbag.AddMember (current_event.Remove, mod_locations);
2705 lexer.EventParsing = false;
2707 event_accessor_block
2709 lexer.EventParsing = true;
2711 current_event.Remove.Block = (ToplevelBlock) $5;
2713 if (current_container.Kind == MemberKind.Interface) {
2714 report.Error (531, current_event.Remove.Block.StartLocation,
2715 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2718 current_local_parameters = null;
2722 event_accessor_block
2725 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2731 attributes_without_members
2732 : attribute_sections CLOSE_BRACE
2734 current_type.UnattachedAttributes = (Attributes) $1;
2735 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2736 lexer.putback ('}');
2740 // For full ast try to recover incomplete ambiguous member
2741 // declaration in form on class X { public int }
2743 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2745 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2747 lexer.putback ('}');
2749 lexer.parsing_generic_declaration = false;
2750 FullNamedExpression type = (FullNamedExpression) $3;
2751 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2752 current_type.AddField (current_field);
2760 ENUM type_declaration_name
2764 enumTypeComment = Lexer.consume_doc_comment ();
2769 Lexer.doc_state = XmlCommentState.Allowed;
2771 MemberName name = (MemberName) $4;
2772 if (name.IsGeneric) {
2773 report.Error (1675, name.Location, "Enums cannot have type parameters");
2776 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2778 opt_enum_member_declarations
2780 lexer.parsing_modifiers = true;
2782 // here will be evaluated after CLOSE_BLACE is consumed.
2784 Lexer.doc_state = XmlCommentState.Allowed;
2786 CLOSE_BRACE opt_semicolon
2789 current_container.DocComment = enumTypeComment;
2791 --lexer.parsing_declaration;
2794 // em.DocComment = ev.DocComment;
2796 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2797 $$ = pop_current_class ();
2809 Error_TypeExpected (GetLocation ($1));
2814 opt_enum_member_declarations
2816 | enum_member_declarations
2817 | enum_member_declarations COMMA
2819 lbag.AddLocation ($1, GetLocation ($2));
2823 enum_member_declarations
2824 : enum_member_declaration
2825 | enum_member_declarations COMMA enum_member_declaration
2827 lbag.AddLocation ($1, GetLocation ($2));
2832 enum_member_declaration
2833 : opt_attributes IDENTIFIER
2835 var lt = (LocatedToken) $2;
2836 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2837 ((Enum) current_type).AddEnumMember (em);
2840 em.DocComment = Lexer.consume_doc_comment ();
2841 Lexer.doc_state = XmlCommentState.Allowed;
2846 | opt_attributes IDENTIFIER
2848 ++lexer.parsing_block;
2850 tmpComment = Lexer.consume_doc_comment ();
2851 Lexer.doc_state = XmlCommentState.NotAllowed;
2854 ASSIGN constant_expression
2856 --lexer.parsing_block;
2858 var lt = (LocatedToken) $2;
2859 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2860 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2861 ((Enum) current_type).AddEnumMember (em);
2864 em.DocComment = ConsumeStoredComment ();
2868 | opt_attributes IDENTIFIER error
2870 Error_SyntaxError (yyToken);
2872 var lt = (LocatedToken) $2;
2873 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2874 ((Enum) current_type).AddEnumMember (em);
2877 em.DocComment = Lexer.consume_doc_comment ();
2878 Lexer.doc_state = XmlCommentState.Allowed;
2883 | attributes_without_members
2886 delegate_declaration
2890 member_type type_declaration_name
2893 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2895 opt_formal_parameter_list CLOSE_PARENS
2897 valid_param_mod = 0;
2899 ParametersCompiled p = (ParametersCompiled) $8;
2901 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2903 p.CheckParameters (del);
2905 current_container.AddTypeContainer (del);
2907 current_delegate = del;
2908 lexer.ConstraintsParsing = true;
2910 opt_type_parameter_constraints_clauses
2912 lexer.ConstraintsParsing = false;
2917 current_delegate.DocComment = Lexer.consume_doc_comment ();
2918 Lexer.doc_state = XmlCommentState.Allowed;
2922 current_delegate.SetConstraints ((List<Constraints>) $11);
2923 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2925 $$ = current_delegate;
2927 current_delegate = null;
2935 if (lang_version < LanguageVersion.ISO_2)
2936 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2938 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2942 namespace_or_type_expr
2944 | qualified_alias_member IDENTIFIER opt_type_argument_list
2946 var lt1 = (LocatedToken) $1;
2947 var lt2 = (LocatedToken) $2;
2949 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2950 lbag.AddLocation ($$, GetLocation ($2));
2952 | qualified_alias_member IDENTIFIER generic_dimension
2954 var lt1 = (LocatedToken) $1;
2955 var lt2 = (LocatedToken) $2;
2957 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2958 lbag.AddLocation ($$, GetLocation ($2));
2964 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2966 var lt = (LocatedToken) $3;
2967 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2968 lbag.AddLocation ($$, GetLocation ($2));
2970 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2972 var lt = (LocatedToken) $3;
2973 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2974 lbag.AddLocation ($$, GetLocation ($2));
2979 : IDENTIFIER opt_type_argument_list
2981 var lt = (LocatedToken) $1;
2982 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2984 | IDENTIFIER generic_dimension
2986 var lt = (LocatedToken) $1;
2987 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2992 // Generics arguments (any type, without attributes)
2994 opt_type_argument_list
2996 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2998 if (lang_version < LanguageVersion.ISO_2)
2999 FeatureIsNotAvailable (GetLocation ($1), "generics");
3003 | OP_GENERICS_LT error
3005 Error_TypeExpected (lexer.Location);
3006 $$ = new TypeArguments ();
3013 TypeArguments type_args = new TypeArguments ();
3014 type_args.Add ((FullNamedExpression) $1);
3017 | type_arguments COMMA type
3019 TypeArguments type_args = (TypeArguments) $1;
3020 type_args.Add ((FullNamedExpression) $3);
3026 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3028 type_declaration_name
3031 lexer.parsing_generic_declaration = true;
3033 opt_type_parameter_list
3035 lexer.parsing_generic_declaration = false;
3036 var lt = (LocatedToken) $1;
3037 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3041 member_declaration_name
3042 : method_declaration_name
3044 MemberName mn = (MemberName)$1;
3045 if (mn.TypeParameters != null)
3046 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3047 mn.GetSignatureForError ()));
3051 method_declaration_name
3052 : type_declaration_name
3053 | explicit_interface IDENTIFIER opt_type_parameter_list
3055 lexer.parsing_generic_declaration = false;
3056 var lt = (LocatedToken) $2;
3057 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3061 indexer_declaration_name
3064 lexer.parsing_generic_declaration = false;
3065 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3067 | explicit_interface THIS
3069 lexer.parsing_generic_declaration = false;
3070 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3075 : IDENTIFIER opt_type_argument_list DOT
3077 var lt = (LocatedToken) $1;
3078 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3079 lbag.AddLocation ($$, GetLocation ($3));
3081 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3083 var lt1 = (LocatedToken) $1;
3084 var lt2 = (LocatedToken) $2;
3086 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3087 lbag.AddLocation ($$, GetLocation ($4));
3089 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3091 var lt = (LocatedToken) $2;
3092 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3093 lbag.AddLocation ($$, GetLocation ($4));
3097 opt_type_parameter_list
3099 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3101 if (lang_version < LanguageVersion.ISO_2)
3102 FeatureIsNotAvailable (GetLocation ($1), "generics");
3105 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3112 var tparams = new TypeParameters ();
3113 tparams.Add ((TypeParameter)$1);
3116 | type_parameters COMMA type_parameter
3118 var tparams = (TypeParameters) $1;
3119 tparams.Add ((TypeParameter)$3);
3121 lbag.AddLocation ($3, GetLocation ($3));
3126 : opt_attributes opt_type_parameter_variance IDENTIFIER
3128 var lt = (LocatedToken)$3;
3129 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3133 if (GetTokenName (yyToken) == "type")
3134 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3136 Error_SyntaxError (yyToken);
3138 $$ = new TypeParameter (MemberName.Null, null, null);
3143 // All types where void is allowed
3146 : type_expression_or_array
3149 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3156 lexer.parsing_generic_declaration = true;
3161 // A type which does not allow `void' to be used
3164 : type_expression_or_array
3174 : type_expression_or_array
3177 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3178 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3182 type_expression_or_array
3184 | type_expression rank_specifiers
3186 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3191 : namespace_or_type_expr opt_nullable
3194 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3196 var sn = $1 as SimpleName;
3197 if (sn != null && sn.Name == "var")
3198 $$ = new VarExpr (sn.Location);
3203 | namespace_or_type_expr pointer_stars
3205 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3207 | builtin_type_expression
3213 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3214 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3218 builtin_type_expression
3219 : builtin_types opt_nullable
3222 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3224 | builtin_types pointer_stars
3226 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3228 | VOID pointer_stars
3230 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3237 var types = new List<FullNamedExpression> (2);
3238 types.Add ((FullNamedExpression) $1);
3241 | type_list COMMA base_type_name
3243 var types = (List<FullNamedExpression>) $1;
3244 types.Add ((FullNamedExpression) $3);
3252 if ($1 is ComposedCast) {
3253 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3260 * replaces all the productions for isolating the various
3261 * simple types, but we need this to reuse it easily in variable_type
3264 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3265 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3266 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3267 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3268 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3269 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3274 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3275 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3276 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3277 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3278 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3279 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3280 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3281 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3282 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3286 // Expressions, section 7.5
3291 : type_name_expression
3293 | array_creation_expression
3294 | parenthesized_expression
3295 | default_value_expression
3296 | invocation_expression
3300 | post_increment_expression
3301 | post_decrement_expression
3302 | object_or_delegate_creation_expression
3303 | anonymous_type_expression
3306 | checked_expression
3307 | unchecked_expression
3308 | pointer_member_access
3309 | anonymous_method_expression
3310 | undocumented_expressions
3311 | interpolated_string
3314 type_name_expression
3316 | IDENTIFIER GENERATE_COMPLETION {
3317 var lt = (LocatedToken) $1;
3318 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3326 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3330 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3331 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3335 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3337 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3339 | INTERPOLATED_STRING_END
3341 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3348 var list = new List<Expression> ();
3349 list.Add ((InterpolatedStringInsert) $1);
3352 | interpolations INTERPOLATED_STRING interpolation
3354 var list = (List<Expression>) $1;
3355 list.Add ((StringLiteral) $2);
3356 list.Add ((InterpolatedStringInsert) $3);
3364 $$ = new InterpolatedStringInsert ((Expression) $1);
3366 | expression COMMA expression
3368 $$ = new InterpolatedStringInsert ((Expression) $1) {
3369 Alignment = (Expression)$3
3374 lexer.parsing_interpolation_format = true;
3378 lexer.parsing_interpolation_format = false;
3380 $$ = new InterpolatedStringInsert ((Expression) $1) {
3384 | expression COMMA expression COLON
3386 lexer.parsing_interpolation_format = true;
3390 lexer.parsing_interpolation_format = false;
3392 $$ = new InterpolatedStringInsert ((Expression) $1) {
3393 Alignment = (Expression)$3,
3394 Format = (string) $6
3401 // Here is the trick, tokenizer may think that parens is a special but
3402 // parser is interested in open parens only, so we merge them.
3403 // Consider: if (a)foo ();
3411 // Use this production to accept closing parenthesis or
3412 // performing completion
3416 | COMPLETE_COMPLETION
3420 parenthesized_expression
3421 : OPEN_PARENS expression CLOSE_PARENS
3423 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3424 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3426 | OPEN_PARENS expression COMPLETE_COMPLETION
3428 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3433 : primary_expression DOT identifier_inside_body opt_type_argument_list
3435 var lt = (LocatedToken) $3;
3436 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3437 lbag.AddLocation ($$, GetLocation ($2));
3439 | primary_expression DOT identifier_inside_body generic_dimension
3441 var lt = (LocatedToken) $3;
3442 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3443 lbag.AddLocation ($$, GetLocation ($2));
3445 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3447 if (lang_version < LanguageVersion.V_6)
3448 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3450 var lt = (LocatedToken) $4;
3451 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3452 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3454 | builtin_types DOT identifier_inside_body opt_type_argument_list
3456 var lt = (LocatedToken) $3;
3457 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3458 lbag.AddLocation ($$, GetLocation ($2));
3460 | BASE DOT identifier_inside_body opt_type_argument_list
3462 var lt = (LocatedToken) $3;
3463 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3464 lbag.AddLocation ($$, GetLocation ($2));
3466 | AWAIT DOT identifier_inside_body opt_type_argument_list
3468 var lt = (LocatedToken) $3;
3469 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3470 lbag.AddLocation ($$, GetLocation ($2));
3472 | qualified_alias_member identifier_inside_body opt_type_argument_list
3474 var lt1 = (LocatedToken) $1;
3475 var lt2 = (LocatedToken) $2;
3477 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3478 lbag.AddLocation ($$, GetLocation ($2));
3480 | qualified_alias_member identifier_inside_body generic_dimension
3482 var lt1 = (LocatedToken) $1;
3483 var lt2 = (LocatedToken) $2;
3485 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3486 lbag.AddLocation ($$, GetLocation ($2));
3488 | primary_expression DOT GENERATE_COMPLETION {
3489 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3491 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3492 var lt = (LocatedToken) $3;
3493 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3495 | builtin_types DOT GENERATE_COMPLETION
3497 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3499 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3500 var lt = (LocatedToken) $3;
3501 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3505 invocation_expression
3506 : primary_expression open_parens_any opt_argument_list close_parens
3508 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3509 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3511 | primary_expression open_parens_any argument_list error
3513 Error_SyntaxError (yyToken);
3515 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3516 lbag.AddLocation ($$, GetLocation ($2));
3518 | primary_expression open_parens_any error
3520 Error_SyntaxError (yyToken);
3522 $$ = new Invocation ((Expression) $1, null);
3523 lbag.AddLocation ($$, GetLocation ($2));
3527 opt_object_or_collection_initializer
3528 : /* empty */ { $$ = null; }
3529 | object_or_collection_initializer
3532 object_or_collection_initializer
3533 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3536 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3538 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3540 lbag.AddLocation ($$, GetLocation ($3));
3542 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3544 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3545 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3549 opt_member_initializer_list
3550 : /* empty */ { $$ = null; }
3551 | member_initializer_list
3557 member_initializer_list
3558 : member_initializer
3560 var a = new List<Expression> ();
3561 a.Add ((Expression) $1);
3564 | member_initializer_list COMMA member_initializer
3566 var a = (List<Expression>)$1;
3567 a.Add ((Expression) $3);
3570 | member_initializer_list error {
3571 Error_SyntaxError (yyToken);
3577 : IDENTIFIER ASSIGN initializer_value
3579 var lt = (LocatedToken) $1;
3580 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3581 lbag.AddLocation ($$, GetLocation ($2));
3583 | AWAIT ASSIGN initializer_value
3585 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3586 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3587 lbag.AddLocation ($$, GetLocation ($2));
3589 | GENERATE_COMPLETION
3591 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3593 | non_assignment_expression opt_COMPLETE_COMPLETION {
3594 CompletionSimpleName csn = $1 as CompletionSimpleName;
3596 $$ = new CollectionElementInitializer ((Expression)$1);
3598 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3600 | OPEN_BRACE expression_list CLOSE_BRACE
3603 $$ = new CollectionElementInitializer (GetLocation ($1));
3605 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3607 lbag.AddLocation ($$, GetLocation ($3));
3609 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3611 if (lang_version < LanguageVersion.V_6)
3612 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3614 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3615 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3617 | OPEN_BRACE CLOSE_BRACE
3619 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3620 $$ = new CollectionElementInitializer (GetLocation ($1));
3621 lbag.AddLocation ($$, GetLocation ($2));
3627 | object_or_collection_initializer
3631 : /* empty */ { $$ = null; }
3636 : argument_or_named_argument
3638 Arguments list = new Arguments (4);
3639 list.Add ((Argument) $1);
3642 | argument_list COMMA argument
3644 Arguments list = (Arguments) $1;
3645 if (list [list.Count - 1] is NamedArgument)
3646 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3648 list.Add ((Argument) $3);
3651 | argument_list COMMA named_argument
3653 Arguments list = (Arguments) $1;
3654 NamedArgument a = (NamedArgument) $3;
3655 for (int i = 0; i < list.Count; ++i) {
3656 NamedArgument na = list [i] as NamedArgument;
3657 if (na != null && na.Name == a.Name)
3658 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3665 | argument_list COMMA error
3667 if (lexer.putback_char == -1)
3668 lexer.putback (')'); // TODO: Wrong but what can I do
3669 Error_SyntaxError (yyToken);
3674 report.Error (839, GetLocation ($1), "An argument is missing");
3682 $$ = new Argument ((Expression) $1);
3684 | non_simple_argument
3687 argument_or_named_argument
3693 : REF variable_reference
3695 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3696 lbag.AddLocation ($$, GetLocation ($1));
3698 | REF declaration_expression
3700 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3702 | OUT variable_reference
3704 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3705 lbag.AddLocation ($$, GetLocation ($1));
3707 | OUT declaration_expression
3709 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3711 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3713 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3714 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3716 | ARGLIST OPEN_PARENS CLOSE_PARENS
3718 $$ = new Argument (new Arglist (GetLocation ($1)));
3719 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3723 declaration_expression
3724 : OPEN_PARENS declaration_expression CLOSE_PARENS
3726 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3727 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3730 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3732 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3733 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3735 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3737 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3738 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3741 | variable_type identifier_inside_body
3743 if (lang_version != LanguageVersion.Experimental)
3744 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3746 var lt = (LocatedToken) $2;
3747 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3748 current_block.AddLocalName (lv);
3749 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3751 | variable_type identifier_inside_body ASSIGN expression
3753 if (lang_version != LanguageVersion.Experimental)
3754 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3756 var lt = (LocatedToken) $2;
3757 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3758 current_block.AddLocalName (lv);
3759 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3760 Initializer = (Expression) $4
3770 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3772 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3773 lbag.AddLocation ($$, GetLocation ($4));
3775 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3777 if (lang_version < LanguageVersion.V_6)
3778 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3780 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3781 ConditionalAccess = true
3784 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3786 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3788 Error_SyntaxError (yyToken);
3789 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3791 | primary_expression OPEN_BRACKET_EXPR error
3793 Error_SyntaxError (yyToken);
3794 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3799 : expression_or_error
3801 var list = new List<Expression> (4);
3802 list.Add ((Expression) $1);
3805 | expression_list COMMA expression_or_error
3807 var list = (List<Expression>) $1;
3808 list.Add ((Expression) $3);
3813 expression_list_arguments
3814 : expression_list_argument
3816 Arguments args = new Arguments (4);
3817 args.Add ((Argument) $1);
3820 | expression_list_arguments COMMA expression_list_argument
3822 Arguments args = (Arguments) $1;
3823 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3824 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3826 args.Add ((Argument) $3);
3831 expression_list_argument
3834 $$ = new Argument ((Expression) $1);
3842 $$ = new This (GetLocation ($1));
3847 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3849 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3850 lbag.AddLocation ($$, GetLocation ($4));
3852 | BASE OPEN_BRACKET error
3854 Error_SyntaxError (yyToken);
3855 $$ = new ElementAccess (null, null, GetLocation ($2));
3859 post_increment_expression
3860 : primary_expression OP_INC
3862 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3866 post_decrement_expression
3867 : primary_expression OP_DEC
3869 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3873 object_or_delegate_creation_expression
3874 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3877 if (lang_version <= LanguageVersion.ISO_2)
3878 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3880 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3882 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3885 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3887 | NEW new_expr_type object_or_collection_initializer
3889 if (lang_version <= LanguageVersion.ISO_2)
3890 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3892 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3896 array_creation_expression
3897 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3899 opt_array_initializer
3901 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3902 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3903 Next = (ComposedTypeSpecifier) $6
3904 }, (ArrayInitializer) $7, GetLocation ($1));
3905 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3907 | NEW new_expr_type rank_specifiers opt_array_initializer
3910 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3912 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3914 | NEW rank_specifier array_initializer
3916 if (lang_version <= LanguageVersion.ISO_2)
3917 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3919 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3921 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3923 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3924 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3926 | NEW new_expr_type error
3928 Error_SyntaxError (yyToken);
3929 // It can be any of new expression, create the most common one
3930 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3936 ++lexer.parsing_type;
3940 --lexer.parsing_type;
3945 anonymous_type_expression
3946 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3948 if (lang_version <= LanguageVersion.ISO_2)
3949 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3951 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3953 // TODO: lbag comma location
3954 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3956 | NEW OPEN_BRACE GENERATE_COMPLETION
3958 $$ = new EmptyCompletion ();
3962 anonymous_type_parameters_opt_comma
3963 : anonymous_type_parameters_opt
3964 | anonymous_type_parameters COMMA
3967 anonymous_type_parameters_opt
3969 | anonymous_type_parameters
3972 anonymous_type_parameters
3973 : anonymous_type_parameter
3975 var a = new List<AnonymousTypeParameter> (4);
3976 a.Add ((AnonymousTypeParameter) $1);
3979 | anonymous_type_parameters COMMA anonymous_type_parameter
3981 var a = (List<AnonymousTypeParameter>) $1;
3982 a.Add ((AnonymousTypeParameter) $3);
3985 | COMPLETE_COMPLETION
3987 $$ = new EmptyCompletion ();
3989 | anonymous_type_parameter COMPLETE_COMPLETION
3995 anonymous_type_parameter
3996 : identifier_inside_body ASSIGN variable_initializer
3998 var lt = (LocatedToken)$1;
3999 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4000 lbag.AddLocation ($$, GetLocation ($2));
4002 | identifier_inside_body
4004 var lt = (LocatedToken)$1;
4005 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4006 lt.Value, lt.Location);
4010 MemberAccess ma = (MemberAccess) $1;
4011 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4015 report.Error (746, lexer.Location,
4016 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4028 | rank_specifier rank_specifiers
4030 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4036 : OPEN_BRACKET CLOSE_BRACKET
4038 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4039 lbag.AddLocation ($$, GetLocation ($2));
4041 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4043 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4044 lbag.AddLocation ($$, GetLocation ($3));
4053 | dim_separators COMMA
4055 $$ = ((int) $1) + 1;
4059 opt_array_initializer
4071 : OPEN_BRACE CLOSE_BRACE
4073 var ai = new ArrayInitializer (0, GetLocation ($1));
4074 ai.VariableDeclaration = current_variable;
4075 lbag.AddLocation (ai, GetLocation ($2));
4078 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4080 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4081 ai.VariableDeclaration = current_variable;
4083 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4085 lbag.AddLocation (ai, GetLocation ($4));
4091 variable_initializer_list
4092 : variable_initializer
4094 var list = new List<Expression> (4);
4095 list.Add ((Expression) $1);
4098 | variable_initializer_list COMMA variable_initializer
4100 var list = (List<Expression>) $1;
4101 list.Add ((Expression) $3);
4107 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4109 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4110 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4114 typeof_type_expression
4118 Error_TypeExpected (lexer.Location);
4126 if (lang_version < LanguageVersion.ISO_2)
4127 FeatureIsNotAvailable (GetLocation ($1), "generics");
4133 qualified_alias_member
4134 : IDENTIFIER DOUBLE_COLON
4136 var lt = (LocatedToken) $1;
4137 if (lang_version == LanguageVersion.ISO_1)
4138 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4145 : SIZEOF open_parens_any type CLOSE_PARENS
4147 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4148 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4150 | SIZEOF open_parens_any type error
4152 Error_SyntaxError (yyToken);
4154 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4155 lbag.AddLocation ($$, GetLocation ($2));
4160 : CHECKED open_parens_any expression CLOSE_PARENS
4162 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4163 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4167 Error_SyntaxError (yyToken);
4169 $$ = new CheckedExpr (null, GetLocation ($1));
4173 unchecked_expression
4174 : UNCHECKED open_parens_any expression CLOSE_PARENS
4176 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4177 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4181 Error_SyntaxError (yyToken);
4183 $$ = new UnCheckedExpr (null, GetLocation ($1));
4187 pointer_member_access
4188 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4190 var lt = (LocatedToken) $3;
4191 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4195 anonymous_method_expression
4196 : DELEGATE opt_anonymous_method_signature
4198 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4202 $$ = end_anonymous ((ParametersBlock) $4);
4204 | ASYNC DELEGATE opt_anonymous_method_signature
4206 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4210 $$ = end_anonymous ((ParametersBlock) $5);
4214 opt_anonymous_method_signature
4217 $$ = ParametersCompiled.Undefined;
4219 | anonymous_method_signature
4222 anonymous_method_signature
4225 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4227 opt_formal_parameter_list CLOSE_PARENS
4229 valid_param_mod = 0;
4234 default_value_expression
4235 : DEFAULT open_parens_any type CLOSE_PARENS
4237 if (lang_version < LanguageVersion.ISO_2)
4238 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4240 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4241 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4246 : primary_expression
4247 | BANG prefixed_unary_expression
4249 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4251 | TILDE prefixed_unary_expression
4253 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4255 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4257 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4258 lbag.AddLocation ($$, GetLocation ($3));
4260 | AWAIT prefixed_unary_expression
4263 if (current_anonymous_method is LambdaExpression) {
4264 report.Error (4034, GetLocation ($1),
4265 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4266 } else if (current_anonymous_method != null) {
4267 report.Error (4035, GetLocation ($1),
4268 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4269 } else if (interactive_async != null) {
4270 current_block.Explicit.RegisterAsyncAwait ();
4271 interactive_async = true;
4273 report.Error (4033, GetLocation ($1),
4274 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4277 current_block.Explicit.RegisterAsyncAwait ();
4280 $$ = new Await ((Expression) $2, GetLocation ($1));
4284 Error_SyntaxError (yyToken);
4286 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4290 Error_SyntaxError (yyToken);
4292 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4294 | OPEN_PARENS_CAST type CLOSE_PARENS error
4296 Error_SyntaxError (yyToken);
4298 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4299 lbag.AddLocation ($$, GetLocation ($3));
4303 Error_SyntaxError (yyToken);
4305 $$ = new Await (null, GetLocation ($1));
4310 // The idea to split this out is from Rhys' grammar
4311 // to solve the problem with casts.
4313 prefixed_unary_expression
4315 | PLUS prefixed_unary_expression
4317 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4319 | MINUS prefixed_unary_expression
4321 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4323 | OP_INC prefixed_unary_expression
4325 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4327 | OP_DEC prefixed_unary_expression
4329 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4331 | STAR prefixed_unary_expression
4333 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4335 | BITWISE_AND prefixed_unary_expression
4337 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4341 Error_SyntaxError (yyToken);
4343 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4347 Error_SyntaxError (yyToken);
4349 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4353 Error_SyntaxError (yyToken);
4355 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4359 Error_SyntaxError (yyToken);
4361 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4365 Error_SyntaxError (yyToken);
4367 $$ = new Indirection (null, GetLocation ($1));
4371 Error_SyntaxError (yyToken);
4373 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4377 multiplicative_expression
4378 : prefixed_unary_expression
4379 | multiplicative_expression STAR prefixed_unary_expression
4381 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4382 lbag.AddLocation ($$, GetLocation ($2));
4384 | multiplicative_expression DIV prefixed_unary_expression
4386 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4387 lbag.AddLocation ($$, GetLocation ($2));
4389 | multiplicative_expression PERCENT prefixed_unary_expression
4391 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4392 lbag.AddLocation ($$, GetLocation ($2));
4394 | multiplicative_expression STAR error
4396 Error_SyntaxError (yyToken);
4398 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4399 lbag.AddLocation ($$, GetLocation ($2));
4401 | multiplicative_expression DIV error
4403 Error_SyntaxError (yyToken);
4405 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4406 lbag.AddLocation ($$, GetLocation ($2));
4408 | multiplicative_expression PERCENT error
4410 Error_SyntaxError (yyToken);
4412 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4413 lbag.AddLocation ($$, GetLocation ($2));
4418 : multiplicative_expression
4419 | additive_expression PLUS multiplicative_expression
4421 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4422 lbag.AddLocation ($$, GetLocation ($2));
4424 | additive_expression MINUS multiplicative_expression
4426 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4427 lbag.AddLocation ($$, GetLocation ($2));
4429 | additive_expression PLUS error
4431 Error_SyntaxError (yyToken);
4433 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4434 lbag.AddLocation ($$, GetLocation ($2));
4436 | additive_expression MINUS error
4438 Error_SyntaxError (yyToken);
4440 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4441 lbag.AddLocation ($$, GetLocation ($2));
4443 | additive_expression AS type
4445 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4447 | additive_expression IS pattern_type_expr opt_identifier
4449 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4451 if (lang_version != LanguageVersion.Experimental)
4452 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4454 var lt = (LocatedToken) $4;
4455 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4456 current_block.AddLocalName (is_expr.Variable);
4461 | additive_expression IS pattern_expr
4463 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4464 if (lang_version != LanguageVersion.Experimental)
4465 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4469 | additive_expression AS error
4471 Error_SyntaxError (yyToken);
4473 $$ = new As ((Expression) $1, null, GetLocation ($2));
4475 | additive_expression IS error
4477 Error_SyntaxError (yyToken);
4479 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4483 var lt = (LocatedToken) $1;
4484 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4488 var lt = (LocatedToken) $1;
4489 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4499 | PLUS prefixed_unary_expression
4501 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4503 | MINUS prefixed_unary_expression
4505 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4508 | default_value_expression
4509 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4511 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4512 lbag.AddLocation ($$, GetLocation ($3));
4516 $$ = new WildcardPattern (GetLocation ($1));
4518 | pattern_expr_invocation
4522 pattern_expr_invocation
4523 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4525 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4530 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4532 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4536 pattern_property_list
4537 : pattern_property_entry
4539 var list = new List<PropertyPatternMember> ();
4540 list.Add ((PropertyPatternMember) $1);
4543 | pattern_property_list COMMA pattern_property_entry
4545 var list = (List<PropertyPatternMember>) $1;
4546 list.Add ((PropertyPatternMember) $3);
4551 pattern_property_entry
4552 : identifier_inside_body IS pattern
4554 var lt = (LocatedToken) $1;
4555 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4561 | pattern_type_expr opt_identifier
4564 var lt = (LocatedToken) $2;
4565 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4566 current_block.AddLocalName (variable);
4574 $$ = new Arguments (0);
4582 Arguments args = new Arguments (4);
4583 args.Add ((Argument) $1);
4586 | pattern_list COMMA pattern_argument
4588 Arguments args = (Arguments) $1;
4589 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4590 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4592 args.Add ((Argument) $3);
4600 $$ = new Argument ((Expression) $1);
4602 | IDENTIFIER COLON pattern
4604 var lt = (LocatedToken) $1;
4605 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4610 : additive_expression
4611 | shift_expression OP_SHIFT_LEFT additive_expression
4613 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4614 lbag.AddLocation ($$, GetLocation ($2));
4616 | shift_expression OP_SHIFT_RIGHT additive_expression
4618 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4619 lbag.AddLocation ($$, GetLocation ($2));
4621 | shift_expression OP_SHIFT_LEFT error
4623 Error_SyntaxError (yyToken);
4625 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4626 lbag.AddLocation ($$, GetLocation ($2));
4628 | shift_expression OP_SHIFT_RIGHT error
4630 Error_SyntaxError (yyToken);
4632 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4633 lbag.AddLocation ($$, GetLocation ($2));
4637 relational_expression
4639 | relational_expression OP_LT shift_expression
4641 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4642 lbag.AddLocation ($$, GetLocation ($2));
4644 | relational_expression OP_GT shift_expression
4646 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4647 lbag.AddLocation ($$, GetLocation ($2));
4649 | relational_expression OP_LE shift_expression
4651 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4652 lbag.AddLocation ($$, GetLocation ($2));
4654 | relational_expression OP_GE shift_expression
4656 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4657 lbag.AddLocation ($$, GetLocation ($2));
4659 | relational_expression OP_LT error
4661 Error_SyntaxError (yyToken);
4663 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4664 lbag.AddLocation ($$, GetLocation ($2));
4666 | relational_expression OP_GT error
4668 Error_SyntaxError (yyToken);
4670 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4671 lbag.AddLocation ($$, GetLocation ($2));
4673 | relational_expression OP_LE error
4675 Error_SyntaxError (yyToken);
4677 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4678 lbag.AddLocation ($$, GetLocation ($2));
4680 | relational_expression OP_GE error
4682 Error_SyntaxError (yyToken);
4684 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4685 lbag.AddLocation ($$, GetLocation ($2));
4690 : relational_expression
4691 | equality_expression OP_EQ relational_expression
4693 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4694 lbag.AddLocation ($$, GetLocation ($2));
4696 | equality_expression OP_NE relational_expression
4698 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4699 lbag.AddLocation ($$, GetLocation ($2));
4701 | equality_expression OP_EQ error
4703 Error_SyntaxError (yyToken);
4705 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4706 lbag.AddLocation ($$, GetLocation ($2));
4708 | equality_expression OP_NE error
4710 Error_SyntaxError (yyToken);
4712 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4713 lbag.AddLocation ($$, GetLocation ($2));
4718 : equality_expression
4719 | and_expression BITWISE_AND equality_expression
4721 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4722 lbag.AddLocation ($$, GetLocation ($2));
4724 | and_expression BITWISE_AND error
4726 Error_SyntaxError (yyToken);
4728 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4729 lbag.AddLocation ($$, GetLocation ($2));
4733 exclusive_or_expression
4735 | exclusive_or_expression CARRET and_expression
4737 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4738 lbag.AddLocation ($$, GetLocation ($2));
4740 | exclusive_or_expression CARRET error
4742 Error_SyntaxError (yyToken);
4744 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4745 lbag.AddLocation ($$, GetLocation ($2));
4749 inclusive_or_expression
4750 : exclusive_or_expression
4751 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4753 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4754 lbag.AddLocation ($$, GetLocation ($2));
4756 | inclusive_or_expression BITWISE_OR error
4758 Error_SyntaxError (yyToken);
4760 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4761 lbag.AddLocation ($$, GetLocation ($2));
4765 conditional_and_expression
4766 : inclusive_or_expression
4767 | conditional_and_expression OP_AND inclusive_or_expression
4769 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4770 lbag.AddLocation ($$, GetLocation ($2));
4772 | conditional_and_expression OP_AND error
4774 Error_SyntaxError (yyToken);
4776 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4777 lbag.AddLocation ($$, GetLocation ($2));
4781 conditional_or_expression
4782 : conditional_and_expression
4783 | conditional_or_expression OP_OR conditional_and_expression
4785 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4786 lbag.AddLocation ($$, GetLocation ($2));
4788 | conditional_or_expression OP_OR error
4790 Error_SyntaxError (yyToken);
4792 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4793 lbag.AddLocation ($$, GetLocation ($2));
4797 null_coalescing_expression
4798 : conditional_or_expression
4799 | conditional_or_expression OP_COALESCING null_coalescing_expression
4801 if (lang_version < LanguageVersion.ISO_2)
4802 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4804 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4805 lbag.AddLocation ($$, GetLocation ($2));
4809 conditional_expression
4810 : null_coalescing_expression
4811 | null_coalescing_expression INTERR expression COLON expression
4813 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4814 lbag.AddLocation ($$, GetLocation ($4));
4816 | null_coalescing_expression INTERR expression error
4818 Error_SyntaxError (yyToken);
4820 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4822 | null_coalescing_expression INTERR expression COLON error
4824 Error_SyntaxError (yyToken);
4826 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4827 lbag.AddLocation ($$, GetLocation ($4));
4829 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4831 Error_SyntaxError (Token.CLOSE_BRACE);
4833 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4834 lbag.AddLocation ($$, GetLocation ($4));
4835 lexer.putback ('}');
4839 assignment_expression
4840 : prefixed_unary_expression ASSIGN expression
4842 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4843 lbag.AddLocation ($$, GetLocation ($2));
4845 | prefixed_unary_expression OP_MULT_ASSIGN expression
4847 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4848 lbag.AddLocation ($$, GetLocation ($2));
4850 | prefixed_unary_expression OP_DIV_ASSIGN expression
4852 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4853 lbag.AddLocation ($$, GetLocation ($2));
4855 | prefixed_unary_expression OP_MOD_ASSIGN expression
4857 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4858 lbag.AddLocation ($$, GetLocation ($2));
4860 | prefixed_unary_expression OP_ADD_ASSIGN expression
4862 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4863 lbag.AddLocation ($$, GetLocation ($2));
4865 | prefixed_unary_expression OP_SUB_ASSIGN expression
4867 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4868 lbag.AddLocation ($$, GetLocation ($2));
4870 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4872 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4873 lbag.AddLocation ($$, GetLocation ($2));
4875 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4877 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4878 lbag.AddLocation ($$, GetLocation ($2));
4880 | prefixed_unary_expression OP_AND_ASSIGN expression
4882 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4883 lbag.AddLocation ($$, GetLocation ($2));
4885 | prefixed_unary_expression OP_OR_ASSIGN expression
4887 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4888 lbag.AddLocation ($$, GetLocation ($2));
4890 | prefixed_unary_expression OP_XOR_ASSIGN expression
4892 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4893 lbag.AddLocation ($$, GetLocation ($2));
4897 lambda_parameter_list
4900 var pars = new List<Parameter> (4);
4901 pars.Add ((Parameter) $1);
4905 | lambda_parameter_list COMMA lambda_parameter
4907 var pars = (List<Parameter>) $1;
4908 Parameter p = (Parameter)$3;
4909 if (pars[0].GetType () != p.GetType ()) {
4910 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4919 : parameter_modifier parameter_type identifier_inside_body
4921 var lt = (LocatedToken) $3;
4923 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4925 | parameter_type identifier_inside_body
4927 var lt = (LocatedToken) $2;
4929 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4933 var lt = (LocatedToken) $1;
4934 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4938 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4939 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4943 opt_lambda_parameter_list
4944 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4945 | lambda_parameter_list {
4946 var pars_list = (List<Parameter>) $1;
4947 $$ = new ParametersCompiled (pars_list.ToArray ());
4951 lambda_expression_body
4953 start_block (Location.Null);
4955 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4957 Block b = end_block (Location.Null);
4958 b.IsCompilerGenerated = true;
4959 b.AddStatement (new ContextualReturn ((Expression) $2));
4965 // Handles only cases like foo = x.FirstOrDefault (l => );
4966 // where we must restore current_variable
4967 Block b = end_block (Location.Null);
4968 b.IsCompilerGenerated = true;
4970 Error_SyntaxError (yyToken);
4979 Error_SyntaxError (yyToken);
4987 var lt = (LocatedToken) $1;
4988 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4989 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4991 lambda_expression_body
4993 $$ = end_anonymous ((ParametersBlock) $4);
4994 lbag.AddLocation ($$, GetLocation ($2));
4998 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4999 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5000 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5002 lambda_expression_body
5004 $$ = end_anonymous ((ParametersBlock) $4);
5005 lbag.AddLocation ($$, GetLocation ($2));
5007 | ASYNC identifier_inside_body ARROW
5009 var lt = (LocatedToken) $2;
5010 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5011 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5013 lambda_expression_body
5015 $$ = end_anonymous ((ParametersBlock) $5);
5016 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5018 | OPEN_PARENS_LAMBDA
5020 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5022 opt_lambda_parameter_list CLOSE_PARENS ARROW
5024 valid_param_mod = 0;
5025 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5027 lambda_expression_body
5029 $$ = end_anonymous ((ParametersBlock) $7);
5030 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5032 | ASYNC OPEN_PARENS_LAMBDA
5034 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5036 opt_lambda_parameter_list CLOSE_PARENS ARROW
5038 valid_param_mod = 0;
5039 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5041 lambda_expression_body
5043 $$ = end_anonymous ((ParametersBlock) $8);
5044 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5049 : assignment_expression
5050 | non_assignment_expression
5053 non_assignment_expression
5054 : conditional_expression
5059 $$ = new ArglistAccess (GetLocation ($1));
5063 undocumented_expressions
5064 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5066 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5067 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5069 | REFTYPE open_parens_any expression CLOSE_PARENS
5071 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5072 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5074 | MAKEREF open_parens_any expression CLOSE_PARENS
5076 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5077 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5088 $$ = new BooleanExpression ((Expression) $1);
5092 opt_primary_parameters
5097 | primary_parameters
5101 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5105 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5106 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5108 if (lang_version != LanguageVersion.Experimental)
5109 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5113 opt_primary_parameters_with_class_base
5122 | primary_parameters
5126 | primary_parameters class_base
5130 | primary_parameters class_base OPEN_PARENS
5132 ++lexer.parsing_block;
5133 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5135 opt_argument_list CLOSE_PARENS
5137 lbag.AppendToMember (current_container, GetLocation ($6));
5138 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5139 --lexer.parsing_block;
5155 type_declaration_name
5157 lexer.ConstraintsParsing = true;
5159 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5160 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5161 FeatureIsNotAvailable (c.Location, "static classes");
5164 push_current_container (c, $3);
5165 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5167 opt_primary_parameters_with_class_base
5168 opt_type_parameter_constraints_clauses
5170 valid_param_mod = 0;
5171 lexer.ConstraintsParsing = false;
5174 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5177 current_container.SetConstraints ((List<Constraints>) $9);
5178 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5181 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5182 Lexer.doc_state = XmlCommentState.Allowed;
5185 lexer.parsing_modifiers = true;
5187 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5189 --lexer.parsing_declaration;
5191 Lexer.doc_state = XmlCommentState.Allowed;
5196 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5198 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5200 $$ = pop_current_class ();
5208 { $$ = $1; } // location
5214 mod_locations = null;
5216 lexer.parsing_modifiers = false;
5220 lexer.parsing_modifiers = false;
5226 | modifiers modifier
5228 var m1 = (Modifiers) $1;
5229 var m2 = (Modifiers) $2;
5231 if ((m1 & m2) != 0) {
5232 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5233 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5234 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5235 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5236 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5237 "More than one protection modifier specified");
5248 StoreModifierLocation ($$, GetLocation ($1));
5250 if (current_container.Kind == MemberKind.Namespace)
5251 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5255 $$ = Modifiers.PUBLIC;
5256 StoreModifierLocation ($$, GetLocation ($1));
5260 $$ = Modifiers.PROTECTED;
5261 StoreModifierLocation ($$, GetLocation ($1));
5265 $$ = Modifiers.INTERNAL;
5266 StoreModifierLocation ($$, GetLocation ($1));
5270 $$ = Modifiers.PRIVATE;
5271 StoreModifierLocation ($$, GetLocation ($1));
5275 $$ = Modifiers.ABSTRACT;
5276 StoreModifierLocation ($$, GetLocation ($1));
5280 $$ = Modifiers.SEALED;
5281 StoreModifierLocation ($$, GetLocation ($1));
5285 $$ = Modifiers.STATIC;
5286 StoreModifierLocation ($$, GetLocation ($1));
5290 $$ = Modifiers.READONLY;
5291 StoreModifierLocation ($$, GetLocation ($1));
5295 $$ = Modifiers.VIRTUAL;
5296 StoreModifierLocation ($$, GetLocation ($1));
5300 $$ = Modifiers.OVERRIDE;
5301 StoreModifierLocation ($$, GetLocation ($1));
5305 $$ = Modifiers.EXTERN;
5306 StoreModifierLocation ($$, GetLocation ($1));
5310 $$ = Modifiers.VOLATILE;
5311 StoreModifierLocation ($$, GetLocation ($1));
5315 $$ = Modifiers.UNSAFE;
5316 StoreModifierLocation ($$, GetLocation ($1));
5317 if (!settings.Unsafe)
5318 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5322 $$ = Modifiers.ASYNC;
5323 StoreModifierLocation ($$, GetLocation ($1));
5335 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5337 | COLON type_list error
5339 Error_SyntaxError (yyToken);
5341 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5345 opt_type_parameter_constraints_clauses
5347 | type_parameter_constraints_clauses
5353 type_parameter_constraints_clauses
5354 : type_parameter_constraints_clause
5356 var constraints = new List<Constraints> (1);
5357 constraints.Add ((Constraints) $1);
5360 | type_parameter_constraints_clauses type_parameter_constraints_clause
5362 var constraints = (List<Constraints>) $1;
5363 Constraints new_constraint = (Constraints)$2;
5365 foreach (Constraints c in constraints) {
5366 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5367 report.Error (409, new_constraint.Location,
5368 "A constraint clause has already been specified for type parameter `{0}'",
5369 new_constraint.TypeParameter.Value);
5373 constraints.Add (new_constraint);
5378 type_parameter_constraints_clause
5379 : WHERE IDENTIFIER COLON type_parameter_constraints
5381 var lt = (LocatedToken) $2;
5382 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5383 lbag.AddLocation ($$, GetLocation ($3));
5385 | WHERE IDENTIFIER error
5387 Error_SyntaxError (yyToken);
5389 var lt = (LocatedToken) $2;
5390 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5394 type_parameter_constraints
5395 : type_parameter_constraint
5397 var constraints = new List<FullNamedExpression> (1);
5398 constraints.Add ((FullNamedExpression) $1);
5401 | type_parameter_constraints COMMA type_parameter_constraint
5403 var constraints = (List<FullNamedExpression>) $1;
5404 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5405 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5406 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5409 prev = $3 as SpecialContraintExpr;
5411 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5412 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5414 prev = constraints [0] as SpecialContraintExpr;
5415 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5416 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5421 constraints.Add ((FullNamedExpression) $3);
5426 type_parameter_constraint
5429 if ($1 is ComposedCast)
5430 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5434 | NEW OPEN_PARENS CLOSE_PARENS
5436 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5437 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5441 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5445 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5449 opt_type_parameter_variance
5454 | type_parameter_variance
5456 if (lang_version <= LanguageVersion.V_3)
5457 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5463 type_parameter_variance
5466 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5470 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5479 // A block is "contained" on the following places:
5481 // property_declaration as part of the accessor body (get/set)
5482 // operator_declaration
5483 // constructor_declaration
5484 // destructor_declaration
5485 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5490 ++lexer.parsing_block;
5491 start_block (GetLocation ($1));
5493 opt_statement_list block_end
5502 --lexer.parsing_block;
5503 $$ = end_block (GetLocation ($1));
5505 | COMPLETE_COMPLETION
5507 --lexer.parsing_block;
5508 $$ = end_block (lexer.Location);
5516 ++lexer.parsing_block;
5517 current_block.StartLocation = GetLocation ($1);
5519 opt_statement_list CLOSE_BRACE
5521 --lexer.parsing_block;
5522 $$ = end_block (GetLocation ($4));
5533 | statement_list statement
5537 : block_variable_declaration
5539 current_block.AddStatement ((Statement) $1);
5541 | valid_declaration_statement
5543 current_block.AddStatement ((Statement) $1);
5548 Error_SyntaxError (yyToken);
5554 // The interactive_statement and its derivatives are only
5555 // used to provide a special version of `expression_statement'
5556 // that has a side effect of assigning the expression to
5559 interactive_statement_list
5560 : interactive_statement
5561 | interactive_statement_list interactive_statement
5564 interactive_statement
5565 : block_variable_declaration
5567 current_block.AddStatement ((Statement) $1);
5569 | interactive_valid_declaration_statement
5571 current_block.AddStatement ((Statement) $1);
5576 valid_declaration_statement
5579 | expression_statement
5580 | selection_statement
5581 | iteration_statement
5585 | unchecked_statement
5592 interactive_valid_declaration_statement
5595 | interactive_expression_statement
5596 | selection_statement
5597 | iteration_statement
5601 | unchecked_statement
5609 : valid_declaration_statement
5610 | block_variable_declaration
5612 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5617 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5622 Error_SyntaxError (yyToken);
5623 $$ = new EmptyStatement (GetLocation ($1));
5630 // Uses lexer.Location because semicolon location is not kept in quick mode
5631 $$ = new EmptyStatement (lexer.Location);
5636 : identifier_inside_body COLON
5638 var lt = (LocatedToken) $1;
5639 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5640 lbag.AddLocation (labeled, GetLocation ($2));
5641 current_block.AddLabel (labeled);
5642 current_block.AddStatement (labeled);
5648 : variable_type_simple
5649 | variable_type_simple rank_specifiers
5652 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5654 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5659 * The following is from Rhys' grammar:
5660 * > Types in local variable declarations must be recognized as
5661 * > expressions to prevent reduce/reduce errors in the grammar.
5662 * > The expressions are converted into types during semantic analysis.
5664 variable_type_simple
5665 : type_name_expression opt_nullable
5667 // Ok, the above "primary_expression" is there to get rid of
5668 // both reduce/reduce and shift/reduces in the grammar, it should
5669 // really just be "type_name". If you use type_name, a reduce/reduce
5670 // creeps up. If you use namespace_or_type_name (which is all we need
5671 // really) two shift/reduces appear.
5674 // So the super-trick is that primary_expression
5675 // can only be either a SimpleName or a MemberAccess.
5676 // The MemberAccess case arises when you have a fully qualified type-name like :
5678 // SimpleName is when you have
5681 var expr = (ATypeNameExpression) $1;
5683 if (expr.Name == "var" && expr is SimpleName)
5684 $$ = new VarExpr (expr.Location);
5688 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5691 | type_name_expression pointer_stars
5693 var expr = (ATypeNameExpression) $1;
5694 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5696 | builtin_type_expression
5702 | pointer_star pointer_stars
5704 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5712 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5716 identifier_inside_body
5720 $$ = Error_AwaitAsIdentifier ($1);
5724 block_variable_declaration
5725 : variable_type identifier_inside_body
5727 var lt = (LocatedToken) $2;
5728 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5729 current_block.AddLocalName (li);
5730 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5732 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5734 $$ = current_variable;
5735 current_variable = null;
5737 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5739 lbag.AddLocation ($$, GetLocation ($6));
5741 | CONST variable_type identifier_inside_body
5743 var lt = (LocatedToken) $3;
5744 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5745 current_block.AddLocalName (li);
5746 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5748 const_variable_initializer opt_const_declarators SEMICOLON
5750 $$ = current_variable;
5751 current_variable = null;
5752 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5756 opt_local_variable_initializer
5758 | ASSIGN block_variable_initializer
5760 current_variable.Initializer = (Expression) $2;
5761 PushLocation (GetLocation ($1));
5762 $$ = current_variable;
5766 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5767 report.Error (650, lexer.Location,
5768 "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");
5770 Error_SyntaxError (yyToken);
5775 opt_variable_declarators
5777 | variable_declarators
5780 opt_using_or_fixed_variable_declarators
5782 | variable_declarators
5784 foreach (var d in current_variable.Declarators) {
5785 if (d.Initializer == null)
5786 Error_MissingInitializer (d.Variable.Location);
5791 variable_declarators
5792 : variable_declarator
5793 | variable_declarators variable_declarator
5797 : COMMA identifier_inside_body
5799 var lt = (LocatedToken) $2;
5800 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5801 var d = new BlockVariableDeclarator (li, null);
5802 current_variable.AddDeclarator (d);
5803 current_block.AddLocalName (li);
5804 lbag.AddLocation (d, GetLocation ($1));
5806 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5808 var lt = (LocatedToken) $2;
5809 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5810 var d = new BlockVariableDeclarator (li, (Expression) $4);
5811 current_variable.AddDeclarator (d);
5812 current_block.AddLocalName (li);
5813 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5817 const_variable_initializer
5820 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5822 | ASSIGN constant_initializer_expr
5824 current_variable.Initializer = (Expression) $2;
5828 opt_const_declarators
5835 | const_declarators const_declarator
5839 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5841 var lt = (LocatedToken) $2;
5842 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5843 var d = new BlockVariableDeclarator (li, (Expression) $4);
5844 current_variable.AddDeclarator (d);
5845 current_block.AddLocalName (li);
5846 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5850 block_variable_initializer
5851 : variable_initializer
5852 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5854 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5855 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5857 | STACKALLOC simple_type
5859 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5860 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5864 expression_statement
5865 : statement_expression SEMICOLON
5868 lbag.AddStatement ($$, GetLocation ($2));
5870 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5871 | statement_expression CLOSE_BRACE
5874 report.Error (1002, GetLocation ($2), "; expected");
5875 lexer.putback ('}');
5879 interactive_expression_statement
5880 : interactive_statement_expression SEMICOLON { $$ = $1; }
5881 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5885 // We have to do the wrapping here and not in the case above,
5886 // because statement_expression is used for example in for_statement
5888 statement_expression
5891 ExpressionStatement s = $1 as ExpressionStatement;
5893 var expr = $1 as Expression;
5894 $$ = new StatementErrorExpression (expr);
5896 $$ = new StatementExpression (s);
5901 interactive_statement_expression
5904 Expression expr = (Expression) $1;
5905 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5909 Error_SyntaxError (yyToken);
5910 $$ = new EmptyStatement (GetLocation ($1));
5920 : IF open_parens_any boolean_expression CLOSE_PARENS
5923 if ($5 is EmptyStatement)
5924 Warning_EmptyStatement (GetLocation ($5));
5926 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5927 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5929 | IF open_parens_any boolean_expression CLOSE_PARENS
5930 embedded_statement ELSE embedded_statement
5932 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5933 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5935 if ($5 is EmptyStatement)
5936 Warning_EmptyStatement (GetLocation ($5));
5937 if ($7 is EmptyStatement)
5938 Warning_EmptyStatement (GetLocation ($7));
5940 | IF open_parens_any boolean_expression error
5942 Error_SyntaxError (yyToken);
5944 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5945 lbag.AddStatement ($$, GetLocation ($2));
5950 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5952 start_block (GetLocation ($5));
5954 opt_switch_sections CLOSE_BRACE
5956 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5957 end_block (GetLocation ($8));
5958 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5960 | SWITCH open_parens_any expression error
5962 Error_SyntaxError (yyToken);
5964 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5965 lbag.AddStatement ($$, GetLocation ($2));
5972 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5979 | switch_sections switch_section
5982 Error_SyntaxError (yyToken);
5987 : switch_labels statement_list
5993 var label = (SwitchLabel) $1;
5994 label.SectionStart = true;
5995 current_block.AddStatement (label);
5997 | switch_labels switch_label
5999 current_block.AddStatement ((Statement) $2);
6004 : CASE constant_expression COLON
6006 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6007 lbag.AddLocation ($$, GetLocation ($3));
6009 | CASE constant_expression error
6011 Error_SyntaxError (yyToken);
6012 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6015 | CASE pattern_expr_invocation COLON
6017 if (lang_version != LanguageVersion.Experimental)
6018 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6020 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6021 PatternMatching = true
6023 lbag.AddLocation ($$, GetLocation ($3));
6028 $$ = new SwitchLabel (null, GetLocation ($1));
6040 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6042 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6043 Warning_EmptyStatement (GetLocation ($5));
6045 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6046 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6048 | WHILE open_parens_any boolean_expression error
6050 Error_SyntaxError (yyToken);
6052 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6053 lbag.AddStatement ($$, GetLocation ($2));
6058 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6060 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6061 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6063 | DO embedded_statement error
6065 Error_SyntaxError (yyToken);
6066 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6068 | DO embedded_statement WHILE open_parens_any boolean_expression error
6070 Error_SyntaxError (yyToken);
6072 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6073 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6078 : FOR open_parens_any
6080 start_block (GetLocation ($2));
6081 current_block.IsCompilerGenerated = true;
6082 For f = new For (GetLocation ($1));
6083 current_block.AddStatement (f);
6092 // Has to use be extra rule to recover started block
6094 : opt_for_initializer SEMICOLON
6096 ((For) $0).Initializer = (Statement) $1;
6098 // Pass the "For" object to the iterator_part4
6099 oob_stack.Push ($0);
6101 for_condition_and_iterator_part
6104 var locations = (Tuple<Location,Location>) $4;
6106 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6107 Warning_EmptyStatement (GetLocation ($5));
6110 f.Statement = (Statement) $5;
6111 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6113 $$ = end_block (GetLocation ($2));
6117 Error_SyntaxError (yyToken);
6118 $$ = end_block (current_block.StartLocation);
6122 for_condition_and_iterator_part
6123 : opt_for_condition SEMICOLON
6125 For f = (For) oob_stack.Peek ();
6126 f.Condition = (BooleanExpression) $1;
6129 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6132 // Handle errors in the case of opt_for_condition being followed by
6133 // a close parenthesis
6134 | opt_for_condition close_parens_close_brace {
6135 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6136 For f = (For) oob_stack.Peek ();
6137 f.Condition = (BooleanExpression) $1;
6138 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6143 : opt_for_iterator CLOSE_PARENS {
6144 For f = (For) oob_stack.Peek ();
6145 f.Iterator = (Statement) $1;
6146 $$ = GetLocation ($2);
6148 | opt_for_iterator CLOSE_BRACE {
6149 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6150 For f = (For) oob_stack.Peek ();
6151 f.Iterator = (Statement) $1;
6152 $$ = GetLocation ($2);
6156 close_parens_close_brace
6158 | CLOSE_BRACE { lexer.putback ('}'); }
6162 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6167 : variable_type identifier_inside_body
6169 var lt = (LocatedToken) $2;
6170 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6171 current_block.AddLocalName (li);
6172 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6174 opt_local_variable_initializer opt_variable_declarators
6176 $$ = current_variable;
6178 lbag.AddLocation (current_variable, PopLocation ());
6180 current_variable = null;
6182 | statement_expression_list
6186 : /* empty */ { $$ = null; }
6187 | boolean_expression
6191 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6196 : statement_expression_list
6199 statement_expression_list
6200 : statement_expression
6201 | statement_expression_list COMMA statement_expression
6203 var sl = $1 as StatementList;
6205 sl = new StatementList ((Statement) $1, (Statement) $3);
6206 lbag.AddStatement (sl, GetLocation ($2));
6208 sl.Add ((Statement) $3);
6209 lbag.AppendTo (sl, GetLocation ($2));
6217 : FOREACH open_parens_any type error
6219 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6221 start_block (GetLocation ($2));
6222 current_block.IsCompilerGenerated = true;
6224 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6225 current_block.AddStatement (f);
6227 lbag.AddStatement (f, GetLocation ($2));
6228 $$ = end_block (GetLocation ($4));
6230 | FOREACH open_parens_any type identifier_inside_body error
6232 Error_SyntaxError (yyToken);
6234 start_block (GetLocation ($2));
6235 current_block.IsCompilerGenerated = true;
6237 var lt = (LocatedToken) $4;
6238 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6239 current_block.AddLocalName (li);
6241 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6242 current_block.AddStatement (f);
6244 lbag.AddStatement (f, GetLocation ($2));
6245 $$ = end_block (GetLocation ($5));
6247 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6249 start_block (GetLocation ($2));
6250 current_block.IsCompilerGenerated = true;
6252 var lt = (LocatedToken) $4;
6253 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6254 current_block.AddLocalName (li);
6259 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6260 Warning_EmptyStatement (GetLocation ($9));
6262 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6263 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6264 end_block (GetLocation ($7));
6272 | continue_statement
6282 $$ = new Break (GetLocation ($1));
6283 lbag.AddStatement ($$, GetLocation ($2));
6288 : CONTINUE SEMICOLON
6290 $$ = new Continue (GetLocation ($1));
6291 lbag.AddStatement ($$, GetLocation ($2));
6295 Error_SyntaxError (yyToken);
6296 $$ = new Continue (GetLocation ($1));
6301 : GOTO identifier_inside_body SEMICOLON
6303 var lt = (LocatedToken) $2;
6304 $$ = new Goto (lt.Value, GetLocation ($1));
6305 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6307 | GOTO CASE constant_expression SEMICOLON
6309 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6310 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6312 | GOTO DEFAULT SEMICOLON
6314 $$ = new GotoDefault (GetLocation ($1));
6315 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6320 : RETURN opt_expression SEMICOLON
6322 $$ = new Return ((Expression) $2, GetLocation ($1));
6323 lbag.AddStatement ($$, GetLocation ($3));
6325 | RETURN expression error
6327 Error_SyntaxError (yyToken);
6328 $$ = new Return ((Expression) $2, GetLocation ($1));
6332 Error_SyntaxError (yyToken);
6333 $$ = new Return (null, GetLocation ($1));
6338 : THROW opt_expression SEMICOLON
6340 $$ = new Throw ((Expression) $2, GetLocation ($1));
6341 lbag.AddStatement ($$, GetLocation ($3));
6343 | THROW expression error
6345 Error_SyntaxError (yyToken);
6346 $$ = new Throw ((Expression) $2, GetLocation ($1));
6350 Error_SyntaxError (yyToken);
6351 $$ = new Throw (null, GetLocation ($1));
6356 : identifier_inside_body RETURN opt_expression SEMICOLON
6358 var lt = (LocatedToken) $1;
6359 string s = lt.Value;
6361 report.Error (1003, lt.Location, "; expected");
6362 } else if ($3 == null) {
6363 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6364 } else if (lang_version == LanguageVersion.ISO_1){
6365 FeatureIsNotAvailable (lt.Location, "iterators");
6368 current_block.Explicit.RegisterIteratorYield ();
6369 $$ = new Yield ((Expression) $3, lt.Location);
6370 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6372 | identifier_inside_body RETURN expression error
6374 Error_SyntaxError (yyToken);
6376 var lt = (LocatedToken) $1;
6377 string s = lt.Value;
6379 report.Error (1003, lt.Location, "; expected");
6380 } else if ($3 == null) {
6381 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6382 } else if (lang_version == LanguageVersion.ISO_1){
6383 FeatureIsNotAvailable (lt.Location, "iterators");
6386 current_block.Explicit.RegisterIteratorYield ();
6387 $$ = new Yield ((Expression) $3, lt.Location);
6388 lbag.AddStatement ($$, GetLocation ($2));
6390 | identifier_inside_body BREAK SEMICOLON
6392 var lt = (LocatedToken) $1;
6393 string s = lt.Value;
6395 report.Error (1003, lt.Location, "; expected");
6396 } else if (lang_version == LanguageVersion.ISO_1){
6397 FeatureIsNotAvailable (lt.Location, "iterators");
6400 current_block.ParametersBlock.TopBlock.IsIterator = true;
6401 $$ = new YieldBreak (lt.Location);
6402 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6412 : TRY block catch_clauses
6414 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6416 | TRY block FINALLY block
6418 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6419 lbag.AddStatement ($$, GetLocation ($3));
6421 | TRY block catch_clauses FINALLY block
6423 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6424 lbag.AddStatement ($$, GetLocation ($4));
6428 Error_SyntaxError (1524, yyToken);
6429 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6436 var l = new List<Catch> (2);
6441 | catch_clauses catch_clause
6443 var l = (List<Catch>) $1;
6445 Catch c = (Catch) $2;
6446 var prev_catch = l [l.Count - 1];
6447 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6448 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6458 | identifier_inside_body
6462 : CATCH opt_catch_filter block
6464 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6465 c.Filter = (CatchFilterExpression) $2;
6468 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6470 start_block (GetLocation ($2));
6471 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6472 c.TypeExpression = (FullNamedExpression) $3;
6475 var lt = (LocatedToken) $4;
6476 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6477 current_block.AddLocalName (c.Variable);
6480 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6482 lexer.parsing_catch_when = true;
6484 opt_catch_filter_or_error
6486 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6489 | CATCH open_parens_any error
6491 if (yyToken == Token.CLOSE_PARENS) {
6492 report.Error (1015, lexer.Location,
6493 "A type that derives from `System.Exception', `object', or `string' expected");
6495 Error_SyntaxError (yyToken);
6498 $$ = new Catch (null, GetLocation ($1));
6502 opt_catch_filter_or_error
6503 : opt_catch_filter block_prepared
6509 end_block (Location.Null);
6510 Error_SyntaxError (yyToken);
6517 lexer.parsing_catch_when = false;
6521 lexer.parsing_catch_when = false;
6523 open_parens_any expression CLOSE_PARENS
6525 if (lang_version <= LanguageVersion.V_5)
6526 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6528 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6529 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6536 $$ = new Checked ((Block) $2, GetLocation ($1));
6543 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6550 if (!settings.Unsafe)
6551 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6553 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6558 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6560 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6561 Warning_EmptyStatement (GetLocation ($5));
6563 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6564 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6566 | LOCK open_parens_any expression error
6568 Error_SyntaxError (yyToken);
6570 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6571 lbag.AddStatement ($$, GetLocation ($2));
6576 : FIXED open_parens_any variable_type identifier_inside_body
6578 start_block (GetLocation ($2));
6580 current_block.IsCompilerGenerated = true;
6581 var lt = (LocatedToken) $4;
6582 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6583 current_block.AddLocalName (li);
6584 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6586 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6588 $$ = current_variable;
6589 current_variable = null;
6593 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6594 Warning_EmptyStatement (GetLocation ($10));
6596 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6597 current_block.AddStatement (f);
6598 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6599 $$ = end_block (GetLocation ($8));
6604 : USING open_parens_any variable_type identifier_inside_body
6606 start_block (GetLocation ($2));
6608 current_block.IsCompilerGenerated = true;
6609 var lt = (LocatedToken) $4;
6610 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6611 current_block.AddLocalName (li);
6612 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6614 using_initialization CLOSE_PARENS
6616 $$ = current_variable;
6617 current_variable = null;
6621 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6622 Warning_EmptyStatement (GetLocation ($9));
6624 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6625 current_block.AddStatement (u);
6626 $$ = end_block (GetLocation ($7));
6628 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6630 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6631 Warning_EmptyStatement (GetLocation ($5));
6633 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6634 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6636 | USING open_parens_any expression error
6638 Error_SyntaxError (yyToken);
6640 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6641 lbag.AddStatement ($$, GetLocation ($2));
6645 using_initialization
6646 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6649 // It has to be here for the parent to safely restore artificial block
6650 Error_SyntaxError (yyToken);
6654 using_or_fixed_variable_initializer
6657 Error_MissingInitializer (lexer.Location);
6659 | ASSIGN variable_initializer
6661 current_variable.Initializer = (Expression) $2;
6662 $$ = current_variable;
6670 : first_from_clause query_body
6672 lexer.query_parsing = false;
6674 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6676 from.Tail.Next = (Linq.AQueryClause)$2;
6679 current_block.SetEndLocation (lexer.Location);
6680 current_block = current_block.Parent;
6682 | nested_from_clause query_body
6684 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6686 from.Tail.Next = (Linq.AQueryClause)$2;
6689 current_block.SetEndLocation (lexer.Location);
6690 current_block = current_block.Parent;
6693 // Bubble up COMPLETE_COMPLETION productions
6694 | first_from_clause COMPLETE_COMPLETION {
6695 lexer.query_parsing = false;
6698 current_block.SetEndLocation (lexer.Location);
6699 current_block = current_block.Parent;
6701 | nested_from_clause COMPLETE_COMPLETION {
6703 current_block.SetEndLocation (lexer.Location);
6704 current_block = current_block.Parent;
6709 : FROM_FIRST identifier_inside_body IN expression
6711 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6713 var lt = (LocatedToken) $2;
6714 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6715 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6716 lbag.AddLocation (clause, GetLocation ($3));
6717 $$ = new Linq.QueryExpression (clause);
6719 | FROM_FIRST type identifier_inside_body IN expression
6721 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6723 var lt = (LocatedToken) $3;
6724 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6725 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6726 IdentifierType = (FullNamedExpression)$2
6728 lbag.AddLocation (clause, GetLocation ($4));
6729 $$ = new Linq.QueryExpression (clause);
6734 : FROM identifier_inside_body IN expression
6736 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6738 var lt = (LocatedToken) $2;
6739 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6740 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6741 lbag.AddLocation (clause, GetLocation ($3));
6742 $$ = new Linq.QueryExpression (clause);
6744 | FROM type identifier_inside_body IN expression
6746 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6748 var lt = (LocatedToken) $3;
6749 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6750 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6751 IdentifierType = (FullNamedExpression)$2
6753 lbag.AddLocation (clause, GetLocation ($4));
6754 $$ = new Linq.QueryExpression (clause);
6759 : FROM identifier_inside_body IN
6761 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6765 var lt = (LocatedToken) $2;
6766 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6767 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6769 current_block.SetEndLocation (lexer.Location);
6770 current_block = current_block.Parent;
6772 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6773 lbag.AddLocation ($$, GetLocation ($3));
6775 | FROM type identifier_inside_body IN
6777 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6781 var lt = (LocatedToken) $3;
6782 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6784 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6785 IdentifierType = (FullNamedExpression)$2
6788 current_block.SetEndLocation (lexer.Location);
6789 current_block = current_block.Parent;
6791 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6793 lbag.AddLocation ($$, GetLocation ($4));
6798 : query_body_clauses select_or_group_clause opt_query_continuation
6800 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6803 head.Next = (Linq.AQueryClause)$3;
6806 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6807 clause.Tail.Next = head;
6813 | select_or_group_clause opt_query_continuation
6815 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6818 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6819 clause.Tail.Next = head;
6825 | query_body_clauses COMPLETE_COMPLETION
6826 | query_body_clauses error
6828 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6833 Error_SyntaxError (yyToken);
6838 select_or_group_clause
6841 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6845 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6847 current_block.SetEndLocation (lexer.Location);
6848 current_block = current_block.Parent;
6852 if (linq_clause_blocks == null)
6853 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6855 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6856 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6860 current_block.SetEndLocation (lexer.Location);
6861 current_block = current_block.Parent;
6863 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6867 var obj = (object[]) $5;
6869 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6870 lbag.AddLocation ($$, (Location) obj[1]);
6872 current_block.SetEndLocation (lexer.Location);
6873 current_block = current_block.Parent;
6878 : BY expression_or_error
6880 $$ = new object[] { $2, GetLocation ($1) };
6884 Error_SyntaxError (yyToken);
6885 $$ = new object[2] { null, Location.Null };
6891 | query_body_clauses query_body_clause
6893 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6907 : LET identifier_inside_body ASSIGN
6909 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6913 var lt = (LocatedToken) $2;
6914 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6915 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6916 lbag.AddLocation ($$, GetLocation ($3));
6918 current_block.SetEndLocation (lexer.Location);
6919 current_block = current_block.Parent;
6921 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6928 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6932 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6934 current_block.SetEndLocation (lexer.Location);
6935 current_block = current_block.Parent;
6940 : JOIN identifier_inside_body IN
6942 if (linq_clause_blocks == null)
6943 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6945 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6946 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6948 expression_or_error ON
6950 current_block.SetEndLocation (lexer.Location);
6951 current_block = current_block.Parent;
6953 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6954 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6956 expression_or_error EQUALS
6958 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6959 current_block.SetEndLocation (lexer.Location);
6960 current_block = current_block.Parent;
6962 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6964 expression_or_error opt_join_into
6966 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6967 current_block.SetEndLocation (lexer.Location);
6969 var outer_selector = linq_clause_blocks.Pop ();
6970 var block = linq_clause_blocks.Pop ();
6972 var lt = (LocatedToken) $2;
6973 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6974 Linq.RangeVariable into;
6978 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6979 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6982 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6984 var parent = block.Parent;
6985 while (parent is Linq.QueryBlock) {
6986 parent = parent.Parent;
6988 current_block.Parent = parent;
6990 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6992 lt = (LocatedToken) $12;
6993 into = new Linq.RangeVariable (lt.Value, lt.Location);
6995 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6996 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6999 current_block = block.Parent;
7000 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7002 | JOIN type identifier_inside_body IN
7004 if (linq_clause_blocks == null)
7005 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7007 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7008 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7010 expression_or_error ON
7012 current_block.SetEndLocation (lexer.Location);
7013 current_block = current_block.Parent;
7015 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7016 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7018 expression_or_error EQUALS
7020 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7021 current_block.SetEndLocation (lexer.Location);
7022 current_block = current_block.Parent;
7024 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7026 expression_or_error opt_join_into
7028 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7029 current_block.SetEndLocation (lexer.Location);
7031 var outer_selector = linq_clause_blocks.Pop ();
7032 var block = linq_clause_blocks.Pop ();
7034 var lt = (LocatedToken) $3;
7035 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7036 Linq.RangeVariable into;
7040 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7041 IdentifierType = (FullNamedExpression)$2
7043 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7046 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7048 var parent = block.Parent;
7049 while (parent is Linq.QueryBlock) {
7050 parent = parent.Parent;
7052 current_block.Parent = parent;
7054 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7056 lt = (LocatedToken) $13;
7057 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7059 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7060 IdentifierType = (FullNamedExpression)$2
7064 current_block = block.Parent;
7065 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7071 | INTO identifier_inside_body
7080 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7084 current_block.SetEndLocation (lexer.Location);
7085 current_block = current_block.Parent;
7095 current_block.SetEndLocation (lexer.Location);
7096 current_block = current_block.Parent;
7098 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7102 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7109 | orderings_then_by COMMA
7111 current_block.SetEndLocation (lexer.Location);
7112 current_block = current_block.Parent;
7114 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7118 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7126 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7128 | expression ASCENDING
7130 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7131 lbag.AddLocation ($$, GetLocation ($2));
7133 | expression DESCENDING
7135 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7136 lbag.AddLocation ($$, GetLocation ($2));
7143 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7145 | expression ASCENDING
7147 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7148 lbag.AddLocation ($$, GetLocation ($2));
7150 | expression DESCENDING
7152 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7153 lbag.AddLocation ($$, GetLocation ($2));
7158 opt_query_continuation
7160 | INTO identifier_inside_body
7162 // query continuation block is not linked with query block but with block
7163 // before. This means each query can use same range variable names for
7164 // different identifiers.
7166 current_block.SetEndLocation (GetLocation ($1));
7167 current_block = current_block.Parent;
7169 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7171 if (linq_clause_blocks == null)
7172 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7174 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7178 var current_block = linq_clause_blocks.Pop ();
7179 var lt = (LocatedToken) $2;
7180 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7181 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7182 next = (Linq.AQueryClause)$4
7188 // Support for using the compiler as an interactive parser
7190 // The INTERACTIVE_PARSER token is first sent to parse our
7191 // productions; If the result is a Statement, the parsing
7192 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7193 // to setup the blocks in advance.
7195 // This setup is here so that in the future we can add
7196 // support for other constructs (type parsing, namespaces, etc)
7197 // that do not require a block to be setup in advance
7201 : EVAL_STATEMENT_PARSER EOF
7202 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7203 | EVAL_STATEMENT_PARSER
7205 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7207 // (ref object retval)
7208 Parameter [] mpar = new Parameter [1];
7209 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7211 ParametersCompiled pars = new ParametersCompiled (mpar);
7212 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7213 if (settings.Unsafe)
7214 mods |= Modifiers.UNSAFE;
7216 current_local_parameters = pars;
7217 var method = new InteractiveMethod (
7219 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7223 current_type.AddMember (method);
7224 oob_stack.Push (method);
7226 interactive_async = false;
7228 ++lexer.parsing_block;
7229 start_block (lexer.Location);
7231 interactive_statement_list opt_COMPLETE_COMPLETION
7233 --lexer.parsing_block;
7234 var method = (InteractiveMethod) oob_stack.Pop ();
7235 method.Block = (ToplevelBlock) end_block(lexer.Location);
7237 if (interactive_async == true) {
7238 method.ChangeToAsync ();
7241 InteractiveResult = (Class) pop_current_class ();
7242 current_local_parameters = null;
7244 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7247 interactive_compilation_unit
7248 : opt_extern_alias_directives opt_using_directives
7249 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7252 opt_COMPLETE_COMPLETION
7254 | COMPLETE_COMPLETION
7257 close_brace_or_complete_completion
7259 | COMPLETE_COMPLETION
7263 // XML documentation code references micro parser
7265 documentation_parsing
7268 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7273 : doc_type_declaration_name opt_doc_method_sig
7275 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7277 | builtin_types opt_doc_method_sig
7279 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7280 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7283 | VOID opt_doc_method_sig
7285 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7286 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7289 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7291 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7292 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7293 var lt = (LocatedToken) $3;
7294 $$ = new MemberName (lt.Value);
7296 | doc_type_declaration_name DOT THIS
7298 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7300 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7302 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7304 opt_doc_parameters CLOSE_BRACKET
7306 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7307 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7309 | EXPLICIT OPERATOR type opt_doc_method_sig
7311 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7312 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7313 module.DocumentationBuilder.ParsedParameters = p;
7314 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7317 | IMPLICIT OPERATOR type opt_doc_method_sig
7319 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7320 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7321 module.DocumentationBuilder.ParsedParameters = p;
7322 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7325 | OPERATOR overloadable_operator opt_doc_method_sig
7327 var p = (List<DocumentationParameter>)$3;
7328 module.DocumentationBuilder.ParsedParameters = p;
7329 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7334 doc_type_declaration_name
7335 : type_declaration_name
7336 | doc_type_declaration_name DOT type_declaration_name
7338 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7346 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7348 opt_doc_parameters CLOSE_PARENS
7357 $$ = new List<DocumentationParameter> (0);
7365 var parameters = new List<DocumentationParameter> ();
7366 parameters.Add ((DocumentationParameter) $1);
7369 | doc_parameters COMMA doc_parameter
7371 var parameters = $1 as List<DocumentationParameter>;
7372 parameters.Add ((DocumentationParameter) $3);
7378 : opt_parameter_modifier parameter_type
7381 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7383 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7390 // A class used to hold info about an operator declarator
7392 class OperatorDeclaration {
7393 public readonly Operator.OpType optype;
7394 public readonly FullNamedExpression ret_type;
7395 public readonly Location location;
7397 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7400 this.ret_type = ret_type;
7401 this.location = location;
7405 void Error_ExpectingTypeName (Expression expr)
7407 if (expr is Invocation){
7408 report.Error (1002, expr.Location, "Expecting `;'");
7410 expr.Error_InvalidExpressionStatement (report);
7414 void Error_ParameterModifierNotValid (string modifier, Location loc)
7416 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7420 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7422 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7423 Parameter.GetModifierSignature (mod));
7426 void Error_TypeExpected (Location loc)
7428 report.Error (1031, loc, "Type expected");
7431 void Error_UnsafeCodeNotAllowed (Location loc)
7433 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7436 void Warning_EmptyStatement (Location loc)
7438 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7441 void Error_NamedArgumentExpected (NamedArgument a)
7443 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7446 void Error_MissingInitializer (Location loc)
7448 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7451 object Error_AwaitAsIdentifier (object token)
7454 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7455 return new LocatedToken ("await", GetLocation (token));
7461 void push_current_container (TypeDefinition tc, object partial_token)
7463 if (module.Evaluator != null){
7464 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7468 undo.AddTypeContainer (current_container, tc);
7471 if (partial_token != null)
7472 current_container.AddPartial (tc);
7474 current_container.AddTypeContainer (tc);
7476 ++lexer.parsing_declaration;
7477 current_container = tc;
7481 TypeContainer pop_current_class ()
7483 var retval = current_container;
7485 current_container = current_container.Parent;
7486 current_type = current_type.Parent as TypeDefinition;
7491 [System.Diagnostics.Conditional ("FULL_AST")]
7492 void StoreModifierLocation (object token, Location loc)
7497 if (mod_locations == null)
7498 mod_locations = new List<Tuple<Modifiers, Location>> ();
7500 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7503 [System.Diagnostics.Conditional ("FULL_AST")]
7504 void PushLocation (Location loc)
7506 if (location_stack == null)
7507 location_stack = new Stack<Location> ();
7509 location_stack.Push (loc);
7512 Location PopLocation ()
7514 if (location_stack == null)
7515 return Location.Null;
7517 return location_stack.Pop ();
7520 string CheckAttributeTarget (int token, string a, Location l)
7523 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7527 if (!Tokenizer.IsValidIdentifier (a)) {
7528 Error_SyntaxError (token);
7530 report.Warning (658, 1, l,
7531 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7534 return string.Empty;
7537 static bool IsUnaryOperator (Operator.OpType op)
7541 case Operator.OpType.LogicalNot:
7542 case Operator.OpType.OnesComplement:
7543 case Operator.OpType.Increment:
7544 case Operator.OpType.Decrement:
7545 case Operator.OpType.True:
7546 case Operator.OpType.False:
7547 case Operator.OpType.UnaryPlus:
7548 case Operator.OpType.UnaryNegation:
7554 void syntax_error (Location l, string msg)
7556 report.Error (1003, l, "Syntax error, " + msg);
7561 public Tokenizer Lexer {
7567 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7568 : this (reader, file, file.Compiler.Report, session)
7572 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7575 current_container = current_namespace = file;
7577 this.module = file.Module;
7578 this.compiler = file.Compiler;
7579 this.settings = compiler.Settings;
7580 this.report = report;
7582 lang_version = settings.Version;
7583 yacc_verbose_flag = settings.VerboseParserFlag;
7584 doc_support = settings.DocumentationFile != null;
7585 lexer = new Tokenizer (reader, file, session, report);
7586 oob_stack = new Stack<object> ();
7587 lbag = session.LocationsBag;
7588 use_global_stacks = session.UseJayGlobalArrays;
7589 parameters_bucket = session.ParametersStack;
7592 public void parse ()
7594 eof_token = Token.EOF;
7597 if (yacc_verbose_flag > 1)
7598 yyparse (lexer, new yydebug.yyDebugSimple ());
7602 Tokenizer tokenizer = lexer as Tokenizer;
7603 tokenizer.cleanup ();
7604 } catch (Exception e){
7605 if (e is yyParser.yyUnexpectedEof) {
7606 Error_SyntaxError (yyToken);
7607 UnexpectedEOF = true;
7611 if (e is yyParser.yyException) {
7612 if (report.Errors == 0)
7613 report.Error (-25, lexer.Location, "Parsing error");
7615 // Used by compiler-tester to test internal errors
7616 if (yacc_verbose_flag > 0 || e is FatalException)
7619 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7624 void CheckToken (int error, int yyToken, string msg, Location loc)
7626 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7627 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7629 report.Error (error, loc, msg);
7632 string ConsumeStoredComment ()
7634 string s = tmpComment;
7636 Lexer.doc_state = XmlCommentState.Allowed;
7640 void FeatureIsNotAvailable (Location loc, string feature)
7642 report.FeatureIsNotAvailable (compiler, loc, feature);
7645 Location GetLocation (object obj)
7647 var lt = obj as LocatedToken;
7651 var mn = obj as MemberName;
7655 var expr = obj as Expression;
7657 return expr.Location;
7659 return lexer.Location;
7662 void start_block (Location loc)
7664 if (current_block == null) {
7665 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7666 parsing_anonymous_method = false;
7667 } else if (parsing_anonymous_method) {
7668 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7669 parsing_anonymous_method = false;
7671 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7676 end_block (Location loc)
7678 Block retval = current_block.Explicit;
7679 retval.SetEndLocation (loc);
7680 current_block = retval.Parent;
7684 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7686 oob_stack.Push (current_anonymous_method);
7687 oob_stack.Push (current_local_parameters);
7688 oob_stack.Push (current_variable);
7689 oob_stack.Push (async_block);
7691 current_local_parameters = parameters;
7693 if (lang_version <= LanguageVersion.ISO_2)
7694 FeatureIsNotAvailable (loc, "lambda expressions");
7696 current_anonymous_method = new LambdaExpression (loc);
7698 if (lang_version == LanguageVersion.ISO_1)
7699 FeatureIsNotAvailable (loc, "anonymous methods");
7701 current_anonymous_method = new AnonymousMethodExpression (loc);
7704 async_block = isAsync;
7705 // Force the next block to be created as a ToplevelBlock
7706 parsing_anonymous_method = true;
7710 * Completes the anonymous method processing, if lambda_expr is null, this
7711 * means that we have a Statement instead of an Expression embedded
7713 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7715 AnonymousMethodExpression retval;
7718 anon_block.IsAsync = true;
7720 current_anonymous_method.Block = anon_block;
7721 retval = current_anonymous_method;
7723 async_block = (bool) oob_stack.Pop ();
7724 current_variable = (BlockVariable) oob_stack.Pop ();
7725 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7726 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7731 void Error_SyntaxError (int token)
7733 Error_SyntaxError (0, token);
7736 void Error_SyntaxError (int error_code, int token)
7738 Error_SyntaxError (error_code, token, "Unexpected symbol");
7741 void Error_SyntaxError (int error_code, int token, string msg)
7743 Lexer.CompleteOnEOF = false;
7745 // An error message has been reported by tokenizer
7746 if (token == Token.ERROR)
7749 // Avoid duplicit error message after unterminated string literals
7750 if (token == Token.LITERAL && lexer.Location.Column == 0)
7753 string symbol = GetSymbolName (token);
7754 string expecting = GetExpecting ();
7755 var loc = lexer.Location - symbol.Length;
7757 if (error_code == 0) {
7758 if (expecting == "`identifier'") {
7759 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7760 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7765 expecting = "identifier";
7766 } else if (expecting == "`)'") {
7773 if (string.IsNullOrEmpty (expecting))
7774 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7776 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7779 string GetExpecting ()
7781 int [] tokens = yyExpectingTokens (yyExpectingState);
7782 var names = new List<string> (tokens.Length);
7783 bool has_type = false;
7784 bool has_identifier = false;
7785 for (int i = 0; i < tokens.Length; i++){
7786 int token = tokens [i];
7787 has_identifier |= token == Token.IDENTIFIER;
7789 string name = GetTokenName (token);
7790 if (name == "<internal>")
7793 has_type |= name == "type";
7794 if (names.Contains (name))
7801 // Too many tokens to enumerate
7803 if (names.Count > 8)
7806 if (has_type && has_identifier)
7807 names.Remove ("identifier");
7809 if (names.Count == 1)
7810 return "`" + GetTokenName (tokens [0]) + "'";
7812 StringBuilder sb = new StringBuilder ();
7814 int count = names.Count;
7815 for (int i = 0; i < count; i++){
7816 bool last = i + 1 == count;
7820 sb.Append (names [i]);
7821 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7823 return sb.ToString ();
7827 string GetSymbolName (int token)
7831 return ((Constant)lexer.Value).GetValue ().ToString ();
7832 case Token.IDENTIFIER:
7833 return ((LocatedToken)lexer.Value).Value;
7875 case Token.BITWISE_AND:
7877 case Token.BITWISE_OR:
7891 case Token.OP_SHIFT_LEFT:
7893 case Token.OP_SHIFT_RIGHT:
7913 case Token.OP_COALESCING:
7915 case Token.OP_MULT_ASSIGN:
7917 case Token.OP_DIV_ASSIGN:
7919 case Token.OP_MOD_ASSIGN:
7921 case Token.OP_ADD_ASSIGN:
7923 case Token.OP_SUB_ASSIGN:
7925 case Token.OP_SHIFT_LEFT_ASSIGN:
7927 case Token.OP_SHIFT_RIGHT_ASSIGN:
7929 case Token.OP_AND_ASSIGN:
7931 case Token.OP_XOR_ASSIGN:
7933 case Token.OP_OR_ASSIGN:
7937 return GetTokenName (token);
7940 static string GetTokenName (int token)
7943 case Token.ABSTRACT:
7965 case Token.CONTINUE:
7969 case Token.DELEGATE:
7979 case Token.EXPLICIT:
7982 case Token.EXTERN_ALIAS:
7998 case Token.IMPLICIT:
8002 case Token.INTERFACE:
8004 case Token.INTERNAL:
8010 case Token.NAMESPACE:
8016 case Token.OPERATOR:
8020 case Token.OVERRIDE:
8026 case Token.PROTECTED:
8030 case Token.READONLY:
8042 case Token.STACKALLOC:
8043 return "stackalloc";
8060 case Token.UNCHECKED:
8068 case Token.VOLATILE:
8076 case Token.REFVALUE:
8077 return "__refvalue";
8087 case Token.FROM_FIRST:
8105 case Token.ASCENDING:
8107 case Token.DESCENDING:
8108 return "descending";
8115 case Token.OPEN_BRACE:
8117 case Token.CLOSE_BRACE:
8119 case Token.OPEN_BRACKET:
8120 case Token.OPEN_BRACKET_EXPR:
8122 case Token.CLOSE_BRACKET:
8124 case Token.OPEN_PARENS_CAST:
8125 case Token.OPEN_PARENS_LAMBDA:
8126 case Token.OPEN_PARENS:
8128 case Token.CLOSE_PARENS:
8134 case Token.DEFAULT_COLON:
8138 case Token.SEMICOLON:
8144 case Token.INTERPOLATED_STRING_END:
8146 case Token.INTERPOLATED_STRING:
8155 case Token.BITWISE_AND:
8156 case Token.BITWISE_OR:
8163 case Token.OP_SHIFT_LEFT:
8164 case Token.OP_SHIFT_RIGHT:
8172 case Token.OP_COALESCING:
8173 case Token.OP_MULT_ASSIGN:
8174 case Token.OP_DIV_ASSIGN:
8175 case Token.OP_MOD_ASSIGN:
8176 case Token.OP_ADD_ASSIGN:
8177 case Token.OP_SUB_ASSIGN:
8178 case Token.OP_SHIFT_LEFT_ASSIGN:
8179 case Token.OP_SHIFT_RIGHT_ASSIGN:
8180 case Token.OP_AND_ASSIGN:
8181 case Token.OP_XOR_ASSIGN:
8182 case Token.OP_OR_ASSIGN:
8183 case Token.INTERR_OPERATOR:
8184 return "<operator>";
8206 case Token.OP_GENERICS_LT:
8207 case Token.GENERIC_DIMENSION:
8209 case Token.OP_GENERICS_GT:
8212 case Token.INTERR_NULLABLE:
8214 case Token.DOUBLE_COLON:
8218 case Token.IDENTIFIER:
8220 return "identifier";
8223 return "end-of-file";
8225 // All of these are internal.
8228 case Token.FIRST_KEYWORD:
8229 case Token.EVAL_COMPILATION_UNIT_PARSER:
8230 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8231 case Token.EVAL_STATEMENT_PARSER:
8232 case Token.LAST_KEYWORD:
8233 case Token.GENERATE_COMPLETION:
8234 case Token.COMPLETE_COMPLETION:
8235 return "<internal>";
8237 // A bit more robust.
8239 return yyNames [token];