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 (GetTokenName (yyToken), GetLocation ($1));
750 var lt = (LocatedToken) $1;
751 $$ = CheckAttributeTarget (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 // here will be evaluated after CLOSE_BLACE is consumed.
2606 Lexer.doc_state = XmlCommentState.Allowed;
2608 CLOSE_BRACE opt_semicolon
2611 current_container.DocComment = enumTypeComment;
2613 --lexer.parsing_declaration;
2616 // em.DocComment = ev.DocComment;
2618 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2619 $$ = pop_current_class ();
2627 var te = $2 as TypeExpression;
2628 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2629 Enum.Error_1008 (GetLocation ($2), report);
2635 Error_TypeExpected (GetLocation ($1));
2640 opt_enum_member_declarations
2642 | enum_member_declarations
2643 | enum_member_declarations COMMA
2645 lbag.AddLocation ($1, GetLocation ($2));
2649 enum_member_declarations
2650 : enum_member_declaration
2651 | enum_member_declarations COMMA enum_member_declaration
2653 lbag.AddLocation ($1, GetLocation ($2));
2658 enum_member_declaration
2659 : opt_attributes IDENTIFIER
2661 var lt = (LocatedToken) $2;
2662 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2663 ((Enum) current_type).AddEnumMember (em);
2666 em.DocComment = Lexer.consume_doc_comment ();
2667 Lexer.doc_state = XmlCommentState.Allowed;
2672 | opt_attributes IDENTIFIER
2674 ++lexer.parsing_block;
2676 tmpComment = Lexer.consume_doc_comment ();
2677 Lexer.doc_state = XmlCommentState.NotAllowed;
2680 ASSIGN constant_expression
2682 --lexer.parsing_block;
2684 var lt = (LocatedToken) $2;
2685 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2686 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2687 ((Enum) current_type).AddEnumMember (em);
2690 em.DocComment = ConsumeStoredComment ();
2694 | opt_attributes IDENTIFIER error
2696 Error_SyntaxError (yyToken);
2698 var lt = (LocatedToken) $2;
2699 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2700 ((Enum) current_type).AddEnumMember (em);
2703 em.DocComment = Lexer.consume_doc_comment ();
2704 Lexer.doc_state = XmlCommentState.Allowed;
2709 | attributes_without_members
2712 delegate_declaration
2716 member_type type_declaration_name
2719 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2721 opt_formal_parameter_list CLOSE_PARENS
2723 valid_param_mod = 0;
2725 ParametersCompiled p = (ParametersCompiled) $8;
2727 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2729 p.CheckParameters (del);
2731 current_container.AddTypeContainer (del);
2733 current_delegate = del;
2734 lexer.ConstraintsParsing = true;
2736 opt_type_parameter_constraints_clauses
2738 lexer.ConstraintsParsing = false;
2743 current_delegate.DocComment = Lexer.consume_doc_comment ();
2744 Lexer.doc_state = XmlCommentState.Allowed;
2748 current_delegate.SetConstraints ((List<Constraints>) $11);
2749 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2751 $$ = current_delegate;
2753 current_delegate = null;
2761 if (lang_version < LanguageVersion.ISO_2)
2762 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2764 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2768 namespace_or_type_expr
2770 | qualified_alias_member IDENTIFIER opt_type_argument_list
2772 var lt1 = (LocatedToken) $1;
2773 var lt2 = (LocatedToken) $2;
2775 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2776 lbag.AddLocation ($$, GetLocation ($2));
2782 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2784 var lt = (LocatedToken) $3;
2785 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2786 lbag.AddLocation ($$, GetLocation ($2));
2791 : IDENTIFIER opt_type_argument_list
2793 var lt = (LocatedToken) $1;
2794 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2799 // Generics arguments (any type, without attributes)
2801 opt_type_argument_list
2803 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2805 if (lang_version < LanguageVersion.ISO_2)
2806 FeatureIsNotAvailable (GetLocation ($1), "generics");
2810 | OP_GENERICS_LT error
2812 Error_TypeExpected (lexer.Location);
2813 $$ = new TypeArguments ();
2820 TypeArguments type_args = new TypeArguments ();
2821 type_args.Add ((FullNamedExpression) $1);
2824 | type_arguments COMMA type
2826 TypeArguments type_args = (TypeArguments) $1;
2827 type_args.Add ((FullNamedExpression) $3);
2833 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2835 type_declaration_name
2838 lexer.parsing_generic_declaration = true;
2840 opt_type_parameter_list
2842 lexer.parsing_generic_declaration = false;
2843 var lt = (LocatedToken) $1;
2844 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2848 member_declaration_name
2849 : method_declaration_name
2851 MemberName mn = (MemberName)$1;
2852 if (mn.TypeParameters != null)
2853 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2854 mn.GetSignatureForError ()));
2858 method_declaration_name
2859 : type_declaration_name
2860 | explicit_interface IDENTIFIER opt_type_parameter_list
2862 lexer.parsing_generic_declaration = false;
2863 var lt = (LocatedToken) $2;
2864 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2868 indexer_declaration_name
2871 lexer.parsing_generic_declaration = false;
2872 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2874 | explicit_interface THIS
2876 lexer.parsing_generic_declaration = false;
2877 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2882 : IDENTIFIER opt_type_argument_list DOT
2884 var lt = (LocatedToken) $1;
2885 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2886 lbag.AddLocation ($$, GetLocation ($3));
2888 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2890 var lt1 = (LocatedToken) $1;
2891 var lt2 = (LocatedToken) $2;
2893 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2894 lbag.AddLocation ($$, GetLocation ($4));
2896 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2898 var lt = (LocatedToken) $2;
2899 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2900 lbag.AddLocation ($$, GetLocation ($4));
2904 opt_type_parameter_list
2906 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2908 if (lang_version < LanguageVersion.ISO_2)
2909 FeatureIsNotAvailable (GetLocation ($1), "generics");
2912 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2919 var tparams = new TypeParameters ();
2920 tparams.Add ((TypeParameter)$1);
2923 | type_parameters COMMA type_parameter
2925 var tparams = (TypeParameters) $1;
2926 tparams.Add ((TypeParameter)$3);
2928 lbag.AddLocation ($3, GetLocation ($3));
2933 : opt_attributes opt_type_parameter_variance IDENTIFIER
2935 var lt = (LocatedToken)$3;
2936 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
2940 if (GetTokenName (yyToken) == "type")
2941 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2943 Error_SyntaxError (yyToken);
2945 $$ = new TypeParameter (MemberName.Null, null, null);
2950 // All types where void is allowed
2953 : type_expression_or_array
2956 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2963 lexer.parsing_generic_declaration = true;
2968 // A type which does not allow `void' to be used
2971 : type_expression_or_array
2974 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2975 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2983 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2984 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2989 : type_expression_or_array
2992 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2993 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2997 type_expression_or_array
2999 | type_expression rank_specifiers
3001 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3006 : namespace_or_type_expr opt_nullable
3009 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3011 var sn = $1 as SimpleName;
3012 if (sn != null && sn.Name == "var")
3013 $$ = new VarExpr (sn.Location);
3018 | namespace_or_type_expr pointer_stars
3020 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3022 | builtin_types opt_nullable
3025 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3027 | builtin_types pointer_stars
3029 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3031 | VOID pointer_stars
3033 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3040 var types = new List<FullNamedExpression> (2);
3041 types.Add ((FullNamedExpression) $1);
3044 | type_list COMMA base_type_name
3046 var types = (List<FullNamedExpression>) $1;
3047 types.Add ((FullNamedExpression) $3);
3055 if ($1 is ComposedCast) {
3056 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3063 * replaces all the productions for isolating the various
3064 * simple types, but we need this to reuse it easily in variable_type
3067 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3068 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3069 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3070 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3071 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3072 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3077 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3078 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3079 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3080 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3081 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3082 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3083 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3084 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3085 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3089 // Expressions, section 7.5
3094 : primary_expression_or_type
3096 | array_creation_expression
3097 | parenthesized_expression
3098 | default_value_expression
3099 | invocation_expression
3103 | post_increment_expression
3104 | post_decrement_expression
3105 | object_or_delegate_creation_expression
3106 | anonymous_type_expression
3109 | checked_expression
3110 | unchecked_expression
3111 | pointer_member_access
3112 | anonymous_method_expression
3113 | undocumented_expressions
3116 primary_expression_or_type
3117 : IDENTIFIER opt_type_argument_list
3119 var lt = (LocatedToken) $1;
3120 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3122 | IDENTIFIER GENERATE_COMPLETION {
3123 var lt = (LocatedToken) $1;
3124 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3132 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3136 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3137 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3142 // Here is the trick, tokenizer may think that parens is a special but
3143 // parser is interested in open parens only, so we merge them.
3144 // Consider: if (a)foo ();
3152 // Use this production to accept closing parenthesis or
3153 // performing completion
3157 | COMPLETE_COMPLETION
3161 parenthesized_expression
3162 : OPEN_PARENS expression CLOSE_PARENS
3164 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3165 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3167 | OPEN_PARENS expression COMPLETE_COMPLETION
3169 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3174 : primary_expression DOT identifier_inside_body opt_type_argument_list
3176 var lt = (LocatedToken) $3;
3177 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3178 lbag.AddLocation ($$, GetLocation ($2));
3180 | builtin_types DOT identifier_inside_body opt_type_argument_list
3182 var lt = (LocatedToken) $3;
3183 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3184 lbag.AddLocation ($$, GetLocation ($2));
3186 | BASE DOT identifier_inside_body opt_type_argument_list
3188 var lt = (LocatedToken) $3;
3189 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3190 lbag.AddLocation ($$, GetLocation ($2));
3192 | qualified_alias_member identifier_inside_body opt_type_argument_list
3194 var lt1 = (LocatedToken) $1;
3195 var lt2 = (LocatedToken) $2;
3197 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3198 lbag.AddLocation ($$, GetLocation ($2));
3200 | primary_expression DOT GENERATE_COMPLETION {
3201 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3203 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3204 var lt = (LocatedToken) $3;
3205 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3207 | builtin_types DOT GENERATE_COMPLETION
3209 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3211 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3212 var lt = (LocatedToken) $3;
3213 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3217 invocation_expression
3218 : primary_expression open_parens_any opt_argument_list close_parens
3220 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3221 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3223 | primary_expression open_parens_any argument_list error
3225 Error_SyntaxError (yyToken);
3227 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3228 lbag.AddLocation ($$, GetLocation ($2));
3230 | primary_expression open_parens_any error
3232 Error_SyntaxError (yyToken);
3234 $$ = new Invocation ((Expression) $1, null);
3235 lbag.AddLocation ($$, GetLocation ($2));
3239 opt_object_or_collection_initializer
3240 : /* empty */ { $$ = null; }
3241 | object_or_collection_initializer
3244 object_or_collection_initializer
3245 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3248 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3250 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3252 lbag.AddLocation ($$, GetLocation ($3));
3254 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3256 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3257 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3261 opt_member_initializer_list
3262 : /* empty */ { $$ = null; }
3263 | member_initializer_list
3269 member_initializer_list
3270 : member_initializer
3272 var a = new List<Expression> ();
3273 a.Add ((Expression) $1);
3276 | member_initializer_list COMMA member_initializer
3278 var a = (List<Expression>)$1;
3279 a.Add ((Expression) $3);
3282 | member_initializer_list error {
3283 Error_SyntaxError (yyToken);
3289 : IDENTIFIER ASSIGN initializer_value
3291 var lt = (LocatedToken) $1;
3292 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3293 lbag.AddLocation ($$, GetLocation ($2));
3295 | AWAIT ASSIGN initializer_value
3297 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3298 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3299 lbag.AddLocation ($$, GetLocation ($2));
3301 | GENERATE_COMPLETION
3303 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3305 | non_assignment_expression opt_COMPLETE_COMPLETION {
3306 CompletionSimpleName csn = $1 as CompletionSimpleName;
3308 $$ = new CollectionElementInitializer ((Expression)$1);
3310 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3312 | OPEN_BRACE expression_list CLOSE_BRACE
3315 $$ = new CollectionElementInitializer (GetLocation ($1));
3317 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3319 lbag.AddLocation ($$, GetLocation ($2));
3321 | OPEN_BRACE CLOSE_BRACE
3323 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3324 $$ = new CollectionElementInitializer (GetLocation ($1));
3325 lbag.AddLocation ($$, GetLocation ($2));
3331 | object_or_collection_initializer
3335 : /* empty */ { $$ = null; }
3340 : argument_or_named_argument
3342 Arguments list = new Arguments (4);
3343 list.Add ((Argument) $1);
3346 | argument_list COMMA argument
3348 Arguments list = (Arguments) $1;
3349 if (list [list.Count - 1] is NamedArgument)
3350 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3352 list.Add ((Argument) $3);
3355 | argument_list COMMA named_argument
3357 Arguments list = (Arguments) $1;
3358 NamedArgument a = (NamedArgument) $3;
3359 for (int i = 0; i < list.Count; ++i) {
3360 NamedArgument na = list [i] as NamedArgument;
3361 if (na != null && na.Name == a.Name)
3362 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3369 | argument_list COMMA error
3371 if (lexer.putback_char == -1)
3372 lexer.putback (')'); // TODO: Wrong but what can I do
3373 Error_SyntaxError (yyToken);
3378 report.Error (839, GetLocation ($1), "An argument is missing");
3386 $$ = new Argument ((Expression) $1);
3388 | non_simple_argument
3391 argument_or_named_argument
3397 : REF variable_reference
3399 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3400 lbag.AddLocation ($$, GetLocation ($1));
3402 | OUT variable_reference
3404 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3405 lbag.AddLocation ($$, GetLocation ($1));
3407 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3409 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3410 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3412 | ARGLIST OPEN_PARENS CLOSE_PARENS
3414 $$ = new Argument (new Arglist (GetLocation ($1)));
3415 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3424 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3426 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3427 lbag.AddLocation ($$, GetLocation ($4));
3429 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3431 Error_SyntaxError (yyToken);
3432 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3434 | primary_expression OPEN_BRACKET_EXPR error
3436 Error_SyntaxError (yyToken);
3437 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3442 : expression_or_error
3444 var list = new List<Expression> (4);
3445 list.Add ((Expression) $1);
3448 | expression_list COMMA expression_or_error
3450 var list = (List<Expression>) $1;
3451 list.Add ((Expression) $3);
3456 expression_list_arguments
3457 : expression_list_argument
3459 Arguments args = new Arguments (4);
3460 args.Add ((Argument) $1);
3463 | expression_list_arguments COMMA expression_list_argument
3465 Arguments args = (Arguments) $1;
3466 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3467 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3469 args.Add ((Argument) $3);
3474 expression_list_argument
3477 $$ = new Argument ((Expression) $1);
3485 $$ = new This (GetLocation ($1));
3490 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3492 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3493 lbag.AddLocation ($$, GetLocation ($4));
3495 | BASE OPEN_BRACKET error
3497 Error_SyntaxError (yyToken);
3498 $$ = new ElementAccess (null, null, GetLocation ($2));
3502 post_increment_expression
3503 : primary_expression OP_INC
3505 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3509 post_decrement_expression
3510 : primary_expression OP_DEC
3512 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3516 object_or_delegate_creation_expression
3517 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3520 if (lang_version <= LanguageVersion.ISO_2)
3521 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3523 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3525 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3528 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3530 | NEW new_expr_type object_or_collection_initializer
3532 if (lang_version <= LanguageVersion.ISO_2)
3533 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3535 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3539 array_creation_expression
3540 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3542 opt_array_initializer
3544 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3545 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3546 Next = (ComposedTypeSpecifier) $6
3547 }, (ArrayInitializer) $7, GetLocation ($1));
3548 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3550 | NEW new_expr_type rank_specifiers opt_array_initializer
3553 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3555 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3557 | NEW rank_specifier array_initializer
3559 if (lang_version <= LanguageVersion.ISO_2)
3560 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3562 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3564 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3566 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3567 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3569 | NEW new_expr_type error
3571 Error_SyntaxError (yyToken);
3572 // It can be any of new expression, create the most common one
3573 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3579 ++lexer.parsing_type;
3583 --lexer.parsing_type;
3588 anonymous_type_expression
3589 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3591 if (lang_version <= LanguageVersion.ISO_2)
3592 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3594 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3596 // TODO: lbag comma location
3597 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3601 anonymous_type_parameters_opt_comma
3602 : anonymous_type_parameters_opt
3603 | anonymous_type_parameters COMMA
3606 anonymous_type_parameters_opt
3608 | anonymous_type_parameters
3611 anonymous_type_parameters
3612 : anonymous_type_parameter
3614 var a = new List<AnonymousTypeParameter> (4);
3615 a.Add ((AnonymousTypeParameter) $1);
3618 | anonymous_type_parameters COMMA anonymous_type_parameter
3620 var a = (List<AnonymousTypeParameter>) $1;
3621 a.Add ((AnonymousTypeParameter) $3);
3626 anonymous_type_parameter
3627 : identifier_inside_body ASSIGN variable_initializer
3629 var lt = (LocatedToken)$1;
3630 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3631 lbag.AddLocation ($$, GetLocation ($2));
3633 | identifier_inside_body
3635 var lt = (LocatedToken)$1;
3636 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3637 lt.Value, lt.Location);
3641 MemberAccess ma = (MemberAccess) $1;
3642 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3646 report.Error (746, lexer.Location,
3647 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3659 | rank_specifier rank_specifiers
3661 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3667 : OPEN_BRACKET CLOSE_BRACKET
3669 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3670 lbag.AddLocation ($$, GetLocation ($2));
3672 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3674 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3675 lbag.AddLocation ($$, GetLocation ($3));
3684 | dim_separators COMMA
3686 $$ = ((int) $1) + 1;
3690 opt_array_initializer
3702 : OPEN_BRACE CLOSE_BRACE
3704 var ai = new ArrayInitializer (0, GetLocation ($1));
3705 ai.VariableDeclaration = current_variable;
3706 lbag.AddLocation (ai, GetLocation ($2));
3709 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3711 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3712 ai.VariableDeclaration = current_variable;
3714 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3716 lbag.AddLocation (ai, GetLocation ($4));
3722 variable_initializer_list
3723 : variable_initializer
3725 var list = new List<Expression> (4);
3726 list.Add ((Expression) $1);
3729 | variable_initializer_list COMMA variable_initializer
3731 var list = (List<Expression>) $1;
3732 list.Add ((Expression) $3);
3740 lexer.TypeOfParsing = true;
3742 open_parens_any typeof_type_expression CLOSE_PARENS
3744 lexer.TypeOfParsing = false;
3745 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3746 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3750 typeof_type_expression
3755 Error_TypeExpected (lexer.Location);
3761 : identifier_inside_body generic_dimension
3763 var lt = (LocatedToken) $1;
3765 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3767 | qualified_alias_member identifier_inside_body generic_dimension
3769 var lt1 = (LocatedToken) $1;
3770 var lt2 = (LocatedToken) $2;
3772 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3773 lbag.AddLocation ($$, GetLocation ($2));
3775 | unbound_type_name DOT identifier_inside_body
3777 var lt = (LocatedToken) $3;
3779 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3781 | unbound_type_name DOT identifier_inside_body generic_dimension
3783 var lt = (LocatedToken) $3;
3785 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3787 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3789 var tne = (ATypeNameExpression) $1;
3790 if (tne.HasTypeArguments)
3791 Error_TypeExpected (GetLocation ($4));
3793 var lt = (LocatedToken) $3;
3794 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3801 if (lang_version < LanguageVersion.ISO_2)
3802 FeatureIsNotAvailable (GetLocation ($1), "generics");
3808 qualified_alias_member
3809 : IDENTIFIER DOUBLE_COLON
3811 var lt = (LocatedToken) $1;
3812 if (lang_version == LanguageVersion.ISO_1)
3813 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3820 : SIZEOF open_parens_any type CLOSE_PARENS
3822 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3823 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3825 | SIZEOF open_parens_any type error
3827 Error_SyntaxError (yyToken);
3829 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3830 lbag.AddLocation ($$, GetLocation ($2));
3835 : CHECKED open_parens_any expression CLOSE_PARENS
3837 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3838 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3842 Error_SyntaxError (yyToken);
3844 $$ = new CheckedExpr (null, GetLocation ($1));
3848 unchecked_expression
3849 : UNCHECKED open_parens_any expression CLOSE_PARENS
3851 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3852 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3856 Error_SyntaxError (yyToken);
3858 $$ = new UnCheckedExpr (null, GetLocation ($1));
3862 pointer_member_access
3863 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3865 var lt = (LocatedToken) $3;
3866 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3870 anonymous_method_expression
3871 : DELEGATE opt_anonymous_method_signature
3873 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3877 $$ = end_anonymous ((ParametersBlock) $4);
3879 | ASYNC DELEGATE opt_anonymous_method_signature
3881 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3885 $$ = end_anonymous ((ParametersBlock) $5);
3889 opt_anonymous_method_signature
3892 $$ = ParametersCompiled.Undefined;
3894 | anonymous_method_signature
3897 anonymous_method_signature
3900 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3902 opt_formal_parameter_list CLOSE_PARENS
3904 valid_param_mod = 0;
3909 default_value_expression
3910 : DEFAULT open_parens_any type CLOSE_PARENS
3912 if (lang_version < LanguageVersion.ISO_2)
3913 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3915 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3916 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3921 : primary_expression
3922 | BANG prefixed_unary_expression
3924 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3926 | TILDE prefixed_unary_expression
3928 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3930 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3932 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3933 lbag.AddLocation ($$, GetLocation ($3));
3935 | AWAIT prefixed_unary_expression
3938 if (current_anonymous_method is LambdaExpression) {
3939 report.Error (4034, GetLocation ($1),
3940 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3941 } else if (current_anonymous_method != null) {
3942 report.Error (4035, GetLocation ($1),
3943 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3944 } else if (interactive_async != null) {
3945 current_block.Explicit.RegisterAsyncAwait ();
3946 interactive_async = true;
3948 report.Error (4033, GetLocation ($1),
3949 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3952 current_block.Explicit.RegisterAsyncAwait ();
3955 $$ = new Await ((Expression) $2, GetLocation ($1));
3959 Error_SyntaxError (yyToken);
3961 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3965 Error_SyntaxError (yyToken);
3967 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3969 | OPEN_PARENS_CAST type CLOSE_PARENS error
3971 Error_SyntaxError (yyToken);
3973 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3974 lbag.AddLocation ($$, GetLocation ($3));
3978 Error_SyntaxError (yyToken);
3980 $$ = new Await (null, GetLocation ($1));
3985 // The idea to split this out is from Rhys' grammar
3986 // to solve the problem with casts.
3988 prefixed_unary_expression
3990 | PLUS prefixed_unary_expression
3992 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3994 | MINUS prefixed_unary_expression
3996 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3998 | OP_INC prefixed_unary_expression
4000 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4002 | OP_DEC prefixed_unary_expression
4004 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4006 | STAR prefixed_unary_expression
4008 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4010 | BITWISE_AND prefixed_unary_expression
4012 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4016 Error_SyntaxError (yyToken);
4018 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4022 Error_SyntaxError (yyToken);
4024 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4028 Error_SyntaxError (yyToken);
4030 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4034 Error_SyntaxError (yyToken);
4036 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4040 Error_SyntaxError (yyToken);
4042 $$ = new Indirection (null, GetLocation ($1));
4046 Error_SyntaxError (yyToken);
4048 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4052 multiplicative_expression
4053 : prefixed_unary_expression
4054 | multiplicative_expression STAR prefixed_unary_expression
4056 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4057 lbag.AddLocation ($$, GetLocation ($2));
4059 | multiplicative_expression DIV prefixed_unary_expression
4061 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4062 lbag.AddLocation ($$, GetLocation ($2));
4064 | multiplicative_expression PERCENT prefixed_unary_expression
4066 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4067 lbag.AddLocation ($$, GetLocation ($2));
4069 | multiplicative_expression STAR error
4071 Error_SyntaxError (yyToken);
4073 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4074 lbag.AddLocation ($$, GetLocation ($2));
4076 | multiplicative_expression DIV error
4078 Error_SyntaxError (yyToken);
4080 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4081 lbag.AddLocation ($$, GetLocation ($2));
4083 | multiplicative_expression PERCENT error
4085 Error_SyntaxError (yyToken);
4087 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4088 lbag.AddLocation ($$, GetLocation ($2));
4093 : multiplicative_expression
4094 | additive_expression PLUS multiplicative_expression
4096 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4097 lbag.AddLocation ($$, GetLocation ($2));
4099 | additive_expression MINUS multiplicative_expression
4101 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4102 lbag.AddLocation ($$, GetLocation ($2));
4104 | additive_expression AS type
4106 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4108 | additive_expression IS type
4110 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4112 | additive_expression PLUS error
4114 Error_SyntaxError (yyToken);
4116 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4117 lbag.AddLocation ($$, GetLocation ($2));
4119 | additive_expression MINUS error
4121 Error_SyntaxError (yyToken);
4123 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4124 lbag.AddLocation ($$, GetLocation ($2));
4126 | additive_expression AS error
4128 Error_SyntaxError (yyToken);
4130 $$ = new As ((Expression) $1, null, GetLocation ($2));
4132 | additive_expression IS error
4134 Error_SyntaxError (yyToken);
4136 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4141 : additive_expression
4142 | shift_expression OP_SHIFT_LEFT additive_expression
4144 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4145 lbag.AddLocation ($$, GetLocation ($2));
4147 | shift_expression OP_SHIFT_RIGHT additive_expression
4149 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4150 lbag.AddLocation ($$, GetLocation ($2));
4152 | shift_expression OP_SHIFT_LEFT error
4154 Error_SyntaxError (yyToken);
4156 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4157 lbag.AddLocation ($$, GetLocation ($2));
4159 | shift_expression OP_SHIFT_RIGHT error
4161 Error_SyntaxError (yyToken);
4163 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4164 lbag.AddLocation ($$, GetLocation ($2));
4168 relational_expression
4170 | relational_expression OP_LT shift_expression
4172 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4173 lbag.AddLocation ($$, GetLocation ($2));
4175 | relational_expression OP_GT shift_expression
4177 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4178 lbag.AddLocation ($$, GetLocation ($2));
4180 | relational_expression OP_LE shift_expression
4182 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4183 lbag.AddLocation ($$, GetLocation ($2));
4185 | relational_expression OP_GE shift_expression
4187 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4188 lbag.AddLocation ($$, GetLocation ($2));
4190 | relational_expression OP_LT error
4192 Error_SyntaxError (yyToken);
4194 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4195 lbag.AddLocation ($$, GetLocation ($2));
4197 | relational_expression OP_GT error
4199 Error_SyntaxError (yyToken);
4201 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4202 lbag.AddLocation ($$, GetLocation ($2));
4204 | relational_expression OP_LE error
4206 Error_SyntaxError (yyToken);
4208 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4209 lbag.AddLocation ($$, GetLocation ($2));
4211 | relational_expression OP_GE error
4213 Error_SyntaxError (yyToken);
4215 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4216 lbag.AddLocation ($$, GetLocation ($2));
4221 : relational_expression
4222 | equality_expression OP_EQ relational_expression
4224 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4225 lbag.AddLocation ($$, GetLocation ($2));
4227 | equality_expression OP_NE relational_expression
4229 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4230 lbag.AddLocation ($$, GetLocation ($2));
4232 | equality_expression OP_EQ error
4234 Error_SyntaxError (yyToken);
4236 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4237 lbag.AddLocation ($$, GetLocation ($2));
4239 | equality_expression OP_NE error
4241 Error_SyntaxError (yyToken);
4243 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4244 lbag.AddLocation ($$, GetLocation ($2));
4249 : equality_expression
4250 | and_expression BITWISE_AND equality_expression
4252 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4253 lbag.AddLocation ($$, GetLocation ($2));
4255 | and_expression BITWISE_AND error
4257 Error_SyntaxError (yyToken);
4259 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4260 lbag.AddLocation ($$, GetLocation ($2));
4264 exclusive_or_expression
4266 | exclusive_or_expression CARRET and_expression
4268 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4269 lbag.AddLocation ($$, GetLocation ($2));
4271 | exclusive_or_expression CARRET error
4273 Error_SyntaxError (yyToken);
4275 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4276 lbag.AddLocation ($$, GetLocation ($2));
4280 inclusive_or_expression
4281 : exclusive_or_expression
4282 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4284 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4285 lbag.AddLocation ($$, GetLocation ($2));
4287 | inclusive_or_expression BITWISE_OR error
4289 Error_SyntaxError (yyToken);
4291 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4292 lbag.AddLocation ($$, GetLocation ($2));
4296 conditional_and_expression
4297 : inclusive_or_expression
4298 | conditional_and_expression OP_AND inclusive_or_expression
4300 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4301 lbag.AddLocation ($$, GetLocation ($2));
4303 | conditional_and_expression OP_AND error
4305 Error_SyntaxError (yyToken);
4307 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4308 lbag.AddLocation ($$, GetLocation ($2));
4312 conditional_or_expression
4313 : conditional_and_expression
4314 | conditional_or_expression OP_OR conditional_and_expression
4316 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4317 lbag.AddLocation ($$, GetLocation ($2));
4319 | conditional_or_expression OP_OR error
4321 Error_SyntaxError (yyToken);
4323 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4324 lbag.AddLocation ($$, GetLocation ($2));
4328 null_coalescing_expression
4329 : conditional_or_expression
4330 | conditional_or_expression OP_COALESCING null_coalescing_expression
4332 if (lang_version < LanguageVersion.ISO_2)
4333 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4335 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4336 lbag.AddLocation ($$, GetLocation ($2));
4340 conditional_expression
4341 : null_coalescing_expression
4342 | null_coalescing_expression INTERR expression COLON expression
4344 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4345 lbag.AddLocation ($$, GetLocation ($4));
4347 | null_coalescing_expression INTERR expression error
4349 Error_SyntaxError (yyToken);
4351 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4353 | null_coalescing_expression INTERR expression COLON error
4355 Error_SyntaxError (yyToken);
4357 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4358 lbag.AddLocation ($$, GetLocation ($4));
4360 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4362 Error_SyntaxError (Token.CLOSE_BRACE);
4364 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4365 lbag.AddLocation ($$, GetLocation ($4));
4366 lexer.putback ('}');
4370 assignment_expression
4371 : prefixed_unary_expression ASSIGN expression
4373 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4374 lbag.AddLocation ($$, GetLocation ($2));
4376 | prefixed_unary_expression OP_MULT_ASSIGN expression
4378 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4379 lbag.AddLocation ($$, GetLocation ($2));
4381 | prefixed_unary_expression OP_DIV_ASSIGN expression
4383 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4384 lbag.AddLocation ($$, GetLocation ($2));
4386 | prefixed_unary_expression OP_MOD_ASSIGN expression
4388 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4389 lbag.AddLocation ($$, GetLocation ($2));
4391 | prefixed_unary_expression OP_ADD_ASSIGN expression
4393 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4394 lbag.AddLocation ($$, GetLocation ($2));
4396 | prefixed_unary_expression OP_SUB_ASSIGN expression
4398 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4399 lbag.AddLocation ($$, GetLocation ($2));
4401 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4403 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4404 lbag.AddLocation ($$, GetLocation ($2));
4406 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4408 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4409 lbag.AddLocation ($$, GetLocation ($2));
4411 | prefixed_unary_expression OP_AND_ASSIGN expression
4413 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4414 lbag.AddLocation ($$, GetLocation ($2));
4416 | prefixed_unary_expression OP_OR_ASSIGN expression
4418 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4419 lbag.AddLocation ($$, GetLocation ($2));
4421 | prefixed_unary_expression OP_XOR_ASSIGN expression
4423 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4424 lbag.AddLocation ($$, GetLocation ($2));
4428 lambda_parameter_list
4431 var pars = new List<Parameter> (4);
4432 pars.Add ((Parameter) $1);
4436 | lambda_parameter_list COMMA lambda_parameter
4438 var pars = (List<Parameter>) $1;
4439 Parameter p = (Parameter)$3;
4440 if (pars[0].GetType () != p.GetType ()) {
4441 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4450 : parameter_modifier parameter_type identifier_inside_body
4452 var lt = (LocatedToken) $3;
4454 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4456 | parameter_type identifier_inside_body
4458 var lt = (LocatedToken) $2;
4460 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4464 var lt = (LocatedToken) $1;
4465 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4469 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4470 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4474 opt_lambda_parameter_list
4475 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4476 | lambda_parameter_list {
4477 var pars_list = (List<Parameter>) $1;
4478 $$ = new ParametersCompiled (pars_list.ToArray ());
4482 lambda_expression_body
4484 start_block (Location.Null);
4486 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4488 Block b = end_block (Location.Null);
4489 b.IsCompilerGenerated = true;
4490 b.AddStatement (new ContextualReturn ((Expression) $2));
4496 // Handles only cases like foo = x.FirstOrDefault (l => );
4497 // where we must restore current_variable
4498 Block b = end_block (Location.Null);
4499 b.IsCompilerGenerated = true;
4501 Error_SyntaxError (yyToken);
4510 Error_SyntaxError (yyToken);
4518 var lt = (LocatedToken) $1;
4519 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4520 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4522 lambda_expression_body
4524 $$ = end_anonymous ((ParametersBlock) $4);
4525 lbag.AddLocation ($$, GetLocation ($2));
4529 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4530 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4531 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4533 lambda_expression_body
4535 $$ = end_anonymous ((ParametersBlock) $4);
4536 lbag.AddLocation ($$, GetLocation ($2));
4538 | ASYNC identifier_inside_body ARROW
4540 var lt = (LocatedToken) $2;
4541 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4542 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4544 lambda_expression_body
4546 $$ = end_anonymous ((ParametersBlock) $5);
4547 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4549 | OPEN_PARENS_LAMBDA
4551 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4553 opt_lambda_parameter_list CLOSE_PARENS ARROW
4555 valid_param_mod = 0;
4556 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4558 lambda_expression_body
4560 $$ = end_anonymous ((ParametersBlock) $7);
4561 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4563 | ASYNC OPEN_PARENS_LAMBDA
4565 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4567 opt_lambda_parameter_list CLOSE_PARENS ARROW
4569 valid_param_mod = 0;
4570 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4572 lambda_expression_body
4574 $$ = end_anonymous ((ParametersBlock) $8);
4575 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4580 : assignment_expression
4581 | non_assignment_expression
4584 non_assignment_expression
4585 : conditional_expression
4590 $$ = new ArglistAccess (GetLocation ($1));
4594 undocumented_expressions
4595 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4597 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4598 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4600 | REFTYPE open_parens_any expression CLOSE_PARENS
4602 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4603 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4605 | MAKEREF open_parens_any expression CLOSE_PARENS
4607 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4608 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4619 $$ = new BooleanExpression ((Expression) $1);
4633 type_declaration_name
4635 lexer.ConstraintsParsing = true;
4637 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4638 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4639 FeatureIsNotAvailable (c.Location, "static classes");
4642 push_current_container (c, $3);
4645 opt_type_parameter_constraints_clauses
4647 lexer.ConstraintsParsing = false;
4650 current_container.SetConstraints ((List<Constraints>) $9);
4651 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4654 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4655 Lexer.doc_state = XmlCommentState.Allowed;
4658 lexer.parsing_modifiers = true;
4660 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4662 --lexer.parsing_declaration;
4664 Lexer.doc_state = XmlCommentState.Allowed;
4669 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4671 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4673 $$ = pop_current_class ();
4681 { $$ = $1; } // location
4687 mod_locations = null;
4689 lexer.parsing_modifiers = false;
4693 lexer.parsing_modifiers = false;
4699 | modifiers modifier
4701 var m1 = (Modifiers) $1;
4702 var m2 = (Modifiers) $2;
4704 if ((m1 & m2) != 0) {
4705 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4706 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4707 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4708 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4709 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4710 "More than one protection modifier specified");
4721 StoreModifierLocation ($$, GetLocation ($1));
4723 if (current_container.Kind == MemberKind.Namespace)
4724 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4728 $$ = Modifiers.PUBLIC;
4729 StoreModifierLocation ($$, GetLocation ($1));
4733 $$ = Modifiers.PROTECTED;
4734 StoreModifierLocation ($$, GetLocation ($1));
4738 $$ = Modifiers.INTERNAL;
4739 StoreModifierLocation ($$, GetLocation ($1));
4743 $$ = Modifiers.PRIVATE;
4744 StoreModifierLocation ($$, GetLocation ($1));
4748 $$ = Modifiers.ABSTRACT;
4749 StoreModifierLocation ($$, GetLocation ($1));
4753 $$ = Modifiers.SEALED;
4754 StoreModifierLocation ($$, GetLocation ($1));
4758 $$ = Modifiers.STATIC;
4759 StoreModifierLocation ($$, GetLocation ($1));
4763 $$ = Modifiers.READONLY;
4764 StoreModifierLocation ($$, GetLocation ($1));
4768 $$ = Modifiers.VIRTUAL;
4769 StoreModifierLocation ($$, GetLocation ($1));
4773 $$ = Modifiers.OVERRIDE;
4774 StoreModifierLocation ($$, GetLocation ($1));
4778 $$ = Modifiers.EXTERN;
4779 StoreModifierLocation ($$, GetLocation ($1));
4783 $$ = Modifiers.VOLATILE;
4784 StoreModifierLocation ($$, GetLocation ($1));
4788 $$ = Modifiers.UNSAFE;
4789 StoreModifierLocation ($$, GetLocation ($1));
4790 if (!settings.Unsafe)
4791 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4795 $$ = Modifiers.ASYNC;
4796 StoreModifierLocation ($$, GetLocation ($1));
4804 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4806 | COLON type_list error
4808 Error_SyntaxError (yyToken);
4810 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4814 opt_type_parameter_constraints_clauses
4816 | type_parameter_constraints_clauses
4822 type_parameter_constraints_clauses
4823 : type_parameter_constraints_clause
4825 var constraints = new List<Constraints> (1);
4826 constraints.Add ((Constraints) $1);
4829 | type_parameter_constraints_clauses type_parameter_constraints_clause
4831 var constraints = (List<Constraints>) $1;
4832 Constraints new_constraint = (Constraints)$2;
4834 foreach (Constraints c in constraints) {
4835 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4836 report.Error (409, new_constraint.Location,
4837 "A constraint clause has already been specified for type parameter `{0}'",
4838 new_constraint.TypeParameter.Value);
4842 constraints.Add (new_constraint);
4847 type_parameter_constraints_clause
4848 : WHERE IDENTIFIER COLON type_parameter_constraints
4850 var lt = (LocatedToken) $2;
4851 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4852 lbag.AddLocation ($$, GetLocation ($3));
4854 | WHERE IDENTIFIER error
4856 Error_SyntaxError (yyToken);
4858 var lt = (LocatedToken) $2;
4859 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4863 type_parameter_constraints
4864 : type_parameter_constraint
4866 var constraints = new List<FullNamedExpression> (1);
4867 constraints.Add ((FullNamedExpression) $1);
4870 | type_parameter_constraints COMMA type_parameter_constraint
4872 var constraints = (List<FullNamedExpression>) $1;
4873 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4874 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4875 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4878 prev = $3 as SpecialContraintExpr;
4880 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4881 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4883 prev = constraints [0] as SpecialContraintExpr;
4884 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4885 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4890 constraints.Add ((FullNamedExpression) $3);
4895 type_parameter_constraint
4898 if ($1 is ComposedCast)
4899 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4903 | NEW OPEN_PARENS CLOSE_PARENS
4905 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4906 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4910 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4914 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4918 opt_type_parameter_variance
4923 | type_parameter_variance
4925 if (lang_version <= LanguageVersion.V_3)
4926 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4932 type_parameter_variance
4935 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
4939 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
4948 // A block is "contained" on the following places:
4950 // property_declaration as part of the accessor body (get/set)
4951 // operator_declaration
4952 // constructor_declaration
4953 // destructor_declaration
4954 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4959 ++lexer.parsing_block;
4960 start_block (GetLocation ($1));
4962 opt_statement_list block_end
4971 --lexer.parsing_block;
4972 $$ = end_block (GetLocation ($1));
4974 | COMPLETE_COMPLETION
4976 --lexer.parsing_block;
4977 $$ = end_block (lexer.Location);
4985 ++lexer.parsing_block;
4986 current_block.StartLocation = GetLocation ($1);
4988 opt_statement_list CLOSE_BRACE
4990 --lexer.parsing_block;
4991 $$ = end_block (GetLocation ($4));
5002 | statement_list statement
5006 : block_variable_declaration
5008 current_block.AddStatement ((Statement) $1);
5010 | valid_declaration_statement
5012 current_block.AddStatement ((Statement) $1);
5017 Error_SyntaxError (yyToken);
5023 // The interactive_statement and its derivatives are only
5024 // used to provide a special version of `expression_statement'
5025 // that has a side effect of assigning the expression to
5028 interactive_statement_list
5029 : interactive_statement
5030 | interactive_statement_list interactive_statement
5033 interactive_statement
5034 : block_variable_declaration
5036 current_block.AddStatement ((Statement) $1);
5038 | interactive_valid_declaration_statement
5040 current_block.AddStatement ((Statement) $1);
5045 valid_declaration_statement
5048 | expression_statement
5049 | selection_statement
5050 | iteration_statement
5054 | unchecked_statement
5061 interactive_valid_declaration_statement
5064 | interactive_expression_statement
5065 | selection_statement
5066 | iteration_statement
5070 | unchecked_statement
5078 : valid_declaration_statement
5079 | block_variable_declaration
5081 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5086 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5091 Error_SyntaxError (yyToken);
5092 $$ = new EmptyStatement (GetLocation ($1));
5099 // Uses lexer.Location because semicolon location is not kept in quick mode
5100 $$ = new EmptyStatement (lexer.Location);
5105 : identifier_inside_body COLON
5107 var lt = (LocatedToken) $1;
5108 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5109 lbag.AddLocation (labeled, GetLocation ($2));
5110 current_block.AddLabel (labeled);
5111 current_block.AddStatement (labeled);
5117 : variable_type_simple
5118 | variable_type_simple rank_specifiers
5121 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5123 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5128 * The following is from Rhys' grammar:
5129 * > Types in local variable declarations must be recognized as
5130 * > expressions to prevent reduce/reduce errors in the grammar.
5131 * > The expressions are converted into types during semantic analysis.
5133 variable_type_simple
5134 : primary_expression_or_type opt_nullable
5136 // Ok, the above "primary_expression" is there to get rid of
5137 // both reduce/reduce and shift/reduces in the grammar, it should
5138 // really just be "type_name". If you use type_name, a reduce/reduce
5139 // creeps up. If you use namespace_or_type_name (which is all we need
5140 // really) two shift/reduces appear.
5143 // So the super-trick is that primary_expression
5144 // can only be either a SimpleName or a MemberAccess.
5145 // The MemberAccess case arises when you have a fully qualified type-name like :
5147 // SimpleName is when you have
5150 Expression expr = (Expression) $1;
5152 SimpleName sn = expr as SimpleName;
5153 if (sn != null && sn.Name == "var")
5154 $$ = new VarExpr (sn.Location);
5157 } else if (expr is ATypeNameExpression) {
5158 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5160 Error_ExpectingTypeName (expr);
5164 | primary_expression_or_type pointer_stars
5166 ATypeNameExpression expr = $1 as ATypeNameExpression;
5169 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5171 Error_ExpectingTypeName ((Expression)$1);
5175 | builtin_types opt_nullable
5180 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5182 | builtin_types pointer_stars
5184 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5186 | VOID pointer_stars
5188 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5192 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5193 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5199 | pointer_star pointer_stars
5201 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5209 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5213 identifier_inside_body
5217 $$ = Error_AwaitAsIdentifier ($1);
5221 block_variable_declaration
5222 : variable_type identifier_inside_body
5224 var lt = (LocatedToken) $2;
5225 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5226 current_block.AddLocalName (li);
5227 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5229 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5231 $$ = current_variable;
5232 current_variable = null;
5234 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5236 lbag.AddLocation ($$, GetLocation ($6));
5238 | CONST variable_type identifier_inside_body
5240 var lt = (LocatedToken) $3;
5241 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5242 current_block.AddLocalName (li);
5243 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5245 const_variable_initializer opt_const_declarators SEMICOLON
5247 $$ = current_variable;
5248 current_variable = null;
5249 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5253 opt_local_variable_initializer
5255 | ASSIGN block_variable_initializer
5257 current_variable.Initializer = (Expression) $2;
5258 PushLocation (GetLocation ($1));
5259 $$ = current_variable;
5263 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5264 report.Error (650, lexer.Location,
5265 "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");
5267 Error_SyntaxError (yyToken);
5272 opt_variable_declarators
5274 | variable_declarators
5277 opt_using_or_fixed_variable_declarators
5279 | variable_declarators
5281 foreach (var d in current_variable.Declarators) {
5282 if (d.Initializer == null)
5283 Error_MissingInitializer (d.Variable.Location);
5288 variable_declarators
5289 : variable_declarator
5290 | variable_declarators variable_declarator
5294 : COMMA identifier_inside_body
5296 var lt = (LocatedToken) $2;
5297 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5298 var d = new BlockVariableDeclarator (li, null);
5299 current_variable.AddDeclarator (d);
5300 current_block.AddLocalName (li);
5301 lbag.AddLocation (d, GetLocation ($1));
5303 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5305 var lt = (LocatedToken) $2;
5306 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5307 var d = new BlockVariableDeclarator (li, (Expression) $4);
5308 current_variable.AddDeclarator (d);
5309 current_block.AddLocalName (li);
5310 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5314 const_variable_initializer
5317 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5319 | ASSIGN constant_initializer_expr
5321 current_variable.Initializer = (Expression) $2;
5325 opt_const_declarators
5332 | const_declarators const_declarator
5336 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5338 var lt = (LocatedToken) $2;
5339 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5340 var d = new BlockVariableDeclarator (li, (Expression) $4);
5341 current_variable.AddDeclarator (d);
5342 current_block.AddLocalName (li);
5343 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5347 block_variable_initializer
5348 : variable_initializer
5349 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5351 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5352 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5354 | STACKALLOC simple_type
5356 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5357 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5361 expression_statement
5362 : statement_expression SEMICOLON
5365 lbag.AddStatement ($$, GetLocation ($2));
5367 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5368 | statement_expression CLOSE_BRACE
5371 report.Error (1002, GetLocation ($2), "; expected");
5372 lexer.putback ('}');
5376 interactive_expression_statement
5377 : interactive_statement_expression SEMICOLON { $$ = $1; }
5378 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5382 // We have to do the wrapping here and not in the case above,
5383 // because statement_expression is used for example in for_statement
5385 statement_expression
5388 ExpressionStatement s = $1 as ExpressionStatement;
5390 var expr = $1 as Expression;
5391 $$ = new StatementErrorExpression (expr);
5393 $$ = new StatementExpression (s);
5398 interactive_statement_expression
5401 Expression expr = (Expression) $1;
5402 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5406 Error_SyntaxError (yyToken);
5407 $$ = new EmptyStatement (GetLocation ($1));
5417 : IF open_parens_any boolean_expression CLOSE_PARENS
5420 if ($5 is EmptyStatement)
5421 Warning_EmptyStatement (GetLocation ($5));
5423 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5424 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5426 | IF open_parens_any boolean_expression CLOSE_PARENS
5427 embedded_statement ELSE embedded_statement
5429 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5430 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5432 if ($5 is EmptyStatement)
5433 Warning_EmptyStatement (GetLocation ($5));
5434 if ($7 is EmptyStatement)
5435 Warning_EmptyStatement (GetLocation ($7));
5437 | IF open_parens_any boolean_expression error
5439 Error_SyntaxError (yyToken);
5441 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5442 lbag.AddStatement ($$, GetLocation ($2));
5447 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5449 start_block (GetLocation ($5));
5451 opt_switch_sections CLOSE_BRACE
5453 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5454 end_block (GetLocation ($8));
5455 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5457 | SWITCH open_parens_any expression error
5459 Error_SyntaxError (yyToken);
5461 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5462 lbag.AddStatement ($$, GetLocation ($2));
5469 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5476 | switch_sections switch_section
5479 Error_SyntaxError (yyToken);
5484 : switch_labels statement_list
5490 var label = (SwitchLabel) $1;
5491 label.SectionStart = true;
5492 current_block.AddStatement (label);
5494 | switch_labels switch_label
5496 current_block.AddStatement ((Statement) $2);
5501 : CASE constant_expression COLON
5503 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5504 lbag.AddLocation ($$, GetLocation ($3));
5506 | CASE constant_expression error
5508 Error_SyntaxError (yyToken);
5509 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5513 $$ = new SwitchLabel (null, GetLocation ($1));
5525 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5527 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5528 Warning_EmptyStatement (GetLocation ($5));
5530 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5531 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5533 | WHILE open_parens_any boolean_expression error
5535 Error_SyntaxError (yyToken);
5537 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5538 lbag.AddStatement ($$, GetLocation ($2));
5543 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5545 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5546 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5548 | DO embedded_statement error
5550 Error_SyntaxError (yyToken);
5551 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5553 | DO embedded_statement WHILE open_parens_any boolean_expression error
5555 Error_SyntaxError (yyToken);
5557 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5558 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5563 : FOR open_parens_any
5565 start_block (GetLocation ($2));
5566 current_block.IsCompilerGenerated = true;
5567 For f = new For (GetLocation ($1));
5568 current_block.AddStatement (f);
5577 // Has to use be extra rule to recover started block
5579 : opt_for_initializer SEMICOLON
5581 ((For) $0).Initializer = (Statement) $1;
5583 // Pass the "For" object to the iterator_part4
5584 oob_stack.Push ($0);
5586 for_condition_and_iterator_part
5589 var locations = (Tuple<Location,Location>) $4;
5591 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5592 Warning_EmptyStatement (GetLocation ($5));
5595 f.Statement = (Statement) $5;
5596 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5598 $$ = end_block (GetLocation ($2));
5602 Error_SyntaxError (yyToken);
5603 $$ = end_block (current_block.StartLocation);
5607 for_condition_and_iterator_part
5608 : opt_for_condition SEMICOLON
5610 For f = (For) oob_stack.Peek ();
5611 f.Condition = (BooleanExpression) $1;
5614 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5617 // Handle errors in the case of opt_for_condition being followed by
5618 // a close parenthesis
5619 | opt_for_condition close_parens_close_brace {
5620 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5621 For f = (For) oob_stack.Peek ();
5622 f.Condition = (BooleanExpression) $1;
5623 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5628 : opt_for_iterator CLOSE_PARENS {
5629 For f = (For) oob_stack.Peek ();
5630 f.Iterator = (Statement) $1;
5631 $$ = GetLocation ($2);
5633 | opt_for_iterator CLOSE_BRACE {
5634 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5635 For f = (For) oob_stack.Peek ();
5636 f.Iterator = (Statement) $1;
5637 $$ = GetLocation ($2);
5641 close_parens_close_brace
5643 | CLOSE_BRACE { lexer.putback ('}'); }
5647 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5652 : variable_type identifier_inside_body
5654 var lt = (LocatedToken) $2;
5655 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5656 current_block.AddLocalName (li);
5657 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5659 opt_local_variable_initializer opt_variable_declarators
5661 $$ = current_variable;
5663 lbag.AddLocation (current_variable, PopLocation ());
5665 current_variable = null;
5667 | statement_expression_list
5671 : /* empty */ { $$ = null; }
5672 | boolean_expression
5676 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5681 : statement_expression_list
5684 statement_expression_list
5685 : statement_expression
5686 | statement_expression_list COMMA statement_expression
5688 var sl = $1 as StatementList;
5690 sl = new StatementList ((Statement) $1, (Statement) $3);
5691 lbag.AddStatement (sl, GetLocation ($2));
5693 sl.Add ((Statement) $3);
5694 lbag.AppendTo (sl, GetLocation ($2));
5702 : FOREACH open_parens_any type error
5704 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5706 start_block (GetLocation ($2));
5707 current_block.IsCompilerGenerated = true;
5709 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5710 current_block.AddStatement (f);
5712 lbag.AddStatement (f, GetLocation ($2));
5713 $$ = end_block (GetLocation ($4));
5715 | FOREACH open_parens_any type identifier_inside_body error
5717 Error_SyntaxError (yyToken);
5719 start_block (GetLocation ($2));
5720 current_block.IsCompilerGenerated = true;
5722 var lt = (LocatedToken) $4;
5723 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5724 current_block.AddLocalName (li);
5726 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5727 current_block.AddStatement (f);
5729 lbag.AddStatement (f, GetLocation ($2));
5730 $$ = end_block (GetLocation ($5));
5732 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5734 start_block (GetLocation ($2));
5735 current_block.IsCompilerGenerated = true;
5737 var lt = (LocatedToken) $4;
5738 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5739 current_block.AddLocalName (li);
5744 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5745 Warning_EmptyStatement (GetLocation ($9));
5747 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5748 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5749 end_block (GetLocation ($7));
5757 | continue_statement
5767 $$ = new Break (GetLocation ($1));
5768 lbag.AddStatement ($$, GetLocation ($2));
5773 : CONTINUE SEMICOLON
5775 $$ = new Continue (GetLocation ($1));
5776 lbag.AddStatement ($$, GetLocation ($2));
5780 Error_SyntaxError (yyToken);
5781 $$ = new Continue (GetLocation ($1));
5786 : GOTO identifier_inside_body SEMICOLON
5788 var lt = (LocatedToken) $2;
5789 $$ = new Goto (lt.Value, GetLocation ($1));
5790 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5792 | GOTO CASE constant_expression SEMICOLON
5794 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5795 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5797 | GOTO DEFAULT SEMICOLON
5799 $$ = new GotoDefault (GetLocation ($1));
5800 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5805 : RETURN opt_expression SEMICOLON
5807 $$ = new Return ((Expression) $2, GetLocation ($1));
5808 lbag.AddStatement ($$, GetLocation ($3));
5810 | RETURN expression error
5812 Error_SyntaxError (yyToken);
5813 $$ = new Return ((Expression) $2, GetLocation ($1));
5817 Error_SyntaxError (yyToken);
5818 $$ = new Return (null, GetLocation ($1));
5823 : THROW opt_expression SEMICOLON
5825 $$ = new Throw ((Expression) $2, GetLocation ($1));
5826 lbag.AddStatement ($$, GetLocation ($3));
5828 | THROW expression error
5830 Error_SyntaxError (yyToken);
5831 $$ = new Throw ((Expression) $2, GetLocation ($1));
5835 Error_SyntaxError (yyToken);
5836 $$ = new Throw (null, GetLocation ($1));
5841 : identifier_inside_body RETURN opt_expression SEMICOLON
5843 var lt = (LocatedToken) $1;
5844 string s = lt.Value;
5846 report.Error (1003, lt.Location, "; expected");
5847 } else if ($3 == null) {
5848 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5849 } else if (lang_version == LanguageVersion.ISO_1){
5850 FeatureIsNotAvailable (lt.Location, "iterators");
5853 current_block.Explicit.RegisterIteratorYield ();
5854 $$ = new Yield ((Expression) $3, lt.Location);
5855 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5857 | identifier_inside_body RETURN expression error
5859 Error_SyntaxError (yyToken);
5861 var lt = (LocatedToken) $1;
5862 string s = lt.Value;
5864 report.Error (1003, lt.Location, "; expected");
5865 } else if ($3 == null) {
5866 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5867 } else if (lang_version == LanguageVersion.ISO_1){
5868 FeatureIsNotAvailable (lt.Location, "iterators");
5871 current_block.Explicit.RegisterIteratorYield ();
5872 $$ = new Yield ((Expression) $3, lt.Location);
5873 lbag.AddStatement ($$, GetLocation ($2));
5875 | identifier_inside_body BREAK SEMICOLON
5877 var lt = (LocatedToken) $1;
5878 string s = lt.Value;
5880 report.Error (1003, lt.Location, "; expected");
5881 } else if (lang_version == LanguageVersion.ISO_1){
5882 FeatureIsNotAvailable (lt.Location, "iterators");
5885 current_block.ParametersBlock.TopBlock.IsIterator = true;
5886 $$ = new YieldBreak (lt.Location);
5887 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5897 : TRY block catch_clauses
5899 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5901 | TRY block FINALLY block
5903 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
5904 lbag.AddStatement ($$, GetLocation ($3));
5906 | TRY block catch_clauses FINALLY block
5908 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
5909 lbag.AddStatement ($$, GetLocation ($4));
5913 Error_SyntaxError (1524, yyToken);
5914 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5921 var l = new List<Catch> (2);
5926 | catch_clauses catch_clause
5928 var l = (List<Catch>) $1;
5930 Catch c = (Catch) $2;
5931 if (l [l.Count - 1].IsGeneral) {
5932 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5942 | identifier_inside_body
5948 $$ = new Catch ((ExplicitBlock) $2, GetLocation ($1));
5950 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5952 start_block (GetLocation ($2));
5953 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
5954 c.TypeExpression = (FullNamedExpression) $3;
5957 var lt = (LocatedToken) $4;
5958 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5959 current_block.AddLocalName (c.Variable);
5962 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5969 | CATCH open_parens_any error
5971 if (yyToken == Token.CLOSE_PARENS) {
5972 report.Error (1015, lexer.Location,
5973 "A type that derives from `System.Exception', `object', or `string' expected");
5975 Error_SyntaxError (yyToken);
5978 $$ = new Catch (null, GetLocation ($1));
5980 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5982 Error_SyntaxError (yyToken);
5984 // Required otherwise missing block could not be detected because
5985 // start_block is run early
5986 var c = new Catch (null, GetLocation ($1));
5987 c.TypeExpression = (FullNamedExpression) $3;
5990 var lt = (LocatedToken) $4;
5991 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5994 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6003 $$ = new Checked ((Block) $2, GetLocation ($1));
6010 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6017 if (!settings.Unsafe)
6018 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6020 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6025 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6027 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6028 Warning_EmptyStatement (GetLocation ($5));
6030 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6031 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6033 | LOCK open_parens_any expression error
6035 Error_SyntaxError (yyToken);
6037 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6038 lbag.AddStatement ($$, GetLocation ($2));
6043 : FIXED open_parens_any variable_type identifier_inside_body
6045 start_block (GetLocation ($2));
6047 current_block.IsCompilerGenerated = true;
6048 var lt = (LocatedToken) $4;
6049 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6050 current_block.AddLocalName (li);
6051 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6053 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6055 $$ = current_variable;
6056 current_variable = null;
6060 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6061 Warning_EmptyStatement (GetLocation ($10));
6063 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6064 current_block.AddStatement (f);
6065 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6066 $$ = end_block (GetLocation ($8));
6071 : USING open_parens_any variable_type identifier_inside_body
6073 start_block (GetLocation ($2));
6075 current_block.IsCompilerGenerated = true;
6076 var lt = (LocatedToken) $4;
6077 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6078 current_block.AddLocalName (li);
6079 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6081 using_initialization CLOSE_PARENS
6083 $$ = current_variable;
6084 current_variable = null;
6088 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6089 Warning_EmptyStatement (GetLocation ($9));
6091 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6092 current_block.AddStatement (u);
6093 $$ = end_block (GetLocation ($7));
6095 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6097 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6098 Warning_EmptyStatement (GetLocation ($5));
6100 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6101 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6103 | USING open_parens_any expression error
6105 Error_SyntaxError (yyToken);
6107 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6108 lbag.AddStatement ($$, GetLocation ($2));
6112 using_initialization
6113 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6116 // It has to be here for the parent to safely restore artificial block
6117 Error_SyntaxError (yyToken);
6121 using_or_fixed_variable_initializer
6124 Error_MissingInitializer (lexer.Location);
6126 | ASSIGN variable_initializer
6128 current_variable.Initializer = (Expression) $2;
6129 $$ = current_variable;
6137 : first_from_clause query_body
6139 lexer.query_parsing = false;
6141 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6143 from.Tail.Next = (Linq.AQueryClause)$2;
6146 current_block.SetEndLocation (lexer.Location);
6147 current_block = current_block.Parent;
6149 | nested_from_clause query_body
6151 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6153 from.Tail.Next = (Linq.AQueryClause)$2;
6156 current_block.SetEndLocation (lexer.Location);
6157 current_block = current_block.Parent;
6160 // Bubble up COMPLETE_COMPLETION productions
6161 | first_from_clause COMPLETE_COMPLETION {
6162 lexer.query_parsing = false;
6165 current_block.SetEndLocation (lexer.Location);
6166 current_block = current_block.Parent;
6168 | nested_from_clause COMPLETE_COMPLETION {
6170 current_block.SetEndLocation (lexer.Location);
6171 current_block = current_block.Parent;
6176 : FROM_FIRST identifier_inside_body IN expression
6178 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6180 var lt = (LocatedToken) $2;
6181 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6182 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6183 lbag.AddLocation (clause, GetLocation ($3));
6184 $$ = new Linq.QueryExpression (clause);
6186 | FROM_FIRST type identifier_inside_body IN expression
6188 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6190 var lt = (LocatedToken) $3;
6191 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6192 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6193 IdentifierType = (FullNamedExpression)$2
6195 lbag.AddLocation (clause, GetLocation ($4));
6196 $$ = new Linq.QueryExpression (clause);
6201 : FROM identifier_inside_body IN expression
6203 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6205 var lt = (LocatedToken) $2;
6206 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6207 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6208 lbag.AddLocation (clause, GetLocation ($3));
6209 $$ = new Linq.QueryExpression (clause);
6211 | FROM type identifier_inside_body IN expression
6213 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6215 var lt = (LocatedToken) $3;
6216 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6217 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6218 IdentifierType = (FullNamedExpression)$2
6220 lbag.AddLocation (clause, GetLocation ($4));
6221 $$ = new Linq.QueryExpression (clause);
6226 : FROM identifier_inside_body IN
6228 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6232 var lt = (LocatedToken) $2;
6233 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6234 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6236 current_block.SetEndLocation (lexer.Location);
6237 current_block = current_block.Parent;
6239 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6240 lbag.AddLocation ($$, GetLocation ($3));
6242 | FROM type identifier_inside_body IN
6244 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6248 var lt = (LocatedToken) $3;
6249 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6251 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6252 IdentifierType = (FullNamedExpression)$2
6255 current_block.SetEndLocation (lexer.Location);
6256 current_block = current_block.Parent;
6258 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6260 lbag.AddLocation ($$, GetLocation ($4));
6265 : query_body_clauses select_or_group_clause opt_query_continuation
6267 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6270 head.Next = (Linq.AQueryClause)$3;
6273 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6274 clause.Tail.Next = head;
6280 | select_or_group_clause opt_query_continuation
6282 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6285 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6286 clause.Tail.Next = head;
6292 | query_body_clauses COMPLETE_COMPLETION
6293 | query_body_clauses error
6295 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6300 Error_SyntaxError (yyToken);
6305 select_or_group_clause
6308 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6312 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6314 current_block.SetEndLocation (lexer.Location);
6315 current_block = current_block.Parent;
6319 if (linq_clause_blocks == null)
6320 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6322 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6323 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6327 current_block.SetEndLocation (lexer.Location);
6328 current_block = current_block.Parent;
6330 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6334 var obj = (object[]) $5;
6336 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6337 lbag.AddLocation ($$, (Location) obj[1]);
6339 current_block.SetEndLocation (lexer.Location);
6340 current_block = current_block.Parent;
6345 : BY expression_or_error
6347 $$ = new object[] { $2, GetLocation ($1) };
6351 Error_SyntaxError (yyToken);
6352 $$ = new object[2] { null, Location.Null };
6358 | query_body_clauses query_body_clause
6360 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6374 : LET identifier_inside_body ASSIGN
6376 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6380 var lt = (LocatedToken) $2;
6381 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6382 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6383 lbag.AddLocation ($$, GetLocation ($3));
6385 current_block.SetEndLocation (lexer.Location);
6386 current_block = current_block.Parent;
6388 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6395 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6399 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6401 current_block.SetEndLocation (lexer.Location);
6402 current_block = current_block.Parent;
6407 : JOIN identifier_inside_body IN
6409 if (linq_clause_blocks == null)
6410 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6412 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6413 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6415 expression_or_error ON
6417 current_block.SetEndLocation (lexer.Location);
6418 current_block = current_block.Parent;
6420 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6421 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6423 expression_or_error EQUALS
6425 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6426 current_block.SetEndLocation (lexer.Location);
6427 current_block = current_block.Parent;
6429 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6431 expression_or_error opt_join_into
6433 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6434 current_block.SetEndLocation (lexer.Location);
6436 var outer_selector = linq_clause_blocks.Pop ();
6437 var block = linq_clause_blocks.Pop ();
6439 var lt = (LocatedToken) $2;
6440 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6441 Linq.RangeVariable into;
6445 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6446 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6449 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6451 var parent = block.Parent;
6452 while (parent is Linq.QueryBlock) {
6453 parent = parent.Parent;
6455 current_block.Parent = parent;
6457 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6459 lt = (LocatedToken) $12;
6460 into = new Linq.RangeVariable (lt.Value, lt.Location);
6462 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6463 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6466 current_block = block.Parent;
6467 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6469 | JOIN type identifier_inside_body IN
6471 if (linq_clause_blocks == null)
6472 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6474 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6475 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6477 expression_or_error ON
6479 current_block.SetEndLocation (lexer.Location);
6480 current_block = current_block.Parent;
6482 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6483 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6485 expression_or_error EQUALS
6487 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6488 current_block.SetEndLocation (lexer.Location);
6489 current_block = current_block.Parent;
6491 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6493 expression_or_error opt_join_into
6495 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6496 current_block.SetEndLocation (lexer.Location);
6498 var outer_selector = linq_clause_blocks.Pop ();
6499 var block = linq_clause_blocks.Pop ();
6501 var lt = (LocatedToken) $3;
6502 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6503 Linq.RangeVariable into;
6507 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6508 IdentifierType = (FullNamedExpression)$2
6510 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6513 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6515 var parent = block.Parent;
6516 while (parent is Linq.QueryBlock) {
6517 parent = parent.Parent;
6519 current_block.Parent = parent;
6521 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6523 lt = (LocatedToken) $13;
6524 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6526 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6527 IdentifierType = (FullNamedExpression)$2
6531 current_block = block.Parent;
6532 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6538 | INTO identifier_inside_body
6547 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6551 current_block.SetEndLocation (lexer.Location);
6552 current_block = current_block.Parent;
6562 current_block.SetEndLocation (lexer.Location);
6563 current_block = current_block.Parent;
6565 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6569 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6576 | orderings_then_by COMMA
6578 current_block.SetEndLocation (lexer.Location);
6579 current_block = current_block.Parent;
6581 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6585 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6593 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6595 | expression ASCENDING
6597 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6598 lbag.AddLocation ($$, GetLocation ($2));
6600 | expression DESCENDING
6602 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6603 lbag.AddLocation ($$, GetLocation ($2));
6610 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6612 | expression ASCENDING
6614 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6615 lbag.AddLocation ($$, GetLocation ($2));
6617 | expression DESCENDING
6619 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6620 lbag.AddLocation ($$, GetLocation ($2));
6625 opt_query_continuation
6627 | INTO identifier_inside_body
6629 // query continuation block is not linked with query block but with block
6630 // before. This means each query can use same range variable names for
6631 // different identifiers.
6633 current_block.SetEndLocation (GetLocation ($1));
6634 current_block = current_block.Parent;
6636 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6638 if (linq_clause_blocks == null)
6639 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6641 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6645 var current_block = linq_clause_blocks.Pop ();
6646 var lt = (LocatedToken) $2;
6647 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6648 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6649 next = (Linq.AQueryClause)$4
6655 // Support for using the compiler as an interactive parser
6657 // The INTERACTIVE_PARSER token is first sent to parse our
6658 // productions; If the result is a Statement, the parsing
6659 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6660 // to setup the blocks in advance.
6662 // This setup is here so that in the future we can add
6663 // support for other constructs (type parsing, namespaces, etc)
6664 // that do not require a block to be setup in advance
6668 : EVAL_STATEMENT_PARSER EOF
6669 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6670 | EVAL_STATEMENT_PARSER
6672 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6674 // (ref object retval)
6675 Parameter [] mpar = new Parameter [1];
6676 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6678 ParametersCompiled pars = new ParametersCompiled (mpar);
6679 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6680 if (settings.Unsafe)
6681 mods |= Modifiers.UNSAFE;
6683 current_local_parameters = pars;
6684 var method = new InteractiveMethod (
6686 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6690 current_type.AddMember (method);
6691 oob_stack.Push (method);
6693 interactive_async = false;
6695 ++lexer.parsing_block;
6696 start_block (lexer.Location);
6698 interactive_statement_list opt_COMPLETE_COMPLETION
6700 --lexer.parsing_block;
6701 var method = (InteractiveMethod) oob_stack.Pop ();
6702 method.Block = (ToplevelBlock) end_block(lexer.Location);
6704 if (interactive_async == true) {
6705 method.ChangeToAsync ();
6708 InteractiveResult = (Class) pop_current_class ();
6709 current_local_parameters = null;
6711 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6714 interactive_compilation_unit
6715 : opt_extern_alias_directives opt_using_directives
6716 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6719 opt_COMPLETE_COMPLETION
6721 | COMPLETE_COMPLETION
6724 close_brace_or_complete_completion
6726 | COMPLETE_COMPLETION
6730 // XML documentation code references micro parser
6732 documentation_parsing
6735 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6740 : doc_type_declaration_name opt_doc_method_sig
6742 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6744 | builtin_types opt_doc_method_sig
6746 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6747 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6750 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6752 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6753 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6754 var lt = (LocatedToken) $3;
6755 $$ = new MemberName (lt.Value);
6757 | doc_type_declaration_name DOT THIS
6759 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6761 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6763 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6765 opt_doc_parameters CLOSE_BRACKET
6767 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6768 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6770 | EXPLICIT OPERATOR type opt_doc_method_sig
6772 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6773 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6774 module.DocumentationBuilder.ParsedParameters = p;
6775 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6778 | IMPLICIT OPERATOR type opt_doc_method_sig
6780 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6781 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6782 module.DocumentationBuilder.ParsedParameters = p;
6783 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6786 | OPERATOR overloadable_operator opt_doc_method_sig
6788 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6789 module.DocumentationBuilder.ParsedParameters = p;
6790 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6795 doc_type_declaration_name
6796 : type_declaration_name
6797 | doc_type_declaration_name DOT type_declaration_name
6799 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6807 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6809 opt_doc_parameters CLOSE_PARENS
6818 $$ = new List<DocumentationParameter> (0);
6826 var parameters = new List<DocumentationParameter> ();
6827 parameters.Add ((DocumentationParameter) $1);
6830 | doc_parameters COMMA doc_parameter
6832 var parameters = $1 as List<DocumentationParameter>;
6833 parameters.Add ((DocumentationParameter) $3);
6839 : opt_parameter_modifier parameter_type
6842 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6844 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6851 // A class used to hold info about an operator declarator
6853 class OperatorDeclaration {
6854 public readonly Operator.OpType optype;
6855 public readonly FullNamedExpression ret_type;
6856 public readonly Location location;
6858 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6861 this.ret_type = ret_type;
6862 this.location = location;
6866 void Error_ExpectingTypeName (Expression expr)
6868 if (expr is Invocation){
6869 report.Error (1002, expr.Location, "Expecting `;'");
6871 expr.Error_InvalidExpressionStatement (report);
6875 void Error_ParameterModifierNotValid (string modifier, Location loc)
6877 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6881 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6883 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6884 Parameter.GetModifierSignature (mod));
6887 void Error_TypeExpected (Location loc)
6889 report.Error (1031, loc, "Type expected");
6892 void Error_UnsafeCodeNotAllowed (Location loc)
6894 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6897 void Warning_EmptyStatement (Location loc)
6899 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6902 void Error_NamedArgumentExpected (NamedArgument a)
6904 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6907 void Error_MissingInitializer (Location loc)
6909 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6912 object Error_AwaitAsIdentifier (object token)
6915 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6916 return new LocatedToken ("await", GetLocation (token));
6922 void push_current_container (TypeDefinition tc, object partial_token)
6924 if (module.Evaluator != null){
6925 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6929 undo.AddTypeContainer (current_container, tc);
6932 if (partial_token != null)
6933 current_container.AddPartial (tc);
6935 current_container.AddTypeContainer (tc);
6937 ++lexer.parsing_declaration;
6938 current_container = tc;
6942 TypeContainer pop_current_class ()
6944 var retval = current_container;
6946 current_container = current_container.Parent;
6947 current_type = current_type.Parent as TypeDefinition;
6952 [System.Diagnostics.Conditional ("FULL_AST")]
6953 void StoreModifierLocation (object token, Location loc)
6958 if (mod_locations == null)
6959 mod_locations = new List<Tuple<Modifiers, Location>> ();
6961 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6964 [System.Diagnostics.Conditional ("FULL_AST")]
6965 void PushLocation (Location loc)
6967 if (location_stack == null)
6968 location_stack = new Stack<Location> ();
6970 location_stack.Push (loc);
6973 Location PopLocation ()
6975 if (location_stack == null)
6976 return Location.Null;
6978 return location_stack.Pop ();
6981 string CheckAttributeTarget (string a, Location l)
6984 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6988 report.Warning (658, 1, l,
6989 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6990 return string.Empty;
6993 static bool IsUnaryOperator (Operator.OpType op)
6997 case Operator.OpType.LogicalNot:
6998 case Operator.OpType.OnesComplement:
6999 case Operator.OpType.Increment:
7000 case Operator.OpType.Decrement:
7001 case Operator.OpType.True:
7002 case Operator.OpType.False:
7003 case Operator.OpType.UnaryPlus:
7004 case Operator.OpType.UnaryNegation:
7010 void syntax_error (Location l, string msg)
7012 report.Error (1003, l, "Syntax error, " + msg);
7017 public Tokenizer Lexer {
7023 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7024 : this (reader, file, file.Compiler.Report, session)
7028 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7031 current_container = current_namespace = file;
7033 this.module = file.Module;
7034 this.compiler = file.Compiler;
7035 this.settings = compiler.Settings;
7036 this.report = report;
7038 lang_version = settings.Version;
7039 yacc_verbose_flag = settings.VerboseParserFlag;
7040 doc_support = settings.DocumentationFile != null;
7041 lexer = new Tokenizer (reader, file, session, report);
7042 oob_stack = new Stack<object> ();
7043 lbag = session.LocationsBag;
7044 use_global_stacks = session.UseJayGlobalArrays;
7045 parameters_bucket = session.ParametersStack;
7048 public void parse ()
7050 eof_token = Token.EOF;
7053 if (yacc_verbose_flag > 1)
7054 yyparse (lexer, new yydebug.yyDebugSimple ());
7058 Tokenizer tokenizer = lexer as Tokenizer;
7059 tokenizer.cleanup ();
7060 } catch (Exception e){
7061 if (e is yyParser.yyUnexpectedEof) {
7062 Error_SyntaxError (yyToken);
7063 UnexpectedEOF = true;
7067 if (e is yyParser.yyException) {
7068 if (report.Errors == 0)
7069 report.Error (-25, lexer.Location, "Parsing error");
7071 // Used by compiler-tester to test internal errors
7072 if (yacc_verbose_flag > 0 || e is FatalException)
7075 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7080 void CheckToken (int error, int yyToken, string msg, Location loc)
7082 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7083 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7085 report.Error (error, loc, msg);
7088 string ConsumeStoredComment ()
7090 string s = tmpComment;
7092 Lexer.doc_state = XmlCommentState.Allowed;
7096 void FeatureIsNotAvailable (Location loc, string feature)
7098 report.FeatureIsNotAvailable (compiler, loc, feature);
7101 Location GetLocation (object obj)
7103 var lt = obj as LocatedToken;
7107 var mn = obj as MemberName;
7111 var expr = obj as Expression;
7113 return expr.Location;
7115 return lexer.Location;
7118 void start_block (Location loc)
7120 if (current_block == null) {
7121 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7122 parsing_anonymous_method = false;
7123 } else if (parsing_anonymous_method) {
7124 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7125 parsing_anonymous_method = false;
7127 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7132 end_block (Location loc)
7134 Block retval = current_block.Explicit;
7135 retval.SetEndLocation (loc);
7136 current_block = retval.Parent;
7140 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7142 oob_stack.Push (current_anonymous_method);
7143 oob_stack.Push (current_local_parameters);
7144 oob_stack.Push (current_variable);
7145 oob_stack.Push (async_block);
7147 current_local_parameters = parameters;
7149 if (lang_version <= LanguageVersion.ISO_2)
7150 FeatureIsNotAvailable (loc, "lambda expressions");
7152 current_anonymous_method = new LambdaExpression (loc);
7154 if (lang_version == LanguageVersion.ISO_1)
7155 FeatureIsNotAvailable (loc, "anonymous methods");
7157 current_anonymous_method = new AnonymousMethodExpression (loc);
7160 async_block = isAsync;
7161 // Force the next block to be created as a ToplevelBlock
7162 parsing_anonymous_method = true;
7166 * Completes the anonymous method processing, if lambda_expr is null, this
7167 * means that we have a Statement instead of an Expression embedded
7169 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7171 AnonymousMethodExpression retval;
7174 anon_block.IsAsync = true;
7176 current_anonymous_method.Block = anon_block;
7177 retval = current_anonymous_method;
7179 async_block = (bool) oob_stack.Pop ();
7180 current_variable = (BlockVariable) oob_stack.Pop ();
7181 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7182 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7187 void Error_SyntaxError (int token)
7189 Error_SyntaxError (0, token);
7192 void Error_SyntaxError (int error_code, int token)
7194 Error_SyntaxError (error_code, token, "Unexpected symbol");
7197 void Error_SyntaxError (int error_code, int token, string msg)
7199 Lexer.CompleteOnEOF = false;
7201 // An error message has been reported by tokenizer
7202 if (token == Token.ERROR)
7205 // Avoid duplicit error message after unterminated string literals
7206 if (token == Token.LITERAL && lexer.Location.Column == 0)
7209 string symbol = GetSymbolName (token);
7210 string expecting = GetExpecting ();
7211 var loc = lexer.Location - symbol.Length;
7213 if (error_code == 0) {
7214 if (expecting == "`identifier'") {
7215 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7216 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7221 expecting = "identifier";
7222 } else if (expecting == "`)'") {
7229 if (string.IsNullOrEmpty (expecting))
7230 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7232 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7235 string GetExpecting ()
7237 int [] tokens = yyExpectingTokens (yyExpectingState);
7238 var names = new List<string> (tokens.Length);
7239 bool has_type = false;
7240 bool has_identifier = false;
7241 for (int i = 0; i < tokens.Length; i++){
7242 int token = tokens [i];
7243 has_identifier |= token == Token.IDENTIFIER;
7245 string name = GetTokenName (token);
7246 if (name == "<internal>")
7249 has_type |= name == "type";
7250 if (names.Contains (name))
7257 // Too many tokens to enumerate
7259 if (names.Count > 8)
7262 if (has_type && has_identifier)
7263 names.Remove ("identifier");
7265 if (names.Count == 1)
7266 return "`" + GetTokenName (tokens [0]) + "'";
7268 StringBuilder sb = new StringBuilder ();
7270 int count = names.Count;
7271 for (int i = 0; i < count; i++){
7272 bool last = i + 1 == count;
7276 sb.Append (names [i]);
7277 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7279 return sb.ToString ();
7283 string GetSymbolName (int token)
7287 return ((Constant)lexer.Value).GetValue ().ToString ();
7288 case Token.IDENTIFIER:
7289 return ((LocatedToken)lexer.Value).Value;
7331 case Token.BITWISE_AND:
7333 case Token.BITWISE_OR:
7347 case Token.OP_SHIFT_LEFT:
7349 case Token.OP_SHIFT_RIGHT:
7369 case Token.OP_COALESCING:
7371 case Token.OP_MULT_ASSIGN:
7373 case Token.OP_DIV_ASSIGN:
7375 case Token.OP_MOD_ASSIGN:
7377 case Token.OP_ADD_ASSIGN:
7379 case Token.OP_SUB_ASSIGN:
7381 case Token.OP_SHIFT_LEFT_ASSIGN:
7383 case Token.OP_SHIFT_RIGHT_ASSIGN:
7385 case Token.OP_AND_ASSIGN:
7387 case Token.OP_XOR_ASSIGN:
7389 case Token.OP_OR_ASSIGN:
7393 return GetTokenName (token);
7396 static string GetTokenName (int token)
7399 case Token.ABSTRACT:
7421 case Token.CONTINUE:
7425 case Token.DELEGATE:
7435 case Token.EXPLICIT:
7438 case Token.EXTERN_ALIAS:
7454 case Token.IMPLICIT:
7458 case Token.INTERFACE:
7460 case Token.INTERNAL:
7466 case Token.NAMESPACE:
7472 case Token.OPERATOR:
7476 case Token.OVERRIDE:
7482 case Token.PROTECTED:
7486 case Token.READONLY:
7498 case Token.STACKALLOC:
7499 return "stackalloc";
7516 case Token.UNCHECKED:
7524 case Token.VOLATILE:
7532 case Token.REFVALUE:
7533 return "__refvalue";
7543 case Token.FROM_FIRST:
7561 case Token.ASCENDING:
7563 case Token.DESCENDING:
7564 return "descending";
7571 case Token.OPEN_BRACE:
7573 case Token.CLOSE_BRACE:
7575 case Token.OPEN_BRACKET:
7576 case Token.OPEN_BRACKET_EXPR:
7578 case Token.CLOSE_BRACKET:
7580 case Token.OPEN_PARENS_CAST:
7581 case Token.OPEN_PARENS_LAMBDA:
7582 case Token.OPEN_PARENS:
7584 case Token.CLOSE_PARENS:
7590 case Token.DEFAULT_COLON:
7594 case Token.SEMICOLON:
7605 case Token.BITWISE_AND:
7606 case Token.BITWISE_OR:
7613 case Token.OP_SHIFT_LEFT:
7614 case Token.OP_SHIFT_RIGHT:
7622 case Token.OP_COALESCING:
7623 case Token.OP_MULT_ASSIGN:
7624 case Token.OP_DIV_ASSIGN:
7625 case Token.OP_MOD_ASSIGN:
7626 case Token.OP_ADD_ASSIGN:
7627 case Token.OP_SUB_ASSIGN:
7628 case Token.OP_SHIFT_LEFT_ASSIGN:
7629 case Token.OP_SHIFT_RIGHT_ASSIGN:
7630 case Token.OP_AND_ASSIGN:
7631 case Token.OP_XOR_ASSIGN:
7632 case Token.OP_OR_ASSIGN:
7633 return "<operator>";
7655 case Token.OP_GENERICS_LT:
7656 case Token.GENERIC_DIMENSION:
7658 case Token.OP_GENERICS_GT:
7661 case Token.INTERR_NULLABLE:
7663 case Token.DOUBLE_COLON:
7667 case Token.IDENTIFIER:
7669 return "identifier";
7672 return "end-of-file";
7674 // All of these are internal.
7677 case Token.FIRST_KEYWORD:
7678 case Token.EVAL_COMPILATION_UNIT_PARSER:
7679 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7680 case Token.EVAL_STATEMENT_PARSER:
7681 case Token.LAST_KEYWORD:
7682 case Token.GENERATE_COMPLETION:
7683 case Token.COMPLETE_COMPLETION:
7684 return "<internal>";
7686 // A bit more robust.
7688 return yyNames [token];