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 | destructor_declaration
928 | attributes_without_members
932 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
933 GetSymbolName (yyToken));
935 lexer.parsing_generic_declaration = false;
946 type_declaration_name
948 lexer.ConstraintsParsing = true;
949 valid_param_mod = ParameterModifierType.PrimaryConstructor;
950 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
952 opt_primary_parameters
954 opt_type_parameter_constraints_clauses
957 lexer.ConstraintsParsing = false;
960 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
963 current_container.SetConstraints ((List<Constraints>) $10);
966 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
968 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
970 lexer.parsing_modifiers = true;
975 Lexer.doc_state = XmlCommentState.Allowed;
977 opt_class_member_declarations CLOSE_BRACE
979 --lexer.parsing_declaration;
981 Lexer.doc_state = XmlCommentState.Allowed;
986 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
988 lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
990 $$ = pop_current_class ();
992 | opt_attributes opt_modifiers opt_partial STRUCT error
994 Error_SyntaxError (yyToken);
1001 CONST type IDENTIFIER
1003 var lt = (LocatedToken) $5;
1004 var mod = (Modifiers) $2;
1005 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1006 current_type.AddMember (current_field);
1008 if ((mod & Modifiers.STATIC) != 0) {
1009 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1014 constant_initializer opt_constant_declarators SEMICOLON
1017 current_field.DocComment = Lexer.consume_doc_comment ();
1018 Lexer.doc_state = XmlCommentState.Allowed;
1021 current_field.Initializer = (ConstInitializer) $7;
1022 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1023 current_field = null;
1029 Error_SyntaxError (yyToken);
1031 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1035 opt_constant_declarators
1037 | constant_declarators
1040 constant_declarators
1041 : constant_declarator
1043 current_field.AddDeclarator ((FieldDeclarator) $1);
1045 | constant_declarators constant_declarator
1047 current_field.AddDeclarator ((FieldDeclarator) $2);
1052 : COMMA IDENTIFIER constant_initializer
1054 var lt = (LocatedToken) $2;
1055 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1056 lbag.AddLocation ($$, GetLocation ($1));
1060 constant_initializer
1063 ++lexer.parsing_block;
1065 constant_initializer_expr
1067 --lexer.parsing_block;
1068 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1072 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1077 constant_initializer_expr
1078 : constant_expression
1085 member_type IDENTIFIER
1087 lexer.parsing_generic_declaration = false;
1089 FullNamedExpression type = (FullNamedExpression) $3;
1090 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1091 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1093 var lt = (LocatedToken) $4;
1094 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1095 current_type.AddField (current_field);
1098 opt_field_initializer
1099 opt_field_declarators
1103 current_field.DocComment = Lexer.consume_doc_comment ();
1104 Lexer.doc_state = XmlCommentState.Allowed;
1107 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1109 current_field = null;
1113 FIXED simple_type IDENTIFIER
1115 if (lang_version < LanguageVersion.ISO_2)
1116 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1118 var lt = (LocatedToken) $5;
1119 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1120 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1122 current_type.AddField (current_field);
1124 fixed_field_size opt_fixed_field_declarators SEMICOLON
1127 current_field.DocComment = Lexer.consume_doc_comment ();
1128 Lexer.doc_state = XmlCommentState.Allowed;
1131 current_field.Initializer = (ConstInitializer) $7;
1132 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1134 current_field = null;
1138 FIXED simple_type error
1141 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1145 opt_field_initializer
1149 ++lexer.parsing_block;
1150 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1151 start_block (GetLocation ($1));
1153 variable_initializer
1155 --lexer.parsing_block;
1156 current_field.Initializer = (Expression) $3;
1157 lbag.AppendToMember (current_field, GetLocation ($1));
1158 end_block (lexer.Location);
1159 current_local_parameters = null;
1163 opt_field_declarators
1171 current_field.AddDeclarator ((FieldDeclarator) $1);
1173 | field_declarators field_declarator
1175 current_field.AddDeclarator ((FieldDeclarator) $2);
1182 var lt = (LocatedToken) $2;
1183 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1184 lbag.AddLocation ($$, GetLocation ($1));
1186 | COMMA IDENTIFIER ASSIGN
1188 ++lexer.parsing_block;
1190 variable_initializer
1192 --lexer.parsing_block;
1193 var lt = (LocatedToken) $2;
1194 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1195 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1199 opt_fixed_field_declarators
1201 | fixed_field_declarators
1204 fixed_field_declarators
1205 : fixed_field_declarator
1207 current_field.AddDeclarator ((FieldDeclarator) $1);
1209 | fixed_field_declarators fixed_field_declarator
1211 current_field.AddDeclarator ((FieldDeclarator) $2);
1215 fixed_field_declarator
1216 : COMMA IDENTIFIER fixed_field_size
1218 var lt = (LocatedToken) $2;
1219 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1220 lbag.AddLocation ($$, GetLocation ($1));
1227 ++lexer.parsing_block;
1229 expression CLOSE_BRACKET
1231 --lexer.parsing_block;
1232 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1233 lbag.AddLocation ($$, GetLocation ($4));
1235 | OPEN_BRACKET error
1237 report.Error (443, lexer.Location, "Value or constant expected");
1242 variable_initializer
1247 // It has to be here for the parent to safely restore artificial block
1248 Error_SyntaxError (yyToken);
1257 Lexer.doc_state = XmlCommentState.NotAllowed;
1259 // Was added earlier in the case of body being eof for full ast
1263 Method method = (Method) $1;
1264 method.Block = (ToplevelBlock) $3;
1265 async_block = false;
1267 if (method.Block == null) {
1268 method.ParameterInfo.CheckParameters (method);
1270 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1271 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1272 method.GetSignatureForError ());
1275 if (current_container.Kind == MemberKind.Interface) {
1276 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1277 method.GetSignatureForError ());
1281 current_local_parameters = null;
1284 Lexer.doc_state = XmlCommentState.Allowed;
1292 method_declaration_name OPEN_PARENS
1294 valid_param_mod = ParameterModifierType.All;
1296 opt_formal_parameter_list CLOSE_PARENS
1298 valid_param_mod = 0;
1299 MemberName name = (MemberName) $4;
1300 current_local_parameters = (ParametersCompiled) $7;
1302 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1303 name, current_local_parameters, (Attributes) $1);
1305 current_type.AddMember (method);
1307 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1310 method.DocComment = Lexer.consume_doc_comment ();
1312 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1316 lexer.ConstraintsParsing = true;
1318 opt_type_parameter_constraints_clauses
1320 lexer.ConstraintsParsing = false;
1323 var method = (Method) $9;
1324 method.SetConstraints ((List<Constraints>) $10);
1334 lexer.parsing_generic_declaration = true;
1336 method_declaration_name
1339 lexer.parsing_generic_declaration = false;
1340 valid_param_mod = ParameterModifierType.All;
1342 opt_formal_parameter_list CLOSE_PARENS
1344 lexer.ConstraintsParsing = true;
1346 opt_type_parameter_constraints_clauses
1348 lexer.ConstraintsParsing = false;
1349 valid_param_mod = 0;
1351 MemberName name = (MemberName) $6;
1352 current_local_parameters = (ParametersCompiled) $9;
1354 var modifiers = (Modifiers) $2;
1355 modifiers |= Modifiers.PARTIAL;
1357 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1358 modifiers, name, current_local_parameters, (Attributes) $1);
1360 current_type.AddMember (method);
1362 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1365 method.SetConstraints ((List<Constraints>) $12);
1368 method.DocComment = Lexer.consume_doc_comment ();
1370 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1371 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1377 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1379 MemberName name = (MemberName) $5;
1380 report.Error (1585, name.Location,
1381 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1383 var method = Method.Create (current_type, (FullNamedExpression) $3,
1384 0, name, (ParametersCompiled) $7, (Attributes) $1);
1386 current_type.AddMember (method);
1388 current_local_parameters = (ParametersCompiled) $7;
1391 method.DocComment = Lexer.consume_doc_comment ();
1398 method_declaration_name error
1400 Error_SyntaxError (yyToken);
1401 current_local_parameters = ParametersCompiled.Undefined;
1403 MemberName name = (MemberName) $4;
1404 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1405 name, current_local_parameters, (Attributes) $1);
1407 current_type.AddMember (method);
1410 method.DocComment = Lexer.consume_doc_comment ();
1418 | SEMICOLON { $$ = null; }
1421 opt_formal_parameter_list
1422 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1423 | formal_parameter_list
1426 formal_parameter_list
1429 var pars_list = (List<Parameter>) $1;
1430 $$ = new ParametersCompiled (pars_list.ToArray ());
1432 | fixed_parameters COMMA parameter_array
1434 var pars_list = (List<Parameter>) $1;
1435 pars_list.Add ((Parameter) $3);
1437 $$ = new ParametersCompiled (pars_list.ToArray ());
1439 | fixed_parameters COMMA arglist_modifier
1441 var pars_list = (List<Parameter>) $1;
1442 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1443 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1445 | parameter_array COMMA error
1448 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1450 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1452 | fixed_parameters COMMA parameter_array COMMA error
1455 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1457 var pars_list = (List<Parameter>) $1;
1458 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1460 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1462 | arglist_modifier COMMA error
1464 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1466 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1468 | fixed_parameters COMMA ARGLIST COMMA error
1470 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1472 var pars_list = (List<Parameter>) $1;
1473 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1475 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1479 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1483 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1487 Error_SyntaxError (yyToken);
1488 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1495 parameters_bucket.Clear ();
1496 Parameter p = (Parameter) $1;
1497 parameters_bucket.Add (p);
1499 default_parameter_used = p.HasDefaultValue;
1500 $$ = parameters_bucket;
1502 | fixed_parameters COMMA fixed_parameter
1504 var pars = (List<Parameter>) $1;
1505 Parameter p = (Parameter) $3;
1507 if (p.HasExtensionMethodModifier)
1508 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1509 else if (!p.HasDefaultValue && default_parameter_used)
1510 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1512 default_parameter_used |= p.HasDefaultValue;
1515 lbag.AddLocation (p, GetLocation ($2));
1524 opt_parameter_modifier
1526 identifier_inside_body
1528 var lt = (LocatedToken) $4;
1529 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1532 opt_parameter_modifier
1534 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1536 var lt = (LocatedToken) $4;
1537 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1538 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1540 | attribute_sections error
1542 Error_SyntaxError (yyToken);
1543 Location l = GetLocation ($2);
1544 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1547 opt_parameter_modifier
1551 Error_SyntaxError (yyToken);
1552 Location l = GetLocation ($4);
1553 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1556 opt_parameter_modifier
1558 identifier_inside_body
1561 ++lexer.parsing_block;
1565 --lexer.parsing_block;
1566 if (lang_version <= LanguageVersion.V_3) {
1567 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1570 Parameter.Modifier mod = (Parameter.Modifier) $2;
1571 if (mod != Parameter.Modifier.NONE) {
1573 case Parameter.Modifier.REF:
1574 case Parameter.Modifier.OUT:
1575 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1576 Parameter.GetModifierSignature (mod));
1579 case Parameter.Modifier.This:
1580 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1581 Parameter.GetModifierSignature (mod));
1584 throw new NotImplementedException (mod.ToString ());
1587 mod = Parameter.Modifier.NONE;
1590 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1591 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1593 var lt = (LocatedToken) $4;
1594 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1595 lbag.AddLocation ($$, GetLocation ($5));
1598 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1602 opt_parameter_modifier
1603 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1604 | parameter_modifiers
1608 : parameter_modifier
1612 | parameter_modifiers parameter_modifier
1614 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1615 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1616 if (((Parameter.Modifier)$1 & p2) == p2) {
1617 Error_DuplicateParameterModifier (lexer.Location, p2);
1619 switch (mod & ~Parameter.Modifier.This) {
1620 case Parameter.Modifier.REF:
1621 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1623 case Parameter.Modifier.OUT:
1624 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1627 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1638 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1639 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1641 $$ = Parameter.Modifier.REF;
1645 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1646 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1648 $$ = Parameter.Modifier.OUT;
1652 if ((valid_param_mod & ParameterModifierType.This) == 0)
1653 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1655 if (lang_version <= LanguageVersion.ISO_2)
1656 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1658 $$ = Parameter.Modifier.This;
1663 : opt_attributes params_modifier type IDENTIFIER
1665 var lt = (LocatedToken) $4;
1666 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1668 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1670 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1672 var lt = (LocatedToken) $4;
1673 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1675 | opt_attributes params_modifier type error
1677 Error_SyntaxError (yyToken);
1679 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1686 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1687 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1689 | PARAMS parameter_modifier
1691 Parameter.Modifier mod = (Parameter.Modifier)$2;
1692 if ((mod & Parameter.Modifier.This) != 0) {
1693 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1695 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1698 | PARAMS params_modifier
1700 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1707 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1708 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1712 property_declaration
1716 member_declaration_name
1719 tmpComment = Lexer.consume_doc_comment ();
1723 var type = (FullNamedExpression) $3;
1724 current_property = new Property (current_type, type, (Modifiers) $2,
1725 (MemberName) $4, (Attributes) $1);
1727 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1728 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1730 current_type.AddMember (current_property);
1731 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1733 lexer.PropertyParsing = true;
1735 accessor_declarations
1737 lexer.PropertyParsing = false;
1740 current_property.DocComment = ConsumeStoredComment ();
1744 lbag.AppendToMember (current_property, GetLocation ($10));
1745 current_property = null;
1751 : opt_attributes opt_modifiers
1752 member_type indexer_declaration_name OPEN_BRACKET
1754 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1756 opt_formal_parameter_list CLOSE_BRACKET
1758 valid_param_mod = 0;
1759 var type = (FullNamedExpression) $3;
1760 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1762 current_property = indexer;
1764 current_type.AddIndexer (indexer);
1765 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1767 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1768 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1770 if (indexer.ParameterInfo.IsEmpty) {
1771 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1775 tmpComment = Lexer.consume_doc_comment ();
1776 Lexer.doc_state = XmlCommentState.Allowed;
1779 lexer.PropertyParsing = true;
1781 OPEN_BRACE accessor_declarations
1783 lexer.PropertyParsing = false;
1787 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1788 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1791 current_property.DocComment = ConsumeStoredComment ();
1793 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1794 current_property = null;
1799 accessor_declarations
1800 : get_accessor_declaration
1801 | get_accessor_declaration accessor_declarations
1802 | set_accessor_declaration
1803 | set_accessor_declaration accessor_declarations
1806 if (yyToken == Token.CLOSE_BRACE) {
1807 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1809 if (yyToken == Token.SEMICOLON)
1810 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1812 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1817 get_accessor_declaration
1818 : opt_attributes opt_modifiers GET
1820 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1821 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1824 if (current_property.Get != null) {
1825 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1828 if (current_property is Indexer) {
1829 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1830 (Attributes) $1, GetLocation ($3));
1832 current_property.Get = new Property.GetMethod (current_property,
1833 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1836 current_local_parameters = current_property.Get.ParameterInfo;
1837 lbag.AddMember (current_property.Get, mod_locations);
1838 lexer.PropertyParsing = false;
1843 current_property.Get.Block = (ToplevelBlock) $5;
1845 if (current_container.Kind == MemberKind.Interface) {
1846 report.Error (531, current_property.Get.Block.StartLocation,
1847 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1851 current_local_parameters = null;
1852 lexer.PropertyParsing = true;
1855 if (Lexer.doc_state == XmlCommentState.Error)
1856 Lexer.doc_state = XmlCommentState.NotAllowed;
1860 set_accessor_declaration
1861 : opt_attributes opt_modifiers SET
1863 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1864 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1867 if (current_property.Set != null) {
1868 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1871 if (current_property is Indexer) {
1872 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1873 ParametersCompiled.MergeGenerated (compiler,
1874 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1875 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1877 (Attributes) $1, GetLocation ($3));
1879 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1880 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1881 (Attributes) $1, GetLocation ($3));
1884 current_local_parameters = current_property.Set.ParameterInfo;
1885 lbag.AddMember (current_property.Set, mod_locations);
1886 lexer.PropertyParsing = false;
1891 current_property.Set.Block = (ToplevelBlock) $5;
1893 if (current_container.Kind == MemberKind.Interface) {
1894 report.Error (531, current_property.Set.Block.StartLocation,
1895 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1899 current_local_parameters = null;
1900 lexer.PropertyParsing = true;
1903 && Lexer.doc_state == XmlCommentState.Error)
1904 Lexer.doc_state = XmlCommentState.NotAllowed;
1917 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1922 interface_declaration
1929 type_declaration_name
1931 lexer.ConstraintsParsing = true;
1932 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1933 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1936 opt_type_parameter_constraints_clauses
1938 lexer.ConstraintsParsing = false;
1941 current_container.SetConstraints ((List<Constraints>) $9);
1944 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1945 Lexer.doc_state = XmlCommentState.Allowed;
1948 lexer.parsing_modifiers = true;
1950 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1952 --lexer.parsing_declaration;
1954 Lexer.doc_state = XmlCommentState.Allowed;
1959 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1961 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
1963 $$ = pop_current_class ();
1965 | opt_attributes opt_modifiers opt_partial INTERFACE error
1967 Error_SyntaxError (yyToken);
1971 opt_interface_member_declarations
1973 | interface_member_declarations
1976 interface_member_declarations
1977 : interface_member_declaration
1979 lexer.parsing_modifiers = true;
1980 lexer.parsing_block = 0;
1982 | interface_member_declarations interface_member_declaration
1984 lexer.parsing_modifiers = true;
1985 lexer.parsing_block = 0;
1989 interface_member_declaration
1990 : constant_declaration
1992 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1996 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1998 | method_declaration
1999 | property_declaration
2001 | indexer_declaration
2002 | operator_declaration
2004 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
2006 | constructor_declaration
2008 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2012 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2016 operator_declaration
2017 : opt_attributes opt_modifiers operator_declarator
2022 OperatorDeclaration decl = (OperatorDeclaration) $3;
2024 Operator op = new Operator (
2025 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2026 current_local_parameters,
2027 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2029 if (op.Block == null)
2030 op.ParameterInfo.CheckParameters (op);
2033 op.DocComment = tmpComment;
2034 Lexer.doc_state = XmlCommentState.Allowed;
2037 // Note again, checking is done in semantic analysis
2038 current_type.AddOperator (op);
2040 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2043 current_local_parameters = null;
2049 | SEMICOLON { $$ = null; }
2053 : type_expression_or_array
2056 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2057 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2062 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2064 valid_param_mod = ParameterModifierType.DefaultValue;
2066 opt_formal_parameter_list CLOSE_PARENS
2068 valid_param_mod = 0;
2070 Location loc = GetLocation ($2);
2071 Operator.OpType op = (Operator.OpType) $3;
2072 current_local_parameters = (ParametersCompiled)$6;
2074 int p_count = current_local_parameters.Count;
2076 if (op == Operator.OpType.Addition)
2077 op = Operator.OpType.UnaryPlus;
2078 else if (op == Operator.OpType.Subtraction)
2079 op = Operator.OpType.UnaryNegation;
2082 if (IsUnaryOperator (op)) {
2084 report.Error (1020, loc, "Overloadable binary operator expected");
2085 } else if (p_count != 1) {
2086 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2087 Operator.GetName (op));
2091 report.Error (1019, loc, "Overloadable unary operator expected");
2092 } else if (p_count != 2) {
2093 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2094 Operator.GetName (op));
2099 tmpComment = Lexer.consume_doc_comment ();
2100 Lexer.doc_state = XmlCommentState.NotAllowed;
2103 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2104 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2106 | conversion_operator_declarator
2109 overloadable_operator
2111 : BANG { $$ = Operator.OpType.LogicalNot; }
2112 | TILDE { $$ = Operator.OpType.OnesComplement; }
2113 | OP_INC { $$ = Operator.OpType.Increment; }
2114 | OP_DEC { $$ = Operator.OpType.Decrement; }
2115 | TRUE { $$ = Operator.OpType.True; }
2116 | FALSE { $$ = Operator.OpType.False; }
2117 // Unary and binary:
2118 | PLUS { $$ = Operator.OpType.Addition; }
2119 | MINUS { $$ = Operator.OpType.Subtraction; }
2121 | STAR { $$ = Operator.OpType.Multiply; }
2122 | DIV { $$ = Operator.OpType.Division; }
2123 | PERCENT { $$ = Operator.OpType.Modulus; }
2124 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2125 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2126 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2127 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2128 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2129 | OP_EQ { $$ = Operator.OpType.Equality; }
2130 | OP_NE { $$ = Operator.OpType.Inequality; }
2131 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2132 | OP_LT { $$ = Operator.OpType.LessThan; }
2133 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2134 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2137 conversion_operator_declarator
2138 : IMPLICIT OPERATOR type OPEN_PARENS
2140 valid_param_mod = ParameterModifierType.DefaultValue;
2142 opt_formal_parameter_list CLOSE_PARENS
2144 valid_param_mod = 0;
2146 Location loc = GetLocation ($2);
2147 current_local_parameters = (ParametersCompiled)$6;
2149 if (current_local_parameters.Count != 1) {
2150 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2154 tmpComment = Lexer.consume_doc_comment ();
2155 Lexer.doc_state = XmlCommentState.NotAllowed;
2158 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2159 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2161 | EXPLICIT OPERATOR type OPEN_PARENS
2163 valid_param_mod = ParameterModifierType.DefaultValue;
2165 opt_formal_parameter_list CLOSE_PARENS
2167 valid_param_mod = 0;
2169 Location loc = GetLocation ($2);
2170 current_local_parameters = (ParametersCompiled)$6;
2172 if (current_local_parameters.Count != 1) {
2173 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2177 tmpComment = Lexer.consume_doc_comment ();
2178 Lexer.doc_state = XmlCommentState.NotAllowed;
2181 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2182 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2186 Error_SyntaxError (yyToken);
2187 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2188 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2192 Error_SyntaxError (yyToken);
2193 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2194 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2198 constructor_declaration
2199 : constructor_declarator
2202 Constructor c = (Constructor) $1;
2203 c.Block = (ToplevelBlock) $2;
2206 c.DocComment = ConsumeStoredComment ();
2208 current_local_parameters = null;
2210 Lexer.doc_state = XmlCommentState.Allowed;
2214 constructor_declarator
2220 tmpComment = Lexer.consume_doc_comment ();
2221 Lexer.doc_state = XmlCommentState.Allowed;
2224 valid_param_mod = ParameterModifierType.All;
2226 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2228 valid_param_mod = 0;
2229 current_local_parameters = (ParametersCompiled) $6;
2231 var lt = (LocatedToken) $3;
2232 var mods = (Modifiers) $2;
2233 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2235 if (lt.Value != current_container.MemberName.Name) {
2236 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2237 } else if ((mods & Modifiers.STATIC) != 0) {
2238 if ((mods & Modifiers.AccessibilityMask) != 0){
2239 report.Error (515, c.Location,
2240 "`{0}': static constructor cannot have an access modifier",
2241 c.GetSignatureForError ());
2245 current_type.AddConstructor (c);
2246 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2250 // start block here, so possible anonymous methods inside
2251 // constructor initializer can get correct parent block
2253 start_block (lexer.Location);
2255 opt_constructor_initializer
2258 var c = (Constructor) $8;
2259 c.Initializer = (ConstructorInitializer) $9;
2262 report.Error (514, c.Location,
2263 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2264 c.GetSignatureForError ());
2274 | SEMICOLON { current_block = null; $$ = null; }
2277 opt_constructor_initializer
2279 | constructor_initializer
2282 constructor_initializer
2283 : COLON BASE OPEN_PARENS
2285 ++lexer.parsing_block;
2287 opt_argument_list CLOSE_PARENS
2289 --lexer.parsing_block;
2290 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2291 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2293 | COLON THIS OPEN_PARENS
2295 ++lexer.parsing_block;
2297 opt_argument_list CLOSE_PARENS
2299 --lexer.parsing_block;
2300 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2301 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2305 Error_SyntaxError (yyToken);
2306 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2307 lbag.AddLocation ($$, GetLocation ($1));
2311 Error_SyntaxError (yyToken);
2316 destructor_declaration
2317 : opt_attributes opt_modifiers TILDE
2320 tmpComment = Lexer.consume_doc_comment ();
2321 Lexer.doc_state = XmlCommentState.NotAllowed;
2324 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2326 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2328 var lt = (LocatedToken) $5;
2329 if (lt.Value != current_container.MemberName.Name){
2330 report.Error (574, lt.Location, "Name of destructor must match name of class");
2331 } else if (current_container.Kind != MemberKind.Class){
2332 report.Error (575, lt.Location, "Only class types can contain destructor");
2335 Destructor d = new Destructor (current_type, (Modifiers) $2,
2336 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2338 d.DocComment = ConsumeStoredComment ();
2340 d.Block = (ToplevelBlock) $8;
2341 current_type.AddMember (d);
2342 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2344 current_local_parameters = null;
2351 EVENT type member_declaration_name
2353 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2354 current_type.AddMember (current_event_field);
2356 if (current_event_field.MemberName.ExplicitInterface != null) {
2357 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2358 current_event_field.GetSignatureForError ());
2361 $$ = current_event_field;
2363 opt_event_initializer
2364 opt_event_declarators
2368 current_event_field.DocComment = Lexer.consume_doc_comment ();
2369 Lexer.doc_state = XmlCommentState.Allowed;
2372 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2373 current_event_field = null;
2377 EVENT type member_declaration_name
2380 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2381 current_type.AddMember (current_event);
2382 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2384 lexer.EventParsing = true;
2386 event_accessor_declarations
2388 if (current_container.Kind == MemberKind.Interface)
2389 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2391 lexer.EventParsing = false;
2396 current_event.DocComment = Lexer.consume_doc_comment ();
2397 Lexer.doc_state = XmlCommentState.Allowed;
2400 lbag.AppendToMember (current_event, GetLocation ($9));
2401 current_event = null;
2402 current_local_parameters = null;
2408 Error_SyntaxError (yyToken);
2410 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2414 opt_event_initializer
2418 ++lexer.parsing_block;
2420 event_variable_initializer
2422 --lexer.parsing_block;
2423 current_event_field.Initializer = (Expression) $3;
2427 opt_event_declarators
2435 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2437 | event_declarators event_declarator
2439 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2446 var lt = (LocatedToken) $2;
2447 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2448 lbag.AddLocation ($$, GetLocation ($1));
2450 | COMMA IDENTIFIER ASSIGN
2452 ++lexer.parsing_block;
2454 event_variable_initializer
2456 --lexer.parsing_block;
2457 var lt = (LocatedToken) $2;
2458 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2459 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2463 event_variable_initializer
2465 if (current_container.Kind == MemberKind.Interface) {
2466 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2467 current_event_field.GetSignatureForError ());
2470 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2471 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2472 current_event_field.GetSignatureForError ());
2475 variable_initializer
2481 event_accessor_declarations
2482 : add_accessor_declaration remove_accessor_declaration
2483 | remove_accessor_declaration add_accessor_declaration
2484 | add_accessor_declaration
2486 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2487 current_event.GetSignatureForError ());
2489 | remove_accessor_declaration
2491 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2492 current_event.GetSignatureForError ());
2496 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2501 add_accessor_declaration
2502 : opt_attributes opt_modifiers ADD
2504 if ($2 != ModifierNone) {
2505 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2508 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2509 current_local_parameters = current_event.Add.ParameterInfo;
2511 lbag.AddMember (current_event.Add, mod_locations);
2512 lexer.EventParsing = false;
2514 event_accessor_block
2516 lexer.EventParsing = true;
2518 current_event.Add.Block = (ToplevelBlock) $5;
2520 if (current_container.Kind == MemberKind.Interface) {
2521 report.Error (531, current_event.Add.Block.StartLocation,
2522 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2525 current_local_parameters = null;
2529 remove_accessor_declaration
2530 : opt_attributes opt_modifiers REMOVE
2532 if ($2 != ModifierNone) {
2533 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2536 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2537 current_local_parameters = current_event.Remove.ParameterInfo;
2539 lbag.AddMember (current_event.Remove, mod_locations);
2540 lexer.EventParsing = false;
2542 event_accessor_block
2544 lexer.EventParsing = true;
2546 current_event.Remove.Block = (ToplevelBlock) $5;
2548 if (current_container.Kind == MemberKind.Interface) {
2549 report.Error (531, current_event.Remove.Block.StartLocation,
2550 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2553 current_local_parameters = null;
2557 event_accessor_block
2560 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2566 attributes_without_members
2567 : attribute_sections CLOSE_BRACE
2569 current_type.UnattachedAttributes = (Attributes) $1;
2570 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2571 lexer.putback ('}');
2575 // For full ast try to recover incomplete ambiguous member
2576 // declaration in form on class X { public int }
2578 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2580 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2582 lexer.putback ('}');
2584 lexer.parsing_generic_declaration = false;
2585 FullNamedExpression type = (FullNamedExpression) $3;
2586 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2587 current_type.AddField (current_field);
2595 ENUM type_declaration_name
2599 enumTypeComment = Lexer.consume_doc_comment ();
2604 Lexer.doc_state = XmlCommentState.Allowed;
2606 MemberName name = (MemberName) $4;
2607 if (name.IsGeneric) {
2608 report.Error (1675, name.Location, "Enums cannot have type parameters");
2611 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2613 opt_enum_member_declarations
2615 lexer.parsing_modifiers = true;
2617 // here will be evaluated after CLOSE_BLACE is consumed.
2619 Lexer.doc_state = XmlCommentState.Allowed;
2621 CLOSE_BRACE opt_semicolon
2624 current_container.DocComment = enumTypeComment;
2626 --lexer.parsing_declaration;
2629 // em.DocComment = ev.DocComment;
2631 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2632 $$ = pop_current_class ();
2640 var te = $2 as TypeExpression;
2641 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2642 Enum.Error_1008 (GetLocation ($2), report);
2648 Error_TypeExpected (GetLocation ($1));
2653 opt_enum_member_declarations
2655 | enum_member_declarations
2656 | enum_member_declarations COMMA
2658 lbag.AddLocation ($1, GetLocation ($2));
2662 enum_member_declarations
2663 : enum_member_declaration
2664 | enum_member_declarations COMMA enum_member_declaration
2666 lbag.AddLocation ($1, GetLocation ($2));
2671 enum_member_declaration
2672 : opt_attributes IDENTIFIER
2674 var lt = (LocatedToken) $2;
2675 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2676 ((Enum) current_type).AddEnumMember (em);
2679 em.DocComment = Lexer.consume_doc_comment ();
2680 Lexer.doc_state = XmlCommentState.Allowed;
2685 | opt_attributes IDENTIFIER
2687 ++lexer.parsing_block;
2689 tmpComment = Lexer.consume_doc_comment ();
2690 Lexer.doc_state = XmlCommentState.NotAllowed;
2693 ASSIGN constant_expression
2695 --lexer.parsing_block;
2697 var lt = (LocatedToken) $2;
2698 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2699 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2700 ((Enum) current_type).AddEnumMember (em);
2703 em.DocComment = ConsumeStoredComment ();
2707 | opt_attributes IDENTIFIER error
2709 Error_SyntaxError (yyToken);
2711 var lt = (LocatedToken) $2;
2712 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2713 ((Enum) current_type).AddEnumMember (em);
2716 em.DocComment = Lexer.consume_doc_comment ();
2717 Lexer.doc_state = XmlCommentState.Allowed;
2722 | attributes_without_members
2725 delegate_declaration
2729 member_type type_declaration_name
2732 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2734 opt_formal_parameter_list CLOSE_PARENS
2736 valid_param_mod = 0;
2738 ParametersCompiled p = (ParametersCompiled) $8;
2740 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2742 p.CheckParameters (del);
2744 current_container.AddTypeContainer (del);
2746 current_delegate = del;
2747 lexer.ConstraintsParsing = true;
2749 opt_type_parameter_constraints_clauses
2751 lexer.ConstraintsParsing = false;
2756 current_delegate.DocComment = Lexer.consume_doc_comment ();
2757 Lexer.doc_state = XmlCommentState.Allowed;
2761 current_delegate.SetConstraints ((List<Constraints>) $11);
2762 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2764 $$ = current_delegate;
2766 current_delegate = null;
2774 if (lang_version < LanguageVersion.ISO_2)
2775 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2777 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2781 namespace_or_type_expr
2783 | qualified_alias_member IDENTIFIER opt_type_argument_list
2785 var lt1 = (LocatedToken) $1;
2786 var lt2 = (LocatedToken) $2;
2788 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2789 lbag.AddLocation ($$, GetLocation ($2));
2795 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2797 var lt = (LocatedToken) $3;
2798 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2799 lbag.AddLocation ($$, GetLocation ($2));
2804 : IDENTIFIER opt_type_argument_list
2806 var lt = (LocatedToken) $1;
2807 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2812 // Generics arguments (any type, without attributes)
2814 opt_type_argument_list
2816 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2818 if (lang_version < LanguageVersion.ISO_2)
2819 FeatureIsNotAvailable (GetLocation ($1), "generics");
2823 | OP_GENERICS_LT error
2825 Error_TypeExpected (lexer.Location);
2826 $$ = new TypeArguments ();
2833 TypeArguments type_args = new TypeArguments ();
2834 type_args.Add ((FullNamedExpression) $1);
2837 | type_arguments COMMA type
2839 TypeArguments type_args = (TypeArguments) $1;
2840 type_args.Add ((FullNamedExpression) $3);
2846 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2848 type_declaration_name
2851 lexer.parsing_generic_declaration = true;
2853 opt_type_parameter_list
2855 lexer.parsing_generic_declaration = false;
2856 var lt = (LocatedToken) $1;
2857 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2861 member_declaration_name
2862 : method_declaration_name
2864 MemberName mn = (MemberName)$1;
2865 if (mn.TypeParameters != null)
2866 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2867 mn.GetSignatureForError ()));
2871 method_declaration_name
2872 : type_declaration_name
2873 | explicit_interface IDENTIFIER opt_type_parameter_list
2875 lexer.parsing_generic_declaration = false;
2876 var lt = (LocatedToken) $2;
2877 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2881 indexer_declaration_name
2884 lexer.parsing_generic_declaration = false;
2885 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2887 | explicit_interface THIS
2889 lexer.parsing_generic_declaration = false;
2890 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2895 : IDENTIFIER opt_type_argument_list DOT
2897 var lt = (LocatedToken) $1;
2898 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2899 lbag.AddLocation ($$, GetLocation ($3));
2901 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2903 var lt1 = (LocatedToken) $1;
2904 var lt2 = (LocatedToken) $2;
2906 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2907 lbag.AddLocation ($$, GetLocation ($4));
2909 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2911 var lt = (LocatedToken) $2;
2912 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2913 lbag.AddLocation ($$, GetLocation ($4));
2917 opt_type_parameter_list
2919 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2921 if (lang_version < LanguageVersion.ISO_2)
2922 FeatureIsNotAvailable (GetLocation ($1), "generics");
2925 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2932 var tparams = new TypeParameters ();
2933 tparams.Add ((TypeParameter)$1);
2936 | type_parameters COMMA type_parameter
2938 var tparams = (TypeParameters) $1;
2939 tparams.Add ((TypeParameter)$3);
2941 lbag.AddLocation ($3, GetLocation ($3));
2946 : opt_attributes opt_type_parameter_variance IDENTIFIER
2948 var lt = (LocatedToken)$3;
2949 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
2953 if (GetTokenName (yyToken) == "type")
2954 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2956 Error_SyntaxError (yyToken);
2958 $$ = new TypeParameter (MemberName.Null, null, null);
2963 // All types where void is allowed
2966 : type_expression_or_array
2969 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2976 lexer.parsing_generic_declaration = true;
2981 // A type which does not allow `void' to be used
2984 : type_expression_or_array
2987 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2988 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2996 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2997 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3002 : type_expression_or_array
3005 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
3006 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3010 type_expression_or_array
3012 | type_expression rank_specifiers
3014 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3019 : namespace_or_type_expr opt_nullable
3022 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3024 var sn = $1 as SimpleName;
3025 if (sn != null && sn.Name == "var")
3026 $$ = new VarExpr (sn.Location);
3031 | namespace_or_type_expr pointer_stars
3033 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3035 | builtin_types opt_nullable
3038 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3040 | builtin_types pointer_stars
3042 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3044 | VOID pointer_stars
3046 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3053 var types = new List<FullNamedExpression> (2);
3054 types.Add ((FullNamedExpression) $1);
3057 | type_list COMMA base_type_name
3059 var types = (List<FullNamedExpression>) $1;
3060 types.Add ((FullNamedExpression) $3);
3068 if ($1 is ComposedCast) {
3069 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3076 * replaces all the productions for isolating the various
3077 * simple types, but we need this to reuse it easily in variable_type
3080 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3081 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3082 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3083 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3084 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3085 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3090 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3091 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3092 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3093 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3094 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3095 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3096 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3097 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3098 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3102 // Expressions, section 7.5
3107 : primary_expression_or_type
3109 | array_creation_expression
3110 | parenthesized_expression
3111 | default_value_expression
3112 | invocation_expression
3116 | post_increment_expression
3117 | post_decrement_expression
3118 | object_or_delegate_creation_expression
3119 | anonymous_type_expression
3122 | checked_expression
3123 | unchecked_expression
3124 | pointer_member_access
3125 | anonymous_method_expression
3126 | undocumented_expressions
3129 primary_expression_or_type
3130 : IDENTIFIER opt_type_argument_list
3132 var lt = (LocatedToken) $1;
3133 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3135 | IDENTIFIER GENERATE_COMPLETION {
3136 var lt = (LocatedToken) $1;
3137 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3145 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3149 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3150 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3155 // Here is the trick, tokenizer may think that parens is a special but
3156 // parser is interested in open parens only, so we merge them.
3157 // Consider: if (a)foo ();
3165 // Use this production to accept closing parenthesis or
3166 // performing completion
3170 | COMPLETE_COMPLETION
3174 parenthesized_expression
3175 : OPEN_PARENS expression CLOSE_PARENS
3177 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3178 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3180 | OPEN_PARENS expression COMPLETE_COMPLETION
3182 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3187 : primary_expression DOT identifier_inside_body opt_type_argument_list
3189 var lt = (LocatedToken) $3;
3190 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3191 lbag.AddLocation ($$, GetLocation ($2));
3193 | builtin_types DOT identifier_inside_body opt_type_argument_list
3195 var lt = (LocatedToken) $3;
3196 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3197 lbag.AddLocation ($$, GetLocation ($2));
3199 | BASE DOT identifier_inside_body opt_type_argument_list
3201 var lt = (LocatedToken) $3;
3202 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3203 lbag.AddLocation ($$, GetLocation ($2));
3205 | AWAIT DOT identifier_inside_body opt_type_argument_list
3207 var lt = (LocatedToken) $3;
3208 $$ = new MemberAccess (new SimpleName ("await", ((LocatedToken) $1).Location), lt.Value, (TypeArguments) $4, lt.Location);
3209 lbag.AddLocation ($$, GetLocation ($2));
3211 | qualified_alias_member identifier_inside_body opt_type_argument_list
3213 var lt1 = (LocatedToken) $1;
3214 var lt2 = (LocatedToken) $2;
3216 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3217 lbag.AddLocation ($$, GetLocation ($2));
3219 | primary_expression DOT GENERATE_COMPLETION {
3220 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3222 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3223 var lt = (LocatedToken) $3;
3224 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3226 | builtin_types DOT GENERATE_COMPLETION
3228 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3230 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3231 var lt = (LocatedToken) $3;
3232 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3236 invocation_expression
3237 : primary_expression open_parens_any opt_argument_list close_parens
3239 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3240 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3242 | primary_expression open_parens_any argument_list error
3244 Error_SyntaxError (yyToken);
3246 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3247 lbag.AddLocation ($$, GetLocation ($2));
3249 | primary_expression open_parens_any error
3251 Error_SyntaxError (yyToken);
3253 $$ = new Invocation ((Expression) $1, null);
3254 lbag.AddLocation ($$, GetLocation ($2));
3258 opt_object_or_collection_initializer
3259 : /* empty */ { $$ = null; }
3260 | object_or_collection_initializer
3263 object_or_collection_initializer
3264 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3267 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3269 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3271 lbag.AddLocation ($$, GetLocation ($3));
3273 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3275 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3276 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3280 opt_member_initializer_list
3281 : /* empty */ { $$ = null; }
3282 | member_initializer_list
3288 member_initializer_list
3289 : member_initializer
3291 var a = new List<Expression> ();
3292 a.Add ((Expression) $1);
3295 | member_initializer_list COMMA member_initializer
3297 var a = (List<Expression>)$1;
3298 a.Add ((Expression) $3);
3301 | member_initializer_list error {
3302 Error_SyntaxError (yyToken);
3308 : IDENTIFIER ASSIGN initializer_value
3310 var lt = (LocatedToken) $1;
3311 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3312 lbag.AddLocation ($$, GetLocation ($2));
3314 | AWAIT ASSIGN initializer_value
3316 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3317 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3318 lbag.AddLocation ($$, GetLocation ($2));
3320 | GENERATE_COMPLETION
3322 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3324 | non_assignment_expression opt_COMPLETE_COMPLETION {
3325 CompletionSimpleName csn = $1 as CompletionSimpleName;
3327 $$ = new CollectionElementInitializer ((Expression)$1);
3329 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3331 | OPEN_BRACE expression_list CLOSE_BRACE
3334 $$ = new CollectionElementInitializer (GetLocation ($1));
3336 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3338 lbag.AddLocation ($$, GetLocation ($2));
3340 | OPEN_BRACE CLOSE_BRACE
3342 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3343 $$ = new CollectionElementInitializer (GetLocation ($1));
3344 lbag.AddLocation ($$, GetLocation ($2));
3350 | object_or_collection_initializer
3354 : /* empty */ { $$ = null; }
3359 : argument_or_named_argument
3361 Arguments list = new Arguments (4);
3362 list.Add ((Argument) $1);
3365 | argument_list COMMA argument
3367 Arguments list = (Arguments) $1;
3368 if (list [list.Count - 1] is NamedArgument)
3369 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3371 list.Add ((Argument) $3);
3374 | argument_list COMMA named_argument
3376 Arguments list = (Arguments) $1;
3377 NamedArgument a = (NamedArgument) $3;
3378 for (int i = 0; i < list.Count; ++i) {
3379 NamedArgument na = list [i] as NamedArgument;
3380 if (na != null && na.Name == a.Name)
3381 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3388 | argument_list COMMA error
3390 if (lexer.putback_char == -1)
3391 lexer.putback (')'); // TODO: Wrong but what can I do
3392 Error_SyntaxError (yyToken);
3397 report.Error (839, GetLocation ($1), "An argument is missing");
3405 $$ = new Argument ((Expression) $1);
3407 | non_simple_argument
3410 argument_or_named_argument
3416 : REF variable_reference
3418 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3419 lbag.AddLocation ($$, GetLocation ($1));
3421 | OUT variable_reference
3423 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3424 lbag.AddLocation ($$, GetLocation ($1));
3426 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3428 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3429 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3431 | ARGLIST OPEN_PARENS CLOSE_PARENS
3433 $$ = new Argument (new Arglist (GetLocation ($1)));
3434 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3443 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3445 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3446 lbag.AddLocation ($$, GetLocation ($4));
3448 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3450 Error_SyntaxError (yyToken);
3451 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3453 | primary_expression OPEN_BRACKET_EXPR error
3455 Error_SyntaxError (yyToken);
3456 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3461 : expression_or_error
3463 var list = new List<Expression> (4);
3464 list.Add ((Expression) $1);
3467 | expression_list COMMA expression_or_error
3469 var list = (List<Expression>) $1;
3470 list.Add ((Expression) $3);
3475 expression_list_arguments
3476 : expression_list_argument
3478 Arguments args = new Arguments (4);
3479 args.Add ((Argument) $1);
3482 | expression_list_arguments COMMA expression_list_argument
3484 Arguments args = (Arguments) $1;
3485 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3486 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3488 args.Add ((Argument) $3);
3493 expression_list_argument
3496 $$ = new Argument ((Expression) $1);
3504 $$ = new This (GetLocation ($1));
3509 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3511 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3512 lbag.AddLocation ($$, GetLocation ($4));
3514 | BASE OPEN_BRACKET error
3516 Error_SyntaxError (yyToken);
3517 $$ = new ElementAccess (null, null, GetLocation ($2));
3521 post_increment_expression
3522 : primary_expression OP_INC
3524 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3528 post_decrement_expression
3529 : primary_expression OP_DEC
3531 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3535 object_or_delegate_creation_expression
3536 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3539 if (lang_version <= LanguageVersion.ISO_2)
3540 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3542 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3544 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3547 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3549 | NEW new_expr_type object_or_collection_initializer
3551 if (lang_version <= LanguageVersion.ISO_2)
3552 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3554 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3558 array_creation_expression
3559 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3561 opt_array_initializer
3563 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3564 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3565 Next = (ComposedTypeSpecifier) $6
3566 }, (ArrayInitializer) $7, GetLocation ($1));
3567 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3569 | NEW new_expr_type rank_specifiers opt_array_initializer
3572 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3574 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3576 | NEW rank_specifier array_initializer
3578 if (lang_version <= LanguageVersion.ISO_2)
3579 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3581 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3583 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3585 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3586 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3588 | NEW new_expr_type error
3590 Error_SyntaxError (yyToken);
3591 // It can be any of new expression, create the most common one
3592 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3598 ++lexer.parsing_type;
3602 --lexer.parsing_type;
3607 anonymous_type_expression
3608 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3610 if (lang_version <= LanguageVersion.ISO_2)
3611 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3613 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3615 // TODO: lbag comma location
3616 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3618 | NEW OPEN_BRACE GENERATE_COMPLETION
3620 $$ = new EmptyCompletion ();
3624 anonymous_type_parameters_opt_comma
3625 : anonymous_type_parameters_opt
3626 | anonymous_type_parameters COMMA
3629 anonymous_type_parameters_opt
3631 | anonymous_type_parameters
3634 anonymous_type_parameters
3635 : anonymous_type_parameter
3637 var a = new List<AnonymousTypeParameter> (4);
3638 a.Add ((AnonymousTypeParameter) $1);
3641 | anonymous_type_parameters COMMA anonymous_type_parameter
3643 var a = (List<AnonymousTypeParameter>) $1;
3644 a.Add ((AnonymousTypeParameter) $3);
3647 | COMPLETE_COMPLETION
3649 $$ = new EmptyCompletion ();
3651 | anonymous_type_parameter COMPLETE_COMPLETION
3657 anonymous_type_parameter
3658 : identifier_inside_body ASSIGN variable_initializer
3660 var lt = (LocatedToken)$1;
3661 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3662 lbag.AddLocation ($$, GetLocation ($2));
3664 | identifier_inside_body
3666 var lt = (LocatedToken)$1;
3667 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3668 lt.Value, lt.Location);
3672 MemberAccess ma = (MemberAccess) $1;
3673 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3677 report.Error (746, lexer.Location,
3678 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3690 | rank_specifier rank_specifiers
3692 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3698 : OPEN_BRACKET CLOSE_BRACKET
3700 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3701 lbag.AddLocation ($$, GetLocation ($2));
3703 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3705 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3706 lbag.AddLocation ($$, GetLocation ($3));
3715 | dim_separators COMMA
3717 $$ = ((int) $1) + 1;
3721 opt_array_initializer
3733 : OPEN_BRACE CLOSE_BRACE
3735 var ai = new ArrayInitializer (0, GetLocation ($1));
3736 ai.VariableDeclaration = current_variable;
3737 lbag.AddLocation (ai, GetLocation ($2));
3740 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3742 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3743 ai.VariableDeclaration = current_variable;
3745 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3747 lbag.AddLocation (ai, GetLocation ($4));
3753 variable_initializer_list
3754 : variable_initializer
3756 var list = new List<Expression> (4);
3757 list.Add ((Expression) $1);
3760 | variable_initializer_list COMMA variable_initializer
3762 var list = (List<Expression>) $1;
3763 list.Add ((Expression) $3);
3771 lexer.TypeOfParsing = true;
3773 open_parens_any typeof_type_expression CLOSE_PARENS
3775 lexer.TypeOfParsing = false;
3776 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3777 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3781 typeof_type_expression
3786 Error_TypeExpected (lexer.Location);
3792 : identifier_inside_body generic_dimension
3794 var lt = (LocatedToken) $1;
3796 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3798 | qualified_alias_member identifier_inside_body generic_dimension
3800 var lt1 = (LocatedToken) $1;
3801 var lt2 = (LocatedToken) $2;
3803 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3804 lbag.AddLocation ($$, GetLocation ($2));
3806 | unbound_type_name DOT identifier_inside_body
3808 var lt = (LocatedToken) $3;
3810 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3812 | unbound_type_name DOT identifier_inside_body generic_dimension
3814 var lt = (LocatedToken) $3;
3816 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3818 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3820 var tne = (ATypeNameExpression) $1;
3821 if (tne.HasTypeArguments)
3822 Error_TypeExpected (GetLocation ($4));
3824 var lt = (LocatedToken) $3;
3825 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3832 if (lang_version < LanguageVersion.ISO_2)
3833 FeatureIsNotAvailable (GetLocation ($1), "generics");
3839 qualified_alias_member
3840 : IDENTIFIER DOUBLE_COLON
3842 var lt = (LocatedToken) $1;
3843 if (lang_version == LanguageVersion.ISO_1)
3844 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3851 : SIZEOF open_parens_any type CLOSE_PARENS
3853 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3854 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3856 | SIZEOF open_parens_any type error
3858 Error_SyntaxError (yyToken);
3860 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3861 lbag.AddLocation ($$, GetLocation ($2));
3866 : CHECKED open_parens_any expression CLOSE_PARENS
3868 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3869 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3873 Error_SyntaxError (yyToken);
3875 $$ = new CheckedExpr (null, GetLocation ($1));
3879 unchecked_expression
3880 : UNCHECKED open_parens_any expression CLOSE_PARENS
3882 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3883 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3887 Error_SyntaxError (yyToken);
3889 $$ = new UnCheckedExpr (null, GetLocation ($1));
3893 pointer_member_access
3894 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3896 var lt = (LocatedToken) $3;
3897 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3901 anonymous_method_expression
3902 : DELEGATE opt_anonymous_method_signature
3904 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3908 $$ = end_anonymous ((ParametersBlock) $4);
3910 | ASYNC DELEGATE opt_anonymous_method_signature
3912 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3916 $$ = end_anonymous ((ParametersBlock) $5);
3920 opt_anonymous_method_signature
3923 $$ = ParametersCompiled.Undefined;
3925 | anonymous_method_signature
3928 anonymous_method_signature
3931 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3933 opt_formal_parameter_list CLOSE_PARENS
3935 valid_param_mod = 0;
3940 default_value_expression
3941 : DEFAULT open_parens_any type CLOSE_PARENS
3943 if (lang_version < LanguageVersion.ISO_2)
3944 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3946 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3947 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3952 : primary_expression
3953 | BANG prefixed_unary_expression
3955 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3957 | TILDE prefixed_unary_expression
3959 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3961 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3963 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3964 lbag.AddLocation ($$, GetLocation ($3));
3966 | AWAIT prefixed_unary_expression
3969 if (current_anonymous_method is LambdaExpression) {
3970 report.Error (4034, GetLocation ($1),
3971 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3972 } else if (current_anonymous_method != null) {
3973 report.Error (4035, GetLocation ($1),
3974 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3975 } else if (interactive_async != null) {
3976 current_block.Explicit.RegisterAsyncAwait ();
3977 interactive_async = true;
3979 report.Error (4033, GetLocation ($1),
3980 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3983 current_block.Explicit.RegisterAsyncAwait ();
3986 $$ = new Await ((Expression) $2, GetLocation ($1));
3990 Error_SyntaxError (yyToken);
3992 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3996 Error_SyntaxError (yyToken);
3998 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
4000 | OPEN_PARENS_CAST type CLOSE_PARENS error
4002 Error_SyntaxError (yyToken);
4004 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
4005 lbag.AddLocation ($$, GetLocation ($3));
4009 Error_SyntaxError (yyToken);
4011 $$ = new Await (null, GetLocation ($1));
4016 // The idea to split this out is from Rhys' grammar
4017 // to solve the problem with casts.
4019 prefixed_unary_expression
4021 | PLUS prefixed_unary_expression
4023 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4025 | MINUS prefixed_unary_expression
4027 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4029 | OP_INC prefixed_unary_expression
4031 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4033 | OP_DEC prefixed_unary_expression
4035 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4037 | STAR prefixed_unary_expression
4039 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4041 | BITWISE_AND prefixed_unary_expression
4043 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4047 Error_SyntaxError (yyToken);
4049 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4053 Error_SyntaxError (yyToken);
4055 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4059 Error_SyntaxError (yyToken);
4061 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4065 Error_SyntaxError (yyToken);
4067 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4071 Error_SyntaxError (yyToken);
4073 $$ = new Indirection (null, GetLocation ($1));
4077 Error_SyntaxError (yyToken);
4079 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4083 multiplicative_expression
4084 : prefixed_unary_expression
4085 | multiplicative_expression STAR prefixed_unary_expression
4087 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4088 lbag.AddLocation ($$, GetLocation ($2));
4090 | multiplicative_expression DIV prefixed_unary_expression
4092 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4093 lbag.AddLocation ($$, GetLocation ($2));
4095 | multiplicative_expression PERCENT prefixed_unary_expression
4097 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4098 lbag.AddLocation ($$, GetLocation ($2));
4100 | multiplicative_expression STAR error
4102 Error_SyntaxError (yyToken);
4104 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4105 lbag.AddLocation ($$, GetLocation ($2));
4107 | multiplicative_expression DIV error
4109 Error_SyntaxError (yyToken);
4111 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4112 lbag.AddLocation ($$, GetLocation ($2));
4114 | multiplicative_expression PERCENT error
4116 Error_SyntaxError (yyToken);
4118 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4119 lbag.AddLocation ($$, GetLocation ($2));
4124 : multiplicative_expression
4125 | additive_expression PLUS multiplicative_expression
4127 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4128 lbag.AddLocation ($$, GetLocation ($2));
4130 | additive_expression MINUS multiplicative_expression
4132 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4133 lbag.AddLocation ($$, GetLocation ($2));
4135 | additive_expression AS type
4137 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4139 | additive_expression IS type
4141 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4143 | additive_expression PLUS error
4145 Error_SyntaxError (yyToken);
4147 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4148 lbag.AddLocation ($$, GetLocation ($2));
4150 | additive_expression MINUS error
4152 Error_SyntaxError (yyToken);
4154 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4155 lbag.AddLocation ($$, GetLocation ($2));
4157 | additive_expression AS error
4159 Error_SyntaxError (yyToken);
4161 $$ = new As ((Expression) $1, null, GetLocation ($2));
4163 | additive_expression IS error
4165 Error_SyntaxError (yyToken);
4167 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4172 : additive_expression
4173 | shift_expression OP_SHIFT_LEFT additive_expression
4175 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4176 lbag.AddLocation ($$, GetLocation ($2));
4178 | shift_expression OP_SHIFT_RIGHT additive_expression
4180 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4181 lbag.AddLocation ($$, GetLocation ($2));
4183 | shift_expression OP_SHIFT_LEFT error
4185 Error_SyntaxError (yyToken);
4187 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4188 lbag.AddLocation ($$, GetLocation ($2));
4190 | shift_expression OP_SHIFT_RIGHT error
4192 Error_SyntaxError (yyToken);
4194 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4195 lbag.AddLocation ($$, GetLocation ($2));
4199 relational_expression
4201 | relational_expression OP_LT shift_expression
4203 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4204 lbag.AddLocation ($$, GetLocation ($2));
4206 | relational_expression OP_GT shift_expression
4208 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4209 lbag.AddLocation ($$, GetLocation ($2));
4211 | relational_expression OP_LE shift_expression
4213 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4214 lbag.AddLocation ($$, GetLocation ($2));
4216 | relational_expression OP_GE shift_expression
4218 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4219 lbag.AddLocation ($$, GetLocation ($2));
4221 | relational_expression OP_LT error
4223 Error_SyntaxError (yyToken);
4225 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4226 lbag.AddLocation ($$, GetLocation ($2));
4228 | relational_expression OP_GT error
4230 Error_SyntaxError (yyToken);
4232 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4233 lbag.AddLocation ($$, GetLocation ($2));
4235 | relational_expression OP_LE error
4237 Error_SyntaxError (yyToken);
4239 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4240 lbag.AddLocation ($$, GetLocation ($2));
4242 | relational_expression OP_GE error
4244 Error_SyntaxError (yyToken);
4246 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4247 lbag.AddLocation ($$, GetLocation ($2));
4252 : relational_expression
4253 | equality_expression OP_EQ relational_expression
4255 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4256 lbag.AddLocation ($$, GetLocation ($2));
4258 | equality_expression OP_NE relational_expression
4260 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4261 lbag.AddLocation ($$, GetLocation ($2));
4263 | equality_expression OP_EQ error
4265 Error_SyntaxError (yyToken);
4267 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4268 lbag.AddLocation ($$, GetLocation ($2));
4270 | equality_expression OP_NE error
4272 Error_SyntaxError (yyToken);
4274 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4275 lbag.AddLocation ($$, GetLocation ($2));
4280 : equality_expression
4281 | and_expression BITWISE_AND equality_expression
4283 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4284 lbag.AddLocation ($$, GetLocation ($2));
4286 | and_expression BITWISE_AND error
4288 Error_SyntaxError (yyToken);
4290 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4291 lbag.AddLocation ($$, GetLocation ($2));
4295 exclusive_or_expression
4297 | exclusive_or_expression CARRET and_expression
4299 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4300 lbag.AddLocation ($$, GetLocation ($2));
4302 | exclusive_or_expression CARRET error
4304 Error_SyntaxError (yyToken);
4306 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4307 lbag.AddLocation ($$, GetLocation ($2));
4311 inclusive_or_expression
4312 : exclusive_or_expression
4313 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4315 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4316 lbag.AddLocation ($$, GetLocation ($2));
4318 | inclusive_or_expression BITWISE_OR error
4320 Error_SyntaxError (yyToken);
4322 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4323 lbag.AddLocation ($$, GetLocation ($2));
4327 conditional_and_expression
4328 : inclusive_or_expression
4329 | conditional_and_expression OP_AND inclusive_or_expression
4331 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4332 lbag.AddLocation ($$, GetLocation ($2));
4334 | conditional_and_expression OP_AND error
4336 Error_SyntaxError (yyToken);
4338 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4339 lbag.AddLocation ($$, GetLocation ($2));
4343 conditional_or_expression
4344 : conditional_and_expression
4345 | conditional_or_expression OP_OR conditional_and_expression
4347 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4348 lbag.AddLocation ($$, GetLocation ($2));
4350 | conditional_or_expression OP_OR error
4352 Error_SyntaxError (yyToken);
4354 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4355 lbag.AddLocation ($$, GetLocation ($2));
4359 null_coalescing_expression
4360 : conditional_or_expression
4361 | conditional_or_expression OP_COALESCING null_coalescing_expression
4363 if (lang_version < LanguageVersion.ISO_2)
4364 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4366 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4367 lbag.AddLocation ($$, GetLocation ($2));
4371 conditional_expression
4372 : null_coalescing_expression
4373 | null_coalescing_expression INTERR expression COLON expression
4375 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4376 lbag.AddLocation ($$, GetLocation ($4));
4378 | null_coalescing_expression INTERR expression error
4380 Error_SyntaxError (yyToken);
4382 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4384 | null_coalescing_expression INTERR expression COLON error
4386 Error_SyntaxError (yyToken);
4388 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4389 lbag.AddLocation ($$, GetLocation ($4));
4391 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4393 Error_SyntaxError (Token.CLOSE_BRACE);
4395 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4396 lbag.AddLocation ($$, GetLocation ($4));
4397 lexer.putback ('}');
4401 assignment_expression
4402 : prefixed_unary_expression ASSIGN expression
4404 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4405 lbag.AddLocation ($$, GetLocation ($2));
4407 | prefixed_unary_expression OP_MULT_ASSIGN expression
4409 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4410 lbag.AddLocation ($$, GetLocation ($2));
4412 | prefixed_unary_expression OP_DIV_ASSIGN expression
4414 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4415 lbag.AddLocation ($$, GetLocation ($2));
4417 | prefixed_unary_expression OP_MOD_ASSIGN expression
4419 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4420 lbag.AddLocation ($$, GetLocation ($2));
4422 | prefixed_unary_expression OP_ADD_ASSIGN expression
4424 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4425 lbag.AddLocation ($$, GetLocation ($2));
4427 | prefixed_unary_expression OP_SUB_ASSIGN expression
4429 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4430 lbag.AddLocation ($$, GetLocation ($2));
4432 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4434 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4435 lbag.AddLocation ($$, GetLocation ($2));
4437 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4439 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4440 lbag.AddLocation ($$, GetLocation ($2));
4442 | prefixed_unary_expression OP_AND_ASSIGN expression
4444 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4445 lbag.AddLocation ($$, GetLocation ($2));
4447 | prefixed_unary_expression OP_OR_ASSIGN expression
4449 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4450 lbag.AddLocation ($$, GetLocation ($2));
4452 | prefixed_unary_expression OP_XOR_ASSIGN expression
4454 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4455 lbag.AddLocation ($$, GetLocation ($2));
4459 lambda_parameter_list
4462 var pars = new List<Parameter> (4);
4463 pars.Add ((Parameter) $1);
4467 | lambda_parameter_list COMMA lambda_parameter
4469 var pars = (List<Parameter>) $1;
4470 Parameter p = (Parameter)$3;
4471 if (pars[0].GetType () != p.GetType ()) {
4472 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4481 : parameter_modifier parameter_type identifier_inside_body
4483 var lt = (LocatedToken) $3;
4485 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4487 | parameter_type identifier_inside_body
4489 var lt = (LocatedToken) $2;
4491 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4495 var lt = (LocatedToken) $1;
4496 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4500 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4501 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4505 opt_lambda_parameter_list
4506 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4507 | lambda_parameter_list {
4508 var pars_list = (List<Parameter>) $1;
4509 $$ = new ParametersCompiled (pars_list.ToArray ());
4513 lambda_expression_body
4515 start_block (Location.Null);
4517 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4519 Block b = end_block (Location.Null);
4520 b.IsCompilerGenerated = true;
4521 b.AddStatement (new ContextualReturn ((Expression) $2));
4527 // Handles only cases like foo = x.FirstOrDefault (l => );
4528 // where we must restore current_variable
4529 Block b = end_block (Location.Null);
4530 b.IsCompilerGenerated = true;
4532 Error_SyntaxError (yyToken);
4541 Error_SyntaxError (yyToken);
4549 var lt = (LocatedToken) $1;
4550 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4551 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4553 lambda_expression_body
4555 $$ = end_anonymous ((ParametersBlock) $4);
4556 lbag.AddLocation ($$, GetLocation ($2));
4560 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4561 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4562 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4564 lambda_expression_body
4566 $$ = end_anonymous ((ParametersBlock) $4);
4567 lbag.AddLocation ($$, GetLocation ($2));
4569 | ASYNC identifier_inside_body ARROW
4571 var lt = (LocatedToken) $2;
4572 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4573 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4575 lambda_expression_body
4577 $$ = end_anonymous ((ParametersBlock) $5);
4578 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4580 | OPEN_PARENS_LAMBDA
4582 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4584 opt_lambda_parameter_list CLOSE_PARENS ARROW
4586 valid_param_mod = 0;
4587 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4589 lambda_expression_body
4591 $$ = end_anonymous ((ParametersBlock) $7);
4592 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4594 | ASYNC OPEN_PARENS_LAMBDA
4596 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4598 opt_lambda_parameter_list CLOSE_PARENS ARROW
4600 valid_param_mod = 0;
4601 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4603 lambda_expression_body
4605 $$ = end_anonymous ((ParametersBlock) $8);
4606 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4611 : assignment_expression
4612 | non_assignment_expression
4615 non_assignment_expression
4616 : conditional_expression
4621 $$ = new ArglistAccess (GetLocation ($1));
4625 undocumented_expressions
4626 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4628 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4629 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4631 | REFTYPE open_parens_any expression CLOSE_PARENS
4633 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4634 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4636 | MAKEREF open_parens_any expression CLOSE_PARENS
4638 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4639 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4650 $$ = new BooleanExpression ((Expression) $1);
4654 opt_primary_parameters
4659 | primary_parameters
4663 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4667 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4668 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4672 opt_primary_parameters_with_class_base
4681 | primary_parameters
4685 | primary_parameters class_base OPEN_PARENS
4687 ++lexer.parsing_block;
4689 opt_argument_list CLOSE_PARENS
4691 lbag.AppendToMember (current_container, GetLocation ($3), GetLocation ($6));
4692 ((Class)current_type).PrimaryConstructorBaseArguments = (Arguments) $5;
4693 --lexer.parsing_block;
4709 type_declaration_name
4711 lexer.ConstraintsParsing = true;
4713 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4714 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4715 FeatureIsNotAvailable (c.Location, "static classes");
4718 push_current_container (c, $3);
4719 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4721 opt_primary_parameters_with_class_base
4722 opt_type_parameter_constraints_clauses
4724 valid_param_mod = 0;
4725 lexer.ConstraintsParsing = false;
4728 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4731 current_container.SetConstraints ((List<Constraints>) $9);
4732 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4735 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4736 Lexer.doc_state = XmlCommentState.Allowed;
4739 lexer.parsing_modifiers = true;
4741 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4743 --lexer.parsing_declaration;
4745 Lexer.doc_state = XmlCommentState.Allowed;
4750 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4752 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4754 $$ = pop_current_class ();
4762 { $$ = $1; } // location
4768 mod_locations = null;
4770 lexer.parsing_modifiers = false;
4774 lexer.parsing_modifiers = false;
4780 | modifiers modifier
4782 var m1 = (Modifiers) $1;
4783 var m2 = (Modifiers) $2;
4785 if ((m1 & m2) != 0) {
4786 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4787 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4788 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4789 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4790 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4791 "More than one protection modifier specified");
4802 StoreModifierLocation ($$, GetLocation ($1));
4804 if (current_container.Kind == MemberKind.Namespace)
4805 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4809 $$ = Modifiers.PUBLIC;
4810 StoreModifierLocation ($$, GetLocation ($1));
4814 $$ = Modifiers.PROTECTED;
4815 StoreModifierLocation ($$, GetLocation ($1));
4819 $$ = Modifiers.INTERNAL;
4820 StoreModifierLocation ($$, GetLocation ($1));
4824 $$ = Modifiers.PRIVATE;
4825 StoreModifierLocation ($$, GetLocation ($1));
4829 $$ = Modifiers.ABSTRACT;
4830 StoreModifierLocation ($$, GetLocation ($1));
4834 $$ = Modifiers.SEALED;
4835 StoreModifierLocation ($$, GetLocation ($1));
4839 $$ = Modifiers.STATIC;
4840 StoreModifierLocation ($$, GetLocation ($1));
4844 $$ = Modifiers.READONLY;
4845 StoreModifierLocation ($$, GetLocation ($1));
4849 $$ = Modifiers.VIRTUAL;
4850 StoreModifierLocation ($$, GetLocation ($1));
4854 $$ = Modifiers.OVERRIDE;
4855 StoreModifierLocation ($$, GetLocation ($1));
4859 $$ = Modifiers.EXTERN;
4860 StoreModifierLocation ($$, GetLocation ($1));
4864 $$ = Modifiers.VOLATILE;
4865 StoreModifierLocation ($$, GetLocation ($1));
4869 $$ = Modifiers.UNSAFE;
4870 StoreModifierLocation ($$, GetLocation ($1));
4871 if (!settings.Unsafe)
4872 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4876 $$ = Modifiers.ASYNC;
4877 StoreModifierLocation ($$, GetLocation ($1));
4889 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4891 | COLON type_list error
4893 Error_SyntaxError (yyToken);
4895 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4899 opt_type_parameter_constraints_clauses
4901 | type_parameter_constraints_clauses
4907 type_parameter_constraints_clauses
4908 : type_parameter_constraints_clause
4910 var constraints = new List<Constraints> (1);
4911 constraints.Add ((Constraints) $1);
4914 | type_parameter_constraints_clauses type_parameter_constraints_clause
4916 var constraints = (List<Constraints>) $1;
4917 Constraints new_constraint = (Constraints)$2;
4919 foreach (Constraints c in constraints) {
4920 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4921 report.Error (409, new_constraint.Location,
4922 "A constraint clause has already been specified for type parameter `{0}'",
4923 new_constraint.TypeParameter.Value);
4927 constraints.Add (new_constraint);
4932 type_parameter_constraints_clause
4933 : WHERE IDENTIFIER COLON type_parameter_constraints
4935 var lt = (LocatedToken) $2;
4936 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4937 lbag.AddLocation ($$, GetLocation ($3));
4939 | WHERE IDENTIFIER error
4941 Error_SyntaxError (yyToken);
4943 var lt = (LocatedToken) $2;
4944 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4948 type_parameter_constraints
4949 : type_parameter_constraint
4951 var constraints = new List<FullNamedExpression> (1);
4952 constraints.Add ((FullNamedExpression) $1);
4955 | type_parameter_constraints COMMA type_parameter_constraint
4957 var constraints = (List<FullNamedExpression>) $1;
4958 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4959 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4960 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4963 prev = $3 as SpecialContraintExpr;
4965 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4966 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4968 prev = constraints [0] as SpecialContraintExpr;
4969 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4970 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4975 constraints.Add ((FullNamedExpression) $3);
4980 type_parameter_constraint
4983 if ($1 is ComposedCast)
4984 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4988 | NEW OPEN_PARENS CLOSE_PARENS
4990 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4991 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4995 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4999 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
5003 opt_type_parameter_variance
5008 | type_parameter_variance
5010 if (lang_version <= LanguageVersion.V_3)
5011 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5017 type_parameter_variance
5020 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5024 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5033 // A block is "contained" on the following places:
5035 // property_declaration as part of the accessor body (get/set)
5036 // operator_declaration
5037 // constructor_declaration
5038 // destructor_declaration
5039 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5044 ++lexer.parsing_block;
5045 start_block (GetLocation ($1));
5047 opt_statement_list block_end
5056 --lexer.parsing_block;
5057 $$ = end_block (GetLocation ($1));
5059 | COMPLETE_COMPLETION
5061 --lexer.parsing_block;
5062 $$ = end_block (lexer.Location);
5070 ++lexer.parsing_block;
5071 current_block.StartLocation = GetLocation ($1);
5073 opt_statement_list CLOSE_BRACE
5075 --lexer.parsing_block;
5076 $$ = end_block (GetLocation ($4));
5087 | statement_list statement
5091 : block_variable_declaration
5093 current_block.AddStatement ((Statement) $1);
5095 | valid_declaration_statement
5097 current_block.AddStatement ((Statement) $1);
5102 Error_SyntaxError (yyToken);
5108 // The interactive_statement and its derivatives are only
5109 // used to provide a special version of `expression_statement'
5110 // that has a side effect of assigning the expression to
5113 interactive_statement_list
5114 : interactive_statement
5115 | interactive_statement_list interactive_statement
5118 interactive_statement
5119 : block_variable_declaration
5121 current_block.AddStatement ((Statement) $1);
5123 | interactive_valid_declaration_statement
5125 current_block.AddStatement ((Statement) $1);
5130 valid_declaration_statement
5133 | expression_statement
5134 | selection_statement
5135 | iteration_statement
5139 | unchecked_statement
5146 interactive_valid_declaration_statement
5149 | interactive_expression_statement
5150 | selection_statement
5151 | iteration_statement
5155 | unchecked_statement
5163 : valid_declaration_statement
5164 | block_variable_declaration
5166 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5171 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5176 Error_SyntaxError (yyToken);
5177 $$ = new EmptyStatement (GetLocation ($1));
5184 // Uses lexer.Location because semicolon location is not kept in quick mode
5185 $$ = new EmptyStatement (lexer.Location);
5190 : identifier_inside_body COLON
5192 var lt = (LocatedToken) $1;
5193 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5194 lbag.AddLocation (labeled, GetLocation ($2));
5195 current_block.AddLabel (labeled);
5196 current_block.AddStatement (labeled);
5202 : variable_type_simple
5203 | variable_type_simple rank_specifiers
5206 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5208 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5213 * The following is from Rhys' grammar:
5214 * > Types in local variable declarations must be recognized as
5215 * > expressions to prevent reduce/reduce errors in the grammar.
5216 * > The expressions are converted into types during semantic analysis.
5218 variable_type_simple
5219 : primary_expression_or_type opt_nullable
5221 // Ok, the above "primary_expression" is there to get rid of
5222 // both reduce/reduce and shift/reduces in the grammar, it should
5223 // really just be "type_name". If you use type_name, a reduce/reduce
5224 // creeps up. If you use namespace_or_type_name (which is all we need
5225 // really) two shift/reduces appear.
5228 // So the super-trick is that primary_expression
5229 // can only be either a SimpleName or a MemberAccess.
5230 // The MemberAccess case arises when you have a fully qualified type-name like :
5232 // SimpleName is when you have
5235 Expression expr = (Expression) $1;
5237 SimpleName sn = expr as SimpleName;
5238 if (sn != null && sn.Name == "var")
5239 $$ = new VarExpr (sn.Location);
5242 } else if (expr is ATypeNameExpression) {
5243 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5245 Error_ExpectingTypeName (expr);
5249 | primary_expression_or_type pointer_stars
5251 ATypeNameExpression expr = $1 as ATypeNameExpression;
5254 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5256 Error_ExpectingTypeName ((Expression)$1);
5260 | builtin_types opt_nullable
5265 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5267 | builtin_types pointer_stars
5269 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5271 | VOID pointer_stars
5273 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5277 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5278 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5284 | pointer_star pointer_stars
5286 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5294 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5298 identifier_inside_body
5302 $$ = Error_AwaitAsIdentifier ($1);
5306 block_variable_declaration
5307 : variable_type identifier_inside_body
5309 var lt = (LocatedToken) $2;
5310 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5311 current_block.AddLocalName (li);
5312 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5314 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5316 $$ = current_variable;
5317 current_variable = null;
5319 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5321 lbag.AddLocation ($$, GetLocation ($6));
5323 | CONST variable_type identifier_inside_body
5325 var lt = (LocatedToken) $3;
5326 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5327 current_block.AddLocalName (li);
5328 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5330 const_variable_initializer opt_const_declarators SEMICOLON
5332 $$ = current_variable;
5333 current_variable = null;
5334 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5338 opt_local_variable_initializer
5340 | ASSIGN block_variable_initializer
5342 current_variable.Initializer = (Expression) $2;
5343 PushLocation (GetLocation ($1));
5344 $$ = current_variable;
5348 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5349 report.Error (650, lexer.Location,
5350 "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");
5352 Error_SyntaxError (yyToken);
5357 opt_variable_declarators
5359 | variable_declarators
5362 opt_using_or_fixed_variable_declarators
5364 | variable_declarators
5366 foreach (var d in current_variable.Declarators) {
5367 if (d.Initializer == null)
5368 Error_MissingInitializer (d.Variable.Location);
5373 variable_declarators
5374 : variable_declarator
5375 | variable_declarators variable_declarator
5379 : COMMA identifier_inside_body
5381 var lt = (LocatedToken) $2;
5382 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5383 var d = new BlockVariableDeclarator (li, null);
5384 current_variable.AddDeclarator (d);
5385 current_block.AddLocalName (li);
5386 lbag.AddLocation (d, GetLocation ($1));
5388 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5390 var lt = (LocatedToken) $2;
5391 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5392 var d = new BlockVariableDeclarator (li, (Expression) $4);
5393 current_variable.AddDeclarator (d);
5394 current_block.AddLocalName (li);
5395 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5399 const_variable_initializer
5402 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5404 | ASSIGN constant_initializer_expr
5406 current_variable.Initializer = (Expression) $2;
5410 opt_const_declarators
5417 | const_declarators const_declarator
5421 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5423 var lt = (LocatedToken) $2;
5424 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5425 var d = new BlockVariableDeclarator (li, (Expression) $4);
5426 current_variable.AddDeclarator (d);
5427 current_block.AddLocalName (li);
5428 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5432 block_variable_initializer
5433 : variable_initializer
5434 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5436 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5437 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5439 | STACKALLOC simple_type
5441 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5442 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5446 expression_statement
5447 : statement_expression SEMICOLON
5450 lbag.AddStatement ($$, GetLocation ($2));
5452 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5453 | statement_expression CLOSE_BRACE
5456 report.Error (1002, GetLocation ($2), "; expected");
5457 lexer.putback ('}');
5461 interactive_expression_statement
5462 : interactive_statement_expression SEMICOLON { $$ = $1; }
5463 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5467 // We have to do the wrapping here and not in the case above,
5468 // because statement_expression is used for example in for_statement
5470 statement_expression
5473 ExpressionStatement s = $1 as ExpressionStatement;
5475 var expr = $1 as Expression;
5476 $$ = new StatementErrorExpression (expr);
5478 $$ = new StatementExpression (s);
5483 interactive_statement_expression
5486 Expression expr = (Expression) $1;
5487 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5491 Error_SyntaxError (yyToken);
5492 $$ = new EmptyStatement (GetLocation ($1));
5502 : IF open_parens_any boolean_expression CLOSE_PARENS
5505 if ($5 is EmptyStatement)
5506 Warning_EmptyStatement (GetLocation ($5));
5508 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5509 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5511 | IF open_parens_any boolean_expression CLOSE_PARENS
5512 embedded_statement ELSE embedded_statement
5514 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5515 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5517 if ($5 is EmptyStatement)
5518 Warning_EmptyStatement (GetLocation ($5));
5519 if ($7 is EmptyStatement)
5520 Warning_EmptyStatement (GetLocation ($7));
5522 | IF open_parens_any boolean_expression error
5524 Error_SyntaxError (yyToken);
5526 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5527 lbag.AddStatement ($$, GetLocation ($2));
5532 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5534 start_block (GetLocation ($5));
5536 opt_switch_sections CLOSE_BRACE
5538 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5539 end_block (GetLocation ($8));
5540 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5542 | SWITCH open_parens_any expression error
5544 Error_SyntaxError (yyToken);
5546 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5547 lbag.AddStatement ($$, GetLocation ($2));
5554 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5561 | switch_sections switch_section
5564 Error_SyntaxError (yyToken);
5569 : switch_labels statement_list
5575 var label = (SwitchLabel) $1;
5576 label.SectionStart = true;
5577 current_block.AddStatement (label);
5579 | switch_labels switch_label
5581 current_block.AddStatement ((Statement) $2);
5586 : CASE constant_expression COLON
5588 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5589 lbag.AddLocation ($$, GetLocation ($3));
5591 | CASE constant_expression error
5593 Error_SyntaxError (yyToken);
5594 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5598 $$ = new SwitchLabel (null, GetLocation ($1));
5610 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5612 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5613 Warning_EmptyStatement (GetLocation ($5));
5615 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5616 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5618 | WHILE open_parens_any boolean_expression error
5620 Error_SyntaxError (yyToken);
5622 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5623 lbag.AddStatement ($$, GetLocation ($2));
5628 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5630 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5631 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5633 | DO embedded_statement error
5635 Error_SyntaxError (yyToken);
5636 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5638 | DO embedded_statement WHILE open_parens_any boolean_expression error
5640 Error_SyntaxError (yyToken);
5642 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5643 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5648 : FOR open_parens_any
5650 start_block (GetLocation ($2));
5651 current_block.IsCompilerGenerated = true;
5652 For f = new For (GetLocation ($1));
5653 current_block.AddStatement (f);
5662 // Has to use be extra rule to recover started block
5664 : opt_for_initializer SEMICOLON
5666 ((For) $0).Initializer = (Statement) $1;
5668 // Pass the "For" object to the iterator_part4
5669 oob_stack.Push ($0);
5671 for_condition_and_iterator_part
5674 var locations = (Tuple<Location,Location>) $4;
5676 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5677 Warning_EmptyStatement (GetLocation ($5));
5680 f.Statement = (Statement) $5;
5681 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5683 $$ = end_block (GetLocation ($2));
5687 Error_SyntaxError (yyToken);
5688 $$ = end_block (current_block.StartLocation);
5692 for_condition_and_iterator_part
5693 : opt_for_condition SEMICOLON
5695 For f = (For) oob_stack.Peek ();
5696 f.Condition = (BooleanExpression) $1;
5699 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5702 // Handle errors in the case of opt_for_condition being followed by
5703 // a close parenthesis
5704 | opt_for_condition close_parens_close_brace {
5705 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5706 For f = (For) oob_stack.Peek ();
5707 f.Condition = (BooleanExpression) $1;
5708 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5713 : opt_for_iterator CLOSE_PARENS {
5714 For f = (For) oob_stack.Peek ();
5715 f.Iterator = (Statement) $1;
5716 $$ = GetLocation ($2);
5718 | opt_for_iterator CLOSE_BRACE {
5719 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5720 For f = (For) oob_stack.Peek ();
5721 f.Iterator = (Statement) $1;
5722 $$ = GetLocation ($2);
5726 close_parens_close_brace
5728 | CLOSE_BRACE { lexer.putback ('}'); }
5732 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5737 : variable_type identifier_inside_body
5739 var lt = (LocatedToken) $2;
5740 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5741 current_block.AddLocalName (li);
5742 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5744 opt_local_variable_initializer opt_variable_declarators
5746 $$ = current_variable;
5748 lbag.AddLocation (current_variable, PopLocation ());
5750 current_variable = null;
5752 | statement_expression_list
5756 : /* empty */ { $$ = null; }
5757 | boolean_expression
5761 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5766 : statement_expression_list
5769 statement_expression_list
5770 : statement_expression
5771 | statement_expression_list COMMA statement_expression
5773 var sl = $1 as StatementList;
5775 sl = new StatementList ((Statement) $1, (Statement) $3);
5776 lbag.AddStatement (sl, GetLocation ($2));
5778 sl.Add ((Statement) $3);
5779 lbag.AppendTo (sl, GetLocation ($2));
5787 : FOREACH open_parens_any type error
5789 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5791 start_block (GetLocation ($2));
5792 current_block.IsCompilerGenerated = true;
5794 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5795 current_block.AddStatement (f);
5797 lbag.AddStatement (f, GetLocation ($2));
5798 $$ = end_block (GetLocation ($4));
5800 | FOREACH open_parens_any type identifier_inside_body error
5802 Error_SyntaxError (yyToken);
5804 start_block (GetLocation ($2));
5805 current_block.IsCompilerGenerated = true;
5807 var lt = (LocatedToken) $4;
5808 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5809 current_block.AddLocalName (li);
5811 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5812 current_block.AddStatement (f);
5814 lbag.AddStatement (f, GetLocation ($2));
5815 $$ = end_block (GetLocation ($5));
5817 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5819 start_block (GetLocation ($2));
5820 current_block.IsCompilerGenerated = true;
5822 var lt = (LocatedToken) $4;
5823 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5824 current_block.AddLocalName (li);
5829 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5830 Warning_EmptyStatement (GetLocation ($9));
5832 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5833 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5834 end_block (GetLocation ($7));
5842 | continue_statement
5852 $$ = new Break (GetLocation ($1));
5853 lbag.AddStatement ($$, GetLocation ($2));
5858 : CONTINUE SEMICOLON
5860 $$ = new Continue (GetLocation ($1));
5861 lbag.AddStatement ($$, GetLocation ($2));
5865 Error_SyntaxError (yyToken);
5866 $$ = new Continue (GetLocation ($1));
5871 : GOTO identifier_inside_body SEMICOLON
5873 var lt = (LocatedToken) $2;
5874 $$ = new Goto (lt.Value, GetLocation ($1));
5875 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5877 | GOTO CASE constant_expression SEMICOLON
5879 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5880 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5882 | GOTO DEFAULT SEMICOLON
5884 $$ = new GotoDefault (GetLocation ($1));
5885 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5890 : RETURN opt_expression SEMICOLON
5892 $$ = new Return ((Expression) $2, GetLocation ($1));
5893 lbag.AddStatement ($$, GetLocation ($3));
5895 | RETURN expression error
5897 Error_SyntaxError (yyToken);
5898 $$ = new Return ((Expression) $2, GetLocation ($1));
5902 Error_SyntaxError (yyToken);
5903 $$ = new Return (null, GetLocation ($1));
5908 : THROW opt_expression SEMICOLON
5910 $$ = new Throw ((Expression) $2, GetLocation ($1));
5911 lbag.AddStatement ($$, GetLocation ($3));
5913 | THROW expression error
5915 Error_SyntaxError (yyToken);
5916 $$ = new Throw ((Expression) $2, GetLocation ($1));
5920 Error_SyntaxError (yyToken);
5921 $$ = new Throw (null, GetLocation ($1));
5926 : identifier_inside_body RETURN opt_expression SEMICOLON
5928 var lt = (LocatedToken) $1;
5929 string s = lt.Value;
5931 report.Error (1003, lt.Location, "; expected");
5932 } else if ($3 == null) {
5933 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5934 } else if (lang_version == LanguageVersion.ISO_1){
5935 FeatureIsNotAvailable (lt.Location, "iterators");
5938 current_block.Explicit.RegisterIteratorYield ();
5939 $$ = new Yield ((Expression) $3, lt.Location);
5940 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5942 | identifier_inside_body RETURN expression error
5944 Error_SyntaxError (yyToken);
5946 var lt = (LocatedToken) $1;
5947 string s = lt.Value;
5949 report.Error (1003, lt.Location, "; expected");
5950 } else if ($3 == null) {
5951 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5952 } else if (lang_version == LanguageVersion.ISO_1){
5953 FeatureIsNotAvailable (lt.Location, "iterators");
5956 current_block.Explicit.RegisterIteratorYield ();
5957 $$ = new Yield ((Expression) $3, lt.Location);
5958 lbag.AddStatement ($$, GetLocation ($2));
5960 | identifier_inside_body BREAK SEMICOLON
5962 var lt = (LocatedToken) $1;
5963 string s = lt.Value;
5965 report.Error (1003, lt.Location, "; expected");
5966 } else if (lang_version == LanguageVersion.ISO_1){
5967 FeatureIsNotAvailable (lt.Location, "iterators");
5970 current_block.ParametersBlock.TopBlock.IsIterator = true;
5971 $$ = new YieldBreak (lt.Location);
5972 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5982 : TRY block catch_clauses
5984 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5986 | TRY block FINALLY block
5988 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
5989 lbag.AddStatement ($$, GetLocation ($3));
5991 | TRY block catch_clauses FINALLY block
5993 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
5994 lbag.AddStatement ($$, GetLocation ($4));
5998 Error_SyntaxError (1524, yyToken);
5999 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
6006 var l = new List<Catch> (2);
6011 | catch_clauses catch_clause
6013 var l = (List<Catch>) $1;
6015 Catch c = (Catch) $2;
6016 var prev_catch = l [l.Count - 1];
6017 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6018 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6028 | identifier_inside_body
6032 : CATCH opt_catch_filter block
6034 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6035 c.Filter = (CatchFilterExpression) $2;
6038 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6040 start_block (GetLocation ($2));
6041 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6042 c.TypeExpression = (FullNamedExpression) $3;
6045 var lt = (LocatedToken) $4;
6046 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6047 current_block.AddLocalName (c.Variable);
6050 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6053 opt_catch_filter block_prepared
6055 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6058 | CATCH open_parens_any error
6060 if (yyToken == Token.CLOSE_PARENS) {
6061 report.Error (1015, lexer.Location,
6062 "A type that derives from `System.Exception', `object', or `string' expected");
6064 Error_SyntaxError (yyToken);
6067 $$ = new Catch (null, GetLocation ($1));
6069 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6071 Error_SyntaxError (yyToken);
6073 // Required otherwise missing block could not be detected because
6074 // start_block is run early
6075 var c = new Catch (null, GetLocation ($1));
6076 c.TypeExpression = (FullNamedExpression) $3;
6079 var lt = (LocatedToken) $4;
6080 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6083 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6091 | IF open_parens_any expression CLOSE_PARENS
6093 if (lang_version <= LanguageVersion.V_5)
6094 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6096 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6097 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6104 $$ = new Checked ((Block) $2, GetLocation ($1));
6111 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6118 if (!settings.Unsafe)
6119 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6121 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6126 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6128 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6129 Warning_EmptyStatement (GetLocation ($5));
6131 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6132 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6134 | LOCK open_parens_any expression error
6136 Error_SyntaxError (yyToken);
6138 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6139 lbag.AddStatement ($$, GetLocation ($2));
6144 : FIXED open_parens_any variable_type identifier_inside_body
6146 start_block (GetLocation ($2));
6148 current_block.IsCompilerGenerated = true;
6149 var lt = (LocatedToken) $4;
6150 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6151 current_block.AddLocalName (li);
6152 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6154 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6156 $$ = current_variable;
6157 current_variable = null;
6161 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6162 Warning_EmptyStatement (GetLocation ($10));
6164 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6165 current_block.AddStatement (f);
6166 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6167 $$ = end_block (GetLocation ($8));
6172 : USING open_parens_any variable_type identifier_inside_body
6174 start_block (GetLocation ($2));
6176 current_block.IsCompilerGenerated = true;
6177 var lt = (LocatedToken) $4;
6178 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6179 current_block.AddLocalName (li);
6180 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6182 using_initialization CLOSE_PARENS
6184 $$ = current_variable;
6185 current_variable = null;
6189 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6190 Warning_EmptyStatement (GetLocation ($9));
6192 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6193 current_block.AddStatement (u);
6194 $$ = end_block (GetLocation ($7));
6196 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6198 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6199 Warning_EmptyStatement (GetLocation ($5));
6201 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6202 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6204 | USING open_parens_any expression error
6206 Error_SyntaxError (yyToken);
6208 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6209 lbag.AddStatement ($$, GetLocation ($2));
6213 using_initialization
6214 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6217 // It has to be here for the parent to safely restore artificial block
6218 Error_SyntaxError (yyToken);
6222 using_or_fixed_variable_initializer
6225 Error_MissingInitializer (lexer.Location);
6227 | ASSIGN variable_initializer
6229 current_variable.Initializer = (Expression) $2;
6230 $$ = current_variable;
6238 : first_from_clause query_body
6240 lexer.query_parsing = false;
6242 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6244 from.Tail.Next = (Linq.AQueryClause)$2;
6247 current_block.SetEndLocation (lexer.Location);
6248 current_block = current_block.Parent;
6250 | nested_from_clause query_body
6252 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6254 from.Tail.Next = (Linq.AQueryClause)$2;
6257 current_block.SetEndLocation (lexer.Location);
6258 current_block = current_block.Parent;
6261 // Bubble up COMPLETE_COMPLETION productions
6262 | first_from_clause COMPLETE_COMPLETION {
6263 lexer.query_parsing = false;
6266 current_block.SetEndLocation (lexer.Location);
6267 current_block = current_block.Parent;
6269 | nested_from_clause COMPLETE_COMPLETION {
6271 current_block.SetEndLocation (lexer.Location);
6272 current_block = current_block.Parent;
6277 : FROM_FIRST identifier_inside_body IN expression
6279 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6281 var lt = (LocatedToken) $2;
6282 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6283 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6284 lbag.AddLocation (clause, GetLocation ($3));
6285 $$ = new Linq.QueryExpression (clause);
6287 | FROM_FIRST type identifier_inside_body IN expression
6289 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6291 var lt = (LocatedToken) $3;
6292 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6293 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6294 IdentifierType = (FullNamedExpression)$2
6296 lbag.AddLocation (clause, GetLocation ($4));
6297 $$ = new Linq.QueryExpression (clause);
6302 : FROM identifier_inside_body IN expression
6304 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6306 var lt = (LocatedToken) $2;
6307 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6308 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6309 lbag.AddLocation (clause, GetLocation ($3));
6310 $$ = new Linq.QueryExpression (clause);
6312 | FROM type identifier_inside_body IN expression
6314 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6316 var lt = (LocatedToken) $3;
6317 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6318 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6319 IdentifierType = (FullNamedExpression)$2
6321 lbag.AddLocation (clause, GetLocation ($4));
6322 $$ = new Linq.QueryExpression (clause);
6327 : FROM identifier_inside_body IN
6329 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6333 var lt = (LocatedToken) $2;
6334 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6335 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6337 current_block.SetEndLocation (lexer.Location);
6338 current_block = current_block.Parent;
6340 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6341 lbag.AddLocation ($$, GetLocation ($3));
6343 | FROM type identifier_inside_body IN
6345 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6349 var lt = (LocatedToken) $3;
6350 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6352 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6353 IdentifierType = (FullNamedExpression)$2
6356 current_block.SetEndLocation (lexer.Location);
6357 current_block = current_block.Parent;
6359 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6361 lbag.AddLocation ($$, GetLocation ($4));
6366 : query_body_clauses select_or_group_clause opt_query_continuation
6368 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6371 head.Next = (Linq.AQueryClause)$3;
6374 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6375 clause.Tail.Next = head;
6381 | select_or_group_clause opt_query_continuation
6383 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6386 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6387 clause.Tail.Next = head;
6393 | query_body_clauses COMPLETE_COMPLETION
6394 | query_body_clauses error
6396 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6401 Error_SyntaxError (yyToken);
6406 select_or_group_clause
6409 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6413 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6415 current_block.SetEndLocation (lexer.Location);
6416 current_block = current_block.Parent;
6420 if (linq_clause_blocks == null)
6421 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6423 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6424 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6428 current_block.SetEndLocation (lexer.Location);
6429 current_block = current_block.Parent;
6431 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6435 var obj = (object[]) $5;
6437 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6438 lbag.AddLocation ($$, (Location) obj[1]);
6440 current_block.SetEndLocation (lexer.Location);
6441 current_block = current_block.Parent;
6446 : BY expression_or_error
6448 $$ = new object[] { $2, GetLocation ($1) };
6452 Error_SyntaxError (yyToken);
6453 $$ = new object[2] { null, Location.Null };
6459 | query_body_clauses query_body_clause
6461 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6475 : LET identifier_inside_body ASSIGN
6477 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6481 var lt = (LocatedToken) $2;
6482 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6483 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6484 lbag.AddLocation ($$, GetLocation ($3));
6486 current_block.SetEndLocation (lexer.Location);
6487 current_block = current_block.Parent;
6489 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6496 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6500 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6502 current_block.SetEndLocation (lexer.Location);
6503 current_block = current_block.Parent;
6508 : JOIN identifier_inside_body IN
6510 if (linq_clause_blocks == null)
6511 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6513 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6514 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6516 expression_or_error ON
6518 current_block.SetEndLocation (lexer.Location);
6519 current_block = current_block.Parent;
6521 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6522 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6524 expression_or_error EQUALS
6526 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6527 current_block.SetEndLocation (lexer.Location);
6528 current_block = current_block.Parent;
6530 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6532 expression_or_error opt_join_into
6534 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6535 current_block.SetEndLocation (lexer.Location);
6537 var outer_selector = linq_clause_blocks.Pop ();
6538 var block = linq_clause_blocks.Pop ();
6540 var lt = (LocatedToken) $2;
6541 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6542 Linq.RangeVariable into;
6546 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6547 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6550 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6552 var parent = block.Parent;
6553 while (parent is Linq.QueryBlock) {
6554 parent = parent.Parent;
6556 current_block.Parent = parent;
6558 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6560 lt = (LocatedToken) $12;
6561 into = new Linq.RangeVariable (lt.Value, lt.Location);
6563 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6564 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6567 current_block = block.Parent;
6568 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6570 | JOIN type identifier_inside_body IN
6572 if (linq_clause_blocks == null)
6573 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6575 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6576 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6578 expression_or_error ON
6580 current_block.SetEndLocation (lexer.Location);
6581 current_block = current_block.Parent;
6583 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6584 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6586 expression_or_error EQUALS
6588 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6589 current_block.SetEndLocation (lexer.Location);
6590 current_block = current_block.Parent;
6592 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6594 expression_or_error opt_join_into
6596 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6597 current_block.SetEndLocation (lexer.Location);
6599 var outer_selector = linq_clause_blocks.Pop ();
6600 var block = linq_clause_blocks.Pop ();
6602 var lt = (LocatedToken) $3;
6603 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6604 Linq.RangeVariable into;
6608 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6609 IdentifierType = (FullNamedExpression)$2
6611 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6614 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6616 var parent = block.Parent;
6617 while (parent is Linq.QueryBlock) {
6618 parent = parent.Parent;
6620 current_block.Parent = parent;
6622 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6624 lt = (LocatedToken) $13;
6625 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6627 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6628 IdentifierType = (FullNamedExpression)$2
6632 current_block = block.Parent;
6633 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6639 | INTO identifier_inside_body
6648 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6652 current_block.SetEndLocation (lexer.Location);
6653 current_block = current_block.Parent;
6663 current_block.SetEndLocation (lexer.Location);
6664 current_block = current_block.Parent;
6666 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6670 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6677 | orderings_then_by COMMA
6679 current_block.SetEndLocation (lexer.Location);
6680 current_block = current_block.Parent;
6682 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6686 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6694 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6696 | expression ASCENDING
6698 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6699 lbag.AddLocation ($$, GetLocation ($2));
6701 | expression DESCENDING
6703 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6704 lbag.AddLocation ($$, GetLocation ($2));
6711 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6713 | expression ASCENDING
6715 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6716 lbag.AddLocation ($$, GetLocation ($2));
6718 | expression DESCENDING
6720 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6721 lbag.AddLocation ($$, GetLocation ($2));
6726 opt_query_continuation
6728 | INTO identifier_inside_body
6730 // query continuation block is not linked with query block but with block
6731 // before. This means each query can use same range variable names for
6732 // different identifiers.
6734 current_block.SetEndLocation (GetLocation ($1));
6735 current_block = current_block.Parent;
6737 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6739 if (linq_clause_blocks == null)
6740 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6742 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6746 var current_block = linq_clause_blocks.Pop ();
6747 var lt = (LocatedToken) $2;
6748 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6749 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6750 next = (Linq.AQueryClause)$4
6756 // Support for using the compiler as an interactive parser
6758 // The INTERACTIVE_PARSER token is first sent to parse our
6759 // productions; If the result is a Statement, the parsing
6760 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6761 // to setup the blocks in advance.
6763 // This setup is here so that in the future we can add
6764 // support for other constructs (type parsing, namespaces, etc)
6765 // that do not require a block to be setup in advance
6769 : EVAL_STATEMENT_PARSER EOF
6770 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6771 | EVAL_STATEMENT_PARSER
6773 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6775 // (ref object retval)
6776 Parameter [] mpar = new Parameter [1];
6777 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6779 ParametersCompiled pars = new ParametersCompiled (mpar);
6780 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6781 if (settings.Unsafe)
6782 mods |= Modifiers.UNSAFE;
6784 current_local_parameters = pars;
6785 var method = new InteractiveMethod (
6787 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6791 current_type.AddMember (method);
6792 oob_stack.Push (method);
6794 interactive_async = false;
6796 ++lexer.parsing_block;
6797 start_block (lexer.Location);
6799 interactive_statement_list opt_COMPLETE_COMPLETION
6801 --lexer.parsing_block;
6802 var method = (InteractiveMethod) oob_stack.Pop ();
6803 method.Block = (ToplevelBlock) end_block(lexer.Location);
6805 if (interactive_async == true) {
6806 method.ChangeToAsync ();
6809 InteractiveResult = (Class) pop_current_class ();
6810 current_local_parameters = null;
6812 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6815 interactive_compilation_unit
6816 : opt_extern_alias_directives opt_using_directives
6817 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6820 opt_COMPLETE_COMPLETION
6822 | COMPLETE_COMPLETION
6825 close_brace_or_complete_completion
6827 | COMPLETE_COMPLETION
6831 // XML documentation code references micro parser
6833 documentation_parsing
6836 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6841 : doc_type_declaration_name opt_doc_method_sig
6843 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6845 | builtin_types opt_doc_method_sig
6847 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6848 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6851 | VOID opt_doc_method_sig
6853 module.DocumentationBuilder.ParsedBuiltinType = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
6854 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6857 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6859 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6860 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6861 var lt = (LocatedToken) $3;
6862 $$ = new MemberName (lt.Value);
6864 | doc_type_declaration_name DOT THIS
6866 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6868 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6870 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6872 opt_doc_parameters CLOSE_BRACKET
6874 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6875 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6877 | EXPLICIT OPERATOR type opt_doc_method_sig
6879 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6880 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6881 module.DocumentationBuilder.ParsedParameters = p;
6882 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6885 | IMPLICIT OPERATOR type opt_doc_method_sig
6887 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6888 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6889 module.DocumentationBuilder.ParsedParameters = p;
6890 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6893 | OPERATOR overloadable_operator opt_doc_method_sig
6895 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6896 module.DocumentationBuilder.ParsedParameters = p;
6897 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6902 doc_type_declaration_name
6903 : type_declaration_name
6904 | doc_type_declaration_name DOT type_declaration_name
6906 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6914 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6916 opt_doc_parameters CLOSE_PARENS
6925 $$ = new List<DocumentationParameter> (0);
6933 var parameters = new List<DocumentationParameter> ();
6934 parameters.Add ((DocumentationParameter) $1);
6937 | doc_parameters COMMA doc_parameter
6939 var parameters = $1 as List<DocumentationParameter>;
6940 parameters.Add ((DocumentationParameter) $3);
6946 : opt_parameter_modifier parameter_type
6949 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6951 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6958 // A class used to hold info about an operator declarator
6960 class OperatorDeclaration {
6961 public readonly Operator.OpType optype;
6962 public readonly FullNamedExpression ret_type;
6963 public readonly Location location;
6965 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6968 this.ret_type = ret_type;
6969 this.location = location;
6973 void Error_ExpectingTypeName (Expression expr)
6975 if (expr is Invocation){
6976 report.Error (1002, expr.Location, "Expecting `;'");
6978 expr.Error_InvalidExpressionStatement (report);
6982 void Error_ParameterModifierNotValid (string modifier, Location loc)
6984 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6988 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6990 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6991 Parameter.GetModifierSignature (mod));
6994 void Error_TypeExpected (Location loc)
6996 report.Error (1031, loc, "Type expected");
6999 void Error_UnsafeCodeNotAllowed (Location loc)
7001 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
7004 void Warning_EmptyStatement (Location loc)
7006 report.Warning (642, 3, loc, "Possible mistaken empty statement");
7009 void Error_NamedArgumentExpected (NamedArgument a)
7011 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
7014 void Error_MissingInitializer (Location loc)
7016 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7019 object Error_AwaitAsIdentifier (object token)
7022 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7023 return new LocatedToken ("await", GetLocation (token));
7029 void push_current_container (TypeDefinition tc, object partial_token)
7031 if (module.Evaluator != null){
7032 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7036 undo.AddTypeContainer (current_container, tc);
7039 if (partial_token != null)
7040 current_container.AddPartial (tc);
7042 current_container.AddTypeContainer (tc);
7044 ++lexer.parsing_declaration;
7045 current_container = tc;
7049 TypeContainer pop_current_class ()
7051 var retval = current_container;
7053 current_container = current_container.Parent;
7054 current_type = current_type.Parent as TypeDefinition;
7059 [System.Diagnostics.Conditional ("FULL_AST")]
7060 void StoreModifierLocation (object token, Location loc)
7065 if (mod_locations == null)
7066 mod_locations = new List<Tuple<Modifiers, Location>> ();
7068 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7071 [System.Diagnostics.Conditional ("FULL_AST")]
7072 void PushLocation (Location loc)
7074 if (location_stack == null)
7075 location_stack = new Stack<Location> ();
7077 location_stack.Push (loc);
7080 Location PopLocation ()
7082 if (location_stack == null)
7083 return Location.Null;
7085 return location_stack.Pop ();
7088 string CheckAttributeTarget (int token, string a, Location l)
7091 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7095 if (!Tokenizer.IsValidIdentifier (a)) {
7096 Error_SyntaxError (token);
7098 report.Warning (658, 1, l,
7099 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7102 return string.Empty;
7105 static bool IsUnaryOperator (Operator.OpType op)
7109 case Operator.OpType.LogicalNot:
7110 case Operator.OpType.OnesComplement:
7111 case Operator.OpType.Increment:
7112 case Operator.OpType.Decrement:
7113 case Operator.OpType.True:
7114 case Operator.OpType.False:
7115 case Operator.OpType.UnaryPlus:
7116 case Operator.OpType.UnaryNegation:
7122 void syntax_error (Location l, string msg)
7124 report.Error (1003, l, "Syntax error, " + msg);
7129 public Tokenizer Lexer {
7135 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7136 : this (reader, file, file.Compiler.Report, session)
7140 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7143 current_container = current_namespace = file;
7145 this.module = file.Module;
7146 this.compiler = file.Compiler;
7147 this.settings = compiler.Settings;
7148 this.report = report;
7150 lang_version = settings.Version;
7151 yacc_verbose_flag = settings.VerboseParserFlag;
7152 doc_support = settings.DocumentationFile != null;
7153 lexer = new Tokenizer (reader, file, session, report);
7154 oob_stack = new Stack<object> ();
7155 lbag = session.LocationsBag;
7156 use_global_stacks = session.UseJayGlobalArrays;
7157 parameters_bucket = session.ParametersStack;
7160 public void parse ()
7162 eof_token = Token.EOF;
7165 if (yacc_verbose_flag > 1)
7166 yyparse (lexer, new yydebug.yyDebugSimple ());
7170 Tokenizer tokenizer = lexer as Tokenizer;
7171 tokenizer.cleanup ();
7172 } catch (Exception e){
7173 if (e is yyParser.yyUnexpectedEof) {
7174 Error_SyntaxError (yyToken);
7175 UnexpectedEOF = true;
7179 if (e is yyParser.yyException) {
7180 if (report.Errors == 0)
7181 report.Error (-25, lexer.Location, "Parsing error");
7183 // Used by compiler-tester to test internal errors
7184 if (yacc_verbose_flag > 0 || e is FatalException)
7187 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7192 void CheckToken (int error, int yyToken, string msg, Location loc)
7194 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7195 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7197 report.Error (error, loc, msg);
7200 string ConsumeStoredComment ()
7202 string s = tmpComment;
7204 Lexer.doc_state = XmlCommentState.Allowed;
7208 void FeatureIsNotAvailable (Location loc, string feature)
7210 report.FeatureIsNotAvailable (compiler, loc, feature);
7213 Location GetLocation (object obj)
7215 var lt = obj as LocatedToken;
7219 var mn = obj as MemberName;
7223 var expr = obj as Expression;
7225 return expr.Location;
7227 return lexer.Location;
7230 void start_block (Location loc)
7232 if (current_block == null) {
7233 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7234 parsing_anonymous_method = false;
7235 } else if (parsing_anonymous_method) {
7236 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7237 parsing_anonymous_method = false;
7239 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7244 end_block (Location loc)
7246 Block retval = current_block.Explicit;
7247 retval.SetEndLocation (loc);
7248 current_block = retval.Parent;
7252 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7254 oob_stack.Push (current_anonymous_method);
7255 oob_stack.Push (current_local_parameters);
7256 oob_stack.Push (current_variable);
7257 oob_stack.Push (async_block);
7259 current_local_parameters = parameters;
7261 if (lang_version <= LanguageVersion.ISO_2)
7262 FeatureIsNotAvailable (loc, "lambda expressions");
7264 current_anonymous_method = new LambdaExpression (loc);
7266 if (lang_version == LanguageVersion.ISO_1)
7267 FeatureIsNotAvailable (loc, "anonymous methods");
7269 current_anonymous_method = new AnonymousMethodExpression (loc);
7272 async_block = isAsync;
7273 // Force the next block to be created as a ToplevelBlock
7274 parsing_anonymous_method = true;
7278 * Completes the anonymous method processing, if lambda_expr is null, this
7279 * means that we have a Statement instead of an Expression embedded
7281 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7283 AnonymousMethodExpression retval;
7286 anon_block.IsAsync = true;
7288 current_anonymous_method.Block = anon_block;
7289 retval = current_anonymous_method;
7291 async_block = (bool) oob_stack.Pop ();
7292 current_variable = (BlockVariable) oob_stack.Pop ();
7293 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7294 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7299 void Error_SyntaxError (int token)
7301 Error_SyntaxError (0, token);
7304 void Error_SyntaxError (int error_code, int token)
7306 Error_SyntaxError (error_code, token, "Unexpected symbol");
7309 void Error_SyntaxError (int error_code, int token, string msg)
7311 Lexer.CompleteOnEOF = false;
7313 // An error message has been reported by tokenizer
7314 if (token == Token.ERROR)
7317 // Avoid duplicit error message after unterminated string literals
7318 if (token == Token.LITERAL && lexer.Location.Column == 0)
7321 string symbol = GetSymbolName (token);
7322 string expecting = GetExpecting ();
7323 var loc = lexer.Location - symbol.Length;
7325 if (error_code == 0) {
7326 if (expecting == "`identifier'") {
7327 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7328 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7333 expecting = "identifier";
7334 } else if (expecting == "`)'") {
7341 if (string.IsNullOrEmpty (expecting))
7342 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7344 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7347 string GetExpecting ()
7349 int [] tokens = yyExpectingTokens (yyExpectingState);
7350 var names = new List<string> (tokens.Length);
7351 bool has_type = false;
7352 bool has_identifier = false;
7353 for (int i = 0; i < tokens.Length; i++){
7354 int token = tokens [i];
7355 has_identifier |= token == Token.IDENTIFIER;
7357 string name = GetTokenName (token);
7358 if (name == "<internal>")
7361 has_type |= name == "type";
7362 if (names.Contains (name))
7369 // Too many tokens to enumerate
7371 if (names.Count > 8)
7374 if (has_type && has_identifier)
7375 names.Remove ("identifier");
7377 if (names.Count == 1)
7378 return "`" + GetTokenName (tokens [0]) + "'";
7380 StringBuilder sb = new StringBuilder ();
7382 int count = names.Count;
7383 for (int i = 0; i < count; i++){
7384 bool last = i + 1 == count;
7388 sb.Append (names [i]);
7389 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7391 return sb.ToString ();
7395 string GetSymbolName (int token)
7399 return ((Constant)lexer.Value).GetValue ().ToString ();
7400 case Token.IDENTIFIER:
7401 return ((LocatedToken)lexer.Value).Value;
7443 case Token.BITWISE_AND:
7445 case Token.BITWISE_OR:
7459 case Token.OP_SHIFT_LEFT:
7461 case Token.OP_SHIFT_RIGHT:
7481 case Token.OP_COALESCING:
7483 case Token.OP_MULT_ASSIGN:
7485 case Token.OP_DIV_ASSIGN:
7487 case Token.OP_MOD_ASSIGN:
7489 case Token.OP_ADD_ASSIGN:
7491 case Token.OP_SUB_ASSIGN:
7493 case Token.OP_SHIFT_LEFT_ASSIGN:
7495 case Token.OP_SHIFT_RIGHT_ASSIGN:
7497 case Token.OP_AND_ASSIGN:
7499 case Token.OP_XOR_ASSIGN:
7501 case Token.OP_OR_ASSIGN:
7505 return GetTokenName (token);
7508 static string GetTokenName (int token)
7511 case Token.ABSTRACT:
7533 case Token.CONTINUE:
7537 case Token.DELEGATE:
7547 case Token.EXPLICIT:
7550 case Token.EXTERN_ALIAS:
7566 case Token.IMPLICIT:
7570 case Token.INTERFACE:
7572 case Token.INTERNAL:
7578 case Token.NAMESPACE:
7584 case Token.OPERATOR:
7588 case Token.OVERRIDE:
7594 case Token.PROTECTED:
7598 case Token.READONLY:
7610 case Token.STACKALLOC:
7611 return "stackalloc";
7628 case Token.UNCHECKED:
7636 case Token.VOLATILE:
7644 case Token.REFVALUE:
7645 return "__refvalue";
7655 case Token.FROM_FIRST:
7673 case Token.ASCENDING:
7675 case Token.DESCENDING:
7676 return "descending";
7683 case Token.OPEN_BRACE:
7685 case Token.CLOSE_BRACE:
7687 case Token.OPEN_BRACKET:
7688 case Token.OPEN_BRACKET_EXPR:
7690 case Token.CLOSE_BRACKET:
7692 case Token.OPEN_PARENS_CAST:
7693 case Token.OPEN_PARENS_LAMBDA:
7694 case Token.OPEN_PARENS:
7696 case Token.CLOSE_PARENS:
7702 case Token.DEFAULT_COLON:
7706 case Token.SEMICOLON:
7717 case Token.BITWISE_AND:
7718 case Token.BITWISE_OR:
7725 case Token.OP_SHIFT_LEFT:
7726 case Token.OP_SHIFT_RIGHT:
7734 case Token.OP_COALESCING:
7735 case Token.OP_MULT_ASSIGN:
7736 case Token.OP_DIV_ASSIGN:
7737 case Token.OP_MOD_ASSIGN:
7738 case Token.OP_ADD_ASSIGN:
7739 case Token.OP_SUB_ASSIGN:
7740 case Token.OP_SHIFT_LEFT_ASSIGN:
7741 case Token.OP_SHIFT_RIGHT_ASSIGN:
7742 case Token.OP_AND_ASSIGN:
7743 case Token.OP_XOR_ASSIGN:
7744 case Token.OP_OR_ASSIGN:
7745 return "<operator>";
7767 case Token.OP_GENERICS_LT:
7768 case Token.GENERIC_DIMENSION:
7770 case Token.OP_GENERICS_GT:
7773 case Token.INTERR_NULLABLE:
7775 case Token.DOUBLE_COLON:
7779 case Token.IDENTIFIER:
7781 return "identifier";
7784 return "end-of-file";
7786 // All of these are internal.
7789 case Token.FIRST_KEYWORD:
7790 case Token.EVAL_COMPILATION_UNIT_PARSER:
7791 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7792 case Token.EVAL_STATEMENT_PARSER:
7793 case Token.LAST_KEYWORD:
7794 case Token.GENERATE_COMPLETION:
7795 case Token.COMPLETE_COMPLETION:
7796 return "<internal>";
7798 // A bit more robust.
7800 return yyNames [token];