3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue
41 static readonly object ModifierNone = 0;
43 NamespaceContainer current_namespace;
44 TypeContainer current_container;
45 TypeDefinition current_type;
46 PropertyBase current_property;
47 EventProperty current_event;
48 EventField current_event_field;
49 FieldBase current_field;
52 /// Current block is used to add statements as we find
57 BlockVariable current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 bool? interactive_async;
122 Stack<Linq.QueryBlock> linq_clause_blocks;
124 ModuleContainer module;
126 readonly CompilerContext compiler;
127 readonly LanguageVersion lang_version;
128 readonly bool doc_support;
129 readonly CompilerSettings settings;
130 readonly Report report;
133 // Instead of allocating carrier array everytime we
134 // share the bucket for very common constructs which can never
137 List<Parameter> parameters_bucket;
140 // Full AST support members
143 List<Tuple<Modifiers, Location>> mod_locations;
144 Stack<Location> location_stack;
148 %token NONE /* This token is never returned by our lexer */
149 %token ERROR // This is used not by the parser, but by the tokenizer.
153 *These are the C# keywords
252 %token INTERR_NULLABLE
260 /* C# keywords which are not really keywords */
266 /* C# single character operators/punctuation. */
294 /* C# multi-character operators. */
299 %token OP_SHIFT_RIGHT
306 %token OP_MULT_ASSIGN
311 %token OP_SHIFT_LEFT_ASSIGN
312 %token OP_SHIFT_RIGHT_ASSIGN
319 /* Generics <,> tokens */
320 %token OP_GENERICS_LT
321 %token OP_GENERICS_LT_DECL
322 %token OP_GENERICS_GT
327 %token OPEN_PARENS_LAMBDA
328 %token OPEN_PARENS_CAST
329 %token GENERIC_DIMENSION
331 %token OPEN_BRACKET_EXPR
333 // Make the parser go into eval mode parsing (statements and compilation units).
334 %token EVAL_STATEMENT_PARSER
335 %token EVAL_COMPILATION_UNIT_PARSER
336 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
341 // This token is generated to trigger the completion engine at this point
343 %token GENERATE_COMPLETION
346 // This token is return repeatedly after the first GENERATE_COMPLETION
347 // token is produced and before the final EOF
349 %token COMPLETE_COMPLETION
351 /* Add precedence rules to solve dangling else s/r conflict */
355 /* Define the operator tokens and their precedences */
363 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
365 %left STAR DIV PERCENT
366 %right BANG CARRET UMINUS
367 %nonassoc OP_INC OP_DEC
369 %left OPEN_BRACKET OPEN_BRACE
372 %start compilation_unit
376 : outer_declaration opt_EOF
378 Lexer.check_incorrect_doc_comment ();
380 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
381 | documentation_parsing
385 : opt_extern_alias_directives opt_using_directives
386 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
389 Attributes attrs = (Attributes) $4;
390 report.Error (1730, attrs.Attrs [0].Location,
391 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
393 current_namespace.UnattachedAttributes = attrs;
396 | opt_extern_alias_directives opt_using_directives attribute_sections
398 module.AddAttributes ((Attributes) $3, current_namespace);
402 if (yyToken == Token.EXTERN_ALIAS)
403 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
405 Error_SyntaxError (yyToken);
414 extern_alias_directives
415 : extern_alias_directive
416 | extern_alias_directives extern_alias_directive
419 extern_alias_directive
420 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
422 var lt = (LocatedToken) $2;
425 syntax_error (lt.Location, "`alias' expected");
427 if (lang_version == LanguageVersion.ISO_1)
428 FeatureIsNotAvailable (lt.Location, "external alias");
430 lt = (LocatedToken) $3;
431 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
432 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
435 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
436 current_namespace.AddUsing (na);
438 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
443 Error_SyntaxError (yyToken);
449 | using_directives using_directive
456 Lexer.doc_state = XmlCommentState.Allowed;
461 : USING namespace_or_type_expr SEMICOLON
463 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
464 current_namespace.AddUsing (un);
466 lbag.AddLocation (un, GetLocation ($3));
468 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
470 var lt = (LocatedToken) $2;
471 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
472 report.Warning (440, 2, lt.Location,
473 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
476 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
477 current_namespace.AddUsing (un);
479 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
483 Error_SyntaxError (yyToken);
489 // Strictly speaking, namespaces don't have attributes but
490 // we parse global attributes along with namespace declarations and then
493 namespace_declaration
494 : opt_attributes NAMESPACE namespace_name
496 Attributes attrs = (Attributes) $1;
497 var name = (MemberName) $3;
499 bool valid_global_attrs = true;
500 if ((current_namespace.DeclarationFound || current_namespace != file)) {
501 valid_global_attrs = false;
503 foreach (var a in attrs.Attrs) {
504 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
507 valid_global_attrs = false;
512 if (!valid_global_attrs)
513 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
516 module.AddAttributes (attrs, current_namespace);
518 var ns = new NamespaceContainer (name, current_namespace);
519 current_namespace.AddTypeContainer (ns);
520 current_container = current_namespace = ns;
525 Lexer.doc_state = XmlCommentState.Allowed;
527 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
530 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
532 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
534 current_container = current_namespace = current_namespace.Parent;
536 | opt_attributes NAMESPACE namespace_name
538 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
540 var name = (MemberName) $3;
541 var ns = new NamespaceContainer (name, current_namespace);
542 lbag.AddLocation (ns, GetLocation ($2));
543 current_namespace.AddTypeContainer (ns);
552 Error_SyntaxError (yyToken);
560 var lt = (LocatedToken) $1;
561 $$ = new MemberName (lt.Value, lt.Location);
563 | namespace_name DOT IDENTIFIER
565 var lt = (LocatedToken) $3;
566 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
567 lbag.AddLocation ($$, GetLocation ($2));
571 Error_SyntaxError (yyToken);
572 $$ = new MemberName ("<invalid>", lexer.Location);
591 opt_extern_alias_directives
593 | extern_alias_directives
596 opt_namespace_or_type_declarations
598 | namespace_or_type_declarations
601 namespace_or_type_declarations
602 : namespace_or_type_declaration
603 | namespace_or_type_declarations namespace_or_type_declaration
606 namespace_or_type_declaration
610 TypeContainer ds = (TypeContainer)$1;
612 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
613 report.Error (1527, ds.Location,
614 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
617 // Here is a trick, for explicit attributes we don't know where they belong to until
618 // we parse succeeding declaration hence we parse them as normal and re-attach them
619 // when we know whether they are global (assembly:, module:) or local (type:).
620 if (ds.OptAttributes != null) {
621 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
624 current_namespace.DeclarationFound = true;
626 | namespace_declaration
628 current_namespace.DeclarationFound = true;
630 | attribute_sections CLOSE_BRACE {
631 current_namespace.UnattachedAttributes = (Attributes) $1;
632 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
640 | interface_declaration
642 | delegate_declaration
644 // Enable this when we have handled all errors, because this acts as a generic fallback
647 // Console.WriteLine ("Token=" + yyToken);
648 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
664 var sect = (List<Attribute>) $1;
665 $$ = new Attributes (sect);
667 | attribute_sections attribute_section
669 Attributes attrs = $1 as Attributes;
670 var sect = (List<Attribute>) $2;
672 attrs = new Attributes (sect);
673 else if (sect != null)
674 attrs.AddAttributes (sect);
682 PushLocation (GetLocation ($1));
683 lexer.parsing_attribute_section = true;
685 attribute_section_cont
687 lexer.parsing_attribute_section = false;
692 attribute_section_cont
693 : attribute_target COLON
695 current_attr_target = (string) $1;
696 if (current_attr_target == "assembly" || current_attr_target == "module") {
697 Lexer.check_incorrect_doc_comment ();
700 attribute_list opt_comma CLOSE_BRACKET
702 // when attribute target is invalid
703 if (current_attr_target == string.Empty)
704 $$ = new List<Attribute> (0);
708 lbag.InsertLocation ($$, 0, PopLocation ());
710 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
712 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
715 current_attr_target = null;
716 lexer.parsing_attribute_section = false;
718 | attribute_list opt_comma CLOSE_BRACKET
722 lbag.InsertLocation ($$, 0, PopLocation ());
724 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
726 lbag.AddLocation ($$, GetLocation($3));
731 Error_SyntaxError (yyToken);
733 var lt = (LocatedToken) $1;
734 var tne = new SimpleName (lt.Value, null, lt.Location);
736 $$ = new List<Attribute> () {
737 new Attribute (null, tne, null, GetLocation ($1), false)
742 CheckAttributeTarget (yyToken, GetTokenName (yyToken), GetLocation ($1));
750 var lt = (LocatedToken) $1;
751 $$ = CheckAttributeTarget (yyToken, lt.Value, lt.Location);
753 | EVENT { $$ = "event"; }
754 | RETURN { $$ = "return"; }
760 $$ = new List<Attribute> (4) { (Attribute) $1 };
762 | attribute_list COMMA attribute
764 var attrs = (List<Attribute>) $1;
766 attrs.Add ((Attribute) $3);
767 lbag.AppendTo (attrs, GetLocation ($2));
777 ++lexer.parsing_block;
779 opt_attribute_arguments
781 --lexer.parsing_block;
783 var tne = (ATypeNameExpression) $1;
784 if (tne.HasTypeArguments) {
785 report.Error (404, tne.Location, "Attributes cannot be generic");
788 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
793 : namespace_or_type_expr
796 opt_attribute_arguments
797 : /* empty */ { $$ = null; }
798 | OPEN_PARENS attribute_arguments CLOSE_PARENS
806 : /* empty */ { $$ = null; }
807 | positional_or_named_argument
809 Arguments a = new Arguments (4);
810 a.Add ((Argument) $1);
811 $$ = new Arguments [] { a, null };
813 | named_attribute_argument
815 Arguments a = new Arguments (4);
816 a.Add ((Argument) $1);
817 $$ = new Arguments [] { null, a };
819 | attribute_arguments COMMA positional_or_named_argument
821 Arguments[] o = (Arguments[]) $1;
823 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
824 o [0] = new Arguments (4);
827 Arguments args = ((Arguments) o [0]);
828 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
829 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
831 args.Add ((Argument) $3);
833 | attribute_arguments COMMA named_attribute_argument
835 Arguments[] o = (Arguments[]) $1;
837 o [1] = new Arguments (4);
840 ((Arguments) o [1]).Add ((Argument) $3);
844 positional_or_named_argument
847 $$ = new Argument ((Expression) $1);
852 Error_SyntaxError (yyToken);
857 named_attribute_argument
860 ++lexer.parsing_block;
864 --lexer.parsing_block;
865 var lt = (LocatedToken) $1;
866 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
867 lbag.AddLocation ($$, GetLocation($2));
872 : identifier_inside_body COLON opt_named_modifier expression_or_error
874 if (lang_version <= LanguageVersion.V_3)
875 FeatureIsNotAvailable (GetLocation ($1), "named argument");
877 // Avoid boxing in common case (no modifier)
878 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
880 var lt = (LocatedToken) $1;
881 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
882 lbag.AddLocation ($$, GetLocation($2));
887 : /* empty */ { $$ = null; }
890 $$ = Argument.AType.Ref;
894 $$ = Argument.AType.Out;
898 opt_class_member_declarations
900 | class_member_declarations
903 class_member_declarations
904 : class_member_declaration
906 lexer.parsing_modifiers = true;
907 lexer.parsing_block = 0;
909 | class_member_declarations class_member_declaration
911 lexer.parsing_modifiers = true;
912 lexer.parsing_block = 0;
916 class_member_declaration
917 : constant_declaration
920 | property_declaration
922 | indexer_declaration
923 | operator_declaration
924 | constructor_declaration
925 | destructor_declaration
927 | attributes_without_members
931 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
932 GetSymbolName (yyToken));
934 lexer.parsing_generic_declaration = false;
945 type_declaration_name
947 lexer.ConstraintsParsing = true;
948 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
951 opt_type_parameter_constraints_clauses
953 lexer.ConstraintsParsing = false;
956 current_container.SetConstraints ((List<Constraints>) $9);
959 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
961 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
963 lexer.parsing_modifiers = true;
968 Lexer.doc_state = XmlCommentState.Allowed;
970 opt_class_member_declarations CLOSE_BRACE
972 --lexer.parsing_declaration;
974 Lexer.doc_state = XmlCommentState.Allowed;
979 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
981 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
983 $$ = pop_current_class ();
985 | opt_attributes opt_modifiers opt_partial STRUCT error
987 Error_SyntaxError (yyToken);
994 CONST type IDENTIFIER
996 var lt = (LocatedToken) $5;
997 var mod = (Modifiers) $2;
998 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
999 current_type.AddMember (current_field);
1001 if ((mod & Modifiers.STATIC) != 0) {
1002 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1007 constant_initializer opt_constant_declarators SEMICOLON
1010 current_field.DocComment = Lexer.consume_doc_comment ();
1011 Lexer.doc_state = XmlCommentState.Allowed;
1014 current_field.Initializer = (ConstInitializer) $7;
1015 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1016 current_field = null;
1022 Error_SyntaxError (yyToken);
1024 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1028 opt_constant_declarators
1030 | constant_declarators
1033 constant_declarators
1034 : constant_declarator
1036 current_field.AddDeclarator ((FieldDeclarator) $1);
1038 | constant_declarators constant_declarator
1040 current_field.AddDeclarator ((FieldDeclarator) $2);
1045 : COMMA IDENTIFIER constant_initializer
1047 var lt = (LocatedToken) $2;
1048 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1049 lbag.AddLocation ($$, GetLocation ($1));
1053 constant_initializer
1056 ++lexer.parsing_block;
1058 constant_initializer_expr
1060 --lexer.parsing_block;
1061 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1065 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1070 constant_initializer_expr
1071 : constant_expression
1078 member_type IDENTIFIER
1080 lexer.parsing_generic_declaration = false;
1082 FullNamedExpression type = (FullNamedExpression) $3;
1083 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1084 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1086 var lt = (LocatedToken) $4;
1087 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1088 current_type.AddField (current_field);
1091 opt_field_initializer
1092 opt_field_declarators
1096 current_field.DocComment = Lexer.consume_doc_comment ();
1097 Lexer.doc_state = XmlCommentState.Allowed;
1100 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1102 current_field = null;
1106 FIXED simple_type IDENTIFIER
1108 if (lang_version < LanguageVersion.ISO_2)
1109 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1111 var lt = (LocatedToken) $5;
1112 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1113 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1115 current_type.AddField (current_field);
1117 fixed_field_size opt_fixed_field_declarators SEMICOLON
1120 current_field.DocComment = Lexer.consume_doc_comment ();
1121 Lexer.doc_state = XmlCommentState.Allowed;
1124 current_field.Initializer = (ConstInitializer) $7;
1125 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1127 current_field = null;
1131 FIXED simple_type error
1134 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1138 opt_field_initializer
1142 ++lexer.parsing_block;
1143 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1144 start_block (GetLocation ($1));
1146 variable_initializer
1148 --lexer.parsing_block;
1149 current_field.Initializer = (Expression) $3;
1150 lbag.AppendToMember (current_field, GetLocation ($1));
1151 end_block (lexer.Location);
1152 current_local_parameters = null;
1156 opt_field_declarators
1164 current_field.AddDeclarator ((FieldDeclarator) $1);
1166 | field_declarators field_declarator
1168 current_field.AddDeclarator ((FieldDeclarator) $2);
1175 var lt = (LocatedToken) $2;
1176 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1177 lbag.AddLocation ($$, GetLocation ($1));
1179 | COMMA IDENTIFIER ASSIGN
1181 ++lexer.parsing_block;
1183 variable_initializer
1185 --lexer.parsing_block;
1186 var lt = (LocatedToken) $2;
1187 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1188 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1192 opt_fixed_field_declarators
1194 | fixed_field_declarators
1197 fixed_field_declarators
1198 : fixed_field_declarator
1200 current_field.AddDeclarator ((FieldDeclarator) $1);
1202 | fixed_field_declarators fixed_field_declarator
1204 current_field.AddDeclarator ((FieldDeclarator) $2);
1208 fixed_field_declarator
1209 : COMMA IDENTIFIER fixed_field_size
1211 var lt = (LocatedToken) $2;
1212 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1213 lbag.AddLocation ($$, GetLocation ($1));
1220 ++lexer.parsing_block;
1222 expression CLOSE_BRACKET
1224 --lexer.parsing_block;
1225 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1226 lbag.AddLocation ($$, GetLocation ($4));
1228 | OPEN_BRACKET error
1230 report.Error (443, lexer.Location, "Value or constant expected");
1235 variable_initializer
1240 // It has to be here for the parent to safely restore artificial block
1241 Error_SyntaxError (yyToken);
1250 Lexer.doc_state = XmlCommentState.NotAllowed;
1252 // Was added earlier in the case of body being eof for full ast
1256 Method method = (Method) $1;
1257 method.Block = (ToplevelBlock) $3;
1258 async_block = false;
1260 if (method.Block == null) {
1261 method.ParameterInfo.CheckParameters (method);
1263 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1264 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1265 method.GetSignatureForError ());
1268 if (current_container.Kind == MemberKind.Interface) {
1269 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1270 method.GetSignatureForError ());
1274 current_local_parameters = null;
1277 Lexer.doc_state = XmlCommentState.Allowed;
1285 method_declaration_name OPEN_PARENS
1287 valid_param_mod = ParameterModifierType.All;
1289 opt_formal_parameter_list CLOSE_PARENS
1291 valid_param_mod = 0;
1292 MemberName name = (MemberName) $4;
1293 current_local_parameters = (ParametersCompiled) $7;
1295 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1296 name, current_local_parameters, (Attributes) $1);
1298 current_type.AddMember (method);
1300 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1303 method.DocComment = Lexer.consume_doc_comment ();
1305 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1309 lexer.ConstraintsParsing = true;
1311 opt_type_parameter_constraints_clauses
1313 lexer.ConstraintsParsing = false;
1316 var method = (Method) $9;
1317 method.SetConstraints ((List<Constraints>) $10);
1327 lexer.parsing_generic_declaration = true;
1329 method_declaration_name
1332 lexer.parsing_generic_declaration = false;
1333 valid_param_mod = ParameterModifierType.All;
1335 opt_formal_parameter_list CLOSE_PARENS
1337 lexer.ConstraintsParsing = true;
1339 opt_type_parameter_constraints_clauses
1341 lexer.ConstraintsParsing = false;
1342 valid_param_mod = 0;
1344 MemberName name = (MemberName) $6;
1345 current_local_parameters = (ParametersCompiled) $9;
1347 var modifiers = (Modifiers) $2;
1348 modifiers |= Modifiers.PARTIAL;
1350 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1351 modifiers, name, current_local_parameters, (Attributes) $1);
1353 current_type.AddMember (method);
1355 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1358 method.SetConstraints ((List<Constraints>) $12);
1361 method.DocComment = Lexer.consume_doc_comment ();
1363 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1364 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1370 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1372 MemberName name = (MemberName) $5;
1373 report.Error (1585, name.Location,
1374 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1376 var method = Method.Create (current_type, (FullNamedExpression) $3,
1377 0, name, (ParametersCompiled) $7, (Attributes) $1);
1379 current_type.AddMember (method);
1381 current_local_parameters = (ParametersCompiled) $7;
1384 method.DocComment = Lexer.consume_doc_comment ();
1391 method_declaration_name error
1393 Error_SyntaxError (yyToken);
1394 current_local_parameters = ParametersCompiled.Undefined;
1396 MemberName name = (MemberName) $4;
1397 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1398 name, current_local_parameters, (Attributes) $1);
1400 current_type.AddMember (method);
1403 method.DocComment = Lexer.consume_doc_comment ();
1411 | SEMICOLON { $$ = null; }
1414 opt_formal_parameter_list
1415 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1416 | formal_parameter_list
1419 formal_parameter_list
1422 var pars_list = (List<Parameter>) $1;
1423 $$ = new ParametersCompiled (pars_list.ToArray ());
1425 | fixed_parameters COMMA parameter_array
1427 var pars_list = (List<Parameter>) $1;
1428 pars_list.Add ((Parameter) $3);
1430 $$ = new ParametersCompiled (pars_list.ToArray ());
1432 | fixed_parameters COMMA arglist_modifier
1434 var pars_list = (List<Parameter>) $1;
1435 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1436 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1438 | parameter_array COMMA error
1441 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1443 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1445 | fixed_parameters COMMA parameter_array COMMA error
1448 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1450 var pars_list = (List<Parameter>) $1;
1451 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1453 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1455 | arglist_modifier COMMA error
1457 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1459 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1461 | fixed_parameters COMMA ARGLIST COMMA error
1463 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1465 var pars_list = (List<Parameter>) $1;
1466 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1468 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1472 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1476 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1480 Error_SyntaxError (yyToken);
1481 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1488 parameters_bucket.Clear ();
1489 Parameter p = (Parameter) $1;
1490 parameters_bucket.Add (p);
1492 default_parameter_used = p.HasDefaultValue;
1493 $$ = parameters_bucket;
1495 | fixed_parameters COMMA fixed_parameter
1497 var pars = (List<Parameter>) $1;
1498 Parameter p = (Parameter) $3;
1500 if (p.HasExtensionMethodModifier)
1501 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1502 else if (!p.HasDefaultValue && default_parameter_used)
1503 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1505 default_parameter_used |= p.HasDefaultValue;
1508 lbag.AddLocation (p, GetLocation ($2));
1517 opt_parameter_modifier
1519 identifier_inside_body
1521 var lt = (LocatedToken) $4;
1522 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1525 opt_parameter_modifier
1527 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1529 var lt = (LocatedToken) $4;
1530 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1531 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1533 | attribute_sections error
1535 Error_SyntaxError (yyToken);
1536 Location l = GetLocation ($2);
1537 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1540 opt_parameter_modifier
1544 Error_SyntaxError (yyToken);
1545 Location l = GetLocation ($4);
1546 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1549 opt_parameter_modifier
1551 identifier_inside_body
1554 ++lexer.parsing_block;
1558 --lexer.parsing_block;
1559 if (lang_version <= LanguageVersion.V_3) {
1560 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1563 Parameter.Modifier mod = (Parameter.Modifier) $2;
1564 if (mod != Parameter.Modifier.NONE) {
1566 case Parameter.Modifier.REF:
1567 case Parameter.Modifier.OUT:
1568 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1569 Parameter.GetModifierSignature (mod));
1572 case Parameter.Modifier.This:
1573 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1574 Parameter.GetModifierSignature (mod));
1577 throw new NotImplementedException (mod.ToString ());
1580 mod = Parameter.Modifier.NONE;
1583 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1584 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1586 var lt = (LocatedToken) $4;
1587 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1588 lbag.AddLocation ($$, GetLocation ($5));
1591 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1595 opt_parameter_modifier
1596 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1597 | parameter_modifiers
1601 : parameter_modifier
1605 | parameter_modifiers parameter_modifier
1607 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1608 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1609 if (((Parameter.Modifier)$1 & p2) == p2) {
1610 Error_DuplicateParameterModifier (lexer.Location, p2);
1612 switch (mod & ~Parameter.Modifier.This) {
1613 case Parameter.Modifier.REF:
1614 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1616 case Parameter.Modifier.OUT:
1617 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1620 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1631 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1632 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1634 $$ = Parameter.Modifier.REF;
1638 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1639 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1641 $$ = Parameter.Modifier.OUT;
1645 if ((valid_param_mod & ParameterModifierType.This) == 0)
1646 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1648 if (lang_version <= LanguageVersion.ISO_2)
1649 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1651 $$ = Parameter.Modifier.This;
1656 : opt_attributes params_modifier type IDENTIFIER
1658 var lt = (LocatedToken) $4;
1659 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1661 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1663 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1665 var lt = (LocatedToken) $4;
1666 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1668 | opt_attributes params_modifier type error
1670 Error_SyntaxError (yyToken);
1672 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1679 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1680 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1682 | PARAMS parameter_modifier
1684 Parameter.Modifier mod = (Parameter.Modifier)$2;
1685 if ((mod & Parameter.Modifier.This) != 0) {
1686 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1688 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1691 | PARAMS params_modifier
1693 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1700 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1701 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1705 property_declaration
1709 member_declaration_name
1712 tmpComment = Lexer.consume_doc_comment ();
1716 var type = (FullNamedExpression) $3;
1717 current_property = new Property (current_type, type, (Modifiers) $2,
1718 (MemberName) $4, (Attributes) $1);
1720 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1721 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1723 current_type.AddMember (current_property);
1724 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1726 lexer.PropertyParsing = true;
1728 accessor_declarations
1730 lexer.PropertyParsing = false;
1733 current_property.DocComment = ConsumeStoredComment ();
1737 lbag.AppendToMember (current_property, GetLocation ($10));
1738 current_property = null;
1744 : opt_attributes opt_modifiers
1745 member_type indexer_declaration_name OPEN_BRACKET
1747 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1749 opt_formal_parameter_list CLOSE_BRACKET
1751 valid_param_mod = 0;
1752 var type = (FullNamedExpression) $3;
1753 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1755 current_property = indexer;
1757 current_type.AddIndexer (indexer);
1758 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1760 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1761 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1763 if (indexer.ParameterInfo.IsEmpty) {
1764 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1768 tmpComment = Lexer.consume_doc_comment ();
1769 Lexer.doc_state = XmlCommentState.Allowed;
1772 lexer.PropertyParsing = true;
1774 OPEN_BRACE accessor_declarations
1776 lexer.PropertyParsing = false;
1780 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1781 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1784 current_property.DocComment = ConsumeStoredComment ();
1786 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1787 current_property = null;
1792 accessor_declarations
1793 : get_accessor_declaration
1794 | get_accessor_declaration accessor_declarations
1795 | set_accessor_declaration
1796 | set_accessor_declaration accessor_declarations
1799 if (yyToken == Token.CLOSE_BRACE) {
1800 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1802 if (yyToken == Token.SEMICOLON)
1803 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1805 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1810 get_accessor_declaration
1811 : opt_attributes opt_modifiers GET
1813 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1814 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1817 if (current_property.Get != null) {
1818 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1821 if (current_property is Indexer) {
1822 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1823 (Attributes) $1, GetLocation ($3));
1825 current_property.Get = new Property.GetMethod (current_property,
1826 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1829 current_local_parameters = current_property.Get.ParameterInfo;
1830 lbag.AddMember (current_property.Get, mod_locations);
1831 lexer.PropertyParsing = false;
1836 current_property.Get.Block = (ToplevelBlock) $5;
1838 if (current_container.Kind == MemberKind.Interface) {
1839 report.Error (531, current_property.Get.Block.StartLocation,
1840 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1844 current_local_parameters = null;
1845 lexer.PropertyParsing = true;
1848 if (Lexer.doc_state == XmlCommentState.Error)
1849 Lexer.doc_state = XmlCommentState.NotAllowed;
1853 set_accessor_declaration
1854 : opt_attributes opt_modifiers SET
1856 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1857 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1860 if (current_property.Set != null) {
1861 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1864 if (current_property is Indexer) {
1865 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1866 ParametersCompiled.MergeGenerated (compiler,
1867 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1868 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1870 (Attributes) $1, GetLocation ($3));
1872 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1873 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1874 (Attributes) $1, GetLocation ($3));
1877 current_local_parameters = current_property.Set.ParameterInfo;
1878 lbag.AddMember (current_property.Set, mod_locations);
1879 lexer.PropertyParsing = false;
1884 current_property.Set.Block = (ToplevelBlock) $5;
1886 if (current_container.Kind == MemberKind.Interface) {
1887 report.Error (531, current_property.Set.Block.StartLocation,
1888 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1892 current_local_parameters = null;
1893 lexer.PropertyParsing = true;
1896 && Lexer.doc_state == XmlCommentState.Error)
1897 Lexer.doc_state = XmlCommentState.NotAllowed;
1910 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1915 interface_declaration
1922 type_declaration_name
1924 lexer.ConstraintsParsing = true;
1925 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1926 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1929 opt_type_parameter_constraints_clauses
1931 lexer.ConstraintsParsing = false;
1934 current_container.SetConstraints ((List<Constraints>) $9);
1937 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1938 Lexer.doc_state = XmlCommentState.Allowed;
1941 lexer.parsing_modifiers = true;
1943 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1945 --lexer.parsing_declaration;
1947 Lexer.doc_state = XmlCommentState.Allowed;
1952 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1954 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
1956 $$ = pop_current_class ();
1958 | opt_attributes opt_modifiers opt_partial INTERFACE error
1960 Error_SyntaxError (yyToken);
1964 opt_interface_member_declarations
1966 | interface_member_declarations
1969 interface_member_declarations
1970 : interface_member_declaration
1972 lexer.parsing_modifiers = true;
1973 lexer.parsing_block = 0;
1975 | interface_member_declarations interface_member_declaration
1977 lexer.parsing_modifiers = true;
1978 lexer.parsing_block = 0;
1982 interface_member_declaration
1983 : constant_declaration
1985 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1989 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1991 | method_declaration
1992 | property_declaration
1994 | indexer_declaration
1995 | operator_declaration
1997 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1999 | constructor_declaration
2001 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
2005 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
2009 operator_declaration
2010 : opt_attributes opt_modifiers operator_declarator
2015 OperatorDeclaration decl = (OperatorDeclaration) $3;
2017 Operator op = new Operator (
2018 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2019 current_local_parameters,
2020 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2022 if (op.Block == null)
2023 op.ParameterInfo.CheckParameters (op);
2026 op.DocComment = tmpComment;
2027 Lexer.doc_state = XmlCommentState.Allowed;
2030 // Note again, checking is done in semantic analysis
2031 current_type.AddOperator (op);
2033 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2036 current_local_parameters = null;
2042 | SEMICOLON { $$ = null; }
2046 : type_expression_or_array
2049 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2050 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2055 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2057 valid_param_mod = ParameterModifierType.DefaultValue;
2059 opt_formal_parameter_list CLOSE_PARENS
2061 valid_param_mod = 0;
2063 Location loc = GetLocation ($2);
2064 Operator.OpType op = (Operator.OpType) $3;
2065 current_local_parameters = (ParametersCompiled)$6;
2067 int p_count = current_local_parameters.Count;
2069 if (op == Operator.OpType.Addition)
2070 op = Operator.OpType.UnaryPlus;
2071 else if (op == Operator.OpType.Subtraction)
2072 op = Operator.OpType.UnaryNegation;
2075 if (IsUnaryOperator (op)) {
2077 report.Error (1020, loc, "Overloadable binary operator expected");
2078 } else if (p_count != 1) {
2079 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2080 Operator.GetName (op));
2084 report.Error (1019, loc, "Overloadable unary operator expected");
2085 } else if (p_count != 2) {
2086 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2087 Operator.GetName (op));
2092 tmpComment = Lexer.consume_doc_comment ();
2093 Lexer.doc_state = XmlCommentState.NotAllowed;
2096 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2097 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2099 | conversion_operator_declarator
2102 overloadable_operator
2104 : BANG { $$ = Operator.OpType.LogicalNot; }
2105 | TILDE { $$ = Operator.OpType.OnesComplement; }
2106 | OP_INC { $$ = Operator.OpType.Increment; }
2107 | OP_DEC { $$ = Operator.OpType.Decrement; }
2108 | TRUE { $$ = Operator.OpType.True; }
2109 | FALSE { $$ = Operator.OpType.False; }
2110 // Unary and binary:
2111 | PLUS { $$ = Operator.OpType.Addition; }
2112 | MINUS { $$ = Operator.OpType.Subtraction; }
2114 | STAR { $$ = Operator.OpType.Multiply; }
2115 | DIV { $$ = Operator.OpType.Division; }
2116 | PERCENT { $$ = Operator.OpType.Modulus; }
2117 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2118 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2119 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2120 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2121 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2122 | OP_EQ { $$ = Operator.OpType.Equality; }
2123 | OP_NE { $$ = Operator.OpType.Inequality; }
2124 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2125 | OP_LT { $$ = Operator.OpType.LessThan; }
2126 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2127 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2130 conversion_operator_declarator
2131 : IMPLICIT OPERATOR type OPEN_PARENS
2133 valid_param_mod = ParameterModifierType.DefaultValue;
2135 opt_formal_parameter_list CLOSE_PARENS
2137 valid_param_mod = 0;
2139 Location loc = GetLocation ($2);
2140 current_local_parameters = (ParametersCompiled)$6;
2142 if (current_local_parameters.Count != 1) {
2143 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2147 tmpComment = Lexer.consume_doc_comment ();
2148 Lexer.doc_state = XmlCommentState.NotAllowed;
2151 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2152 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2154 | EXPLICIT OPERATOR type OPEN_PARENS
2156 valid_param_mod = ParameterModifierType.DefaultValue;
2158 opt_formal_parameter_list CLOSE_PARENS
2160 valid_param_mod = 0;
2162 Location loc = GetLocation ($2);
2163 current_local_parameters = (ParametersCompiled)$6;
2165 if (current_local_parameters.Count != 1) {
2166 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2170 tmpComment = Lexer.consume_doc_comment ();
2171 Lexer.doc_state = XmlCommentState.NotAllowed;
2174 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2175 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2179 Error_SyntaxError (yyToken);
2180 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2181 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2185 Error_SyntaxError (yyToken);
2186 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2187 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2191 constructor_declaration
2192 : constructor_declarator
2195 Constructor c = (Constructor) $1;
2196 c.Block = (ToplevelBlock) $2;
2199 c.DocComment = ConsumeStoredComment ();
2201 current_local_parameters = null;
2203 Lexer.doc_state = XmlCommentState.Allowed;
2207 constructor_declarator
2213 tmpComment = Lexer.consume_doc_comment ();
2214 Lexer.doc_state = XmlCommentState.Allowed;
2217 valid_param_mod = ParameterModifierType.All;
2219 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2221 valid_param_mod = 0;
2222 current_local_parameters = (ParametersCompiled) $6;
2224 var lt = (LocatedToken) $3;
2225 var mods = (Modifiers) $2;
2226 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2228 if (lt.Value != current_container.MemberName.Name) {
2229 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2230 } else if ((mods & Modifiers.STATIC) != 0) {
2231 if ((mods & Modifiers.AccessibilityMask) != 0){
2232 report.Error (515, c.Location,
2233 "`{0}': static constructor cannot have an access modifier",
2234 c.GetSignatureForError ());
2238 current_type.AddConstructor (c);
2239 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2243 // start block here, so possible anonymous methods inside
2244 // constructor initializer can get correct parent block
2246 start_block (lexer.Location);
2248 opt_constructor_initializer
2251 var c = (Constructor) $8;
2252 c.Initializer = (ConstructorInitializer) $9;
2255 report.Error (514, c.Location,
2256 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2257 c.GetSignatureForError ());
2267 | SEMICOLON { current_block = null; $$ = null; }
2270 opt_constructor_initializer
2272 | constructor_initializer
2275 constructor_initializer
2276 : COLON BASE OPEN_PARENS
2278 ++lexer.parsing_block;
2280 opt_argument_list CLOSE_PARENS
2282 --lexer.parsing_block;
2283 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2284 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2286 | COLON THIS OPEN_PARENS
2288 ++lexer.parsing_block;
2290 opt_argument_list CLOSE_PARENS
2292 --lexer.parsing_block;
2293 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2294 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2298 Error_SyntaxError (yyToken);
2299 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2300 lbag.AddLocation ($$, GetLocation ($1));
2304 Error_SyntaxError (yyToken);
2309 destructor_declaration
2310 : opt_attributes opt_modifiers TILDE
2313 tmpComment = Lexer.consume_doc_comment ();
2314 Lexer.doc_state = XmlCommentState.NotAllowed;
2317 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2319 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2321 var lt = (LocatedToken) $5;
2322 if (lt.Value != current_container.MemberName.Name){
2323 report.Error (574, lt.Location, "Name of destructor must match name of class");
2324 } else if (current_container.Kind != MemberKind.Class){
2325 report.Error (575, lt.Location, "Only class types can contain destructor");
2328 Destructor d = new Destructor (current_type, (Modifiers) $2,
2329 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2331 d.DocComment = ConsumeStoredComment ();
2333 d.Block = (ToplevelBlock) $8;
2334 current_type.AddMember (d);
2335 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2337 current_local_parameters = null;
2344 EVENT type member_declaration_name
2346 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2347 current_type.AddMember (current_event_field);
2349 if (current_event_field.MemberName.ExplicitInterface != null) {
2350 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2351 current_event_field.GetSignatureForError ());
2354 $$ = current_event_field;
2356 opt_event_initializer
2357 opt_event_declarators
2361 current_event_field.DocComment = Lexer.consume_doc_comment ();
2362 Lexer.doc_state = XmlCommentState.Allowed;
2365 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2366 current_event_field = null;
2370 EVENT type member_declaration_name
2373 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2374 current_type.AddMember (current_event);
2375 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2377 lexer.EventParsing = true;
2379 event_accessor_declarations
2381 if (current_container.Kind == MemberKind.Interface)
2382 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2384 lexer.EventParsing = false;
2389 current_event.DocComment = Lexer.consume_doc_comment ();
2390 Lexer.doc_state = XmlCommentState.Allowed;
2393 lbag.AppendToMember (current_event, GetLocation ($9));
2394 current_event = null;
2395 current_local_parameters = null;
2401 Error_SyntaxError (yyToken);
2403 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2407 opt_event_initializer
2411 ++lexer.parsing_block;
2413 event_variable_initializer
2415 --lexer.parsing_block;
2416 current_event_field.Initializer = (Expression) $3;
2420 opt_event_declarators
2428 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2430 | event_declarators event_declarator
2432 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2439 var lt = (LocatedToken) $2;
2440 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2441 lbag.AddLocation ($$, GetLocation ($1));
2443 | COMMA IDENTIFIER ASSIGN
2445 ++lexer.parsing_block;
2447 event_variable_initializer
2449 --lexer.parsing_block;
2450 var lt = (LocatedToken) $2;
2451 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2452 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2456 event_variable_initializer
2458 if (current_container.Kind == MemberKind.Interface) {
2459 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2460 current_event_field.GetSignatureForError ());
2463 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2464 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2465 current_event_field.GetSignatureForError ());
2468 variable_initializer
2474 event_accessor_declarations
2475 : add_accessor_declaration remove_accessor_declaration
2476 | remove_accessor_declaration add_accessor_declaration
2477 | add_accessor_declaration
2479 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2480 current_event.GetSignatureForError ());
2482 | remove_accessor_declaration
2484 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2485 current_event.GetSignatureForError ());
2489 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2494 add_accessor_declaration
2495 : opt_attributes opt_modifiers ADD
2497 if ($2 != ModifierNone) {
2498 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2501 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2502 current_local_parameters = current_event.Add.ParameterInfo;
2504 lbag.AddMember (current_event.Add, mod_locations);
2505 lexer.EventParsing = false;
2507 event_accessor_block
2509 lexer.EventParsing = true;
2511 current_event.Add.Block = (ToplevelBlock) $5;
2513 if (current_container.Kind == MemberKind.Interface) {
2514 report.Error (531, current_event.Add.Block.StartLocation,
2515 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2518 current_local_parameters = null;
2522 remove_accessor_declaration
2523 : opt_attributes opt_modifiers REMOVE
2525 if ($2 != ModifierNone) {
2526 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2529 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2530 current_local_parameters = current_event.Remove.ParameterInfo;
2532 lbag.AddMember (current_event.Remove, mod_locations);
2533 lexer.EventParsing = false;
2535 event_accessor_block
2537 lexer.EventParsing = true;
2539 current_event.Remove.Block = (ToplevelBlock) $5;
2541 if (current_container.Kind == MemberKind.Interface) {
2542 report.Error (531, current_event.Remove.Block.StartLocation,
2543 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2546 current_local_parameters = null;
2550 event_accessor_block
2553 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2559 attributes_without_members
2560 : attribute_sections CLOSE_BRACE
2562 current_type.UnattachedAttributes = (Attributes) $1;
2563 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2564 lexer.putback ('}');
2568 // For full ast try to recover incomplete ambiguous member
2569 // declaration in form on class X { public int }
2571 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2573 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2575 lexer.putback ('}');
2577 lexer.parsing_generic_declaration = false;
2578 FullNamedExpression type = (FullNamedExpression) $3;
2579 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2580 current_type.AddField (current_field);
2588 ENUM type_declaration_name
2592 enumTypeComment = Lexer.consume_doc_comment ();
2597 Lexer.doc_state = XmlCommentState.Allowed;
2599 MemberName name = (MemberName) $4;
2600 if (name.IsGeneric) {
2601 report.Error (1675, name.Location, "Enums cannot have type parameters");
2604 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2606 opt_enum_member_declarations
2608 lexer.parsing_modifiers = true;
2610 // here will be evaluated after CLOSE_BLACE is consumed.
2612 Lexer.doc_state = XmlCommentState.Allowed;
2614 CLOSE_BRACE opt_semicolon
2617 current_container.DocComment = enumTypeComment;
2619 --lexer.parsing_declaration;
2622 // em.DocComment = ev.DocComment;
2624 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2625 $$ = pop_current_class ();
2633 var te = $2 as TypeExpression;
2634 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2635 Enum.Error_1008 (GetLocation ($2), report);
2641 Error_TypeExpected (GetLocation ($1));
2646 opt_enum_member_declarations
2648 | enum_member_declarations
2649 | enum_member_declarations COMMA
2651 lbag.AddLocation ($1, GetLocation ($2));
2655 enum_member_declarations
2656 : enum_member_declaration
2657 | enum_member_declarations COMMA enum_member_declaration
2659 lbag.AddLocation ($1, GetLocation ($2));
2664 enum_member_declaration
2665 : opt_attributes IDENTIFIER
2667 var lt = (LocatedToken) $2;
2668 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2669 ((Enum) current_type).AddEnumMember (em);
2672 em.DocComment = Lexer.consume_doc_comment ();
2673 Lexer.doc_state = XmlCommentState.Allowed;
2678 | opt_attributes IDENTIFIER
2680 ++lexer.parsing_block;
2682 tmpComment = Lexer.consume_doc_comment ();
2683 Lexer.doc_state = XmlCommentState.NotAllowed;
2686 ASSIGN constant_expression
2688 --lexer.parsing_block;
2690 var lt = (LocatedToken) $2;
2691 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2692 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2693 ((Enum) current_type).AddEnumMember (em);
2696 em.DocComment = ConsumeStoredComment ();
2700 | opt_attributes IDENTIFIER error
2702 Error_SyntaxError (yyToken);
2704 var lt = (LocatedToken) $2;
2705 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2706 ((Enum) current_type).AddEnumMember (em);
2709 em.DocComment = Lexer.consume_doc_comment ();
2710 Lexer.doc_state = XmlCommentState.Allowed;
2715 | attributes_without_members
2718 delegate_declaration
2722 member_type type_declaration_name
2725 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2727 opt_formal_parameter_list CLOSE_PARENS
2729 valid_param_mod = 0;
2731 ParametersCompiled p = (ParametersCompiled) $8;
2733 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2735 p.CheckParameters (del);
2737 current_container.AddTypeContainer (del);
2739 current_delegate = del;
2740 lexer.ConstraintsParsing = true;
2742 opt_type_parameter_constraints_clauses
2744 lexer.ConstraintsParsing = false;
2749 current_delegate.DocComment = Lexer.consume_doc_comment ();
2750 Lexer.doc_state = XmlCommentState.Allowed;
2754 current_delegate.SetConstraints ((List<Constraints>) $11);
2755 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2757 $$ = current_delegate;
2759 current_delegate = null;
2767 if (lang_version < LanguageVersion.ISO_2)
2768 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2770 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2774 namespace_or_type_expr
2776 | qualified_alias_member IDENTIFIER opt_type_argument_list
2778 var lt1 = (LocatedToken) $1;
2779 var lt2 = (LocatedToken) $2;
2781 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2782 lbag.AddLocation ($$, GetLocation ($2));
2788 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2790 var lt = (LocatedToken) $3;
2791 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2792 lbag.AddLocation ($$, GetLocation ($2));
2797 : IDENTIFIER opt_type_argument_list
2799 var lt = (LocatedToken) $1;
2800 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2805 // Generics arguments (any type, without attributes)
2807 opt_type_argument_list
2809 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2811 if (lang_version < LanguageVersion.ISO_2)
2812 FeatureIsNotAvailable (GetLocation ($1), "generics");
2816 | OP_GENERICS_LT error
2818 Error_TypeExpected (lexer.Location);
2819 $$ = new TypeArguments ();
2826 TypeArguments type_args = new TypeArguments ();
2827 type_args.Add ((FullNamedExpression) $1);
2830 | type_arguments COMMA type
2832 TypeArguments type_args = (TypeArguments) $1;
2833 type_args.Add ((FullNamedExpression) $3);
2839 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2841 type_declaration_name
2844 lexer.parsing_generic_declaration = true;
2846 opt_type_parameter_list
2848 lexer.parsing_generic_declaration = false;
2849 var lt = (LocatedToken) $1;
2850 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2854 member_declaration_name
2855 : method_declaration_name
2857 MemberName mn = (MemberName)$1;
2858 if (mn.TypeParameters != null)
2859 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2860 mn.GetSignatureForError ()));
2864 method_declaration_name
2865 : type_declaration_name
2866 | explicit_interface IDENTIFIER opt_type_parameter_list
2868 lexer.parsing_generic_declaration = false;
2869 var lt = (LocatedToken) $2;
2870 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2874 indexer_declaration_name
2877 lexer.parsing_generic_declaration = false;
2878 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2880 | explicit_interface THIS
2882 lexer.parsing_generic_declaration = false;
2883 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2888 : IDENTIFIER opt_type_argument_list DOT
2890 var lt = (LocatedToken) $1;
2891 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2892 lbag.AddLocation ($$, GetLocation ($3));
2894 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2896 var lt1 = (LocatedToken) $1;
2897 var lt2 = (LocatedToken) $2;
2899 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2900 lbag.AddLocation ($$, GetLocation ($4));
2902 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2904 var lt = (LocatedToken) $2;
2905 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2906 lbag.AddLocation ($$, GetLocation ($4));
2910 opt_type_parameter_list
2912 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2914 if (lang_version < LanguageVersion.ISO_2)
2915 FeatureIsNotAvailable (GetLocation ($1), "generics");
2918 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2925 var tparams = new TypeParameters ();
2926 tparams.Add ((TypeParameter)$1);
2929 | type_parameters COMMA type_parameter
2931 var tparams = (TypeParameters) $1;
2932 tparams.Add ((TypeParameter)$3);
2934 lbag.AddLocation ($3, GetLocation ($3));
2939 : opt_attributes opt_type_parameter_variance IDENTIFIER
2941 var lt = (LocatedToken)$3;
2942 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (VarianceDecl) $2);
2946 if (GetTokenName (yyToken) == "type")
2947 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2949 Error_SyntaxError (yyToken);
2951 $$ = new TypeParameter (MemberName.Null, null, null);
2956 // All types where void is allowed
2959 : type_expression_or_array
2962 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2969 lexer.parsing_generic_declaration = true;
2974 // A type which does not allow `void' to be used
2977 : type_expression_or_array
2980 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2981 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2989 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2990 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2995 : type_expression_or_array
2998 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2999 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
3003 type_expression_or_array
3005 | type_expression rank_specifiers
3007 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3012 : namespace_or_type_expr opt_nullable
3015 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3017 var sn = $1 as SimpleName;
3018 if (sn != null && sn.Name == "var")
3019 $$ = new VarExpr (sn.Location);
3024 | namespace_or_type_expr pointer_stars
3026 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3028 | builtin_types opt_nullable
3031 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3033 | builtin_types pointer_stars
3035 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3037 | VOID pointer_stars
3039 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3046 var types = new List<FullNamedExpression> (2);
3047 types.Add ((FullNamedExpression) $1);
3050 | type_list COMMA base_type_name
3052 var types = (List<FullNamedExpression>) $1;
3053 types.Add ((FullNamedExpression) $3);
3061 if ($1 is ComposedCast) {
3062 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3069 * replaces all the productions for isolating the various
3070 * simple types, but we need this to reuse it easily in variable_type
3073 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3074 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3075 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3076 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3077 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3078 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3083 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3084 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3085 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3086 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3087 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3088 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3089 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3090 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3091 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3095 // Expressions, section 7.5
3100 : primary_expression_or_type
3102 | array_creation_expression
3103 | parenthesized_expression
3104 | default_value_expression
3105 | invocation_expression
3109 | post_increment_expression
3110 | post_decrement_expression
3111 | object_or_delegate_creation_expression
3112 | anonymous_type_expression
3115 | checked_expression
3116 | unchecked_expression
3117 | pointer_member_access
3118 | anonymous_method_expression
3119 | undocumented_expressions
3122 primary_expression_or_type
3123 : IDENTIFIER opt_type_argument_list
3125 var lt = (LocatedToken) $1;
3126 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3128 | IDENTIFIER GENERATE_COMPLETION {
3129 var lt = (LocatedToken) $1;
3130 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3138 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3142 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3143 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3148 // Here is the trick, tokenizer may think that parens is a special but
3149 // parser is interested in open parens only, so we merge them.
3150 // Consider: if (a)foo ();
3158 // Use this production to accept closing parenthesis or
3159 // performing completion
3163 | COMPLETE_COMPLETION
3167 parenthesized_expression
3168 : OPEN_PARENS expression CLOSE_PARENS
3170 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3171 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3173 | OPEN_PARENS expression COMPLETE_COMPLETION
3175 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3180 : primary_expression 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 | builtin_types DOT identifier_inside_body opt_type_argument_list
3188 var lt = (LocatedToken) $3;
3189 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3190 lbag.AddLocation ($$, GetLocation ($2));
3192 | BASE DOT identifier_inside_body opt_type_argument_list
3194 var lt = (LocatedToken) $3;
3195 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3196 lbag.AddLocation ($$, GetLocation ($2));
3198 | qualified_alias_member identifier_inside_body opt_type_argument_list
3200 var lt1 = (LocatedToken) $1;
3201 var lt2 = (LocatedToken) $2;
3203 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3204 lbag.AddLocation ($$, GetLocation ($2));
3206 | primary_expression DOT GENERATE_COMPLETION {
3207 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3209 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3210 var lt = (LocatedToken) $3;
3211 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3213 | builtin_types DOT GENERATE_COMPLETION
3215 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3217 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3218 var lt = (LocatedToken) $3;
3219 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3223 invocation_expression
3224 : primary_expression open_parens_any opt_argument_list close_parens
3226 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3227 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3229 | primary_expression open_parens_any argument_list error
3231 Error_SyntaxError (yyToken);
3233 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3234 lbag.AddLocation ($$, GetLocation ($2));
3236 | primary_expression open_parens_any error
3238 Error_SyntaxError (yyToken);
3240 $$ = new Invocation ((Expression) $1, null);
3241 lbag.AddLocation ($$, GetLocation ($2));
3245 opt_object_or_collection_initializer
3246 : /* empty */ { $$ = null; }
3247 | object_or_collection_initializer
3250 object_or_collection_initializer
3251 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3254 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3256 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3258 lbag.AddLocation ($$, GetLocation ($3));
3260 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3262 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3263 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3267 opt_member_initializer_list
3268 : /* empty */ { $$ = null; }
3269 | member_initializer_list
3275 member_initializer_list
3276 : member_initializer
3278 var a = new List<Expression> ();
3279 a.Add ((Expression) $1);
3282 | member_initializer_list COMMA member_initializer
3284 var a = (List<Expression>)$1;
3285 a.Add ((Expression) $3);
3288 | member_initializer_list error {
3289 Error_SyntaxError (yyToken);
3295 : IDENTIFIER ASSIGN initializer_value
3297 var lt = (LocatedToken) $1;
3298 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3299 lbag.AddLocation ($$, GetLocation ($2));
3301 | AWAIT ASSIGN initializer_value
3303 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3304 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3305 lbag.AddLocation ($$, GetLocation ($2));
3307 | GENERATE_COMPLETION
3309 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3311 | non_assignment_expression opt_COMPLETE_COMPLETION {
3312 CompletionSimpleName csn = $1 as CompletionSimpleName;
3314 $$ = new CollectionElementInitializer ((Expression)$1);
3316 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3318 | OPEN_BRACE expression_list CLOSE_BRACE
3321 $$ = new CollectionElementInitializer (GetLocation ($1));
3323 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3325 lbag.AddLocation ($$, GetLocation ($2));
3327 | OPEN_BRACE CLOSE_BRACE
3329 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3330 $$ = new CollectionElementInitializer (GetLocation ($1));
3331 lbag.AddLocation ($$, GetLocation ($2));
3337 | object_or_collection_initializer
3341 : /* empty */ { $$ = null; }
3346 : argument_or_named_argument
3348 Arguments list = new Arguments (4);
3349 list.Add ((Argument) $1);
3352 | argument_list COMMA argument
3354 Arguments list = (Arguments) $1;
3355 if (list [list.Count - 1] is NamedArgument)
3356 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3358 list.Add ((Argument) $3);
3361 | argument_list COMMA named_argument
3363 Arguments list = (Arguments) $1;
3364 NamedArgument a = (NamedArgument) $3;
3365 for (int i = 0; i < list.Count; ++i) {
3366 NamedArgument na = list [i] as NamedArgument;
3367 if (na != null && na.Name == a.Name)
3368 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3375 | argument_list COMMA error
3377 if (lexer.putback_char == -1)
3378 lexer.putback (')'); // TODO: Wrong but what can I do
3379 Error_SyntaxError (yyToken);
3384 report.Error (839, GetLocation ($1), "An argument is missing");
3392 $$ = new Argument ((Expression) $1);
3394 | non_simple_argument
3397 argument_or_named_argument
3403 : REF variable_reference
3405 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3406 lbag.AddLocation ($$, GetLocation ($1));
3408 | OUT variable_reference
3410 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3411 lbag.AddLocation ($$, GetLocation ($1));
3413 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3415 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3416 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3418 | ARGLIST OPEN_PARENS CLOSE_PARENS
3420 $$ = new Argument (new Arglist (GetLocation ($1)));
3421 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3430 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3432 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3433 lbag.AddLocation ($$, GetLocation ($4));
3435 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3437 Error_SyntaxError (yyToken);
3438 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3440 | primary_expression OPEN_BRACKET_EXPR error
3442 Error_SyntaxError (yyToken);
3443 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3448 : expression_or_error
3450 var list = new List<Expression> (4);
3451 list.Add ((Expression) $1);
3454 | expression_list COMMA expression_or_error
3456 var list = (List<Expression>) $1;
3457 list.Add ((Expression) $3);
3462 expression_list_arguments
3463 : expression_list_argument
3465 Arguments args = new Arguments (4);
3466 args.Add ((Argument) $1);
3469 | expression_list_arguments COMMA expression_list_argument
3471 Arguments args = (Arguments) $1;
3472 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3473 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3475 args.Add ((Argument) $3);
3480 expression_list_argument
3483 $$ = new Argument ((Expression) $1);
3491 $$ = new This (GetLocation ($1));
3496 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3498 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3499 lbag.AddLocation ($$, GetLocation ($4));
3501 | BASE OPEN_BRACKET error
3503 Error_SyntaxError (yyToken);
3504 $$ = new ElementAccess (null, null, GetLocation ($2));
3508 post_increment_expression
3509 : primary_expression OP_INC
3511 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3515 post_decrement_expression
3516 : primary_expression OP_DEC
3518 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3522 object_or_delegate_creation_expression
3523 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3526 if (lang_version <= LanguageVersion.ISO_2)
3527 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3529 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3531 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3534 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3536 | NEW new_expr_type object_or_collection_initializer
3538 if (lang_version <= LanguageVersion.ISO_2)
3539 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3541 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3545 array_creation_expression
3546 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3548 opt_array_initializer
3550 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3551 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3552 Next = (ComposedTypeSpecifier) $6
3553 }, (ArrayInitializer) $7, GetLocation ($1));
3554 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3556 | NEW new_expr_type rank_specifiers opt_array_initializer
3559 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3561 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3563 | NEW rank_specifier array_initializer
3565 if (lang_version <= LanguageVersion.ISO_2)
3566 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3568 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3570 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3572 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3573 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3575 | NEW new_expr_type error
3577 Error_SyntaxError (yyToken);
3578 // It can be any of new expression, create the most common one
3579 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3585 ++lexer.parsing_type;
3589 --lexer.parsing_type;
3594 anonymous_type_expression
3595 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3597 if (lang_version <= LanguageVersion.ISO_2)
3598 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3600 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3602 // TODO: lbag comma location
3603 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3607 anonymous_type_parameters_opt_comma
3608 : anonymous_type_parameters_opt
3609 | anonymous_type_parameters COMMA
3612 anonymous_type_parameters_opt
3614 | anonymous_type_parameters
3617 anonymous_type_parameters
3618 : anonymous_type_parameter
3620 var a = new List<AnonymousTypeParameter> (4);
3621 a.Add ((AnonymousTypeParameter) $1);
3624 | anonymous_type_parameters COMMA anonymous_type_parameter
3626 var a = (List<AnonymousTypeParameter>) $1;
3627 a.Add ((AnonymousTypeParameter) $3);
3632 anonymous_type_parameter
3633 : identifier_inside_body ASSIGN variable_initializer
3635 var lt = (LocatedToken)$1;
3636 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3637 lbag.AddLocation ($$, GetLocation ($2));
3639 | identifier_inside_body
3641 var lt = (LocatedToken)$1;
3642 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3643 lt.Value, lt.Location);
3647 MemberAccess ma = (MemberAccess) $1;
3648 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3652 report.Error (746, lexer.Location,
3653 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3665 | rank_specifier rank_specifiers
3667 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3673 : OPEN_BRACKET CLOSE_BRACKET
3675 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3676 lbag.AddLocation ($$, GetLocation ($2));
3678 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3680 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3681 lbag.AddLocation ($$, GetLocation ($3));
3690 | dim_separators COMMA
3692 $$ = ((int) $1) + 1;
3696 opt_array_initializer
3708 : OPEN_BRACE CLOSE_BRACE
3710 var ai = new ArrayInitializer (0, GetLocation ($1));
3711 ai.VariableDeclaration = current_variable;
3712 lbag.AddLocation (ai, GetLocation ($2));
3715 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3717 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3718 ai.VariableDeclaration = current_variable;
3720 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3722 lbag.AddLocation (ai, GetLocation ($4));
3728 variable_initializer_list
3729 : variable_initializer
3731 var list = new List<Expression> (4);
3732 list.Add ((Expression) $1);
3735 | variable_initializer_list COMMA variable_initializer
3737 var list = (List<Expression>) $1;
3738 list.Add ((Expression) $3);
3746 lexer.TypeOfParsing = true;
3748 open_parens_any typeof_type_expression CLOSE_PARENS
3750 lexer.TypeOfParsing = false;
3751 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3752 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3756 typeof_type_expression
3761 Error_TypeExpected (lexer.Location);
3767 : identifier_inside_body generic_dimension
3769 var lt = (LocatedToken) $1;
3771 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3773 | qualified_alias_member identifier_inside_body generic_dimension
3775 var lt1 = (LocatedToken) $1;
3776 var lt2 = (LocatedToken) $2;
3778 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3779 lbag.AddLocation ($$, GetLocation ($2));
3781 | unbound_type_name DOT identifier_inside_body
3783 var lt = (LocatedToken) $3;
3785 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3787 | unbound_type_name DOT identifier_inside_body generic_dimension
3789 var lt = (LocatedToken) $3;
3791 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3793 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3795 var tne = (ATypeNameExpression) $1;
3796 if (tne.HasTypeArguments)
3797 Error_TypeExpected (GetLocation ($4));
3799 var lt = (LocatedToken) $3;
3800 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3807 if (lang_version < LanguageVersion.ISO_2)
3808 FeatureIsNotAvailable (GetLocation ($1), "generics");
3814 qualified_alias_member
3815 : IDENTIFIER DOUBLE_COLON
3817 var lt = (LocatedToken) $1;
3818 if (lang_version == LanguageVersion.ISO_1)
3819 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3826 : SIZEOF open_parens_any type CLOSE_PARENS
3828 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3829 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3831 | SIZEOF open_parens_any type error
3833 Error_SyntaxError (yyToken);
3835 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3836 lbag.AddLocation ($$, GetLocation ($2));
3841 : CHECKED open_parens_any expression CLOSE_PARENS
3843 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3844 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3848 Error_SyntaxError (yyToken);
3850 $$ = new CheckedExpr (null, GetLocation ($1));
3854 unchecked_expression
3855 : UNCHECKED open_parens_any expression CLOSE_PARENS
3857 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3858 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3862 Error_SyntaxError (yyToken);
3864 $$ = new UnCheckedExpr (null, GetLocation ($1));
3868 pointer_member_access
3869 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3871 var lt = (LocatedToken) $3;
3872 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3876 anonymous_method_expression
3877 : DELEGATE opt_anonymous_method_signature
3879 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3883 $$ = end_anonymous ((ParametersBlock) $4);
3885 | ASYNC DELEGATE opt_anonymous_method_signature
3887 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3891 $$ = end_anonymous ((ParametersBlock) $5);
3895 opt_anonymous_method_signature
3898 $$ = ParametersCompiled.Undefined;
3900 | anonymous_method_signature
3903 anonymous_method_signature
3906 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3908 opt_formal_parameter_list CLOSE_PARENS
3910 valid_param_mod = 0;
3915 default_value_expression
3916 : DEFAULT open_parens_any type CLOSE_PARENS
3918 if (lang_version < LanguageVersion.ISO_2)
3919 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3921 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3922 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3927 : primary_expression
3928 | BANG prefixed_unary_expression
3930 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3932 | TILDE prefixed_unary_expression
3934 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3936 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3938 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3939 lbag.AddLocation ($$, GetLocation ($3));
3941 | AWAIT prefixed_unary_expression
3944 if (current_anonymous_method is LambdaExpression) {
3945 report.Error (4034, GetLocation ($1),
3946 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3947 } else if (current_anonymous_method != null) {
3948 report.Error (4035, GetLocation ($1),
3949 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3950 } else if (interactive_async != null) {
3951 current_block.Explicit.RegisterAsyncAwait ();
3952 interactive_async = true;
3954 report.Error (4033, GetLocation ($1),
3955 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3958 current_block.Explicit.RegisterAsyncAwait ();
3961 $$ = new Await ((Expression) $2, GetLocation ($1));
3965 Error_SyntaxError (yyToken);
3967 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3971 Error_SyntaxError (yyToken);
3973 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3975 | OPEN_PARENS_CAST type CLOSE_PARENS error
3977 Error_SyntaxError (yyToken);
3979 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3980 lbag.AddLocation ($$, GetLocation ($3));
3984 Error_SyntaxError (yyToken);
3986 $$ = new Await (null, GetLocation ($1));
3991 // The idea to split this out is from Rhys' grammar
3992 // to solve the problem with casts.
3994 prefixed_unary_expression
3996 | PLUS prefixed_unary_expression
3998 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
4000 | MINUS prefixed_unary_expression
4002 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
4004 | OP_INC prefixed_unary_expression
4006 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
4008 | OP_DEC prefixed_unary_expression
4010 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
4012 | STAR prefixed_unary_expression
4014 $$ = new Indirection ((Expression) $2, GetLocation ($1));
4016 | BITWISE_AND prefixed_unary_expression
4018 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
4022 Error_SyntaxError (yyToken);
4024 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4028 Error_SyntaxError (yyToken);
4030 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4034 Error_SyntaxError (yyToken);
4036 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4040 Error_SyntaxError (yyToken);
4042 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4046 Error_SyntaxError (yyToken);
4048 $$ = new Indirection (null, GetLocation ($1));
4052 Error_SyntaxError (yyToken);
4054 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4058 multiplicative_expression
4059 : prefixed_unary_expression
4060 | multiplicative_expression STAR prefixed_unary_expression
4062 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4063 lbag.AddLocation ($$, GetLocation ($2));
4065 | multiplicative_expression DIV prefixed_unary_expression
4067 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4068 lbag.AddLocation ($$, GetLocation ($2));
4070 | multiplicative_expression PERCENT prefixed_unary_expression
4072 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4073 lbag.AddLocation ($$, GetLocation ($2));
4075 | multiplicative_expression STAR error
4077 Error_SyntaxError (yyToken);
4079 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4080 lbag.AddLocation ($$, GetLocation ($2));
4082 | multiplicative_expression DIV error
4084 Error_SyntaxError (yyToken);
4086 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4087 lbag.AddLocation ($$, GetLocation ($2));
4089 | multiplicative_expression PERCENT error
4091 Error_SyntaxError (yyToken);
4093 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4094 lbag.AddLocation ($$, GetLocation ($2));
4099 : multiplicative_expression
4100 | additive_expression PLUS multiplicative_expression
4102 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4103 lbag.AddLocation ($$, GetLocation ($2));
4105 | additive_expression MINUS multiplicative_expression
4107 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4108 lbag.AddLocation ($$, GetLocation ($2));
4110 | additive_expression AS type
4112 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4114 | additive_expression IS type
4116 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4118 | additive_expression PLUS error
4120 Error_SyntaxError (yyToken);
4122 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4123 lbag.AddLocation ($$, GetLocation ($2));
4125 | additive_expression MINUS error
4127 Error_SyntaxError (yyToken);
4129 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4130 lbag.AddLocation ($$, GetLocation ($2));
4132 | additive_expression AS error
4134 Error_SyntaxError (yyToken);
4136 $$ = new As ((Expression) $1, null, GetLocation ($2));
4138 | additive_expression IS error
4140 Error_SyntaxError (yyToken);
4142 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4147 : additive_expression
4148 | shift_expression OP_SHIFT_LEFT additive_expression
4150 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4151 lbag.AddLocation ($$, GetLocation ($2));
4153 | shift_expression OP_SHIFT_RIGHT additive_expression
4155 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4156 lbag.AddLocation ($$, GetLocation ($2));
4158 | shift_expression OP_SHIFT_LEFT error
4160 Error_SyntaxError (yyToken);
4162 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4163 lbag.AddLocation ($$, GetLocation ($2));
4165 | shift_expression OP_SHIFT_RIGHT error
4167 Error_SyntaxError (yyToken);
4169 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4170 lbag.AddLocation ($$, GetLocation ($2));
4174 relational_expression
4176 | relational_expression OP_LT shift_expression
4178 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4179 lbag.AddLocation ($$, GetLocation ($2));
4181 | relational_expression OP_GT shift_expression
4183 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4184 lbag.AddLocation ($$, GetLocation ($2));
4186 | relational_expression OP_LE shift_expression
4188 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4189 lbag.AddLocation ($$, GetLocation ($2));
4191 | relational_expression OP_GE shift_expression
4193 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4194 lbag.AddLocation ($$, GetLocation ($2));
4196 | relational_expression OP_LT error
4198 Error_SyntaxError (yyToken);
4200 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4201 lbag.AddLocation ($$, GetLocation ($2));
4203 | relational_expression OP_GT error
4205 Error_SyntaxError (yyToken);
4207 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4208 lbag.AddLocation ($$, GetLocation ($2));
4210 | relational_expression OP_LE error
4212 Error_SyntaxError (yyToken);
4214 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4215 lbag.AddLocation ($$, GetLocation ($2));
4217 | relational_expression OP_GE error
4219 Error_SyntaxError (yyToken);
4221 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4222 lbag.AddLocation ($$, GetLocation ($2));
4227 : relational_expression
4228 | equality_expression OP_EQ relational_expression
4230 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4231 lbag.AddLocation ($$, GetLocation ($2));
4233 | equality_expression OP_NE relational_expression
4235 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4236 lbag.AddLocation ($$, GetLocation ($2));
4238 | equality_expression OP_EQ error
4240 Error_SyntaxError (yyToken);
4242 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4243 lbag.AddLocation ($$, GetLocation ($2));
4245 | equality_expression OP_NE error
4247 Error_SyntaxError (yyToken);
4249 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4250 lbag.AddLocation ($$, GetLocation ($2));
4255 : equality_expression
4256 | and_expression BITWISE_AND equality_expression
4258 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4259 lbag.AddLocation ($$, GetLocation ($2));
4261 | and_expression BITWISE_AND error
4263 Error_SyntaxError (yyToken);
4265 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4266 lbag.AddLocation ($$, GetLocation ($2));
4270 exclusive_or_expression
4272 | exclusive_or_expression CARRET and_expression
4274 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4275 lbag.AddLocation ($$, GetLocation ($2));
4277 | exclusive_or_expression CARRET error
4279 Error_SyntaxError (yyToken);
4281 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4282 lbag.AddLocation ($$, GetLocation ($2));
4286 inclusive_or_expression
4287 : exclusive_or_expression
4288 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4290 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4291 lbag.AddLocation ($$, GetLocation ($2));
4293 | inclusive_or_expression BITWISE_OR error
4295 Error_SyntaxError (yyToken);
4297 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4298 lbag.AddLocation ($$, GetLocation ($2));
4302 conditional_and_expression
4303 : inclusive_or_expression
4304 | conditional_and_expression OP_AND inclusive_or_expression
4306 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4307 lbag.AddLocation ($$, GetLocation ($2));
4309 | conditional_and_expression OP_AND error
4311 Error_SyntaxError (yyToken);
4313 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4314 lbag.AddLocation ($$, GetLocation ($2));
4318 conditional_or_expression
4319 : conditional_and_expression
4320 | conditional_or_expression OP_OR conditional_and_expression
4322 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4323 lbag.AddLocation ($$, GetLocation ($2));
4325 | conditional_or_expression OP_OR error
4327 Error_SyntaxError (yyToken);
4329 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4330 lbag.AddLocation ($$, GetLocation ($2));
4334 null_coalescing_expression
4335 : conditional_or_expression
4336 | conditional_or_expression OP_COALESCING null_coalescing_expression
4338 if (lang_version < LanguageVersion.ISO_2)
4339 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4341 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4342 lbag.AddLocation ($$, GetLocation ($2));
4346 conditional_expression
4347 : null_coalescing_expression
4348 | null_coalescing_expression INTERR expression COLON expression
4350 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4351 lbag.AddLocation ($$, GetLocation ($4));
4353 | null_coalescing_expression INTERR expression error
4355 Error_SyntaxError (yyToken);
4357 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4359 | null_coalescing_expression INTERR expression COLON error
4361 Error_SyntaxError (yyToken);
4363 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4364 lbag.AddLocation ($$, GetLocation ($4));
4366 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4368 Error_SyntaxError (Token.CLOSE_BRACE);
4370 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4371 lbag.AddLocation ($$, GetLocation ($4));
4372 lexer.putback ('}');
4376 assignment_expression
4377 : prefixed_unary_expression ASSIGN expression
4379 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4380 lbag.AddLocation ($$, GetLocation ($2));
4382 | prefixed_unary_expression OP_MULT_ASSIGN expression
4384 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4385 lbag.AddLocation ($$, GetLocation ($2));
4387 | prefixed_unary_expression OP_DIV_ASSIGN expression
4389 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4390 lbag.AddLocation ($$, GetLocation ($2));
4392 | prefixed_unary_expression OP_MOD_ASSIGN expression
4394 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4395 lbag.AddLocation ($$, GetLocation ($2));
4397 | prefixed_unary_expression OP_ADD_ASSIGN expression
4399 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4400 lbag.AddLocation ($$, GetLocation ($2));
4402 | prefixed_unary_expression OP_SUB_ASSIGN expression
4404 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4405 lbag.AddLocation ($$, GetLocation ($2));
4407 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4409 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4410 lbag.AddLocation ($$, GetLocation ($2));
4412 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4414 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4415 lbag.AddLocation ($$, GetLocation ($2));
4417 | prefixed_unary_expression OP_AND_ASSIGN expression
4419 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4420 lbag.AddLocation ($$, GetLocation ($2));
4422 | prefixed_unary_expression OP_OR_ASSIGN expression
4424 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4425 lbag.AddLocation ($$, GetLocation ($2));
4427 | prefixed_unary_expression OP_XOR_ASSIGN expression
4429 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4430 lbag.AddLocation ($$, GetLocation ($2));
4434 lambda_parameter_list
4437 var pars = new List<Parameter> (4);
4438 pars.Add ((Parameter) $1);
4442 | lambda_parameter_list COMMA lambda_parameter
4444 var pars = (List<Parameter>) $1;
4445 Parameter p = (Parameter)$3;
4446 if (pars[0].GetType () != p.GetType ()) {
4447 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4456 : parameter_modifier parameter_type identifier_inside_body
4458 var lt = (LocatedToken) $3;
4460 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4462 | parameter_type identifier_inside_body
4464 var lt = (LocatedToken) $2;
4466 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4470 var lt = (LocatedToken) $1;
4471 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4475 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4476 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4480 opt_lambda_parameter_list
4481 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4482 | lambda_parameter_list {
4483 var pars_list = (List<Parameter>) $1;
4484 $$ = new ParametersCompiled (pars_list.ToArray ());
4488 lambda_expression_body
4490 start_block (Location.Null);
4492 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4494 Block b = end_block (Location.Null);
4495 b.IsCompilerGenerated = true;
4496 b.AddStatement (new ContextualReturn ((Expression) $2));
4502 // Handles only cases like foo = x.FirstOrDefault (l => );
4503 // where we must restore current_variable
4504 Block b = end_block (Location.Null);
4505 b.IsCompilerGenerated = true;
4507 Error_SyntaxError (yyToken);
4516 Error_SyntaxError (yyToken);
4524 var lt = (LocatedToken) $1;
4525 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4526 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4528 lambda_expression_body
4530 $$ = end_anonymous ((ParametersBlock) $4);
4531 lbag.AddLocation ($$, GetLocation ($2));
4535 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4536 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4537 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4539 lambda_expression_body
4541 $$ = end_anonymous ((ParametersBlock) $4);
4542 lbag.AddLocation ($$, GetLocation ($2));
4544 | ASYNC identifier_inside_body ARROW
4546 var lt = (LocatedToken) $2;
4547 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4548 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4550 lambda_expression_body
4552 $$ = end_anonymous ((ParametersBlock) $5);
4553 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4555 | OPEN_PARENS_LAMBDA
4557 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4559 opt_lambda_parameter_list CLOSE_PARENS ARROW
4561 valid_param_mod = 0;
4562 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4564 lambda_expression_body
4566 $$ = end_anonymous ((ParametersBlock) $7);
4567 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4569 | ASYNC OPEN_PARENS_LAMBDA
4571 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4573 opt_lambda_parameter_list CLOSE_PARENS ARROW
4575 valid_param_mod = 0;
4576 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4578 lambda_expression_body
4580 $$ = end_anonymous ((ParametersBlock) $8);
4581 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4586 : assignment_expression
4587 | non_assignment_expression
4590 non_assignment_expression
4591 : conditional_expression
4596 $$ = new ArglistAccess (GetLocation ($1));
4600 undocumented_expressions
4601 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4603 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4604 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4606 | REFTYPE open_parens_any expression CLOSE_PARENS
4608 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4609 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4611 | MAKEREF open_parens_any expression CLOSE_PARENS
4613 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4614 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4625 $$ = new BooleanExpression ((Expression) $1);
4639 type_declaration_name
4641 lexer.ConstraintsParsing = true;
4643 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4644 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4645 FeatureIsNotAvailable (c.Location, "static classes");
4648 push_current_container (c, $3);
4651 opt_type_parameter_constraints_clauses
4653 lexer.ConstraintsParsing = false;
4656 current_container.SetConstraints ((List<Constraints>) $9);
4657 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4660 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4661 Lexer.doc_state = XmlCommentState.Allowed;
4664 lexer.parsing_modifiers = true;
4666 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4668 --lexer.parsing_declaration;
4670 Lexer.doc_state = XmlCommentState.Allowed;
4675 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
4677 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4679 $$ = pop_current_class ();
4687 { $$ = $1; } // location
4693 mod_locations = null;
4695 lexer.parsing_modifiers = false;
4699 lexer.parsing_modifiers = false;
4705 | modifiers modifier
4707 var m1 = (Modifiers) $1;
4708 var m2 = (Modifiers) $2;
4710 if ((m1 & m2) != 0) {
4711 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4712 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4713 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4714 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4715 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4716 "More than one protection modifier specified");
4727 StoreModifierLocation ($$, GetLocation ($1));
4729 if (current_container.Kind == MemberKind.Namespace)
4730 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4734 $$ = Modifiers.PUBLIC;
4735 StoreModifierLocation ($$, GetLocation ($1));
4739 $$ = Modifiers.PROTECTED;
4740 StoreModifierLocation ($$, GetLocation ($1));
4744 $$ = Modifiers.INTERNAL;
4745 StoreModifierLocation ($$, GetLocation ($1));
4749 $$ = Modifiers.PRIVATE;
4750 StoreModifierLocation ($$, GetLocation ($1));
4754 $$ = Modifiers.ABSTRACT;
4755 StoreModifierLocation ($$, GetLocation ($1));
4759 $$ = Modifiers.SEALED;
4760 StoreModifierLocation ($$, GetLocation ($1));
4764 $$ = Modifiers.STATIC;
4765 StoreModifierLocation ($$, GetLocation ($1));
4769 $$ = Modifiers.READONLY;
4770 StoreModifierLocation ($$, GetLocation ($1));
4774 $$ = Modifiers.VIRTUAL;
4775 StoreModifierLocation ($$, GetLocation ($1));
4779 $$ = Modifiers.OVERRIDE;
4780 StoreModifierLocation ($$, GetLocation ($1));
4784 $$ = Modifiers.EXTERN;
4785 StoreModifierLocation ($$, GetLocation ($1));
4789 $$ = Modifiers.VOLATILE;
4790 StoreModifierLocation ($$, GetLocation ($1));
4794 $$ = Modifiers.UNSAFE;
4795 StoreModifierLocation ($$, GetLocation ($1));
4796 if (!settings.Unsafe)
4797 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4801 $$ = Modifiers.ASYNC;
4802 StoreModifierLocation ($$, GetLocation ($1));
4810 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4812 | COLON type_list error
4814 Error_SyntaxError (yyToken);
4816 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4820 opt_type_parameter_constraints_clauses
4822 | type_parameter_constraints_clauses
4828 type_parameter_constraints_clauses
4829 : type_parameter_constraints_clause
4831 var constraints = new List<Constraints> (1);
4832 constraints.Add ((Constraints) $1);
4835 | type_parameter_constraints_clauses type_parameter_constraints_clause
4837 var constraints = (List<Constraints>) $1;
4838 Constraints new_constraint = (Constraints)$2;
4840 foreach (Constraints c in constraints) {
4841 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4842 report.Error (409, new_constraint.Location,
4843 "A constraint clause has already been specified for type parameter `{0}'",
4844 new_constraint.TypeParameter.Value);
4848 constraints.Add (new_constraint);
4853 type_parameter_constraints_clause
4854 : WHERE IDENTIFIER COLON type_parameter_constraints
4856 var lt = (LocatedToken) $2;
4857 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4858 lbag.AddLocation ($$, GetLocation ($3));
4860 | WHERE IDENTIFIER error
4862 Error_SyntaxError (yyToken);
4864 var lt = (LocatedToken) $2;
4865 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4869 type_parameter_constraints
4870 : type_parameter_constraint
4872 var constraints = new List<FullNamedExpression> (1);
4873 constraints.Add ((FullNamedExpression) $1);
4876 | type_parameter_constraints COMMA type_parameter_constraint
4878 var constraints = (List<FullNamedExpression>) $1;
4879 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4880 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4881 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4884 prev = $3 as SpecialContraintExpr;
4886 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4887 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4889 prev = constraints [0] as SpecialContraintExpr;
4890 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4891 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4896 constraints.Add ((FullNamedExpression) $3);
4901 type_parameter_constraint
4904 if ($1 is ComposedCast)
4905 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4909 | NEW OPEN_PARENS CLOSE_PARENS
4911 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4912 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4916 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4920 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4924 opt_type_parameter_variance
4929 | type_parameter_variance
4931 if (lang_version <= LanguageVersion.V_3)
4932 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4938 type_parameter_variance
4941 $$ = new VarianceDecl (Variance.Covariant, GetLocation ($1));
4945 $$ = new VarianceDecl (Variance.Contravariant, GetLocation ($1));
4954 // A block is "contained" on the following places:
4956 // property_declaration as part of the accessor body (get/set)
4957 // operator_declaration
4958 // constructor_declaration
4959 // destructor_declaration
4960 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4965 ++lexer.parsing_block;
4966 start_block (GetLocation ($1));
4968 opt_statement_list block_end
4977 --lexer.parsing_block;
4978 $$ = end_block (GetLocation ($1));
4980 | COMPLETE_COMPLETION
4982 --lexer.parsing_block;
4983 $$ = end_block (lexer.Location);
4991 ++lexer.parsing_block;
4992 current_block.StartLocation = GetLocation ($1);
4994 opt_statement_list CLOSE_BRACE
4996 --lexer.parsing_block;
4997 $$ = end_block (GetLocation ($4));
5008 | statement_list statement
5012 : block_variable_declaration
5014 current_block.AddStatement ((Statement) $1);
5016 | valid_declaration_statement
5018 current_block.AddStatement ((Statement) $1);
5023 Error_SyntaxError (yyToken);
5029 // The interactive_statement and its derivatives are only
5030 // used to provide a special version of `expression_statement'
5031 // that has a side effect of assigning the expression to
5034 interactive_statement_list
5035 : interactive_statement
5036 | interactive_statement_list interactive_statement
5039 interactive_statement
5040 : block_variable_declaration
5042 current_block.AddStatement ((Statement) $1);
5044 | interactive_valid_declaration_statement
5046 current_block.AddStatement ((Statement) $1);
5051 valid_declaration_statement
5054 | expression_statement
5055 | selection_statement
5056 | iteration_statement
5060 | unchecked_statement
5067 interactive_valid_declaration_statement
5070 | interactive_expression_statement
5071 | selection_statement
5072 | iteration_statement
5076 | unchecked_statement
5084 : valid_declaration_statement
5085 | block_variable_declaration
5087 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5092 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5097 Error_SyntaxError (yyToken);
5098 $$ = new EmptyStatement (GetLocation ($1));
5105 // Uses lexer.Location because semicolon location is not kept in quick mode
5106 $$ = new EmptyStatement (lexer.Location);
5111 : identifier_inside_body COLON
5113 var lt = (LocatedToken) $1;
5114 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5115 lbag.AddLocation (labeled, GetLocation ($2));
5116 current_block.AddLabel (labeled);
5117 current_block.AddStatement (labeled);
5123 : variable_type_simple
5124 | variable_type_simple rank_specifiers
5127 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5129 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5134 * The following is from Rhys' grammar:
5135 * > Types in local variable declarations must be recognized as
5136 * > expressions to prevent reduce/reduce errors in the grammar.
5137 * > The expressions are converted into types during semantic analysis.
5139 variable_type_simple
5140 : primary_expression_or_type opt_nullable
5142 // Ok, the above "primary_expression" is there to get rid of
5143 // both reduce/reduce and shift/reduces in the grammar, it should
5144 // really just be "type_name". If you use type_name, a reduce/reduce
5145 // creeps up. If you use namespace_or_type_name (which is all we need
5146 // really) two shift/reduces appear.
5149 // So the super-trick is that primary_expression
5150 // can only be either a SimpleName or a MemberAccess.
5151 // The MemberAccess case arises when you have a fully qualified type-name like :
5153 // SimpleName is when you have
5156 Expression expr = (Expression) $1;
5158 SimpleName sn = expr as SimpleName;
5159 if (sn != null && sn.Name == "var")
5160 $$ = new VarExpr (sn.Location);
5163 } else if (expr is ATypeNameExpression) {
5164 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5166 Error_ExpectingTypeName (expr);
5170 | primary_expression_or_type pointer_stars
5172 ATypeNameExpression expr = $1 as ATypeNameExpression;
5175 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5177 Error_ExpectingTypeName ((Expression)$1);
5181 | builtin_types opt_nullable
5186 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5188 | builtin_types pointer_stars
5190 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5192 | VOID pointer_stars
5194 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5198 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5199 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5205 | pointer_star pointer_stars
5207 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5215 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5219 identifier_inside_body
5223 $$ = Error_AwaitAsIdentifier ($1);
5227 block_variable_declaration
5228 : variable_type identifier_inside_body
5230 var lt = (LocatedToken) $2;
5231 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5232 current_block.AddLocalName (li);
5233 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5235 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5237 $$ = current_variable;
5238 current_variable = null;
5240 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5242 lbag.AddLocation ($$, GetLocation ($6));
5244 | CONST variable_type identifier_inside_body
5246 var lt = (LocatedToken) $3;
5247 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5248 current_block.AddLocalName (li);
5249 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5251 const_variable_initializer opt_const_declarators SEMICOLON
5253 $$ = current_variable;
5254 current_variable = null;
5255 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5259 opt_local_variable_initializer
5261 | ASSIGN block_variable_initializer
5263 current_variable.Initializer = (Expression) $2;
5264 PushLocation (GetLocation ($1));
5265 $$ = current_variable;
5269 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5270 report.Error (650, lexer.Location,
5271 "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");
5273 Error_SyntaxError (yyToken);
5278 opt_variable_declarators
5280 | variable_declarators
5283 opt_using_or_fixed_variable_declarators
5285 | variable_declarators
5287 foreach (var d in current_variable.Declarators) {
5288 if (d.Initializer == null)
5289 Error_MissingInitializer (d.Variable.Location);
5294 variable_declarators
5295 : variable_declarator
5296 | variable_declarators variable_declarator
5300 : COMMA identifier_inside_body
5302 var lt = (LocatedToken) $2;
5303 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5304 var d = new BlockVariableDeclarator (li, null);
5305 current_variable.AddDeclarator (d);
5306 current_block.AddLocalName (li);
5307 lbag.AddLocation (d, GetLocation ($1));
5309 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5311 var lt = (LocatedToken) $2;
5312 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5313 var d = new BlockVariableDeclarator (li, (Expression) $4);
5314 current_variable.AddDeclarator (d);
5315 current_block.AddLocalName (li);
5316 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5320 const_variable_initializer
5323 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5325 | ASSIGN constant_initializer_expr
5327 current_variable.Initializer = (Expression) $2;
5331 opt_const_declarators
5338 | const_declarators const_declarator
5342 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5344 var lt = (LocatedToken) $2;
5345 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5346 var d = new BlockVariableDeclarator (li, (Expression) $4);
5347 current_variable.AddDeclarator (d);
5348 current_block.AddLocalName (li);
5349 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5353 block_variable_initializer
5354 : variable_initializer
5355 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5357 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5358 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5360 | STACKALLOC simple_type
5362 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5363 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5367 expression_statement
5368 : statement_expression SEMICOLON
5371 lbag.AddStatement ($$, GetLocation ($2));
5373 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5374 | statement_expression CLOSE_BRACE
5377 report.Error (1002, GetLocation ($2), "; expected");
5378 lexer.putback ('}');
5382 interactive_expression_statement
5383 : interactive_statement_expression SEMICOLON { $$ = $1; }
5384 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5388 // We have to do the wrapping here and not in the case above,
5389 // because statement_expression is used for example in for_statement
5391 statement_expression
5394 ExpressionStatement s = $1 as ExpressionStatement;
5396 var expr = $1 as Expression;
5397 $$ = new StatementErrorExpression (expr);
5399 $$ = new StatementExpression (s);
5404 interactive_statement_expression
5407 Expression expr = (Expression) $1;
5408 $$ = new StatementExpression (new OptionalAssign (expr, lexer.Location));
5412 Error_SyntaxError (yyToken);
5413 $$ = new EmptyStatement (GetLocation ($1));
5423 : IF open_parens_any boolean_expression CLOSE_PARENS
5426 if ($5 is EmptyStatement)
5427 Warning_EmptyStatement (GetLocation ($5));
5429 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5430 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5432 | IF open_parens_any boolean_expression CLOSE_PARENS
5433 embedded_statement ELSE embedded_statement
5435 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5436 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5438 if ($5 is EmptyStatement)
5439 Warning_EmptyStatement (GetLocation ($5));
5440 if ($7 is EmptyStatement)
5441 Warning_EmptyStatement (GetLocation ($7));
5443 | IF open_parens_any boolean_expression error
5445 Error_SyntaxError (yyToken);
5447 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5448 lbag.AddStatement ($$, GetLocation ($2));
5453 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5455 start_block (GetLocation ($5));
5457 opt_switch_sections CLOSE_BRACE
5459 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5460 end_block (GetLocation ($8));
5461 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5463 | SWITCH open_parens_any expression error
5465 Error_SyntaxError (yyToken);
5467 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5468 lbag.AddStatement ($$, GetLocation ($2));
5475 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5482 | switch_sections switch_section
5485 Error_SyntaxError (yyToken);
5490 : switch_labels statement_list
5496 var label = (SwitchLabel) $1;
5497 label.SectionStart = true;
5498 current_block.AddStatement (label);
5500 | switch_labels switch_label
5502 current_block.AddStatement ((Statement) $2);
5507 : CASE constant_expression COLON
5509 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5510 lbag.AddLocation ($$, GetLocation ($3));
5512 | CASE constant_expression error
5514 Error_SyntaxError (yyToken);
5515 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5519 $$ = new SwitchLabel (null, GetLocation ($1));
5531 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5533 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5534 Warning_EmptyStatement (GetLocation ($5));
5536 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5537 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5539 | WHILE open_parens_any boolean_expression error
5541 Error_SyntaxError (yyToken);
5543 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5544 lbag.AddStatement ($$, GetLocation ($2));
5549 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5551 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5552 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5554 | DO embedded_statement error
5556 Error_SyntaxError (yyToken);
5557 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5559 | DO embedded_statement WHILE open_parens_any boolean_expression error
5561 Error_SyntaxError (yyToken);
5563 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5564 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5569 : FOR open_parens_any
5571 start_block (GetLocation ($2));
5572 current_block.IsCompilerGenerated = true;
5573 For f = new For (GetLocation ($1));
5574 current_block.AddStatement (f);
5583 // Has to use be extra rule to recover started block
5585 : opt_for_initializer SEMICOLON
5587 ((For) $0).Initializer = (Statement) $1;
5589 // Pass the "For" object to the iterator_part4
5590 oob_stack.Push ($0);
5592 for_condition_and_iterator_part
5595 var locations = (Tuple<Location,Location>) $4;
5597 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5598 Warning_EmptyStatement (GetLocation ($5));
5601 f.Statement = (Statement) $5;
5602 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5604 $$ = end_block (GetLocation ($2));
5608 Error_SyntaxError (yyToken);
5609 $$ = end_block (current_block.StartLocation);
5613 for_condition_and_iterator_part
5614 : opt_for_condition SEMICOLON
5616 For f = (For) oob_stack.Peek ();
5617 f.Condition = (BooleanExpression) $1;
5620 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5623 // Handle errors in the case of opt_for_condition being followed by
5624 // a close parenthesis
5625 | opt_for_condition close_parens_close_brace {
5626 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5627 For f = (For) oob_stack.Peek ();
5628 f.Condition = (BooleanExpression) $1;
5629 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5634 : opt_for_iterator CLOSE_PARENS {
5635 For f = (For) oob_stack.Peek ();
5636 f.Iterator = (Statement) $1;
5637 $$ = GetLocation ($2);
5639 | opt_for_iterator CLOSE_BRACE {
5640 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5641 For f = (For) oob_stack.Peek ();
5642 f.Iterator = (Statement) $1;
5643 $$ = GetLocation ($2);
5647 close_parens_close_brace
5649 | CLOSE_BRACE { lexer.putback ('}'); }
5653 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5658 : variable_type identifier_inside_body
5660 var lt = (LocatedToken) $2;
5661 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5662 current_block.AddLocalName (li);
5663 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5665 opt_local_variable_initializer opt_variable_declarators
5667 $$ = current_variable;
5669 lbag.AddLocation (current_variable, PopLocation ());
5671 current_variable = null;
5673 | statement_expression_list
5677 : /* empty */ { $$ = null; }
5678 | boolean_expression
5682 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5687 : statement_expression_list
5690 statement_expression_list
5691 : statement_expression
5692 | statement_expression_list COMMA statement_expression
5694 var sl = $1 as StatementList;
5696 sl = new StatementList ((Statement) $1, (Statement) $3);
5697 lbag.AddStatement (sl, GetLocation ($2));
5699 sl.Add ((Statement) $3);
5700 lbag.AppendTo (sl, GetLocation ($2));
5708 : FOREACH open_parens_any type error
5710 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5712 start_block (GetLocation ($2));
5713 current_block.IsCompilerGenerated = true;
5715 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5716 current_block.AddStatement (f);
5718 lbag.AddStatement (f, GetLocation ($2));
5719 $$ = end_block (GetLocation ($4));
5721 | FOREACH open_parens_any type identifier_inside_body error
5723 Error_SyntaxError (yyToken);
5725 start_block (GetLocation ($2));
5726 current_block.IsCompilerGenerated = true;
5728 var lt = (LocatedToken) $4;
5729 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5730 current_block.AddLocalName (li);
5732 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5733 current_block.AddStatement (f);
5735 lbag.AddStatement (f, GetLocation ($2));
5736 $$ = end_block (GetLocation ($5));
5738 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5740 start_block (GetLocation ($2));
5741 current_block.IsCompilerGenerated = true;
5743 var lt = (LocatedToken) $4;
5744 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5745 current_block.AddLocalName (li);
5750 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5751 Warning_EmptyStatement (GetLocation ($9));
5753 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5754 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5755 end_block (GetLocation ($7));
5763 | continue_statement
5773 $$ = new Break (GetLocation ($1));
5774 lbag.AddStatement ($$, GetLocation ($2));
5779 : CONTINUE SEMICOLON
5781 $$ = new Continue (GetLocation ($1));
5782 lbag.AddStatement ($$, GetLocation ($2));
5786 Error_SyntaxError (yyToken);
5787 $$ = new Continue (GetLocation ($1));
5792 : GOTO identifier_inside_body SEMICOLON
5794 var lt = (LocatedToken) $2;
5795 $$ = new Goto (lt.Value, GetLocation ($1));
5796 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5798 | GOTO CASE constant_expression SEMICOLON
5800 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5801 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5803 | GOTO DEFAULT SEMICOLON
5805 $$ = new GotoDefault (GetLocation ($1));
5806 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5811 : RETURN opt_expression SEMICOLON
5813 $$ = new Return ((Expression) $2, GetLocation ($1));
5814 lbag.AddStatement ($$, GetLocation ($3));
5816 | RETURN expression error
5818 Error_SyntaxError (yyToken);
5819 $$ = new Return ((Expression) $2, GetLocation ($1));
5823 Error_SyntaxError (yyToken);
5824 $$ = new Return (null, GetLocation ($1));
5829 : THROW opt_expression SEMICOLON
5831 $$ = new Throw ((Expression) $2, GetLocation ($1));
5832 lbag.AddStatement ($$, GetLocation ($3));
5834 | THROW expression error
5836 Error_SyntaxError (yyToken);
5837 $$ = new Throw ((Expression) $2, GetLocation ($1));
5841 Error_SyntaxError (yyToken);
5842 $$ = new Throw (null, GetLocation ($1));
5847 : identifier_inside_body RETURN opt_expression SEMICOLON
5849 var lt = (LocatedToken) $1;
5850 string s = lt.Value;
5852 report.Error (1003, lt.Location, "; expected");
5853 } else if ($3 == null) {
5854 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5855 } else if (lang_version == LanguageVersion.ISO_1){
5856 FeatureIsNotAvailable (lt.Location, "iterators");
5859 current_block.Explicit.RegisterIteratorYield ();
5860 $$ = new Yield ((Expression) $3, lt.Location);
5861 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5863 | identifier_inside_body RETURN expression error
5865 Error_SyntaxError (yyToken);
5867 var lt = (LocatedToken) $1;
5868 string s = lt.Value;
5870 report.Error (1003, lt.Location, "; expected");
5871 } else if ($3 == null) {
5872 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5873 } else if (lang_version == LanguageVersion.ISO_1){
5874 FeatureIsNotAvailable (lt.Location, "iterators");
5877 current_block.Explicit.RegisterIteratorYield ();
5878 $$ = new Yield ((Expression) $3, lt.Location);
5879 lbag.AddStatement ($$, GetLocation ($2));
5881 | identifier_inside_body BREAK SEMICOLON
5883 var lt = (LocatedToken) $1;
5884 string s = lt.Value;
5886 report.Error (1003, lt.Location, "; expected");
5887 } else if (lang_version == LanguageVersion.ISO_1){
5888 FeatureIsNotAvailable (lt.Location, "iterators");
5891 current_block.ParametersBlock.TopBlock.IsIterator = true;
5892 $$ = new YieldBreak (lt.Location);
5893 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5903 : TRY block catch_clauses
5905 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5907 | TRY block FINALLY block
5909 $$ = new TryFinally ((Statement) $2, (ExplicitBlock) $4, GetLocation ($1));
5910 lbag.AddStatement ($$, GetLocation ($3));
5912 | TRY block catch_clauses FINALLY block
5914 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (ExplicitBlock) $5, GetLocation ($1));
5915 lbag.AddStatement ($$, GetLocation ($4));
5919 Error_SyntaxError (1524, yyToken);
5920 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5927 var l = new List<Catch> (2);
5932 | catch_clauses catch_clause
5934 var l = (List<Catch>) $1;
5936 Catch c = (Catch) $2;
5937 if (l [l.Count - 1].IsGeneral) {
5938 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5948 | identifier_inside_body
5954 $$ = new Catch ((ExplicitBlock) $2, GetLocation ($1));
5956 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5958 start_block (GetLocation ($2));
5959 var c = new Catch ((ExplicitBlock) current_block, GetLocation ($1));
5960 c.TypeExpression = (FullNamedExpression) $3;
5963 var lt = (LocatedToken) $4;
5964 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5965 current_block.AddLocalName (c.Variable);
5968 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5975 | CATCH open_parens_any error
5977 if (yyToken == Token.CLOSE_PARENS) {
5978 report.Error (1015, lexer.Location,
5979 "A type that derives from `System.Exception', `object', or `string' expected");
5981 Error_SyntaxError (yyToken);
5984 $$ = new Catch (null, GetLocation ($1));
5986 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5988 Error_SyntaxError (yyToken);
5990 // Required otherwise missing block could not be detected because
5991 // start_block is run early
5992 var c = new Catch (null, GetLocation ($1));
5993 c.TypeExpression = (FullNamedExpression) $3;
5996 var lt = (LocatedToken) $4;
5997 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
6000 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
6009 $$ = new Checked ((Block) $2, GetLocation ($1));
6016 $$ = new Unchecked ((Block) $2, GetLocation ($1));
6023 if (!settings.Unsafe)
6024 Error_UnsafeCodeNotAllowed (GetLocation ($1));
6026 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6031 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6033 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6034 Warning_EmptyStatement (GetLocation ($5));
6036 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6037 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6039 | LOCK open_parens_any expression error
6041 Error_SyntaxError (yyToken);
6043 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6044 lbag.AddStatement ($$, GetLocation ($2));
6049 : FIXED open_parens_any variable_type identifier_inside_body
6051 start_block (GetLocation ($2));
6053 current_block.IsCompilerGenerated = true;
6054 var lt = (LocatedToken) $4;
6055 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6056 current_block.AddLocalName (li);
6057 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6059 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6061 $$ = current_variable;
6062 current_variable = null;
6066 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6067 Warning_EmptyStatement (GetLocation ($10));
6069 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6070 current_block.AddStatement (f);
6071 lbag.AddStatement (f, GetLocation ($2), GetLocation ($8));
6072 $$ = end_block (GetLocation ($8));
6077 : USING open_parens_any variable_type identifier_inside_body
6079 start_block (GetLocation ($2));
6081 current_block.IsCompilerGenerated = true;
6082 var lt = (LocatedToken) $4;
6083 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6084 current_block.AddLocalName (li);
6085 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6087 using_initialization CLOSE_PARENS
6089 $$ = current_variable;
6090 current_variable = null;
6094 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6095 Warning_EmptyStatement (GetLocation ($9));
6097 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6098 current_block.AddStatement (u);
6099 $$ = end_block (GetLocation ($7));
6101 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6103 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6104 Warning_EmptyStatement (GetLocation ($5));
6106 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6107 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6109 | USING open_parens_any expression error
6111 Error_SyntaxError (yyToken);
6113 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6114 lbag.AddStatement ($$, GetLocation ($2));
6118 using_initialization
6119 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6122 // It has to be here for the parent to safely restore artificial block
6123 Error_SyntaxError (yyToken);
6127 using_or_fixed_variable_initializer
6130 Error_MissingInitializer (lexer.Location);
6132 | ASSIGN variable_initializer
6134 current_variable.Initializer = (Expression) $2;
6135 $$ = current_variable;
6143 : first_from_clause query_body
6145 lexer.query_parsing = false;
6147 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6149 from.Tail.Next = (Linq.AQueryClause)$2;
6152 current_block.SetEndLocation (lexer.Location);
6153 current_block = current_block.Parent;
6155 | nested_from_clause query_body
6157 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6159 from.Tail.Next = (Linq.AQueryClause)$2;
6162 current_block.SetEndLocation (lexer.Location);
6163 current_block = current_block.Parent;
6166 // Bubble up COMPLETE_COMPLETION productions
6167 | first_from_clause COMPLETE_COMPLETION {
6168 lexer.query_parsing = false;
6171 current_block.SetEndLocation (lexer.Location);
6172 current_block = current_block.Parent;
6174 | nested_from_clause COMPLETE_COMPLETION {
6176 current_block.SetEndLocation (lexer.Location);
6177 current_block = current_block.Parent;
6182 : FROM_FIRST identifier_inside_body IN expression
6184 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6186 var lt = (LocatedToken) $2;
6187 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6188 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6189 lbag.AddLocation (clause, GetLocation ($3));
6190 $$ = new Linq.QueryExpression (clause);
6192 | FROM_FIRST type identifier_inside_body IN expression
6194 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6196 var lt = (LocatedToken) $3;
6197 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6198 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6199 IdentifierType = (FullNamedExpression)$2
6201 lbag.AddLocation (clause, GetLocation ($4));
6202 $$ = new Linq.QueryExpression (clause);
6207 : FROM identifier_inside_body IN expression
6209 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6211 var lt = (LocatedToken) $2;
6212 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6213 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1));
6214 lbag.AddLocation (clause, GetLocation ($3));
6215 $$ = new Linq.QueryExpression (clause);
6217 | FROM type identifier_inside_body IN expression
6219 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6221 var lt = (LocatedToken) $3;
6222 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6223 var clause = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6224 IdentifierType = (FullNamedExpression)$2
6226 lbag.AddLocation (clause, GetLocation ($4));
6227 $$ = new Linq.QueryExpression (clause);
6232 : FROM identifier_inside_body IN
6234 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6238 var lt = (LocatedToken) $2;
6239 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6240 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6242 current_block.SetEndLocation (lexer.Location);
6243 current_block = current_block.Parent;
6245 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6246 lbag.AddLocation ($$, GetLocation ($3));
6248 | FROM type identifier_inside_body IN
6250 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6254 var lt = (LocatedToken) $3;
6255 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6257 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6258 IdentifierType = (FullNamedExpression)$2
6261 current_block.SetEndLocation (lexer.Location);
6262 current_block = current_block.Parent;
6264 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6266 lbag.AddLocation ($$, GetLocation ($4));
6271 : query_body_clauses select_or_group_clause opt_query_continuation
6273 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6276 head.Next = (Linq.AQueryClause)$3;
6279 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6280 clause.Tail.Next = head;
6286 | select_or_group_clause opt_query_continuation
6288 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6291 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6292 clause.Tail.Next = head;
6298 | query_body_clauses COMPLETE_COMPLETION
6299 | query_body_clauses error
6301 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6306 Error_SyntaxError (yyToken);
6311 select_or_group_clause
6314 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6318 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6320 current_block.SetEndLocation (lexer.Location);
6321 current_block = current_block.Parent;
6325 if (linq_clause_blocks == null)
6326 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6328 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6329 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6333 current_block.SetEndLocation (lexer.Location);
6334 current_block = current_block.Parent;
6336 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6340 var obj = (object[]) $5;
6342 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6343 lbag.AddLocation ($$, (Location) obj[1]);
6345 current_block.SetEndLocation (lexer.Location);
6346 current_block = current_block.Parent;
6351 : BY expression_or_error
6353 $$ = new object[] { $2, GetLocation ($1) };
6357 Error_SyntaxError (yyToken);
6358 $$ = new object[2] { null, Location.Null };
6364 | query_body_clauses query_body_clause
6366 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6380 : LET identifier_inside_body ASSIGN
6382 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6386 var lt = (LocatedToken) $2;
6387 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6388 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6389 lbag.AddLocation ($$, GetLocation ($3));
6391 current_block.SetEndLocation (lexer.Location);
6392 current_block = current_block.Parent;
6394 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6401 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6405 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6407 current_block.SetEndLocation (lexer.Location);
6408 current_block = current_block.Parent;
6413 : JOIN identifier_inside_body IN
6415 if (linq_clause_blocks == null)
6416 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6418 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6419 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6421 expression_or_error ON
6423 current_block.SetEndLocation (lexer.Location);
6424 current_block = current_block.Parent;
6426 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6427 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6429 expression_or_error EQUALS
6431 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6432 current_block.SetEndLocation (lexer.Location);
6433 current_block = current_block.Parent;
6435 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6437 expression_or_error opt_join_into
6439 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6440 current_block.SetEndLocation (lexer.Location);
6442 var outer_selector = linq_clause_blocks.Pop ();
6443 var block = linq_clause_blocks.Pop ();
6445 var lt = (LocatedToken) $2;
6446 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6447 Linq.RangeVariable into;
6451 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6452 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6455 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6457 var parent = block.Parent;
6458 while (parent is Linq.QueryBlock) {
6459 parent = parent.Parent;
6461 current_block.Parent = parent;
6463 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6465 lt = (LocatedToken) $12;
6466 into = new Linq.RangeVariable (lt.Value, lt.Location);
6468 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6469 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6472 current_block = block.Parent;
6473 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6475 | JOIN type identifier_inside_body IN
6477 if (linq_clause_blocks == null)
6478 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6480 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6481 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6483 expression_or_error ON
6485 current_block.SetEndLocation (lexer.Location);
6486 current_block = current_block.Parent;
6488 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6489 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6491 expression_or_error EQUALS
6493 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6494 current_block.SetEndLocation (lexer.Location);
6495 current_block = current_block.Parent;
6497 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6499 expression_or_error opt_join_into
6501 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6502 current_block.SetEndLocation (lexer.Location);
6504 var outer_selector = linq_clause_blocks.Pop ();
6505 var block = linq_clause_blocks.Pop ();
6507 var lt = (LocatedToken) $3;
6508 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6509 Linq.RangeVariable into;
6513 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6514 IdentifierType = (FullNamedExpression)$2
6516 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6519 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6521 var parent = block.Parent;
6522 while (parent is Linq.QueryBlock) {
6523 parent = parent.Parent;
6525 current_block.Parent = parent;
6527 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6529 lt = (LocatedToken) $13;
6530 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6532 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6533 IdentifierType = (FullNamedExpression)$2
6537 current_block = block.Parent;
6538 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6544 | INTO identifier_inside_body
6553 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6557 current_block.SetEndLocation (lexer.Location);
6558 current_block = current_block.Parent;
6568 current_block.SetEndLocation (lexer.Location);
6569 current_block = current_block.Parent;
6571 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6575 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6582 | orderings_then_by COMMA
6584 current_block.SetEndLocation (lexer.Location);
6585 current_block = current_block.Parent;
6587 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6591 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6599 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6601 | expression ASCENDING
6603 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6604 lbag.AddLocation ($$, GetLocation ($2));
6606 | expression DESCENDING
6608 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6609 lbag.AddLocation ($$, GetLocation ($2));
6616 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6618 | expression ASCENDING
6620 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6621 lbag.AddLocation ($$, GetLocation ($2));
6623 | expression DESCENDING
6625 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6626 lbag.AddLocation ($$, GetLocation ($2));
6631 opt_query_continuation
6633 | INTO identifier_inside_body
6635 // query continuation block is not linked with query block but with block
6636 // before. This means each query can use same range variable names for
6637 // different identifiers.
6639 current_block.SetEndLocation (GetLocation ($1));
6640 current_block = current_block.Parent;
6642 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6644 if (linq_clause_blocks == null)
6645 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6647 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6651 var current_block = linq_clause_blocks.Pop ();
6652 var lt = (LocatedToken) $2;
6653 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6654 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6655 next = (Linq.AQueryClause)$4
6661 // Support for using the compiler as an interactive parser
6663 // The INTERACTIVE_PARSER token is first sent to parse our
6664 // productions; If the result is a Statement, the parsing
6665 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6666 // to setup the blocks in advance.
6668 // This setup is here so that in the future we can add
6669 // support for other constructs (type parsing, namespaces, etc)
6670 // that do not require a block to be setup in advance
6674 : EVAL_STATEMENT_PARSER EOF
6675 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6676 | EVAL_STATEMENT_PARSER
6678 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6680 // (ref object retval)
6681 Parameter [] mpar = new Parameter [1];
6682 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6684 ParametersCompiled pars = new ParametersCompiled (mpar);
6685 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6686 if (settings.Unsafe)
6687 mods |= Modifiers.UNSAFE;
6689 current_local_parameters = pars;
6690 var method = new InteractiveMethod (
6692 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6696 current_type.AddMember (method);
6697 oob_stack.Push (method);
6699 interactive_async = false;
6701 ++lexer.parsing_block;
6702 start_block (lexer.Location);
6704 interactive_statement_list opt_COMPLETE_COMPLETION
6706 --lexer.parsing_block;
6707 var method = (InteractiveMethod) oob_stack.Pop ();
6708 method.Block = (ToplevelBlock) end_block(lexer.Location);
6710 if (interactive_async == true) {
6711 method.ChangeToAsync ();
6714 InteractiveResult = (Class) pop_current_class ();
6715 current_local_parameters = null;
6717 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6720 interactive_compilation_unit
6721 : opt_extern_alias_directives opt_using_directives
6722 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6725 opt_COMPLETE_COMPLETION
6727 | COMPLETE_COMPLETION
6730 close_brace_or_complete_completion
6732 | COMPLETE_COMPLETION
6736 // XML documentation code references micro parser
6738 documentation_parsing
6741 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6746 : doc_type_declaration_name opt_doc_method_sig
6748 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6750 | builtin_types opt_doc_method_sig
6752 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6753 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6756 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6758 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6759 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6760 var lt = (LocatedToken) $3;
6761 $$ = new MemberName (lt.Value);
6763 | doc_type_declaration_name DOT THIS
6765 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6767 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6769 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6771 opt_doc_parameters CLOSE_BRACKET
6773 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6774 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6776 | EXPLICIT OPERATOR type opt_doc_method_sig
6778 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6779 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6780 module.DocumentationBuilder.ParsedParameters = p;
6781 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6784 | IMPLICIT OPERATOR type opt_doc_method_sig
6786 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6787 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6788 module.DocumentationBuilder.ParsedParameters = p;
6789 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6792 | OPERATOR overloadable_operator opt_doc_method_sig
6794 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6795 module.DocumentationBuilder.ParsedParameters = p;
6796 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6801 doc_type_declaration_name
6802 : type_declaration_name
6803 | doc_type_declaration_name DOT type_declaration_name
6805 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6813 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6815 opt_doc_parameters CLOSE_PARENS
6824 $$ = new List<DocumentationParameter> (0);
6832 var parameters = new List<DocumentationParameter> ();
6833 parameters.Add ((DocumentationParameter) $1);
6836 | doc_parameters COMMA doc_parameter
6838 var parameters = $1 as List<DocumentationParameter>;
6839 parameters.Add ((DocumentationParameter) $3);
6845 : opt_parameter_modifier parameter_type
6848 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6850 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6857 // A class used to hold info about an operator declarator
6859 class OperatorDeclaration {
6860 public readonly Operator.OpType optype;
6861 public readonly FullNamedExpression ret_type;
6862 public readonly Location location;
6864 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6867 this.ret_type = ret_type;
6868 this.location = location;
6872 void Error_ExpectingTypeName (Expression expr)
6874 if (expr is Invocation){
6875 report.Error (1002, expr.Location, "Expecting `;'");
6877 expr.Error_InvalidExpressionStatement (report);
6881 void Error_ParameterModifierNotValid (string modifier, Location loc)
6883 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6887 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6889 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6890 Parameter.GetModifierSignature (mod));
6893 void Error_TypeExpected (Location loc)
6895 report.Error (1031, loc, "Type expected");
6898 void Error_UnsafeCodeNotAllowed (Location loc)
6900 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6903 void Warning_EmptyStatement (Location loc)
6905 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6908 void Error_NamedArgumentExpected (NamedArgument a)
6910 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6913 void Error_MissingInitializer (Location loc)
6915 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6918 object Error_AwaitAsIdentifier (object token)
6921 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6922 return new LocatedToken ("await", GetLocation (token));
6928 void push_current_container (TypeDefinition tc, object partial_token)
6930 if (module.Evaluator != null){
6931 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6935 undo.AddTypeContainer (current_container, tc);
6938 if (partial_token != null)
6939 current_container.AddPartial (tc);
6941 current_container.AddTypeContainer (tc);
6943 ++lexer.parsing_declaration;
6944 current_container = tc;
6948 TypeContainer pop_current_class ()
6950 var retval = current_container;
6952 current_container = current_container.Parent;
6953 current_type = current_type.Parent as TypeDefinition;
6958 [System.Diagnostics.Conditional ("FULL_AST")]
6959 void StoreModifierLocation (object token, Location loc)
6964 if (mod_locations == null)
6965 mod_locations = new List<Tuple<Modifiers, Location>> ();
6967 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6970 [System.Diagnostics.Conditional ("FULL_AST")]
6971 void PushLocation (Location loc)
6973 if (location_stack == null)
6974 location_stack = new Stack<Location> ();
6976 location_stack.Push (loc);
6979 Location PopLocation ()
6981 if (location_stack == null)
6982 return Location.Null;
6984 return location_stack.Pop ();
6987 string CheckAttributeTarget (int token, string a, Location l)
6990 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6994 if (!Tokenizer.IsValidIdentifier (a)) {
6995 Error_SyntaxError (token);
6997 report.Warning (658, 1, l,
6998 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
7001 return string.Empty;
7004 static bool IsUnaryOperator (Operator.OpType op)
7008 case Operator.OpType.LogicalNot:
7009 case Operator.OpType.OnesComplement:
7010 case Operator.OpType.Increment:
7011 case Operator.OpType.Decrement:
7012 case Operator.OpType.True:
7013 case Operator.OpType.False:
7014 case Operator.OpType.UnaryPlus:
7015 case Operator.OpType.UnaryNegation:
7021 void syntax_error (Location l, string msg)
7023 report.Error (1003, l, "Syntax error, " + msg);
7028 public Tokenizer Lexer {
7034 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
7035 : this (reader, file, file.Compiler.Report, session)
7039 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
7042 current_container = current_namespace = file;
7044 this.module = file.Module;
7045 this.compiler = file.Compiler;
7046 this.settings = compiler.Settings;
7047 this.report = report;
7049 lang_version = settings.Version;
7050 yacc_verbose_flag = settings.VerboseParserFlag;
7051 doc_support = settings.DocumentationFile != null;
7052 lexer = new Tokenizer (reader, file, session, report);
7053 oob_stack = new Stack<object> ();
7054 lbag = session.LocationsBag;
7055 use_global_stacks = session.UseJayGlobalArrays;
7056 parameters_bucket = session.ParametersStack;
7059 public void parse ()
7061 eof_token = Token.EOF;
7064 if (yacc_verbose_flag > 1)
7065 yyparse (lexer, new yydebug.yyDebugSimple ());
7069 Tokenizer tokenizer = lexer as Tokenizer;
7070 tokenizer.cleanup ();
7071 } catch (Exception e){
7072 if (e is yyParser.yyUnexpectedEof) {
7073 Error_SyntaxError (yyToken);
7074 UnexpectedEOF = true;
7078 if (e is yyParser.yyException) {
7079 if (report.Errors == 0)
7080 report.Error (-25, lexer.Location, "Parsing error");
7082 // Used by compiler-tester to test internal errors
7083 if (yacc_verbose_flag > 0 || e is FatalException)
7086 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7091 void CheckToken (int error, int yyToken, string msg, Location loc)
7093 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7094 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7096 report.Error (error, loc, msg);
7099 string ConsumeStoredComment ()
7101 string s = tmpComment;
7103 Lexer.doc_state = XmlCommentState.Allowed;
7107 void FeatureIsNotAvailable (Location loc, string feature)
7109 report.FeatureIsNotAvailable (compiler, loc, feature);
7112 Location GetLocation (object obj)
7114 var lt = obj as LocatedToken;
7118 var mn = obj as MemberName;
7122 var expr = obj as Expression;
7124 return expr.Location;
7126 return lexer.Location;
7129 void start_block (Location loc)
7131 if (current_block == null) {
7132 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7133 parsing_anonymous_method = false;
7134 } else if (parsing_anonymous_method) {
7135 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7136 parsing_anonymous_method = false;
7138 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7143 end_block (Location loc)
7145 Block retval = current_block.Explicit;
7146 retval.SetEndLocation (loc);
7147 current_block = retval.Parent;
7151 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7153 oob_stack.Push (current_anonymous_method);
7154 oob_stack.Push (current_local_parameters);
7155 oob_stack.Push (current_variable);
7156 oob_stack.Push (async_block);
7158 current_local_parameters = parameters;
7160 if (lang_version <= LanguageVersion.ISO_2)
7161 FeatureIsNotAvailable (loc, "lambda expressions");
7163 current_anonymous_method = new LambdaExpression (loc);
7165 if (lang_version == LanguageVersion.ISO_1)
7166 FeatureIsNotAvailable (loc, "anonymous methods");
7168 current_anonymous_method = new AnonymousMethodExpression (loc);
7171 async_block = isAsync;
7172 // Force the next block to be created as a ToplevelBlock
7173 parsing_anonymous_method = true;
7177 * Completes the anonymous method processing, if lambda_expr is null, this
7178 * means that we have a Statement instead of an Expression embedded
7180 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7182 AnonymousMethodExpression retval;
7185 anon_block.IsAsync = true;
7187 current_anonymous_method.Block = anon_block;
7188 retval = current_anonymous_method;
7190 async_block = (bool) oob_stack.Pop ();
7191 current_variable = (BlockVariable) oob_stack.Pop ();
7192 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7193 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7198 void Error_SyntaxError (int token)
7200 Error_SyntaxError (0, token);
7203 void Error_SyntaxError (int error_code, int token)
7205 Error_SyntaxError (error_code, token, "Unexpected symbol");
7208 void Error_SyntaxError (int error_code, int token, string msg)
7210 Lexer.CompleteOnEOF = false;
7212 // An error message has been reported by tokenizer
7213 if (token == Token.ERROR)
7216 // Avoid duplicit error message after unterminated string literals
7217 if (token == Token.LITERAL && lexer.Location.Column == 0)
7220 string symbol = GetSymbolName (token);
7221 string expecting = GetExpecting ();
7222 var loc = lexer.Location - symbol.Length;
7224 if (error_code == 0) {
7225 if (expecting == "`identifier'") {
7226 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7227 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7232 expecting = "identifier";
7233 } else if (expecting == "`)'") {
7240 if (string.IsNullOrEmpty (expecting))
7241 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7243 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7246 string GetExpecting ()
7248 int [] tokens = yyExpectingTokens (yyExpectingState);
7249 var names = new List<string> (tokens.Length);
7250 bool has_type = false;
7251 bool has_identifier = false;
7252 for (int i = 0; i < tokens.Length; i++){
7253 int token = tokens [i];
7254 has_identifier |= token == Token.IDENTIFIER;
7256 string name = GetTokenName (token);
7257 if (name == "<internal>")
7260 has_type |= name == "type";
7261 if (names.Contains (name))
7268 // Too many tokens to enumerate
7270 if (names.Count > 8)
7273 if (has_type && has_identifier)
7274 names.Remove ("identifier");
7276 if (names.Count == 1)
7277 return "`" + GetTokenName (tokens [0]) + "'";
7279 StringBuilder sb = new StringBuilder ();
7281 int count = names.Count;
7282 for (int i = 0; i < count; i++){
7283 bool last = i + 1 == count;
7287 sb.Append (names [i]);
7288 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7290 return sb.ToString ();
7294 string GetSymbolName (int token)
7298 return ((Constant)lexer.Value).GetValue ().ToString ();
7299 case Token.IDENTIFIER:
7300 return ((LocatedToken)lexer.Value).Value;
7342 case Token.BITWISE_AND:
7344 case Token.BITWISE_OR:
7358 case Token.OP_SHIFT_LEFT:
7360 case Token.OP_SHIFT_RIGHT:
7380 case Token.OP_COALESCING:
7382 case Token.OP_MULT_ASSIGN:
7384 case Token.OP_DIV_ASSIGN:
7386 case Token.OP_MOD_ASSIGN:
7388 case Token.OP_ADD_ASSIGN:
7390 case Token.OP_SUB_ASSIGN:
7392 case Token.OP_SHIFT_LEFT_ASSIGN:
7394 case Token.OP_SHIFT_RIGHT_ASSIGN:
7396 case Token.OP_AND_ASSIGN:
7398 case Token.OP_XOR_ASSIGN:
7400 case Token.OP_OR_ASSIGN:
7404 return GetTokenName (token);
7407 static string GetTokenName (int token)
7410 case Token.ABSTRACT:
7432 case Token.CONTINUE:
7436 case Token.DELEGATE:
7446 case Token.EXPLICIT:
7449 case Token.EXTERN_ALIAS:
7465 case Token.IMPLICIT:
7469 case Token.INTERFACE:
7471 case Token.INTERNAL:
7477 case Token.NAMESPACE:
7483 case Token.OPERATOR:
7487 case Token.OVERRIDE:
7493 case Token.PROTECTED:
7497 case Token.READONLY:
7509 case Token.STACKALLOC:
7510 return "stackalloc";
7527 case Token.UNCHECKED:
7535 case Token.VOLATILE:
7543 case Token.REFVALUE:
7544 return "__refvalue";
7554 case Token.FROM_FIRST:
7572 case Token.ASCENDING:
7574 case Token.DESCENDING:
7575 return "descending";
7582 case Token.OPEN_BRACE:
7584 case Token.CLOSE_BRACE:
7586 case Token.OPEN_BRACKET:
7587 case Token.OPEN_BRACKET_EXPR:
7589 case Token.CLOSE_BRACKET:
7591 case Token.OPEN_PARENS_CAST:
7592 case Token.OPEN_PARENS_LAMBDA:
7593 case Token.OPEN_PARENS:
7595 case Token.CLOSE_PARENS:
7601 case Token.DEFAULT_COLON:
7605 case Token.SEMICOLON:
7616 case Token.BITWISE_AND:
7617 case Token.BITWISE_OR:
7624 case Token.OP_SHIFT_LEFT:
7625 case Token.OP_SHIFT_RIGHT:
7633 case Token.OP_COALESCING:
7634 case Token.OP_MULT_ASSIGN:
7635 case Token.OP_DIV_ASSIGN:
7636 case Token.OP_MOD_ASSIGN:
7637 case Token.OP_ADD_ASSIGN:
7638 case Token.OP_SUB_ASSIGN:
7639 case Token.OP_SHIFT_LEFT_ASSIGN:
7640 case Token.OP_SHIFT_RIGHT_ASSIGN:
7641 case Token.OP_AND_ASSIGN:
7642 case Token.OP_XOR_ASSIGN:
7643 case Token.OP_OR_ASSIGN:
7644 return "<operator>";
7666 case Token.OP_GENERICS_LT:
7667 case Token.GENERIC_DIMENSION:
7669 case Token.OP_GENERICS_GT:
7672 case Token.INTERR_NULLABLE:
7674 case Token.DOUBLE_COLON:
7678 case Token.IDENTIFIER:
7680 return "identifier";
7683 return "end-of-file";
7685 // All of these are internal.
7688 case Token.FIRST_KEYWORD:
7689 case Token.EVAL_COMPILATION_UNIT_PARSER:
7690 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7691 case Token.EVAL_STATEMENT_PARSER:
7692 case Token.LAST_KEYWORD:
7693 case Token.GENERATE_COMPLETION:
7694 case Token.COMPLETE_COMPLETION:
7695 return "<internal>";
7697 // A bit more robust.
7699 return yyNames [token];