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
261 /* C# keywords which are not really keywords */
267 /* C# single character operators/punctuation. */
295 /* C# multi-character operators. */
300 %token OP_SHIFT_RIGHT
307 %token OP_MULT_ASSIGN
312 %token OP_SHIFT_LEFT_ASSIGN
313 %token OP_SHIFT_RIGHT_ASSIGN
320 /* Generics <,> tokens */
321 %token OP_GENERICS_LT
322 %token OP_GENERICS_LT_DECL
323 %token OP_GENERICS_GT
328 %token OPEN_PARENS_LAMBDA
329 %token OPEN_PARENS_CAST
330 %token GENERIC_DIMENSION
332 %token OPEN_BRACKET_EXPR
334 // Make the parser go into eval mode parsing (statements and compilation units).
335 %token EVAL_STATEMENT_PARSER
336 %token EVAL_COMPILATION_UNIT_PARSER
337 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
342 // This token is generated to trigger the completion engine at this point
344 %token GENERATE_COMPLETION
347 // This token is return repeatedly after the first GENERATE_COMPLETION
348 // token is produced and before the final EOF
350 %token COMPLETE_COMPLETION
352 /* Add precedence rules to solve dangling else s/r conflict */
356 /* Define the operator tokens and their precedences */
364 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
366 %left STAR DIV PERCENT
367 %right BANG CARRET UMINUS
368 %nonassoc OP_INC OP_DEC
370 %left OPEN_BRACKET OPEN_BRACE
373 %start compilation_unit
377 : outer_declaration opt_EOF
379 Lexer.check_incorrect_doc_comment ();
381 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
382 | documentation_parsing
386 : opt_extern_alias_directives opt_using_directives
387 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
390 Attributes attrs = (Attributes) $4;
391 report.Error (1730, attrs.Attrs [0].Location,
392 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
394 current_namespace.UnattachedAttributes = attrs;
397 | opt_extern_alias_directives opt_using_directives attribute_sections
399 module.AddAttributes ((Attributes) $3, current_namespace);
403 if (yyToken == Token.EXTERN_ALIAS)
404 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
406 Error_SyntaxError (yyToken);
415 extern_alias_directives
416 : extern_alias_directive
417 | extern_alias_directives extern_alias_directive
420 extern_alias_directive
421 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
423 var lt = (LocatedToken) $2;
426 syntax_error (lt.Location, "`alias' expected");
428 if (lang_version == LanguageVersion.ISO_1)
429 FeatureIsNotAvailable (lt.Location, "external alias");
431 lt = (LocatedToken) $3;
432 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
433 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
436 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
437 current_namespace.AddUsing (na);
439 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
444 Error_SyntaxError (yyToken);
450 | using_directives using_directive
457 Lexer.doc_state = XmlCommentState.Allowed;
462 : USING namespace_or_type_expr SEMICOLON
464 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
465 current_namespace.AddUsing (un);
467 lbag.AddLocation (un, GetLocation ($3));
469 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
471 var lt = (LocatedToken) $2;
472 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
473 report.Warning (440, 2, lt.Location,
474 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
477 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
478 current_namespace.AddUsing (un);
480 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
484 Error_SyntaxError (yyToken);
490 // Strictly speaking, namespaces don't have attributes but
491 // we parse global attributes along with namespace declarations and then
494 namespace_declaration
495 : opt_attributes NAMESPACE namespace_name
497 Attributes attrs = (Attributes) $1;
498 var name = (MemberName) $3;
500 bool valid_global_attrs = true;
501 if ((current_namespace.DeclarationFound || current_namespace != file)) {
502 valid_global_attrs = false;
504 foreach (var a in attrs.Attrs) {
505 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
508 valid_global_attrs = false;
513 if (!valid_global_attrs)
514 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
517 module.AddAttributes (attrs, current_namespace);
519 var ns = new NamespaceContainer (name, current_namespace);
520 current_namespace.AddTypeContainer (ns);
521 current_container = current_namespace = ns;
526 Lexer.doc_state = XmlCommentState.Allowed;
528 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
531 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
533 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
535 current_container = current_namespace = current_namespace.Parent;
537 | opt_attributes NAMESPACE namespace_name
539 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
541 var name = (MemberName) $3;
542 var ns = new NamespaceContainer (name, current_namespace);
543 lbag.AddLocation (ns, GetLocation ($2));
544 current_namespace.AddTypeContainer (ns);
553 Error_SyntaxError (yyToken);
561 var lt = (LocatedToken) $1;
562 $$ = new MemberName (lt.Value, lt.Location);
564 | namespace_name DOT IDENTIFIER
566 var lt = (LocatedToken) $3;
567 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
568 lbag.AddLocation ($$, GetLocation ($2));
572 Error_SyntaxError (yyToken);
573 $$ = new MemberName ("<invalid>", lexer.Location);
592 opt_extern_alias_directives
594 | extern_alias_directives
597 opt_namespace_or_type_declarations
599 | namespace_or_type_declarations
602 namespace_or_type_declarations
603 : namespace_or_type_declaration
604 | namespace_or_type_declarations namespace_or_type_declaration
607 namespace_or_type_declaration
611 TypeContainer ds = (TypeContainer)$1;
613 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
614 report.Error (1527, ds.Location,
615 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
618 // Here is a trick, for explicit attributes we don't know where they belong to until
619 // we parse succeeding declaration hence we parse them as normal and re-attach them
620 // when we know whether they are global (assembly:, module:) or local (type:).
621 if (ds.OptAttributes != null) {
622 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
625 current_namespace.DeclarationFound = true;
627 | namespace_declaration
629 current_namespace.DeclarationFound = true;
631 | attribute_sections CLOSE_BRACE {
632 current_namespace.UnattachedAttributes = (Attributes) $1;
633 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
641 | interface_declaration
643 | delegate_declaration
645 // Enable this when we have handled all errors, because this acts as a generic fallback
648 // Console.WriteLine ("Token=" + yyToken);
649 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
665 var sect = (List<Attribute>) $1;
666 $$ = new Attributes (sect);
668 | attribute_sections attribute_section
670 Attributes attrs = $1 as Attributes;
671 var sect = (List<Attribute>) $2;
673 attrs = new Attributes (sect);
674 else if (sect != null)
675 attrs.AddAttributes (sect);
683 PushLocation (GetLocation ($1));
684 lexer.parsing_attribute_section = true;
686 attribute_section_cont
688 lexer.parsing_attribute_section = false;
693 attribute_section_cont
694 : attribute_target COLON
696 current_attr_target = (string) $1;
697 if (current_attr_target == "assembly" || current_attr_target == "module") {
698 Lexer.check_incorrect_doc_comment ();
701 attribute_list opt_comma CLOSE_BRACKET
703 // when attribute target is invalid
704 if (current_attr_target == string.Empty)
705 $$ = new List<Attribute> (0);
709 lbag.InsertLocation ($$, 0, PopLocation ());
711 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
713 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
716 current_attr_target = null;
717 lexer.parsing_attribute_section = false;
719 | attribute_list opt_comma CLOSE_BRACKET
723 lbag.InsertLocation ($$, 0, PopLocation ());
725 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
727 lbag.AddLocation ($$, GetLocation($3));
732 Error_SyntaxError (yyToken);
734 var lt = (LocatedToken) $1;
735 var tne = new SimpleName (lt.Value, null, lt.Location);
737 $$ = new List<Attribute> () {
738 new Attribute (null, tne, null, GetLocation ($1), false)
743 CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1));
751 var lt = (LocatedToken) $1;
752 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
754 | EVENT { $$ = "event"; }
755 | RETURN { $$ = "return"; }
761 $$ = new List<Attribute> (4) { (Attribute) $1 };
763 | attribute_list COMMA attribute
765 var attrs = (List<Attribute>) $1;
767 attrs.Add ((Attribute) $3);
768 lbag.AppendTo (attrs, GetLocation ($2));
778 ++lexer.parsing_block;
780 opt_attribute_arguments
782 --lexer.parsing_block;
784 var tne = (ATypeNameExpression) $1;
785 if (tne.HasTypeArguments) {
786 report.Error (404, tne.Location, "Attributes cannot be generic");
789 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
794 : namespace_or_type_expr
797 opt_attribute_arguments
798 : /* empty */ { $$ = null; }
799 | OPEN_PARENS attribute_arguments CLOSE_PARENS
807 : /* empty */ { $$ = null; }
808 | positional_or_named_argument
810 Arguments a = new Arguments (4);
811 a.Add ((Argument) $1);
812 $$ = new Arguments [] { a, null };
814 | named_attribute_argument
816 Arguments a = new Arguments (4);
817 a.Add ((Argument) $1);
818 $$ = new Arguments [] { null, a };
820 | attribute_arguments COMMA positional_or_named_argument
822 Arguments[] o = (Arguments[]) $1;
824 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
825 o [0] = new Arguments (4);
828 Arguments args = ((Arguments) o [0]);
829 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
830 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
832 args.Add ((Argument) $3);
834 | attribute_arguments COMMA named_attribute_argument
836 Arguments[] o = (Arguments[]) $1;
838 o [1] = new Arguments (4);
841 ((Arguments) o [1]).Add ((Argument) $3);
845 positional_or_named_argument
848 $$ = new Argument ((Expression) $1);
853 Error_SyntaxError (yyToken);
858 named_attribute_argument
861 ++lexer.parsing_block;
865 --lexer.parsing_block;
866 var lt = (LocatedToken) $1;
867 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
868 lbag.AddLocation ($$, GetLocation($2));
873 : identifier_inside_body COLON opt_named_modifier expression_or_error
875 if (lang_version <= LanguageVersion.V_3)
876 FeatureIsNotAvailable (GetLocation ($1), "named argument");
878 // Avoid boxing in common case (no modifier)
879 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
881 var lt = (LocatedToken) $1;
882 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
883 lbag.AddLocation ($$, GetLocation($2));
888 : /* empty */ { $$ = null; }
891 $$ = Argument.AType.Ref;
895 $$ = Argument.AType.Out;
899 opt_class_member_declarations
901 | class_member_declarations
904 class_member_declarations
905 : class_member_declaration
907 lexer.parsing_modifiers = true;
908 lexer.parsing_block = 0;
910 | class_member_declarations class_member_declaration
912 lexer.parsing_modifiers = true;
913 lexer.parsing_block = 0;
917 class_member_declaration
918 : constant_declaration
921 | property_declaration
923 | indexer_declaration
924 | operator_declaration
925 | constructor_declaration
926 | primary_constructor_body
927 | destructor_declaration
929 | attributes_without_members
933 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
934 GetSymbolName (yyToken));
936 lexer.parsing_generic_declaration = false;
940 primary_constructor_body
943 current_local_parameters = current_type.PrimaryConstructorParameters;
944 if (current_local_parameters == null) {
945 report.Error (9010, GetLocation ($1), "Primary constructor body is not allowed");
946 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
949 ++lexer.parsing_block;
950 start_block (GetLocation ($1));
952 opt_statement_list block_end
954 current_local_parameters = null;
955 var t = current_type as ClassOrStruct;
957 var b = (ToplevelBlock) $4;
958 if (t.PrimaryConstructorBlock != null) {
959 report.Error (8041, b.StartLocation, "Primary constructor already has a body");
961 t.PrimaryConstructorBlock = b;
974 type_declaration_name
976 lexer.ConstraintsParsing = true;
977 valid_param_mod = ParameterModifierType.PrimaryConstructor;
978 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
980 opt_primary_parameters
982 opt_type_parameter_constraints_clauses
985 lexer.ConstraintsParsing = false;
988 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
991 current_container.SetConstraints ((List<Constraints>) $10);
994 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
996 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
998 lexer.parsing_modifiers = true;
1003 Lexer.doc_state = XmlCommentState.Allowed;
1005 opt_class_member_declarations CLOSE_BRACE
1007 --lexer.parsing_declaration;
1009 Lexer.doc_state = XmlCommentState.Allowed;
1014 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
1016 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
1018 $$ = pop_current_class ();
1020 | opt_attributes opt_modifiers opt_partial STRUCT error
1022 Error_SyntaxError (yyToken);
1026 constant_declaration
1029 CONST type IDENTIFIER
1031 var lt = (LocatedToken) $5;
1032 var mod = (Modifiers) $2;
1033 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1034 current_type.AddMember (current_field);
1036 if ((mod & Modifiers.STATIC) != 0) {
1037 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1042 constant_initializer opt_constant_declarators SEMICOLON
1045 current_field.DocComment = Lexer.consume_doc_comment ();
1046 Lexer.doc_state = XmlCommentState.Allowed;
1049 current_field.Initializer = (ConstInitializer) $7;
1050 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1051 current_field = null;
1057 Error_SyntaxError (yyToken);
1059 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1063 opt_constant_declarators
1065 | constant_declarators
1068 constant_declarators
1069 : constant_declarator
1071 current_field.AddDeclarator ((FieldDeclarator) $1);
1073 | constant_declarators constant_declarator
1075 current_field.AddDeclarator ((FieldDeclarator) $2);
1080 : COMMA IDENTIFIER constant_initializer
1082 var lt = (LocatedToken) $2;
1083 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1084 lbag.AddLocation ($$, GetLocation ($1));
1088 constant_initializer
1091 ++lexer.parsing_block;
1093 constant_initializer_expr
1095 --lexer.parsing_block;
1096 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1100 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1105 constant_initializer_expr
1106 : constant_expression
1113 member_type IDENTIFIER
1115 lexer.parsing_generic_declaration = false;
1117 FullNamedExpression type = (FullNamedExpression) $3;
1118 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1119 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1121 var lt = (LocatedToken) $4;
1122 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1123 current_type.AddField (current_field);
1126 opt_field_initializer
1127 opt_field_declarators
1131 current_field.DocComment = Lexer.consume_doc_comment ();
1132 Lexer.doc_state = XmlCommentState.Allowed;
1135 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1137 current_field = null;
1141 FIXED simple_type IDENTIFIER
1143 if (lang_version < LanguageVersion.ISO_2)
1144 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1146 var lt = (LocatedToken) $5;
1147 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1148 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1150 current_type.AddField (current_field);
1152 fixed_field_size opt_fixed_field_declarators SEMICOLON
1155 current_field.DocComment = Lexer.consume_doc_comment ();
1156 Lexer.doc_state = XmlCommentState.Allowed;
1159 current_field.Initializer = (ConstInitializer) $7;
1160 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1162 current_field = null;
1166 FIXED simple_type error
1169 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1173 opt_field_initializer
1177 ++lexer.parsing_block;
1178 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1179 start_block (GetLocation ($1));
1181 variable_initializer
1183 --lexer.parsing_block;
1184 current_field.Initializer = (Expression) $3;
1185 lbag.AppendToMember (current_field, GetLocation ($1));
1186 end_block (lexer.Location);
1187 current_local_parameters = null;
1191 opt_field_declarators
1199 current_field.AddDeclarator ((FieldDeclarator) $1);
1201 | field_declarators field_declarator
1203 current_field.AddDeclarator ((FieldDeclarator) $2);
1210 var lt = (LocatedToken) $2;
1211 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1212 lbag.AddLocation ($$, GetLocation ($1));
1214 | COMMA IDENTIFIER ASSIGN
1216 ++lexer.parsing_block;
1218 variable_initializer
1220 --lexer.parsing_block;
1221 var lt = (LocatedToken) $2;
1222 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1223 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1227 opt_fixed_field_declarators
1229 | fixed_field_declarators
1232 fixed_field_declarators
1233 : fixed_field_declarator
1235 current_field.AddDeclarator ((FieldDeclarator) $1);
1237 | fixed_field_declarators fixed_field_declarator
1239 current_field.AddDeclarator ((FieldDeclarator) $2);
1243 fixed_field_declarator
1244 : COMMA IDENTIFIER fixed_field_size
1246 var lt = (LocatedToken) $2;
1247 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1248 lbag.AddLocation ($$, GetLocation ($1));
1255 ++lexer.parsing_block;
1257 expression CLOSE_BRACKET
1259 --lexer.parsing_block;
1260 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1261 lbag.AddLocation ($$, GetLocation ($4));
1263 | OPEN_BRACKET error
1265 report.Error (443, lexer.Location, "Value or constant expected");
1270 variable_initializer
1275 // It has to be here for the parent to safely restore artificial block
1276 Error_SyntaxError (yyToken);
1285 Lexer.doc_state = XmlCommentState.NotAllowed;
1287 // Was added earlier in the case of body being eof for full ast
1291 Method method = (Method) $1;
1292 method.Block = (ToplevelBlock) $3;
1293 async_block = false;
1295 if (method.Block == null) {
1296 method.ParameterInfo.CheckParameters (method);
1298 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1299 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1300 method.GetSignatureForError ());
1303 if (current_container.Kind == MemberKind.Interface) {
1304 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1305 method.GetSignatureForError ());
1309 current_local_parameters = null;
1312 Lexer.doc_state = XmlCommentState.Allowed;
1320 method_declaration_name OPEN_PARENS
1322 valid_param_mod = ParameterModifierType.All;
1324 opt_formal_parameter_list CLOSE_PARENS
1326 valid_param_mod = 0;
1327 MemberName name = (MemberName) $4;
1328 current_local_parameters = (ParametersCompiled) $7;
1330 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1331 name, current_local_parameters, (Attributes) $1);
1333 current_type.AddMember (method);
1335 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1338 method.DocComment = Lexer.consume_doc_comment ();
1340 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1344 lexer.ConstraintsParsing = true;
1346 opt_type_parameter_constraints_clauses
1348 lexer.ConstraintsParsing = false;
1351 var method = (Method) $9;
1352 method.SetConstraints ((List<Constraints>) $10);
1362 lexer.parsing_generic_declaration = true;
1364 method_declaration_name
1367 lexer.parsing_generic_declaration = false;
1368 valid_param_mod = ParameterModifierType.All;
1370 opt_formal_parameter_list CLOSE_PARENS
1372 lexer.ConstraintsParsing = true;
1374 opt_type_parameter_constraints_clauses
1376 lexer.ConstraintsParsing = false;
1377 valid_param_mod = 0;
1379 MemberName name = (MemberName) $6;
1380 current_local_parameters = (ParametersCompiled) $9;
1382 var modifiers = (Modifiers) $2;
1383 modifiers |= Modifiers.PARTIAL;
1385 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1386 modifiers, name, current_local_parameters, (Attributes) $1);
1388 current_type.AddMember (method);
1390 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1393 method.SetConstraints ((List<Constraints>) $12);
1396 method.DocComment = Lexer.consume_doc_comment ();
1398 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1399 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1405 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1407 MemberName name = (MemberName) $5;
1408 report.Error (1585, name.Location,
1409 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1411 var method = Method.Create (current_type, (FullNamedExpression) $3,
1412 0, name, (ParametersCompiled) $7, (Attributes) $1);
1414 current_type.AddMember (method);
1416 current_local_parameters = (ParametersCompiled) $7;
1419 method.DocComment = Lexer.consume_doc_comment ();
1426 method_declaration_name error
1428 Error_SyntaxError (yyToken);
1429 current_local_parameters = ParametersCompiled.Undefined;
1431 MemberName name = (MemberName) $4;
1432 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1433 name, current_local_parameters, (Attributes) $1);
1435 current_type.AddMember (method);
1438 method.DocComment = Lexer.consume_doc_comment ();
1447 | SEMICOLON { $$ = null; }
1453 if (lang_version < LanguageVersion.V_6) {
1454 FeatureIsNotAvailable (GetLocation ($1), "expression bodied members");
1457 ++lexer.parsing_block;
1458 start_block (GetLocation ($1));
1460 expression SEMICOLON
1462 lexer.parsing_block = 0;
1463 current_block.AddStatement (new ContextualReturn ((Expression) $3));
1464 var b = end_block (GetLocation ($4));
1465 b.IsCompilerGenerated = true;
1470 opt_formal_parameter_list
1471 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1472 | formal_parameter_list
1475 formal_parameter_list
1478 var pars_list = (List<Parameter>) $1;
1479 $$ = new ParametersCompiled (pars_list.ToArray ());
1481 | fixed_parameters COMMA parameter_array
1483 var pars_list = (List<Parameter>) $1;
1484 pars_list.Add ((Parameter) $3);
1486 $$ = new ParametersCompiled (pars_list.ToArray ());
1488 | fixed_parameters COMMA arglist_modifier
1490 var pars_list = (List<Parameter>) $1;
1491 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1492 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1494 | parameter_array COMMA error
1497 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1499 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1501 | fixed_parameters COMMA parameter_array COMMA error
1504 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1506 var pars_list = (List<Parameter>) $1;
1507 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1509 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1511 | arglist_modifier COMMA error
1513 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1515 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1517 | fixed_parameters COMMA ARGLIST COMMA error
1519 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1521 var pars_list = (List<Parameter>) $1;
1522 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1524 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1528 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1532 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1536 Error_SyntaxError (yyToken);
1537 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1544 parameters_bucket.Clear ();
1545 Parameter p = (Parameter) $1;
1546 parameters_bucket.Add (p);
1548 default_parameter_used = p.HasDefaultValue;
1549 $$ = parameters_bucket;
1551 | fixed_parameters COMMA fixed_parameter
1553 var pars = (List<Parameter>) $1;
1554 Parameter p = (Parameter) $3;
1556 if (p.HasExtensionMethodModifier)
1557 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1558 else if (!p.HasDefaultValue && default_parameter_used)
1559 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1561 default_parameter_used |= p.HasDefaultValue;
1564 lbag.AddLocation (p, GetLocation ($2));
1573 opt_parameter_modifier
1575 identifier_inside_body
1577 var lt = (LocatedToken) $4;
1578 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1581 opt_parameter_modifier
1583 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1585 var lt = (LocatedToken) $4;
1586 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1587 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1589 | attribute_sections error
1591 Error_SyntaxError (yyToken);
1592 Location l = GetLocation ($2);
1593 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1596 opt_parameter_modifier
1600 Error_SyntaxError (yyToken);
1601 Location l = GetLocation ($4);
1602 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1605 opt_parameter_modifier
1607 identifier_inside_body
1610 ++lexer.parsing_block;
1614 --lexer.parsing_block;
1615 if (lang_version <= LanguageVersion.V_3) {
1616 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1619 Parameter.Modifier mod = (Parameter.Modifier) $2;
1620 if (mod != Parameter.Modifier.NONE) {
1622 case Parameter.Modifier.REF:
1623 case Parameter.Modifier.OUT:
1624 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1625 Parameter.GetModifierSignature (mod));
1628 case Parameter.Modifier.This:
1629 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1630 Parameter.GetModifierSignature (mod));
1633 throw new NotImplementedException (mod.ToString ());
1636 mod = Parameter.Modifier.NONE;
1639 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1640 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1642 var lt = (LocatedToken) $4;
1643 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1644 lbag.AddLocation ($$, GetLocation ($5));
1647 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1651 opt_parameter_modifier
1652 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1653 | parameter_modifiers
1657 : parameter_modifier
1661 | parameter_modifiers parameter_modifier
1663 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1664 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1665 if (((Parameter.Modifier)$1 & p2) == p2) {
1666 Error_DuplicateParameterModifier (lexer.Location, p2);
1668 switch (mod & ~Parameter.Modifier.This) {
1669 case Parameter.Modifier.REF:
1670 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1672 case Parameter.Modifier.OUT:
1673 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1676 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1687 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1688 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1690 $$ = Parameter.Modifier.REF;
1694 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1695 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1697 $$ = Parameter.Modifier.OUT;
1701 if ((valid_param_mod & ParameterModifierType.This) == 0)
1702 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1704 if (lang_version <= LanguageVersion.ISO_2)
1705 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1707 $$ = Parameter.Modifier.This;
1712 : opt_attributes params_modifier type IDENTIFIER
1714 var lt = (LocatedToken) $4;
1715 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1717 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1719 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1721 var lt = (LocatedToken) $4;
1722 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1724 | opt_attributes params_modifier type error
1726 Error_SyntaxError (yyToken);
1728 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1735 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1736 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1738 | PARAMS parameter_modifier
1740 Parameter.Modifier mod = (Parameter.Modifier)$2;
1741 if ((mod & Parameter.Modifier.This) != 0) {
1742 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1744 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1747 | PARAMS params_modifier
1749 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1756 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1757 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1761 property_declaration
1765 member_declaration_name
1767 lexer.parsing_generic_declaration = false;
1769 tmpComment = Lexer.consume_doc_comment ();
1773 var type = (FullNamedExpression) $3;
1774 current_property = new Property (current_type, type, (Modifiers) $2,
1775 (MemberName) $4, (Attributes) $1);
1777 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1778 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1780 current_type.AddMember (current_property);
1781 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1783 lexer.PropertyParsing = true;
1785 accessor_declarations
1787 lexer.PropertyParsing = false;
1790 current_property.DocComment = ConsumeStoredComment ();
1794 lbag.AppendToMember (current_property, GetLocation ($10));
1795 lexer.parsing_modifiers = true;
1797 opt_property_initializer
1799 current_property = null;
1804 member_declaration_name
1806 lexer.parsing_generic_declaration = false;
1808 tmpComment = Lexer.consume_doc_comment ();
1809 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1813 var type = (FullNamedExpression) $3;
1814 var property = new Property (current_type, type, (Modifiers) $2,
1815 (MemberName) $4, (Attributes) $1);
1817 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1818 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", property.GetSignatureForError ());
1820 property.Get = new Property.GetMethod (property, Modifiers.COMPILER_GENERATED, null, property.Location);
1821 property.Get.Block = (ToplevelBlock) $6;
1823 current_type.AddMember (property);
1825 current_local_parameters = null;
1829 opt_property_initializer
1833 ++lexer.parsing_block;
1834 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1835 start_block (GetLocation ($1));
1837 expression SEMICOLON
1839 --lexer.parsing_block;
1840 ((Property)current_property).Initializer = (Expression) $3;
1841 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($4));
1842 end_block (GetLocation ($4));
1843 current_local_parameters = null;
1848 : opt_attributes opt_modifiers
1849 member_type indexer_declaration_name OPEN_BRACKET
1851 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1853 opt_formal_parameter_list CLOSE_BRACKET
1855 valid_param_mod = 0;
1856 var type = (FullNamedExpression) $3;
1857 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1859 current_property = indexer;
1861 current_type.AddIndexer (indexer);
1862 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1864 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1865 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1867 if (indexer.ParameterInfo.IsEmpty) {
1868 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1872 tmpComment = Lexer.consume_doc_comment ();
1873 Lexer.doc_state = XmlCommentState.Allowed;
1876 lexer.PropertyParsing = true;
1877 current_local_parameters = (ParametersCompiled) $7;
1881 lexer.PropertyParsing = false;
1882 current_local_parameters = null;
1884 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1885 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1888 current_property.DocComment = ConsumeStoredComment ();
1890 current_property = null;
1895 : OPEN_BRACE accessor_declarations CLOSE_BRACE
1897 lbag.AppendToMember (current_property, GetLocation ($1), GetLocation ($3));
1901 current_property.Get = new Indexer.GetIndexerMethod (current_property, Modifiers.COMPILER_GENERATED, current_local_parameters, null, current_property.Location);
1902 current_property.Get.Block = (ToplevelBlock) $1;
1906 accessor_declarations
1907 : get_accessor_declaration
1908 | get_accessor_declaration accessor_declarations
1909 | set_accessor_declaration
1910 | set_accessor_declaration accessor_declarations
1913 if (yyToken == Token.CLOSE_BRACE) {
1914 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1916 if (yyToken == Token.SEMICOLON)
1917 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1919 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1924 get_accessor_declaration
1925 : opt_attributes opt_modifiers GET
1927 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1928 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1931 if (current_property.Get != null) {
1932 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1935 if (current_property is Indexer) {
1936 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1937 (Attributes) $1, GetLocation ($3));
1939 current_property.Get = new Property.GetMethod (current_property,
1940 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1943 current_local_parameters = current_property.Get.ParameterInfo;
1944 lbag.AddMember (current_property.Get, mod_locations);
1945 lexer.PropertyParsing = false;
1950 current_property.Get.Block = (ToplevelBlock) $5;
1952 if (current_container.Kind == MemberKind.Interface) {
1953 report.Error (531, current_property.Get.Block.StartLocation,
1954 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1958 current_local_parameters = null;
1959 lexer.PropertyParsing = true;
1962 if (Lexer.doc_state == XmlCommentState.Error)
1963 Lexer.doc_state = XmlCommentState.NotAllowed;
1967 set_accessor_declaration
1968 : opt_attributes opt_modifiers SET
1970 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1971 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1974 if (current_property.Set != null) {
1975 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1978 if (current_property is Indexer) {
1979 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1980 ParametersCompiled.MergeGenerated (compiler,
1981 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1982 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1984 (Attributes) $1, GetLocation ($3));
1986 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1987 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1988 (Attributes) $1, GetLocation ($3));
1991 current_local_parameters = current_property.Set.ParameterInfo;
1992 lbag.AddMember (current_property.Set, mod_locations);
1993 lexer.PropertyParsing = false;
1998 current_property.Set.Block = (ToplevelBlock) $5;
2000 if (current_container.Kind == MemberKind.Interface) {
2001 report.Error (531, current_property.Set.Block.StartLocation,
2002 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
2006 current_local_parameters = null;
2007 lexer.PropertyParsing = true;
2010 && Lexer.doc_state == XmlCommentState.Error)
2011 Lexer.doc_state = XmlCommentState.NotAllowed;
2024 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
2029 interface_declaration
2036 type_declaration_name
2038 lexer.ConstraintsParsing = true;
2039 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
2040 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
2043 opt_type_parameter_constraints_clauses
2045 lexer.ConstraintsParsing = false;
2048 current_container.SetConstraints ((List<Constraints>) $9);
2051 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
2052 Lexer.doc_state = XmlCommentState.Allowed;
2055 lexer.parsing_modifiers = true;
2057 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
2059 --lexer.parsing_declaration;
2061 Lexer.doc_state = XmlCommentState.Allowed;
2066 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
2068 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
2070 $$ = pop_current_class ();
2072 | opt_attributes opt_modifiers opt_partial INTERFACE error
2074 Error_SyntaxError (yyToken);
2078 opt_interface_member_declarations
2080 | interface_member_declarations
2083 interface_member_declarations
2084 : interface_member_declaration
2086 lexer.parsing_modifiers = true;
2087 lexer.parsing_block = 0;
2089 | interface_member_declarations interface_member_declaration
2091 lexer.parsing_modifiers = true;
2092 lexer.parsing_block = 0;
2096 interface_member_declaration
2097 : constant_declaration
2099 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2103 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
2105 | method_declaration
2106 | property_declaration
2108 | indexer_declaration
2109 | operator_declaration
2111 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2113 | constructor_declaration
2115 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2119 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2123 operator_declaration
2124 : opt_attributes opt_modifiers operator_declarator
2129 OperatorDeclaration decl = (OperatorDeclaration) $3;
2131 Operator op = new Operator (
2132 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2133 current_local_parameters,
2134 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2136 if (op.Block == null)
2137 op.ParameterInfo.CheckParameters (op);
2140 op.DocComment = tmpComment;
2141 Lexer.doc_state = XmlCommentState.Allowed;
2144 // Note again, checking is done in semantic analysis
2145 current_type.AddOperator (op);
2147 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2150 current_local_parameters = null;
2155 : type_expression_or_array
2158 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2159 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2164 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2166 valid_param_mod = ParameterModifierType.DefaultValue;
2168 opt_formal_parameter_list CLOSE_PARENS
2170 valid_param_mod = 0;
2172 Location loc = GetLocation ($2);
2173 Operator.OpType op = (Operator.OpType) $3;
2174 current_local_parameters = (ParametersCompiled)$6;
2176 int p_count = current_local_parameters.Count;
2178 if (op == Operator.OpType.Addition)
2179 op = Operator.OpType.UnaryPlus;
2180 else if (op == Operator.OpType.Subtraction)
2181 op = Operator.OpType.UnaryNegation;
2184 if (IsUnaryOperator (op)) {
2186 report.Error (1020, loc, "Overloadable binary operator expected");
2187 } else if (p_count != 1) {
2188 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2189 Operator.GetName (op));
2193 report.Error (1019, loc, "Overloadable unary operator expected");
2194 } else if (p_count != 2) {
2195 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2196 Operator.GetName (op));
2201 tmpComment = Lexer.consume_doc_comment ();
2202 Lexer.doc_state = XmlCommentState.NotAllowed;
2205 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2206 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2208 | conversion_operator_declarator
2211 overloadable_operator
2213 : BANG { $$ = Operator.OpType.LogicalNot; }
2214 | TILDE { $$ = Operator.OpType.OnesComplement; }
2215 | OP_INC { $$ = Operator.OpType.Increment; }
2216 | OP_DEC { $$ = Operator.OpType.Decrement; }
2217 | TRUE { $$ = Operator.OpType.True; }
2218 | FALSE { $$ = Operator.OpType.False; }
2219 // Unary and binary:
2220 | PLUS { $$ = Operator.OpType.Addition; }
2221 | MINUS { $$ = Operator.OpType.Subtraction; }
2223 | STAR { $$ = Operator.OpType.Multiply; }
2224 | DIV { $$ = Operator.OpType.Division; }
2225 | PERCENT { $$ = Operator.OpType.Modulus; }
2226 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2227 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2228 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2229 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2230 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2231 | OP_EQ { $$ = Operator.OpType.Equality; }
2232 | OP_NE { $$ = Operator.OpType.Inequality; }
2233 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2234 | OP_LT { $$ = Operator.OpType.LessThan; }
2235 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2236 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2239 conversion_operator_declarator
2240 : IMPLICIT OPERATOR type OPEN_PARENS
2242 valid_param_mod = ParameterModifierType.DefaultValue;
2244 opt_formal_parameter_list CLOSE_PARENS
2246 valid_param_mod = 0;
2248 Location loc = GetLocation ($2);
2249 current_local_parameters = (ParametersCompiled)$6;
2251 if (current_local_parameters.Count != 1) {
2252 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2256 tmpComment = Lexer.consume_doc_comment ();
2257 Lexer.doc_state = XmlCommentState.NotAllowed;
2260 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2261 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2263 | EXPLICIT OPERATOR type OPEN_PARENS
2265 valid_param_mod = ParameterModifierType.DefaultValue;
2267 opt_formal_parameter_list CLOSE_PARENS
2269 valid_param_mod = 0;
2271 Location loc = GetLocation ($2);
2272 current_local_parameters = (ParametersCompiled)$6;
2274 if (current_local_parameters.Count != 1) {
2275 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2279 tmpComment = Lexer.consume_doc_comment ();
2280 Lexer.doc_state = XmlCommentState.NotAllowed;
2283 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2284 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2288 Error_SyntaxError (yyToken);
2289 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2290 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2294 Error_SyntaxError (yyToken);
2295 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2296 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2300 constructor_declaration
2301 : constructor_declarator
2304 Constructor c = (Constructor) $1;
2305 c.Block = (ToplevelBlock) $2;
2308 c.DocComment = ConsumeStoredComment ();
2310 current_local_parameters = null;
2312 Lexer.doc_state = XmlCommentState.Allowed;
2316 constructor_declarator
2322 tmpComment = Lexer.consume_doc_comment ();
2323 Lexer.doc_state = XmlCommentState.Allowed;
2326 valid_param_mod = ParameterModifierType.All;
2328 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2330 valid_param_mod = 0;
2331 current_local_parameters = (ParametersCompiled) $6;
2333 var lt = (LocatedToken) $3;
2334 var mods = (Modifiers) $2;
2335 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2337 if (lt.Value != current_container.MemberName.Name) {
2338 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2339 } else if ((mods & Modifiers.STATIC) != 0) {
2340 if ((mods & Modifiers.AccessibilityMask) != 0){
2341 report.Error (515, c.Location,
2342 "`{0}': static constructor cannot have an access modifier",
2343 c.GetSignatureForError ());
2347 current_type.AddConstructor (c);
2348 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2352 // start block here, so possible anonymous methods inside
2353 // constructor initializer can get correct parent block
2355 start_block (lexer.Location);
2357 opt_constructor_initializer
2360 var c = (Constructor) $8;
2361 c.Initializer = (ConstructorInitializer) $9;
2364 report.Error (514, c.Location,
2365 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2366 c.GetSignatureForError ());
2376 | SEMICOLON { current_block = null; $$ = null; }
2379 opt_constructor_initializer
2381 | constructor_initializer
2384 constructor_initializer
2385 : COLON BASE OPEN_PARENS
2387 ++lexer.parsing_block;
2389 opt_argument_list CLOSE_PARENS
2391 --lexer.parsing_block;
2392 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2393 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2395 | COLON THIS OPEN_PARENS
2397 ++lexer.parsing_block;
2399 opt_argument_list CLOSE_PARENS
2401 --lexer.parsing_block;
2402 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2403 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2407 Error_SyntaxError (yyToken);
2408 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2409 lbag.AddLocation ($$, GetLocation ($1));
2413 Error_SyntaxError (yyToken);
2418 destructor_declaration
2419 : opt_attributes opt_modifiers TILDE
2422 tmpComment = Lexer.consume_doc_comment ();
2423 Lexer.doc_state = XmlCommentState.NotAllowed;
2426 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2428 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2430 var lt = (LocatedToken) $5;
2431 if (lt.Value != current_container.MemberName.Name){
2432 report.Error (574, lt.Location, "Name of destructor must match name of class");
2433 } else if (current_container.Kind != MemberKind.Class){
2434 report.Error (575, lt.Location, "Only class types can contain destructor");
2437 Destructor d = new Destructor (current_type, (Modifiers) $2,
2438 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2440 d.DocComment = ConsumeStoredComment ();
2442 d.Block = (ToplevelBlock) $8;
2443 current_type.AddMember (d);
2444 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2446 current_local_parameters = null;
2453 EVENT type member_declaration_name
2455 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2456 current_type.AddMember (current_event_field);
2458 if (current_event_field.MemberName.ExplicitInterface != null) {
2459 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2460 current_event_field.GetSignatureForError ());
2463 $$ = current_event_field;
2465 opt_event_initializer
2466 opt_event_declarators
2470 current_event_field.DocComment = Lexer.consume_doc_comment ();
2471 Lexer.doc_state = XmlCommentState.Allowed;
2474 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2475 current_event_field = null;
2479 EVENT type member_declaration_name
2482 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2483 current_type.AddMember (current_event);
2484 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2486 lexer.EventParsing = true;
2488 event_accessor_declarations
2490 if (current_container.Kind == MemberKind.Interface)
2491 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2493 lexer.EventParsing = false;
2498 current_event.DocComment = Lexer.consume_doc_comment ();
2499 Lexer.doc_state = XmlCommentState.Allowed;
2502 lbag.AppendToMember (current_event, GetLocation ($9));
2503 current_event = null;
2504 current_local_parameters = null;
2510 Error_SyntaxError (yyToken);
2512 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2516 opt_event_initializer
2520 ++lexer.parsing_block;
2522 event_variable_initializer
2524 --lexer.parsing_block;
2525 current_event_field.Initializer = (Expression) $3;
2529 opt_event_declarators
2537 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2539 | event_declarators event_declarator
2541 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2548 var lt = (LocatedToken) $2;
2549 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2550 lbag.AddLocation ($$, GetLocation ($1));
2552 | COMMA IDENTIFIER ASSIGN
2554 ++lexer.parsing_block;
2556 event_variable_initializer
2558 --lexer.parsing_block;
2559 var lt = (LocatedToken) $2;
2560 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2561 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2565 event_variable_initializer
2567 if (current_container.Kind == MemberKind.Interface) {
2568 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2569 current_event_field.GetSignatureForError ());
2572 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2573 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2574 current_event_field.GetSignatureForError ());
2577 variable_initializer
2583 event_accessor_declarations
2584 : add_accessor_declaration remove_accessor_declaration
2585 | remove_accessor_declaration add_accessor_declaration
2586 | add_accessor_declaration
2588 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2589 current_event.GetSignatureForError ());
2591 | remove_accessor_declaration
2593 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2594 current_event.GetSignatureForError ());
2598 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2603 add_accessor_declaration
2604 : opt_attributes opt_modifiers ADD
2606 if ($2 != ModifierNone) {
2607 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2610 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2611 current_local_parameters = current_event.Add.ParameterInfo;
2613 lbag.AddMember (current_event.Add, mod_locations);
2614 lexer.EventParsing = false;
2616 event_accessor_block
2618 lexer.EventParsing = true;
2620 current_event.Add.Block = (ToplevelBlock) $5;
2622 if (current_container.Kind == MemberKind.Interface) {
2623 report.Error (531, current_event.Add.Block.StartLocation,
2624 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2627 current_local_parameters = null;
2631 remove_accessor_declaration
2632 : opt_attributes opt_modifiers REMOVE
2634 if ($2 != ModifierNone) {
2635 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2638 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2639 current_local_parameters = current_event.Remove.ParameterInfo;
2641 lbag.AddMember (current_event.Remove, mod_locations);
2642 lexer.EventParsing = false;
2644 event_accessor_block
2646 lexer.EventParsing = true;
2648 current_event.Remove.Block = (ToplevelBlock) $5;
2650 if (current_container.Kind == MemberKind.Interface) {
2651 report.Error (531, current_event.Remove.Block.StartLocation,
2652 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2655 current_local_parameters = null;
2659 event_accessor_block
2662 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2668 attributes_without_members
2669 : attribute_sections CLOSE_BRACE
2671 current_type.UnattachedAttributes = (Attributes) $1;
2672 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2673 lexer.putback ('}');
2677 // For full ast try to recover incomplete ambiguous member
2678 // declaration in form on class X { public int }
2680 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2682 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2684 lexer.putback ('}');
2686 lexer.parsing_generic_declaration = false;
2687 FullNamedExpression type = (FullNamedExpression) $3;
2688 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2689 current_type.AddField (current_field);
2697 ENUM type_declaration_name
2701 enumTypeComment = Lexer.consume_doc_comment ();
2706 Lexer.doc_state = XmlCommentState.Allowed;
2708 MemberName name = (MemberName) $4;
2709 if (name.IsGeneric) {
2710 report.Error (1675, name.Location, "Enums cannot have type parameters");
2713 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2715 opt_enum_member_declarations
2717 lexer.parsing_modifiers = true;
2719 // here will be evaluated after CLOSE_BLACE is consumed.
2721 Lexer.doc_state = XmlCommentState.Allowed;
2723 CLOSE_BRACE opt_semicolon
2726 current_container.DocComment = enumTypeComment;
2728 --lexer.parsing_declaration;
2731 // em.DocComment = ev.DocComment;
2733 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2734 $$ = pop_current_class ();
2742 var te = $2 as TypeExpression;
2743 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2744 Enum.Error_1008 (GetLocation ($2), report);
2750 Error_TypeExpected (GetLocation ($1));
2755 opt_enum_member_declarations
2757 | enum_member_declarations
2758 | enum_member_declarations COMMA
2760 lbag.AddLocation ($1, GetLocation ($2));
2764 enum_member_declarations
2765 : enum_member_declaration
2766 | enum_member_declarations COMMA enum_member_declaration
2768 lbag.AddLocation ($1, GetLocation ($2));
2773 enum_member_declaration
2774 : opt_attributes IDENTIFIER
2776 var lt = (LocatedToken) $2;
2777 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2778 ((Enum) current_type).AddEnumMember (em);
2781 em.DocComment = Lexer.consume_doc_comment ();
2782 Lexer.doc_state = XmlCommentState.Allowed;
2787 | opt_attributes IDENTIFIER
2789 ++lexer.parsing_block;
2791 tmpComment = Lexer.consume_doc_comment ();
2792 Lexer.doc_state = XmlCommentState.NotAllowed;
2795 ASSIGN constant_expression
2797 --lexer.parsing_block;
2799 var lt = (LocatedToken) $2;
2800 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2801 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2802 ((Enum) current_type).AddEnumMember (em);
2805 em.DocComment = ConsumeStoredComment ();
2809 | opt_attributes IDENTIFIER error
2811 Error_SyntaxError (yyToken);
2813 var lt = (LocatedToken) $2;
2814 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2815 ((Enum) current_type).AddEnumMember (em);
2818 em.DocComment = Lexer.consume_doc_comment ();
2819 Lexer.doc_state = XmlCommentState.Allowed;
2824 | attributes_without_members
2827 delegate_declaration
2831 member_type type_declaration_name
2834 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2836 opt_formal_parameter_list CLOSE_PARENS
2838 valid_param_mod = 0;
2840 ParametersCompiled p = (ParametersCompiled) $8;
2842 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2844 p.CheckParameters (del);
2846 current_container.AddTypeContainer (del);
2848 current_delegate = del;
2849 lexer.ConstraintsParsing = true;
2851 opt_type_parameter_constraints_clauses
2853 lexer.ConstraintsParsing = false;
2858 current_delegate.DocComment = Lexer.consume_doc_comment ();
2859 Lexer.doc_state = XmlCommentState.Allowed;
2863 current_delegate.SetConstraints ((List<Constraints>) $11);
2864 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2866 $$ = current_delegate;
2868 current_delegate = null;
2876 if (lang_version < LanguageVersion.ISO_2)
2877 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2879 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2883 namespace_or_type_expr
2885 | qualified_alias_member IDENTIFIER opt_type_argument_list
2887 var lt1 = (LocatedToken) $1;
2888 var lt2 = (LocatedToken) $2;
2890 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2891 lbag.AddLocation ($$, GetLocation ($2));
2897 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2899 var lt = (LocatedToken) $3;
2900 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2901 lbag.AddLocation ($$, GetLocation ($2));
2906 : IDENTIFIER opt_type_argument_list
2908 var lt = (LocatedToken) $1;
2909 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2914 // Generics arguments (any type, without attributes)
2916 opt_type_argument_list
2918 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2920 if (lang_version < LanguageVersion.ISO_2)
2921 FeatureIsNotAvailable (GetLocation ($1), "generics");
2925 | OP_GENERICS_LT error
2927 Error_TypeExpected (lexer.Location);
2928 $$ = new TypeArguments ();
2935 TypeArguments type_args = new TypeArguments ();
2936 type_args.Add ((FullNamedExpression) $1);
2939 | type_arguments COMMA type
2941 TypeArguments type_args = (TypeArguments) $1;
2942 type_args.Add ((FullNamedExpression) $3);
2948 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2950 type_declaration_name
2953 lexer.parsing_generic_declaration = true;
2955 opt_type_parameter_list
2957 lexer.parsing_generic_declaration = false;
2958 var lt = (LocatedToken) $1;
2959 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2963 member_declaration_name
2964 : method_declaration_name
2966 MemberName mn = (MemberName)$1;
2967 if (mn.TypeParameters != null)
2968 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2969 mn.GetSignatureForError ()));
2973 method_declaration_name
2974 : type_declaration_name
2975 | explicit_interface IDENTIFIER opt_type_parameter_list
2977 lexer.parsing_generic_declaration = false;
2978 var lt = (LocatedToken) $2;
2979 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2983 indexer_declaration_name
2986 lexer.parsing_generic_declaration = false;
2987 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2989 | explicit_interface THIS
2991 lexer.parsing_generic_declaration = false;
2992 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2997 : IDENTIFIER opt_type_argument_list DOT
2999 var lt = (LocatedToken) $1;
3000 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
3001 lbag.AddLocation ($$, GetLocation ($3));
3003 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
3005 var lt1 = (LocatedToken) $1;
3006 var lt2 = (LocatedToken) $2;
3008 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3009 lbag.AddLocation ($$, GetLocation ($4));
3011 | explicit_interface IDENTIFIER opt_type_argument_list DOT
3013 var lt = (LocatedToken) $2;
3014 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
3015 lbag.AddLocation ($$, GetLocation ($4));
3019 opt_type_parameter_list
3021 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
3023 if (lang_version < LanguageVersion.ISO_2)
3024 FeatureIsNotAvailable (GetLocation ($1), "generics");
3027 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3034 var tparams = new TypeParameters ();
3035 tparams.Add ((TypeParameter)$1);
3038 | type_parameters COMMA type_parameter
3040 var tparams = (TypeParameters) $1;
3041 tparams.Add ((TypeParameter)$3);
3043 lbag.AddLocation ($3, GetLocation ($3));
3048 : opt_attributes opt_type_parameter_variance IDENTIFIER
3050 var lt = (LocatedToken)$3;
3051 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
3055 if (GetTokenName (yyToken) == "type")
3056 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
3058 Error_SyntaxError (yyToken);
3060 $$ = new TypeParameter (MemberName.Null, null, null);
3065 // All types where void is allowed
3068 : type_expression_or_array
3071 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3078 lexer.parsing_generic_declaration = true;
3083 // A type which does not allow `void' to be used
3086 : type_expression_or_array
3089 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3090 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3098 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
3099 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3104 : type_expression_or_array
3107 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3108 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3112 type_expression_or_array
3114 | type_expression rank_specifiers
3116 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3121 : namespace_or_type_expr opt_nullable
3124 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3126 var sn = $1 as SimpleName;
3127 if (sn != null && sn.Name == "var")
3128 $$ = new VarExpr (sn.Location);
3133 | namespace_or_type_expr pointer_stars
3135 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3137 | builtin_types opt_nullable
3140 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3142 | builtin_types pointer_stars
3144 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3146 | VOID pointer_stars
3148 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3155 var types = new List<FullNamedExpression> (2);
3156 types.Add ((FullNamedExpression) $1);
3159 | type_list COMMA base_type_name
3161 var types = (List<FullNamedExpression>) $1;
3162 types.Add ((FullNamedExpression) $3);
3170 if ($1 is ComposedCast) {
3171 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3178 * replaces all the productions for isolating the various
3179 * simple types, but we need this to reuse it easily in variable_type
3182 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3183 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3184 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3185 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3186 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3187 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3192 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3193 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3194 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3195 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3196 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3197 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3198 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3199 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3200 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3204 // Expressions, section 7.5
3209 : primary_expression_or_type
3211 | array_creation_expression
3212 | parenthesized_expression
3213 | default_value_expression
3214 | invocation_expression
3218 | post_increment_expression
3219 | post_decrement_expression
3220 | object_or_delegate_creation_expression
3221 | anonymous_type_expression
3224 | checked_expression
3225 | unchecked_expression
3226 | pointer_member_access
3227 | anonymous_method_expression
3228 | undocumented_expressions
3231 primary_expression_or_type
3232 : IDENTIFIER opt_type_argument_list
3234 var lt = (LocatedToken) $1;
3235 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3237 | IDENTIFIER GENERATE_COMPLETION {
3238 var lt = (LocatedToken) $1;
3239 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3247 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3251 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3252 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3257 // Here is the trick, tokenizer may think that parens is a special but
3258 // parser is interested in open parens only, so we merge them.
3259 // Consider: if (a)foo ();
3267 // Use this production to accept closing parenthesis or
3268 // performing completion
3272 | COMPLETE_COMPLETION
3276 parenthesized_expression
3277 : OPEN_PARENS expression CLOSE_PARENS
3279 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3280 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3282 | OPEN_PARENS expression COMPLETE_COMPLETION
3284 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3289 : primary_expression DOT identifier_inside_body opt_type_argument_list
3291 var lt = (LocatedToken) $3;
3292 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3293 lbag.AddLocation ($$, GetLocation ($2));
3295 | builtin_types DOT identifier_inside_body opt_type_argument_list
3297 var lt = (LocatedToken) $3;
3298 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3299 lbag.AddLocation ($$, GetLocation ($2));
3301 | BASE DOT identifier_inside_body opt_type_argument_list
3303 var lt = (LocatedToken) $3;
3304 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3305 lbag.AddLocation ($$, GetLocation ($2));
3307 | AWAIT DOT identifier_inside_body opt_type_argument_list
3309 var lt = (LocatedToken) $3;
3310 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3311 lbag.AddLocation ($$, GetLocation ($2));
3313 | qualified_alias_member identifier_inside_body opt_type_argument_list
3315 var lt1 = (LocatedToken) $1;
3316 var lt2 = (LocatedToken) $2;
3318 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3319 lbag.AddLocation ($$, GetLocation ($2));
3321 | primary_expression DOT GENERATE_COMPLETION {
3322 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3324 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3325 var lt = (LocatedToken) $3;
3326 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3328 | builtin_types DOT GENERATE_COMPLETION
3330 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3332 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3333 var lt = (LocatedToken) $3;
3334 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3338 invocation_expression
3339 : primary_expression open_parens_any opt_argument_list close_parens
3341 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3342 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3344 | primary_expression open_parens_any argument_list error
3346 Error_SyntaxError (yyToken);
3348 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3349 lbag.AddLocation ($$, GetLocation ($2));
3351 | primary_expression open_parens_any error
3353 Error_SyntaxError (yyToken);
3355 $$ = new Invocation ((Expression) $1, null);
3356 lbag.AddLocation ($$, GetLocation ($2));
3360 opt_object_or_collection_initializer
3361 : /* empty */ { $$ = null; }
3362 | object_or_collection_initializer
3365 object_or_collection_initializer
3366 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3369 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3371 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3373 lbag.AddLocation ($$, GetLocation ($3));
3375 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3377 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3378 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3382 opt_member_initializer_list
3383 : /* empty */ { $$ = null; }
3384 | member_initializer_list
3390 member_initializer_list
3391 : member_initializer
3393 var a = new List<Expression> ();
3394 a.Add ((Expression) $1);
3397 | member_initializer_list COMMA member_initializer
3399 var a = (List<Expression>)$1;
3400 a.Add ((Expression) $3);
3403 | member_initializer_list error {
3404 Error_SyntaxError (yyToken);
3410 : IDENTIFIER ASSIGN initializer_value
3412 var lt = (LocatedToken) $1;
3413 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3414 lbag.AddLocation ($$, GetLocation ($2));
3416 | AWAIT ASSIGN initializer_value
3418 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3419 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3420 lbag.AddLocation ($$, GetLocation ($2));
3422 | GENERATE_COMPLETION
3424 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3426 | non_assignment_expression opt_COMPLETE_COMPLETION {
3427 CompletionSimpleName csn = $1 as CompletionSimpleName;
3429 $$ = new CollectionElementInitializer ((Expression)$1);
3431 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3433 | OPEN_BRACE expression_list CLOSE_BRACE
3436 $$ = new CollectionElementInitializer (GetLocation ($1));
3438 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3440 lbag.AddLocation ($$, GetLocation ($2));
3442 | OPEN_BRACE CLOSE_BRACE
3444 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3445 $$ = new CollectionElementInitializer (GetLocation ($1));
3446 lbag.AddLocation ($$, GetLocation ($2));
3452 | object_or_collection_initializer
3456 : /* empty */ { $$ = null; }
3461 : argument_or_named_argument
3463 Arguments list = new Arguments (4);
3464 list.Add ((Argument) $1);
3467 | argument_list COMMA argument
3469 Arguments list = (Arguments) $1;
3470 if (list [list.Count - 1] is NamedArgument)
3471 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3473 list.Add ((Argument) $3);
3476 | argument_list COMMA named_argument
3478 Arguments list = (Arguments) $1;
3479 NamedArgument a = (NamedArgument) $3;
3480 for (int i = 0; i < list.Count; ++i) {
3481 NamedArgument na = list [i] as NamedArgument;
3482 if (na != null && na.Name == a.Name)
3483 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3490 | argument_list COMMA error
3492 if (lexer.putback_char == -1)
3493 lexer.putback (')'); // TODO: Wrong but what can I do
3494 Error_SyntaxError (yyToken);
3499 report.Error (839, GetLocation ($1), "An argument is missing");
3507 $$ = new Argument ((Expression) $1);
3509 | non_simple_argument
3512 argument_or_named_argument
3518 : REF variable_reference
3520 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3521 lbag.AddLocation ($$, GetLocation ($1));
3523 | OUT variable_reference
3525 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3526 lbag.AddLocation ($$, GetLocation ($1));
3528 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3530 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3531 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3533 | ARGLIST OPEN_PARENS CLOSE_PARENS
3535 $$ = new Argument (new Arglist (GetLocation ($1)));
3536 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3545 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3547 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3548 lbag.AddLocation ($$, GetLocation ($4));
3550 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3552 Error_SyntaxError (yyToken);
3553 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3555 | primary_expression OPEN_BRACKET_EXPR error
3557 Error_SyntaxError (yyToken);
3558 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3563 : expression_or_error
3565 var list = new List<Expression> (4);
3566 list.Add ((Expression) $1);
3569 | expression_list COMMA expression_or_error
3571 var list = (List<Expression>) $1;
3572 list.Add ((Expression) $3);
3577 expression_list_arguments
3578 : expression_list_argument
3580 Arguments args = new Arguments (4);
3581 args.Add ((Argument) $1);
3584 | expression_list_arguments COMMA expression_list_argument
3586 Arguments args = (Arguments) $1;
3587 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3588 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3590 args.Add ((Argument) $3);
3595 expression_list_argument
3598 $$ = new Argument ((Expression) $1);
3606 $$ = new This (GetLocation ($1));
3611 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3613 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3614 lbag.AddLocation ($$, GetLocation ($4));
3616 | BASE OPEN_BRACKET error
3618 Error_SyntaxError (yyToken);
3619 $$ = new ElementAccess (null, null, GetLocation ($2));
3623 post_increment_expression
3624 : primary_expression OP_INC
3626 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3630 post_decrement_expression
3631 : primary_expression OP_DEC
3633 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3637 object_or_delegate_creation_expression
3638 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3641 if (lang_version <= LanguageVersion.ISO_2)
3642 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3644 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3646 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3649 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3651 | NEW new_expr_type object_or_collection_initializer
3653 if (lang_version <= LanguageVersion.ISO_2)
3654 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3656 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3660 array_creation_expression
3661 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3663 opt_array_initializer
3665 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3666 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3667 Next = (ComposedTypeSpecifier) $6
3668 }, (ArrayInitializer) $7, GetLocation ($1));
3669 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3671 | NEW new_expr_type rank_specifiers opt_array_initializer
3674 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3676 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3678 | NEW rank_specifier array_initializer
3680 if (lang_version <= LanguageVersion.ISO_2)
3681 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3683 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3685 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3687 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3688 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3690 | NEW new_expr_type error
3692 Error_SyntaxError (yyToken);
3693 // It can be any of new expression, create the most common one
3694 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3700 ++lexer.parsing_type;
3704 --lexer.parsing_type;
3709 anonymous_type_expression
3710 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3712 if (lang_version <= LanguageVersion.ISO_2)
3713 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3715 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3717 // TODO: lbag comma location
3718 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3720 | NEW OPEN_BRACE GENERATE_COMPLETION
3722 $$ = new EmptyCompletion ();
3726 anonymous_type_parameters_opt_comma
3727 : anonymous_type_parameters_opt
3728 | anonymous_type_parameters COMMA
3731 anonymous_type_parameters_opt
3733 | anonymous_type_parameters
3736 anonymous_type_parameters
3737 : anonymous_type_parameter
3739 var a = new List<AnonymousTypeParameter> (4);
3740 a.Add ((AnonymousTypeParameter) $1);
3743 | anonymous_type_parameters COMMA anonymous_type_parameter
3745 var a = (List<AnonymousTypeParameter>) $1;
3746 a.Add ((AnonymousTypeParameter) $3);
3749 | COMPLETE_COMPLETION
3751 $$ = new EmptyCompletion ();
3753 | anonymous_type_parameter COMPLETE_COMPLETION
3759 anonymous_type_parameter
3760 : identifier_inside_body ASSIGN variable_initializer
3762 var lt = (LocatedToken)$1;
3763 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3764 lbag.AddLocation ($$, GetLocation ($2));
3766 | identifier_inside_body
3768 var lt = (LocatedToken)$1;
3769 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3770 lt.Value, lt.Location);
3774 MemberAccess ma = (MemberAccess) $1;
3775 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3779 report.Error (746, lexer.Location,
3780 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3792 | rank_specifier rank_specifiers
3794 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3800 : OPEN_BRACKET CLOSE_BRACKET
3802 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3803 lbag.AddLocation ($$, GetLocation ($2));
3805 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3807 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3808 lbag.AddLocation ($$, GetLocation ($3));
3817 | dim_separators COMMA
3819 $$ = ((int) $1) + 1;
3823 opt_array_initializer
3835 : OPEN_BRACE CLOSE_BRACE
3837 var ai = new ArrayInitializer (0, GetLocation ($1));
3838 ai.VariableDeclaration = current_variable;
3839 lbag.AddLocation (ai, GetLocation ($2));
3842 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3844 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3845 ai.VariableDeclaration = current_variable;
3847 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3849 lbag.AddLocation (ai, GetLocation ($4));
3855 variable_initializer_list
3856 : variable_initializer
3858 var list = new List<Expression> (4);
3859 list.Add ((Expression) $1);
3862 | variable_initializer_list COMMA variable_initializer
3864 var list = (List<Expression>) $1;
3865 list.Add ((Expression) $3);
3873 lexer.TypeOfParsing = true;
3875 open_parens_any typeof_type_expression CLOSE_PARENS
3877 lexer.TypeOfParsing = false;
3878 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3879 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3883 typeof_type_expression
3888 Error_TypeExpected (lexer.Location);
3894 : identifier_inside_body generic_dimension
3896 var lt = (LocatedToken) $1;
3898 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3900 | qualified_alias_member identifier_inside_body generic_dimension
3902 var lt1 = (LocatedToken) $1;
3903 var lt2 = (LocatedToken) $2;
3905 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3906 lbag.AddLocation ($$, GetLocation ($2));
3908 | unbound_type_name DOT identifier_inside_body
3910 var lt = (LocatedToken) $3;
3912 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3914 | unbound_type_name DOT identifier_inside_body generic_dimension
3916 var lt = (LocatedToken) $3;
3918 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3920 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3922 var tne = (ATypeNameExpression) $1;
3923 if (tne.HasTypeArguments)
3924 Error_TypeExpected (GetLocation ($4));
3926 var lt = (LocatedToken) $3;
3927 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3934 if (lang_version < LanguageVersion.ISO_2)
3935 FeatureIsNotAvailable (GetLocation ($1), "generics");
3941 qualified_alias_member
3942 : IDENTIFIER DOUBLE_COLON
3944 var lt = (LocatedToken) $1;
3945 if (lang_version == LanguageVersion.ISO_1)
3946 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3953 : SIZEOF open_parens_any type CLOSE_PARENS
3955 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3956 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3958 | SIZEOF open_parens_any type error
3960 Error_SyntaxError (yyToken);
3962 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3963 lbag.AddLocation ($$, GetLocation ($2));
3968 : CHECKED open_parens_any expression CLOSE_PARENS
3970 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3971 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3975 Error_SyntaxError (yyToken);
3977 $$ = new CheckedExpr (null, GetLocation ($1));
3981 unchecked_expression
3982 : UNCHECKED open_parens_any expression CLOSE_PARENS
3984 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3985 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3989 Error_SyntaxError (yyToken);
3991 $$ = new UnCheckedExpr (null, GetLocation ($1));
3995 pointer_member_access
3996 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3998 var lt = (LocatedToken) $3;
3999 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
4003 anonymous_method_expression
4004 : DELEGATE opt_anonymous_method_signature
4006 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
4010 $$ = end_anonymous ((ParametersBlock) $4);
4012 | ASYNC DELEGATE opt_anonymous_method_signature
4014 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
4018 $$ = end_anonymous ((ParametersBlock) $5);
4022 opt_anonymous_method_signature
4025 $$ = ParametersCompiled.Undefined;
4027 | anonymous_method_signature
4030 anonymous_method_signature
4033 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4035 opt_formal_parameter_list CLOSE_PARENS
4037 valid_param_mod = 0;
4042 default_value_expression
4043 : DEFAULT open_parens_any type CLOSE_PARENS
4045 if (lang_version < LanguageVersion.ISO_2)
4046 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
4048 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
4049 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4054 : primary_expression
4055 | BANG prefixed_unary_expression
4057 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
4059 | TILDE prefixed_unary_expression
4061 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
4063 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
4065 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
4066 lbag.AddLocation ($$, GetLocation ($3));
4068 | AWAIT prefixed_unary_expression
4071 if (current_anonymous_method is LambdaExpression) {
4072 report.Error (4034, GetLocation ($1),
4073 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
4074 } else if (current_anonymous_method != null) {
4075 report.Error (4035, GetLocation ($1),
4076 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
4077 } else if (interactive_async != null) {
4078 current_block.Explicit.RegisterAsyncAwait ();
4079 interactive_async = true;
4081 report.Error (4033, GetLocation ($1),
4082 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
4085 current_block.Explicit.RegisterAsyncAwait ();
4088 $$ = new Await ((Expression) $2, GetLocation ($1));
4092 Error_SyntaxError (yyToken);
4094 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
4098 Error_SyntaxError (yyToken);
4100 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4102 | OPEN_PARENS_CAST type CLOSE_PARENS error
4104 Error_SyntaxError (yyToken);
4106 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4107 lbag.AddLocation ($$, GetLocation ($3));
4111 Error_SyntaxError (yyToken);
4113 $$ = new Await (null, GetLocation ($1));
4118 // The idea to split this out is from Rhys' grammar
4119 // to solve the problem with casts.
4121 prefixed_unary_expression
4123 | PLUS prefixed_unary_expression
4125 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4127 | MINUS prefixed_unary_expression
4129 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4131 | OP_INC prefixed_unary_expression
4133 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4135 | OP_DEC prefixed_unary_expression
4137 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4139 | STAR prefixed_unary_expression
4141 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4143 | BITWISE_AND prefixed_unary_expression
4145 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4149 Error_SyntaxError (yyToken);
4151 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4155 Error_SyntaxError (yyToken);
4157 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4161 Error_SyntaxError (yyToken);
4163 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4167 Error_SyntaxError (yyToken);
4169 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4173 Error_SyntaxError (yyToken);
4175 $$ = new Indirection (null, GetLocation ($1));
4179 Error_SyntaxError (yyToken);
4181 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4185 multiplicative_expression
4186 : prefixed_unary_expression
4187 | multiplicative_expression STAR prefixed_unary_expression
4189 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4190 lbag.AddLocation ($$, GetLocation ($2));
4192 | multiplicative_expression DIV prefixed_unary_expression
4194 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4195 lbag.AddLocation ($$, GetLocation ($2));
4197 | multiplicative_expression PERCENT prefixed_unary_expression
4199 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4200 lbag.AddLocation ($$, GetLocation ($2));
4202 | multiplicative_expression STAR error
4204 Error_SyntaxError (yyToken);
4206 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4207 lbag.AddLocation ($$, GetLocation ($2));
4209 | multiplicative_expression DIV error
4211 Error_SyntaxError (yyToken);
4213 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4214 lbag.AddLocation ($$, GetLocation ($2));
4216 | multiplicative_expression PERCENT error
4218 Error_SyntaxError (yyToken);
4220 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4221 lbag.AddLocation ($$, GetLocation ($2));
4226 : multiplicative_expression
4227 | additive_expression PLUS multiplicative_expression
4229 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4230 lbag.AddLocation ($$, GetLocation ($2));
4232 | additive_expression MINUS multiplicative_expression
4234 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4235 lbag.AddLocation ($$, GetLocation ($2));
4237 | additive_expression AS type
4239 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4241 | additive_expression IS type
4243 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4245 | additive_expression PLUS error
4247 Error_SyntaxError (yyToken);
4249 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4250 lbag.AddLocation ($$, GetLocation ($2));
4252 | additive_expression MINUS error
4254 Error_SyntaxError (yyToken);
4256 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4257 lbag.AddLocation ($$, GetLocation ($2));
4259 | additive_expression AS error
4261 Error_SyntaxError (yyToken);
4263 $$ = new As ((Expression) $1, null, GetLocation ($2));
4265 | additive_expression IS error
4267 Error_SyntaxError (yyToken);
4269 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4273 var lt = (LocatedToken) $1;
4274 $$ = new Is (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4278 var lt = (LocatedToken) $1;
4279 $$ = new As (new SimpleName (lt.Value, lt.Location), (Expression) $3, GetLocation ($2));
4284 : additive_expression
4285 | shift_expression OP_SHIFT_LEFT additive_expression
4287 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4288 lbag.AddLocation ($$, GetLocation ($2));
4290 | shift_expression OP_SHIFT_RIGHT additive_expression
4292 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4293 lbag.AddLocation ($$, GetLocation ($2));
4295 | shift_expression OP_SHIFT_LEFT error
4297 Error_SyntaxError (yyToken);
4299 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4300 lbag.AddLocation ($$, GetLocation ($2));
4302 | shift_expression OP_SHIFT_RIGHT error
4304 Error_SyntaxError (yyToken);
4306 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4307 lbag.AddLocation ($$, GetLocation ($2));
4311 relational_expression
4313 | relational_expression OP_LT shift_expression
4315 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4316 lbag.AddLocation ($$, GetLocation ($2));
4318 | relational_expression OP_GT shift_expression
4320 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4321 lbag.AddLocation ($$, GetLocation ($2));
4323 | relational_expression OP_LE shift_expression
4325 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4326 lbag.AddLocation ($$, GetLocation ($2));
4328 | relational_expression OP_GE shift_expression
4330 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4331 lbag.AddLocation ($$, GetLocation ($2));
4333 | relational_expression OP_LT error
4335 Error_SyntaxError (yyToken);
4337 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4338 lbag.AddLocation ($$, GetLocation ($2));
4340 | relational_expression OP_GT error
4342 Error_SyntaxError (yyToken);
4344 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4345 lbag.AddLocation ($$, GetLocation ($2));
4347 | relational_expression OP_LE error
4349 Error_SyntaxError (yyToken);
4351 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4352 lbag.AddLocation ($$, GetLocation ($2));
4354 | relational_expression OP_GE error
4356 Error_SyntaxError (yyToken);
4358 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4359 lbag.AddLocation ($$, GetLocation ($2));
4364 : relational_expression
4365 | equality_expression OP_EQ relational_expression
4367 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4368 lbag.AddLocation ($$, GetLocation ($2));
4370 | equality_expression OP_NE relational_expression
4372 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4373 lbag.AddLocation ($$, GetLocation ($2));
4375 | equality_expression OP_EQ error
4377 Error_SyntaxError (yyToken);
4379 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4380 lbag.AddLocation ($$, GetLocation ($2));
4382 | equality_expression OP_NE error
4384 Error_SyntaxError (yyToken);
4386 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4387 lbag.AddLocation ($$, GetLocation ($2));
4392 : equality_expression
4393 | and_expression BITWISE_AND equality_expression
4395 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4396 lbag.AddLocation ($$, GetLocation ($2));
4398 | and_expression BITWISE_AND error
4400 Error_SyntaxError (yyToken);
4402 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4403 lbag.AddLocation ($$, GetLocation ($2));
4407 exclusive_or_expression
4409 | exclusive_or_expression CARRET and_expression
4411 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4412 lbag.AddLocation ($$, GetLocation ($2));
4414 | exclusive_or_expression CARRET error
4416 Error_SyntaxError (yyToken);
4418 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4419 lbag.AddLocation ($$, GetLocation ($2));
4423 inclusive_or_expression
4424 : exclusive_or_expression
4425 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4427 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4428 lbag.AddLocation ($$, GetLocation ($2));
4430 | inclusive_or_expression BITWISE_OR error
4432 Error_SyntaxError (yyToken);
4434 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4435 lbag.AddLocation ($$, GetLocation ($2));
4439 conditional_and_expression
4440 : inclusive_or_expression
4441 | conditional_and_expression OP_AND inclusive_or_expression
4443 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4444 lbag.AddLocation ($$, GetLocation ($2));
4446 | conditional_and_expression OP_AND error
4448 Error_SyntaxError (yyToken);
4450 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4451 lbag.AddLocation ($$, GetLocation ($2));
4455 conditional_or_expression
4456 : conditional_and_expression
4457 | conditional_or_expression OP_OR conditional_and_expression
4459 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4460 lbag.AddLocation ($$, GetLocation ($2));
4462 | conditional_or_expression OP_OR error
4464 Error_SyntaxError (yyToken);
4466 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4467 lbag.AddLocation ($$, GetLocation ($2));
4471 null_coalescing_expression
4472 : conditional_or_expression
4473 | conditional_or_expression OP_COALESCING null_coalescing_expression
4475 if (lang_version < LanguageVersion.ISO_2)
4476 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4478 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4479 lbag.AddLocation ($$, GetLocation ($2));
4483 conditional_expression
4484 : null_coalescing_expression
4485 | null_coalescing_expression INTERR expression COLON expression
4487 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4488 lbag.AddLocation ($$, GetLocation ($4));
4490 | null_coalescing_expression INTERR expression error
4492 Error_SyntaxError (yyToken);
4494 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4496 | null_coalescing_expression INTERR expression COLON error
4498 Error_SyntaxError (yyToken);
4500 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4501 lbag.AddLocation ($$, GetLocation ($4));
4503 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4505 Error_SyntaxError (Token.CLOSE_BRACE);
4507 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4508 lbag.AddLocation ($$, GetLocation ($4));
4509 lexer.putback ('}');
4513 assignment_expression
4514 : prefixed_unary_expression ASSIGN expression
4516 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4517 lbag.AddLocation ($$, GetLocation ($2));
4519 | prefixed_unary_expression OP_MULT_ASSIGN expression
4521 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4522 lbag.AddLocation ($$, GetLocation ($2));
4524 | prefixed_unary_expression OP_DIV_ASSIGN expression
4526 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4527 lbag.AddLocation ($$, GetLocation ($2));
4529 | prefixed_unary_expression OP_MOD_ASSIGN expression
4531 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4532 lbag.AddLocation ($$, GetLocation ($2));
4534 | prefixed_unary_expression OP_ADD_ASSIGN expression
4536 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4537 lbag.AddLocation ($$, GetLocation ($2));
4539 | prefixed_unary_expression OP_SUB_ASSIGN expression
4541 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4542 lbag.AddLocation ($$, GetLocation ($2));
4544 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4546 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4547 lbag.AddLocation ($$, GetLocation ($2));
4549 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4551 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4552 lbag.AddLocation ($$, GetLocation ($2));
4554 | prefixed_unary_expression OP_AND_ASSIGN expression
4556 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4557 lbag.AddLocation ($$, GetLocation ($2));
4559 | prefixed_unary_expression OP_OR_ASSIGN expression
4561 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4562 lbag.AddLocation ($$, GetLocation ($2));
4564 | prefixed_unary_expression OP_XOR_ASSIGN expression
4566 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4567 lbag.AddLocation ($$, GetLocation ($2));
4571 lambda_parameter_list
4574 var pars = new List<Parameter> (4);
4575 pars.Add ((Parameter) $1);
4579 | lambda_parameter_list COMMA lambda_parameter
4581 var pars = (List<Parameter>) $1;
4582 Parameter p = (Parameter)$3;
4583 if (pars[0].GetType () != p.GetType ()) {
4584 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4593 : parameter_modifier parameter_type identifier_inside_body
4595 var lt = (LocatedToken) $3;
4597 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4599 | parameter_type identifier_inside_body
4601 var lt = (LocatedToken) $2;
4603 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4607 var lt = (LocatedToken) $1;
4608 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4612 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4613 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4617 opt_lambda_parameter_list
4618 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4619 | lambda_parameter_list {
4620 var pars_list = (List<Parameter>) $1;
4621 $$ = new ParametersCompiled (pars_list.ToArray ());
4625 lambda_expression_body
4627 start_block (Location.Null);
4629 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4631 Block b = end_block (Location.Null);
4632 b.IsCompilerGenerated = true;
4633 b.AddStatement (new ContextualReturn ((Expression) $2));
4639 // Handles only cases like foo = x.FirstOrDefault (l => );
4640 // where we must restore current_variable
4641 Block b = end_block (Location.Null);
4642 b.IsCompilerGenerated = true;
4644 Error_SyntaxError (yyToken);
4653 Error_SyntaxError (yyToken);
4661 var lt = (LocatedToken) $1;
4662 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4663 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4665 lambda_expression_body
4667 $$ = end_anonymous ((ParametersBlock) $4);
4668 lbag.AddLocation ($$, GetLocation ($2));
4672 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4673 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4674 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4676 lambda_expression_body
4678 $$ = end_anonymous ((ParametersBlock) $4);
4679 lbag.AddLocation ($$, GetLocation ($2));
4681 | ASYNC identifier_inside_body ARROW
4683 var lt = (LocatedToken) $2;
4684 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4685 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4687 lambda_expression_body
4689 $$ = end_anonymous ((ParametersBlock) $5);
4690 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4692 | OPEN_PARENS_LAMBDA
4694 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4696 opt_lambda_parameter_list CLOSE_PARENS ARROW
4698 valid_param_mod = 0;
4699 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4701 lambda_expression_body
4703 $$ = end_anonymous ((ParametersBlock) $7);
4704 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4706 | ASYNC OPEN_PARENS_LAMBDA
4708 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4710 opt_lambda_parameter_list CLOSE_PARENS ARROW
4712 valid_param_mod = 0;
4713 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4715 lambda_expression_body
4717 $$ = end_anonymous ((ParametersBlock) $8);
4718 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4723 : assignment_expression
4724 | non_assignment_expression
4727 non_assignment_expression
4728 : conditional_expression
4733 $$ = new ArglistAccess (GetLocation ($1));
4737 undocumented_expressions
4738 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4740 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4741 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4743 | REFTYPE open_parens_any expression CLOSE_PARENS
4745 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4746 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4748 | MAKEREF open_parens_any expression CLOSE_PARENS
4750 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4751 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4762 $$ = new BooleanExpression ((Expression) $1);
4766 opt_primary_parameters
4771 | primary_parameters
4775 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4779 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4780 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4782 if (lang_version < LanguageVersion.V_6)
4783 FeatureIsNotAvailable (GetLocation ($1), "primary constructor");
4787 opt_primary_parameters_with_class_base
4796 | primary_parameters
4800 | primary_parameters class_base
4804 | primary_parameters class_base OPEN_PARENS
4806 ++lexer.parsing_block;
4807 current_type.PrimaryConstructorBaseArgumentsStart = GetLocation ($3);
4809 opt_argument_list CLOSE_PARENS
4811 lbag.AppendToMember (current_container, GetLocation ($6));
4812 current_type.PrimaryConstructorBaseArguments = (Arguments) $5;
4813 --lexer.parsing_block;
4829 type_declaration_name
4831 lexer.ConstraintsParsing = true;
4833 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4834 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4835 FeatureIsNotAvailable (c.Location, "static classes");
4838 push_current_container (c, $3);
4839 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4841 opt_primary_parameters_with_class_base
4842 opt_type_parameter_constraints_clauses
4844 valid_param_mod = 0;
4845 lexer.ConstraintsParsing = false;
4848 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4851 current_container.SetConstraints ((List<Constraints>) $9);
4852 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4855 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4856 Lexer.doc_state = XmlCommentState.Allowed;
4859 lexer.parsing_modifiers = true;
4861 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4863 --lexer.parsing_declaration;
4865 Lexer.doc_state = XmlCommentState.Allowed;
4870 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4872 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4874 $$ = pop_current_class ();
4882 { $$ = $1; } // location
4888 mod_locations = null;
4890 lexer.parsing_modifiers = false;
4894 lexer.parsing_modifiers = false;
4900 | modifiers modifier
4902 var m1 = (Modifiers) $1;
4903 var m2 = (Modifiers) $2;
4905 if ((m1 & m2) != 0) {
4906 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4907 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4908 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4909 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4910 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4911 "More than one protection modifier specified");
4922 StoreModifierLocation ($$, GetLocation ($1));
4924 if (current_container.Kind == MemberKind.Namespace)
4925 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4929 $$ = Modifiers.PUBLIC;
4930 StoreModifierLocation ($$, GetLocation ($1));
4934 $$ = Modifiers.PROTECTED;
4935 StoreModifierLocation ($$, GetLocation ($1));
4939 $$ = Modifiers.INTERNAL;
4940 StoreModifierLocation ($$, GetLocation ($1));
4944 $$ = Modifiers.PRIVATE;
4945 StoreModifierLocation ($$, GetLocation ($1));
4949 $$ = Modifiers.ABSTRACT;
4950 StoreModifierLocation ($$, GetLocation ($1));
4954 $$ = Modifiers.SEALED;
4955 StoreModifierLocation ($$, GetLocation ($1));
4959 $$ = Modifiers.STATIC;
4960 StoreModifierLocation ($$, GetLocation ($1));
4964 $$ = Modifiers.READONLY;
4965 StoreModifierLocation ($$, GetLocation ($1));
4969 $$ = Modifiers.VIRTUAL;
4970 StoreModifierLocation ($$, GetLocation ($1));
4974 $$ = Modifiers.OVERRIDE;
4975 StoreModifierLocation ($$, GetLocation ($1));
4979 $$ = Modifiers.EXTERN;
4980 StoreModifierLocation ($$, GetLocation ($1));
4984 $$ = Modifiers.VOLATILE;
4985 StoreModifierLocation ($$, GetLocation ($1));
4989 $$ = Modifiers.UNSAFE;
4990 StoreModifierLocation ($$, GetLocation ($1));
4991 if (!settings.Unsafe)
4992 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4996 $$ = Modifiers.ASYNC;
4997 StoreModifierLocation ($$, GetLocation ($1));
5009 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5011 | COLON type_list error
5013 Error_SyntaxError (yyToken);
5015 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
5019 opt_type_parameter_constraints_clauses
5021 | type_parameter_constraints_clauses
5027 type_parameter_constraints_clauses
5028 : type_parameter_constraints_clause
5030 var constraints = new List<Constraints> (1);
5031 constraints.Add ((Constraints) $1);
5034 | type_parameter_constraints_clauses type_parameter_constraints_clause
5036 var constraints = (List<Constraints>) $1;
5037 Constraints new_constraint = (Constraints)$2;
5039 foreach (Constraints c in constraints) {
5040 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
5041 report.Error (409, new_constraint.Location,
5042 "A constraint clause has already been specified for type parameter `{0}'",
5043 new_constraint.TypeParameter.Value);
5047 constraints.Add (new_constraint);
5052 type_parameter_constraints_clause
5053 : WHERE IDENTIFIER COLON type_parameter_constraints
5055 var lt = (LocatedToken) $2;
5056 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
5057 lbag.AddLocation ($$, GetLocation ($3));
5059 | WHERE IDENTIFIER error
5061 Error_SyntaxError (yyToken);
5063 var lt = (LocatedToken) $2;
5064 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
5068 type_parameter_constraints
5069 : type_parameter_constraint
5071 var constraints = new List<FullNamedExpression> (1);
5072 constraints.Add ((FullNamedExpression) $1);
5075 | type_parameter_constraints COMMA type_parameter_constraint
5077 var constraints = (List<FullNamedExpression>) $1;
5078 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
5079 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
5080 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
5083 prev = $3 as SpecialContraintExpr;
5085 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
5086 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
5088 prev = constraints [0] as SpecialContraintExpr;
5089 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
5090 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
5095 constraints.Add ((FullNamedExpression) $3);
5100 type_parameter_constraint
5103 if ($1 is ComposedCast)
5104 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
5108 | NEW OPEN_PARENS CLOSE_PARENS
5110 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
5111 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
5115 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
5119 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5123 opt_type_parameter_variance
5128 | type_parameter_variance
5130 if (lang_version <= LanguageVersion.V_3)
5131 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5137 type_parameter_variance
5140 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5144 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5153 // A block is "contained" on the following places:
5155 // property_declaration as part of the accessor body (get/set)
5156 // operator_declaration
5157 // constructor_declaration
5158 // destructor_declaration
5159 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5164 ++lexer.parsing_block;
5165 start_block (GetLocation ($1));
5167 opt_statement_list block_end
5176 --lexer.parsing_block;
5177 $$ = end_block (GetLocation ($1));
5179 | COMPLETE_COMPLETION
5181 --lexer.parsing_block;
5182 $$ = end_block (lexer.Location);
5190 ++lexer.parsing_block;
5191 current_block.StartLocation = GetLocation ($1);
5193 opt_statement_list CLOSE_BRACE
5195 --lexer.parsing_block;
5196 $$ = end_block (GetLocation ($4));
5207 | statement_list statement
5211 : block_variable_declaration
5213 current_block.AddStatement ((Statement) $1);
5215 | valid_declaration_statement
5217 current_block.AddStatement ((Statement) $1);
5222 Error_SyntaxError (yyToken);
5228 // The interactive_statement and its derivatives are only
5229 // used to provide a special version of `expression_statement'
5230 // that has a side effect of assigning the expression to
5233 interactive_statement_list
5234 : interactive_statement
5235 | interactive_statement_list interactive_statement
5238 interactive_statement
5239 : block_variable_declaration
5241 current_block.AddStatement ((Statement) $1);
5243 | interactive_valid_declaration_statement
5245 current_block.AddStatement ((Statement) $1);
5250 valid_declaration_statement
5253 | expression_statement
5254 | selection_statement
5255 | iteration_statement
5259 | unchecked_statement
5266 interactive_valid_declaration_statement
5269 | interactive_expression_statement
5270 | selection_statement
5271 | iteration_statement
5275 | unchecked_statement
5283 : valid_declaration_statement
5284 | block_variable_declaration
5286 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5291 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5296 Error_SyntaxError (yyToken);
5297 $$ = new EmptyStatement (GetLocation ($1));
5304 // Uses lexer.Location because semicolon location is not kept in quick mode
5305 $$ = new EmptyStatement (lexer.Location);
5310 : identifier_inside_body COLON
5312 var lt = (LocatedToken) $1;
5313 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5314 lbag.AddLocation (labeled, GetLocation ($2));
5315 current_block.AddLabel (labeled);
5316 current_block.AddStatement (labeled);
5322 : variable_type_simple
5323 | variable_type_simple rank_specifiers
5326 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5328 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5333 * The following is from Rhys' grammar:
5334 * > Types in local variable declarations must be recognized as
5335 * > expressions to prevent reduce/reduce errors in the grammar.
5336 * > The expressions are converted into types during semantic analysis.
5338 variable_type_simple
5339 : primary_expression_or_type opt_nullable
5341 // Ok, the above "primary_expression" is there to get rid of
5342 // both reduce/reduce and shift/reduces in the grammar, it should
5343 // really just be "type_name". If you use type_name, a reduce/reduce
5344 // creeps up. If you use namespace_or_type_name (which is all we need
5345 // really) two shift/reduces appear.
5348 // So the super-trick is that primary_expression
5349 // can only be either a SimpleName or a MemberAccess.
5350 // The MemberAccess case arises when you have a fully qualified type-name like :
5352 // SimpleName is when you have
5355 Expression expr = (Expression) $1;
5357 SimpleName sn = expr as SimpleName;
5358 if (sn != null && sn.Name == "var")
5359 $$ = new VarExpr (sn.Location);
5362 } else if (expr is ATypeNameExpression) {
5363 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5365 Error_ExpectingTypeName (expr);
5369 | primary_expression_or_type pointer_stars
5371 ATypeNameExpression expr = $1 as ATypeNameExpression;
5374 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5376 Error_ExpectingTypeName ((Expression)$1);
5380 | builtin_types opt_nullable
5385 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5387 | builtin_types pointer_stars
5389 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5391 | VOID pointer_stars
5393 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5397 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5398 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5404 | pointer_star pointer_stars
5406 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5414 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5418 identifier_inside_body
5422 $$ = Error_AwaitAsIdentifier ($1);
5426 block_variable_declaration
5427 : variable_type identifier_inside_body
5429 var lt = (LocatedToken) $2;
5430 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5431 current_block.AddLocalName (li);
5432 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5434 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5436 $$ = current_variable;
5437 current_variable = null;
5439 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5441 lbag.AddLocation ($$, GetLocation ($6));
5443 | CONST variable_type identifier_inside_body
5445 var lt = (LocatedToken) $3;
5446 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5447 current_block.AddLocalName (li);
5448 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5450 const_variable_initializer opt_const_declarators SEMICOLON
5452 $$ = current_variable;
5453 current_variable = null;
5454 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5458 opt_local_variable_initializer
5460 | ASSIGN block_variable_initializer
5462 current_variable.Initializer = (Expression) $2;
5463 PushLocation (GetLocation ($1));
5464 $$ = current_variable;
5468 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5469 report.Error (650, lexer.Location,
5470 "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");
5472 Error_SyntaxError (yyToken);
5477 opt_variable_declarators
5479 | variable_declarators
5482 opt_using_or_fixed_variable_declarators
5484 | variable_declarators
5486 foreach (var d in current_variable.Declarators) {
5487 if (d.Initializer == null)
5488 Error_MissingInitializer (d.Variable.Location);
5493 variable_declarators
5494 : variable_declarator
5495 | variable_declarators variable_declarator
5499 : COMMA identifier_inside_body
5501 var lt = (LocatedToken) $2;
5502 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5503 var d = new BlockVariableDeclarator (li, null);
5504 current_variable.AddDeclarator (d);
5505 current_block.AddLocalName (li);
5506 lbag.AddLocation (d, GetLocation ($1));
5508 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5510 var lt = (LocatedToken) $2;
5511 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5512 var d = new BlockVariableDeclarator (li, (Expression) $4);
5513 current_variable.AddDeclarator (d);
5514 current_block.AddLocalName (li);
5515 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5519 const_variable_initializer
5522 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5524 | ASSIGN constant_initializer_expr
5526 current_variable.Initializer = (Expression) $2;
5530 opt_const_declarators
5537 | const_declarators const_declarator
5541 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5543 var lt = (LocatedToken) $2;
5544 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5545 var d = new BlockVariableDeclarator (li, (Expression) $4);
5546 current_variable.AddDeclarator (d);
5547 current_block.AddLocalName (li);
5548 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5552 block_variable_initializer
5553 : variable_initializer
5554 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5556 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5557 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5559 | STACKALLOC simple_type
5561 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5562 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5566 expression_statement
5567 : statement_expression SEMICOLON
5570 lbag.AddStatement ($$, GetLocation ($2));
5572 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5573 | statement_expression CLOSE_BRACE
5576 report.Error (1002, GetLocation ($2), "; expected");
5577 lexer.putback ('}');
5581 interactive_expression_statement
5582 : interactive_statement_expression SEMICOLON { $$ = $1; }
5583 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5587 // We have to do the wrapping here and not in the case above,
5588 // because statement_expression is used for example in for_statement
5590 statement_expression
5593 ExpressionStatement s = $1 as ExpressionStatement;
5595 var expr = $1 as Expression;
5596 $$ = new StatementErrorExpression (expr);
5598 $$ = new StatementExpression (s);
5603 interactive_statement_expression
5606 Expression expr = (Expression) $1;
5607 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5611 Error_SyntaxError (yyToken);
5612 $$ = new EmptyStatement (GetLocation ($1));
5622 : IF open_parens_any boolean_expression CLOSE_PARENS
5625 if ($5 is EmptyStatement)
5626 Warning_EmptyStatement (GetLocation ($5));
5628 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5629 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5631 | IF open_parens_any boolean_expression CLOSE_PARENS
5632 embedded_statement ELSE embedded_statement
5634 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5635 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5637 if ($5 is EmptyStatement)
5638 Warning_EmptyStatement (GetLocation ($5));
5639 if ($7 is EmptyStatement)
5640 Warning_EmptyStatement (GetLocation ($7));
5642 | IF open_parens_any boolean_expression error
5644 Error_SyntaxError (yyToken);
5646 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5647 lbag.AddStatement ($$, GetLocation ($2));
5652 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5654 start_block (GetLocation ($5));
5656 opt_switch_sections CLOSE_BRACE
5658 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5659 end_block (GetLocation ($8));
5660 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5662 | SWITCH open_parens_any expression error
5664 Error_SyntaxError (yyToken);
5666 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5667 lbag.AddStatement ($$, GetLocation ($2));
5674 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5681 | switch_sections switch_section
5684 Error_SyntaxError (yyToken);
5689 : switch_labels statement_list
5695 var label = (SwitchLabel) $1;
5696 label.SectionStart = true;
5697 current_block.AddStatement (label);
5699 | switch_labels switch_label
5701 current_block.AddStatement ((Statement) $2);
5706 : CASE constant_expression COLON
5708 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5709 lbag.AddLocation ($$, GetLocation ($3));
5711 | CASE constant_expression error
5713 Error_SyntaxError (yyToken);
5714 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5718 $$ = new SwitchLabel (null, GetLocation ($1));
5730 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5732 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5733 Warning_EmptyStatement (GetLocation ($5));
5735 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5736 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5738 | WHILE open_parens_any boolean_expression error
5740 Error_SyntaxError (yyToken);
5742 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5743 lbag.AddStatement ($$, GetLocation ($2));
5748 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5750 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5751 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5753 | DO embedded_statement error
5755 Error_SyntaxError (yyToken);
5756 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5758 | DO embedded_statement WHILE open_parens_any boolean_expression error
5760 Error_SyntaxError (yyToken);
5762 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5763 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5768 : FOR open_parens_any
5770 start_block (GetLocation ($2));
5771 current_block.IsCompilerGenerated = true;
5772 For f = new For (GetLocation ($1));
5773 current_block.AddStatement (f);
5782 // Has to use be extra rule to recover started block
5784 : opt_for_initializer SEMICOLON
5786 ((For) $0).Initializer = (Statement) $1;
5788 // Pass the "For" object to the iterator_part4
5789 oob_stack.Push ($0);
5791 for_condition_and_iterator_part
5794 var locations = (Tuple<Location,Location>) $4;
5796 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5797 Warning_EmptyStatement (GetLocation ($5));
5800 f.Statement = (Statement) $5;
5801 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5803 $$ = end_block (GetLocation ($2));
5807 Error_SyntaxError (yyToken);
5808 $$ = end_block (current_block.StartLocation);
5812 for_condition_and_iterator_part
5813 : opt_for_condition SEMICOLON
5815 For f = (For) oob_stack.Peek ();
5816 f.Condition = (BooleanExpression) $1;
5819 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5822 // Handle errors in the case of opt_for_condition being followed by
5823 // a close parenthesis
5824 | opt_for_condition close_parens_close_brace {
5825 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5826 For f = (For) oob_stack.Peek ();
5827 f.Condition = (BooleanExpression) $1;
5828 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5833 : opt_for_iterator CLOSE_PARENS {
5834 For f = (For) oob_stack.Peek ();
5835 f.Iterator = (Statement) $1;
5836 $$ = GetLocation ($2);
5838 | opt_for_iterator CLOSE_BRACE {
5839 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5840 For f = (For) oob_stack.Peek ();
5841 f.Iterator = (Statement) $1;
5842 $$ = GetLocation ($2);
5846 close_parens_close_brace
5848 | CLOSE_BRACE { lexer.putback ('}'); }
5852 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5857 : variable_type identifier_inside_body
5859 var lt = (LocatedToken) $2;
5860 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5861 current_block.AddLocalName (li);
5862 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5864 opt_local_variable_initializer opt_variable_declarators
5866 $$ = current_variable;
5868 lbag.AddLocation (current_variable, PopLocation ());
5870 current_variable = null;
5872 | statement_expression_list
5876 : /* empty */ { $$ = null; }
5877 | boolean_expression
5881 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5886 : statement_expression_list
5889 statement_expression_list
5890 : statement_expression
5891 | statement_expression_list COMMA statement_expression
5893 var sl = $1 as StatementList;
5895 sl = new StatementList ((Statement) $1, (Statement) $3);
5896 lbag.AddStatement (sl, GetLocation ($2));
5898 sl.Add ((Statement) $3);
5899 lbag.AppendTo (sl, GetLocation ($2));
5907 : FOREACH open_parens_any type error
5909 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5911 start_block (GetLocation ($2));
5912 current_block.IsCompilerGenerated = true;
5914 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5915 current_block.AddStatement (f);
5917 lbag.AddStatement (f, GetLocation ($2));
5918 $$ = end_block (GetLocation ($4));
5920 | FOREACH open_parens_any type identifier_inside_body error
5922 Error_SyntaxError (yyToken);
5924 start_block (GetLocation ($2));
5925 current_block.IsCompilerGenerated = true;
5927 var lt = (LocatedToken) $4;
5928 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5929 current_block.AddLocalName (li);
5931 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5932 current_block.AddStatement (f);
5934 lbag.AddStatement (f, GetLocation ($2));
5935 $$ = end_block (GetLocation ($5));
5937 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5939 start_block (GetLocation ($2));
5940 current_block.IsCompilerGenerated = true;
5942 var lt = (LocatedToken) $4;
5943 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5944 current_block.AddLocalName (li);
5949 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5950 Warning_EmptyStatement (GetLocation ($9));
5952 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5953 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5954 end_block (GetLocation ($7));
5962 | continue_statement
5972 $$ = new Break (GetLocation ($1));
5973 lbag.AddStatement ($$, GetLocation ($2));
5978 : CONTINUE SEMICOLON
5980 $$ = new Continue (GetLocation ($1));
5981 lbag.AddStatement ($$, GetLocation ($2));
5985 Error_SyntaxError (yyToken);
5986 $$ = new Continue (GetLocation ($1));
5991 : GOTO identifier_inside_body SEMICOLON
5993 var lt = (LocatedToken) $2;
5994 $$ = new Goto (lt.Value, GetLocation ($1));
5995 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5997 | GOTO CASE constant_expression SEMICOLON
5999 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
6000 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6002 | GOTO DEFAULT SEMICOLON
6004 $$ = new GotoDefault (GetLocation ($1));
6005 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6010 : RETURN opt_expression SEMICOLON
6012 $$ = new Return ((Expression) $2, GetLocation ($1));
6013 lbag.AddStatement ($$, GetLocation ($3));
6015 | RETURN expression error
6017 Error_SyntaxError (yyToken);
6018 $$ = new Return ((Expression) $2, GetLocation ($1));
6022 Error_SyntaxError (yyToken);
6023 $$ = new Return (null, GetLocation ($1));
6028 : THROW opt_expression SEMICOLON
6030 $$ = new Throw ((Expression) $2, GetLocation ($1));
6031 lbag.AddStatement ($$, GetLocation ($3));
6033 | THROW expression error
6035 Error_SyntaxError (yyToken);
6036 $$ = new Throw ((Expression) $2, GetLocation ($1));
6040 Error_SyntaxError (yyToken);
6041 $$ = new Throw (null, GetLocation ($1));
6046 : identifier_inside_body RETURN opt_expression SEMICOLON
6048 var lt = (LocatedToken) $1;
6049 string s = lt.Value;
6051 report.Error (1003, lt.Location, "; expected");
6052 } else if ($3 == null) {
6053 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6054 } else if (lang_version == LanguageVersion.ISO_1){
6055 FeatureIsNotAvailable (lt.Location, "iterators");
6058 current_block.Explicit.RegisterIteratorYield ();
6059 $$ = new Yield ((Expression) $3, lt.Location);
6060 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6062 | identifier_inside_body RETURN expression error
6064 Error_SyntaxError (yyToken);
6066 var lt = (LocatedToken) $1;
6067 string s = lt.Value;
6069 report.Error (1003, lt.Location, "; expected");
6070 } else if ($3 == null) {
6071 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
6072 } else if (lang_version == LanguageVersion.ISO_1){
6073 FeatureIsNotAvailable (lt.Location, "iterators");
6076 current_block.Explicit.RegisterIteratorYield ();
6077 $$ = new Yield ((Expression) $3, lt.Location);
6078 lbag.AddStatement ($$, GetLocation ($2));
6080 | identifier_inside_body BREAK SEMICOLON
6082 var lt = (LocatedToken) $1;
6083 string s = lt.Value;
6085 report.Error (1003, lt.Location, "; expected");
6086 } else if (lang_version == LanguageVersion.ISO_1){
6087 FeatureIsNotAvailable (lt.Location, "iterators");
6090 current_block.ParametersBlock.TopBlock.IsIterator = true;
6091 $$ = new YieldBreak (lt.Location);
6092 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
6102 : TRY block catch_clauses
6104 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
6106 | TRY block FINALLY block
6108 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
6109 lbag.AddStatement ($$, GetLocation ($3));
6111 | TRY block catch_clauses FINALLY block
6113 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
6114 lbag.AddStatement ($$, GetLocation ($4));
6118 Error_SyntaxError (1524, yyToken);
6119 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6126 var l = new List<Catch> (2);
6131 | catch_clauses catch_clause
6133 var l = (List<Catch>) $1;
6135 Catch c = (Catch) $2;
6136 var prev_catch = l [l.Count - 1];
6137 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6138 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6148 | identifier_inside_body
6152 : CATCH opt_catch_filter block
6154 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6155 c.Filter = (CatchFilterExpression) $2;
6158 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6160 start_block (GetLocation ($2));
6161 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6162 c.TypeExpression = (FullNamedExpression) $3;
6165 var lt = (LocatedToken) $4;
6166 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6167 current_block.AddLocalName (c.Variable);
6170 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6173 opt_catch_filter block_prepared
6175 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6178 | CATCH open_parens_any error
6180 if (yyToken == Token.CLOSE_PARENS) {
6181 report.Error (1015, lexer.Location,
6182 "A type that derives from `System.Exception', `object', or `string' expected");
6184 Error_SyntaxError (yyToken);
6187 $$ = new Catch (null, GetLocation ($1));
6189 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6191 Error_SyntaxError (yyToken);
6193 // Required otherwise missing block could not be detected because
6194 // start_block is run early
6195 var c = new Catch (null, GetLocation ($1));
6196 c.TypeExpression = (FullNamedExpression) $3;
6199 var lt = (LocatedToken) $4;
6200 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6203 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6211 | IF open_parens_any expression CLOSE_PARENS
6213 if (lang_version <= LanguageVersion.V_5)
6214 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6216 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6217 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6224 $$ = new Checked ((Block) $2, GetLocation ($1));
6231 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6238 if (!settings.Unsafe)
6239 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6241 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6246 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6248 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6249 Warning_EmptyStatement (GetLocation ($5));
6251 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6252 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6254 | LOCK open_parens_any expression error
6256 Error_SyntaxError (yyToken);
6258 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6259 lbag.AddStatement ($$, GetLocation ($2));
6264 : FIXED open_parens_any variable_type identifier_inside_body
6266 start_block (GetLocation ($2));
6268 current_block.IsCompilerGenerated = true;
6269 var lt = (LocatedToken) $4;
6270 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6271 current_block.AddLocalName (li);
6272 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6274 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6276 $$ = current_variable;
6277 current_variable = null;
6281 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6282 Warning_EmptyStatement (GetLocation ($10));
6284 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6285 current_block.AddStatement (f);
6286 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6287 $$ = end_block (GetLocation ($8));
6292 : USING open_parens_any variable_type identifier_inside_body
6294 start_block (GetLocation ($2));
6296 current_block.IsCompilerGenerated = true;
6297 var lt = (LocatedToken) $4;
6298 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6299 current_block.AddLocalName (li);
6300 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6302 using_initialization CLOSE_PARENS
6304 $$ = current_variable;
6305 current_variable = null;
6309 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6310 Warning_EmptyStatement (GetLocation ($9));
6312 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6313 current_block.AddStatement (u);
6314 $$ = end_block (GetLocation ($7));
6316 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6318 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6319 Warning_EmptyStatement (GetLocation ($5));
6321 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6322 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6324 | USING open_parens_any expression error
6326 Error_SyntaxError (yyToken);
6328 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6329 lbag.AddStatement ($$, GetLocation ($2));
6333 using_initialization
6334 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6337 // It has to be here for the parent to safely restore artificial block
6338 Error_SyntaxError (yyToken);
6342 using_or_fixed_variable_initializer
6345 Error_MissingInitializer (lexer.Location);
6347 | ASSIGN variable_initializer
6349 current_variable.Initializer = (Expression) $2;
6350 $$ = current_variable;
6358 : first_from_clause query_body
6360 lexer.query_parsing = false;
6362 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6364 from.Tail.Next = (Linq.AQueryClause)$2;
6367 current_block.SetEndLocation (lexer.Location);
6368 current_block = current_block.Parent;
6370 | nested_from_clause query_body
6372 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6374 from.Tail.Next = (Linq.AQueryClause)$2;
6377 current_block.SetEndLocation (lexer.Location);
6378 current_block = current_block.Parent;
6381 // Bubble up COMPLETE_COMPLETION productions
6382 | first_from_clause COMPLETE_COMPLETION {
6383 lexer.query_parsing = false;
6386 current_block.SetEndLocation (lexer.Location);
6387 current_block = current_block.Parent;
6389 | nested_from_clause COMPLETE_COMPLETION {
6391 current_block.SetEndLocation (lexer.Location);
6392 current_block = current_block.Parent;
6397 : FROM_FIRST identifier_inside_body IN expression
6399 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6401 var lt = (LocatedToken) $2;
6402 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6403 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6404 lbag.AddLocation (clause, GetLocation ($3));
6405 $$ = new Linq.QueryExpression (clause);
6407 | FROM_FIRST type identifier_inside_body IN expression
6409 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6411 var lt = (LocatedToken) $3;
6412 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6413 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6414 IdentifierType = (FullNamedExpression)$2
6416 lbag.AddLocation (clause, GetLocation ($4));
6417 $$ = new Linq.QueryExpression (clause);
6422 : FROM identifier_inside_body IN expression
6424 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6426 var lt = (LocatedToken) $2;
6427 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6428 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6429 lbag.AddLocation (clause, GetLocation ($3));
6430 $$ = new Linq.QueryExpression (clause);
6432 | FROM type identifier_inside_body IN expression
6434 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6436 var lt = (LocatedToken) $3;
6437 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6438 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6439 IdentifierType = (FullNamedExpression)$2
6441 lbag.AddLocation (clause, GetLocation ($4));
6442 $$ = new Linq.QueryExpression (clause);
6447 : FROM identifier_inside_body IN
6449 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6453 var lt = (LocatedToken) $2;
6454 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6455 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6457 current_block.SetEndLocation (lexer.Location);
6458 current_block = current_block.Parent;
6460 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6461 lbag.AddLocation ($$, GetLocation ($3));
6463 | FROM type identifier_inside_body IN
6465 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6469 var lt = (LocatedToken) $3;
6470 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6472 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6473 IdentifierType = (FullNamedExpression)$2
6476 current_block.SetEndLocation (lexer.Location);
6477 current_block = current_block.Parent;
6479 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6481 lbag.AddLocation ($$, GetLocation ($4));
6486 : query_body_clauses select_or_group_clause opt_query_continuation
6488 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6491 head.Next = (Linq.AQueryClause)$3;
6494 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6495 clause.Tail.Next = head;
6501 | select_or_group_clause opt_query_continuation
6503 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6506 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6507 clause.Tail.Next = head;
6513 | query_body_clauses COMPLETE_COMPLETION
6514 | query_body_clauses error
6516 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6521 Error_SyntaxError (yyToken);
6526 select_or_group_clause
6529 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6533 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6535 current_block.SetEndLocation (lexer.Location);
6536 current_block = current_block.Parent;
6540 if (linq_clause_blocks == null)
6541 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6543 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6544 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6548 current_block.SetEndLocation (lexer.Location);
6549 current_block = current_block.Parent;
6551 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6555 var obj = (object[]) $5;
6557 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6558 lbag.AddLocation ($$, (Location) obj[1]);
6560 current_block.SetEndLocation (lexer.Location);
6561 current_block = current_block.Parent;
6566 : BY expression_or_error
6568 $$ = new object[] { $2, GetLocation ($1) };
6572 Error_SyntaxError (yyToken);
6573 $$ = new object[2] { null, Location.Null };
6579 | query_body_clauses query_body_clause
6581 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6595 : LET identifier_inside_body ASSIGN
6597 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6601 var lt = (LocatedToken) $2;
6602 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6603 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6604 lbag.AddLocation ($$, GetLocation ($3));
6606 current_block.SetEndLocation (lexer.Location);
6607 current_block = current_block.Parent;
6609 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6616 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6620 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6622 current_block.SetEndLocation (lexer.Location);
6623 current_block = current_block.Parent;
6628 : JOIN identifier_inside_body IN
6630 if (linq_clause_blocks == null)
6631 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6633 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6634 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6636 expression_or_error ON
6638 current_block.SetEndLocation (lexer.Location);
6639 current_block = current_block.Parent;
6641 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6642 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6644 expression_or_error EQUALS
6646 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6647 current_block.SetEndLocation (lexer.Location);
6648 current_block = current_block.Parent;
6650 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6652 expression_or_error opt_join_into
6654 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6655 current_block.SetEndLocation (lexer.Location);
6657 var outer_selector = linq_clause_blocks.Pop ();
6658 var block = linq_clause_blocks.Pop ();
6660 var lt = (LocatedToken) $2;
6661 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6662 Linq.RangeVariable into;
6666 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6667 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6670 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6672 var parent = block.Parent;
6673 while (parent is Linq.QueryBlock) {
6674 parent = parent.Parent;
6676 current_block.Parent = parent;
6678 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6680 lt = (LocatedToken) $12;
6681 into = new Linq.RangeVariable (lt.Value, lt.Location);
6683 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6684 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6687 current_block = block.Parent;
6688 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6690 | JOIN type identifier_inside_body IN
6692 if (linq_clause_blocks == null)
6693 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6695 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6696 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6698 expression_or_error ON
6700 current_block.SetEndLocation (lexer.Location);
6701 current_block = current_block.Parent;
6703 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6704 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6706 expression_or_error EQUALS
6708 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6709 current_block.SetEndLocation (lexer.Location);
6710 current_block = current_block.Parent;
6712 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6714 expression_or_error opt_join_into
6716 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6717 current_block.SetEndLocation (lexer.Location);
6719 var outer_selector = linq_clause_blocks.Pop ();
6720 var block = linq_clause_blocks.Pop ();
6722 var lt = (LocatedToken) $3;
6723 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6724 Linq.RangeVariable into;
6728 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6729 IdentifierType = (FullNamedExpression)$2
6731 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6734 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6736 var parent = block.Parent;
6737 while (parent is Linq.QueryBlock) {
6738 parent = parent.Parent;
6740 current_block.Parent = parent;
6742 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6744 lt = (LocatedToken) $13;
6745 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6747 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6748 IdentifierType = (FullNamedExpression)$2
6752 current_block = block.Parent;
6753 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6759 | INTO identifier_inside_body
6768 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6772 current_block.SetEndLocation (lexer.Location);
6773 current_block = current_block.Parent;
6783 current_block.SetEndLocation (lexer.Location);
6784 current_block = current_block.Parent;
6786 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6790 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6797 | orderings_then_by COMMA
6799 current_block.SetEndLocation (lexer.Location);
6800 current_block = current_block.Parent;
6802 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6806 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6814 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6816 | expression ASCENDING
6818 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6819 lbag.AddLocation ($$, GetLocation ($2));
6821 | expression DESCENDING
6823 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6824 lbag.AddLocation ($$, GetLocation ($2));
6831 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6833 | expression ASCENDING
6835 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6836 lbag.AddLocation ($$, GetLocation ($2));
6838 | expression DESCENDING
6840 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6841 lbag.AddLocation ($$, GetLocation ($2));
6846 opt_query_continuation
6848 | INTO identifier_inside_body
6850 // query continuation block is not linked with query block but with block
6851 // before. This means each query can use same range variable names for
6852 // different identifiers.
6854 current_block.SetEndLocation (GetLocation ($1));
6855 current_block = current_block.Parent;
6857 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6859 if (linq_clause_blocks == null)
6860 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6862 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6866 var current_block = linq_clause_blocks.Pop ();
6867 var lt = (LocatedToken) $2;
6868 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6869 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6870 next = (Linq.AQueryClause)$4
6876 // Support for using the compiler as an interactive parser
6878 // The INTERACTIVE_PARSER token is first sent to parse our
6879 // productions; If the result is a Statement, the parsing
6880 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6881 // to setup the blocks in advance.
6883 // This setup is here so that in the future we can add
6884 // support for other constructs (type parsing, namespaces, etc)
6885 // that do not require a block to be setup in advance
6889 : EVAL_STATEMENT_PARSER EOF
6890 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6891 | EVAL_STATEMENT_PARSER
6893 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6895 // (ref object retval)
6896 Parameter [] mpar = new Parameter [1];
6897 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6899 ParametersCompiled pars = new ParametersCompiled (mpar);
6900 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6901 if (settings.Unsafe)
6902 mods |= Modifiers.UNSAFE;
6904 current_local_parameters = pars;
6905 var method = new InteractiveMethod (
6907 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6911 current_type.AddMember (method);
6912 oob_stack.Push (method);
6914 interactive_async = false;
6916 ++lexer.parsing_block;
6917 start_block (lexer.Location);
6919 interactive_statement_list opt_COMPLETE_COMPLETION
6921 --lexer.parsing_block;
6922 var method = (InteractiveMethod) oob_stack.Pop ();
6923 method.Block = (ToplevelBlock) end_block(lexer.Location);
6925 if (interactive_async == true) {
6926 method.ChangeToAsync ();
6929 InteractiveResult = (Class) pop_current_class ();
6930 current_local_parameters = null;
6932 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6935 interactive_compilation_unit
6936 : opt_extern_alias_directives opt_using_directives
6937 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6940 opt_COMPLETE_COMPLETION
6942 | COMPLETE_COMPLETION
6945 close_brace_or_complete_completion
6947 | COMPLETE_COMPLETION
6951 // XML documentation code references micro parser
6953 documentation_parsing
6956 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6961 : doc_type_declaration_name opt_doc_method_sig
6963 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6965 | builtin_types opt_doc_method_sig
6967 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6968 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6971 | VOID opt_doc_method_sig
6973 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
6974 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6977 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6979 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6980 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6981 var lt = (LocatedToken) $3;
6982 $$ = new MemberName (lt.Value);
6984 | doc_type_declaration_name DOT THIS
6986 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6988 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6990 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6992 opt_doc_parameters CLOSE_BRACKET
6994 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6995 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6997 | EXPLICIT OPERATOR type opt_doc_method_sig
6999 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7000 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7001 module.DocumentationBuilder.ParsedParameters = p;
7002 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
7005 | IMPLICIT OPERATOR type opt_doc_method_sig
7007 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
7008 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
7009 module.DocumentationBuilder.ParsedParameters = p;
7010 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
7013 | OPERATOR overloadable_operator opt_doc_method_sig
7015 var p = (List<DocumentationParameter>)$3;
7016 module.DocumentationBuilder.ParsedParameters = p;
7017 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
7022 doc_type_declaration_name
7023 : type_declaration_name
7024 | doc_type_declaration_name DOT type_declaration_name
7026 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
7034 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
7036 opt_doc_parameters CLOSE_PARENS
7045 $$ = new List<DocumentationParameter> (0);
7053 var parameters = new List<DocumentationParameter> ();
7054 parameters.Add ((DocumentationParameter) $1);
7057 | doc_parameters COMMA doc_parameter
7059 var parameters = $1 as List<DocumentationParameter>;
7060 parameters.Add ((DocumentationParameter) $3);
7066 : opt_parameter_modifier parameter_type
7069 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
7071 $$ = new DocumentationParameter ((FullNamedExpression) $2);
7078 // A class used to hold info about an operator declarator
7080 class OperatorDeclaration {
7081 public readonly Operator.OpType optype;
7082 public readonly FullNamedExpression ret_type;
7083 public readonly Location location;
7085 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
7088 this.ret_type = ret_type;
7089 this.location = location;
7093 void Error_ExpectingTypeName (Expression expr)
7095 if (expr is Invocation){
7096 report.Error (1002, expr.Location, "Expecting `;'");
7098 expr.Error_InvalidExpressionStatement (report);
7102 void Error_ParameterModifierNotValid (string modifier, Location loc)
7104 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
7108 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
7110 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
7111 Parameter.GetModifierSignature (mod));
7114 void Error_TypeExpected (Location loc)
7116 report.Error (1031, loc, "Type expected");
7119 void Error_UnsafeCodeNotAllowed (Location loc)
7121 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7124 void Warning_EmptyStatement (Location loc)
7126 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7129 void Error_NamedArgumentExpected (NamedArgument a)
7131 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7134 void Error_MissingInitializer (Location loc)
7136 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7139 object Error_AwaitAsIdentifier (object token)
7142 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7143 return new LocatedToken ("await", GetLocation (token));
7149 void push_current_container (TypeDefinition tc, object partial_token)
7151 if (module.Evaluator != null){
7152 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7156 undo.AddTypeContainer (current_container, tc);
7159 if (partial_token != null)
7160 current_container.AddPartial (tc);
7162 current_container.AddTypeContainer (tc);
7164 ++lexer.parsing_declaration;
7165 current_container = tc;
7169 TypeContainer pop_current_class ()
7171 var retval = current_container;
7173 current_container = current_container.Parent;
7174 current_type = current_type.Parent as TypeDefinition;
7179 [System.Diagnostics.Conditional ("FULL_AST")]
7180 void StoreModifierLocation (object token, Location loc)
7185 if (mod_locations == null)
7186 mod_locations = new List<Tuple<Modifiers, Location>> ();
7188 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7191 [System.Diagnostics.Conditional ("FULL_AST")]
7192 void PushLocation (Location loc)
7194 if (location_stack == null)
7195 location_stack = new Stack<Location> ();
7197 location_stack.Push (loc);
7200 Location PopLocation ()
7202 if (location_stack == null)
7203 return Location.Null;
7205 return location_stack.Pop ();
7208 string CheckAttributeTarget (int token, string a, Location l)
7211 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7215 if (!Tokenizer.IsValidIdentifier (a)) {
7216 Error_SyntaxError (token);
7218 report.Warning (658, 1, l,
7219 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7222 return string.Empty;
7225 static bool IsUnaryOperator (Operator.OpType op)
7229 case Operator.OpType.LogicalNot:
7230 case Operator.OpType.OnesComplement:
7231 case Operator.OpType.Increment:
7232 case Operator.OpType.Decrement:
7233 case Operator.OpType.True:
7234 case Operator.OpType.False:
7235 case Operator.OpType.UnaryPlus:
7236 case Operator.OpType.UnaryNegation:
7242 void syntax_error (Location l, string msg)
7244 report.Error (1003, l, "Syntax error, " + msg);
7249 public Tokenizer Lexer {
7255 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7256 : this (reader, file, file.Compiler.Report, session)
7260 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7263 current_container = current_namespace = file;
7265 this.module = file.Module;
7266 this.compiler = file.Compiler;
7267 this.settings = compiler.Settings;
7268 this.report = report;
7270 lang_version = settings.Version;
7271 yacc_verbose_flag = settings.VerboseParserFlag;
7272 doc_support = settings.DocumentationFile != null;
7273 lexer = new Tokenizer (reader, file, session, report);
7274 oob_stack = new Stack<object> ();
7275 lbag = session.LocationsBag;
7276 use_global_stacks = session.UseJayGlobalArrays;
7277 parameters_bucket = session.ParametersStack;
7280 public void parse ()
7282 eof_token = Token.EOF;
7285 if (yacc_verbose_flag > 1)
7286 yyparse (lexer, new yydebug.yyDebugSimple ());
7290 Tokenizer tokenizer = lexer as Tokenizer;
7291 tokenizer.cleanup ();
7292 } catch (Exception e){
7293 if (e is yyParser.yyUnexpectedEof) {
7294 Error_SyntaxError (yyToken);
7295 UnexpectedEOF = true;
7299 if (e is yyParser.yyException) {
7300 if (report.Errors == 0)
7301 report.Error (-25, lexer.Location, "Parsing error");
7303 // Used by compiler-tester to test internal errors
7304 if (yacc_verbose_flag > 0 || e is FatalException)
7307 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7312 void CheckToken (int error, int yyToken, string msg, Location loc)
7314 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7315 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7317 report.Error (error, loc, msg);
7320 string ConsumeStoredComment ()
7322 string s = tmpComment;
7324 Lexer.doc_state = XmlCommentState.Allowed;
7328 void FeatureIsNotAvailable (Location loc, string feature)
7330 report.FeatureIsNotAvailable (compiler, loc, feature);
7333 Location GetLocation (object obj)
7335 var lt = obj as LocatedToken;
7339 var mn = obj as MemberName;
7343 var expr = obj as Expression;
7345 return expr.Location;
7347 return lexer.Location;
7350 void start_block (Location loc)
7352 if (current_block == null) {
7353 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7354 parsing_anonymous_method = false;
7355 } else if (parsing_anonymous_method) {
7356 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7357 parsing_anonymous_method = false;
7359 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7364 end_block (Location loc)
7366 Block retval = current_block.Explicit;
7367 retval.SetEndLocation (loc);
7368 current_block = retval.Parent;
7372 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7374 oob_stack.Push (current_anonymous_method);
7375 oob_stack.Push (current_local_parameters);
7376 oob_stack.Push (current_variable);
7377 oob_stack.Push (async_block);
7379 current_local_parameters = parameters;
7381 if (lang_version <= LanguageVersion.ISO_2)
7382 FeatureIsNotAvailable (loc, "lambda expressions");
7384 current_anonymous_method = new LambdaExpression (loc);
7386 if (lang_version == LanguageVersion.ISO_1)
7387 FeatureIsNotAvailable (loc, "anonymous methods");
7389 current_anonymous_method = new AnonymousMethodExpression (loc);
7392 async_block = isAsync;
7393 // Force the next block to be created as a ToplevelBlock
7394 parsing_anonymous_method = true;
7398 * Completes the anonymous method processing, if lambda_expr is null, this
7399 * means that we have a Statement instead of an Expression embedded
7401 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7403 AnonymousMethodExpression retval;
7406 anon_block.IsAsync = true;
7408 current_anonymous_method.Block = anon_block;
7409 retval = current_anonymous_method;
7411 async_block = (bool) oob_stack.Pop ();
7412 current_variable = (BlockVariable) oob_stack.Pop ();
7413 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7414 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7419 void Error_SyntaxError (int token)
7421 Error_SyntaxError (0, token);
7424 void Error_SyntaxError (int error_code, int token)
7426 Error_SyntaxError (error_code, token, "Unexpected symbol");
7429 void Error_SyntaxError (int error_code, int token, string msg)
7431 Lexer.CompleteOnEOF = false;
7433 // An error message has been reported by tokenizer
7434 if (token == Token.ERROR)
7437 // Avoid duplicit error message after unterminated string literals
7438 if (token == Token.LITERAL && lexer.Location.Column == 0)
7441 string symbol = GetSymbolName (token);
7442 string expecting = GetExpecting ();
7443 var loc = lexer.Location - symbol.Length;
7445 if (error_code == 0) {
7446 if (expecting == "`identifier'") {
7447 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7448 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7453 expecting = "identifier";
7454 } else if (expecting == "`)'") {
7461 if (string.IsNullOrEmpty (expecting))
7462 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7464 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7467 string GetExpecting ()
7469 int [] tokens = yyExpectingTokens (yyExpectingState);
7470 var names = new List<string> (tokens.Length);
7471 bool has_type = false;
7472 bool has_identifier = false;
7473 for (int i = 0; i < tokens.Length; i++){
7474 int token = tokens [i];
7475 has_identifier |= token == Token.IDENTIFIER;
7477 string name = GetTokenName (token);
7478 if (name == "<internal>")
7481 has_type |= name == "type";
7482 if (names.Contains (name))
7489 // Too many tokens to enumerate
7491 if (names.Count > 8)
7494 if (has_type && has_identifier)
7495 names.Remove ("identifier");
7497 if (names.Count == 1)
7498 return "`" + GetTokenName (tokens [0]) + "'";
7500 StringBuilder sb = new StringBuilder ();
7502 int count = names.Count;
7503 for (int i = 0; i < count; i++){
7504 bool last = i + 1 == count;
7508 sb.Append (names [i]);
7509 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7511 return sb.ToString ();
7515 string GetSymbolName (int token)
7519 return ((Constant)lexer.Value).GetValue ().ToString ();
7520 case Token.IDENTIFIER:
7521 return ((LocatedToken)lexer.Value).Value;
7563 case Token.BITWISE_AND:
7565 case Token.BITWISE_OR:
7579 case Token.OP_SHIFT_LEFT:
7581 case Token.OP_SHIFT_RIGHT:
7601 case Token.OP_COALESCING:
7603 case Token.OP_MULT_ASSIGN:
7605 case Token.OP_DIV_ASSIGN:
7607 case Token.OP_MOD_ASSIGN:
7609 case Token.OP_ADD_ASSIGN:
7611 case Token.OP_SUB_ASSIGN:
7613 case Token.OP_SHIFT_LEFT_ASSIGN:
7615 case Token.OP_SHIFT_RIGHT_ASSIGN:
7617 case Token.OP_AND_ASSIGN:
7619 case Token.OP_XOR_ASSIGN:
7621 case Token.OP_OR_ASSIGN:
7625 return GetTokenName (token);
7628 static string GetTokenName (int token)
7631 case Token.ABSTRACT:
7653 case Token.CONTINUE:
7657 case Token.DELEGATE:
7667 case Token.EXPLICIT:
7670 case Token.EXTERN_ALIAS:
7686 case Token.IMPLICIT:
7690 case Token.INTERFACE:
7692 case Token.INTERNAL:
7698 case Token.NAMESPACE:
7704 case Token.OPERATOR:
7708 case Token.OVERRIDE:
7714 case Token.PROTECTED:
7718 case Token.READONLY:
7730 case Token.STACKALLOC:
7731 return "stackalloc";
7748 case Token.UNCHECKED:
7756 case Token.VOLATILE:
7764 case Token.REFVALUE:
7765 return "__refvalue";
7775 case Token.FROM_FIRST:
7793 case Token.ASCENDING:
7795 case Token.DESCENDING:
7796 return "descending";
7803 case Token.OPEN_BRACE:
7805 case Token.CLOSE_BRACE:
7807 case Token.OPEN_BRACKET:
7808 case Token.OPEN_BRACKET_EXPR:
7810 case Token.CLOSE_BRACKET:
7812 case Token.OPEN_PARENS_CAST:
7813 case Token.OPEN_PARENS_LAMBDA:
7814 case Token.OPEN_PARENS:
7816 case Token.CLOSE_PARENS:
7822 case Token.DEFAULT_COLON:
7826 case Token.SEMICOLON:
7837 case Token.BITWISE_AND:
7838 case Token.BITWISE_OR:
7845 case Token.OP_SHIFT_LEFT:
7846 case Token.OP_SHIFT_RIGHT:
7854 case Token.OP_COALESCING:
7855 case Token.OP_MULT_ASSIGN:
7856 case Token.OP_DIV_ASSIGN:
7857 case Token.OP_MOD_ASSIGN:
7858 case Token.OP_ADD_ASSIGN:
7859 case Token.OP_SUB_ASSIGN:
7860 case Token.OP_SHIFT_LEFT_ASSIGN:
7861 case Token.OP_SHIFT_RIGHT_ASSIGN:
7862 case Token.OP_AND_ASSIGN:
7863 case Token.OP_XOR_ASSIGN:
7864 case Token.OP_OR_ASSIGN:
7865 return "<operator>";
7887 case Token.OP_GENERICS_LT:
7888 case Token.GENERIC_DIMENSION:
7890 case Token.OP_GENERICS_GT:
7893 case Token.INTERR_NULLABLE:
7895 case Token.DOUBLE_COLON:
7899 case Token.IDENTIFIER:
7901 return "identifier";
7904 return "end-of-file";
7906 // All of these are internal.
7909 case Token.FIRST_KEYWORD:
7910 case Token.EVAL_COMPILATION_UNIT_PARSER:
7911 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7912 case Token.EVAL_STATEMENT_PARSER:
7913 case Token.LAST_KEYWORD:
7914 case Token.GENERATE_COMPLETION:
7915 case Token.COMPLETE_COMPLETION:
7916 return "<internal>";
7918 // A bit more robust.
7920 return yyNames [token];