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 ());
1862 property.DocComment = ConsumeStoredComment ();
1864 current_type.AddMember (property);
1866 current_local_parameters = null;
1870 opt_property_initializer
1874 ++lexer.parsing_block;
1875 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1876 start_block (GetLocation ($1));
1878 property_initializer SEMICOLON
1880 --lexer.parsing_block;
1881 ((Property)current_property).Initializer = (Expression) $3;
1882 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1883 end_block (GetLocation ($4));
1884 current_local_parameters = null;
1888 property_initializer
1894 : opt_attributes opt_modifiers
1895 member_type indexer_declaration_name OPEN_BRACKET
1897 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1899 opt_formal_parameter_list CLOSE_BRACKET
1901 valid_param_mod = 0;
1902 var type = (FullNamedExpression) $3;
1903 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1905 current_property = indexer;
1907 current_type.AddIndexer (indexer);
1908 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1910 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1911 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1913 if (indexer.ParameterInfo.IsEmpty) {
1914 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1918 tmpComment = Lexer.consume_doc_comment ();
1919 Lexer.doc_state = XmlCommentState.Allowed;
1922 lexer.PropertyParsing = true;
1923 current_local_parameters = (ParametersCompiled) $7;
1927 lexer.PropertyParsing = false;
1928 current_local_parameters = null;
1930 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1931 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1934 current_property.DocComment = ConsumeStoredComment ();
1936 current_property = null;
1941 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1943 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1947 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1948 current_property.Get.Block = (ToplevelBlock) $1;
1952 accessor_declarations
1953 : get_accessor_declaration
1954 | get_accessor_declaration accessor_declarations
1955 | set_accessor_declaration
1956 | set_accessor_declaration accessor_declarations
1959 if (yyToken == Token.CLOSE_BRACE) {
1960 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1962 if (yyToken == Token.SEMICOLON)
1963 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1965 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1970 get_accessor_declaration
1971 : opt_attributes opt_modifiers GET
1973 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1974 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1977 if (current_property.Get != null) {
1978 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1981 if (current_property is Indexer) {
1982 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1983 (Attributes) $1, GetLocation ($3));
1985 current_property.Get = new Property.GetMethod (current_property,
1986 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1989 current_local_parameters = current_property.Get.ParameterInfo;
1990 lbag.AddMember (current_property.Get, mod_locations);
1991 lexer.PropertyParsing = false;
1996 current_property.Get.Block = (ToplevelBlock) $5;
1998 if (current_container.Kind == MemberKind.Interface) {
1999 report.Error (531, current_property.Get.Block.StartLocation,
2000 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
2004 current_local_parameters = null;
2005 lexer.PropertyParsing = true;
2008 if (Lexer.doc_state == XmlCommentState.Error)
2009 Lexer.doc_state = XmlCommentState.NotAllowed;
2013 set_accessor_declaration
2014 : opt_attributes opt_modifiers SET
2016 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
2017 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
2020 if (current_property.Set != null) {
2021 report.Error (1007, GetLocation ($3), "Property accessor already defined");
2024 if (current_property is Indexer) {
2025 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
2026 ParametersCompiled.MergeGenerated (compiler,
2027 ((Indexer)current_property).ParameterInfo, true, new Parameter (
2028 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
2030 (Attributes) $1, GetLocation ($3));
2032 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
2033 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
2034 (Attributes) $1, GetLocation ($3));
2037 current_local_parameters = current_property.Set.ParameterInfo;
2038 lbag.AddMember (current_property.Set, mod_locations);
2039 lexer.PropertyParsing = false;
2044 current_property.Set.Block = (ToplevelBlock) $5;
2046 if (current_container.Kind == MemberKind.Interface) {
2047 report.Error (531, current_property.Set.Block.StartLocation,
2048 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2052 current_local_parameters = null;
2053 lexer.PropertyParsing = true;
2056 && Lexer.doc_state == XmlCommentState.Error)
2057 Lexer.doc_state = XmlCommentState.NotAllowed;
2070 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2075 interface_declaration
2082 type_declaration_name
2084 lexer.ConstraintsParsing = true;
2085 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2086 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2089 opt_type_parameter_constraints_clauses
2091 lexer.ConstraintsParsing = false;
2094 current_container.SetConstraints ((List<Constraints>) $9);
2097 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2098 Lexer.doc_state = XmlCommentState.Allowed;
2101 lexer.parsing_modifiers = true;
2103 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2105 --lexer.parsing_declaration;
2107 Lexer.doc_state = XmlCommentState.Allowed;
2112 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2114 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2116 $$ = pop_current_class ();
2118 | opt_attributes opt_modifiers opt_partial INTERFACE error
2120 Error_SyntaxError (yyToken);
2124 opt_interface_member_declarations
2126 | interface_member_declarations
2129 interface_member_declarations
2130 : interface_member_declaration
2132 lexer.parsing_modifiers = true;
2133 lexer.parsing_block = 0;
2135 | interface_member_declarations interface_member_declaration
2137 lexer.parsing_modifiers = true;
2138 lexer.parsing_block = 0;
2142 interface_member_declaration
2143 : constant_declaration
2145 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2149 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2151 | method_declaration
2152 | property_declaration
2154 | indexer_declaration
2155 | operator_declaration
2157 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2159 | constructor_declaration
2161 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2165 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2169 operator_declaration
2170 : opt_attributes opt_modifiers operator_declarator
2173 method_body_expression_block
2175 OperatorDeclaration decl = (OperatorDeclaration) $3;
2177 Operator op = new Operator (
2178 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2179 current_local_parameters,
2180 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2182 if (op.Block == null)
2183 op.ParameterInfo.CheckParameters (op);
2186 op.DocComment = tmpComment;
2187 Lexer.doc_state = XmlCommentState.Allowed;
2190 // Note again, checking is done in semantic analysis
2191 current_type.AddOperator (op);
2193 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2196 current_local_parameters = null;
2201 : type_expression_or_array
2204 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2205 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2210 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2212 valid_param_mod = ParameterModifierType.DefaultValue;
2213 if ((Operator.OpType) $3 == Operator.OpType.Is)
2214 valid_param_mod |= ParameterModifierType.Out;
2216 opt_formal_parameter_list CLOSE_PARENS
2218 valid_param_mod = 0;
2220 Location loc = GetLocation ($2);
2221 Operator.OpType op = (Operator.OpType) $3;
2222 current_local_parameters = (ParametersCompiled)$6;
2224 int p_count = current_local_parameters.Count;
2226 if (op == Operator.OpType.Addition)
2227 op = Operator.OpType.UnaryPlus;
2228 else if (op == Operator.OpType.Subtraction)
2229 op = Operator.OpType.UnaryNegation;
2232 if (IsUnaryOperator (op)) {
2234 report.Error (1020, loc, "Overloadable binary operator expected");
2235 } else if (p_count != 1) {
2236 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2237 Operator.GetName (op));
2239 } else if (op == Operator.OpType.Is) {
2240 // TODO: Special checks for is operator
2243 report.Error (1019, loc, "Overloadable unary operator expected");
2244 } else if (p_count != 2) {
2245 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2246 Operator.GetName (op));
2251 tmpComment = Lexer.consume_doc_comment ();
2252 Lexer.doc_state = XmlCommentState.NotAllowed;
2255 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2256 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2258 | conversion_operator_declarator
2261 overloadable_operator
2263 : BANG { $$ = Operator.OpType.LogicalNot; }
2264 | TILDE { $$ = Operator.OpType.OnesComplement; }
2265 | OP_INC { $$ = Operator.OpType.Increment; }
2266 | OP_DEC { $$ = Operator.OpType.Decrement; }
2267 | TRUE { $$ = Operator.OpType.True; }
2268 | FALSE { $$ = Operator.OpType.False; }
2269 // Unary and binary:
2270 | PLUS { $$ = Operator.OpType.Addition; }
2271 | MINUS { $$ = Operator.OpType.Subtraction; }
2273 | STAR { $$ = Operator.OpType.Multiply; }
2274 | DIV { $$ = Operator.OpType.Division; }
2275 | PERCENT { $$ = Operator.OpType.Modulus; }
2276 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2277 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2278 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2279 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2280 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2281 | OP_EQ { $$ = Operator.OpType.Equality; }
2282 | OP_NE { $$ = Operator.OpType.Inequality; }
2283 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2284 | OP_LT { $$ = Operator.OpType.LessThan; }
2285 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2286 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2289 if (lang_version != LanguageVersion.Experimental)
2290 FeatureIsNotAvailable (GetLocation ($1), "is user operator");
2292 $$ = Operator.OpType.Is;
2296 conversion_operator_declarator
2297 : IMPLICIT OPERATOR type OPEN_PARENS
2299 valid_param_mod = ParameterModifierType.DefaultValue;
2301 opt_formal_parameter_list CLOSE_PARENS
2303 valid_param_mod = 0;
2305 Location loc = GetLocation ($2);
2306 current_local_parameters = (ParametersCompiled)$6;
2308 if (current_local_parameters.Count != 1) {
2309 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2313 tmpComment = Lexer.consume_doc_comment ();
2314 Lexer.doc_state = XmlCommentState.NotAllowed;
2317 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2318 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2320 | EXPLICIT OPERATOR type OPEN_PARENS
2322 valid_param_mod = ParameterModifierType.DefaultValue;
2324 opt_formal_parameter_list CLOSE_PARENS
2326 valid_param_mod = 0;
2328 Location loc = GetLocation ($2);
2329 current_local_parameters = (ParametersCompiled)$6;
2331 if (current_local_parameters.Count != 1) {
2332 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2336 tmpComment = Lexer.consume_doc_comment ();
2337 Lexer.doc_state = XmlCommentState.NotAllowed;
2340 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2341 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2345 Error_SyntaxError (yyToken);
2346 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2347 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2351 Error_SyntaxError (yyToken);
2352 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2353 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2357 constructor_declaration
2358 : constructor_declarator
2361 Constructor c = (Constructor) $1;
2362 c.Block = (ToplevelBlock) $2;
2365 c.DocComment = ConsumeStoredComment ();
2367 current_local_parameters = null;
2369 Lexer.doc_state = XmlCommentState.Allowed;
2373 constructor_declarator
2379 tmpComment = Lexer.consume_doc_comment ();
2380 Lexer.doc_state = XmlCommentState.Allowed;
2383 valid_param_mod = ParameterModifierType.All;
2385 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2387 valid_param_mod = 0;
2388 current_local_parameters = (ParametersCompiled) $6;
2390 var lt = (LocatedToken) $3;
2391 var mods = (Modifiers) $2;
2392 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2394 if (lt.Value != current_container.MemberName.Name) {
2395 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2396 } else if ((mods & Modifiers.STATIC) != 0) {
2397 if (!current_local_parameters.IsEmpty) {
2398 report.Error (132, c.Location, "`{0}': The static constructor must be parameterless",
2399 c.GetSignatureForError ());
2402 if ((mods & Modifiers.AccessibilityMask) != 0){
2403 report.Error (515, c.Location,
2404 "`{0}': static constructor cannot have an access modifier",
2405 c.GetSignatureForError ());
2408 if (current_type.Kind == MemberKind.Struct && current_local_parameters.IsEmpty) {
2409 report.Error (568, c.Location, "Structs cannot contain explicit parameterless constructors");
2413 current_type.AddConstructor (c);
2414 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2418 // start block here, so possible anonymous methods inside
2419 // constructor initializer can get correct parent block
2421 start_block (lexer.Location);
2423 opt_constructor_initializer
2426 var c = (Constructor) $8;
2427 c.Initializer = (ConstructorInitializer) $9;
2430 report.Error (514, c.Location,
2431 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2432 c.GetSignatureForError ());
2442 | SEMICOLON { current_block = null; $$ = null; }
2445 opt_constructor_initializer
2447 | constructor_initializer
2450 constructor_initializer
2451 : COLON BASE OPEN_PARENS
2453 ++lexer.parsing_block;
2455 opt_argument_list CLOSE_PARENS
2457 --lexer.parsing_block;
2458 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2459 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2461 | COLON THIS OPEN_PARENS
2463 ++lexer.parsing_block;
2465 opt_argument_list CLOSE_PARENS
2467 --lexer.parsing_block;
2468 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2469 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2473 Error_SyntaxError (yyToken);
2474 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2475 lbag.AddLocation ($$, GetLocation ($1));
2479 Error_SyntaxError (yyToken);
2484 destructor_declaration
2485 : opt_attributes opt_modifiers TILDE
2488 tmpComment = Lexer.consume_doc_comment ();
2489 Lexer.doc_state = XmlCommentState.NotAllowed;
2492 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2494 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2496 var lt = (LocatedToken) $5;
2497 if (lt.Value != current_container.MemberName.Name){
2498 report.Error (574, lt.Location, "Name of destructor must match name of class");
2499 } else if (current_container.Kind != MemberKind.Class){
2500 report.Error (575, lt.Location, "Only class types can contain destructor");
2503 Destructor d = new Destructor (current_type, (Modifiers) $2,
2504 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2506 d.DocComment = ConsumeStoredComment ();
2508 d.Block = (ToplevelBlock) $8;
2509 current_type.AddMember (d);
2510 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2512 current_local_parameters = null;
2519 EVENT type member_declaration_name
2521 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2522 current_type.AddMember (current_event_field);
2524 if (current_event_field.MemberName.ExplicitInterface != null) {
2525 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2526 current_event_field.GetSignatureForError ());
2529 $$ = current_event_field;
2531 opt_event_initializer
2532 opt_event_declarators
2536 current_event_field.DocComment = Lexer.consume_doc_comment ();
2537 Lexer.doc_state = XmlCommentState.Allowed;
2540 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2541 current_event_field = null;
2545 EVENT type member_declaration_name
2548 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2549 current_type.AddMember (current_event);
2550 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2552 lexer.EventParsing = true;
2554 event_accessor_declarations
2556 if (current_container.Kind == MemberKind.Interface)
2557 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2559 lexer.EventParsing = false;
2564 current_event.DocComment = Lexer.consume_doc_comment ();
2565 Lexer.doc_state = XmlCommentState.Allowed;
2568 lbag.AppendToMember (current_event, GetLocation ($9));
2569 current_event = null;
2570 current_local_parameters = null;
2576 Error_SyntaxError (yyToken);
2578 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2582 opt_event_initializer
2586 ++lexer.parsing_block;
2588 event_variable_initializer
2590 --lexer.parsing_block;
2591 current_event_field.Initializer = (Expression) $3;
2595 opt_event_declarators
2603 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2605 | event_declarators event_declarator
2607 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2614 var lt = (LocatedToken) $2;
2615 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2616 lbag.AddLocation ($$, GetLocation ($1));
2618 | COMMA IDENTIFIER ASSIGN
2620 ++lexer.parsing_block;
2622 event_variable_initializer
2624 --lexer.parsing_block;
2625 var lt = (LocatedToken) $2;
2626 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2627 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2631 event_variable_initializer
2633 if (current_container.Kind == MemberKind.Interface) {
2634 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2635 current_event_field.GetSignatureForError ());
2638 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2639 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2640 current_event_field.GetSignatureForError ());
2643 variable_initializer
2649 event_accessor_declarations
2650 : add_accessor_declaration remove_accessor_declaration
2651 | remove_accessor_declaration add_accessor_declaration
2652 | add_accessor_declaration
2654 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2655 current_event.GetSignatureForError ());
2657 | remove_accessor_declaration
2659 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2660 current_event.GetSignatureForError ());
2664 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2669 add_accessor_declaration
2670 : opt_attributes opt_modifiers ADD
2672 if ($2 != ModifierNone) {
2673 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2676 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2677 current_local_parameters = current_event.Add.ParameterInfo;
2679 lbag.AddMember (current_event.Add, mod_locations);
2680 lexer.EventParsing = false;
2682 event_accessor_block
2684 lexer.EventParsing = true;
2686 current_event.Add.Block = (ToplevelBlock) $5;
2688 if (current_container.Kind == MemberKind.Interface) {
2689 report.Error (531, current_event.Add.Block.StartLocation,
2690 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2693 current_local_parameters = null;
2697 remove_accessor_declaration
2698 : opt_attributes opt_modifiers REMOVE
2700 if ($2 != ModifierNone) {
2701 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2704 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2705 current_local_parameters = current_event.Remove.ParameterInfo;
2707 lbag.AddMember (current_event.Remove, mod_locations);
2708 lexer.EventParsing = false;
2710 event_accessor_block
2712 lexer.EventParsing = true;
2714 current_event.Remove.Block = (ToplevelBlock) $5;
2716 if (current_container.Kind == MemberKind.Interface) {
2717 report.Error (531, current_event.Remove.Block.StartLocation,
2718 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2721 current_local_parameters = null;
2725 event_accessor_block
2728 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2734 attributes_without_members
2735 : attribute_sections CLOSE_BRACE
2737 current_type.UnattachedAttributes = (Attributes) $1;
2738 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2739 lexer.putback ('}');
2743 // For full ast try to recover incomplete ambiguous member
2744 // declaration in form on class X { public int }
2746 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2748 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2750 lexer.putback ('}');
2752 lexer.parsing_generic_declaration = false;
2753 FullNamedExpression type = (FullNamedExpression) $3;
2754 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2755 current_type.AddField (current_field);
2763 ENUM type_declaration_name
2767 enumTypeComment = Lexer.consume_doc_comment ();
2772 Lexer.doc_state = XmlCommentState.Allowed;
2774 MemberName name = (MemberName) $4;
2775 if (name.IsGeneric) {
2776 report.Error (1675, name.Location, "Enums cannot have type parameters");
2779 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2781 opt_enum_member_declarations
2783 lexer.parsing_modifiers = true;
2785 // here will be evaluated after CLOSE_BLACE is consumed.
2787 Lexer.doc_state = XmlCommentState.Allowed;
2789 CLOSE_BRACE opt_semicolon
2792 current_container.DocComment = enumTypeComment;
2794 --lexer.parsing_declaration;
2797 // em.DocComment = ev.DocComment;
2799 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2800 $$ = pop_current_class ();
2812 Error_TypeExpected (GetLocation ($1));
2817 opt_enum_member_declarations
2819 | enum_member_declarations
2820 | enum_member_declarations COMMA
2822 lbag.AddLocation ($1, GetLocation ($2));
2826 enum_member_declarations
2827 : enum_member_declaration
2828 | enum_member_declarations COMMA enum_member_declaration
2830 lbag.AddLocation ($1, GetLocation ($2));
2835 enum_member_declaration
2836 : opt_attributes IDENTIFIER
2838 var lt = (LocatedToken) $2;
2839 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2840 ((Enum) current_type).AddEnumMember (em);
2843 em.DocComment = Lexer.consume_doc_comment ();
2844 Lexer.doc_state = XmlCommentState.Allowed;
2849 | opt_attributes IDENTIFIER
2851 ++lexer.parsing_block;
2853 tmpComment = Lexer.consume_doc_comment ();
2854 Lexer.doc_state = XmlCommentState.NotAllowed;
2857 ASSIGN constant_expression
2859 --lexer.parsing_block;
2861 var lt = (LocatedToken) $2;
2862 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2863 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2864 ((Enum) current_type).AddEnumMember (em);
2867 em.DocComment = ConsumeStoredComment ();
2871 | opt_attributes IDENTIFIER error
2873 Error_SyntaxError (yyToken);
2875 var lt = (LocatedToken) $2;
2876 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2877 ((Enum) current_type).AddEnumMember (em);
2880 em.DocComment = Lexer.consume_doc_comment ();
2881 Lexer.doc_state = XmlCommentState.Allowed;
2886 | attributes_without_members
2889 delegate_declaration
2893 member_type type_declaration_name
2896 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2898 opt_formal_parameter_list CLOSE_PARENS
2900 valid_param_mod = 0;
2902 ParametersCompiled p = (ParametersCompiled) $8;
2904 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2906 p.CheckParameters (del);
2908 current_container.AddTypeContainer (del);
2910 current_delegate = del;
2911 lexer.ConstraintsParsing = true;
2913 opt_type_parameter_constraints_clauses
2915 lexer.ConstraintsParsing = false;
2920 current_delegate.DocComment = Lexer.consume_doc_comment ();
2921 Lexer.doc_state = XmlCommentState.Allowed;
2925 current_delegate.SetConstraints ((List<Constraints>) $11);
2926 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2928 $$ = current_delegate;
2930 current_delegate = null;
2938 if (lang_version < LanguageVersion.ISO_2)
2939 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2941 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2945 namespace_or_type_expr
2947 | qualified_alias_member IDENTIFIER opt_type_argument_list
2949 var lt1 = (LocatedToken) $1;
2950 var lt2 = (LocatedToken) $2;
2952 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2953 lbag.AddLocation ($$, GetLocation ($2));
2955 | qualified_alias_member IDENTIFIER generic_dimension
2957 var lt1 = (LocatedToken) $1;
2958 var lt2 = (LocatedToken) $2;
2960 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
2961 lbag.AddLocation ($$, GetLocation ($2));
2967 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2969 var lt = (LocatedToken) $3;
2970 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2971 lbag.AddLocation ($$, GetLocation ($2));
2973 | namespace_or_type_expr DOT IDENTIFIER generic_dimension
2975 var lt = (LocatedToken) $3;
2976 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
2977 lbag.AddLocation ($$, GetLocation ($2));
2982 : IDENTIFIER opt_type_argument_list
2984 var lt = (LocatedToken) $1;
2985 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2987 | IDENTIFIER generic_dimension
2989 var lt = (LocatedToken) $1;
2990 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
2995 // Generics arguments (any type, without attributes)
2997 opt_type_argument_list
2999 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
3001 if (lang_version < LanguageVersion.ISO_2)
3002 FeatureIsNotAvailable (GetLocation ($1), "generics");
3006 | OP_GENERICS_LT error
3008 Error_TypeExpected (lexer.Location);
3009 $$ = new TypeArguments ();
3016 TypeArguments type_args = new TypeArguments ();
3017 type_args.Add ((FullNamedExpression) $1);
3020 | type_arguments COMMA type
3022 TypeArguments type_args = (TypeArguments) $1;
3023 type_args.Add ((FullNamedExpression) $3);
3029 // Generics parameters (identifiers only, with attributes), used in type or method declarations
3031 type_declaration_name
3034 lexer.parsing_generic_declaration = true;
3036 opt_type_parameter_list
3038 lexer.parsing_generic_declaration = false;
3039 var lt = (LocatedToken) $1;
3040 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
3044 member_declaration_name
3045 : method_declaration_name
3047 MemberName mn = (MemberName)$1;
3048 if (mn.TypeParameters != null)
3049 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
3050 mn.GetSignatureForError ()));
3054 method_declaration_name
3055 : type_declaration_name
3056 | explicit_interface IDENTIFIER opt_type_parameter_list
3058 lexer.parsing_generic_declaration = false;
3059 var lt = (LocatedToken) $2;
3060 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
3064 indexer_declaration_name
3067 lexer.parsing_generic_declaration = false;
3068 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
3070 | explicit_interface THIS
3072 lexer.parsing_generic_declaration = false;
3073 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
3078 : IDENTIFIER opt_type_argument_list DOT
3080 var lt = (LocatedToken) $1;
3081 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3082 lbag.AddLocation ($$, GetLocation ($3));
3084 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3086 var lt1 = (LocatedToken) $1;
3087 var lt2 = (LocatedToken) $2;
3089 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3090 lbag.AddLocation ($$, GetLocation ($4));
3092 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3094 var lt = (LocatedToken) $2;
3095 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3096 lbag.AddLocation ($$, GetLocation ($4));
3100 opt_type_parameter_list
3102 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3104 if (lang_version < LanguageVersion.ISO_2)
3105 FeatureIsNotAvailable (GetLocation ($1), "generics");
3108 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3115 var tparams = new TypeParameters ();
3116 tparams.Add ((TypeParameter)$1);
3119 | type_parameters COMMA type_parameter
3121 var tparams = (TypeParameters) $1;
3122 tparams.Add ((TypeParameter)$3);
3124 lbag.AddLocation ($3, GetLocation ($3));
3129 : opt_attributes opt_type_parameter_variance IDENTIFIER
3131 var lt = (LocatedToken)$3;
3132 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3136 if (GetTokenName (yyToken) == "type")
3137 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3139 Error_SyntaxError (yyToken);
3141 $$ = new TypeParameter (MemberName.Null, null, null);
3146 // All types where void is allowed
3149 : type_expression_or_array
3152 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3159 lexer.parsing_generic_declaration = true;
3164 // A type which does not allow `void' to be used
3167 : type_expression_or_array
3177 : type_expression_or_array
3180 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3181 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3185 type_expression_or_array
3187 | type_expression rank_specifiers
3189 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3194 : namespace_or_type_expr opt_nullable
3197 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3199 var sn = $1 as SimpleName;
3200 if (sn != null && sn.Name == "var")
3201 $$ = new VarExpr (sn.Location);
3206 | namespace_or_type_expr pointer_stars
3208 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3210 | builtin_type_expression
3216 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3217 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3221 builtin_type_expression
3222 : builtin_types opt_nullable
3225 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3227 | builtin_types pointer_stars
3229 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3231 | VOID pointer_stars
3233 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3240 var types = new List<FullNamedExpression> (2);
3241 types.Add ((FullNamedExpression) $1);
3244 | type_list COMMA base_type_name
3246 var types = (List<FullNamedExpression>) $1;
3247 types.Add ((FullNamedExpression) $3);
3255 if ($1 is ComposedCast) {
3256 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3263 * replaces all the productions for isolating the various
3264 * simple types, but we need this to reuse it easily in variable_type
3267 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3268 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3269 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3270 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3271 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3272 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3277 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3278 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3279 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3280 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3281 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3282 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3283 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3284 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3285 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3289 // Expressions, section 7.5
3294 : type_name_expression
3296 | array_creation_expression
3297 | parenthesized_expression
3298 | default_value_expression
3299 | invocation_expression
3303 | post_increment_expression
3304 | post_decrement_expression
3305 | object_or_delegate_creation_expression
3306 | anonymous_type_expression
3309 | checked_expression
3310 | unchecked_expression
3311 | pointer_member_access
3312 | anonymous_method_expression
3313 | undocumented_expressions
3314 | interpolated_string
3317 type_name_expression
3319 | IDENTIFIER GENERATE_COMPLETION {
3320 var lt = (LocatedToken) $1;
3321 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3329 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3333 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3334 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3338 : INTERPOLATED_STRING interpolations INTERPOLATED_STRING_END
3340 $$ = new InterpolatedString ((StringLiteral) $1, (List<Expression>) $2, (StringLiteral) $3);
3342 | INTERPOLATED_STRING_END
3344 $$ = new InterpolatedString ((StringLiteral) $1, null, null);
3351 var list = new List<Expression> ();
3352 list.Add ((InterpolatedStringInsert) $1);
3355 | interpolations INTERPOLATED_STRING interpolation
3357 var list = (List<Expression>) $1;
3358 list.Add ((StringLiteral) $2);
3359 list.Add ((InterpolatedStringInsert) $3);
3367 $$ = new InterpolatedStringInsert ((Expression) $1);
3369 | expression COMMA expression
3371 $$ = new InterpolatedStringInsert ((Expression) $1) {
3372 Alignment = (Expression)$3
3377 lexer.parsing_interpolation_format = true;
3381 lexer.parsing_interpolation_format = false;
3383 $$ = new InterpolatedStringInsert ((Expression) $1) {
3387 | expression COMMA expression COLON
3389 lexer.parsing_interpolation_format = true;
3393 lexer.parsing_interpolation_format = false;
3395 $$ = new InterpolatedStringInsert ((Expression) $1) {
3396 Alignment = (Expression)$3,
3397 Format = (string) $6
3404 // Here is the trick, tokenizer may think that parens is a special but
3405 // parser is interested in open parens only, so we merge them.
3406 // Consider: if (a)foo ();
3414 // Use this production to accept closing parenthesis or
3415 // performing completion
3419 | COMPLETE_COMPLETION
3423 parenthesized_expression
3424 : OPEN_PARENS expression CLOSE_PARENS
3426 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3427 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3429 | OPEN_PARENS expression COMPLETE_COMPLETION
3431 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3436 : primary_expression DOT identifier_inside_body opt_type_argument_list
3438 var lt = (LocatedToken) $3;
3439 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3440 lbag.AddLocation ($$, GetLocation ($2));
3442 | primary_expression DOT identifier_inside_body generic_dimension
3444 var lt = (LocatedToken) $3;
3445 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3446 lbag.AddLocation ($$, GetLocation ($2));
3448 | primary_expression INTERR_OPERATOR DOT identifier_inside_body opt_type_argument_list
3450 if (lang_version < LanguageVersion.V_6)
3451 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3453 var lt = (LocatedToken) $4;
3454 $$ = new ConditionalMemberAccess ((Expression) $1, lt.Value, (TypeArguments) $5, lt.Location);
3455 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3457 | builtin_types DOT identifier_inside_body opt_type_argument_list
3459 var lt = (LocatedToken) $3;
3460 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3461 lbag.AddLocation ($$, GetLocation ($2));
3463 | BASE DOT identifier_inside_body opt_type_argument_list
3465 var lt = (LocatedToken) $3;
3466 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3467 lbag.AddLocation ($$, GetLocation ($2));
3469 | AWAIT DOT identifier_inside_body opt_type_argument_list
3471 var lt = (LocatedToken) $3;
3472 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3473 lbag.AddLocation ($$, GetLocation ($2));
3475 | qualified_alias_member identifier_inside_body opt_type_argument_list
3477 var lt1 = (LocatedToken) $1;
3478 var lt2 = (LocatedToken) $2;
3480 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3481 lbag.AddLocation ($$, GetLocation ($2));
3483 | qualified_alias_member identifier_inside_body generic_dimension
3485 var lt1 = (LocatedToken) $1;
3486 var lt2 = (LocatedToken) $2;
3488 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3489 lbag.AddLocation ($$, GetLocation ($2));
3491 | primary_expression DOT GENERATE_COMPLETION {
3492 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3494 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3495 var lt = (LocatedToken) $3;
3496 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3498 | builtin_types DOT GENERATE_COMPLETION
3500 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3502 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3503 var lt = (LocatedToken) $3;
3504 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3508 invocation_expression
3509 : primary_expression open_parens_any opt_argument_list close_parens
3511 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3512 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3514 | primary_expression open_parens_any argument_list error
3516 Error_SyntaxError (yyToken);
3518 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3519 lbag.AddLocation ($$, GetLocation ($2));
3521 | primary_expression open_parens_any error
3523 Error_SyntaxError (yyToken);
3525 $$ = new Invocation ((Expression) $1, null);
3526 lbag.AddLocation ($$, GetLocation ($2));
3530 opt_object_or_collection_initializer
3531 : /* empty */ { $$ = null; }
3532 | object_or_collection_initializer
3535 object_or_collection_initializer
3536 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3539 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3541 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3543 lbag.AddLocation ($$, GetLocation ($3));
3545 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3547 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3548 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3552 opt_member_initializer_list
3553 : /* empty */ { $$ = null; }
3554 | member_initializer_list
3560 member_initializer_list
3561 : member_initializer
3563 var a = new List<Expression> ();
3564 a.Add ((Expression) $1);
3567 | member_initializer_list COMMA member_initializer
3569 var a = (List<Expression>)$1;
3570 a.Add ((Expression) $3);
3573 | member_initializer_list error {
3574 Error_SyntaxError (yyToken);
3580 : IDENTIFIER ASSIGN initializer_value
3582 var lt = (LocatedToken) $1;
3583 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3584 lbag.AddLocation ($$, GetLocation ($2));
3586 | AWAIT ASSIGN initializer_value
3588 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3589 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3590 lbag.AddLocation ($$, GetLocation ($2));
3592 | GENERATE_COMPLETION
3594 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3596 | non_assignment_expression opt_COMPLETE_COMPLETION {
3597 CompletionSimpleName csn = $1 as CompletionSimpleName;
3599 $$ = new CollectionElementInitializer ((Expression)$1);
3601 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3603 | OPEN_BRACE expression_list CLOSE_BRACE
3606 $$ = new CollectionElementInitializer (GetLocation ($1));
3608 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3610 lbag.AddLocation ($$, GetLocation ($3));
3612 | OPEN_BRACKET_EXPR argument_list CLOSE_BRACKET ASSIGN initializer_value
3614 if (lang_version < LanguageVersion.V_6)
3615 FeatureIsNotAvailable (GetLocation ($1), "dictionary initializer");
3617 $$ = new DictionaryElementInitializer ((Arguments)$2, (Expression) $5, GetLocation ($1));
3618 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3620 | OPEN_BRACE CLOSE_BRACE
3622 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3623 $$ = new CollectionElementInitializer (GetLocation ($1));
3624 lbag.AddLocation ($$, GetLocation ($2));
3630 | object_or_collection_initializer
3634 : /* empty */ { $$ = null; }
3639 : argument_or_named_argument
3641 Arguments list = new Arguments (4);
3642 list.Add ((Argument) $1);
3645 | argument_list COMMA argument
3647 Arguments list = (Arguments) $1;
3648 if (list [list.Count - 1] is NamedArgument)
3649 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3651 list.Add ((Argument) $3);
3654 | argument_list COMMA named_argument
3656 Arguments list = (Arguments) $1;
3657 NamedArgument a = (NamedArgument) $3;
3658 for (int i = 0; i < list.Count; ++i) {
3659 NamedArgument na = list [i] as NamedArgument;
3660 if (na != null && na.Name == a.Name)
3661 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3668 | argument_list COMMA error
3670 if (lexer.putback_char == -1)
3671 lexer.putback (')'); // TODO: Wrong but what can I do
3672 Error_SyntaxError (yyToken);
3677 report.Error (839, GetLocation ($1), "An argument is missing");
3685 $$ = new Argument ((Expression) $1);
3687 | non_simple_argument
3690 argument_or_named_argument
3696 : REF variable_reference
3698 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3699 lbag.AddLocation ($$, GetLocation ($1));
3701 | REF declaration_expression
3703 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3705 | OUT variable_reference
3707 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3708 lbag.AddLocation ($$, GetLocation ($1));
3710 | OUT declaration_expression
3712 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3714 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3716 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3717 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3719 | ARGLIST OPEN_PARENS CLOSE_PARENS
3721 $$ = new Argument (new Arglist (GetLocation ($1)));
3722 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3726 declaration_expression
3727 : OPEN_PARENS declaration_expression CLOSE_PARENS
3729 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3730 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3733 | CHECKED open_parens_any declaration_expression CLOSE_PARENS
3735 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3736 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3738 | UNCHECKED open_parens_any declaration_expression CLOSE_PARENS
3740 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3741 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3744 | variable_type identifier_inside_body
3746 if (lang_version != LanguageVersion.Experimental)
3747 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3749 var lt = (LocatedToken) $2;
3750 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3751 current_block.AddLocalName (lv);
3752 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv);
3754 | variable_type identifier_inside_body ASSIGN expression
3756 if (lang_version != LanguageVersion.Experimental)
3757 FeatureIsNotAvailable (GetLocation ($1), "declaration expression");
3759 var lt = (LocatedToken) $2;
3760 var lv = new LocalVariable (current_block, lt.Value, lt.Location);
3761 current_block.AddLocalName (lv);
3762 $$ = new DeclarationExpression ((FullNamedExpression) $1, lv) {
3763 Initializer = (Expression) $4
3773 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3775 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3776 lbag.AddLocation ($$, GetLocation ($4));
3778 | primary_expression INTERR_OPERATOR OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3780 if (lang_version < LanguageVersion.V_6)
3781 FeatureIsNotAvailable (GetLocation ($2), "null propagating operator");
3783 $$ = new ElementAccess ((Expression) $1, (Arguments) $4, GetLocation ($3)) {
3784 ConditionalAccess = true
3787 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5));
3789 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3791 Error_SyntaxError (yyToken);
3792 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3794 | primary_expression OPEN_BRACKET_EXPR error
3796 Error_SyntaxError (yyToken);
3797 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3802 : expression_or_error
3804 var list = new List<Expression> (4);
3805 list.Add ((Expression) $1);
3808 | expression_list COMMA expression_or_error
3810 var list = (List<Expression>) $1;
3811 list.Add ((Expression) $3);
3816 expression_list_arguments
3817 : expression_list_argument
3819 Arguments args = new Arguments (4);
3820 args.Add ((Argument) $1);
3823 | expression_list_arguments COMMA expression_list_argument
3825 Arguments args = (Arguments) $1;
3826 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3827 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3829 args.Add ((Argument) $3);
3834 expression_list_argument
3837 $$ = new Argument ((Expression) $1);
3845 $$ = new This (GetLocation ($1));
3850 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3852 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3853 lbag.AddLocation ($$, GetLocation ($4));
3855 | BASE OPEN_BRACKET error
3857 Error_SyntaxError (yyToken);
3858 $$ = new ElementAccess (null, null, GetLocation ($2));
3862 post_increment_expression
3863 : primary_expression OP_INC
3865 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3869 post_decrement_expression
3870 : primary_expression OP_DEC
3872 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3876 object_or_delegate_creation_expression
3877 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3880 if (lang_version <= LanguageVersion.ISO_2)
3881 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3883 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3885 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3888 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3890 | NEW new_expr_type object_or_collection_initializer
3892 if (lang_version <= LanguageVersion.ISO_2)
3893 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3895 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3899 array_creation_expression
3900 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3902 opt_array_initializer
3904 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3905 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3906 Next = (ComposedTypeSpecifier) $6
3907 }, (ArrayInitializer) $7, GetLocation ($1));
3908 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3910 | NEW new_expr_type rank_specifiers opt_array_initializer
3913 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3915 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3917 | NEW rank_specifier array_initializer
3919 if (lang_version <= LanguageVersion.ISO_2)
3920 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3922 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3924 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3926 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3927 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3929 | NEW new_expr_type error
3931 Error_SyntaxError (yyToken);
3932 // It can be any of new expression, create the most common one
3933 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3939 ++lexer.parsing_type;
3943 --lexer.parsing_type;
3948 anonymous_type_expression
3949 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3951 if (lang_version <= LanguageVersion.ISO_2)
3952 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3954 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3956 // TODO: lbag comma location
3957 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3959 | NEW OPEN_BRACE GENERATE_COMPLETION
3961 $$ = new EmptyCompletion ();
3965 anonymous_type_parameters_opt_comma
3966 : anonymous_type_parameters_opt
3967 | anonymous_type_parameters COMMA
3970 anonymous_type_parameters_opt
3972 | anonymous_type_parameters
3975 anonymous_type_parameters
3976 : anonymous_type_parameter
3978 var a = new List<AnonymousTypeParameter> (4);
3979 a.Add ((AnonymousTypeParameter) $1);
3982 | anonymous_type_parameters COMMA anonymous_type_parameter
3984 var a = (List<AnonymousTypeParameter>) $1;
3985 a.Add ((AnonymousTypeParameter) $3);
3988 | COMPLETE_COMPLETION
3990 $$ = new EmptyCompletion ();
3992 | anonymous_type_parameter COMPLETE_COMPLETION
3998 anonymous_type_parameter
3999 : identifier_inside_body ASSIGN variable_initializer
4001 var lt = (LocatedToken)$1;
4002 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
4003 lbag.AddLocation ($$, GetLocation ($2));
4005 | identifier_inside_body
4007 var lt = (LocatedToken)$1;
4008 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
4009 lt.Value, lt.Location);
4013 MemberAccess ma = (MemberAccess) $1;
4014 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
4018 report.Error (746, lexer.Location,
4019 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
4031 | rank_specifier rank_specifiers
4033 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4039 : OPEN_BRACKET CLOSE_BRACKET
4041 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
4042 lbag.AddLocation ($$, GetLocation ($2));
4044 | OPEN_BRACKET dim_separators CLOSE_BRACKET
4046 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
4047 lbag.AddLocation ($$, GetLocation ($3));
4056 | dim_separators COMMA
4058 $$ = ((int) $1) + 1;
4062 opt_array_initializer
4074 : OPEN_BRACE CLOSE_BRACE
4076 var ai = new ArrayInitializer (0, GetLocation ($1));
4077 ai.VariableDeclaration = current_variable;
4078 lbag.AddLocation (ai, GetLocation ($2));
4081 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
4083 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
4084 ai.VariableDeclaration = current_variable;
4086 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
4088 lbag.AddLocation (ai, GetLocation ($4));
4094 variable_initializer_list
4095 : variable_initializer
4097 var list = new List<Expression> (4);
4098 list.Add ((Expression) $1);
4101 | variable_initializer_list COMMA variable_initializer
4103 var list = (List<Expression>) $1;
4104 list.Add ((Expression) $3);
4110 : TYPEOF open_parens_any typeof_type_expression CLOSE_PARENS
4112 $$ = new TypeOf ((FullNamedExpression) $3, GetLocation ($1));
4113 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4117 typeof_type_expression
4121 Error_TypeExpected (lexer.Location);
4129 if (lang_version < LanguageVersion.ISO_2)
4130 FeatureIsNotAvailable (GetLocation ($1), "generics");
4136 qualified_alias_member
4137 : IDENTIFIER DOUBLE_COLON
4139 var lt = (LocatedToken) $1;
4140 if (lang_version == LanguageVersion.ISO_1)
4141 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
4148 : SIZEOF open_parens_any type CLOSE_PARENS
4150 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4151 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4153 | SIZEOF open_parens_any type error
4155 Error_SyntaxError (yyToken);
4157 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
4158 lbag.AddLocation ($$, GetLocation ($2));
4163 : CHECKED open_parens_any expression CLOSE_PARENS
4165 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
4166 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4170 Error_SyntaxError (yyToken);
4172 $$ = new CheckedExpr (null, GetLocation ($1));
4176 unchecked_expression
4177 : UNCHECKED open_parens_any expression CLOSE_PARENS
4179 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
4180 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4184 Error_SyntaxError (yyToken);
4186 $$ = new UnCheckedExpr (null, GetLocation ($1));
4190 pointer_member_access
4191 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
4193 var lt = (LocatedToken) $3;
4194 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4198 anonymous_method_expression
4199 : DELEGATE opt_anonymous_method_signature
4201 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4205 $$ = end_anonymous ((ParametersBlock) $4);
4207 | ASYNC DELEGATE opt_anonymous_method_signature
4209 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4213 $$ = end_anonymous ((ParametersBlock) $5);
4217 opt_anonymous_method_signature
4220 $$ = ParametersCompiled.Undefined;
4222 | anonymous_method_signature
4225 anonymous_method_signature
4228 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4230 opt_formal_parameter_list CLOSE_PARENS
4232 valid_param_mod = 0;
4237 default_value_expression
4238 : DEFAULT open_parens_any type CLOSE_PARENS
4240 if (lang_version < LanguageVersion.ISO_2)
4241 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4243 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4244 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4249 : primary_expression
4250 | BANG prefixed_unary_expression
4252 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4254 | TILDE prefixed_unary_expression
4256 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4258 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4260 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4261 lbag.AddLocation ($$, GetLocation ($3));
4263 | AWAIT prefixed_unary_expression
4266 if (current_anonymous_method is LambdaExpression) {
4267 report.Error (4034, GetLocation ($1),
4268 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4269 } else if (current_anonymous_method != null) {
4270 report.Error (4035, GetLocation ($1),
4271 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4272 } else if (interactive_async != null) {
4273 current_block.Explicit.RegisterAsyncAwait ();
4274 interactive_async = true;
4276 report.Error (4033, GetLocation ($1),
4277 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4280 current_block.Explicit.RegisterAsyncAwait ();
4283 $$ = new Await ((Expression) $2, GetLocation ($1));
4287 Error_SyntaxError (yyToken);
4289 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4293 Error_SyntaxError (yyToken);
4295 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4297 | OPEN_PARENS_CAST type CLOSE_PARENS error
4299 Error_SyntaxError (yyToken);
4301 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4302 lbag.AddLocation ($$, GetLocation ($3));
4306 Error_SyntaxError (yyToken);
4308 $$ = new Await (null, GetLocation ($1));
4313 // The idea to split this out is from Rhys' grammar
4314 // to solve the problem with casts.
4316 prefixed_unary_expression
4318 | PLUS prefixed_unary_expression
4320 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4322 | MINUS prefixed_unary_expression
4324 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4326 | OP_INC prefixed_unary_expression
4328 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4330 | OP_DEC prefixed_unary_expression
4332 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4334 | STAR prefixed_unary_expression
4336 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4338 | BITWISE_AND prefixed_unary_expression
4340 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4344 Error_SyntaxError (yyToken);
4346 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4350 Error_SyntaxError (yyToken);
4352 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4356 Error_SyntaxError (yyToken);
4358 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4362 Error_SyntaxError (yyToken);
4364 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4368 Error_SyntaxError (yyToken);
4370 $$ = new Indirection (null, GetLocation ($1));
4374 Error_SyntaxError (yyToken);
4376 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4380 multiplicative_expression
4381 : prefixed_unary_expression
4382 | multiplicative_expression STAR prefixed_unary_expression
4384 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4385 lbag.AddLocation ($$, GetLocation ($2));
4387 | multiplicative_expression DIV prefixed_unary_expression
4389 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4390 lbag.AddLocation ($$, GetLocation ($2));
4392 | multiplicative_expression PERCENT prefixed_unary_expression
4394 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4395 lbag.AddLocation ($$, GetLocation ($2));
4397 | multiplicative_expression STAR error
4399 Error_SyntaxError (yyToken);
4401 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4402 lbag.AddLocation ($$, GetLocation ($2));
4404 | multiplicative_expression DIV error
4406 Error_SyntaxError (yyToken);
4408 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4409 lbag.AddLocation ($$, GetLocation ($2));
4411 | multiplicative_expression PERCENT error
4413 Error_SyntaxError (yyToken);
4415 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4416 lbag.AddLocation ($$, GetLocation ($2));
4421 : multiplicative_expression
4422 | additive_expression PLUS multiplicative_expression
4424 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4425 lbag.AddLocation ($$, GetLocation ($2));
4427 | additive_expression MINUS multiplicative_expression
4429 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4430 lbag.AddLocation ($$, GetLocation ($2));
4432 | additive_expression PLUS error
4434 Error_SyntaxError (yyToken);
4436 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4437 lbag.AddLocation ($$, GetLocation ($2));
4439 | additive_expression MINUS error
4441 Error_SyntaxError (yyToken);
4443 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4444 lbag.AddLocation ($$, GetLocation ($2));
4446 | additive_expression AS type
4448 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4450 | additive_expression IS pattern_type_expr opt_identifier
4452 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4454 if (lang_version != LanguageVersion.Experimental)
4455 FeatureIsNotAvailable (GetLocation ($4), "type pattern matching");
4457 var lt = (LocatedToken) $4;
4458 is_expr.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
4459 current_block.AddLocalName (is_expr.Variable);
4464 | additive_expression IS pattern_expr
4466 var is_expr = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4467 if (lang_version != LanguageVersion.Experimental)
4468 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
4472 | additive_expression AS error
4474 Error_SyntaxError (yyToken);
4476 $$ = new As ((Expression) $1, null, GetLocation ($2));
4478 | additive_expression IS error
4480 Error_SyntaxError (yyToken);
4482 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4486 var lt = (LocatedToken) $1;
4487 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4491 var lt = (LocatedToken) $1;
4492 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4502 | PLUS prefixed_unary_expression
4504 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4506 | MINUS prefixed_unary_expression
4508 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4511 | default_value_expression
4512 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4514 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4515 lbag.AddLocation ($$, GetLocation ($3));
4519 $$ = new WildcardPattern (GetLocation ($1));
4521 | pattern_expr_invocation
4525 pattern_expr_invocation
4526 : type_name_expression OPEN_PARENS opt_pattern_list CLOSE_PARENS
4528 $$ = new RecursivePattern ((ATypeNameExpression) $1, (Arguments) $3, GetLocation ($2));
4533 : type_name_expression OPEN_BRACE pattern_property_list CLOSE_BRACE
4535 $$ = new PropertyPattern ((ATypeNameExpression) $1, (List<PropertyPatternMember>) $3, GetLocation ($2));
4539 pattern_property_list
4540 : pattern_property_entry
4542 var list = new List<PropertyPatternMember> ();
4543 list.Add ((PropertyPatternMember) $1);
4546 | pattern_property_list COMMA pattern_property_entry
4548 var list = (List<PropertyPatternMember>) $1;
4549 list.Add ((PropertyPatternMember) $3);
4554 pattern_property_entry
4555 : identifier_inside_body IS pattern
4557 var lt = (LocatedToken) $1;
4558 $$ = new PropertyPatternMember (lt.Value, (Expression) $3, lt.Location);
4564 | pattern_type_expr opt_identifier
4567 var lt = (LocatedToken) $2;
4568 var variable = new LocalVariable (current_block, lt.Value, lt.Location);
4569 current_block.AddLocalName (variable);
4577 $$ = new Arguments (0);
4585 Arguments args = new Arguments (4);
4586 args.Add ((Argument) $1);
4589 | pattern_list COMMA pattern_argument
4591 Arguments args = (Arguments) $1;
4592 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
4593 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
4595 args.Add ((Argument) $3);
4603 $$ = new Argument ((Expression) $1);
4605 | IDENTIFIER COLON pattern
4607 var lt = (LocatedToken) $1;
4608 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3);
4613 : additive_expression
4614 | shift_expression OP_SHIFT_LEFT additive_expression
4616 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4617 lbag.AddLocation ($$, GetLocation ($2));
4619 | shift_expression OP_SHIFT_RIGHT additive_expression
4621 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4622 lbag.AddLocation ($$, GetLocation ($2));
4624 | shift_expression OP_SHIFT_LEFT error
4626 Error_SyntaxError (yyToken);
4628 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4629 lbag.AddLocation ($$, GetLocation ($2));
4631 | shift_expression OP_SHIFT_RIGHT error
4633 Error_SyntaxError (yyToken);
4635 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4636 lbag.AddLocation ($$, GetLocation ($2));
4640 relational_expression
4642 | relational_expression OP_LT shift_expression
4644 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4645 lbag.AddLocation ($$, GetLocation ($2));
4647 | relational_expression OP_GT shift_expression
4649 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4650 lbag.AddLocation ($$, GetLocation ($2));
4652 | relational_expression OP_LE shift_expression
4654 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4655 lbag.AddLocation ($$, GetLocation ($2));
4657 | relational_expression OP_GE shift_expression
4659 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4660 lbag.AddLocation ($$, GetLocation ($2));
4662 | relational_expression OP_LT error
4664 Error_SyntaxError (yyToken);
4666 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4667 lbag.AddLocation ($$, GetLocation ($2));
4669 | relational_expression OP_GT error
4671 Error_SyntaxError (yyToken);
4673 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4674 lbag.AddLocation ($$, GetLocation ($2));
4676 | relational_expression OP_LE error
4678 Error_SyntaxError (yyToken);
4680 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4681 lbag.AddLocation ($$, GetLocation ($2));
4683 | relational_expression OP_GE error
4685 Error_SyntaxError (yyToken);
4687 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4688 lbag.AddLocation ($$, GetLocation ($2));
4693 : relational_expression
4694 | equality_expression OP_EQ relational_expression
4696 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4697 lbag.AddLocation ($$, GetLocation ($2));
4699 | equality_expression OP_NE relational_expression
4701 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4702 lbag.AddLocation ($$, GetLocation ($2));
4704 | equality_expression OP_EQ error
4706 Error_SyntaxError (yyToken);
4708 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4709 lbag.AddLocation ($$, GetLocation ($2));
4711 | equality_expression OP_NE error
4713 Error_SyntaxError (yyToken);
4715 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4716 lbag.AddLocation ($$, GetLocation ($2));
4721 : equality_expression
4722 | and_expression BITWISE_AND equality_expression
4724 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4725 lbag.AddLocation ($$, GetLocation ($2));
4727 | and_expression BITWISE_AND error
4729 Error_SyntaxError (yyToken);
4731 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4732 lbag.AddLocation ($$, GetLocation ($2));
4736 exclusive_or_expression
4738 | exclusive_or_expression CARRET and_expression
4740 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4741 lbag.AddLocation ($$, GetLocation ($2));
4743 | exclusive_or_expression CARRET error
4745 Error_SyntaxError (yyToken);
4747 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4748 lbag.AddLocation ($$, GetLocation ($2));
4752 inclusive_or_expression
4753 : exclusive_or_expression
4754 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4756 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4757 lbag.AddLocation ($$, GetLocation ($2));
4759 | inclusive_or_expression BITWISE_OR error
4761 Error_SyntaxError (yyToken);
4763 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4764 lbag.AddLocation ($$, GetLocation ($2));
4768 conditional_and_expression
4769 : inclusive_or_expression
4770 | conditional_and_expression OP_AND inclusive_or_expression
4772 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4773 lbag.AddLocation ($$, GetLocation ($2));
4775 | conditional_and_expression OP_AND error
4777 Error_SyntaxError (yyToken);
4779 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4780 lbag.AddLocation ($$, GetLocation ($2));
4784 conditional_or_expression
4785 : conditional_and_expression
4786 | conditional_or_expression OP_OR conditional_and_expression
4788 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4789 lbag.AddLocation ($$, GetLocation ($2));
4791 | conditional_or_expression OP_OR error
4793 Error_SyntaxError (yyToken);
4795 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4796 lbag.AddLocation ($$, GetLocation ($2));
4800 null_coalescing_expression
4801 : conditional_or_expression
4802 | conditional_or_expression OP_COALESCING null_coalescing_expression
4804 if (lang_version < LanguageVersion.ISO_2)
4805 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4807 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4808 lbag.AddLocation ($$, GetLocation ($2));
4812 conditional_expression
4813 : null_coalescing_expression
4814 | null_coalescing_expression INTERR expression COLON expression
4816 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4817 lbag.AddLocation ($$, GetLocation ($4));
4819 | null_coalescing_expression INTERR expression error
4821 Error_SyntaxError (yyToken);
4823 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4825 | null_coalescing_expression INTERR expression COLON error
4827 Error_SyntaxError (yyToken);
4829 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4830 lbag.AddLocation ($$, GetLocation ($4));
4832 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4834 Error_SyntaxError (Token.CLOSE_BRACE);
4836 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4837 lbag.AddLocation ($$, GetLocation ($4));
4838 lexer.putback ('}');
4842 assignment_expression
4843 : prefixed_unary_expression ASSIGN expression
4845 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4846 lbag.AddLocation ($$, GetLocation ($2));
4848 | prefixed_unary_expression OP_MULT_ASSIGN expression
4850 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4851 lbag.AddLocation ($$, GetLocation ($2));
4853 | prefixed_unary_expression OP_DIV_ASSIGN expression
4855 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4856 lbag.AddLocation ($$, GetLocation ($2));
4858 | prefixed_unary_expression OP_MOD_ASSIGN expression
4860 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4861 lbag.AddLocation ($$, GetLocation ($2));
4863 | prefixed_unary_expression OP_ADD_ASSIGN expression
4865 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4866 lbag.AddLocation ($$, GetLocation ($2));
4868 | prefixed_unary_expression OP_SUB_ASSIGN expression
4870 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4871 lbag.AddLocation ($$, GetLocation ($2));
4873 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4875 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4876 lbag.AddLocation ($$, GetLocation ($2));
4878 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4880 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4881 lbag.AddLocation ($$, GetLocation ($2));
4883 | prefixed_unary_expression OP_AND_ASSIGN expression
4885 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4886 lbag.AddLocation ($$, GetLocation ($2));
4888 | prefixed_unary_expression OP_OR_ASSIGN expression
4890 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4891 lbag.AddLocation ($$, GetLocation ($2));
4893 | prefixed_unary_expression OP_XOR_ASSIGN expression
4895 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4896 lbag.AddLocation ($$, GetLocation ($2));
4900 lambda_parameter_list
4903 var pars = new List<Parameter> (4);
4904 pars.Add ((Parameter) $1);
4908 | lambda_parameter_list COMMA lambda_parameter
4910 var pars = (List<Parameter>) $1;
4911 Parameter p = (Parameter)$3;
4912 if (pars[0].GetType () != p.GetType ()) {
4913 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4922 : parameter_modifier parameter_type identifier_inside_body
4924 var lt = (LocatedToken) $3;
4926 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4928 | parameter_type identifier_inside_body
4930 var lt = (LocatedToken) $2;
4932 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4936 var lt = (LocatedToken) $1;
4937 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4941 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4942 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4946 opt_lambda_parameter_list
4947 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4948 | lambda_parameter_list {
4949 var pars_list = (List<Parameter>) $1;
4950 $$ = new ParametersCompiled (pars_list.ToArray ());
4954 lambda_expression_body
4956 start_block (Location.Null);
4958 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4960 Block b = end_block (Location.Null);
4961 b.IsCompilerGenerated = true;
4962 b.AddStatement (new ContextualReturn ((Expression) $2));
4968 // Handles only cases like foo = x.FirstOrDefault (l => );
4969 // where we must restore current_variable
4970 Block b = end_block (Location.Null);
4971 b.IsCompilerGenerated = true;
4973 Error_SyntaxError (yyToken);
4982 Error_SyntaxError (yyToken);
4990 var lt = (LocatedToken) $1;
4991 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4992 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4994 lambda_expression_body
4996 $$ = end_anonymous ((ParametersBlock) $4);
4997 lbag.AddLocation ($$, GetLocation ($2));
5001 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
5002 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5003 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
5005 lambda_expression_body
5007 $$ = end_anonymous ((ParametersBlock) $4);
5008 lbag.AddLocation ($$, GetLocation ($2));
5010 | ASYNC identifier_inside_body ARROW
5012 var lt = (LocatedToken) $2;
5013 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
5014 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
5016 lambda_expression_body
5018 $$ = end_anonymous ((ParametersBlock) $5);
5019 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
5021 | OPEN_PARENS_LAMBDA
5023 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5025 opt_lambda_parameter_list CLOSE_PARENS ARROW
5027 valid_param_mod = 0;
5028 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
5030 lambda_expression_body
5032 $$ = end_anonymous ((ParametersBlock) $7);
5033 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
5035 | ASYNC OPEN_PARENS_LAMBDA
5037 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
5039 opt_lambda_parameter_list CLOSE_PARENS ARROW
5041 valid_param_mod = 0;
5042 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
5044 lambda_expression_body
5046 $$ = end_anonymous ((ParametersBlock) $8);
5047 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
5052 : assignment_expression
5053 | non_assignment_expression
5056 non_assignment_expression
5057 : conditional_expression
5062 $$ = new ArglistAccess (GetLocation ($1));
5066 undocumented_expressions
5067 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
5069 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
5070 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5072 | REFTYPE open_parens_any expression CLOSE_PARENS
5074 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
5075 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5077 | MAKEREF open_parens_any expression CLOSE_PARENS
5079 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
5080 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
5091 $$ = new BooleanExpression ((Expression) $1);
5095 opt_primary_parameters
5100 | primary_parameters
5104 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
5108 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
5109 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
5111 if (lang_version != LanguageVersion.Experimental)
5112 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
5116 opt_primary_parameters_with_class_base
5125 | primary_parameters
5129 | primary_parameters class_base
5133 | primary_parameters class_base OPEN_PARENS
5135 ++lexer.parsing_block;
5136 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
5138 opt_argument_list CLOSE_PARENS
5140 lbag.AppendToMember (current_container, GetLocation ($6));
5141 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
5142 --lexer.parsing_block;
5158 type_declaration_name
5160 lexer.ConstraintsParsing = true;
5162 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
5163 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
5164 FeatureIsNotAvailable (c.Location, "static classes");
5167 push_current_container (c, $3);
5168 valid_param_mod = ParameterModifierType.PrimaryConstructor;
5170 opt_primary_parameters_with_class_base
5171 opt_type_parameter_constraints_clauses
5173 valid_param_mod = 0;
5174 lexer.ConstraintsParsing = false;
5177 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
5180 current_container.SetConstraints ((List<Constraints>) $9);
5181 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
5184 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
5185 Lexer.doc_state = XmlCommentState.Allowed;
5188 lexer.parsing_modifiers = true;
5190 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
5192 --lexer.parsing_declaration;
5194 Lexer.doc_state = XmlCommentState.Allowed;
5199 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
5201 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
5203 $$ = pop_current_class ();
5211 { $$ = $1; } // location
5217 mod_locations = null;
5219 lexer.parsing_modifiers = false;
5223 lexer.parsing_modifiers = false;
5229 | modifiers modifier
5231 var m1 = (Modifiers) $1;
5232 var m2 = (Modifiers) $2;
5234 if ((m1 & m2) != 0) {
5235 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
5236 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
5237 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
5238 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
5239 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
5240 "More than one protection modifier specified");
5251 StoreModifierLocation ($$, GetLocation ($1));
5253 if (current_container.Kind == MemberKind.Namespace)
5254 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
5258 $$ = Modifiers.PUBLIC;
5259 StoreModifierLocation ($$, GetLocation ($1));
5263 $$ = Modifiers.PROTECTED;
5264 StoreModifierLocation ($$, GetLocation ($1));
5268 $$ = Modifiers.INTERNAL;
5269 StoreModifierLocation ($$, GetLocation ($1));
5273 $$ = Modifiers.PRIVATE;
5274 StoreModifierLocation ($$, GetLocation ($1));
5278 $$ = Modifiers.ABSTRACT;
5279 StoreModifierLocation ($$, GetLocation ($1));
5283 $$ = Modifiers.SEALED;
5284 StoreModifierLocation ($$, GetLocation ($1));
5288 $$ = Modifiers.STATIC;
5289 StoreModifierLocation ($$, GetLocation ($1));
5293 $$ = Modifiers.READONLY;
5294 StoreModifierLocation ($$, GetLocation ($1));
5298 $$ = Modifiers.VIRTUAL;
5299 StoreModifierLocation ($$, GetLocation ($1));
5303 $$ = Modifiers.OVERRIDE;
5304 StoreModifierLocation ($$, GetLocation ($1));
5308 $$ = Modifiers.EXTERN;
5309 StoreModifierLocation ($$, GetLocation ($1));
5313 $$ = Modifiers.VOLATILE;
5314 StoreModifierLocation ($$, GetLocation ($1));
5318 $$ = Modifiers.UNSAFE;
5319 StoreModifierLocation ($$, GetLocation ($1));
5320 if (!settings.Unsafe)
5321 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5325 $$ = Modifiers.ASYNC;
5326 StoreModifierLocation ($$, GetLocation ($1));
5338 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5340 | COLON type_list error
5342 Error_SyntaxError (yyToken);
5344 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5348 opt_type_parameter_constraints_clauses
5350 | type_parameter_constraints_clauses
5356 type_parameter_constraints_clauses
5357 : type_parameter_constraints_clause
5359 var constraints = new List<Constraints> (1);
5360 constraints.Add ((Constraints) $1);
5363 | type_parameter_constraints_clauses type_parameter_constraints_clause
5365 var constraints = (List<Constraints>) $1;
5366 Constraints new_constraint = (Constraints)$2;
5368 foreach (Constraints c in constraints) {
5369 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5370 report.Error (409, new_constraint.Location,
5371 "A constraint clause has already been specified for type parameter `{0}'",
5372 new_constraint.TypeParameter.Value);
5376 constraints.Add (new_constraint);
5381 type_parameter_constraints_clause
5382 : WHERE IDENTIFIER COLON type_parameter_constraints
5384 var lt = (LocatedToken) $2;
5385 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5386 lbag.AddLocation ($$, GetLocation ($3));
5388 | WHERE IDENTIFIER error
5390 Error_SyntaxError (yyToken);
5392 var lt = (LocatedToken) $2;
5393 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5397 type_parameter_constraints
5398 : type_parameter_constraint
5400 var constraints = new List<FullNamedExpression> (1);
5401 constraints.Add ((FullNamedExpression) $1);
5404 | type_parameter_constraints COMMA type_parameter_constraint
5406 var constraints = (List<FullNamedExpression>) $1;
5407 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5408 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5409 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5412 prev = $3 as SpecialContraintExpr;
5414 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5415 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5417 prev = constraints [0] as SpecialContraintExpr;
5418 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5419 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5424 constraints.Add ((FullNamedExpression) $3);
5429 type_parameter_constraint
5432 if ($1 is ComposedCast)
5433 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5437 | NEW OPEN_PARENS CLOSE_PARENS
5439 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5440 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5444 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5448 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5452 opt_type_parameter_variance
5457 | type_parameter_variance
5459 if (lang_version <= LanguageVersion.V_3)
5460 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5466 type_parameter_variance
5469 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5473 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5482 // A block is "contained" on the following places:
5484 // property_declaration as part of the accessor body (get/set)
5485 // operator_declaration
5486 // constructor_declaration
5487 // destructor_declaration
5488 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5493 ++lexer.parsing_block;
5494 start_block (GetLocation ($1));
5496 opt_statement_list block_end
5505 --lexer.parsing_block;
5506 $$ = end_block (GetLocation ($1));
5508 | COMPLETE_COMPLETION
5510 --lexer.parsing_block;
5511 $$ = end_block (lexer.Location);
5519 ++lexer.parsing_block;
5520 current_block.StartLocation = GetLocation ($1);
5522 opt_statement_list CLOSE_BRACE
5524 --lexer.parsing_block;
5525 $$ = end_block (GetLocation ($4));
5536 | statement_list statement
5540 : block_variable_declaration
5542 current_block.AddStatement ((Statement) $1);
5544 | valid_declaration_statement
5546 current_block.AddStatement ((Statement) $1);
5551 Error_SyntaxError (yyToken);
5557 // The interactive_statement and its derivatives are only
5558 // used to provide a special version of `expression_statement'
5559 // that has a side effect of assigning the expression to
5562 interactive_statement_list
5563 : interactive_statement
5564 | interactive_statement_list interactive_statement
5567 interactive_statement
5568 : block_variable_declaration
5570 current_block.AddStatement ((Statement) $1);
5572 | interactive_valid_declaration_statement
5574 current_block.AddStatement ((Statement) $1);
5579 valid_declaration_statement
5582 | expression_statement
5583 | selection_statement
5584 | iteration_statement
5588 | unchecked_statement
5595 interactive_valid_declaration_statement
5598 | interactive_expression_statement
5599 | selection_statement
5600 | iteration_statement
5604 | unchecked_statement
5612 : valid_declaration_statement
5613 | block_variable_declaration
5615 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5620 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5625 Error_SyntaxError (yyToken);
5626 $$ = new EmptyStatement (GetLocation ($1));
5633 // Uses lexer.Location because semicolon location is not kept in quick mode
5634 $$ = new EmptyStatement (lexer.Location);
5639 : identifier_inside_body COLON
5641 var lt = (LocatedToken) $1;
5642 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5643 lbag.AddLocation (labeled, GetLocation ($2));
5644 current_block.AddLabel (labeled);
5645 current_block.AddStatement (labeled);
5651 : variable_type_simple
5652 | variable_type_simple rank_specifiers
5655 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5657 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5662 * The following is from Rhys' grammar:
5663 * > Types in local variable declarations must be recognized as
5664 * > expressions to prevent reduce/reduce errors in the grammar.
5665 * > The expressions are converted into types during semantic analysis.
5667 variable_type_simple
5668 : type_name_expression opt_nullable
5670 // Ok, the above "primary_expression" is there to get rid of
5671 // both reduce/reduce and shift/reduces in the grammar, it should
5672 // really just be "type_name". If you use type_name, a reduce/reduce
5673 // creeps up. If you use namespace_or_type_name (which is all we need
5674 // really) two shift/reduces appear.
5677 // So the super-trick is that primary_expression
5678 // can only be either a SimpleName or a MemberAccess.
5679 // The MemberAccess case arises when you have a fully qualified type-name like :
5681 // SimpleName is when you have
5684 var expr = (ATypeNameExpression) $1;
5686 if (expr.Name == "var" && expr is SimpleName)
5687 $$ = new VarExpr (expr.Location);
5691 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5694 | type_name_expression pointer_stars
5696 var expr = (ATypeNameExpression) $1;
5697 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5699 | builtin_type_expression
5705 | pointer_star pointer_stars
5707 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5715 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5719 identifier_inside_body
5723 $$ = Error_AwaitAsIdentifier ($1);
5727 block_variable_declaration
5728 : variable_type identifier_inside_body
5730 var lt = (LocatedToken) $2;
5731 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5732 current_block.AddLocalName (li);
5733 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5735 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5737 $$ = current_variable;
5738 current_variable = null;
5740 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5742 lbag.AddLocation ($$, GetLocation ($6));
5744 | CONST variable_type identifier_inside_body
5746 var lt = (LocatedToken) $3;
5747 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5748 current_block.AddLocalName (li);
5749 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5751 const_variable_initializer opt_const_declarators SEMICOLON
5753 $$ = current_variable;
5754 current_variable = null;
5755 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5759 opt_local_variable_initializer
5761 | ASSIGN block_variable_initializer
5763 current_variable.Initializer = (Expression) $2;
5764 PushLocation (GetLocation ($1));
5765 $$ = current_variable;
5769 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5770 report.Error (650, lexer.Location,
5771 "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");
5773 Error_SyntaxError (yyToken);
5778 opt_variable_declarators
5780 | variable_declarators
5783 opt_using_or_fixed_variable_declarators
5785 | variable_declarators
5787 foreach (var d in current_variable.Declarators) {
5788 if (d.Initializer == null)
5789 Error_MissingInitializer (d.Variable.Location);
5794 variable_declarators
5795 : variable_declarator
5796 | variable_declarators variable_declarator
5800 : COMMA identifier_inside_body
5802 var lt = (LocatedToken) $2;
5803 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5804 var d = new BlockVariableDeclarator (li, null);
5805 current_variable.AddDeclarator (d);
5806 current_block.AddLocalName (li);
5807 lbag.AddLocation (d, GetLocation ($1));
5809 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5811 var lt = (LocatedToken) $2;
5812 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5813 var d = new BlockVariableDeclarator (li, (Expression) $4);
5814 current_variable.AddDeclarator (d);
5815 current_block.AddLocalName (li);
5816 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5820 const_variable_initializer
5823 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5825 | ASSIGN constant_initializer_expr
5827 current_variable.Initializer = (Expression) $2;
5831 opt_const_declarators
5838 | const_declarators const_declarator
5842 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5844 var lt = (LocatedToken) $2;
5845 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5846 var d = new BlockVariableDeclarator (li, (Expression) $4);
5847 current_variable.AddDeclarator (d);
5848 current_block.AddLocalName (li);
5849 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5853 block_variable_initializer
5854 : variable_initializer
5855 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5857 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5858 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5860 | STACKALLOC simple_type
5862 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5863 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5867 expression_statement
5868 : statement_expression SEMICOLON
5871 lbag.AddStatement ($$, GetLocation ($2));
5873 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5874 | statement_expression CLOSE_BRACE
5877 report.Error (1002, GetLocation ($2), "; expected");
5878 lexer.putback ('}');
5882 interactive_expression_statement
5883 : interactive_statement_expression SEMICOLON { $$ = $1; }
5884 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5888 // We have to do the wrapping here and not in the case above,
5889 // because statement_expression is used for example in for_statement
5891 statement_expression
5894 ExpressionStatement s = $1 as ExpressionStatement;
5896 var expr = $1 as Expression;
5897 $$ = new StatementErrorExpression (expr);
5899 $$ = new StatementExpression (s);
5904 interactive_statement_expression
5907 Expression expr = (Expression) $1;
5908 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5912 Error_SyntaxError (yyToken);
5913 $$ = new EmptyStatement (GetLocation ($1));
5923 : IF open_parens_any boolean_expression CLOSE_PARENS
5926 if ($5 is EmptyStatement)
5927 Warning_EmptyStatement (GetLocation ($5));
5929 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5930 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5932 | IF open_parens_any boolean_expression CLOSE_PARENS
5933 embedded_statement ELSE embedded_statement
5935 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5936 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5938 if ($5 is EmptyStatement)
5939 Warning_EmptyStatement (GetLocation ($5));
5940 if ($7 is EmptyStatement)
5941 Warning_EmptyStatement (GetLocation ($7));
5943 | IF open_parens_any boolean_expression error
5945 Error_SyntaxError (yyToken);
5947 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5948 lbag.AddStatement ($$, GetLocation ($2));
5953 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5955 start_block (GetLocation ($5));
5957 opt_switch_sections CLOSE_BRACE
5959 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5960 end_block (GetLocation ($8));
5961 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5963 | SWITCH open_parens_any expression error
5965 Error_SyntaxError (yyToken);
5967 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5968 lbag.AddStatement ($$, GetLocation ($2));
5975 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5982 | switch_sections switch_section
5985 Error_SyntaxError (yyToken);
5990 : switch_labels statement_list
5996 var label = (SwitchLabel) $1;
5997 label.SectionStart = true;
5998 current_block.AddStatement (label);
6000 | switch_labels switch_label
6002 current_block.AddStatement ((Statement) $2);
6007 : CASE constant_expression COLON
6009 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6010 lbag.AddLocation ($$, GetLocation ($3));
6012 | CASE constant_expression error
6014 Error_SyntaxError (yyToken);
6015 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
6018 | CASE pattern_expr_invocation COLON
6020 if (lang_version != LanguageVersion.Experimental)
6021 FeatureIsNotAvailable (GetLocation ($2), "pattern matching");
6023 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)) {
6024 PatternMatching = true
6026 lbag.AddLocation ($$, GetLocation ($3));
6031 $$ = new SwitchLabel (null, GetLocation ($1));
6043 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
6045 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6046 Warning_EmptyStatement (GetLocation ($5));
6048 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
6049 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6051 | WHILE open_parens_any boolean_expression error
6053 Error_SyntaxError (yyToken);
6055 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
6056 lbag.AddStatement ($$, GetLocation ($2));
6061 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
6063 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6064 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
6066 | DO embedded_statement error
6068 Error_SyntaxError (yyToken);
6069 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
6071 | DO embedded_statement WHILE open_parens_any boolean_expression error
6073 Error_SyntaxError (yyToken);
6075 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
6076 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
6081 : FOR open_parens_any
6083 start_block (GetLocation ($2));
6084 current_block.IsCompilerGenerated = true;
6085 For f = new For (GetLocation ($1));
6086 current_block.AddStatement (f);
6095 // Has to use be extra rule to recover started block
6097 : opt_for_initializer SEMICOLON
6099 ((For) $0).Initializer = (Statement) $1;
6101 // Pass the "For" object to the iterator_part4
6102 oob_stack.Push ($0);
6104 for_condition_and_iterator_part
6107 var locations = (Tuple<Location,Location>) $4;
6109 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6110 Warning_EmptyStatement (GetLocation ($5));
6113 f.Statement = (Statement) $5;
6114 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
6116 $$ = end_block (GetLocation ($2));
6120 Error_SyntaxError (yyToken);
6121 $$ = end_block (current_block.StartLocation);
6125 for_condition_and_iterator_part
6126 : opt_for_condition SEMICOLON
6128 For f = (For) oob_stack.Peek ();
6129 f.Condition = (BooleanExpression) $1;
6132 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
6135 // Handle errors in the case of opt_for_condition being followed by
6136 // a close parenthesis
6137 | opt_for_condition close_parens_close_brace {
6138 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
6139 For f = (For) oob_stack.Peek ();
6140 f.Condition = (BooleanExpression) $1;
6141 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
6146 : opt_for_iterator CLOSE_PARENS {
6147 For f = (For) oob_stack.Peek ();
6148 f.Iterator = (Statement) $1;
6149 $$ = GetLocation ($2);
6151 | opt_for_iterator CLOSE_BRACE {
6152 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
6153 For f = (For) oob_stack.Peek ();
6154 f.Iterator = (Statement) $1;
6155 $$ = GetLocation ($2);
6159 close_parens_close_brace
6161 | CLOSE_BRACE { lexer.putback ('}'); }
6165 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6170 : variable_type identifier_inside_body
6172 var lt = (LocatedToken) $2;
6173 var li = new LocalVariable (current_block, lt.Value, lt.Location);
6174 current_block.AddLocalName (li);
6175 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
6177 opt_local_variable_initializer opt_variable_declarators
6179 $$ = current_variable;
6181 lbag.AddLocation (current_variable, PopLocation ());
6183 current_variable = null;
6185 | statement_expression_list
6189 : /* empty */ { $$ = null; }
6190 | boolean_expression
6194 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
6199 : statement_expression_list
6202 statement_expression_list
6203 : statement_expression
6204 | statement_expression_list COMMA statement_expression
6206 var sl = $1 as StatementList;
6208 sl = new StatementList ((Statement) $1, (Statement) $3);
6209 lbag.AddStatement (sl, GetLocation ($2));
6211 sl.Add ((Statement) $3);
6212 lbag.AppendTo (sl, GetLocation ($2));
6220 : FOREACH open_parens_any type error
6222 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
6224 start_block (GetLocation ($2));
6225 current_block.IsCompilerGenerated = true;
6227 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
6228 current_block.AddStatement (f);
6230 lbag.AddStatement (f, GetLocation ($2));
6231 $$ = end_block (GetLocation ($4));
6233 | FOREACH open_parens_any type identifier_inside_body error
6235 Error_SyntaxError (yyToken);
6237 start_block (GetLocation ($2));
6238 current_block.IsCompilerGenerated = true;
6240 var lt = (LocatedToken) $4;
6241 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6242 current_block.AddLocalName (li);
6244 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
6245 current_block.AddStatement (f);
6247 lbag.AddStatement (f, GetLocation ($2));
6248 $$ = end_block (GetLocation ($5));
6250 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
6252 start_block (GetLocation ($2));
6253 current_block.IsCompilerGenerated = true;
6255 var lt = (LocatedToken) $4;
6256 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
6257 current_block.AddLocalName (li);
6262 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6263 Warning_EmptyStatement (GetLocation ($9));
6265 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
6266 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
6267 end_block (GetLocation ($7));
6275 | continue_statement
6285 $$ = new Break (GetLocation ($1));
6286 lbag.AddStatement ($$, GetLocation ($2));
6291 : CONTINUE SEMICOLON
6293 $$ = new Continue (GetLocation ($1));
6294 lbag.AddStatement ($$, GetLocation ($2));
6298 Error_SyntaxError (yyToken);
6299 $$ = new Continue (GetLocation ($1));
6304 : GOTO identifier_inside_body SEMICOLON
6306 var lt = (LocatedToken) $2;
6307 $$ = new Goto (lt.Value, GetLocation ($1));
6308 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6310 | GOTO CASE constant_expression SEMICOLON
6312 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6313 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6315 | GOTO DEFAULT SEMICOLON
6317 $$ = new GotoDefault (GetLocation ($1));
6318 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6323 : RETURN opt_expression SEMICOLON
6325 $$ = new Return ((Expression) $2, GetLocation ($1));
6326 lbag.AddStatement ($$, GetLocation ($3));
6328 | RETURN expression error
6330 Error_SyntaxError (yyToken);
6331 $$ = new Return ((Expression) $2, GetLocation ($1));
6335 Error_SyntaxError (yyToken);
6336 $$ = new Return (null, GetLocation ($1));
6341 : THROW opt_expression SEMICOLON
6343 $$ = new Throw ((Expression) $2, GetLocation ($1));
6344 lbag.AddStatement ($$, GetLocation ($3));
6346 | THROW expression error
6348 Error_SyntaxError (yyToken);
6349 $$ = new Throw ((Expression) $2, GetLocation ($1));
6353 Error_SyntaxError (yyToken);
6354 $$ = new Throw (null, GetLocation ($1));
6359 : identifier_inside_body RETURN opt_expression SEMICOLON
6361 var lt = (LocatedToken) $1;
6362 string s = lt.Value;
6364 report.Error (1003, lt.Location, "; expected");
6365 } else if ($3 == null) {
6366 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6367 } else if (lang_version == LanguageVersion.ISO_1){
6368 FeatureIsNotAvailable (lt.Location, "iterators");
6371 current_block.Explicit.RegisterIteratorYield ();
6372 $$ = new Yield ((Expression) $3, lt.Location);
6373 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6375 | identifier_inside_body RETURN expression error
6377 Error_SyntaxError (yyToken);
6379 var lt = (LocatedToken) $1;
6380 string s = lt.Value;
6382 report.Error (1003, lt.Location, "; expected");
6383 } else if ($3 == null) {
6384 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6385 } else if (lang_version == LanguageVersion.ISO_1){
6386 FeatureIsNotAvailable (lt.Location, "iterators");
6389 current_block.Explicit.RegisterIteratorYield ();
6390 $$ = new Yield ((Expression) $3, lt.Location);
6391 lbag.AddStatement ($$, GetLocation ($2));
6393 | identifier_inside_body BREAK SEMICOLON
6395 var lt = (LocatedToken) $1;
6396 string s = lt.Value;
6398 report.Error (1003, lt.Location, "; expected");
6399 } else if (lang_version == LanguageVersion.ISO_1){
6400 FeatureIsNotAvailable (lt.Location, "iterators");
6403 current_block.ParametersBlock.TopBlock.IsIterator = true;
6404 $$ = new YieldBreak (lt.Location);
6405 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6415 : TRY block catch_clauses
6417 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6419 | TRY block FINALLY block
6421 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6422 lbag.AddStatement ($$, GetLocation ($3));
6424 | TRY block catch_clauses FINALLY block
6426 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6427 lbag.AddStatement ($$, GetLocation ($4));
6431 Error_SyntaxError (1524, yyToken);
6432 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6439 var l = new List<Catch> (2);
6444 | catch_clauses catch_clause
6446 var l = (List<Catch>) $1;
6448 Catch c = (Catch) $2;
6449 var prev_catch = l [l.Count - 1];
6450 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6451 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6461 | identifier_inside_body
6465 : CATCH opt_catch_filter block
6467 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6468 c.Filter = (CatchFilterExpression) $2;
6471 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6473 start_block (GetLocation ($2));
6474 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6475 c.TypeExpression = (FullNamedExpression) $3;
6478 var lt = (LocatedToken) $4;
6479 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6480 current_block.AddLocalName (c.Variable);
6483 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6485 lexer.parsing_catch_when = true;
6487 opt_catch_filter_or_error
6489 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6492 | CATCH open_parens_any error
6494 if (yyToken == Token.CLOSE_PARENS) {
6495 report.Error (1015, lexer.Location,
6496 "A type that derives from `System.Exception', `object', or `string' expected");
6498 Error_SyntaxError (yyToken);
6501 $$ = new Catch (null, GetLocation ($1));
6505 opt_catch_filter_or_error
6506 : opt_catch_filter block_prepared
6512 end_block (Location.Null);
6513 Error_SyntaxError (yyToken);
6520 lexer.parsing_catch_when = false;
6524 lexer.parsing_catch_when = false;
6526 open_parens_any expression CLOSE_PARENS
6528 if (lang_version <= LanguageVersion.V_5)
6529 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6531 $$ = new CatchFilterExpression ((Expression) $4, GetLocation ($1));
6532 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
6539 $$ = new Checked ((Block) $2, GetLocation ($1));
6546 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6553 if (!settings.Unsafe)
6554 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6556 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6561 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6563 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6564 Warning_EmptyStatement (GetLocation ($5));
6566 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6567 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6569 | LOCK open_parens_any expression error
6571 Error_SyntaxError (yyToken);
6573 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6574 lbag.AddStatement ($$, GetLocation ($2));
6579 : FIXED open_parens_any variable_type identifier_inside_body
6581 start_block (GetLocation ($2));
6583 current_block.IsCompilerGenerated = true;
6584 var lt = (LocatedToken) $4;
6585 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6586 current_block.AddLocalName (li);
6587 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6589 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6591 $$ = current_variable;
6592 current_variable = null;
6596 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6597 Warning_EmptyStatement (GetLocation ($10));
6599 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6600 current_block.AddStatement (f);
6601 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6602 $$ = end_block (GetLocation ($8));
6607 : USING open_parens_any variable_type identifier_inside_body
6609 start_block (GetLocation ($2));
6611 current_block.IsCompilerGenerated = true;
6612 var lt = (LocatedToken) $4;
6613 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6614 current_block.AddLocalName (li);
6615 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6617 using_initialization CLOSE_PARENS
6619 $$ = current_variable;
6620 current_variable = null;
6624 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6625 Warning_EmptyStatement (GetLocation ($9));
6627 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6628 current_block.AddStatement (u);
6629 $$ = end_block (GetLocation ($7));
6631 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6633 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6634 Warning_EmptyStatement (GetLocation ($5));
6636 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6637 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6639 | USING open_parens_any expression error
6641 Error_SyntaxError (yyToken);
6643 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6644 lbag.AddStatement ($$, GetLocation ($2));
6648 using_initialization
6649 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6652 // It has to be here for the parent to safely restore artificial block
6653 Error_SyntaxError (yyToken);
6657 using_or_fixed_variable_initializer
6660 Error_MissingInitializer (lexer.Location);
6662 | ASSIGN variable_initializer
6664 current_variable.Initializer = (Expression) $2;
6665 $$ = current_variable;
6673 : first_from_clause query_body
6675 lexer.query_parsing = false;
6677 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6679 from.Tail.Next = (Linq.AQueryClause)$2;
6682 current_block.SetEndLocation (lexer.Location);
6683 current_block = current_block.Parent;
6685 | nested_from_clause query_body
6687 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6689 from.Tail.Next = (Linq.AQueryClause)$2;
6692 current_block.SetEndLocation (lexer.Location);
6693 current_block = current_block.Parent;
6696 // Bubble up COMPLETE_COMPLETION productions
6697 | first_from_clause COMPLETE_COMPLETION {
6698 lexer.query_parsing = false;
6701 current_block.SetEndLocation (lexer.Location);
6702 current_block = current_block.Parent;
6704 | nested_from_clause COMPLETE_COMPLETION {
6706 current_block.SetEndLocation (lexer.Location);
6707 current_block = current_block.Parent;
6712 : FROM_FIRST identifier_inside_body IN expression
6714 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6716 var lt = (LocatedToken) $2;
6717 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6718 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6719 lbag.AddLocation (clause, GetLocation ($3));
6720 $$ = new Linq.QueryExpression (clause);
6722 | FROM_FIRST type identifier_inside_body IN expression
6724 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6726 var lt = (LocatedToken) $3;
6727 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6728 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6729 IdentifierType = (FullNamedExpression)$2
6731 lbag.AddLocation (clause, GetLocation ($4));
6732 $$ = new Linq.QueryExpression (clause);
6737 : FROM identifier_inside_body IN expression
6739 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6741 var lt = (LocatedToken) $2;
6742 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6743 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6744 lbag.AddLocation (clause, GetLocation ($3));
6745 $$ = new Linq.QueryExpression (clause);
6747 | FROM type identifier_inside_body IN expression
6749 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6751 var lt = (LocatedToken) $3;
6752 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6753 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6754 IdentifierType = (FullNamedExpression)$2
6756 lbag.AddLocation (clause, GetLocation ($4));
6757 $$ = new Linq.QueryExpression (clause);
6762 : FROM identifier_inside_body IN
6764 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6768 var lt = (LocatedToken) $2;
6769 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6770 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6772 current_block.SetEndLocation (lexer.Location);
6773 current_block = current_block.Parent;
6775 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6776 lbag.AddLocation ($$, GetLocation ($3));
6778 | FROM type identifier_inside_body IN
6780 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6784 var lt = (LocatedToken) $3;
6785 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6787 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6788 IdentifierType = (FullNamedExpression)$2
6791 current_block.SetEndLocation (lexer.Location);
6792 current_block = current_block.Parent;
6794 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6796 lbag.AddLocation ($$, GetLocation ($4));
6801 : query_body_clauses select_or_group_clause opt_query_continuation
6803 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6806 head.Next = (Linq.AQueryClause)$3;
6809 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6810 clause.Tail.Next = head;
6816 | select_or_group_clause opt_query_continuation
6818 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6821 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6822 clause.Tail.Next = head;
6828 | query_body_clauses COMPLETE_COMPLETION
6829 | query_body_clauses error
6831 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6836 Error_SyntaxError (yyToken);
6841 select_or_group_clause
6844 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6848 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6850 current_block.SetEndLocation (lexer.Location);
6851 current_block = current_block.Parent;
6855 if (linq_clause_blocks == null)
6856 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6858 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6859 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6863 current_block.SetEndLocation (lexer.Location);
6864 current_block = current_block.Parent;
6866 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6870 var obj = (object[]) $5;
6872 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6873 lbag.AddLocation ($$, (Location) obj[1]);
6875 current_block.SetEndLocation (lexer.Location);
6876 current_block = current_block.Parent;
6881 : BY expression_or_error
6883 $$ = new object[] { $2, GetLocation ($1) };
6887 Error_SyntaxError (yyToken);
6888 $$ = new object[2] { null, Location.Null };
6894 | query_body_clauses query_body_clause
6896 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6910 : LET identifier_inside_body ASSIGN
6912 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6916 var lt = (LocatedToken) $2;
6917 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6918 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6919 lbag.AddLocation ($$, GetLocation ($3));
6921 current_block.SetEndLocation (lexer.Location);
6922 current_block = current_block.Parent;
6924 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6931 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6935 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6937 current_block.SetEndLocation (lexer.Location);
6938 current_block = current_block.Parent;
6943 : JOIN identifier_inside_body IN
6945 if (linq_clause_blocks == null)
6946 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6948 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6949 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6951 expression_or_error ON
6953 current_block.SetEndLocation (lexer.Location);
6954 current_block = current_block.Parent;
6956 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6957 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6959 expression_or_error EQUALS
6961 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6962 current_block.SetEndLocation (lexer.Location);
6963 current_block = current_block.Parent;
6965 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6967 expression_or_error opt_join_into
6969 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6970 current_block.SetEndLocation (lexer.Location);
6972 var outer_selector = linq_clause_blocks.Pop ();
6973 var block = linq_clause_blocks.Pop ();
6975 var lt = (LocatedToken) $2;
6976 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6977 Linq.RangeVariable into;
6981 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6982 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6985 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6987 var parent = block.Parent;
6988 while (parent is Linq.QueryBlock) {
6989 parent = parent.Parent;
6991 current_block.Parent = parent;
6993 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6995 lt = (LocatedToken) $12;
6996 into = new Linq.RangeVariable (lt.Value, lt.Location);
6998 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6999 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
7002 current_block = block.Parent;
7003 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7005 | JOIN type identifier_inside_body IN
7007 if (linq_clause_blocks == null)
7008 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7010 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7011 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7013 expression_or_error ON
7015 current_block.SetEndLocation (lexer.Location);
7016 current_block = current_block.Parent;
7018 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7019 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7021 expression_or_error EQUALS
7023 current_block.AddStatement (new ContextualReturn ((Expression) $9));
7024 current_block.SetEndLocation (lexer.Location);
7025 current_block = current_block.Parent;
7027 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7029 expression_or_error opt_join_into
7031 current_block.AddStatement (new ContextualReturn ((Expression) $12));
7032 current_block.SetEndLocation (lexer.Location);
7034 var outer_selector = linq_clause_blocks.Pop ();
7035 var block = linq_clause_blocks.Pop ();
7037 var lt = (LocatedToken) $3;
7038 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
7039 Linq.RangeVariable into;
7043 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
7044 IdentifierType = (FullNamedExpression)$2
7046 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
7049 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
7051 var parent = block.Parent;
7052 while (parent is Linq.QueryBlock) {
7053 parent = parent.Parent;
7055 current_block.Parent = parent;
7057 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
7059 lt = (LocatedToken) $13;
7060 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
7062 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
7063 IdentifierType = (FullNamedExpression)$2
7067 current_block = block.Parent;
7068 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
7074 | INTO identifier_inside_body
7083 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7087 current_block.SetEndLocation (lexer.Location);
7088 current_block = current_block.Parent;
7098 current_block.SetEndLocation (lexer.Location);
7099 current_block = current_block.Parent;
7101 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7105 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
7112 | orderings_then_by COMMA
7114 current_block.SetEndLocation (lexer.Location);
7115 current_block = current_block.Parent;
7117 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
7121 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
7129 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7131 | expression ASCENDING
7133 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7134 lbag.AddLocation ($$, GetLocation ($2));
7136 | expression DESCENDING
7138 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7139 lbag.AddLocation ($$, GetLocation ($2));
7146 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7148 | expression ASCENDING
7150 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
7151 lbag.AddLocation ($$, GetLocation ($2));
7153 | expression DESCENDING
7155 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
7156 lbag.AddLocation ($$, GetLocation ($2));
7161 opt_query_continuation
7163 | INTO identifier_inside_body
7165 // query continuation block is not linked with query block but with block
7166 // before. This means each query can use same range variable names for
7167 // different identifiers.
7169 current_block.SetEndLocation (GetLocation ($1));
7170 current_block = current_block.Parent;
7172 current_block = new Linq.QueryBlock (current_block, lexer.Location);
7174 if (linq_clause_blocks == null)
7175 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
7177 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
7181 var current_block = linq_clause_blocks.Pop ();
7182 var lt = (LocatedToken) $2;
7183 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
7184 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
7185 next = (Linq.AQueryClause)$4
7191 // Support for using the compiler as an interactive parser
7193 // The INTERACTIVE_PARSER token is first sent to parse our
7194 // productions; If the result is a Statement, the parsing
7195 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
7196 // to setup the blocks in advance.
7198 // This setup is here so that in the future we can add
7199 // support for other constructs (type parsing, namespaces, etc)
7200 // that do not require a block to be setup in advance
7204 : EVAL_STATEMENT_PARSER EOF
7205 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
7206 | EVAL_STATEMENT_PARSER
7208 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
7210 // (ref object retval)
7211 Parameter [] mpar = new Parameter [1];
7212 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
7214 ParametersCompiled pars = new ParametersCompiled (mpar);
7215 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
7216 if (settings.Unsafe)
7217 mods |= Modifiers.UNSAFE;
7219 current_local_parameters = pars;
7220 var method = new InteractiveMethod (
7222 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
7226 current_type.AddMember (method);
7227 oob_stack.Push (method);
7229 interactive_async = false;
7231 ++lexer.parsing_block;
7232 start_block (lexer.Location);
7234 interactive_statement_list opt_COMPLETE_COMPLETION
7236 --lexer.parsing_block;
7237 var method = (InteractiveMethod) oob_stack.Pop ();
7238 method.Block = (ToplevelBlock) end_block(lexer.Location);
7240 if (interactive_async == true) {
7241 method.ChangeToAsync ();
7244 InteractiveResult = (Class) pop_current_class ();
7245 current_local_parameters = null;
7247 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
7250 interactive_compilation_unit
7251 : opt_extern_alias_directives opt_using_directives
7252 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
7255 opt_COMPLETE_COMPLETION
7257 | COMPLETE_COMPLETION
7260 close_brace_or_complete_completion
7262 | COMPLETE_COMPLETION
7266 // XML documentation code references micro parser
7268 documentation_parsing
7271 module.DocumentationBuilder.ParsedName = (MemberName) $2;
7276 : doc_type_declaration_name opt_doc_method_sig
7278 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7280 | builtin_types opt_doc_method_sig
7282 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7283 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7286 | VOID opt_doc_method_sig
7288 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
7289 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
7292 | builtin_types DOT IDENTIFIER opt_doc_method_sig
7294 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
7295 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
7296 var lt = (LocatedToken) $3;
7297 $$ = new MemberName (lt.Value);
7299 | doc_type_declaration_name DOT THIS
7301 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7303 | doc_type_declaration_name DOT THIS OPEN_BRACKET
7305 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7307 opt_doc_parameters CLOSE_BRACKET
7309 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
7310 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
7312 | EXPLICIT OPERATOR type opt_doc_method_sig
7314 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7315 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7316 module.DocumentationBuilder.ParsedParameters = p;
7317 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7320 | IMPLICIT OPERATOR type opt_doc_method_sig
7322 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7323 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7324 module.DocumentationBuilder.ParsedParameters = p;
7325 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7328 | OPERATOR overloadable_operator opt_doc_method_sig
7330 var p = (List<DocumentationParameter>)$3;
7331 module.DocumentationBuilder.ParsedParameters = p;
7332 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7337 doc_type_declaration_name
7338 : type_declaration_name
7339 | doc_type_declaration_name DOT type_declaration_name
7341 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7349 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7351 opt_doc_parameters CLOSE_PARENS
7360 $$ = new List<DocumentationParameter> (0);
7368 var parameters = new List<DocumentationParameter> ();
7369 parameters.Add ((DocumentationParameter) $1);
7372 | doc_parameters COMMA doc_parameter
7374 var parameters = $1 as List<DocumentationParameter>;
7375 parameters.Add ((DocumentationParameter) $3);
7381 : opt_parameter_modifier parameter_type
7384 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7386 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7393 // A class used to hold info about an operator declarator
7395 class OperatorDeclaration {
7396 public readonly Operator.OpType optype;
7397 public readonly FullNamedExpression ret_type;
7398 public readonly Location location;
7400 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7403 this.ret_type = ret_type;
7404 this.location = location;
7408 void Error_ExpectingTypeName (Expression expr)
7410 if (expr is Invocation){
7411 report.Error (1002, expr.Location, "Expecting `;'");
7413 expr.Error_InvalidExpressionStatement (report);
7417 void Error_ParameterModifierNotValid (string modifier, Location loc)
7419 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7423 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7425 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7426 Parameter.GetModifierSignature (mod));
7429 void Error_TypeExpected (Location loc)
7431 report.Error (1031, loc, "Type expected");
7434 void Error_UnsafeCodeNotAllowed (Location loc)
7436 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7439 void Warning_EmptyStatement (Location loc)
7441 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7444 void Error_NamedArgumentExpected (NamedArgument a)
7446 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7449 void Error_MissingInitializer (Location loc)
7451 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7454 object Error_AwaitAsIdentifier (object token)
7457 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7458 return new LocatedToken ("await", GetLocation (token));
7464 void push_current_container (TypeDefinition tc, object partial_token)
7466 if (module.Evaluator != null){
7467 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7471 undo.AddTypeContainer (current_container, tc);
7474 if (partial_token != null)
7475 current_container.AddPartial (tc);
7477 current_container.AddTypeContainer (tc);
7479 ++lexer.parsing_declaration;
7480 current_container = tc;
7484 TypeContainer pop_current_class ()
7486 var retval = current_container;
7488 current_container = current_container.Parent;
7489 current_type = current_type.Parent as TypeDefinition;
7494 [System.Diagnostics.Conditional ("FULL_AST")]
7495 void StoreModifierLocation (object token, Location loc)
7500 if (mod_locations == null)
7501 mod_locations = new List<Tuple<Modifiers, Location>> ();
7503 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7506 [System.Diagnostics.Conditional ("FULL_AST")]
7507 void PushLocation (Location loc)
7509 if (location_stack == null)
7510 location_stack = new Stack<Location> ();
7512 location_stack.Push (loc);
7515 Location PopLocation ()
7517 if (location_stack == null)
7518 return Location.Null;
7520 return location_stack.Pop ();
7523 string CheckAttributeTarget (int token, string a, Location l)
7526 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7530 if (!Tokenizer.IsValidIdentifier (a)) {
7531 Error_SyntaxError (token);
7533 report.Warning (658, 1, l,
7534 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7537 return string.Empty;
7540 static bool IsUnaryOperator (Operator.OpType op)
7544 case Operator.OpType.LogicalNot:
7545 case Operator.OpType.OnesComplement:
7546 case Operator.OpType.Increment:
7547 case Operator.OpType.Decrement:
7548 case Operator.OpType.True:
7549 case Operator.OpType.False:
7550 case Operator.OpType.UnaryPlus:
7551 case Operator.OpType.UnaryNegation:
7557 void syntax_error (Location l, string msg)
7559 report.Error (1003, l, "Syntax error, " + msg);
7564 public Tokenizer Lexer {
7570 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7571 : this (reader, file, file.Compiler.Report, session)
7575 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7578 current_container = current_namespace = file;
7580 this.module = file.Module;
7581 this.compiler = file.Compiler;
7582 this.settings = compiler.Settings;
7583 this.report = report;
7585 lang_version = settings.Version;
7586 yacc_verbose_flag = settings.VerboseParserFlag;
7587 doc_support = settings.DocumentationFile != null;
7588 lexer = new Tokenizer (reader, file, session, report);
7589 oob_stack = new Stack<object> ();
7590 lbag = session.LocationsBag;
7591 use_global_stacks = session.UseJayGlobalArrays;
7592 parameters_bucket = session.ParametersStack;
7595 public void parse ()
7597 eof_token = Token.EOF;
7600 if (yacc_verbose_flag > 1)
7601 yyparse (lexer, new yydebug.yyDebugSimple ());
7605 Tokenizer tokenizer = lexer as Tokenizer;
7606 tokenizer.cleanup ();
7607 } catch (Exception e){
7608 if (e is yyParser.yyUnexpectedEof) {
7609 Error_SyntaxError (yyToken);
7610 UnexpectedEOF = true;
7614 if (e is yyParser.yyException) {
7615 if (report.Errors == 0)
7616 report.Error (-25, lexer.Location, "Parsing error");
7618 // Used by compiler-tester to test internal errors
7619 if (yacc_verbose_flag > 0 || e is FatalException)
7622 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7627 void CheckToken (int error, int yyToken, string msg, Location loc)
7629 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7630 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7632 report.Error (error, loc, msg);
7635 string ConsumeStoredComment ()
7637 string s = tmpComment;
7639 Lexer.doc_state = XmlCommentState.Allowed;
7643 void FeatureIsNotAvailable (Location loc, string feature)
7645 report.FeatureIsNotAvailable (compiler, loc, feature);
7648 Location GetLocation (object obj)
7650 var lt = obj as LocatedToken;
7654 var mn = obj as MemberName;
7658 var expr = obj as Expression;
7660 return expr.Location;
7662 return lexer.Location;
7665 void start_block (Location loc)
7667 if (current_block == null) {
7668 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7669 parsing_anonymous_method = false;
7670 } else if (parsing_anonymous_method) {
7671 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7672 parsing_anonymous_method = false;
7674 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7679 end_block (Location loc)
7681 Block retval = current_block.Explicit;
7682 retval.SetEndLocation (loc);
7683 current_block = retval.Parent;
7687 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7689 oob_stack.Push (current_anonymous_method);
7690 oob_stack.Push (current_local_parameters);
7691 oob_stack.Push (current_variable);
7692 oob_stack.Push (async_block);
7694 current_local_parameters = parameters;
7696 if (lang_version <= LanguageVersion.ISO_2)
7697 FeatureIsNotAvailable (loc, "lambda expressions");
7699 current_anonymous_method = new LambdaExpression (loc);
7701 if (lang_version == LanguageVersion.ISO_1)
7702 FeatureIsNotAvailable (loc, "anonymous methods");
7704 current_anonymous_method = new AnonymousMethodExpression (loc);
7707 async_block = isAsync;
7708 // Force the next block to be created as a ToplevelBlock
7709 parsing_anonymous_method = true;
7713 * Completes the anonymous method processing, if lambda_expr is null, this
7714 * means that we have a Statement instead of an Expression embedded
7716 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7718 AnonymousMethodExpression retval;
7721 anon_block.IsAsync = true;
7723 current_anonymous_method.Block = anon_block;
7724 retval = current_anonymous_method;
7726 async_block = (bool) oob_stack.Pop ();
7727 current_variable = (BlockVariable) oob_stack.Pop ();
7728 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7729 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7734 void Error_SyntaxError (int token)
7736 Error_SyntaxError (0, token);
7739 void Error_SyntaxError (int error_code, int token)
7741 Error_SyntaxError (error_code, token, "Unexpected symbol");
7744 void Error_SyntaxError (int error_code, int token, string msg)
7746 Lexer.CompleteOnEOF = false;
7748 // An error message has been reported by tokenizer
7749 if (token == Token.ERROR)
7752 // Avoid duplicit error message after unterminated string literals
7753 if (token == Token.LITERAL && lexer.Location.Column == 0)
7756 string symbol = GetSymbolName (token);
7757 string expecting = GetExpecting ();
7758 var loc = lexer.Location - symbol.Length;
7760 if (error_code == 0) {
7761 if (expecting == "`identifier'") {
7762 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7763 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7768 expecting = "identifier";
7769 } else if (expecting == "`)'") {
7776 if (string.IsNullOrEmpty (expecting))
7777 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7779 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7782 string GetExpecting ()
7784 int [] tokens = yyExpectingTokens (yyExpectingState);
7785 var names = new List<string> (tokens.Length);
7786 bool has_type = false;
7787 bool has_identifier = false;
7788 for (int i = 0; i < tokens.Length; i++){
7789 int token = tokens [i];
7790 has_identifier |= token == Token.IDENTIFIER;
7792 string name = GetTokenName (token);
7793 if (name == "<internal>")
7796 has_type |= name == "type";
7797 if (names.Contains (name))
7804 // Too many tokens to enumerate
7806 if (names.Count > 8)
7809 if (has_type && has_identifier)
7810 names.Remove ("identifier");
7812 if (names.Count == 1)
7813 return "`" + GetTokenName (tokens [0]) + "'";
7815 StringBuilder sb = new StringBuilder ();
7817 int count = names.Count;
7818 for (int i = 0; i < count; i++){
7819 bool last = i + 1 == count;
7823 sb.Append (names [i]);
7824 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7826 return sb.ToString ();
7830 string GetSymbolName (int token)
7834 return ((Constant)lexer.Value).GetValue ().ToString ();
7835 case Token.IDENTIFIER:
7836 return ((LocatedToken)lexer.Value).Value;
7878 case Token.BITWISE_AND:
7880 case Token.BITWISE_OR:
7894 case Token.OP_SHIFT_LEFT:
7896 case Token.OP_SHIFT_RIGHT:
7916 case Token.OP_COALESCING:
7918 case Token.OP_MULT_ASSIGN:
7920 case Token.OP_DIV_ASSIGN:
7922 case Token.OP_MOD_ASSIGN:
7924 case Token.OP_ADD_ASSIGN:
7926 case Token.OP_SUB_ASSIGN:
7928 case Token.OP_SHIFT_LEFT_ASSIGN:
7930 case Token.OP_SHIFT_RIGHT_ASSIGN:
7932 case Token.OP_AND_ASSIGN:
7934 case Token.OP_XOR_ASSIGN:
7936 case Token.OP_OR_ASSIGN:
7940 return GetTokenName (token);
7943 static string GetTokenName (int token)
7946 case Token.ABSTRACT:
7968 case Token.CONTINUE:
7972 case Token.DELEGATE:
7982 case Token.EXPLICIT:
7985 case Token.EXTERN_ALIAS:
8001 case Token.IMPLICIT:
8005 case Token.INTERFACE:
8007 case Token.INTERNAL:
8013 case Token.NAMESPACE:
8019 case Token.OPERATOR:
8023 case Token.OVERRIDE:
8029 case Token.PROTECTED:
8033 case Token.READONLY:
8045 case Token.STACKALLOC:
8046 return "stackalloc";
8063 case Token.UNCHECKED:
8071 case Token.VOLATILE:
8079 case Token.REFVALUE:
8080 return "__refvalue";
8090 case Token.FROM_FIRST:
8108 case Token.ASCENDING:
8110 case Token.DESCENDING:
8111 return "descending";
8118 case Token.OPEN_BRACE:
8120 case Token.CLOSE_BRACE:
8122 case Token.OPEN_BRACKET:
8123 case Token.OPEN_BRACKET_EXPR:
8125 case Token.CLOSE_BRACKET:
8127 case Token.OPEN_PARENS_CAST:
8128 case Token.OPEN_PARENS_LAMBDA:
8129 case Token.OPEN_PARENS:
8131 case Token.CLOSE_PARENS:
8137 case Token.DEFAULT_COLON:
8141 case Token.SEMICOLON:
8147 case Token.INTERPOLATED_STRING_END:
8149 case Token.INTERPOLATED_STRING:
8158 case Token.BITWISE_AND:
8159 case Token.BITWISE_OR:
8166 case Token.OP_SHIFT_LEFT:
8167 case Token.OP_SHIFT_RIGHT:
8175 case Token.OP_COALESCING:
8176 case Token.OP_MULT_ASSIGN:
8177 case Token.OP_DIV_ASSIGN:
8178 case Token.OP_MOD_ASSIGN:
8179 case Token.OP_ADD_ASSIGN:
8180 case Token.OP_SUB_ASSIGN:
8181 case Token.OP_SHIFT_LEFT_ASSIGN:
8182 case Token.OP_SHIFT_RIGHT_ASSIGN:
8183 case Token.OP_AND_ASSIGN:
8184 case Token.OP_XOR_ASSIGN:
8185 case Token.OP_OR_ASSIGN:
8186 case Token.INTERR_OPERATOR:
8187 return "<operator>";
8209 case Token.OP_GENERICS_LT:
8210 case Token.GENERIC_DIMENSION:
8212 case Token.OP_GENERICS_GT:
8215 case Token.INTERR_NULLABLE:
8217 case Token.DOUBLE_COLON:
8221 case Token.IDENTIFIER:
8223 return "identifier";
8226 return "end-of-file";
8228 // All of these are internal.
8231 case Token.FIRST_KEYWORD:
8232 case Token.EVAL_COMPILATION_UNIT_PARSER:
8233 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
8234 case Token.EVAL_STATEMENT_PARSER:
8235 case Token.LAST_KEYWORD:
8236 case Token.GENERATE_COMPLETION:
8237 case Token.COMPLETE_COMPLETION:
8238 return "<internal>";
8240 // A bit more robust.
8242 return yyNames [token];