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));
3620 anonymous_type_parameters_opt_comma
3621 : anonymous_type_parameters_opt
3622 | anonymous_type_parameters COMMA
3625 anonymous_type_parameters_opt
3627 | anonymous_type_parameters
3630 anonymous_type_parameters
3631 : anonymous_type_parameter
3633 var a = new List<AnonymousTypeParameter> (4);
3634 a.Add ((AnonymousTypeParameter) $1);
3637 | anonymous_type_parameters COMMA anonymous_type_parameter
3639 var a = (List<AnonymousTypeParameter>) $1;
3640 a.Add ((AnonymousTypeParameter) $3);
3645 anonymous_type_parameter
3646 : identifier_inside_body ASSIGN variable_initializer
3648 var lt = (LocatedToken)$1;
3649 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3650 lbag.AddLocation ($$, GetLocation ($2));
3652 | identifier_inside_body
3654 var lt = (LocatedToken)$1;
3655 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3656 lt.Value, lt.Location);
3660 MemberAccess ma = (MemberAccess) $1;
3661 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3665 report.Error (746, lexer.Location,
3666 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3678 | rank_specifier rank_specifiers
3680 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3686 : OPEN_BRACKET CLOSE_BRACKET
3688 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3689 lbag.AddLocation ($$, GetLocation ($2));
3691 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3693 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3694 lbag.AddLocation ($$, GetLocation ($3));
3703 | dim_separators COMMA
3705 $$ = ((int) $1) + 1;
3709 opt_array_initializer
3721 : OPEN_BRACE CLOSE_BRACE
3723 var ai = new ArrayInitializer (0, GetLocation ($1));
3724 ai.VariableDeclaration = current_variable;
3725 lbag.AddLocation (ai, GetLocation ($2));
3728 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3730 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3731 ai.VariableDeclaration = current_variable;
3733 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3735 lbag.AddLocation (ai, GetLocation ($4));
3741 variable_initializer_list
3742 : variable_initializer
3744 var list = new List<Expression> (4);
3745 list.Add ((Expression) $1);
3748 | variable_initializer_list COMMA variable_initializer
3750 var list = (List<Expression>) $1;
3751 list.Add ((Expression) $3);
3759 lexer.TypeOfParsing = true;
3761 open_parens_any typeof_type_expression CLOSE_PARENS
3763 lexer.TypeOfParsing = false;
3764 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3765 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3769 typeof_type_expression
3774 Error_TypeExpected (lexer.Location);
3780 : identifier_inside_body generic_dimension
3782 var lt = (LocatedToken) $1;
3784 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3786 | qualified_alias_member identifier_inside_body generic_dimension
3788 var lt1 = (LocatedToken) $1;
3789 var lt2 = (LocatedToken) $2;
3791 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3792 lbag.AddLocation ($$, GetLocation ($2));
3794 | unbound_type_name DOT identifier_inside_body
3796 var lt = (LocatedToken) $3;
3798 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3800 | unbound_type_name DOT identifier_inside_body generic_dimension
3802 var lt = (LocatedToken) $3;
3804 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3806 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3808 var tne = (ATypeNameExpression) $1;
3809 if (tne.HasTypeArguments)
3810 Error_TypeExpected (GetLocation ($4));
3812 var lt = (LocatedToken) $3;
3813 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3820 if (lang_version < LanguageVersion.ISO_2)
3821 FeatureIsNotAvailable (GetLocation ($1), "generics");
3827 qualified_alias_member
3828 : IDENTIFIER DOUBLE_COLON
3830 var lt = (LocatedToken) $1;
3831 if (lang_version == LanguageVersion.ISO_1)
3832 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3839 : SIZEOF open_parens_any type CLOSE_PARENS
3841 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3842 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3844 | SIZEOF open_parens_any type error
3846 Error_SyntaxError (yyToken);
3848 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3849 lbag.AddLocation ($$, GetLocation ($2));
3854 : CHECKED open_parens_any expression CLOSE_PARENS
3856 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3857 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3861 Error_SyntaxError (yyToken);
3863 $$ = new CheckedExpr (null, GetLocation ($1));
3867 unchecked_expression
3868 : UNCHECKED open_parens_any expression CLOSE_PARENS
3870 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3871 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3875 Error_SyntaxError (yyToken);
3877 $$ = new UnCheckedExpr (null, GetLocation ($1));
3881 pointer_member_access
3882 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3884 var lt = (LocatedToken) $3;
3885 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3889 anonymous_method_expression
3890 : DELEGATE opt_anonymous_method_signature
3892 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3896 $$ = end_anonymous ((ParametersBlock) $4);
3898 | ASYNC DELEGATE opt_anonymous_method_signature
3900 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3904 $$ = end_anonymous ((ParametersBlock) $5);
3908 opt_anonymous_method_signature
3911 $$ = ParametersCompiled.Undefined;
3913 | anonymous_method_signature
3916 anonymous_method_signature
3919 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3921 opt_formal_parameter_list CLOSE_PARENS
3923 valid_param_mod = 0;
3928 default_value_expression
3929 : DEFAULT open_parens_any type CLOSE_PARENS
3931 if (lang_version < LanguageVersion.ISO_2)
3932 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3934 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3935 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3940 : primary_expression
3941 | BANG prefixed_unary_expression
3943 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3945 | TILDE prefixed_unary_expression
3947 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3949 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3951 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3952 lbag.AddLocation ($$, GetLocation ($3));
3954 | AWAIT prefixed_unary_expression
3957 if (current_anonymous_method is LambdaExpression) {
3958 report.Error (4034, GetLocation ($1),
3959 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3960 } else if (current_anonymous_method != null) {
3961 report.Error (4035, GetLocation ($1),
3962 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3963 } else if (interactive_async != null) {
3964 current_block.Explicit.RegisterAsyncAwait ();
3965 interactive_async = true;
3967 report.Error (4033, GetLocation ($1),
3968 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3971 current_block.Explicit.RegisterAsyncAwait ();
3974 $$ = new Await ((Expression) $2, GetLocation ($1));
3978 Error_SyntaxError (yyToken);
3980 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3984 Error_SyntaxError (yyToken);
3986 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3988 | OPEN_PARENS_CAST type CLOSE_PARENS error
3990 Error_SyntaxError (yyToken);
3992 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3993 lbag.AddLocation ($$, GetLocation ($3));
3997 Error_SyntaxError (yyToken);
3999 $$ = new Await (null, GetLocation ($1));
4004 // The idea to split this out is from Rhys' grammar
4005 // to solve the problem with casts.
4007 prefixed_unary_expression
4009 | PLUS prefixed_unary_expression
4011 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4013 | MINUS prefixed_unary_expression
4015 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4017 | OP_INC prefixed_unary_expression
4019 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4021 | OP_DEC prefixed_unary_expression
4023 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4025 | STAR prefixed_unary_expression
4027 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4029 | BITWISE_AND prefixed_unary_expression
4031 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4035 Error_SyntaxError (yyToken);
4037 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4041 Error_SyntaxError (yyToken);
4043 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4047 Error_SyntaxError (yyToken);
4049 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4053 Error_SyntaxError (yyToken);
4055 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4059 Error_SyntaxError (yyToken);
4061 $$ = new Indirection (null, GetLocation ($1));
4065 Error_SyntaxError (yyToken);
4067 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4071 multiplicative_expression
4072 : prefixed_unary_expression
4073 | multiplicative_expression STAR prefixed_unary_expression
4075 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4076 lbag.AddLocation ($$, GetLocation ($2));
4078 | multiplicative_expression DIV prefixed_unary_expression
4080 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4081 lbag.AddLocation ($$, GetLocation ($2));
4083 | multiplicative_expression PERCENT prefixed_unary_expression
4085 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4086 lbag.AddLocation ($$, GetLocation ($2));
4088 | multiplicative_expression STAR error
4090 Error_SyntaxError (yyToken);
4092 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4093 lbag.AddLocation ($$, GetLocation ($2));
4095 | multiplicative_expression DIV error
4097 Error_SyntaxError (yyToken);
4099 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4100 lbag.AddLocation ($$, GetLocation ($2));
4102 | multiplicative_expression PERCENT error
4104 Error_SyntaxError (yyToken);
4106 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4107 lbag.AddLocation ($$, GetLocation ($2));
4112 : multiplicative_expression
4113 | additive_expression PLUS multiplicative_expression
4115 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4116 lbag.AddLocation ($$, GetLocation ($2));
4118 | additive_expression MINUS multiplicative_expression
4120 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4121 lbag.AddLocation ($$, GetLocation ($2));
4123 | additive_expression AS type
4125 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4127 | additive_expression IS type
4129 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4131 | additive_expression PLUS error
4133 Error_SyntaxError (yyToken);
4135 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4136 lbag.AddLocation ($$, GetLocation ($2));
4138 | additive_expression MINUS error
4140 Error_SyntaxError (yyToken);
4142 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4143 lbag.AddLocation ($$, GetLocation ($2));
4145 | additive_expression AS error
4147 Error_SyntaxError (yyToken);
4149 $$ = new As ((Expression) $1, null, GetLocation ($2));
4151 | additive_expression IS error
4153 Error_SyntaxError (yyToken);
4155 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4160 : additive_expression
4161 | shift_expression OP_SHIFT_LEFT additive_expression
4163 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4164 lbag.AddLocation ($$, GetLocation ($2));
4166 | shift_expression OP_SHIFT_RIGHT additive_expression
4168 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4169 lbag.AddLocation ($$, GetLocation ($2));
4171 | shift_expression OP_SHIFT_LEFT error
4173 Error_SyntaxError (yyToken);
4175 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4176 lbag.AddLocation ($$, GetLocation ($2));
4178 | shift_expression OP_SHIFT_RIGHT error
4180 Error_SyntaxError (yyToken);
4182 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4183 lbag.AddLocation ($$, GetLocation ($2));
4187 relational_expression
4189 | relational_expression OP_LT shift_expression
4191 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4192 lbag.AddLocation ($$, GetLocation ($2));
4194 | relational_expression OP_GT shift_expression
4196 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4197 lbag.AddLocation ($$, GetLocation ($2));
4199 | relational_expression OP_LE shift_expression
4201 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4202 lbag.AddLocation ($$, GetLocation ($2));
4204 | relational_expression OP_GE shift_expression
4206 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4207 lbag.AddLocation ($$, GetLocation ($2));
4209 | relational_expression OP_LT error
4211 Error_SyntaxError (yyToken);
4213 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4214 lbag.AddLocation ($$, GetLocation ($2));
4216 | relational_expression OP_GT error
4218 Error_SyntaxError (yyToken);
4220 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4221 lbag.AddLocation ($$, GetLocation ($2));
4223 | relational_expression OP_LE error
4225 Error_SyntaxError (yyToken);
4227 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4228 lbag.AddLocation ($$, GetLocation ($2));
4230 | relational_expression OP_GE error
4232 Error_SyntaxError (yyToken);
4234 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4235 lbag.AddLocation ($$, GetLocation ($2));
4240 : relational_expression
4241 | equality_expression OP_EQ relational_expression
4243 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4244 lbag.AddLocation ($$, GetLocation ($2));
4246 | equality_expression OP_NE relational_expression
4248 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4249 lbag.AddLocation ($$, GetLocation ($2));
4251 | equality_expression OP_EQ error
4253 Error_SyntaxError (yyToken);
4255 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4256 lbag.AddLocation ($$, GetLocation ($2));
4258 | equality_expression OP_NE error
4260 Error_SyntaxError (yyToken);
4262 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4263 lbag.AddLocation ($$, GetLocation ($2));
4268 : equality_expression
4269 | and_expression BITWISE_AND equality_expression
4271 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4272 lbag.AddLocation ($$, GetLocation ($2));
4274 | and_expression BITWISE_AND error
4276 Error_SyntaxError (yyToken);
4278 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4279 lbag.AddLocation ($$, GetLocation ($2));
4283 exclusive_or_expression
4285 | exclusive_or_expression CARRET and_expression
4287 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4288 lbag.AddLocation ($$, GetLocation ($2));
4290 | exclusive_or_expression CARRET error
4292 Error_SyntaxError (yyToken);
4294 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4295 lbag.AddLocation ($$, GetLocation ($2));
4299 inclusive_or_expression
4300 : exclusive_or_expression
4301 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4303 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4304 lbag.AddLocation ($$, GetLocation ($2));
4306 | inclusive_or_expression BITWISE_OR error
4308 Error_SyntaxError (yyToken);
4310 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4311 lbag.AddLocation ($$, GetLocation ($2));
4315 conditional_and_expression
4316 : inclusive_or_expression
4317 | conditional_and_expression OP_AND inclusive_or_expression
4319 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4320 lbag.AddLocation ($$, GetLocation ($2));
4322 | conditional_and_expression OP_AND error
4324 Error_SyntaxError (yyToken);
4326 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4327 lbag.AddLocation ($$, GetLocation ($2));
4331 conditional_or_expression
4332 : conditional_and_expression
4333 | conditional_or_expression OP_OR conditional_and_expression
4335 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4336 lbag.AddLocation ($$, GetLocation ($2));
4338 | conditional_or_expression OP_OR error
4340 Error_SyntaxError (yyToken);
4342 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4343 lbag.AddLocation ($$, GetLocation ($2));
4347 null_coalescing_expression
4348 : conditional_or_expression
4349 | conditional_or_expression OP_COALESCING null_coalescing_expression
4351 if (lang_version < LanguageVersion.ISO_2)
4352 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4354 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4355 lbag.AddLocation ($$, GetLocation ($2));
4359 conditional_expression
4360 : null_coalescing_expression
4361 | null_coalescing_expression INTERR expression COLON expression
4363 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4364 lbag.AddLocation ($$, GetLocation ($4));
4366 | null_coalescing_expression INTERR expression error
4368 Error_SyntaxError (yyToken);
4370 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4372 | null_coalescing_expression INTERR expression COLON error
4374 Error_SyntaxError (yyToken);
4376 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4377 lbag.AddLocation ($$, GetLocation ($4));
4379 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4381 Error_SyntaxError (Token.CLOSE_BRACE);
4383 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4384 lbag.AddLocation ($$, GetLocation ($4));
4385 lexer.putback ('}');
4389 assignment_expression
4390 : prefixed_unary_expression ASSIGN expression
4392 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4393 lbag.AddLocation ($$, GetLocation ($2));
4395 | prefixed_unary_expression OP_MULT_ASSIGN expression
4397 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4398 lbag.AddLocation ($$, GetLocation ($2));
4400 | prefixed_unary_expression OP_DIV_ASSIGN expression
4402 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4403 lbag.AddLocation ($$, GetLocation ($2));
4405 | prefixed_unary_expression OP_MOD_ASSIGN expression
4407 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4408 lbag.AddLocation ($$, GetLocation ($2));
4410 | prefixed_unary_expression OP_ADD_ASSIGN expression
4412 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4413 lbag.AddLocation ($$, GetLocation ($2));
4415 | prefixed_unary_expression OP_SUB_ASSIGN expression
4417 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4418 lbag.AddLocation ($$, GetLocation ($2));
4420 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4422 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4423 lbag.AddLocation ($$, GetLocation ($2));
4425 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4427 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4428 lbag.AddLocation ($$, GetLocation ($2));
4430 | prefixed_unary_expression OP_AND_ASSIGN expression
4432 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4433 lbag.AddLocation ($$, GetLocation ($2));
4435 | prefixed_unary_expression OP_OR_ASSIGN expression
4437 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4438 lbag.AddLocation ($$, GetLocation ($2));
4440 | prefixed_unary_expression OP_XOR_ASSIGN expression
4442 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4443 lbag.AddLocation ($$, GetLocation ($2));
4447 lambda_parameter_list
4450 var pars = new List<Parameter> (4);
4451 pars.Add ((Parameter) $1);
4455 | lambda_parameter_list COMMA lambda_parameter
4457 var pars = (List<Parameter>) $1;
4458 Parameter p = (Parameter)$3;
4459 if (pars[0].GetType () != p.GetType ()) {
4460 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4469 : parameter_modifier parameter_type identifier_inside_body
4471 var lt = (LocatedToken) $3;
4473 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4475 | parameter_type identifier_inside_body
4477 var lt = (LocatedToken) $2;
4479 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4483 var lt = (LocatedToken) $1;
4484 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4488 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4489 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4493 opt_lambda_parameter_list
4494 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4495 | lambda_parameter_list {
4496 var pars_list = (List<Parameter>) $1;
4497 $$ = new ParametersCompiled (pars_list.ToArray ());
4501 lambda_expression_body
4503 start_block (Location.Null);
4505 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4507 Block b = end_block (Location.Null);
4508 b.IsCompilerGenerated = true;
4509 b.AddStatement (new ContextualReturn ((Expression) $2));
4515 // Handles only cases like foo = x.FirstOrDefault (l => );
4516 // where we must restore current_variable
4517 Block b = end_block (Location.Null);
4518 b.IsCompilerGenerated = true;
4520 Error_SyntaxError (yyToken);
4529 Error_SyntaxError (yyToken);
4537 var lt = (LocatedToken) $1;
4538 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4539 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4541 lambda_expression_body
4543 $$ = end_anonymous ((ParametersBlock) $4);
4544 lbag.AddLocation ($$, GetLocation ($2));
4548 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4549 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4550 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4552 lambda_expression_body
4554 $$ = end_anonymous ((ParametersBlock) $4);
4555 lbag.AddLocation ($$, GetLocation ($2));
4557 | ASYNC identifier_inside_body ARROW
4559 var lt = (LocatedToken) $2;
4560 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4561 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4563 lambda_expression_body
4565 $$ = end_anonymous ((ParametersBlock) $5);
4566 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4568 | OPEN_PARENS_LAMBDA
4570 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4572 opt_lambda_parameter_list CLOSE_PARENS ARROW
4574 valid_param_mod = 0;
4575 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4577 lambda_expression_body
4579 $$ = end_anonymous ((ParametersBlock) $7);
4580 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4582 | ASYNC OPEN_PARENS_LAMBDA
4584 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4586 opt_lambda_parameter_list CLOSE_PARENS ARROW
4588 valid_param_mod = 0;
4589 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4591 lambda_expression_body
4593 $$ = end_anonymous ((ParametersBlock) $8);
4594 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4599 : assignment_expression
4600 | non_assignment_expression
4603 non_assignment_expression
4604 : conditional_expression
4609 $$ = new ArglistAccess (GetLocation ($1));
4613 undocumented_expressions
4614 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4616 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4617 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4619 | REFTYPE open_parens_any expression CLOSE_PARENS
4621 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4622 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4624 | MAKEREF open_parens_any expression CLOSE_PARENS
4626 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4627 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4638 $$ = new BooleanExpression ((Expression) $1);
4642 opt_primary_parameters
4647 | primary_parameters
4651 : OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
4655 // Cannot use opt_formal_parameter_list because it can be shared instance for empty parameters
4656 lbag.AppendToMember (current_container, GetLocation ($1), GetLocation ($3));
4660 opt_primary_parameters_with_class_base
4669 | primary_parameters
4673 | primary_parameters class_base OPEN_PARENS
4675 ++lexer.parsing_block;
4677 opt_argument_list CLOSE_PARENS
4679 lbag.AppendToMember (current_container, GetLocation ($3), GetLocation ($6));
4680 ((Class)current_type).PrimaryConstructorBaseArguments = (Arguments) $5;
4681 --lexer.parsing_block;
4697 type_declaration_name
4699 lexer.ConstraintsParsing = true;
4701 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4702 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4703 FeatureIsNotAvailable (c.Location, "static classes");
4706 push_current_container (c, $3);
4707 valid_param_mod = ParameterModifierType.PrimaryConstructor;
4709 opt_primary_parameters_with_class_base
4710 opt_type_parameter_constraints_clauses
4712 valid_param_mod = 0;
4713 lexer.ConstraintsParsing = false;
4716 current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
4719 current_container.SetConstraints ((List<Constraints>) $9);
4720 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4723 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4724 Lexer.doc_state = XmlCommentState.Allowed;
4727 lexer.parsing_modifiers = true;
4729 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4731 --lexer.parsing_declaration;
4733 Lexer.doc_state = XmlCommentState.Allowed;
4738 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4740 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4742 $$ = pop_current_class ();
4750 { $$ = $1; } // location
4756 mod_locations = null;
4758 lexer.parsing_modifiers = false;
4762 lexer.parsing_modifiers = false;
4768 | modifiers modifier
4770 var m1 = (Modifiers) $1;
4771 var m2 = (Modifiers) $2;
4773 if ((m1 & m2) != 0) {
4774 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4775 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4776 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4777 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4778 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4779 "More than one protection modifier specified");
4790 StoreModifierLocation ($$, GetLocation ($1));
4792 if (current_container.Kind == MemberKind.Namespace)
4793 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4797 $$ = Modifiers.PUBLIC;
4798 StoreModifierLocation ($$, GetLocation ($1));
4802 $$ = Modifiers.PROTECTED;
4803 StoreModifierLocation ($$, GetLocation ($1));
4807 $$ = Modifiers.INTERNAL;
4808 StoreModifierLocation ($$, GetLocation ($1));
4812 $$ = Modifiers.PRIVATE;
4813 StoreModifierLocation ($$, GetLocation ($1));
4817 $$ = Modifiers.ABSTRACT;
4818 StoreModifierLocation ($$, GetLocation ($1));
4822 $$ = Modifiers.SEALED;
4823 StoreModifierLocation ($$, GetLocation ($1));
4827 $$ = Modifiers.STATIC;
4828 StoreModifierLocation ($$, GetLocation ($1));
4832 $$ = Modifiers.READONLY;
4833 StoreModifierLocation ($$, GetLocation ($1));
4837 $$ = Modifiers.VIRTUAL;
4838 StoreModifierLocation ($$, GetLocation ($1));
4842 $$ = Modifiers.OVERRIDE;
4843 StoreModifierLocation ($$, GetLocation ($1));
4847 $$ = Modifiers.EXTERN;
4848 StoreModifierLocation ($$, GetLocation ($1));
4852 $$ = Modifiers.VOLATILE;
4853 StoreModifierLocation ($$, GetLocation ($1));
4857 $$ = Modifiers.UNSAFE;
4858 StoreModifierLocation ($$, GetLocation ($1));
4859 if (!settings.Unsafe)
4860 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4864 $$ = Modifiers.ASYNC;
4865 StoreModifierLocation ($$, GetLocation ($1));
4877 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4879 | COLON type_list error
4881 Error_SyntaxError (yyToken);
4883 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4887 opt_type_parameter_constraints_clauses
4889 | type_parameter_constraints_clauses
4895 type_parameter_constraints_clauses
4896 : type_parameter_constraints_clause
4898 var constraints = new List<Constraints> (1);
4899 constraints.Add ((Constraints) $1);
4902 | type_parameter_constraints_clauses type_parameter_constraints_clause
4904 var constraints = (List<Constraints>) $1;
4905 Constraints new_constraint = (Constraints)$2;
4907 foreach (Constraints c in constraints) {
4908 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4909 report.Error (409, new_constraint.Location,
4910 "A constraint clause has already been specified for type parameter `{0}'",
4911 new_constraint.TypeParameter.Value);
4915 constraints.Add (new_constraint);
4920 type_parameter_constraints_clause
4921 : WHERE IDENTIFIER COLON type_parameter_constraints
4923 var lt = (LocatedToken) $2;
4924 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4925 lbag.AddLocation ($$, GetLocation ($3));
4927 | WHERE IDENTIFIER error
4929 Error_SyntaxError (yyToken);
4931 var lt = (LocatedToken) $2;
4932 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4936 type_parameter_constraints
4937 : type_parameter_constraint
4939 var constraints = new List<FullNamedExpression> (1);
4940 constraints.Add ((FullNamedExpression) $1);
4943 | type_parameter_constraints COMMA type_parameter_constraint
4945 var constraints = (List<FullNamedExpression>) $1;
4946 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4947 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4948 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4951 prev = $3 as SpecialContraintExpr;
4953 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4954 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4956 prev = constraints [0] as SpecialContraintExpr;
4957 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4958 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4963 constraints.Add ((FullNamedExpression) $3);
4968 type_parameter_constraint
4971 if ($1 is ComposedCast)
4972 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4976 | NEW OPEN_PARENS CLOSE_PARENS
4978 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4979 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4983 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4987 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4991 opt_type_parameter_variance
4996 | type_parameter_variance
4998 if (lang_version <= LanguageVersion.V_3)
4999 FeatureIsNotAvailable (lexer.Location, "generic type variance");
5005 type_parameter_variance
5008 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
5012 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
5021 // A block is "contained" on the following places:
5023 // property_declaration as part of the accessor body (get/set)
5024 // operator_declaration
5025 // constructor_declaration
5026 // destructor_declaration
5027 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
5032 ++lexer.parsing_block;
5033 start_block (GetLocation ($1));
5035 opt_statement_list block_end
5044 --lexer.parsing_block;
5045 $$ = end_block (GetLocation ($1));
5047 | COMPLETE_COMPLETION
5049 --lexer.parsing_block;
5050 $$ = end_block (lexer.Location);
5058 ++lexer.parsing_block;
5059 current_block.StartLocation = GetLocation ($1);
5061 opt_statement_list CLOSE_BRACE
5063 --lexer.parsing_block;
5064 $$ = end_block (GetLocation ($4));
5075 | statement_list statement
5079 : block_variable_declaration
5081 current_block.AddStatement ((Statement) $1);
5083 | valid_declaration_statement
5085 current_block.AddStatement ((Statement) $1);
5090 Error_SyntaxError (yyToken);
5096 // The interactive_statement and its derivatives are only
5097 // used to provide a special version of `expression_statement'
5098 // that has a side effect of assigning the expression to
5101 interactive_statement_list
5102 : interactive_statement
5103 | interactive_statement_list interactive_statement
5106 interactive_statement
5107 : block_variable_declaration
5109 current_block.AddStatement ((Statement) $1);
5111 | interactive_valid_declaration_statement
5113 current_block.AddStatement ((Statement) $1);
5118 valid_declaration_statement
5121 | expression_statement
5122 | selection_statement
5123 | iteration_statement
5127 | unchecked_statement
5134 interactive_valid_declaration_statement
5137 | interactive_expression_statement
5138 | selection_statement
5139 | iteration_statement
5143 | unchecked_statement
5151 : valid_declaration_statement
5152 | block_variable_declaration
5154 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5159 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5164 Error_SyntaxError (yyToken);
5165 $$ = new EmptyStatement (GetLocation ($1));
5172 // Uses lexer.Location because semicolon location is not kept in quick mode
5173 $$ = new EmptyStatement (lexer.Location);
5178 : identifier_inside_body COLON
5180 var lt = (LocatedToken) $1;
5181 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5182 lbag.AddLocation (labeled, GetLocation ($2));
5183 current_block.AddLabel (labeled);
5184 current_block.AddStatement (labeled);
5190 : variable_type_simple
5191 | variable_type_simple rank_specifiers
5194 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5196 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5201 * The following is from Rhys' grammar:
5202 * > Types in local variable declarations must be recognized as
5203 * > expressions to prevent reduce/reduce errors in the grammar.
5204 * > The expressions are converted into types during semantic analysis.
5206 variable_type_simple
5207 : primary_expression_or_type opt_nullable
5209 // Ok, the above "primary_expression" is there to get rid of
5210 // both reduce/reduce and shift/reduces in the grammar, it should
5211 // really just be "type_name". If you use type_name, a reduce/reduce
5212 // creeps up. If you use namespace_or_type_name (which is all we need
5213 // really) two shift/reduces appear.
5216 // So the super-trick is that primary_expression
5217 // can only be either a SimpleName or a MemberAccess.
5218 // The MemberAccess case arises when you have a fully qualified type-name like :
5220 // SimpleName is when you have
5223 Expression expr = (Expression) $1;
5225 SimpleName sn = expr as SimpleName;
5226 if (sn != null && sn.Name == "var")
5227 $$ = new VarExpr (sn.Location);
5230 } else if (expr is ATypeNameExpression) {
5231 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5233 Error_ExpectingTypeName (expr);
5237 | primary_expression_or_type pointer_stars
5239 ATypeNameExpression expr = $1 as ATypeNameExpression;
5242 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5244 Error_ExpectingTypeName ((Expression)$1);
5248 | builtin_types opt_nullable
5253 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5255 | builtin_types pointer_stars
5257 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5259 | VOID pointer_stars
5261 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5265 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5266 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5272 | pointer_star pointer_stars
5274 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5282 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5286 identifier_inside_body
5290 $$ = Error_AwaitAsIdentifier ($1);
5294 block_variable_declaration
5295 : variable_type identifier_inside_body
5297 var lt = (LocatedToken) $2;
5298 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5299 current_block.AddLocalName (li);
5300 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5302 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5304 $$ = current_variable;
5305 current_variable = null;
5307 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5309 lbag.AddLocation ($$, GetLocation ($6));
5311 | CONST variable_type identifier_inside_body
5313 var lt = (LocatedToken) $3;
5314 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5315 current_block.AddLocalName (li);
5316 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5318 const_variable_initializer opt_const_declarators SEMICOLON
5320 $$ = current_variable;
5321 current_variable = null;
5322 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5326 opt_local_variable_initializer
5328 | ASSIGN block_variable_initializer
5330 current_variable.Initializer = (Expression) $2;
5331 PushLocation (GetLocation ($1));
5332 $$ = current_variable;
5336 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5337 report.Error (650, lexer.Location,
5338 "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");
5340 Error_SyntaxError (yyToken);
5345 opt_variable_declarators
5347 | variable_declarators
5350 opt_using_or_fixed_variable_declarators
5352 | variable_declarators
5354 foreach (var d in current_variable.Declarators) {
5355 if (d.Initializer == null)
5356 Error_MissingInitializer (d.Variable.Location);
5361 variable_declarators
5362 : variable_declarator
5363 | variable_declarators variable_declarator
5367 : COMMA identifier_inside_body
5369 var lt = (LocatedToken) $2;
5370 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5371 var d = new BlockVariableDeclarator (li, null);
5372 current_variable.AddDeclarator (d);
5373 current_block.AddLocalName (li);
5374 lbag.AddLocation (d, GetLocation ($1));
5376 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5378 var lt = (LocatedToken) $2;
5379 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5380 var d = new BlockVariableDeclarator (li, (Expression) $4);
5381 current_variable.AddDeclarator (d);
5382 current_block.AddLocalName (li);
5383 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5387 const_variable_initializer
5390 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5392 | ASSIGN constant_initializer_expr
5394 current_variable.Initializer = (Expression) $2;
5398 opt_const_declarators
5405 | const_declarators const_declarator
5409 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5411 var lt = (LocatedToken) $2;
5412 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5413 var d = new BlockVariableDeclarator (li, (Expression) $4);
5414 current_variable.AddDeclarator (d);
5415 current_block.AddLocalName (li);
5416 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5420 block_variable_initializer
5421 : variable_initializer
5422 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5424 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5425 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5427 | STACKALLOC simple_type
5429 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5430 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5434 expression_statement
5435 : statement_expression SEMICOLON
5438 lbag.AddStatement ($$, GetLocation ($2));
5440 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5441 | statement_expression CLOSE_BRACE
5444 report.Error (1002, GetLocation ($2), "; expected");
5445 lexer.putback ('}');
5449 interactive_expression_statement
5450 : interactive_statement_expression SEMICOLON { $$ = $1; }
5451 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5455 // We have to do the wrapping here and not in the case above,
5456 // because statement_expression is used for example in for_statement
5458 statement_expression
5461 ExpressionStatement s = $1 as ExpressionStatement;
5463 var expr = $1 as Expression;
5464 $$ = new StatementErrorExpression (expr);
5466 $$ = new StatementExpression (s);
5471 interactive_statement_expression
5474 Expression expr = (Expression) $1;
5475 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5479 Error_SyntaxError (yyToken);
5480 $$ = new EmptyStatement (GetLocation ($1));
5490 : IF open_parens_any boolean_expression CLOSE_PARENS
5493 if ($5 is EmptyStatement)
5494 Warning_EmptyStatement (GetLocation ($5));
5496 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5497 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5499 | IF open_parens_any boolean_expression CLOSE_PARENS
5500 embedded_statement ELSE embedded_statement
5502 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5503 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5505 if ($5 is EmptyStatement)
5506 Warning_EmptyStatement (GetLocation ($5));
5507 if ($7 is EmptyStatement)
5508 Warning_EmptyStatement (GetLocation ($7));
5510 | IF open_parens_any boolean_expression error
5512 Error_SyntaxError (yyToken);
5514 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5515 lbag.AddStatement ($$, GetLocation ($2));
5520 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5522 start_block (GetLocation ($5));
5524 opt_switch_sections CLOSE_BRACE
5526 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5527 end_block (GetLocation ($8));
5528 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5530 | SWITCH open_parens_any expression error
5532 Error_SyntaxError (yyToken);
5534 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5535 lbag.AddStatement ($$, GetLocation ($2));
5542 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5549 | switch_sections switch_section
5552 Error_SyntaxError (yyToken);
5557 : switch_labels statement_list
5563 var label = (SwitchLabel) $1;
5564 label.SectionStart = true;
5565 current_block.AddStatement (label);
5567 | switch_labels switch_label
5569 current_block.AddStatement ((Statement) $2);
5574 : CASE constant_expression COLON
5576 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5577 lbag.AddLocation ($$, GetLocation ($3));
5579 | CASE constant_expression error
5581 Error_SyntaxError (yyToken);
5582 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5586 $$ = new SwitchLabel (null, GetLocation ($1));
5598 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5600 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5601 Warning_EmptyStatement (GetLocation ($5));
5603 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5604 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5606 | WHILE open_parens_any boolean_expression error
5608 Error_SyntaxError (yyToken);
5610 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5611 lbag.AddStatement ($$, GetLocation ($2));
5616 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5618 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5619 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5621 | DO embedded_statement error
5623 Error_SyntaxError (yyToken);
5624 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5626 | DO embedded_statement WHILE open_parens_any boolean_expression error
5628 Error_SyntaxError (yyToken);
5630 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5631 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5636 : FOR open_parens_any
5638 start_block (GetLocation ($2));
5639 current_block.IsCompilerGenerated = true;
5640 For f = new For (GetLocation ($1));
5641 current_block.AddStatement (f);
5650 // Has to use be extra rule to recover started block
5652 : opt_for_initializer SEMICOLON
5654 ((For) $0).Initializer = (Statement) $1;
5656 // Pass the "For" object to the iterator_part4
5657 oob_stack.Push ($0);
5659 for_condition_and_iterator_part
5662 var locations = (Tuple<Location,Location>) $4;
5664 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5665 Warning_EmptyStatement (GetLocation ($5));
5668 f.Statement = (Statement) $5;
5669 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5671 $$ = end_block (GetLocation ($2));
5675 Error_SyntaxError (yyToken);
5676 $$ = end_block (current_block.StartLocation);
5680 for_condition_and_iterator_part
5681 : opt_for_condition SEMICOLON
5683 For f = (For) oob_stack.Peek ();
5684 f.Condition = (BooleanExpression) $1;
5687 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5690 // Handle errors in the case of opt_for_condition being followed by
5691 // a close parenthesis
5692 | opt_for_condition close_parens_close_brace {
5693 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5694 For f = (For) oob_stack.Peek ();
5695 f.Condition = (BooleanExpression) $1;
5696 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5701 : opt_for_iterator CLOSE_PARENS {
5702 For f = (For) oob_stack.Peek ();
5703 f.Iterator = (Statement) $1;
5704 $$ = GetLocation ($2);
5706 | opt_for_iterator CLOSE_BRACE {
5707 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5708 For f = (For) oob_stack.Peek ();
5709 f.Iterator = (Statement) $1;
5710 $$ = GetLocation ($2);
5714 close_parens_close_brace
5716 | CLOSE_BRACE { lexer.putback ('}'); }
5720 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5725 : variable_type identifier_inside_body
5727 var lt = (LocatedToken) $2;
5728 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5729 current_block.AddLocalName (li);
5730 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5732 opt_local_variable_initializer opt_variable_declarators
5734 $$ = current_variable;
5736 lbag.AddLocation (current_variable, PopLocation ());
5738 current_variable = null;
5740 | statement_expression_list
5744 : /* empty */ { $$ = null; }
5745 | boolean_expression
5749 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5754 : statement_expression_list
5757 statement_expression_list
5758 : statement_expression
5759 | statement_expression_list COMMA statement_expression
5761 var sl = $1 as StatementList;
5763 sl = new StatementList ((Statement) $1, (Statement) $3);
5764 lbag.AddStatement (sl, GetLocation ($2));
5766 sl.Add ((Statement) $3);
5767 lbag.AppendTo (sl, GetLocation ($2));
5775 : FOREACH open_parens_any type error
5777 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5779 start_block (GetLocation ($2));
5780 current_block.IsCompilerGenerated = true;
5782 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5783 current_block.AddStatement (f);
5785 lbag.AddStatement (f, GetLocation ($2));
5786 $$ = end_block (GetLocation ($4));
5788 | FOREACH open_parens_any type identifier_inside_body error
5790 Error_SyntaxError (yyToken);
5792 start_block (GetLocation ($2));
5793 current_block.IsCompilerGenerated = true;
5795 var lt = (LocatedToken) $4;
5796 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5797 current_block.AddLocalName (li);
5799 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5800 current_block.AddStatement (f);
5802 lbag.AddStatement (f, GetLocation ($2));
5803 $$ = end_block (GetLocation ($5));
5805 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5807 start_block (GetLocation ($2));
5808 current_block.IsCompilerGenerated = true;
5810 var lt = (LocatedToken) $4;
5811 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5812 current_block.AddLocalName (li);
5817 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5818 Warning_EmptyStatement (GetLocation ($9));
5820 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5821 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5822 end_block (GetLocation ($7));
5830 | continue_statement
5840 $$ = new Break (GetLocation ($1));
5841 lbag.AddStatement ($$, GetLocation ($2));
5846 : CONTINUE SEMICOLON
5848 $$ = new Continue (GetLocation ($1));
5849 lbag.AddStatement ($$, GetLocation ($2));
5853 Error_SyntaxError (yyToken);
5854 $$ = new Continue (GetLocation ($1));
5859 : GOTO identifier_inside_body SEMICOLON
5861 var lt = (LocatedToken) $2;
5862 $$ = new Goto (lt.Value, GetLocation ($1));
5863 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5865 | GOTO CASE constant_expression SEMICOLON
5867 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5868 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5870 | GOTO DEFAULT SEMICOLON
5872 $$ = new GotoDefault (GetLocation ($1));
5873 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5878 : RETURN opt_expression SEMICOLON
5880 $$ = new Return ((Expression) $2, GetLocation ($1));
5881 lbag.AddStatement ($$, GetLocation ($3));
5883 | RETURN expression error
5885 Error_SyntaxError (yyToken);
5886 $$ = new Return ((Expression) $2, GetLocation ($1));
5890 Error_SyntaxError (yyToken);
5891 $$ = new Return (null, GetLocation ($1));
5896 : THROW opt_expression SEMICOLON
5898 $$ = new Throw ((Expression) $2, GetLocation ($1));
5899 lbag.AddStatement ($$, GetLocation ($3));
5901 | THROW expression error
5903 Error_SyntaxError (yyToken);
5904 $$ = new Throw ((Expression) $2, GetLocation ($1));
5908 Error_SyntaxError (yyToken);
5909 $$ = new Throw (null, GetLocation ($1));
5914 : identifier_inside_body RETURN opt_expression SEMICOLON
5916 var lt = (LocatedToken) $1;
5917 string s = lt.Value;
5919 report.Error (1003, lt.Location, "; expected");
5920 } else if ($3 == null) {
5921 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5922 } else if (lang_version == LanguageVersion.ISO_1){
5923 FeatureIsNotAvailable (lt.Location, "iterators");
5926 current_block.Explicit.RegisterIteratorYield ();
5927 $$ = new Yield ((Expression) $3, lt.Location);
5928 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5930 | identifier_inside_body RETURN expression error
5932 Error_SyntaxError (yyToken);
5934 var lt = (LocatedToken) $1;
5935 string s = lt.Value;
5937 report.Error (1003, lt.Location, "; expected");
5938 } else if ($3 == null) {
5939 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5940 } else if (lang_version == LanguageVersion.ISO_1){
5941 FeatureIsNotAvailable (lt.Location, "iterators");
5944 current_block.Explicit.RegisterIteratorYield ();
5945 $$ = new Yield ((Expression) $3, lt.Location);
5946 lbag.AddStatement ($$, GetLocation ($2));
5948 | identifier_inside_body BREAK SEMICOLON
5950 var lt = (LocatedToken) $1;
5951 string s = lt.Value;
5953 report.Error (1003, lt.Location, "; expected");
5954 } else if (lang_version == LanguageVersion.ISO_1){
5955 FeatureIsNotAvailable (lt.Location, "iterators");
5958 current_block.ParametersBlock.TopBlock.IsIterator = true;
5959 $$ = new YieldBreak (lt.Location);
5960 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5970 : TRY block catch_clauses
5972 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5974 | TRY block FINALLY block
5976 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
5977 lbag.AddStatement ($$, GetLocation ($3));
5979 | TRY block catch_clauses FINALLY block
5981 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
5982 lbag.AddStatement ($$, GetLocation ($4));
5986 Error_SyntaxError (1524, yyToken);
5987 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5994 var l = new List<Catch> (2);
5999 | catch_clauses catch_clause
6001 var l = (List<Catch>) $1;
6003 Catch c = (Catch) $2;
6004 var prev_catch = l [l.Count - 1];
6005 if (prev_catch.IsGeneral && prev_catch.Filter == null) {
6006 report.Error (1017, c.loc, "Try statement already has an empty catch block");
6016 | identifier_inside_body
6020 : CATCH opt_catch_filter block
6022 var c = new Catch ((ExplicitBlock) $3, GetLocation ($1));
6023 c.Filter = (CatchFilterExpression) $2;
6026 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
6028 start_block (GetLocation ($2));
6029 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
6030 c.TypeExpression = (FullNamedExpression) $3;
6033 var lt = (LocatedToken) $4;
6034 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6035 current_block.AddLocalName (c.Variable);
6038 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6041 opt_catch_filter block_prepared
6043 ((Catch) $6).Filter = (CatchFilterExpression) $7;
6046 | CATCH open_parens_any error
6048 if (yyToken == Token.CLOSE_PARENS) {
6049 report.Error (1015, lexer.Location,
6050 "A type that derives from `System.Exception', `object', or `string' expected");
6052 Error_SyntaxError (yyToken);
6055 $$ = new Catch (null, GetLocation ($1));
6057 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
6059 Error_SyntaxError (yyToken);
6061 // Required otherwise missing block could not be detected because
6062 // start_block is run early
6063 var c = new Catch (null, GetLocation ($1));
6064 c.TypeExpression = (FullNamedExpression) $3;
6067 var lt = (LocatedToken) $4;
6068 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6071 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6079 | IF open_parens_any expression CLOSE_PARENS
6081 if (lang_version <= LanguageVersion.V_5)
6082 FeatureIsNotAvailable (GetLocation ($1), "exception filter");
6084 $$ = new CatchFilterExpression ((Expression) $3, GetLocation ($1));
6085 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
6092 $$ = new Checked ((Block) $2, GetLocation ($1));
6099 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6106 if (!settings.Unsafe)
6107 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6109 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6114 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6116 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6117 Warning_EmptyStatement (GetLocation ($5));
6119 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6120 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6122 | LOCK open_parens_any expression error
6124 Error_SyntaxError (yyToken);
6126 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6127 lbag.AddStatement ($$, GetLocation ($2));
6132 : FIXED open_parens_any variable_type identifier_inside_body
6134 start_block (GetLocation ($2));
6136 current_block.IsCompilerGenerated = true;
6137 var lt = (LocatedToken) $4;
6138 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6139 current_block.AddLocalName (li);
6140 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6142 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6144 $$ = current_variable;
6145 current_variable = null;
6149 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6150 Warning_EmptyStatement (GetLocation ($10));
6152 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6153 current_block.AddStatement (f);
6154 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6155 $$ = end_block (GetLocation ($8));
6160 : USING open_parens_any variable_type identifier_inside_body
6162 start_block (GetLocation ($2));
6164 current_block.IsCompilerGenerated = true;
6165 var lt = (LocatedToken) $4;
6166 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6167 current_block.AddLocalName (li);
6168 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6170 using_initialization CLOSE_PARENS
6172 $$ = current_variable;
6173 current_variable = null;
6177 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6178 Warning_EmptyStatement (GetLocation ($9));
6180 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6181 current_block.AddStatement (u);
6182 $$ = end_block (GetLocation ($7));
6184 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6186 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6187 Warning_EmptyStatement (GetLocation ($5));
6189 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6190 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6192 | USING open_parens_any expression error
6194 Error_SyntaxError (yyToken);
6196 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6197 lbag.AddStatement ($$, GetLocation ($2));
6201 using_initialization
6202 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6205 // It has to be here for the parent to safely restore artificial block
6206 Error_SyntaxError (yyToken);
6210 using_or_fixed_variable_initializer
6213 Error_MissingInitializer (lexer.Location);
6215 | ASSIGN variable_initializer
6217 current_variable.Initializer = (Expression) $2;
6218 $$ = current_variable;
6226 : first_from_clause query_body
6228 lexer.query_parsing = false;
6230 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6232 from.Tail.Next = (Linq.AQueryClause)$2;
6235 current_block.SetEndLocation (lexer.Location);
6236 current_block = current_block.Parent;
6238 | nested_from_clause query_body
6240 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6242 from.Tail.Next = (Linq.AQueryClause)$2;
6245 current_block.SetEndLocation (lexer.Location);
6246 current_block = current_block.Parent;
6249 // Bubble up COMPLETE_COMPLETION productions
6250 | first_from_clause COMPLETE_COMPLETION {
6251 lexer.query_parsing = false;
6254 current_block.SetEndLocation (lexer.Location);
6255 current_block = current_block.Parent;
6257 | nested_from_clause COMPLETE_COMPLETION {
6259 current_block.SetEndLocation (lexer.Location);
6260 current_block = current_block.Parent;
6265 : FROM_FIRST identifier_inside_body IN expression
6267 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6269 var lt = (LocatedToken) $2;
6270 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6271 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6272 lbag.AddLocation (clause, GetLocation ($3));
6273 $$ = new Linq.QueryExpression (clause);
6275 | FROM_FIRST type identifier_inside_body IN expression
6277 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6279 var lt = (LocatedToken) $3;
6280 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6281 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6282 IdentifierType = (FullNamedExpression)$2
6284 lbag.AddLocation (clause, GetLocation ($4));
6285 $$ = new Linq.QueryExpression (clause);
6290 : FROM identifier_inside_body IN expression
6292 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6294 var lt = (LocatedToken) $2;
6295 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6296 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6297 lbag.AddLocation (clause, GetLocation ($3));
6298 $$ = new Linq.QueryExpression (clause);
6300 | FROM type identifier_inside_body IN expression
6302 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6304 var lt = (LocatedToken) $3;
6305 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6306 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6307 IdentifierType = (FullNamedExpression)$2
6309 lbag.AddLocation (clause, GetLocation ($4));
6310 $$ = new Linq.QueryExpression (clause);
6315 : FROM identifier_inside_body IN
6317 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6321 var lt = (LocatedToken) $2;
6322 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6323 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6325 current_block.SetEndLocation (lexer.Location);
6326 current_block = current_block.Parent;
6328 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6329 lbag.AddLocation ($$, GetLocation ($3));
6331 | FROM type identifier_inside_body IN
6333 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6337 var lt = (LocatedToken) $3;
6338 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6340 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6341 IdentifierType = (FullNamedExpression)$2
6344 current_block.SetEndLocation (lexer.Location);
6345 current_block = current_block.Parent;
6347 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6349 lbag.AddLocation ($$, GetLocation ($4));
6354 : query_body_clauses select_or_group_clause opt_query_continuation
6356 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6359 head.Next = (Linq.AQueryClause)$3;
6362 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6363 clause.Tail.Next = head;
6369 | select_or_group_clause opt_query_continuation
6371 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6374 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6375 clause.Tail.Next = head;
6381 | query_body_clauses COMPLETE_COMPLETION
6382 | query_body_clauses error
6384 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6389 Error_SyntaxError (yyToken);
6394 select_or_group_clause
6397 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6401 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6403 current_block.SetEndLocation (lexer.Location);
6404 current_block = current_block.Parent;
6408 if (linq_clause_blocks == null)
6409 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6411 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6412 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6416 current_block.SetEndLocation (lexer.Location);
6417 current_block = current_block.Parent;
6419 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6423 var obj = (object[]) $5;
6425 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6426 lbag.AddLocation ($$, (Location) obj[1]);
6428 current_block.SetEndLocation (lexer.Location);
6429 current_block = current_block.Parent;
6434 : BY expression_or_error
6436 $$ = new object[] { $2, GetLocation ($1) };
6440 Error_SyntaxError (yyToken);
6441 $$ = new object[2] { null, Location.Null };
6447 | query_body_clauses query_body_clause
6449 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6463 : LET identifier_inside_body ASSIGN
6465 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6469 var lt = (LocatedToken) $2;
6470 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6471 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6472 lbag.AddLocation ($$, GetLocation ($3));
6474 current_block.SetEndLocation (lexer.Location);
6475 current_block = current_block.Parent;
6477 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6484 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6488 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6490 current_block.SetEndLocation (lexer.Location);
6491 current_block = current_block.Parent;
6496 : JOIN identifier_inside_body IN
6498 if (linq_clause_blocks == null)
6499 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6501 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6502 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6504 expression_or_error ON
6506 current_block.SetEndLocation (lexer.Location);
6507 current_block = current_block.Parent;
6509 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6510 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6512 expression_or_error EQUALS
6514 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6515 current_block.SetEndLocation (lexer.Location);
6516 current_block = current_block.Parent;
6518 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6520 expression_or_error opt_join_into
6522 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6523 current_block.SetEndLocation (lexer.Location);
6525 var outer_selector = linq_clause_blocks.Pop ();
6526 var block = linq_clause_blocks.Pop ();
6528 var lt = (LocatedToken) $2;
6529 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6530 Linq.RangeVariable into;
6534 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6535 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6538 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6540 var parent = block.Parent;
6541 while (parent is Linq.QueryBlock) {
6542 parent = parent.Parent;
6544 current_block.Parent = parent;
6546 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6548 lt = (LocatedToken) $12;
6549 into = new Linq.RangeVariable (lt.Value, lt.Location);
6551 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6552 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6555 current_block = block.Parent;
6556 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6558 | JOIN type identifier_inside_body IN
6560 if (linq_clause_blocks == null)
6561 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6563 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6564 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6566 expression_or_error ON
6568 current_block.SetEndLocation (lexer.Location);
6569 current_block = current_block.Parent;
6571 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6572 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6574 expression_or_error EQUALS
6576 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6577 current_block.SetEndLocation (lexer.Location);
6578 current_block = current_block.Parent;
6580 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6582 expression_or_error opt_join_into
6584 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6585 current_block.SetEndLocation (lexer.Location);
6587 var outer_selector = linq_clause_blocks.Pop ();
6588 var block = linq_clause_blocks.Pop ();
6590 var lt = (LocatedToken) $3;
6591 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6592 Linq.RangeVariable into;
6596 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6597 IdentifierType = (FullNamedExpression)$2
6599 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6602 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6604 var parent = block.Parent;
6605 while (parent is Linq.QueryBlock) {
6606 parent = parent.Parent;
6608 current_block.Parent = parent;
6610 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6612 lt = (LocatedToken) $13;
6613 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6615 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6616 IdentifierType = (FullNamedExpression)$2
6620 current_block = block.Parent;
6621 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6627 | INTO identifier_inside_body
6636 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6640 current_block.SetEndLocation (lexer.Location);
6641 current_block = current_block.Parent;
6651 current_block.SetEndLocation (lexer.Location);
6652 current_block = current_block.Parent;
6654 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6658 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6665 | orderings_then_by COMMA
6667 current_block.SetEndLocation (lexer.Location);
6668 current_block = current_block.Parent;
6670 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6674 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6682 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6684 | expression ASCENDING
6686 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6687 lbag.AddLocation ($$, GetLocation ($2));
6689 | expression DESCENDING
6691 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6692 lbag.AddLocation ($$, GetLocation ($2));
6699 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6701 | expression ASCENDING
6703 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6704 lbag.AddLocation ($$, GetLocation ($2));
6706 | expression DESCENDING
6708 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6709 lbag.AddLocation ($$, GetLocation ($2));
6714 opt_query_continuation
6716 | INTO identifier_inside_body
6718 // query continuation block is not linked with query block but with block
6719 // before. This means each query can use same range variable names for
6720 // different identifiers.
6722 current_block.SetEndLocation (GetLocation ($1));
6723 current_block = current_block.Parent;
6725 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6727 if (linq_clause_blocks == null)
6728 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6730 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6734 var current_block = linq_clause_blocks.Pop ();
6735 var lt = (LocatedToken) $2;
6736 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6737 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6738 next = (Linq.AQueryClause)$4
6744 // Support for using the compiler as an interactive parser
6746 // The INTERACTIVE_PARSER token is first sent to parse our
6747 // productions; If the result is a Statement, the parsing
6748 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6749 // to setup the blocks in advance.
6751 // This setup is here so that in the future we can add
6752 // support for other constructs (type parsing, namespaces, etc)
6753 // that do not require a block to be setup in advance
6757 : EVAL_STATEMENT_PARSER EOF
6758 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6759 | EVAL_STATEMENT_PARSER
6761 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6763 // (ref object retval)
6764 Parameter [] mpar = new Parameter [1];
6765 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6767 ParametersCompiled pars = new ParametersCompiled (mpar);
6768 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6769 if (settings.Unsafe)
6770 mods |= Modifiers.UNSAFE;
6772 current_local_parameters = pars;
6773 var method = new InteractiveMethod (
6775 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6779 current_type.AddMember (method);
6780 oob_stack.Push (method);
6782 interactive_async = false;
6784 ++lexer.parsing_block;
6785 start_block (lexer.Location);
6787 interactive_statement_list opt_COMPLETE_COMPLETION
6789 --lexer.parsing_block;
6790 var method = (InteractiveMethod) oob_stack.Pop ();
6791 method.Block = (ToplevelBlock) end_block(lexer.Location);
6793 if (interactive_async == true) {
6794 method.ChangeToAsync ();
6797 InteractiveResult = (Class) pop_current_class ();
6798 current_local_parameters = null;
6800 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6803 interactive_compilation_unit
6804 : opt_extern_alias_directives opt_using_directives
6805 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6808 opt_COMPLETE_COMPLETION
6810 | COMPLETE_COMPLETION
6813 close_brace_or_complete_completion
6815 | COMPLETE_COMPLETION
6819 // XML documentation code references micro parser
6821 documentation_parsing
6824 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6829 : doc_type_declaration_name opt_doc_method_sig
6831 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6833 | builtin_types opt_doc_method_sig
6835 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6836 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6839 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6841 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6842 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6843 var lt = (LocatedToken) $3;
6844 $$ = new MemberName (lt.Value);
6846 | doc_type_declaration_name DOT THIS
6848 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6850 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6852 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6854 opt_doc_parameters CLOSE_BRACKET
6856 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6857 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6859 | EXPLICIT OPERATOR type opt_doc_method_sig
6861 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6862 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6863 module.DocumentationBuilder.ParsedParameters = p;
6864 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6867 | IMPLICIT OPERATOR type opt_doc_method_sig
6869 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6870 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6871 module.DocumentationBuilder.ParsedParameters = p;
6872 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6875 | OPERATOR overloadable_operator opt_doc_method_sig
6877 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6878 module.DocumentationBuilder.ParsedParameters = p;
6879 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6884 doc_type_declaration_name
6885 : type_declaration_name
6886 | doc_type_declaration_name DOT type_declaration_name
6888 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6896 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6898 opt_doc_parameters CLOSE_PARENS
6907 $$ = new List<DocumentationParameter> (0);
6915 var parameters = new List<DocumentationParameter> ();
6916 parameters.Add ((DocumentationParameter) $1);
6919 | doc_parameters COMMA doc_parameter
6921 var parameters = $1 as List<DocumentationParameter>;
6922 parameters.Add ((DocumentationParameter) $3);
6928 : opt_parameter_modifier parameter_type
6931 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6933 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6940 // A class used to hold info about an operator declarator
6942 class OperatorDeclaration {
6943 public readonly Operator.OpType optype;
6944 public readonly FullNamedExpression ret_type;
6945 public readonly Location location;
6947 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6950 this.ret_type = ret_type;
6951 this.location = location;
6955 void Error_ExpectingTypeName (Expression expr)
6957 if (expr is Invocation){
6958 report.Error (1002, expr.Location, "Expecting `;'");
6960 expr.Error_InvalidExpressionStatement (report);
6964 void Error_ParameterModifierNotValid (string modifier, Location loc)
6966 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6970 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6972 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6973 Parameter.GetModifierSignature (mod));
6976 void Error_TypeExpected (Location loc)
6978 report.Error (1031, loc, "Type expected");
6981 void Error_UnsafeCodeNotAllowed (Location loc)
6983 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6986 void Warning_EmptyStatement (Location loc)
6988 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6991 void Error_NamedArgumentExpected (NamedArgument a)
6993 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6996 void Error_MissingInitializer (Location loc)
6998 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
7001 object Error_AwaitAsIdentifier (object token)
7004 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
7005 return new LocatedToken ("await", GetLocation (token));
7011 void push_current_container (TypeDefinition tc, object partial_token)
7013 if (module.Evaluator != null){
7014 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
7018 undo.AddTypeContainer (current_container, tc);
7021 if (partial_token != null)
7022 current_container.AddPartial (tc);
7024 current_container.AddTypeContainer (tc);
7026 ++lexer.parsing_declaration;
7027 current_container = tc;
7031 TypeContainer pop_current_class ()
7033 var retval = current_container;
7035 current_container = current_container.Parent;
7036 current_type = current_type.Parent as TypeDefinition;
7041 [System.Diagnostics.Conditional ("FULL_AST")]
7042 void StoreModifierLocation (object token, Location loc)
7047 if (mod_locations == null)
7048 mod_locations = new List<Tuple<Modifiers, Location>> ();
7050 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
7053 [System.Diagnostics.Conditional ("FULL_AST")]
7054 void PushLocation (Location loc)
7056 if (location_stack == null)
7057 location_stack = new Stack<Location> ();
7059 location_stack.Push (loc);
7062 Location PopLocation ()
7064 if (location_stack == null)
7065 return Location.Null;
7067 return location_stack.Pop ();
7070 string CheckAttributeTarget (int token, string a, Location l)
7073 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
7077 if (!Tokenizer.IsValidIdentifier (a)) {
7078 Error_SyntaxError (token);
7080 report.Warning (658, 1, l,
7081 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7084 return string.Empty;
7087 static bool IsUnaryOperator (Operator.OpType op)
7091 case Operator.OpType.LogicalNot:
7092 case Operator.OpType.OnesComplement:
7093 case Operator.OpType.Increment:
7094 case Operator.OpType.Decrement:
7095 case Operator.OpType.True:
7096 case Operator.OpType.False:
7097 case Operator.OpType.UnaryPlus:
7098 case Operator.OpType.UnaryNegation:
7104 void syntax_error (Location l, string msg)
7106 report.Error (1003, l, "Syntax error, " + msg);
7111 public Tokenizer Lexer {
7117 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7118 : this (reader, file, file.Compiler.Report, session)
7122 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7125 current_container = current_namespace = file;
7127 this.module = file.Module;
7128 this.compiler = file.Compiler;
7129 this.settings = compiler.Settings;
7130 this.report = report;
7132 lang_version = settings.Version;
7133 yacc_verbose_flag = settings.VerboseParserFlag;
7134 doc_support = settings.DocumentationFile != null;
7135 lexer = new Tokenizer (reader, file, session, report);
7136 oob_stack = new Stack<object> ();
7137 lbag = session.LocationsBag;
7138 use_global_stacks = session.UseJayGlobalArrays;
7139 parameters_bucket = session.ParametersStack;
7142 public void parse ()
7144 eof_token = Token.EOF;
7147 if (yacc_verbose_flag > 1)
7148 yyparse (lexer, new yydebug.yyDebugSimple ());
7152 Tokenizer tokenizer = lexer as Tokenizer;
7153 tokenizer.cleanup ();
7154 } catch (Exception e){
7155 if (e is yyParser.yyUnexpectedEof) {
7156 Error_SyntaxError (yyToken);
7157 UnexpectedEOF = true;
7161 if (e is yyParser.yyException) {
7162 if (report.Errors == 0)
7163 report.Error (-25, lexer.Location, "Parsing error");
7165 // Used by compiler-tester to test internal errors
7166 if (yacc_verbose_flag > 0 || e is FatalException)
7169 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7174 void CheckToken (int error, int yyToken, string msg, Location loc)
7176 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7177 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7179 report.Error (error, loc, msg);
7182 string ConsumeStoredComment ()
7184 string s = tmpComment;
7186 Lexer.doc_state = XmlCommentState.Allowed;
7190 void FeatureIsNotAvailable (Location loc, string feature)
7192 report.FeatureIsNotAvailable (compiler, loc, feature);
7195 Location GetLocation (object obj)
7197 var lt = obj as LocatedToken;
7201 var mn = obj as MemberName;
7205 var expr = obj as Expression;
7207 return expr.Location;
7209 return lexer.Location;
7212 void start_block (Location loc)
7214 if (current_block == null) {
7215 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7216 parsing_anonymous_method = false;
7217 } else if (parsing_anonymous_method) {
7218 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7219 parsing_anonymous_method = false;
7221 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7226 end_block (Location loc)
7228 Block retval = current_block.Explicit;
7229 retval.SetEndLocation (loc);
7230 current_block = retval.Parent;
7234 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7236 oob_stack.Push (current_anonymous_method);
7237 oob_stack.Push (current_local_parameters);
7238 oob_stack.Push (current_variable);
7239 oob_stack.Push (async_block);
7241 current_local_parameters = parameters;
7243 if (lang_version <= LanguageVersion.ISO_2)
7244 FeatureIsNotAvailable (loc, "lambda expressions");
7246 current_anonymous_method = new LambdaExpression (loc);
7248 if (lang_version == LanguageVersion.ISO_1)
7249 FeatureIsNotAvailable (loc, "anonymous methods");
7251 current_anonymous_method = new AnonymousMethodExpression (loc);
7254 async_block = isAsync;
7255 // Force the next block to be created as a ToplevelBlock
7256 parsing_anonymous_method = true;
7260 * Completes the anonymous method processing, if lambda_expr is null, this
7261 * means that we have a Statement instead of an Expression embedded
7263 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7265 AnonymousMethodExpression retval;
7268 anon_block.IsAsync = true;
7270 current_anonymous_method.Block = anon_block;
7271 retval = current_anonymous_method;
7273 async_block = (bool) oob_stack.Pop ();
7274 current_variable = (BlockVariable) oob_stack.Pop ();
7275 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7276 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7281 void Error_SyntaxError (int token)
7283 Error_SyntaxError (0, token);
7286 void Error_SyntaxError (int error_code, int token)
7288 Error_SyntaxError (error_code, token, "Unexpected symbol");
7291 void Error_SyntaxError (int error_code, int token, string msg)
7293 Lexer.CompleteOnEOF = false;
7295 // An error message has been reported by tokenizer
7296 if (token == Token.ERROR)
7299 // Avoid duplicit error message after unterminated string literals
7300 if (token == Token.LITERAL && lexer.Location.Column == 0)
7303 string symbol = GetSymbolName (token);
7304 string expecting = GetExpecting ();
7305 var loc = lexer.Location - symbol.Length;
7307 if (error_code == 0) {
7308 if (expecting == "`identifier'") {
7309 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7310 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7315 expecting = "identifier";
7316 } else if (expecting == "`)'") {
7323 if (string.IsNullOrEmpty (expecting))
7324 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7326 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7329 string GetExpecting ()
7331 int [] tokens = yyExpectingTokens (yyExpectingState);
7332 var names = new List<string> (tokens.Length);
7333 bool has_type = false;
7334 bool has_identifier = false;
7335 for (int i = 0; i < tokens.Length; i++){
7336 int token = tokens [i];
7337 has_identifier |= token == Token.IDENTIFIER;
7339 string name = GetTokenName (token);
7340 if (name == "<internal>")
7343 has_type |= name == "type";
7344 if (names.Contains (name))
7351 // Too many tokens to enumerate
7353 if (names.Count > 8)
7356 if (has_type && has_identifier)
7357 names.Remove ("identifier");
7359 if (names.Count == 1)
7360 return "`" + GetTokenName (tokens [0]) + "'";
7362 StringBuilder sb = new StringBuilder ();
7364 int count = names.Count;
7365 for (int i = 0; i < count; i++){
7366 bool last = i + 1 == count;
7370 sb.Append (names [i]);
7371 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7373 return sb.ToString ();
7377 string GetSymbolName (int token)
7381 return ((Constant)lexer.Value).GetValue ().ToString ();
7382 case Token.IDENTIFIER:
7383 return ((LocatedToken)lexer.Value).Value;
7425 case Token.BITWISE_AND:
7427 case Token.BITWISE_OR:
7441 case Token.OP_SHIFT_LEFT:
7443 case Token.OP_SHIFT_RIGHT:
7463 case Token.OP_COALESCING:
7465 case Token.OP_MULT_ASSIGN:
7467 case Token.OP_DIV_ASSIGN:
7469 case Token.OP_MOD_ASSIGN:
7471 case Token.OP_ADD_ASSIGN:
7473 case Token.OP_SUB_ASSIGN:
7475 case Token.OP_SHIFT_LEFT_ASSIGN:
7477 case Token.OP_SHIFT_RIGHT_ASSIGN:
7479 case Token.OP_AND_ASSIGN:
7481 case Token.OP_XOR_ASSIGN:
7483 case Token.OP_OR_ASSIGN:
7487 return GetTokenName (token);
7490 static string GetTokenName (int token)
7493 case Token.ABSTRACT:
7515 case Token.CONTINUE:
7519 case Token.DELEGATE:
7529 case Token.EXPLICIT:
7532 case Token.EXTERN_ALIAS:
7548 case Token.IMPLICIT:
7552 case Token.INTERFACE:
7554 case Token.INTERNAL:
7560 case Token.NAMESPACE:
7566 case Token.OPERATOR:
7570 case Token.OVERRIDE:
7576 case Token.PROTECTED:
7580 case Token.READONLY:
7592 case Token.STACKALLOC:
7593 return "stackalloc";
7610 case Token.UNCHECKED:
7618 case Token.VOLATILE:
7626 case Token.REFVALUE:
7627 return "__refvalue";
7637 case Token.FROM_FIRST:
7655 case Token.ASCENDING:
7657 case Token.DESCENDING:
7658 return "descending";
7665 case Token.OPEN_BRACE:
7667 case Token.CLOSE_BRACE:
7669 case Token.OPEN_BRACKET:
7670 case Token.OPEN_BRACKET_EXPR:
7672 case Token.CLOSE_BRACKET:
7674 case Token.OPEN_PARENS_CAST:
7675 case Token.OPEN_PARENS_LAMBDA:
7676 case Token.OPEN_PARENS:
7678 case Token.CLOSE_PARENS:
7684 case Token.DEFAULT_COLON:
7688 case Token.SEMICOLON:
7699 case Token.BITWISE_AND:
7700 case Token.BITWISE_OR:
7707 case Token.OP_SHIFT_LEFT:
7708 case Token.OP_SHIFT_RIGHT:
7716 case Token.OP_COALESCING:
7717 case Token.OP_MULT_ASSIGN:
7718 case Token.OP_DIV_ASSIGN:
7719 case Token.OP_MOD_ASSIGN:
7720 case Token.OP_ADD_ASSIGN:
7721 case Token.OP_SUB_ASSIGN:
7722 case Token.OP_SHIFT_LEFT_ASSIGN:
7723 case Token.OP_SHIFT_RIGHT_ASSIGN:
7724 case Token.OP_AND_ASSIGN:
7725 case Token.OP_XOR_ASSIGN:
7726 case Token.OP_OR_ASSIGN:
7727 return "<operator>";
7749 case Token.OP_GENERICS_LT:
7750 case Token.GENERIC_DIMENSION:
7752 case Token.OP_GENERICS_GT:
7755 case Token.INTERR_NULLABLE:
7757 case Token.DOUBLE_COLON:
7761 case Token.IDENTIFIER:
7763 return "identifier";
7766 return "end-of-file";
7768 // All of these are internal.
7771 case Token.FIRST_KEYWORD:
7772 case Token.EVAL_COMPILATION_UNIT_PARSER:
7773 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7774 case Token.EVAL_STATEMENT_PARSER:
7775 case Token.LAST_KEYWORD:
7776 case Token.GENERATE_COMPLETION:
7777 case Token.COMPLETE_COMPLETION:
7778 return "<internal>";
7780 // A bit more robust.
7782 return yyNames [token];