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
41 static readonly object ModifierNone = 0;
43 NamespaceContainer current_namespace;
44 TypeContainer current_container;
45 TypeDefinition current_type;
46 PropertyBase current_property;
47 EventProperty current_event;
48 EventField current_event_field;
49 FieldBase current_field;
52 /// Current block is used to add statements as we find
57 BlockVariable current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 bool? interactive_async;
122 Stack<Linq.QueryBlock> linq_clause_blocks;
124 ModuleContainer module;
126 readonly CompilerContext compiler;
127 readonly LanguageVersion lang_version;
128 readonly bool doc_support;
129 readonly CompilerSettings settings;
130 readonly Report report;
133 // Instead of allocating carrier array everytime we
134 // share the bucket for very common constructs which can never
137 List<Parameter> parameters_bucket;
140 // Full AST support members
143 List<Tuple<Modifiers, Location>> mod_locations;
144 Stack<Location> location_stack;
148 %token NONE /* This token is never returned by our lexer */
149 %token ERROR // This is used not by the parser, but by the tokenizer.
153 *These are the C# keywords
252 %token INTERR_NULLABLE
260 /* C# keywords which are not really keywords */
266 /* C# single character operators/punctuation. */
294 /* C# multi-character operators. */
299 %token OP_SHIFT_RIGHT
306 %token OP_MULT_ASSIGN
311 %token OP_SHIFT_LEFT_ASSIGN
312 %token OP_SHIFT_RIGHT_ASSIGN
319 /* Generics <,> tokens */
320 %token OP_GENERICS_LT
321 %token OP_GENERICS_LT_DECL
322 %token OP_GENERICS_GT
327 %token OPEN_PARENS_LAMBDA
328 %token OPEN_PARENS_CAST
329 %token GENERIC_DIMENSION
331 %token OPEN_BRACKET_EXPR
333 // Make the parser go into eval mode parsing (statements and compilation units).
334 %token EVAL_STATEMENT_PARSER
335 %token EVAL_COMPILATION_UNIT_PARSER
336 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
341 // This token is generated to trigger the completion engine at this point
343 %token GENERATE_COMPLETION
346 // This token is return repeatedly after the first GENERATE_COMPLETION
347 // token is produced and before the final EOF
349 %token COMPLETE_COMPLETION
351 /* Add precedence rules to solve dangling else s/r conflict */
355 /* Define the operator tokens and their precedences */
363 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
365 %left STAR DIV PERCENT
366 %right BANG CARRET UMINUS
367 %nonassoc OP_INC OP_DEC
369 %left OPEN_BRACKET OPEN_BRACE
372 %start compilation_unit
376 : outer_declaration opt_EOF
378 Lexer.check_incorrect_doc_comment ();
380 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
381 | documentation_parsing
385 : opt_extern_alias_directives opt_using_directives
386 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
389 Attributes attrs = (Attributes) $4;
390 report.Error (1730, attrs.Attrs [0].Location,
391 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
393 current_namespace.UnattachedAttributes = attrs;
396 | opt_extern_alias_directives opt_using_directives attribute_sections
398 module.AddAttributes ((Attributes) $3, current_namespace);
402 if (yyToken == Token.EXTERN_ALIAS)
403 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
405 Error_SyntaxError (yyToken);
414 extern_alias_directives
415 : extern_alias_directive
416 | extern_alias_directives extern_alias_directive
419 extern_alias_directive
420 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
422 var lt = (LocatedToken) $2;
425 syntax_error (lt.Location, "`alias' expected");
427 if (lang_version == LanguageVersion.ISO_1)
428 FeatureIsNotAvailable (lt.Location, "external alias");
430 lt = (LocatedToken) $3;
431 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
432 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
435 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
436 current_namespace.AddUsing (na);
438 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
443 Error_SyntaxError (yyToken);
449 | using_directives using_directive
456 Lexer.doc_state = XmlCommentState.Allowed;
461 : USING namespace_or_type_expr SEMICOLON
463 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
464 current_namespace.AddUsing (un);
466 lbag.AddLocation (un, GetLocation ($3));
468 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
470 var lt = (LocatedToken) $2;
471 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
472 report.Warning (440, 2, lt.Location,
473 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
476 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
477 current_namespace.AddUsing (un);
479 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
483 Error_SyntaxError (yyToken);
489 // Strictly speaking, namespaces don't have attributes but
490 // we parse global attributes along with namespace declarations and then
493 namespace_declaration
494 : opt_attributes NAMESPACE namespace_name
496 Attributes attrs = (Attributes) $1;
497 var name = (MemberName) $3;
499 bool valid_global_attrs = true;
500 if ((current_namespace.DeclarationFound || current_namespace != file)) {
501 valid_global_attrs = false;
503 foreach (var a in attrs.Attrs) {
504 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
507 valid_global_attrs = false;
512 if (!valid_global_attrs)
513 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
516 module.AddAttributes (attrs, current_namespace);
518 var ns = new NamespaceContainer (name, current_namespace);
519 current_namespace.AddTypeContainer (ns);
520 current_container = current_namespace = ns;
525 Lexer.doc_state = XmlCommentState.Allowed;
527 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
530 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
532 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
534 current_container = current_namespace = current_namespace.Parent;
536 | opt_attributes NAMESPACE namespace_name
538 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
540 var name = (MemberName) $3;
541 var ns = new NamespaceContainer (name, current_namespace);
542 lbag.AddLocation (ns, GetLocation ($2));
543 current_namespace.AddTypeContainer (ns);
552 Error_SyntaxError (yyToken);
560 var lt = (LocatedToken) $1;
561 $$ = new MemberName (lt.Value, lt.Location);
563 | namespace_name DOT IDENTIFIER
565 var lt = (LocatedToken) $3;
566 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
567 lbag.AddLocation ($$, GetLocation ($2));
571 Error_SyntaxError (yyToken);
572 $$ = new MemberName ("<invalid>", lexer.Location);
591 opt_extern_alias_directives
593 | extern_alias_directives
596 opt_namespace_or_type_declarations
598 | namespace_or_type_declarations
601 namespace_or_type_declarations
602 : namespace_or_type_declaration
603 | namespace_or_type_declarations namespace_or_type_declaration
606 namespace_or_type_declaration
610 TypeContainer ds = (TypeContainer)$1;
612 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
613 report.Error (1527, ds.Location,
614 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
617 // Here is a trick, for explicit attributes we don't know where they belong to until
618 // we parse succeeding declaration hence we parse them as normal and re-attach them
619 // when we know whether they are global (assembly:, module:) or local (type:).
620 if (ds.OptAttributes != null) {
621 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
624 current_namespace.DeclarationFound = true;
626 | namespace_declaration
628 current_namespace.DeclarationFound = true;
630 | attribute_sections CLOSE_BRACE {
631 current_namespace.UnattachedAttributes = (Attributes) $1;
632 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
640 | interface_declaration
642 | delegate_declaration
644 // Enable this when we have handled all errors, because this acts as a generic fallback
647 // Console.WriteLine ("Token=" + yyToken);
648 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
664 var sect = (List<Attribute>) $1;
665 $$ = new Attributes (sect);
667 | attribute_sections attribute_section
669 Attributes attrs = $1 as Attributes;
670 var sect = (List<Attribute>) $2;
672 attrs = new Attributes (sect);
673 else if (sect != null)
674 attrs.AddAttributes (sect);
682 PushLocation (GetLocation ($1));
683 lexer.parsing_attribute_section = true;
685 attribute_section_cont
687 lexer.parsing_attribute_section = false;
692 attribute_section_cont
693 : attribute_target COLON
695 current_attr_target = (string) $1;
696 if (current_attr_target == "assembly" || current_attr_target == "module") {
697 Lexer.check_incorrect_doc_comment ();
700 attribute_list opt_comma CLOSE_BRACKET
702 // when attribute target is invalid
703 if (current_attr_target == string.Empty)
704 $$ = new List<Attribute> (0);
708 lbag.InsertLocation ($$, 0, PopLocation ());
710 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
712 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
715 current_attr_target = null;
716 lexer.parsing_attribute_section = false;
718 | attribute_list opt_comma CLOSE_BRACKET
722 lbag.InsertLocation ($$, 0, PopLocation ());
724 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
726 lbag.AddLocation ($$, GetLocation($3));
731 Error_SyntaxError (yyToken);
733 var lt = (LocatedToken) $1;
734 var tne = new SimpleName (lt.Value, null, lt.Location);
736 $$ = new List<Attribute> () {
737 new Attribute (null, tne, null, GetLocation ($1), false)
742 CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1));
750 var lt = (LocatedToken) $1;
751 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
753 | EVENT { $$ = "event"; }
754 | RETURN { $$ = "return"; }
760 $$ = new List<Attribute> (4) { (Attribute) $1 };
762 | attribute_list COMMA attribute
764 var attrs = (List<Attribute>) $1;
766 attrs.Add ((Attribute) $3);
767 lbag.AppendTo (attrs, GetLocation ($2));
777 ++lexer.parsing_block;
779 opt_attribute_arguments
781 --lexer.parsing_block;
783 var tne = (ATypeNameExpression) $1;
784 if (tne.HasTypeArguments) {
785 report.Error (404, tne.Location, "Attributes cannot be generic");
788 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
793 : namespace_or_type_expr
796 opt_attribute_arguments
797 : /* empty */ { $$ = null; }
798 | OPEN_PARENS attribute_arguments CLOSE_PARENS
806 : /* empty */ { $$ = null; }
807 | positional_or_named_argument
809 Arguments a = new Arguments (4);
810 a.Add ((Argument) $1);
811 $$ = new Arguments [] { a, null };
813 | named_attribute_argument
815 Arguments a = new Arguments (4);
816 a.Add ((Argument) $1);
817 $$ = new Arguments [] { null, a };
819 | attribute_arguments COMMA positional_or_named_argument
821 Arguments[] o = (Arguments[]) $1;
823 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
824 o [0] = new Arguments (4);
827 Arguments args = ((Arguments) o [0]);
828 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
829 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
831 args.Add ((Argument) $3);
833 | attribute_arguments COMMA named_attribute_argument
835 Arguments[] o = (Arguments[]) $1;
837 o [1] = new Arguments (4);
840 ((Arguments) o [1]).Add ((Argument) $3);
844 positional_or_named_argument
847 $$ = new Argument ((Expression) $1);
852 Error_SyntaxError (yyToken);
857 named_attribute_argument
860 ++lexer.parsing_block;
864 --lexer.parsing_block;
865 var lt = (LocatedToken) $1;
866 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
867 lbag.AddLocation ($$, GetLocation($2));
872 : identifier_inside_body COLON opt_named_modifier expression_or_error
874 if (lang_version <= LanguageVersion.V_3)
875 FeatureIsNotAvailable (GetLocation ($1), "named argument");
877 // Avoid boxing in common case (no modifier)
878 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
880 var lt = (LocatedToken) $1;
881 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
882 lbag.AddLocation ($$, GetLocation($2));
887 : /* empty */ { $$ = null; }
890 $$ = Argument.AType.Ref;
894 $$ = Argument.AType.Out;
898 opt_class_member_declarations
900 | class_member_declarations
903 class_member_declarations
904 : class_member_declaration
906 lexer.parsing_modifiers = true;
908 | class_member_declarations class_member_declaration
910 lexer.parsing_modifiers = true;
914 class_member_declaration
915 : constant_declaration
918 | property_declaration
920 | indexer_declaration
921 | operator_declaration
922 | constructor_declaration
923 | destructor_declaration
925 | attributes_without_members
929 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
930 GetSymbolName (yyToken));
932 lexer.parsing_generic_declaration = false;
943 type_declaration_name
945 lexer.ConstraintsParsing = true;
946 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
949 opt_type_parameter_constraints_clauses
951 lexer.ConstraintsParsing = false;
954 current_container.SetConstraints ((List<Constraints>) $9);
957 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
959 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
961 lexer.parsing_modifiers = true;
966 Lexer.doc_state = XmlCommentState.Allowed;
968 opt_class_member_declarations CLOSE_BRACE
970 --lexer.parsing_declaration;
972 Lexer.doc_state = XmlCommentState.Allowed;
977 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
979 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
981 $$ = pop_current_class ();
983 | opt_attributes opt_modifiers opt_partial STRUCT error
985 Error_SyntaxError (yyToken);
992 CONST type IDENTIFIER
994 var lt = (LocatedToken) $5;
995 var mod = (Modifiers) $2;
996 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
997 current_type.AddMember (current_field);
999 if ((mod & Modifiers.STATIC) != 0) {
1000 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1005 constant_initializer opt_constant_declarators SEMICOLON
1008 current_field.DocComment = Lexer.consume_doc_comment ();
1009 Lexer.doc_state = XmlCommentState.Allowed;
1012 current_field.Initializer = (ConstInitializer) $7;
1013 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1014 current_field = null;
1020 Error_SyntaxError (yyToken);
1022 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1026 opt_constant_declarators
1028 | constant_declarators
1031 constant_declarators
1032 : constant_declarator
1034 current_field.AddDeclarator ((FieldDeclarator) $1);
1036 | constant_declarators constant_declarator
1038 current_field.AddDeclarator ((FieldDeclarator) $2);
1043 : COMMA IDENTIFIER constant_initializer
1045 var lt = (LocatedToken) $2;
1046 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1047 lbag.AddLocation ($$, GetLocation ($1));
1051 constant_initializer
1054 ++lexer.parsing_block;
1056 constant_initializer_expr
1058 --lexer.parsing_block;
1059 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1063 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1068 constant_initializer_expr
1069 : constant_expression
1076 member_type IDENTIFIER
1078 lexer.parsing_generic_declaration = false;
1080 FullNamedExpression type = (FullNamedExpression) $3;
1081 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1082 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1084 var lt = (LocatedToken) $4;
1085 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1086 current_type.AddField (current_field);
1089 opt_field_initializer
1090 opt_field_declarators
1094 current_field.DocComment = Lexer.consume_doc_comment ();
1095 Lexer.doc_state = XmlCommentState.Allowed;
1098 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1100 current_field = null;
1104 FIXED simple_type IDENTIFIER
1106 if (lang_version < LanguageVersion.ISO_2)
1107 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1109 var lt = (LocatedToken) $5;
1110 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1111 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1113 current_type.AddField (current_field);
1115 fixed_field_size opt_fixed_field_declarators SEMICOLON
1118 current_field.DocComment = Lexer.consume_doc_comment ();
1119 Lexer.doc_state = XmlCommentState.Allowed;
1122 current_field.Initializer = (ConstInitializer) $7;
1123 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1125 current_field = null;
1129 FIXED simple_type error
1132 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1136 opt_field_initializer
1140 ++lexer.parsing_block;
1141 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1142 start_block (GetLocation ($1));
1144 variable_initializer
1146 --lexer.parsing_block;
1147 current_field.Initializer = (Expression) $3;
1148 lbag.AppendToMember (current_field, GetLocation ($1));
1149 end_block (lexer.Location);
1150 current_local_parameters = null;
1154 opt_field_declarators
1162 current_field.AddDeclarator ((FieldDeclarator) $1);
1164 | field_declarators field_declarator
1166 current_field.AddDeclarator ((FieldDeclarator) $2);
1173 var lt = (LocatedToken) $2;
1174 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1175 lbag.AddLocation ($$, GetLocation ($1));
1177 | COMMA IDENTIFIER ASSIGN
1179 ++lexer.parsing_block;
1181 variable_initializer
1183 --lexer.parsing_block;
1184 var lt = (LocatedToken) $2;
1185 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1186 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1190 opt_fixed_field_declarators
1192 | fixed_field_declarators
1195 fixed_field_declarators
1196 : fixed_field_declarator
1198 current_field.AddDeclarator ((FieldDeclarator) $1);
1200 | fixed_field_declarators fixed_field_declarator
1202 current_field.AddDeclarator ((FieldDeclarator) $2);
1206 fixed_field_declarator
1207 : COMMA IDENTIFIER fixed_field_size
1209 var lt = (LocatedToken) $2;
1210 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1211 lbag.AddLocation ($$, GetLocation ($1));
1218 ++lexer.parsing_block;
1220 expression CLOSE_BRACKET
1222 --lexer.parsing_block;
1223 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1224 lbag.AddLocation ($$, GetLocation ($4));
1226 | OPEN_BRACKET error
1228 report.Error (443, lexer.Location, "Value or constant expected");
1233 variable_initializer
1238 // It has to be here for the parent to safely restore artificial block
1239 Error_SyntaxError (yyToken);
1248 Lexer.doc_state = XmlCommentState.NotAllowed;
1250 // Was added earlier in the case of body being eof for full ast
1254 Method method = (Method) $1;
1255 method.Block = (ToplevelBlock) $3;
1256 async_block = false;
1258 if (method.Block == null) {
1259 method.ParameterInfo.CheckParameters (method);
1261 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1262 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1263 method.GetSignatureForError ());
1266 if (current_container.Kind == MemberKind.Interface) {
1267 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1268 method.GetSignatureForError ());
1272 current_local_parameters = null;
1275 Lexer.doc_state = XmlCommentState.Allowed;
1283 method_declaration_name OPEN_PARENS
1285 valid_param_mod = ParameterModifierType.All;
1287 opt_formal_parameter_list CLOSE_PARENS
1289 valid_param_mod = 0;
1290 MemberName name = (MemberName) $4;
1291 current_local_parameters = (ParametersCompiled) $7;
1293 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1294 name, current_local_parameters, (Attributes) $1);
1296 current_type.AddMember (method);
1298 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1301 method.DocComment = Lexer.consume_doc_comment ();
1303 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1307 lexer.ConstraintsParsing = true;
1309 opt_type_parameter_constraints_clauses
1311 lexer.ConstraintsParsing = false;
1314 var method = (Method) $9;
1315 method.SetConstraints ((List<Constraints>) $10);
1325 lexer.parsing_generic_declaration = true;
1327 method_declaration_name
1330 lexer.parsing_generic_declaration = false;
1331 valid_param_mod = ParameterModifierType.All;
1333 opt_formal_parameter_list CLOSE_PARENS
1335 lexer.ConstraintsParsing = true;
1337 opt_type_parameter_constraints_clauses
1339 lexer.ConstraintsParsing = false;
1340 valid_param_mod = 0;
1342 MemberName name = (MemberName) $6;
1343 current_local_parameters = (ParametersCompiled) $9;
1345 var modifiers = (Modifiers) $2;
1346 modifiers |= Modifiers.PARTIAL;
1348 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1349 modifiers, name, current_local_parameters, (Attributes) $1);
1351 current_type.AddMember (method);
1353 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1356 method.SetConstraints ((List<Constraints>) $12);
1359 method.DocComment = Lexer.consume_doc_comment ();
1361 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1362 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1368 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1370 MemberName name = (MemberName) $5;
1371 report.Error (1585, name.Location,
1372 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1374 var method = Method.Create (current_type, (FullNamedExpression) $3,
1375 0, name, (ParametersCompiled) $7, (Attributes) $1);
1377 current_type.AddMember (method);
1379 current_local_parameters = (ParametersCompiled) $7;
1382 method.DocComment = Lexer.consume_doc_comment ();
1389 method_declaration_name error
1391 Error_SyntaxError (yyToken);
1392 current_local_parameters = ParametersCompiled.Undefined;
1394 MemberName name = (MemberName) $4;
1395 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1396 name, current_local_parameters, (Attributes) $1);
1398 current_type.AddMember (method);
1401 method.DocComment = Lexer.consume_doc_comment ();
1409 | SEMICOLON { $$ = null; }
1412 opt_formal_parameter_list
1413 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1414 | formal_parameter_list
1417 formal_parameter_list
1420 var pars_list = (List<Parameter>) $1;
1421 $$ = new ParametersCompiled (pars_list.ToArray ());
1423 | fixed_parameters COMMA parameter_array
1425 var pars_list = (List<Parameter>) $1;
1426 pars_list.Add ((Parameter) $3);
1428 $$ = new ParametersCompiled (pars_list.ToArray ());
1430 | fixed_parameters COMMA arglist_modifier
1432 var pars_list = (List<Parameter>) $1;
1433 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1434 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1436 | parameter_array COMMA error
1439 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1441 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1443 | fixed_parameters COMMA parameter_array COMMA error
1446 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1448 var pars_list = (List<Parameter>) $1;
1449 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1451 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1453 | arglist_modifier COMMA error
1455 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1457 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1459 | fixed_parameters COMMA ARGLIST COMMA error
1461 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1463 var pars_list = (List<Parameter>) $1;
1464 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1466 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1470 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1474 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1478 Error_SyntaxError (yyToken);
1479 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1486 parameters_bucket.Clear ();
1487 Parameter p = (Parameter) $1;
1488 parameters_bucket.Add (p);
1490 default_parameter_used = p.HasDefaultValue;
1491 $$ = parameters_bucket;
1493 | fixed_parameters COMMA fixed_parameter
1495 var pars = (List<Parameter>) $1;
1496 Parameter p = (Parameter) $3;
1498 if (p.HasExtensionMethodModifier)
1499 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1500 else if (!p.HasDefaultValue && default_parameter_used)
1501 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1503 default_parameter_used |= p.HasDefaultValue;
1506 lbag.AddLocation (p, GetLocation ($2));
1515 opt_parameter_modifier
1517 identifier_inside_body
1519 var lt = (LocatedToken) $4;
1520 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1523 opt_parameter_modifier
1525 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1527 var lt = (LocatedToken) $4;
1528 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1529 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1531 | attribute_sections error
1533 Error_SyntaxError (yyToken);
1534 Location l = GetLocation ($2);
1535 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1538 opt_parameter_modifier
1542 Error_SyntaxError (yyToken);
1543 Location l = GetLocation ($4);
1544 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1547 opt_parameter_modifier
1549 identifier_inside_body
1552 ++lexer.parsing_block;
1556 --lexer.parsing_block;
1557 if (lang_version <= LanguageVersion.V_3) {
1558 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1561 Parameter.Modifier mod = (Parameter.Modifier) $2;
1562 if (mod != Parameter.Modifier.NONE) {
1564 case Parameter.Modifier.REF:
1565 case Parameter.Modifier.OUT:
1566 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1567 Parameter.GetModifierSignature (mod));
1570 case Parameter.Modifier.This:
1571 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1572 Parameter.GetModifierSignature (mod));
1575 throw new NotImplementedException (mod.ToString ());
1578 mod = Parameter.Modifier.NONE;
1581 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1582 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1584 var lt = (LocatedToken) $4;
1585 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1586 lbag.AddLocation ($$, GetLocation ($5));
1589 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1593 opt_parameter_modifier
1594 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1595 | parameter_modifiers
1599 : parameter_modifier
1603 | parameter_modifiers parameter_modifier
1605 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1606 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1607 if (((Parameter.Modifier)$1 & p2) == p2) {
1608 Error_DuplicateParameterModifier (lexer.Location, p2);
1610 switch (mod & ~Parameter.Modifier.This) {
1611 case Parameter.Modifier.REF:
1612 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1614 case Parameter.Modifier.OUT:
1615 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1618 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1629 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1630 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1632 $$ = Parameter.Modifier.REF;
1636 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1637 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1639 $$ = Parameter.Modifier.OUT;
1643 if ((valid_param_mod & ParameterModifierType.This) == 0)
1644 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1646 if (lang_version <= LanguageVersion.ISO_2)
1647 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1649 $$ = Parameter.Modifier.This;
1654 : opt_attributes params_modifier type IDENTIFIER
1656 var lt = (LocatedToken) $4;
1657 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1659 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1661 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1663 var lt = (LocatedToken) $4;
1664 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1666 | opt_attributes params_modifier type error
1668 Error_SyntaxError (yyToken);
1670 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1677 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1678 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1680 | PARAMS parameter_modifier
1682 Parameter.Modifier mod = (Parameter.Modifier)$2;
1683 if ((mod & Parameter.Modifier.This) != 0) {
1684 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1686 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1689 | PARAMS params_modifier
1691 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1698 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1699 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1703 property_declaration
1707 member_declaration_name
1710 tmpComment = Lexer.consume_doc_comment ();
1714 var type = (FullNamedExpression) $3;
1715 current_property = new Property (current_type, type, (Modifiers) $2,
1716 (MemberName) $4, (Attributes) $1);
1718 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1719 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1721 current_type.AddMember (current_property);
1722 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1724 lexer.PropertyParsing = true;
1726 accessor_declarations
1728 lexer.PropertyParsing = false;
1731 current_property.DocComment = ConsumeStoredComment ();
1735 lbag.AppendToMember (current_property, GetLocation ($10));
1736 current_property = null;
1742 : opt_attributes opt_modifiers
1743 member_type indexer_declaration_name OPEN_BRACKET
1745 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1747 opt_formal_parameter_list CLOSE_BRACKET
1749 valid_param_mod = 0;
1750 var type = (FullNamedExpression) $3;
1751 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1753 current_property = indexer;
1755 current_type.AddIndexer (indexer);
1756 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1758 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1759 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1761 if (indexer.ParameterInfo.IsEmpty) {
1762 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1766 tmpComment = Lexer.consume_doc_comment ();
1767 Lexer.doc_state = XmlCommentState.Allowed;
1770 lexer.PropertyParsing = true;
1772 OPEN_BRACE accessor_declarations
1774 lexer.PropertyParsing = false;
1778 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1779 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1782 current_property.DocComment = ConsumeStoredComment ();
1784 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1785 current_property = null;
1790 accessor_declarations
1791 : get_accessor_declaration
1792 | get_accessor_declaration accessor_declarations
1793 | set_accessor_declaration
1794 | set_accessor_declaration accessor_declarations
1797 if (yyToken == Token.CLOSE_BRACE) {
1798 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1800 if (yyToken == Token.SEMICOLON)
1801 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1803 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1808 get_accessor_declaration
1809 : opt_attributes opt_modifiers GET
1811 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1812 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1815 if (current_property.Get != null) {
1816 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1819 if (current_property is Indexer) {
1820 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1821 (Attributes) $1, GetLocation ($3));
1823 current_property.Get = new Property.GetMethod (current_property,
1824 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1827 current_local_parameters = current_property.Get.ParameterInfo;
1828 lbag.AddMember (current_property.Get, mod_locations);
1829 lexer.PropertyParsing = false;
1834 current_property.Get.Block = (ToplevelBlock) $5;
1836 if (current_container.Kind == MemberKind.Interface) {
1837 report.Error (531, current_property.Get.Block.StartLocation,
1838 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1842 current_local_parameters = null;
1843 lexer.PropertyParsing = true;
1846 if (Lexer.doc_state == XmlCommentState.Error)
1847 Lexer.doc_state = XmlCommentState.NotAllowed;
1851 set_accessor_declaration
1852 : opt_attributes opt_modifiers SET
1854 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1855 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1858 if (current_property.Set != null) {
1859 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1862 if (current_property is Indexer) {
1863 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1864 ParametersCompiled.MergeGenerated (compiler,
1865 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1866 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1868 (Attributes) $1, GetLocation ($3));
1870 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1871 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1872 (Attributes) $1, GetLocation ($3));
1875 current_local_parameters = current_property.Set.ParameterInfo;
1876 lbag.AddMember (current_property.Set, mod_locations);
1877 lexer.PropertyParsing = false;
1882 current_property.Set.Block = (ToplevelBlock) $5;
1884 if (current_container.Kind == MemberKind.Interface) {
1885 report.Error (531, current_property.Set.Block.StartLocation,
1886 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1890 current_local_parameters = null;
1891 lexer.PropertyParsing = true;
1894 && Lexer.doc_state == XmlCommentState.Error)
1895 Lexer.doc_state = XmlCommentState.NotAllowed;
1908 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1913 interface_declaration
1920 type_declaration_name
1922 lexer.ConstraintsParsing = true;
1923 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1924 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1927 opt_type_parameter_constraints_clauses
1929 lexer.ConstraintsParsing = false;
1932 current_container.SetConstraints ((List<Constraints>) $9);
1935 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1936 Lexer.doc_state = XmlCommentState.Allowed;
1939 lexer.parsing_modifiers = true;
1941 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1943 --lexer.parsing_declaration;
1945 Lexer.doc_state = XmlCommentState.Allowed;
1950 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1952 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
1954 $$ = pop_current_class ();
1956 | opt_attributes opt_modifiers opt_partial INTERFACE error
1958 Error_SyntaxError (yyToken);
1962 opt_interface_member_declarations
1964 | interface_member_declarations
1967 interface_member_declarations
1968 : interface_member_declaration
1970 lexer.parsing_modifiers = true;
1972 | interface_member_declarations interface_member_declaration
1974 lexer.parsing_modifiers = true;
1978 interface_member_declaration
1979 : constant_declaration
1981 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1985 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1987 | method_declaration
1988 | property_declaration
1990 | indexer_declaration
1991 | operator_declaration
1993 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1995 | constructor_declaration
1997 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2001 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2005 operator_declaration
2006 : opt_attributes opt_modifiers operator_declarator
2011 OperatorDeclaration decl = (OperatorDeclaration) $3;
2013 Operator op = new Operator (
2014 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2015 current_local_parameters,
2016 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2018 if (op.Block == null)
2019 op.ParameterInfo.CheckParameters (op);
2022 op.DocComment = tmpComment;
2023 Lexer.doc_state = XmlCommentState.Allowed;
2026 // Note again, checking is done in semantic analysis
2027 current_type.AddOperator (op);
2029 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2032 current_local_parameters = null;
2038 | SEMICOLON { $$ = null; }
2042 : type_expression_or_array
2045 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2046 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2051 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2053 valid_param_mod = ParameterModifierType.DefaultValue;
2055 opt_formal_parameter_list CLOSE_PARENS
2057 valid_param_mod = 0;
2059 Location loc = GetLocation ($2);
2060 Operator.OpType op = (Operator.OpType) $3;
2061 current_local_parameters = (ParametersCompiled)$6;
2063 int p_count = current_local_parameters.Count;
2065 if (op == Operator.OpType.Addition)
2066 op = Operator.OpType.UnaryPlus;
2067 else if (op == Operator.OpType.Subtraction)
2068 op = Operator.OpType.UnaryNegation;
2071 if (IsUnaryOperator (op)) {
2073 report.Error (1020, loc, "Overloadable binary operator expected");
2074 } else if (p_count != 1) {
2075 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2076 Operator.GetName (op));
2080 report.Error (1019, loc, "Overloadable unary operator expected");
2081 } else if (p_count != 2) {
2082 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2083 Operator.GetName (op));
2088 tmpComment = Lexer.consume_doc_comment ();
2089 Lexer.doc_state = XmlCommentState.NotAllowed;
2092 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2093 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2095 | conversion_operator_declarator
2098 overloadable_operator
2100 : BANG { $$ = Operator.OpType.LogicalNot; }
2101 | TILDE { $$ = Operator.OpType.OnesComplement; }
2102 | OP_INC { $$ = Operator.OpType.Increment; }
2103 | OP_DEC { $$ = Operator.OpType.Decrement; }
2104 | TRUE { $$ = Operator.OpType.True; }
2105 | FALSE { $$ = Operator.OpType.False; }
2106 // Unary and binary:
2107 | PLUS { $$ = Operator.OpType.Addition; }
2108 | MINUS { $$ = Operator.OpType.Subtraction; }
2110 | STAR { $$ = Operator.OpType.Multiply; }
2111 | DIV { $$ = Operator.OpType.Division; }
2112 | PERCENT { $$ = Operator.OpType.Modulus; }
2113 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2114 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2115 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2116 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2117 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2118 | OP_EQ { $$ = Operator.OpType.Equality; }
2119 | OP_NE { $$ = Operator.OpType.Inequality; }
2120 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2121 | OP_LT { $$ = Operator.OpType.LessThan; }
2122 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2123 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2126 conversion_operator_declarator
2127 : IMPLICIT OPERATOR type OPEN_PARENS
2129 valid_param_mod = ParameterModifierType.DefaultValue;
2131 opt_formal_parameter_list CLOSE_PARENS
2133 valid_param_mod = 0;
2135 Location loc = GetLocation ($2);
2136 current_local_parameters = (ParametersCompiled)$6;
2138 if (current_local_parameters.Count != 1) {
2139 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2143 tmpComment = Lexer.consume_doc_comment ();
2144 Lexer.doc_state = XmlCommentState.NotAllowed;
2147 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2148 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2150 | EXPLICIT OPERATOR type OPEN_PARENS
2152 valid_param_mod = ParameterModifierType.DefaultValue;
2154 opt_formal_parameter_list CLOSE_PARENS
2156 valid_param_mod = 0;
2158 Location loc = GetLocation ($2);
2159 current_local_parameters = (ParametersCompiled)$6;
2161 if (current_local_parameters.Count != 1) {
2162 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2166 tmpComment = Lexer.consume_doc_comment ();
2167 Lexer.doc_state = XmlCommentState.NotAllowed;
2170 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2171 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2175 Error_SyntaxError (yyToken);
2176 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2177 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2181 Error_SyntaxError (yyToken);
2182 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2183 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2187 constructor_declaration
2188 : constructor_declarator
2191 Constructor c = (Constructor) $1;
2192 c.Block = (ToplevelBlock) $2;
2195 c.DocComment = ConsumeStoredComment ();
2197 current_local_parameters = null;
2199 Lexer.doc_state = XmlCommentState.Allowed;
2203 constructor_declarator
2209 tmpComment = Lexer.consume_doc_comment ();
2210 Lexer.doc_state = XmlCommentState.Allowed;
2213 valid_param_mod = ParameterModifierType.All;
2215 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2217 valid_param_mod = 0;
2218 current_local_parameters = (ParametersCompiled) $6;
2220 var lt = (LocatedToken) $3;
2221 var mods = (Modifiers) $2;
2222 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2224 if (lt.Value != current_container.MemberName.Name) {
2225 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2226 } else if ((mods & Modifiers.STATIC) != 0) {
2227 if ((mods & Modifiers.AccessibilityMask) != 0){
2228 report.Error (515, c.Location,
2229 "`{0}': static constructor cannot have an access modifier",
2230 c.GetSignatureForError ());
2234 current_type.AddConstructor (c);
2235 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2239 // start block here, so possible anonymous methods inside
2240 // constructor initializer can get correct parent block
2242 start_block (lexer.Location);
2244 opt_constructor_initializer
2247 var c = (Constructor) $8;
2248 c.Initializer = (ConstructorInitializer) $9;
2251 report.Error (514, c.Location,
2252 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2253 c.GetSignatureForError ());
2263 | SEMICOLON { current_block = null; $$ = null; }
2266 opt_constructor_initializer
2268 | constructor_initializer
2271 constructor_initializer
2272 : COLON BASE OPEN_PARENS
2274 ++lexer.parsing_block;
2276 opt_argument_list CLOSE_PARENS
2278 --lexer.parsing_block;
2279 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2280 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2282 | COLON THIS OPEN_PARENS
2284 ++lexer.parsing_block;
2286 opt_argument_list CLOSE_PARENS
2288 --lexer.parsing_block;
2289 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2290 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2294 Error_SyntaxError (yyToken);
2295 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2296 lbag.AddLocation ($$, GetLocation ($1));
2300 Error_SyntaxError (yyToken);
2305 destructor_declaration
2306 : opt_attributes opt_modifiers TILDE
2309 tmpComment = Lexer.consume_doc_comment ();
2310 Lexer.doc_state = XmlCommentState.NotAllowed;
2313 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2315 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2317 var lt = (LocatedToken) $5;
2318 if (lt.Value != current_container.MemberName.Name){
2319 report.Error (574, lt.Location, "Name of destructor must match name of class");
2320 } else if (current_container.Kind != MemberKind.Class){
2321 report.Error (575, lt.Location, "Only class types can contain destructor");
2324 Destructor d = new Destructor (current_type, (Modifiers) $2,
2325 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2327 d.DocComment = ConsumeStoredComment ();
2329 d.Block = (ToplevelBlock) $8;
2330 current_type.AddMember (d);
2331 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2333 current_local_parameters = null;
2340 EVENT type member_declaration_name
2342 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2343 current_type.AddMember (current_event_field);
2345 if (current_event_field.MemberName.ExplicitInterface != null) {
2346 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2347 current_event_field.GetSignatureForError ());
2350 $$ = current_event_field;
2352 opt_event_initializer
2353 opt_event_declarators
2357 current_event_field.DocComment = Lexer.consume_doc_comment ();
2358 Lexer.doc_state = XmlCommentState.Allowed;
2361 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2362 current_event_field = null;
2366 EVENT type member_declaration_name
2369 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2370 current_type.AddMember (current_event);
2371 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2373 lexer.EventParsing = true;
2375 event_accessor_declarations
2377 if (current_container.Kind == MemberKind.Interface)
2378 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2380 lexer.EventParsing = false;
2385 current_event.DocComment = Lexer.consume_doc_comment ();
2386 Lexer.doc_state = XmlCommentState.Allowed;
2389 lbag.AppendToMember (current_event, GetLocation ($9));
2390 current_event = null;
2391 current_local_parameters = null;
2397 Error_SyntaxError (yyToken);
2399 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2403 opt_event_initializer
2407 ++lexer.parsing_block;
2409 event_variable_initializer
2411 --lexer.parsing_block;
2412 current_event_field.Initializer = (Expression) $3;
2416 opt_event_declarators
2424 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2426 | event_declarators event_declarator
2428 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2435 var lt = (LocatedToken) $2;
2436 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2437 lbag.AddLocation ($$, GetLocation ($1));
2439 | COMMA IDENTIFIER ASSIGN
2441 ++lexer.parsing_block;
2443 event_variable_initializer
2445 --lexer.parsing_block;
2446 var lt = (LocatedToken) $2;
2447 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2448 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2452 event_variable_initializer
2454 if (current_container.Kind == MemberKind.Interface) {
2455 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2456 current_event_field.GetSignatureForError ());
2459 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2460 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2461 current_event_field.GetSignatureForError ());
2464 variable_initializer
2470 event_accessor_declarations
2471 : add_accessor_declaration remove_accessor_declaration
2472 | remove_accessor_declaration add_accessor_declaration
2473 | add_accessor_declaration
2475 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2476 current_event.GetSignatureForError ());
2478 | remove_accessor_declaration
2480 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2481 current_event.GetSignatureForError ());
2485 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2490 add_accessor_declaration
2491 : opt_attributes opt_modifiers ADD
2493 if ($2 != ModifierNone) {
2494 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2497 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2498 current_local_parameters = current_event.Add.ParameterInfo;
2500 lbag.AddMember (current_event.Add, mod_locations);
2501 lexer.EventParsing = false;
2503 event_accessor_block
2505 lexer.EventParsing = true;
2507 current_event.Add.Block = (ToplevelBlock) $5;
2509 if (current_container.Kind == MemberKind.Interface) {
2510 report.Error (531, current_event.Add.Block.StartLocation,
2511 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2514 current_local_parameters = null;
2518 remove_accessor_declaration
2519 : opt_attributes opt_modifiers REMOVE
2521 if ($2 != ModifierNone) {
2522 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2525 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2526 current_local_parameters = current_event.Remove.ParameterInfo;
2528 lbag.AddMember (current_event.Remove, mod_locations);
2529 lexer.EventParsing = false;
2531 event_accessor_block
2533 lexer.EventParsing = true;
2535 current_event.Remove.Block = (ToplevelBlock) $5;
2537 if (current_container.Kind == MemberKind.Interface) {
2538 report.Error (531, current_event.Remove.Block.StartLocation,
2539 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2542 current_local_parameters = null;
2546 event_accessor_block
2549 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2555 attributes_without_members
2556 : attribute_sections CLOSE_BRACE
2558 current_type.UnattachedAttributes = (Attributes) $1;
2559 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2560 lexer.putback ('}');
2564 // For full ast try to recover incomplete ambiguous member
2565 // declaration in form on class X { public int }
2567 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2569 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2571 lexer.putback ('}');
2573 lexer.parsing_generic_declaration = false;
2574 FullNamedExpression type = (FullNamedExpression) $3;
2575 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2576 current_type.AddField (current_field);
2584 ENUM type_declaration_name
2588 enumTypeComment = Lexer.consume_doc_comment ();
2593 Lexer.doc_state = XmlCommentState.Allowed;
2595 MemberName name = (MemberName) $4;
2596 if (name.IsGeneric) {
2597 report.Error (1675, name.Location, "Enums cannot have type parameters");
2600 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2602 opt_enum_member_declarations
2604 lexer.parsing_modifiers = true;
2606 // here will be evaluated after CLOSE_BLACE is consumed.
2608 Lexer.doc_state = XmlCommentState.Allowed;
2610 CLOSE_BRACE opt_semicolon
2613 current_container.DocComment = enumTypeComment;
2615 --lexer.parsing_declaration;
2618 // em.DocComment = ev.DocComment;
2620 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2621 $$ = pop_current_class ();
2629 var te = $2 as TypeExpression;
2630 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2631 Enum.Error_1008 (GetLocation ($2), report);
2637 Error_TypeExpected (GetLocation ($1));
2642 opt_enum_member_declarations
2644 | enum_member_declarations
2645 | enum_member_declarations COMMA
2647 lbag.AddLocation ($1, GetLocation ($2));
2651 enum_member_declarations
2652 : enum_member_declaration
2653 | enum_member_declarations COMMA enum_member_declaration
2655 lbag.AddLocation ($1, GetLocation ($2));
2660 enum_member_declaration
2661 : opt_attributes IDENTIFIER
2663 var lt = (LocatedToken) $2;
2664 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2665 ((Enum) current_type).AddEnumMember (em);
2668 em.DocComment = Lexer.consume_doc_comment ();
2669 Lexer.doc_state = XmlCommentState.Allowed;
2674 | opt_attributes IDENTIFIER
2676 ++lexer.parsing_block;
2678 tmpComment = Lexer.consume_doc_comment ();
2679 Lexer.doc_state = XmlCommentState.NotAllowed;
2682 ASSIGN constant_expression
2684 --lexer.parsing_block;
2686 var lt = (LocatedToken) $2;
2687 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2688 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2689 ((Enum) current_type).AddEnumMember (em);
2692 em.DocComment = ConsumeStoredComment ();
2696 | opt_attributes IDENTIFIER error
2698 Error_SyntaxError (yyToken);
2700 var lt = (LocatedToken) $2;
2701 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2702 ((Enum) current_type).AddEnumMember (em);
2705 em.DocComment = Lexer.consume_doc_comment ();
2706 Lexer.doc_state = XmlCommentState.Allowed;
2711 | attributes_without_members
2714 delegate_declaration
2718 member_type type_declaration_name
2721 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2723 opt_formal_parameter_list CLOSE_PARENS
2725 valid_param_mod = 0;
2727 ParametersCompiled p = (ParametersCompiled) $8;
2729 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2731 p.CheckParameters (del);
2733 current_container.AddTypeContainer (del);
2735 current_delegate = del;
2736 lexer.ConstraintsParsing = true;
2738 opt_type_parameter_constraints_clauses
2740 lexer.ConstraintsParsing = false;
2745 current_delegate.DocComment = Lexer.consume_doc_comment ();
2746 Lexer.doc_state = XmlCommentState.Allowed;
2750 current_delegate.SetConstraints ((List<Constraints>) $11);
2751 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2753 $$ = current_delegate;
2755 current_delegate = null;
2763 if (lang_version < LanguageVersion.ISO_2)
2764 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2766 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2770 namespace_or_type_expr
2772 | qualified_alias_member IDENTIFIER opt_type_argument_list
2774 var lt1 = (LocatedToken) $1;
2775 var lt2 = (LocatedToken) $2;
2777 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2778 lbag.AddLocation ($$, GetLocation ($2));
2784 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2786 var lt = (LocatedToken) $3;
2787 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2788 lbag.AddLocation ($$, GetLocation ($2));
2793 : IDENTIFIER opt_type_argument_list
2795 var lt = (LocatedToken) $1;
2796 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2801 // Generics arguments (any type, without attributes)
2803 opt_type_argument_list
2805 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2807 if (lang_version < LanguageVersion.ISO_2)
2808 FeatureIsNotAvailable (GetLocation ($1), "generics");
2812 | OP_GENERICS_LT error
2814 Error_TypeExpected (lexer.Location);
2815 $$ = new TypeArguments ();
2822 TypeArguments type_args = new TypeArguments ();
2823 type_args.Add ((FullNamedExpression) $1);
2826 | type_arguments COMMA type
2828 TypeArguments type_args = (TypeArguments) $1;
2829 type_args.Add ((FullNamedExpression) $3);
2835 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2837 type_declaration_name
2840 lexer.parsing_generic_declaration = true;
2842 opt_type_parameter_list
2844 lexer.parsing_generic_declaration = false;
2845 var lt = (LocatedToken) $1;
2846 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2850 member_declaration_name
2851 : method_declaration_name
2853 MemberName mn = (MemberName)$1;
2854 if (mn.TypeParameters != null)
2855 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2856 mn.GetSignatureForError ()));
2860 method_declaration_name
2861 : type_declaration_name
2862 | explicit_interface IDENTIFIER opt_type_parameter_list
2864 lexer.parsing_generic_declaration = false;
2865 var lt = (LocatedToken) $2;
2866 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2870 indexer_declaration_name
2873 lexer.parsing_generic_declaration = false;
2874 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2876 | explicit_interface THIS
2878 lexer.parsing_generic_declaration = false;
2879 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2884 : IDENTIFIER opt_type_argument_list DOT
2886 var lt = (LocatedToken) $1;
2887 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2888 lbag.AddLocation ($$, GetLocation ($3));
2890 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2892 var lt1 = (LocatedToken) $1;
2893 var lt2 = (LocatedToken) $2;
2895 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2896 lbag.AddLocation ($$, GetLocation ($4));
2898 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2900 var lt = (LocatedToken) $2;
2901 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2902 lbag.AddLocation ($$, GetLocation ($4));
2906 opt_type_parameter_list
2908 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2910 if (lang_version < LanguageVersion.ISO_2)
2911 FeatureIsNotAvailable (GetLocation ($1), "generics");
2914 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2921 var tparams = new TypeParameters ();
2922 tparams.Add ((TypeParameter)$1);
2925 | type_parameters COMMA type_parameter
2927 var tparams = (TypeParameters) $1;
2928 tparams.Add ((TypeParameter)$3);
2930 lbag.AddLocation ($3, GetLocation ($3));
2935 : opt_attributes opt_type_parameter_variance IDENTIFIER
2937 var lt = (LocatedToken)$3;
2938 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
2942 if (GetTokenName (yyToken) == "type")
2943 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2945 Error_SyntaxError (yyToken);
2947 $$ = new TypeParameter (MemberName.Null, null, null);
2952 // All types where void is allowed
2955 : type_expression_or_array
2958 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2965 lexer.parsing_generic_declaration = true;
2970 // A type which does not allow `void' to be used
2973 : type_expression_or_array
2976 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2977 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2985 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2986 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2991 : type_expression_or_array
2994 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2995 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2999 type_expression_or_array
3001 | type_expression rank_specifiers
3003 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3008 : namespace_or_type_expr opt_nullable
3011 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3013 var sn = $1 as SimpleName;
3014 if (sn != null && sn.Name == "var")
3015 $$ = new VarExpr (sn.Location);
3020 | namespace_or_type_expr pointer_stars
3022 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3024 | builtin_types opt_nullable
3027 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3029 | builtin_types pointer_stars
3031 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3033 | VOID pointer_stars
3035 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3042 var types = new List<FullNamedExpression> (2);
3043 types.Add ((FullNamedExpression) $1);
3046 | type_list COMMA base_type_name
3048 var types = (List<FullNamedExpression>) $1;
3049 types.Add ((FullNamedExpression) $3);
3057 if ($1 is ComposedCast) {
3058 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3065 * replaces all the productions for isolating the various
3066 * simple types, but we need this to reuse it easily in variable_type
3069 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3070 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3071 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3072 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3073 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3074 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3079 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3080 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3081 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3082 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3083 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3084 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3085 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3086 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3087 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3091 // Expressions, section 7.5
3096 : primary_expression_or_type
3098 | array_creation_expression
3099 | parenthesized_expression
3100 | default_value_expression
3101 | invocation_expression
3105 | post_increment_expression
3106 | post_decrement_expression
3107 | object_or_delegate_creation_expression
3108 | anonymous_type_expression
3111 | checked_expression
3112 | unchecked_expression
3113 | pointer_member_access
3114 | anonymous_method_expression
3115 | undocumented_expressions
3118 primary_expression_or_type
3119 : IDENTIFIER opt_type_argument_list
3121 var lt = (LocatedToken) $1;
3122 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3124 | IDENTIFIER GENERATE_COMPLETION {
3125 var lt = (LocatedToken) $1;
3126 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3134 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3138 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3139 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3144 // Here is the trick, tokenizer may think that parens is a special but
3145 // parser is interested in open parens only, so we merge them.
3146 // Consider: if (a)foo ();
3154 // Use this production to accept closing parenthesis or
3155 // performing completion
3159 | COMPLETE_COMPLETION
3163 parenthesized_expression
3164 : OPEN_PARENS expression CLOSE_PARENS
3166 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3167 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3169 | OPEN_PARENS expression COMPLETE_COMPLETION
3171 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3176 : primary_expression DOT identifier_inside_body opt_type_argument_list
3178 var lt = (LocatedToken) $3;
3179 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3180 lbag.AddLocation ($$, GetLocation ($2));
3182 | builtin_types DOT identifier_inside_body opt_type_argument_list
3184 var lt = (LocatedToken) $3;
3185 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3186 lbag.AddLocation ($$, GetLocation ($2));
3188 | BASE DOT identifier_inside_body opt_type_argument_list
3190 var lt = (LocatedToken) $3;
3191 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3192 lbag.AddLocation ($$, GetLocation ($2));
3194 | qualified_alias_member identifier_inside_body opt_type_argument_list
3196 var lt1 = (LocatedToken) $1;
3197 var lt2 = (LocatedToken) $2;
3199 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3200 lbag.AddLocation ($$, GetLocation ($2));
3202 | primary_expression DOT GENERATE_COMPLETION {
3203 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3205 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3206 var lt = (LocatedToken) $3;
3207 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3209 | builtin_types DOT GENERATE_COMPLETION
3211 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3213 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3214 var lt = (LocatedToken) $3;
3215 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3219 invocation_expression
3220 : primary_expression open_parens_any opt_argument_list close_parens
3222 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3223 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3225 | primary_expression open_parens_any argument_list error
3227 Error_SyntaxError (yyToken);
3229 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3230 lbag.AddLocation ($$, GetLocation ($2));
3232 | primary_expression open_parens_any error
3234 Error_SyntaxError (yyToken);
3236 $$ = new Invocation ((Expression) $1, null);
3237 lbag.AddLocation ($$, GetLocation ($2));
3241 opt_object_or_collection_initializer
3242 : /* empty */ { $$ = null; }
3243 | object_or_collection_initializer
3246 object_or_collection_initializer
3247 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3250 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3252 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3254 lbag.AddLocation ($$, GetLocation ($3));
3256 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3258 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3259 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3263 opt_member_initializer_list
3264 : /* empty */ { $$ = null; }
3265 | member_initializer_list
3271 member_initializer_list
3272 : member_initializer
3274 var a = new List<Expression> ();
3275 a.Add ((Expression) $1);
3278 | member_initializer_list COMMA member_initializer
3280 var a = (List<Expression>)$1;
3281 a.Add ((Expression) $3);
3284 | member_initializer_list error {
3285 Error_SyntaxError (yyToken);
3291 : IDENTIFIER ASSIGN initializer_value
3293 var lt = (LocatedToken) $1;
3294 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3295 lbag.AddLocation ($$, GetLocation ($2));
3297 | AWAIT ASSIGN initializer_value
3299 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3300 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3301 lbag.AddLocation ($$, GetLocation ($2));
3303 | GENERATE_COMPLETION
3305 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3307 | non_assignment_expression opt_COMPLETE_COMPLETION {
3308 CompletionSimpleName csn = $1 as CompletionSimpleName;
3310 $$ = new CollectionElementInitializer ((Expression)$1);
3312 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3314 | OPEN_BRACE expression_list CLOSE_BRACE
3317 $$ = new CollectionElementInitializer (GetLocation ($1));
3319 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3321 lbag.AddLocation ($$, GetLocation ($2));
3323 | OPEN_BRACE CLOSE_BRACE
3325 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3326 $$ = new CollectionElementInitializer (GetLocation ($1));
3327 lbag.AddLocation ($$, GetLocation ($2));
3333 | object_or_collection_initializer
3337 : /* empty */ { $$ = null; }
3342 : argument_or_named_argument
3344 Arguments list = new Arguments (4);
3345 list.Add ((Argument) $1);
3348 | argument_list COMMA argument
3350 Arguments list = (Arguments) $1;
3351 if (list [list.Count - 1] is NamedArgument)
3352 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3354 list.Add ((Argument) $3);
3357 | argument_list COMMA named_argument
3359 Arguments list = (Arguments) $1;
3360 NamedArgument a = (NamedArgument) $3;
3361 for (int i = 0; i < list.Count; ++i) {
3362 NamedArgument na = list [i] as NamedArgument;
3363 if (na != null && na.Name == a.Name)
3364 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3371 | argument_list COMMA error
3373 if (lexer.putback_char == -1)
3374 lexer.putback (')'); // TODO: Wrong but what can I do
3375 Error_SyntaxError (yyToken);
3380 report.Error (839, GetLocation ($1), "An argument is missing");
3388 $$ = new Argument ((Expression) $1);
3390 | non_simple_argument
3393 argument_or_named_argument
3399 : REF variable_reference
3401 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3402 lbag.AddLocation ($$, GetLocation ($1));
3404 | OUT variable_reference
3406 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3407 lbag.AddLocation ($$, GetLocation ($1));
3409 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3411 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3412 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3414 | ARGLIST OPEN_PARENS CLOSE_PARENS
3416 $$ = new Argument (new Arglist (GetLocation ($1)));
3417 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3426 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3428 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3429 lbag.AddLocation ($$, GetLocation ($4));
3431 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3433 Error_SyntaxError (yyToken);
3434 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3436 | primary_expression OPEN_BRACKET_EXPR error
3438 Error_SyntaxError (yyToken);
3439 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3444 : expression_or_error
3446 var list = new List<Expression> (4);
3447 list.Add ((Expression) $1);
3450 | expression_list COMMA expression_or_error
3452 var list = (List<Expression>) $1;
3453 list.Add ((Expression) $3);
3458 expression_list_arguments
3459 : expression_list_argument
3461 Arguments args = new Arguments (4);
3462 args.Add ((Argument) $1);
3465 | expression_list_arguments COMMA expression_list_argument
3467 Arguments args = (Arguments) $1;
3468 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3469 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3471 args.Add ((Argument) $3);
3476 expression_list_argument
3479 $$ = new Argument ((Expression) $1);
3487 $$ = new This (GetLocation ($1));
3492 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3494 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3495 lbag.AddLocation ($$, GetLocation ($4));
3497 | BASE OPEN_BRACKET error
3499 Error_SyntaxError (yyToken);
3500 $$ = new ElementAccess (null, null, GetLocation ($2));
3504 post_increment_expression
3505 : primary_expression OP_INC
3507 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3511 post_decrement_expression
3512 : primary_expression OP_DEC
3514 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3518 object_or_delegate_creation_expression
3519 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3522 if (lang_version <= LanguageVersion.ISO_2)
3523 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3525 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3527 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3530 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3532 | NEW new_expr_type object_or_collection_initializer
3534 if (lang_version <= LanguageVersion.ISO_2)
3535 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3537 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3541 array_creation_expression
3542 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3544 opt_array_initializer
3546 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3547 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3548 Next = (ComposedTypeSpecifier) $6
3549 }, (ArrayInitializer) $7, GetLocation ($1));
3550 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3552 | NEW new_expr_type rank_specifiers opt_array_initializer
3555 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3557 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3559 | NEW rank_specifier array_initializer
3561 if (lang_version <= LanguageVersion.ISO_2)
3562 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3564 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3566 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3568 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3569 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3571 | NEW new_expr_type error
3573 Error_SyntaxError (yyToken);
3574 // It can be any of new expression, create the most common one
3575 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3581 ++lexer.parsing_type;
3585 --lexer.parsing_type;
3590 anonymous_type_expression
3591 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3593 if (lang_version <= LanguageVersion.ISO_2)
3594 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3596 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3598 // TODO: lbag comma location
3599 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3603 anonymous_type_parameters_opt_comma
3604 : anonymous_type_parameters_opt
3605 | anonymous_type_parameters COMMA
3608 anonymous_type_parameters_opt
3610 | anonymous_type_parameters
3613 anonymous_type_parameters
3614 : anonymous_type_parameter
3616 var a = new List<AnonymousTypeParameter> (4);
3617 a.Add ((AnonymousTypeParameter) $1);
3620 | anonymous_type_parameters COMMA anonymous_type_parameter
3622 var a = (List<AnonymousTypeParameter>) $1;
3623 a.Add ((AnonymousTypeParameter) $3);
3628 anonymous_type_parameter
3629 : identifier_inside_body ASSIGN variable_initializer
3631 var lt = (LocatedToken)$1;
3632 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3633 lbag.AddLocation ($$, GetLocation ($2));
3635 | identifier_inside_body
3637 var lt = (LocatedToken)$1;
3638 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3639 lt.Value, lt.Location);
3643 MemberAccess ma = (MemberAccess) $1;
3644 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3648 report.Error (746, lexer.Location,
3649 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3661 | rank_specifier rank_specifiers
3663 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3669 : OPEN_BRACKET CLOSE_BRACKET
3671 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3672 lbag.AddLocation ($$, GetLocation ($2));
3674 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3676 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3677 lbag.AddLocation ($$, GetLocation ($3));
3686 | dim_separators COMMA
3688 $$ = ((int) $1) + 1;
3692 opt_array_initializer
3704 : OPEN_BRACE CLOSE_BRACE
3706 var ai = new ArrayInitializer (0, GetLocation ($1));
3707 ai.VariableDeclaration = current_variable;
3708 lbag.AddLocation (ai, GetLocation ($2));
3711 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3713 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3714 ai.VariableDeclaration = current_variable;
3716 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3718 lbag.AddLocation (ai, GetLocation ($4));
3724 variable_initializer_list
3725 : variable_initializer
3727 var list = new List<Expression> (4);
3728 list.Add ((Expression) $1);
3731 | variable_initializer_list COMMA variable_initializer
3733 var list = (List<Expression>) $1;
3734 list.Add ((Expression) $3);
3742 lexer.TypeOfParsing = true;
3744 open_parens_any typeof_type_expression CLOSE_PARENS
3746 lexer.TypeOfParsing = false;
3747 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3748 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3752 typeof_type_expression
3757 Error_TypeExpected (lexer.Location);
3763 : identifier_inside_body generic_dimension
3765 var lt = (LocatedToken) $1;
3767 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3769 | qualified_alias_member identifier_inside_body generic_dimension
3771 var lt1 = (LocatedToken) $1;
3772 var lt2 = (LocatedToken) $2;
3774 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3775 lbag.AddLocation ($$, GetLocation ($2));
3777 | unbound_type_name DOT identifier_inside_body
3779 var lt = (LocatedToken) $3;
3781 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3783 | unbound_type_name DOT identifier_inside_body generic_dimension
3785 var lt = (LocatedToken) $3;
3787 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3789 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3791 var tne = (ATypeNameExpression) $1;
3792 if (tne.HasTypeArguments)
3793 Error_TypeExpected (GetLocation ($4));
3795 var lt = (LocatedToken) $3;
3796 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3803 if (lang_version < LanguageVersion.ISO_2)
3804 FeatureIsNotAvailable (GetLocation ($1), "generics");
3810 qualified_alias_member
3811 : IDENTIFIER DOUBLE_COLON
3813 var lt = (LocatedToken) $1;
3814 if (lang_version == LanguageVersion.ISO_1)
3815 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3822 : SIZEOF open_parens_any type CLOSE_PARENS
3824 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3825 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3827 | SIZEOF open_parens_any type error
3829 Error_SyntaxError (yyToken);
3831 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3832 lbag.AddLocation ($$, GetLocation ($2));
3837 : CHECKED open_parens_any expression CLOSE_PARENS
3839 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3840 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3844 Error_SyntaxError (yyToken);
3846 $$ = new CheckedExpr (null, GetLocation ($1));
3850 unchecked_expression
3851 : UNCHECKED open_parens_any expression CLOSE_PARENS
3853 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3854 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3858 Error_SyntaxError (yyToken);
3860 $$ = new UnCheckedExpr (null, GetLocation ($1));
3864 pointer_member_access
3865 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3867 var lt = (LocatedToken) $3;
3868 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3872 anonymous_method_expression
3873 : DELEGATE opt_anonymous_method_signature
3875 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3879 $$ = end_anonymous ((ParametersBlock) $4);
3881 | ASYNC DELEGATE opt_anonymous_method_signature
3883 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3887 $$ = end_anonymous ((ParametersBlock) $5);
3891 opt_anonymous_method_signature
3894 $$ = ParametersCompiled.Undefined;
3896 | anonymous_method_signature
3899 anonymous_method_signature
3902 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3904 opt_formal_parameter_list CLOSE_PARENS
3906 valid_param_mod = 0;
3911 default_value_expression
3912 : DEFAULT open_parens_any type CLOSE_PARENS
3914 if (lang_version < LanguageVersion.ISO_2)
3915 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3917 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3918 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3923 : primary_expression
3924 | BANG prefixed_unary_expression
3926 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3928 | TILDE prefixed_unary_expression
3930 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3932 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3934 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3935 lbag.AddLocation ($$, GetLocation ($3));
3937 | AWAIT prefixed_unary_expression
3940 if (current_anonymous_method is LambdaExpression) {
3941 report.Error (4034, GetLocation ($1),
3942 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3943 } else if (current_anonymous_method != null) {
3944 report.Error (4035, GetLocation ($1),
3945 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3946 } else if (interactive_async != null) {
3947 current_block.Explicit.RegisterAsyncAwait ();
3948 interactive_async = true;
3950 report.Error (4033, GetLocation ($1),
3951 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3954 current_block.Explicit.RegisterAsyncAwait ();
3957 $$ = new Await ((Expression) $2, GetLocation ($1));
3961 Error_SyntaxError (yyToken);
3963 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3967 Error_SyntaxError (yyToken);
3969 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3971 | OPEN_PARENS_CAST type CLOSE_PARENS error
3973 Error_SyntaxError (yyToken);
3975 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3976 lbag.AddLocation ($$, GetLocation ($3));
3980 Error_SyntaxError (yyToken);
3982 $$ = new Await (null, GetLocation ($1));
3987 // The idea to split this out is from Rhys' grammar
3988 // to solve the problem with casts.
3990 prefixed_unary_expression
3992 | PLUS prefixed_unary_expression
3994 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3996 | MINUS prefixed_unary_expression
3998 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4000 | OP_INC prefixed_unary_expression
4002 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4004 | OP_DEC prefixed_unary_expression
4006 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4008 | STAR prefixed_unary_expression
4010 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4012 | BITWISE_AND prefixed_unary_expression
4014 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4018 Error_SyntaxError (yyToken);
4020 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4024 Error_SyntaxError (yyToken);
4026 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4030 Error_SyntaxError (yyToken);
4032 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4036 Error_SyntaxError (yyToken);
4038 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4042 Error_SyntaxError (yyToken);
4044 $$ = new Indirection (null, GetLocation ($1));
4048 Error_SyntaxError (yyToken);
4050 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4054 multiplicative_expression
4055 : prefixed_unary_expression
4056 | multiplicative_expression STAR prefixed_unary_expression
4058 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4059 lbag.AddLocation ($$, GetLocation ($2));
4061 | multiplicative_expression DIV prefixed_unary_expression
4063 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4064 lbag.AddLocation ($$, GetLocation ($2));
4066 | multiplicative_expression PERCENT prefixed_unary_expression
4068 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4069 lbag.AddLocation ($$, GetLocation ($2));
4071 | multiplicative_expression STAR error
4073 Error_SyntaxError (yyToken);
4075 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4076 lbag.AddLocation ($$, GetLocation ($2));
4078 | multiplicative_expression DIV error
4080 Error_SyntaxError (yyToken);
4082 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4083 lbag.AddLocation ($$, GetLocation ($2));
4085 | multiplicative_expression PERCENT error
4087 Error_SyntaxError (yyToken);
4089 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4090 lbag.AddLocation ($$, GetLocation ($2));
4095 : multiplicative_expression
4096 | additive_expression PLUS multiplicative_expression
4098 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4099 lbag.AddLocation ($$, GetLocation ($2));
4101 | additive_expression MINUS multiplicative_expression
4103 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4104 lbag.AddLocation ($$, GetLocation ($2));
4106 | additive_expression AS type
4108 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4110 | additive_expression IS type
4112 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4114 | additive_expression PLUS error
4116 Error_SyntaxError (yyToken);
4118 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4119 lbag.AddLocation ($$, GetLocation ($2));
4121 | additive_expression MINUS error
4123 Error_SyntaxError (yyToken);
4125 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4126 lbag.AddLocation ($$, GetLocation ($2));
4128 | additive_expression AS error
4130 Error_SyntaxError (yyToken);
4132 $$ = new As ((Expression) $1, null, GetLocation ($2));
4134 | additive_expression IS error
4136 Error_SyntaxError (yyToken);
4138 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4143 : additive_expression
4144 | shift_expression OP_SHIFT_LEFT additive_expression
4146 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4147 lbag.AddLocation ($$, GetLocation ($2));
4149 | shift_expression OP_SHIFT_RIGHT additive_expression
4151 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4152 lbag.AddLocation ($$, GetLocation ($2));
4154 | shift_expression OP_SHIFT_LEFT error
4156 Error_SyntaxError (yyToken);
4158 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4159 lbag.AddLocation ($$, GetLocation ($2));
4161 | shift_expression OP_SHIFT_RIGHT error
4163 Error_SyntaxError (yyToken);
4165 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4166 lbag.AddLocation ($$, GetLocation ($2));
4170 relational_expression
4172 | relational_expression OP_LT shift_expression
4174 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4175 lbag.AddLocation ($$, GetLocation ($2));
4177 | relational_expression OP_GT shift_expression
4179 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4180 lbag.AddLocation ($$, GetLocation ($2));
4182 | relational_expression OP_LE shift_expression
4184 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4185 lbag.AddLocation ($$, GetLocation ($2));
4187 | relational_expression OP_GE shift_expression
4189 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4190 lbag.AddLocation ($$, GetLocation ($2));
4192 | relational_expression OP_LT error
4194 Error_SyntaxError (yyToken);
4196 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4197 lbag.AddLocation ($$, GetLocation ($2));
4199 | relational_expression OP_GT error
4201 Error_SyntaxError (yyToken);
4203 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4204 lbag.AddLocation ($$, GetLocation ($2));
4206 | relational_expression OP_LE error
4208 Error_SyntaxError (yyToken);
4210 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4211 lbag.AddLocation ($$, GetLocation ($2));
4213 | relational_expression OP_GE error
4215 Error_SyntaxError (yyToken);
4217 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4218 lbag.AddLocation ($$, GetLocation ($2));
4223 : relational_expression
4224 | equality_expression OP_EQ relational_expression
4226 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4227 lbag.AddLocation ($$, GetLocation ($2));
4229 | equality_expression OP_NE relational_expression
4231 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4232 lbag.AddLocation ($$, GetLocation ($2));
4234 | equality_expression OP_EQ error
4236 Error_SyntaxError (yyToken);
4238 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4239 lbag.AddLocation ($$, GetLocation ($2));
4241 | equality_expression OP_NE error
4243 Error_SyntaxError (yyToken);
4245 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4246 lbag.AddLocation ($$, GetLocation ($2));
4251 : equality_expression
4252 | and_expression BITWISE_AND equality_expression
4254 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4255 lbag.AddLocation ($$, GetLocation ($2));
4257 | and_expression BITWISE_AND error
4259 Error_SyntaxError (yyToken);
4261 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4262 lbag.AddLocation ($$, GetLocation ($2));
4266 exclusive_or_expression
4268 | exclusive_or_expression CARRET and_expression
4270 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4271 lbag.AddLocation ($$, GetLocation ($2));
4273 | exclusive_or_expression CARRET error
4275 Error_SyntaxError (yyToken);
4277 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4278 lbag.AddLocation ($$, GetLocation ($2));
4282 inclusive_or_expression
4283 : exclusive_or_expression
4284 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4286 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4287 lbag.AddLocation ($$, GetLocation ($2));
4289 | inclusive_or_expression BITWISE_OR error
4291 Error_SyntaxError (yyToken);
4293 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4294 lbag.AddLocation ($$, GetLocation ($2));
4298 conditional_and_expression
4299 : inclusive_or_expression
4300 | conditional_and_expression OP_AND inclusive_or_expression
4302 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4303 lbag.AddLocation ($$, GetLocation ($2));
4305 | conditional_and_expression OP_AND error
4307 Error_SyntaxError (yyToken);
4309 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4310 lbag.AddLocation ($$, GetLocation ($2));
4314 conditional_or_expression
4315 : conditional_and_expression
4316 | conditional_or_expression OP_OR conditional_and_expression
4318 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4319 lbag.AddLocation ($$, GetLocation ($2));
4321 | conditional_or_expression OP_OR error
4323 Error_SyntaxError (yyToken);
4325 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4326 lbag.AddLocation ($$, GetLocation ($2));
4330 null_coalescing_expression
4331 : conditional_or_expression
4332 | conditional_or_expression OP_COALESCING null_coalescing_expression
4334 if (lang_version < LanguageVersion.ISO_2)
4335 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4337 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4338 lbag.AddLocation ($$, GetLocation ($2));
4342 conditional_expression
4343 : null_coalescing_expression
4344 | null_coalescing_expression INTERR expression COLON expression
4346 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4347 lbag.AddLocation ($$, GetLocation ($4));
4349 | null_coalescing_expression INTERR expression error
4351 Error_SyntaxError (yyToken);
4353 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4355 | null_coalescing_expression INTERR expression COLON error
4357 Error_SyntaxError (yyToken);
4359 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4360 lbag.AddLocation ($$, GetLocation ($4));
4362 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4364 Error_SyntaxError (Token.CLOSE_BRACE);
4366 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4367 lbag.AddLocation ($$, GetLocation ($4));
4368 lexer.putback ('}');
4372 assignment_expression
4373 : prefixed_unary_expression ASSIGN expression
4375 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4376 lbag.AddLocation ($$, GetLocation ($2));
4378 | prefixed_unary_expression OP_MULT_ASSIGN expression
4380 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4381 lbag.AddLocation ($$, GetLocation ($2));
4383 | prefixed_unary_expression OP_DIV_ASSIGN expression
4385 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4386 lbag.AddLocation ($$, GetLocation ($2));
4388 | prefixed_unary_expression OP_MOD_ASSIGN expression
4390 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4391 lbag.AddLocation ($$, GetLocation ($2));
4393 | prefixed_unary_expression OP_ADD_ASSIGN expression
4395 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4396 lbag.AddLocation ($$, GetLocation ($2));
4398 | prefixed_unary_expression OP_SUB_ASSIGN expression
4400 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4401 lbag.AddLocation ($$, GetLocation ($2));
4403 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4405 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4406 lbag.AddLocation ($$, GetLocation ($2));
4408 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4410 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4411 lbag.AddLocation ($$, GetLocation ($2));
4413 | prefixed_unary_expression OP_AND_ASSIGN expression
4415 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4416 lbag.AddLocation ($$, GetLocation ($2));
4418 | prefixed_unary_expression OP_OR_ASSIGN expression
4420 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4421 lbag.AddLocation ($$, GetLocation ($2));
4423 | prefixed_unary_expression OP_XOR_ASSIGN expression
4425 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4426 lbag.AddLocation ($$, GetLocation ($2));
4430 lambda_parameter_list
4433 var pars = new List<Parameter> (4);
4434 pars.Add ((Parameter) $1);
4438 | lambda_parameter_list COMMA lambda_parameter
4440 var pars = (List<Parameter>) $1;
4441 Parameter p = (Parameter)$3;
4442 if (pars[0].GetType () != p.GetType ()) {
4443 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4452 : parameter_modifier parameter_type identifier_inside_body
4454 var lt = (LocatedToken) $3;
4456 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4458 | parameter_type identifier_inside_body
4460 var lt = (LocatedToken) $2;
4462 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4466 var lt = (LocatedToken) $1;
4467 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4471 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4472 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4476 opt_lambda_parameter_list
4477 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4478 | lambda_parameter_list {
4479 var pars_list = (List<Parameter>) $1;
4480 $$ = new ParametersCompiled (pars_list.ToArray ());
4484 lambda_expression_body
4486 start_block (Location.Null);
4488 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4490 Block b = end_block (Location.Null);
4491 b.IsCompilerGenerated = true;
4492 b.AddStatement (new ContextualReturn ((Expression) $2));
4498 // Handles only cases like foo = x.FirstOrDefault (l => );
4499 // where we must restore current_variable
4500 Block b = end_block (Location.Null);
4501 b.IsCompilerGenerated = true;
4503 Error_SyntaxError (yyToken);
4512 Error_SyntaxError (yyToken);
4520 var lt = (LocatedToken) $1;
4521 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4522 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4524 lambda_expression_body
4526 $$ = end_anonymous ((ParametersBlock) $4);
4527 lbag.AddLocation ($$, GetLocation ($2));
4531 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4532 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4533 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4535 lambda_expression_body
4537 $$ = end_anonymous ((ParametersBlock) $4);
4538 lbag.AddLocation ($$, GetLocation ($2));
4540 | ASYNC identifier_inside_body ARROW
4542 var lt = (LocatedToken) $2;
4543 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4544 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4546 lambda_expression_body
4548 $$ = end_anonymous ((ParametersBlock) $5);
4549 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4551 | OPEN_PARENS_LAMBDA
4553 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4555 opt_lambda_parameter_list CLOSE_PARENS ARROW
4557 valid_param_mod = 0;
4558 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4560 lambda_expression_body
4562 $$ = end_anonymous ((ParametersBlock) $7);
4563 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4565 | ASYNC OPEN_PARENS_LAMBDA
4567 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4569 opt_lambda_parameter_list CLOSE_PARENS ARROW
4571 valid_param_mod = 0;
4572 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4574 lambda_expression_body
4576 $$ = end_anonymous ((ParametersBlock) $8);
4577 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4582 : assignment_expression
4583 | non_assignment_expression
4586 non_assignment_expression
4587 : conditional_expression
4592 $$ = new ArglistAccess (GetLocation ($1));
4596 undocumented_expressions
4597 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4599 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4600 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4602 | REFTYPE open_parens_any expression CLOSE_PARENS
4604 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4605 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4607 | MAKEREF open_parens_any expression CLOSE_PARENS
4609 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4610 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4621 $$ = new BooleanExpression ((Expression) $1);
4635 type_declaration_name
4637 lexer.ConstraintsParsing = true;
4639 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4640 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4641 FeatureIsNotAvailable (c.Location, "static classes");
4644 push_current_container (c, $3);
4647 opt_type_parameter_constraints_clauses
4649 lexer.ConstraintsParsing = false;
4652 current_container.SetConstraints ((List<Constraints>) $9);
4653 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4656 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4657 Lexer.doc_state = XmlCommentState.Allowed;
4660 lexer.parsing_modifiers = true;
4662 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4664 --lexer.parsing_declaration;
4666 Lexer.doc_state = XmlCommentState.Allowed;
4671 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4673 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4675 $$ = pop_current_class ();
4683 { $$ = $1; } // location
4689 mod_locations = null;
4691 lexer.parsing_modifiers = false;
4695 lexer.parsing_modifiers = false;
4701 | modifiers modifier
4703 var m1 = (Modifiers) $1;
4704 var m2 = (Modifiers) $2;
4706 if ((m1 & m2) != 0) {
4707 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4708 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4709 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4710 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4711 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4712 "More than one protection modifier specified");
4723 StoreModifierLocation ($$, GetLocation ($1));
4725 if (current_container.Kind == MemberKind.Namespace)
4726 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4730 $$ = Modifiers.PUBLIC;
4731 StoreModifierLocation ($$, GetLocation ($1));
4735 $$ = Modifiers.PROTECTED;
4736 StoreModifierLocation ($$, GetLocation ($1));
4740 $$ = Modifiers.INTERNAL;
4741 StoreModifierLocation ($$, GetLocation ($1));
4745 $$ = Modifiers.PRIVATE;
4746 StoreModifierLocation ($$, GetLocation ($1));
4750 $$ = Modifiers.ABSTRACT;
4751 StoreModifierLocation ($$, GetLocation ($1));
4755 $$ = Modifiers.SEALED;
4756 StoreModifierLocation ($$, GetLocation ($1));
4760 $$ = Modifiers.STATIC;
4761 StoreModifierLocation ($$, GetLocation ($1));
4765 $$ = Modifiers.READONLY;
4766 StoreModifierLocation ($$, GetLocation ($1));
4770 $$ = Modifiers.VIRTUAL;
4771 StoreModifierLocation ($$, GetLocation ($1));
4775 $$ = Modifiers.OVERRIDE;
4776 StoreModifierLocation ($$, GetLocation ($1));
4780 $$ = Modifiers.EXTERN;
4781 StoreModifierLocation ($$, GetLocation ($1));
4785 $$ = Modifiers.VOLATILE;
4786 StoreModifierLocation ($$, GetLocation ($1));
4790 $$ = Modifiers.UNSAFE;
4791 StoreModifierLocation ($$, GetLocation ($1));
4792 if (!settings.Unsafe)
4793 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4797 $$ = Modifiers.ASYNC;
4798 StoreModifierLocation ($$, GetLocation ($1));
4806 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4808 | COLON type_list error
4810 Error_SyntaxError (yyToken);
4812 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4816 opt_type_parameter_constraints_clauses
4818 | type_parameter_constraints_clauses
4824 type_parameter_constraints_clauses
4825 : type_parameter_constraints_clause
4827 var constraints = new List<Constraints> (1);
4828 constraints.Add ((Constraints) $1);
4831 | type_parameter_constraints_clauses type_parameter_constraints_clause
4833 var constraints = (List<Constraints>) $1;
4834 Constraints new_constraint = (Constraints)$2;
4836 foreach (Constraints c in constraints) {
4837 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4838 report.Error (409, new_constraint.Location,
4839 "A constraint clause has already been specified for type parameter `{0}'",
4840 new_constraint.TypeParameter.Value);
4844 constraints.Add (new_constraint);
4849 type_parameter_constraints_clause
4850 : WHERE IDENTIFIER COLON type_parameter_constraints
4852 var lt = (LocatedToken) $2;
4853 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4854 lbag.AddLocation ($$, GetLocation ($3));
4856 | WHERE IDENTIFIER error
4858 Error_SyntaxError (yyToken);
4860 var lt = (LocatedToken) $2;
4861 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4865 type_parameter_constraints
4866 : type_parameter_constraint
4868 var constraints = new List<FullNamedExpression> (1);
4869 constraints.Add ((FullNamedExpression) $1);
4872 | type_parameter_constraints COMMA type_parameter_constraint
4874 var constraints = (List<FullNamedExpression>) $1;
4875 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4876 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4877 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4880 prev = $3 as SpecialContraintExpr;
4882 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4883 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4885 prev = constraints [0] as SpecialContraintExpr;
4886 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4887 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4892 constraints.Add ((FullNamedExpression) $3);
4897 type_parameter_constraint
4900 if ($1 is ComposedCast)
4901 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4905 | NEW OPEN_PARENS CLOSE_PARENS
4907 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4908 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4912 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4916 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4920 opt_type_parameter_variance
4925 | type_parameter_variance
4927 if (lang_version <= LanguageVersion.V_3)
4928 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4934 type_parameter_variance
4937 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
4941 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
4950 // A block is "contained" on the following places:
4952 // property_declaration as part of the accessor body (get/set)
4953 // operator_declaration
4954 // constructor_declaration
4955 // destructor_declaration
4956 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4961 ++lexer.parsing_block;
4962 start_block (GetLocation ($1));
4964 opt_statement_list block_end
4973 --lexer.parsing_block;
4974 $$ = end_block (GetLocation ($1));
4976 | COMPLETE_COMPLETION
4978 --lexer.parsing_block;
4979 $$ = end_block (lexer.Location);
4987 ++lexer.parsing_block;
4988 current_block.StartLocation = GetLocation ($1);
4990 opt_statement_list CLOSE_BRACE
4992 --lexer.parsing_block;
4993 $$ = end_block (GetLocation ($4));
5004 | statement_list statement
5008 : block_variable_declaration
5010 current_block.AddStatement ((Statement) $1);
5012 | valid_declaration_statement
5014 current_block.AddStatement ((Statement) $1);
5019 Error_SyntaxError (yyToken);
5025 // The interactive_statement and its derivatives are only
5026 // used to provide a special version of `expression_statement'
5027 // that has a side effect of assigning the expression to
5030 interactive_statement_list
5031 : interactive_statement
5032 | interactive_statement_list interactive_statement
5035 interactive_statement
5036 : block_variable_declaration
5038 current_block.AddStatement ((Statement) $1);
5040 | interactive_valid_declaration_statement
5042 current_block.AddStatement ((Statement) $1);
5047 valid_declaration_statement
5050 | expression_statement
5051 | selection_statement
5052 | iteration_statement
5056 | unchecked_statement
5063 interactive_valid_declaration_statement
5066 | interactive_expression_statement
5067 | selection_statement
5068 | iteration_statement
5072 | unchecked_statement
5080 : valid_declaration_statement
5081 | block_variable_declaration
5083 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5088 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5093 Error_SyntaxError (yyToken);
5094 $$ = new EmptyStatement (GetLocation ($1));
5101 // Uses lexer.Location because semicolon location is not kept in quick mode
5102 $$ = new EmptyStatement (lexer.Location);
5107 : identifier_inside_body COLON
5109 var lt = (LocatedToken) $1;
5110 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5111 lbag.AddLocation (labeled, GetLocation ($2));
5112 current_block.AddLabel (labeled);
5113 current_block.AddStatement (labeled);
5119 : variable_type_simple
5120 | variable_type_simple rank_specifiers
5123 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5125 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5130 * The following is from Rhys' grammar:
5131 * > Types in local variable declarations must be recognized as
5132 * > expressions to prevent reduce/reduce errors in the grammar.
5133 * > The expressions are converted into types during semantic analysis.
5135 variable_type_simple
5136 : primary_expression_or_type opt_nullable
5138 // Ok, the above "primary_expression" is there to get rid of
5139 // both reduce/reduce and shift/reduces in the grammar, it should
5140 // really just be "type_name". If you use type_name, a reduce/reduce
5141 // creeps up. If you use namespace_or_type_name (which is all we need
5142 // really) two shift/reduces appear.
5145 // So the super-trick is that primary_expression
5146 // can only be either a SimpleName or a MemberAccess.
5147 // The MemberAccess case arises when you have a fully qualified type-name like :
5149 // SimpleName is when you have
5152 Expression expr = (Expression) $1;
5154 SimpleName sn = expr as SimpleName;
5155 if (sn != null && sn.Name == "var")
5156 $$ = new VarExpr (sn.Location);
5159 } else if (expr is ATypeNameExpression) {
5160 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5162 Error_ExpectingTypeName (expr);
5166 | primary_expression_or_type pointer_stars
5168 ATypeNameExpression expr = $1 as ATypeNameExpression;
5171 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5173 Error_ExpectingTypeName ((Expression)$1);
5177 | builtin_types opt_nullable
5182 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5184 | builtin_types pointer_stars
5186 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5188 | VOID pointer_stars
5190 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5194 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5195 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5201 | pointer_star pointer_stars
5203 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5211 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5215 identifier_inside_body
5219 $$ = Error_AwaitAsIdentifier ($1);
5223 block_variable_declaration
5224 : variable_type identifier_inside_body
5226 var lt = (LocatedToken) $2;
5227 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5228 current_block.AddLocalName (li);
5229 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5231 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5233 $$ = current_variable;
5234 current_variable = null;
5236 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5238 lbag.AddLocation ($$, GetLocation ($6));
5240 | CONST variable_type identifier_inside_body
5242 var lt = (LocatedToken) $3;
5243 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5244 current_block.AddLocalName (li);
5245 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5247 const_variable_initializer opt_const_declarators SEMICOLON
5249 $$ = current_variable;
5250 current_variable = null;
5251 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5255 opt_local_variable_initializer
5257 | ASSIGN block_variable_initializer
5259 current_variable.Initializer = (Expression) $2;
5260 PushLocation (GetLocation ($1));
5261 $$ = current_variable;
5265 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5266 report.Error (650, lexer.Location,
5267 "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");
5269 Error_SyntaxError (yyToken);
5274 opt_variable_declarators
5276 | variable_declarators
5279 opt_using_or_fixed_variable_declarators
5281 | variable_declarators
5283 foreach (var d in current_variable.Declarators) {
5284 if (d.Initializer == null)
5285 Error_MissingInitializer (d.Variable.Location);
5290 variable_declarators
5291 : variable_declarator
5292 | variable_declarators variable_declarator
5296 : COMMA identifier_inside_body
5298 var lt = (LocatedToken) $2;
5299 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5300 var d = new BlockVariableDeclarator (li, null);
5301 current_variable.AddDeclarator (d);
5302 current_block.AddLocalName (li);
5303 lbag.AddLocation (d, GetLocation ($1));
5305 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5307 var lt = (LocatedToken) $2;
5308 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5309 var d = new BlockVariableDeclarator (li, (Expression) $4);
5310 current_variable.AddDeclarator (d);
5311 current_block.AddLocalName (li);
5312 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5316 const_variable_initializer
5319 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5321 | ASSIGN constant_initializer_expr
5323 current_variable.Initializer = (Expression) $2;
5327 opt_const_declarators
5334 | const_declarators const_declarator
5338 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5340 var lt = (LocatedToken) $2;
5341 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5342 var d = new BlockVariableDeclarator (li, (Expression) $4);
5343 current_variable.AddDeclarator (d);
5344 current_block.AddLocalName (li);
5345 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5349 block_variable_initializer
5350 : variable_initializer
5351 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5353 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5354 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5356 | STACKALLOC simple_type
5358 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5359 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5363 expression_statement
5364 : statement_expression SEMICOLON
5367 lbag.AddStatement ($$, GetLocation ($2));
5369 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5370 | statement_expression CLOSE_BRACE
5373 report.Error (1002, GetLocation ($2), "; expected");
5374 lexer.putback ('}');
5378 interactive_expression_statement
5379 : interactive_statement_expression SEMICOLON { $$ = $1; }
5380 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5384 // We have to do the wrapping here and not in the case above,
5385 // because statement_expression is used for example in for_statement
5387 statement_expression
5390 ExpressionStatement s = $1 as ExpressionStatement;
5392 var expr = $1 as Expression;
5393 $$ = new StatementErrorExpression (expr);
5395 $$ = new StatementExpression (s);
5400 interactive_statement_expression
5403 Expression expr = (Expression) $1;
5404 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5408 Error_SyntaxError (yyToken);
5409 $$ = new EmptyStatement (GetLocation ($1));
5419 : IF open_parens_any boolean_expression CLOSE_PARENS
5422 if ($5 is EmptyStatement)
5423 Warning_EmptyStatement (GetLocation ($5));
5425 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5426 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5428 | IF open_parens_any boolean_expression CLOSE_PARENS
5429 embedded_statement ELSE embedded_statement
5431 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5432 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5434 if ($5 is EmptyStatement)
5435 Warning_EmptyStatement (GetLocation ($5));
5436 if ($7 is EmptyStatement)
5437 Warning_EmptyStatement (GetLocation ($7));
5439 | IF open_parens_any boolean_expression error
5441 Error_SyntaxError (yyToken);
5443 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5444 lbag.AddStatement ($$, GetLocation ($2));
5449 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5451 start_block (GetLocation ($5));
5453 opt_switch_sections CLOSE_BRACE
5455 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5456 end_block (GetLocation ($8));
5457 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5459 | SWITCH open_parens_any expression error
5461 Error_SyntaxError (yyToken);
5463 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5464 lbag.AddStatement ($$, GetLocation ($2));
5471 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5478 | switch_sections switch_section
5481 Error_SyntaxError (yyToken);
5486 : switch_labels statement_list
5492 var label = (SwitchLabel) $1;
5493 label.SectionStart = true;
5494 current_block.AddStatement (label);
5496 | switch_labels switch_label
5498 current_block.AddStatement ((Statement) $2);
5503 : CASE constant_expression COLON
5505 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5506 lbag.AddLocation ($$, GetLocation ($3));
5508 | CASE constant_expression error
5510 Error_SyntaxError (yyToken);
5511 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5515 $$ = new SwitchLabel (null, GetLocation ($1));
5527 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5529 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5530 Warning_EmptyStatement (GetLocation ($5));
5532 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5533 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5535 | WHILE open_parens_any boolean_expression error
5537 Error_SyntaxError (yyToken);
5539 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5540 lbag.AddStatement ($$, GetLocation ($2));
5545 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5547 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5548 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5550 | DO embedded_statement error
5552 Error_SyntaxError (yyToken);
5553 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5555 | DO embedded_statement WHILE open_parens_any boolean_expression error
5557 Error_SyntaxError (yyToken);
5559 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5560 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5565 : FOR open_parens_any
5567 start_block (GetLocation ($2));
5568 current_block.IsCompilerGenerated = true;
5569 For f = new For (GetLocation ($1));
5570 current_block.AddStatement (f);
5579 // Has to use be extra rule to recover started block
5581 : opt_for_initializer SEMICOLON
5583 ((For) $0).Initializer = (Statement) $1;
5585 // Pass the "For" object to the iterator_part4
5586 oob_stack.Push ($0);
5588 for_condition_and_iterator_part
5591 var locations = (Tuple<Location,Location>) $4;
5593 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5594 Warning_EmptyStatement (GetLocation ($5));
5597 f.Statement = (Statement) $5;
5598 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5600 $$ = end_block (GetLocation ($2));
5604 Error_SyntaxError (yyToken);
5605 $$ = end_block (current_block.StartLocation);
5609 for_condition_and_iterator_part
5610 : opt_for_condition SEMICOLON
5612 For f = (For) oob_stack.Peek ();
5613 f.Condition = (BooleanExpression) $1;
5616 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5619 // Handle errors in the case of opt_for_condition being followed by
5620 // a close parenthesis
5621 | opt_for_condition close_parens_close_brace {
5622 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5623 For f = (For) oob_stack.Peek ();
5624 f.Condition = (BooleanExpression) $1;
5625 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5630 : opt_for_iterator CLOSE_PARENS {
5631 For f = (For) oob_stack.Peek ();
5632 f.Iterator = (Statement) $1;
5633 $$ = GetLocation ($2);
5635 | opt_for_iterator CLOSE_BRACE {
5636 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5637 For f = (For) oob_stack.Peek ();
5638 f.Iterator = (Statement) $1;
5639 $$ = GetLocation ($2);
5643 close_parens_close_brace
5645 | CLOSE_BRACE { lexer.putback ('}'); }
5649 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5654 : variable_type identifier_inside_body
5656 var lt = (LocatedToken) $2;
5657 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5658 current_block.AddLocalName (li);
5659 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5661 opt_local_variable_initializer opt_variable_declarators
5663 $$ = current_variable;
5665 lbag.AddLocation (current_variable, PopLocation ());
5667 current_variable = null;
5669 | statement_expression_list
5673 : /* empty */ { $$ = null; }
5674 | boolean_expression
5678 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5683 : statement_expression_list
5686 statement_expression_list
5687 : statement_expression
5688 | statement_expression_list COMMA statement_expression
5690 var sl = $1 as StatementList;
5692 sl = new StatementList ((Statement) $1, (Statement) $3);
5693 lbag.AddStatement (sl, GetLocation ($2));
5695 sl.Add ((Statement) $3);
5696 lbag.AppendTo (sl, GetLocation ($2));
5704 : FOREACH open_parens_any type error
5706 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5708 start_block (GetLocation ($2));
5709 current_block.IsCompilerGenerated = true;
5711 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5712 current_block.AddStatement (f);
5714 lbag.AddStatement (f, GetLocation ($2));
5715 $$ = end_block (GetLocation ($4));
5717 | FOREACH open_parens_any type identifier_inside_body error
5719 Error_SyntaxError (yyToken);
5721 start_block (GetLocation ($2));
5722 current_block.IsCompilerGenerated = true;
5724 var lt = (LocatedToken) $4;
5725 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5726 current_block.AddLocalName (li);
5728 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5729 current_block.AddStatement (f);
5731 lbag.AddStatement (f, GetLocation ($2));
5732 $$ = end_block (GetLocation ($5));
5734 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5736 start_block (GetLocation ($2));
5737 current_block.IsCompilerGenerated = true;
5739 var lt = (LocatedToken) $4;
5740 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5741 current_block.AddLocalName (li);
5746 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5747 Warning_EmptyStatement (GetLocation ($9));
5749 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5750 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5751 end_block (GetLocation ($7));
5759 | continue_statement
5769 $$ = new Break (GetLocation ($1));
5770 lbag.AddStatement ($$, GetLocation ($2));
5775 : CONTINUE SEMICOLON
5777 $$ = new Continue (GetLocation ($1));
5778 lbag.AddStatement ($$, GetLocation ($2));
5782 Error_SyntaxError (yyToken);
5783 $$ = new Continue (GetLocation ($1));
5788 : GOTO identifier_inside_body SEMICOLON
5790 var lt = (LocatedToken) $2;
5791 $$ = new Goto (lt.Value, GetLocation ($1));
5792 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5794 | GOTO CASE constant_expression SEMICOLON
5796 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5797 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5799 | GOTO DEFAULT SEMICOLON
5801 $$ = new GotoDefault (GetLocation ($1));
5802 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5807 : RETURN opt_expression SEMICOLON
5809 $$ = new Return ((Expression) $2, GetLocation ($1));
5810 lbag.AddStatement ($$, GetLocation ($3));
5812 | RETURN expression error
5814 Error_SyntaxError (yyToken);
5815 $$ = new Return ((Expression) $2, GetLocation ($1));
5819 Error_SyntaxError (yyToken);
5820 $$ = new Return (null, GetLocation ($1));
5825 : THROW opt_expression SEMICOLON
5827 $$ = new Throw ((Expression) $2, GetLocation ($1));
5828 lbag.AddStatement ($$, GetLocation ($3));
5830 | THROW expression error
5832 Error_SyntaxError (yyToken);
5833 $$ = new Throw ((Expression) $2, GetLocation ($1));
5837 Error_SyntaxError (yyToken);
5838 $$ = new Throw (null, GetLocation ($1));
5843 : identifier_inside_body RETURN opt_expression SEMICOLON
5845 var lt = (LocatedToken) $1;
5846 string s = lt.Value;
5848 report.Error (1003, lt.Location, "; expected");
5849 } else if ($3 == null) {
5850 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5851 } else if (lang_version == LanguageVersion.ISO_1){
5852 FeatureIsNotAvailable (lt.Location, "iterators");
5855 current_block.Explicit.RegisterIteratorYield ();
5856 $$ = new Yield ((Expression) $3, lt.Location);
5857 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5859 | identifier_inside_body RETURN expression error
5861 Error_SyntaxError (yyToken);
5863 var lt = (LocatedToken) $1;
5864 string s = lt.Value;
5866 report.Error (1003, lt.Location, "; expected");
5867 } else if ($3 == null) {
5868 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5869 } else if (lang_version == LanguageVersion.ISO_1){
5870 FeatureIsNotAvailable (lt.Location, "iterators");
5873 current_block.Explicit.RegisterIteratorYield ();
5874 $$ = new Yield ((Expression) $3, lt.Location);
5875 lbag.AddStatement ($$, GetLocation ($2));
5877 | identifier_inside_body BREAK SEMICOLON
5879 var lt = (LocatedToken) $1;
5880 string s = lt.Value;
5882 report.Error (1003, lt.Location, "; expected");
5883 } else if (lang_version == LanguageVersion.ISO_1){
5884 FeatureIsNotAvailable (lt.Location, "iterators");
5887 current_block.ParametersBlock.TopBlock.IsIterator = true;
5888 $$ = new YieldBreak (lt.Location);
5889 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5899 : TRY block catch_clauses
5901 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5903 | TRY block FINALLY block
5905 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
5906 lbag.AddStatement ($$, GetLocation ($3));
5908 | TRY block catch_clauses FINALLY block
5910 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
5911 lbag.AddStatement ($$, GetLocation ($4));
5915 Error_SyntaxError (1524, yyToken);
5916 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5923 var l = new List<Catch> (2);
5928 | catch_clauses catch_clause
5930 var l = (List<Catch>) $1;
5932 Catch c = (Catch) $2;
5933 if (l [l.Count - 1].IsGeneral) {
5934 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5944 | identifier_inside_body
5950 $$ = new Catch ((ExplicitBlock) $2, GetLocation ($1));
5952 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5954 start_block (GetLocation ($2));
5955 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
5956 c.TypeExpression = (FullNamedExpression) $3;
5959 var lt = (LocatedToken) $4;
5960 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5961 current_block.AddLocalName (c.Variable);
5964 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5971 | CATCH open_parens_any error
5973 if (yyToken == Token.CLOSE_PARENS) {
5974 report.Error (1015, lexer.Location,
5975 "A type that derives from `System.Exception', `object', or `string' expected");
5977 Error_SyntaxError (yyToken);
5980 $$ = new Catch (null, GetLocation ($1));
5982 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5984 Error_SyntaxError (yyToken);
5986 // Required otherwise missing block could not be detected because
5987 // start_block is run early
5988 var c = new Catch (null, GetLocation ($1));
5989 c.TypeExpression = (FullNamedExpression) $3;
5992 var lt = (LocatedToken) $4;
5993 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5996 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6005 $$ = new Checked ((Block) $2, GetLocation ($1));
6012 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6019 if (!settings.Unsafe)
6020 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6022 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6027 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6029 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6030 Warning_EmptyStatement (GetLocation ($5));
6032 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6033 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6035 | LOCK open_parens_any expression error
6037 Error_SyntaxError (yyToken);
6039 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6040 lbag.AddStatement ($$, GetLocation ($2));
6045 : FIXED open_parens_any variable_type identifier_inside_body
6047 start_block (GetLocation ($2));
6049 current_block.IsCompilerGenerated = true;
6050 var lt = (LocatedToken) $4;
6051 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6052 current_block.AddLocalName (li);
6053 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6055 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6057 $$ = current_variable;
6058 current_variable = null;
6062 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6063 Warning_EmptyStatement (GetLocation ($10));
6065 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6066 current_block.AddStatement (f);
6067 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6068 $$ = end_block (GetLocation ($8));
6073 : USING open_parens_any variable_type identifier_inside_body
6075 start_block (GetLocation ($2));
6077 current_block.IsCompilerGenerated = true;
6078 var lt = (LocatedToken) $4;
6079 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6080 current_block.AddLocalName (li);
6081 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6083 using_initialization CLOSE_PARENS
6085 $$ = current_variable;
6086 current_variable = null;
6090 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6091 Warning_EmptyStatement (GetLocation ($9));
6093 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6094 current_block.AddStatement (u);
6095 $$ = end_block (GetLocation ($7));
6097 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6099 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6100 Warning_EmptyStatement (GetLocation ($5));
6102 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6103 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6105 | USING open_parens_any expression error
6107 Error_SyntaxError (yyToken);
6109 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6110 lbag.AddStatement ($$, GetLocation ($2));
6114 using_initialization
6115 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6118 // It has to be here for the parent to safely restore artificial block
6119 Error_SyntaxError (yyToken);
6123 using_or_fixed_variable_initializer
6126 Error_MissingInitializer (lexer.Location);
6128 | ASSIGN variable_initializer
6130 current_variable.Initializer = (Expression) $2;
6131 $$ = current_variable;
6139 : first_from_clause query_body
6141 lexer.query_parsing = false;
6143 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6145 from.Tail.Next = (Linq.AQueryClause)$2;
6148 current_block.SetEndLocation (lexer.Location);
6149 current_block = current_block.Parent;
6151 | nested_from_clause query_body
6153 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6155 from.Tail.Next = (Linq.AQueryClause)$2;
6158 current_block.SetEndLocation (lexer.Location);
6159 current_block = current_block.Parent;
6162 // Bubble up COMPLETE_COMPLETION productions
6163 | first_from_clause COMPLETE_COMPLETION {
6164 lexer.query_parsing = false;
6167 current_block.SetEndLocation (lexer.Location);
6168 current_block = current_block.Parent;
6170 | nested_from_clause COMPLETE_COMPLETION {
6172 current_block.SetEndLocation (lexer.Location);
6173 current_block = current_block.Parent;
6178 : FROM_FIRST identifier_inside_body IN expression
6180 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6182 var lt = (LocatedToken) $2;
6183 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6184 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6185 lbag.AddLocation (clause, GetLocation ($3));
6186 $$ = new Linq.QueryExpression (clause);
6188 | FROM_FIRST type identifier_inside_body IN expression
6190 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6192 var lt = (LocatedToken) $3;
6193 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6194 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6195 IdentifierType = (FullNamedExpression)$2
6197 lbag.AddLocation (clause, GetLocation ($4));
6198 $$ = new Linq.QueryExpression (clause);
6203 : FROM identifier_inside_body IN expression
6205 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6207 var lt = (LocatedToken) $2;
6208 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6209 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6210 lbag.AddLocation (clause, GetLocation ($3));
6211 $$ = new Linq.QueryExpression (clause);
6213 | FROM type identifier_inside_body IN expression
6215 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6217 var lt = (LocatedToken) $3;
6218 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6219 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6220 IdentifierType = (FullNamedExpression)$2
6222 lbag.AddLocation (clause, GetLocation ($4));
6223 $$ = new Linq.QueryExpression (clause);
6228 : FROM identifier_inside_body IN
6230 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6234 var lt = (LocatedToken) $2;
6235 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6236 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6238 current_block.SetEndLocation (lexer.Location);
6239 current_block = current_block.Parent;
6241 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6242 lbag.AddLocation ($$, GetLocation ($3));
6244 | FROM type identifier_inside_body IN
6246 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6250 var lt = (LocatedToken) $3;
6251 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6253 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6254 IdentifierType = (FullNamedExpression)$2
6257 current_block.SetEndLocation (lexer.Location);
6258 current_block = current_block.Parent;
6260 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6262 lbag.AddLocation ($$, GetLocation ($4));
6267 : query_body_clauses select_or_group_clause opt_query_continuation
6269 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6272 head.Next = (Linq.AQueryClause)$3;
6275 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6276 clause.Tail.Next = head;
6282 | select_or_group_clause opt_query_continuation
6284 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6287 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6288 clause.Tail.Next = head;
6294 | query_body_clauses COMPLETE_COMPLETION
6295 | query_body_clauses error
6297 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6302 Error_SyntaxError (yyToken);
6307 select_or_group_clause
6310 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6314 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6316 current_block.SetEndLocation (lexer.Location);
6317 current_block = current_block.Parent;
6321 if (linq_clause_blocks == null)
6322 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6324 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6325 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6329 current_block.SetEndLocation (lexer.Location);
6330 current_block = current_block.Parent;
6332 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6336 var obj = (object[]) $5;
6338 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6339 lbag.AddLocation ($$, (Location) obj[1]);
6341 current_block.SetEndLocation (lexer.Location);
6342 current_block = current_block.Parent;
6347 : BY expression_or_error
6349 $$ = new object[] { $2, GetLocation ($1) };
6353 Error_SyntaxError (yyToken);
6354 $$ = new object[2] { null, Location.Null };
6360 | query_body_clauses query_body_clause
6362 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6376 : LET identifier_inside_body ASSIGN
6378 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6382 var lt = (LocatedToken) $2;
6383 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6384 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6385 lbag.AddLocation ($$, GetLocation ($3));
6387 current_block.SetEndLocation (lexer.Location);
6388 current_block = current_block.Parent;
6390 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6397 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6401 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6403 current_block.SetEndLocation (lexer.Location);
6404 current_block = current_block.Parent;
6409 : JOIN identifier_inside_body IN
6411 if (linq_clause_blocks == null)
6412 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6414 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6415 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6417 expression_or_error ON
6419 current_block.SetEndLocation (lexer.Location);
6420 current_block = current_block.Parent;
6422 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6423 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6425 expression_or_error EQUALS
6427 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6428 current_block.SetEndLocation (lexer.Location);
6429 current_block = current_block.Parent;
6431 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6433 expression_or_error opt_join_into
6435 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6436 current_block.SetEndLocation (lexer.Location);
6438 var outer_selector = linq_clause_blocks.Pop ();
6439 var block = linq_clause_blocks.Pop ();
6441 var lt = (LocatedToken) $2;
6442 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6443 Linq.RangeVariable into;
6447 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6448 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6451 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6453 var parent = block.Parent;
6454 while (parent is Linq.QueryBlock) {
6455 parent = parent.Parent;
6457 current_block.Parent = parent;
6459 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6461 lt = (LocatedToken) $12;
6462 into = new Linq.RangeVariable (lt.Value, lt.Location);
6464 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6465 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6468 current_block = block.Parent;
6469 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6471 | JOIN type identifier_inside_body IN
6473 if (linq_clause_blocks == null)
6474 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6476 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6477 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6479 expression_or_error ON
6481 current_block.SetEndLocation (lexer.Location);
6482 current_block = current_block.Parent;
6484 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6485 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6487 expression_or_error EQUALS
6489 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6490 current_block.SetEndLocation (lexer.Location);
6491 current_block = current_block.Parent;
6493 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6495 expression_or_error opt_join_into
6497 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6498 current_block.SetEndLocation (lexer.Location);
6500 var outer_selector = linq_clause_blocks.Pop ();
6501 var block = linq_clause_blocks.Pop ();
6503 var lt = (LocatedToken) $3;
6504 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6505 Linq.RangeVariable into;
6509 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6510 IdentifierType = (FullNamedExpression)$2
6512 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6515 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6517 var parent = block.Parent;
6518 while (parent is Linq.QueryBlock) {
6519 parent = parent.Parent;
6521 current_block.Parent = parent;
6523 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6525 lt = (LocatedToken) $13;
6526 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6528 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6529 IdentifierType = (FullNamedExpression)$2
6533 current_block = block.Parent;
6534 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6540 | INTO identifier_inside_body
6549 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6553 current_block.SetEndLocation (lexer.Location);
6554 current_block = current_block.Parent;
6564 current_block.SetEndLocation (lexer.Location);
6565 current_block = current_block.Parent;
6567 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6571 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6578 | orderings_then_by COMMA
6580 current_block.SetEndLocation (lexer.Location);
6581 current_block = current_block.Parent;
6583 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6587 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6595 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6597 | expression ASCENDING
6599 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6600 lbag.AddLocation ($$, GetLocation ($2));
6602 | expression DESCENDING
6604 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6605 lbag.AddLocation ($$, GetLocation ($2));
6612 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6614 | expression ASCENDING
6616 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6617 lbag.AddLocation ($$, GetLocation ($2));
6619 | expression DESCENDING
6621 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6622 lbag.AddLocation ($$, GetLocation ($2));
6627 opt_query_continuation
6629 | INTO identifier_inside_body
6631 // query continuation block is not linked with query block but with block
6632 // before. This means each query can use same range variable names for
6633 // different identifiers.
6635 current_block.SetEndLocation (GetLocation ($1));
6636 current_block = current_block.Parent;
6638 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6640 if (linq_clause_blocks == null)
6641 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6643 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6647 var current_block = linq_clause_blocks.Pop ();
6648 var lt = (LocatedToken) $2;
6649 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6650 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6651 next = (Linq.AQueryClause)$4
6657 // Support for using the compiler as an interactive parser
6659 // The INTERACTIVE_PARSER token is first sent to parse our
6660 // productions; If the result is a Statement, the parsing
6661 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6662 // to setup the blocks in advance.
6664 // This setup is here so that in the future we can add
6665 // support for other constructs (type parsing, namespaces, etc)
6666 // that do not require a block to be setup in advance
6670 : EVAL_STATEMENT_PARSER EOF
6671 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6672 | EVAL_STATEMENT_PARSER
6674 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6676 // (ref object retval)
6677 Parameter [] mpar = new Parameter [1];
6678 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6680 ParametersCompiled pars = new ParametersCompiled (mpar);
6681 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6682 if (settings.Unsafe)
6683 mods |= Modifiers.UNSAFE;
6685 current_local_parameters = pars;
6686 var method = new InteractiveMethod (
6688 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6692 current_type.AddMember (method);
6693 oob_stack.Push (method);
6695 interactive_async = false;
6697 ++lexer.parsing_block;
6698 start_block (lexer.Location);
6700 interactive_statement_list opt_COMPLETE_COMPLETION
6702 --lexer.parsing_block;
6703 var method = (InteractiveMethod) oob_stack.Pop ();
6704 method.Block = (ToplevelBlock) end_block(lexer.Location);
6706 if (interactive_async == true) {
6707 method.ChangeToAsync ();
6710 InteractiveResult = (Class) pop_current_class ();
6711 current_local_parameters = null;
6713 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6716 interactive_compilation_unit
6717 : opt_extern_alias_directives opt_using_directives
6718 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6721 opt_COMPLETE_COMPLETION
6723 | COMPLETE_COMPLETION
6726 close_brace_or_complete_completion
6728 | COMPLETE_COMPLETION
6732 // XML documentation code references micro parser
6734 documentation_parsing
6737 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6742 : doc_type_declaration_name opt_doc_method_sig
6744 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6746 | builtin_types opt_doc_method_sig
6748 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6749 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6752 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6754 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6755 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6756 var lt = (LocatedToken) $3;
6757 $$ = new MemberName (lt.Value);
6759 | doc_type_declaration_name DOT THIS
6761 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6763 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6765 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6767 opt_doc_parameters CLOSE_BRACKET
6769 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6770 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6772 | EXPLICIT OPERATOR type opt_doc_method_sig
6774 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6775 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6776 module.DocumentationBuilder.ParsedParameters = p;
6777 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6780 | IMPLICIT OPERATOR type opt_doc_method_sig
6782 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6783 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6784 module.DocumentationBuilder.ParsedParameters = p;
6785 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6788 | OPERATOR overloadable_operator opt_doc_method_sig
6790 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6791 module.DocumentationBuilder.ParsedParameters = p;
6792 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6797 doc_type_declaration_name
6798 : type_declaration_name
6799 | doc_type_declaration_name DOT type_declaration_name
6801 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6809 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6811 opt_doc_parameters CLOSE_PARENS
6820 $$ = new List<DocumentationParameter> (0);
6828 var parameters = new List<DocumentationParameter> ();
6829 parameters.Add ((DocumentationParameter) $1);
6832 | doc_parameters COMMA doc_parameter
6834 var parameters = $1 as List<DocumentationParameter>;
6835 parameters.Add ((DocumentationParameter) $3);
6841 : opt_parameter_modifier parameter_type
6844 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6846 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6853 // A class used to hold info about an operator declarator
6855 class OperatorDeclaration {
6856 public readonly Operator.OpType optype;
6857 public readonly FullNamedExpression ret_type;
6858 public readonly Location location;
6860 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6863 this.ret_type = ret_type;
6864 this.location = location;
6868 void Error_ExpectingTypeName (Expression expr)
6870 if (expr is Invocation){
6871 report.Error (1002, expr.Location, "Expecting `;'");
6873 expr.Error_InvalidExpressionStatement (report);
6877 void Error_ParameterModifierNotValid (string modifier, Location loc)
6879 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6883 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6885 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6886 Parameter.GetModifierSignature (mod));
6889 void Error_TypeExpected (Location loc)
6891 report.Error (1031, loc, "Type expected");
6894 void Error_UnsafeCodeNotAllowed (Location loc)
6896 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6899 void Warning_EmptyStatement (Location loc)
6901 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6904 void Error_NamedArgumentExpected (NamedArgument a)
6906 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6909 void Error_MissingInitializer (Location loc)
6911 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6914 object Error_AwaitAsIdentifier (object token)
6917 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6918 return new LocatedToken ("await", GetLocation (token));
6924 void push_current_container (TypeDefinition tc, object partial_token)
6926 if (module.Evaluator != null){
6927 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6931 undo.AddTypeContainer (current_container, tc);
6934 if (partial_token != null)
6935 current_container.AddPartial (tc);
6937 current_container.AddTypeContainer (tc);
6939 ++lexer.parsing_declaration;
6940 current_container = tc;
6944 TypeContainer pop_current_class ()
6946 var retval = current_container;
6948 current_container = current_container.Parent;
6949 current_type = current_type.Parent as TypeDefinition;
6954 [System.Diagnostics.Conditional ("FULL_AST")]
6955 void StoreModifierLocation (object token, Location loc)
6960 if (mod_locations == null)
6961 mod_locations = new List<Tuple<Modifiers, Location>> ();
6963 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6966 [System.Diagnostics.Conditional ("FULL_AST")]
6967 void PushLocation (Location loc)
6969 if (location_stack == null)
6970 location_stack = new Stack<Location> ();
6972 location_stack.Push (loc);
6975 Location PopLocation ()
6977 if (location_stack == null)
6978 return Location.Null;
6980 return location_stack.Pop ();
6983 string CheckAttributeTarget (int token, string a, Location l)
6986 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6990 if (!Tokenizer.IsValidIdentifier (a)) {
6991 Error_SyntaxError (token);
6993 report.Warning (658, 1, l,
6994 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6997 return string.Empty;
7000 static bool IsUnaryOperator (Operator.OpType op)
7004 case Operator.OpType.LogicalNot:
7005 case Operator.OpType.OnesComplement:
7006 case Operator.OpType.Increment:
7007 case Operator.OpType.Decrement:
7008 case Operator.OpType.True:
7009 case Operator.OpType.False:
7010 case Operator.OpType.UnaryPlus:
7011 case Operator.OpType.UnaryNegation:
7017 void syntax_error (Location l, string msg)
7019 report.Error (1003, l, "Syntax error, " + msg);
7024 public Tokenizer Lexer {
7030 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7031 : this (reader, file, file.Compiler.Report, session)
7035 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7038 current_container = current_namespace = file;
7040 this.module = file.Module;
7041 this.compiler = file.Compiler;
7042 this.settings = compiler.Settings;
7043 this.report = report;
7045 lang_version = settings.Version;
7046 yacc_verbose_flag = settings.VerboseParserFlag;
7047 doc_support = settings.DocumentationFile != null;
7048 lexer = new Tokenizer (reader, file, session, report);
7049 oob_stack = new Stack<object> ();
7050 lbag = session.LocationsBag;
7051 use_global_stacks = session.UseJayGlobalArrays;
7052 parameters_bucket = session.ParametersStack;
7055 public void parse ()
7057 eof_token = Token.EOF;
7060 if (yacc_verbose_flag > 1)
7061 yyparse (lexer, new yydebug.yyDebugSimple ());
7065 Tokenizer tokenizer = lexer as Tokenizer;
7066 tokenizer.cleanup ();
7067 } catch (Exception e){
7068 if (e is yyParser.yyUnexpectedEof) {
7069 Error_SyntaxError (yyToken);
7070 UnexpectedEOF = true;
7074 if (e is yyParser.yyException) {
7075 if (report.Errors == 0)
7076 report.Error (-25, lexer.Location, "Parsing error");
7078 // Used by compiler-tester to test internal errors
7079 if (yacc_verbose_flag > 0 || e is FatalException)
7082 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7087 void CheckToken (int error, int yyToken, string msg, Location loc)
7089 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7090 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7092 report.Error (error, loc, msg);
7095 string ConsumeStoredComment ()
7097 string s = tmpComment;
7099 Lexer.doc_state = XmlCommentState.Allowed;
7103 void FeatureIsNotAvailable (Location loc, string feature)
7105 report.FeatureIsNotAvailable (compiler, loc, feature);
7108 Location GetLocation (object obj)
7110 var lt = obj as LocatedToken;
7114 var mn = obj as MemberName;
7118 var expr = obj as Expression;
7120 return expr.Location;
7122 return lexer.Location;
7125 void start_block (Location loc)
7127 if (current_block == null) {
7128 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7129 parsing_anonymous_method = false;
7130 } else if (parsing_anonymous_method) {
7131 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7132 parsing_anonymous_method = false;
7134 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7139 end_block (Location loc)
7141 Block retval = current_block.Explicit;
7142 retval.SetEndLocation (loc);
7143 current_block = retval.Parent;
7147 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7149 oob_stack.Push (current_anonymous_method);
7150 oob_stack.Push (current_local_parameters);
7151 oob_stack.Push (current_variable);
7152 oob_stack.Push (async_block);
7154 current_local_parameters = parameters;
7156 if (lang_version <= LanguageVersion.ISO_2)
7157 FeatureIsNotAvailable (loc, "lambda expressions");
7159 current_anonymous_method = new LambdaExpression (loc);
7161 if (lang_version == LanguageVersion.ISO_1)
7162 FeatureIsNotAvailable (loc, "anonymous methods");
7164 current_anonymous_method = new AnonymousMethodExpression (loc);
7167 async_block = isAsync;
7168 // Force the next block to be created as a ToplevelBlock
7169 parsing_anonymous_method = true;
7173 * Completes the anonymous method processing, if lambda_expr is null, this
7174 * means that we have a Statement instead of an Expression embedded
7176 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7178 AnonymousMethodExpression retval;
7181 anon_block.IsAsync = true;
7183 current_anonymous_method.Block = anon_block;
7184 retval = current_anonymous_method;
7186 async_block = (bool) oob_stack.Pop ();
7187 current_variable = (BlockVariable) oob_stack.Pop ();
7188 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7189 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7194 void Error_SyntaxError (int token)
7196 Error_SyntaxError (0, token);
7199 void Error_SyntaxError (int error_code, int token)
7201 Error_SyntaxError (error_code, token, "Unexpected symbol");
7204 void Error_SyntaxError (int error_code, int token, string msg)
7206 Lexer.CompleteOnEOF = false;
7208 // An error message has been reported by tokenizer
7209 if (token == Token.ERROR)
7212 // Avoid duplicit error message after unterminated string literals
7213 if (token == Token.LITERAL && lexer.Location.Column == 0)
7216 string symbol = GetSymbolName (token);
7217 string expecting = GetExpecting ();
7218 var loc = lexer.Location - symbol.Length;
7220 if (error_code == 0) {
7221 if (expecting == "`identifier'") {
7222 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7223 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7228 expecting = "identifier";
7229 } else if (expecting == "`)'") {
7236 if (string.IsNullOrEmpty (expecting))
7237 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7239 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7242 string GetExpecting ()
7244 int [] tokens = yyExpectingTokens (yyExpectingState);
7245 var names = new List<string> (tokens.Length);
7246 bool has_type = false;
7247 bool has_identifier = false;
7248 for (int i = 0; i < tokens.Length; i++){
7249 int token = tokens [i];
7250 has_identifier |= token == Token.IDENTIFIER;
7252 string name = GetTokenName (token);
7253 if (name == "<internal>")
7256 has_type |= name == "type";
7257 if (names.Contains (name))
7264 // Too many tokens to enumerate
7266 if (names.Count > 8)
7269 if (has_type && has_identifier)
7270 names.Remove ("identifier");
7272 if (names.Count == 1)
7273 return "`" + GetTokenName (tokens [0]) + "'";
7275 StringBuilder sb = new StringBuilder ();
7277 int count = names.Count;
7278 for (int i = 0; i < count; i++){
7279 bool last = i + 1 == count;
7283 sb.Append (names [i]);
7284 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7286 return sb.ToString ();
7290 string GetSymbolName (int token)
7294 return ((Constant)lexer.Value).GetValue ().ToString ();
7295 case Token.IDENTIFIER:
7296 return ((LocatedToken)lexer.Value).Value;
7338 case Token.BITWISE_AND:
7340 case Token.BITWISE_OR:
7354 case Token.OP_SHIFT_LEFT:
7356 case Token.OP_SHIFT_RIGHT:
7376 case Token.OP_COALESCING:
7378 case Token.OP_MULT_ASSIGN:
7380 case Token.OP_DIV_ASSIGN:
7382 case Token.OP_MOD_ASSIGN:
7384 case Token.OP_ADD_ASSIGN:
7386 case Token.OP_SUB_ASSIGN:
7388 case Token.OP_SHIFT_LEFT_ASSIGN:
7390 case Token.OP_SHIFT_RIGHT_ASSIGN:
7392 case Token.OP_AND_ASSIGN:
7394 case Token.OP_XOR_ASSIGN:
7396 case Token.OP_OR_ASSIGN:
7400 return GetTokenName (token);
7403 static string GetTokenName (int token)
7406 case Token.ABSTRACT:
7428 case Token.CONTINUE:
7432 case Token.DELEGATE:
7442 case Token.EXPLICIT:
7445 case Token.EXTERN_ALIAS:
7461 case Token.IMPLICIT:
7465 case Token.INTERFACE:
7467 case Token.INTERNAL:
7473 case Token.NAMESPACE:
7479 case Token.OPERATOR:
7483 case Token.OVERRIDE:
7489 case Token.PROTECTED:
7493 case Token.READONLY:
7505 case Token.STACKALLOC:
7506 return "stackalloc";
7523 case Token.UNCHECKED:
7531 case Token.VOLATILE:
7539 case Token.REFVALUE:
7540 return "__refvalue";
7550 case Token.FROM_FIRST:
7568 case Token.ASCENDING:
7570 case Token.DESCENDING:
7571 return "descending";
7578 case Token.OPEN_BRACE:
7580 case Token.CLOSE_BRACE:
7582 case Token.OPEN_BRACKET:
7583 case Token.OPEN_BRACKET_EXPR:
7585 case Token.CLOSE_BRACKET:
7587 case Token.OPEN_PARENS_CAST:
7588 case Token.OPEN_PARENS_LAMBDA:
7589 case Token.OPEN_PARENS:
7591 case Token.CLOSE_PARENS:
7597 case Token.DEFAULT_COLON:
7601 case Token.SEMICOLON:
7612 case Token.BITWISE_AND:
7613 case Token.BITWISE_OR:
7620 case Token.OP_SHIFT_LEFT:
7621 case Token.OP_SHIFT_RIGHT:
7629 case Token.OP_COALESCING:
7630 case Token.OP_MULT_ASSIGN:
7631 case Token.OP_DIV_ASSIGN:
7632 case Token.OP_MOD_ASSIGN:
7633 case Token.OP_ADD_ASSIGN:
7634 case Token.OP_SUB_ASSIGN:
7635 case Token.OP_SHIFT_LEFT_ASSIGN:
7636 case Token.OP_SHIFT_RIGHT_ASSIGN:
7637 case Token.OP_AND_ASSIGN:
7638 case Token.OP_XOR_ASSIGN:
7639 case Token.OP_OR_ASSIGN:
7640 return "<operator>";
7662 case Token.OP_GENERICS_LT:
7663 case Token.GENERIC_DIMENSION:
7665 case Token.OP_GENERICS_GT:
7668 case Token.INTERR_NULLABLE:
7670 case Token.DOUBLE_COLON:
7674 case Token.IDENTIFIER:
7676 return "identifier";
7679 return "end-of-file";
7681 // All of these are internal.
7684 case Token.FIRST_KEYWORD:
7685 case Token.EVAL_COMPILATION_UNIT_PARSER:
7686 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7687 case Token.EVAL_STATEMENT_PARSER:
7688 case Token.LAST_KEYWORD:
7689 case Token.GENERATE_COMPLETION:
7690 case Token.COMPLETE_COMPLETION:
7691 return "<internal>";
7693 // A bit more robust.
7695 return yyNames [token];