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 BlockVariableDeclaration 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 Stack<Linq.QueryBlock> linq_clause_blocks;
122 ModuleContainer module;
124 readonly CompilerContext compiler;
125 readonly LanguageVersion lang_version;
126 readonly bool doc_support;
127 readonly CompilerSettings settings;
128 readonly Report report;
131 // Instead of allocating carrier array everytime we
132 // share the bucket for very common constructs which can never
135 List<Parameter> parameters_bucket;
138 // Full AST support members
141 List<Tuple<Modifiers, Location>> mod_locations;
142 Stack<Location> location_stack;
146 %token NONE /* This token is never returned by our lexer */
147 %token ERROR // This is used not by the parser, but by the tokenizer.
151 *These are the C# keywords
250 %token INTERR_NULLABLE
258 /* C# keywords which are not really keywords */
264 /* C# single character operators/punctuation. */
292 /* C# multi-character operators. */
297 %token OP_SHIFT_RIGHT
304 %token OP_MULT_ASSIGN
309 %token OP_SHIFT_LEFT_ASSIGN
310 %token OP_SHIFT_RIGHT_ASSIGN
317 /* Generics <,> tokens */
318 %token OP_GENERICS_LT
319 %token OP_GENERICS_LT_DECL
320 %token OP_GENERICS_GT
325 %token OPEN_PARENS_LAMBDA
326 %token OPEN_PARENS_CAST
327 %token GENERIC_DIMENSION
329 %token OPEN_BRACKET_EXPR
331 // Make the parser go into eval mode parsing (statements and compilation units).
332 %token EVAL_STATEMENT_PARSER
333 %token EVAL_COMPILATION_UNIT_PARSER
334 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
339 // This token is generated to trigger the completion engine at this point
341 %token GENERATE_COMPLETION
344 // This token is return repeatedly after the first GENERATE_COMPLETION
345 // token is produced and before the final EOF
347 %token COMPLETE_COMPLETION
349 /* Add precedence rules to solve dangling else s/r conflict */
353 /* Define the operator tokens and their precedences */
361 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
363 %left STAR DIV PERCENT
364 %right BANG CARRET UMINUS
365 %nonassoc OP_INC OP_DEC
367 %left OPEN_BRACKET OPEN_BRACE
370 %start compilation_unit
374 : outer_declaration opt_EOF
376 Lexer.check_incorrect_doc_comment ();
378 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
379 | documentation_parsing
383 : opt_extern_alias_directives opt_using_directives
384 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
387 Attributes attrs = (Attributes) $4;
388 report.Error (1730, attrs.Attrs [0].Location,
389 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
391 current_namespace.UnattachedAttributes = attrs;
394 | opt_extern_alias_directives opt_using_directives attribute_sections
396 module.AddAttributes ((Attributes) $3, current_namespace);
400 if (yyToken == Token.EXTERN_ALIAS)
401 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
403 Error_SyntaxError (yyToken);
412 extern_alias_directives
413 : extern_alias_directive
414 | extern_alias_directives extern_alias_directive
417 extern_alias_directive
418 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
420 var lt = (Tokenizer.LocatedToken) $2;
423 syntax_error (lt.Location, "`alias' expected");
425 if (lang_version == LanguageVersion.ISO_1)
426 FeatureIsNotAvailable (lt.Location, "external alias");
428 lt = (Tokenizer.LocatedToken) $3;
429 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
430 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
433 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
434 current_namespace.AddUsing (na);
436 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
441 Error_SyntaxError (yyToken);
447 | using_directives using_directive
454 Lexer.doc_state = XmlCommentState.Allowed;
459 : USING namespace_or_type_expr SEMICOLON
461 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
462 current_namespace.AddUsing (un);
464 lbag.AddLocation (un, GetLocation ($3));
466 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
468 var lt = (Tokenizer.LocatedToken) $2;
469 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
470 report.Warning (440, 2, lt.Location,
471 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
474 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
475 current_namespace.AddUsing (un);
477 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
481 Error_SyntaxError (yyToken);
487 // Strictly speaking, namespaces don't have attributes but
488 // we parse global attributes along with namespace declarations and then
491 namespace_declaration
492 : opt_attributes NAMESPACE namespace_name
494 Attributes attrs = (Attributes) $1;
495 var name = (MemberName) $3;
497 bool valid_global_attrs = true;
498 if ((current_namespace.DeclarationFound || current_namespace != file)) {
499 valid_global_attrs = false;
501 foreach (var a in attrs.Attrs) {
502 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
505 valid_global_attrs = false;
510 if (!valid_global_attrs)
511 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
514 module.AddAttributes (attrs, current_namespace);
516 var ns = new NamespaceContainer (name, current_namespace);
517 current_namespace.AddTypeContainer (ns);
518 current_container = current_namespace = ns;
523 Lexer.doc_state = XmlCommentState.Allowed;
525 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
528 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
530 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
532 current_container = current_namespace = current_namespace.Parent;
534 | opt_attributes NAMESPACE namespace_name
536 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
538 var name = (MemberName) $3;
539 var ns = new NamespaceContainer (name, current_namespace);
540 lbag.AddLocation (ns, GetLocation ($2));
541 current_namespace.AddTypeContainer (ns);
550 Error_SyntaxError (yyToken);
558 var lt = (Tokenizer.LocatedToken) $1;
559 $$ = new MemberName (lt.Value, lt.Location);
561 | namespace_name DOT IDENTIFIER
563 var lt = (Tokenizer.LocatedToken) $3;
564 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
568 Error_SyntaxError (yyToken);
569 $$ = new MemberName ("<invalid>", lexer.Location);
588 opt_extern_alias_directives
590 | extern_alias_directives
593 opt_namespace_or_type_declarations
595 | namespace_or_type_declarations
598 namespace_or_type_declarations
599 : namespace_or_type_declaration
600 | namespace_or_type_declarations namespace_or_type_declaration
603 namespace_or_type_declaration
607 TypeContainer ds = (TypeContainer)$1;
609 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
610 report.Error (1527, ds.Location,
611 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
614 // Here is a trick, for explicit attributes we don't know where they belong to until
615 // we parse succeeding declaration hence we parse them as normal and re-attach them
616 // when we know whether they are global (assembly:, module:) or local (type:).
617 if (ds.OptAttributes != null) {
618 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
621 current_namespace.DeclarationFound = true;
623 | namespace_declaration
625 current_namespace.DeclarationFound = true;
627 | attribute_sections CLOSE_BRACE {
628 current_namespace.UnattachedAttributes = (Attributes) $1;
629 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
637 | interface_declaration
639 | delegate_declaration
641 // Enable this when we have handled all errors, because this acts as a generic fallback
644 // Console.WriteLine ("Token=" + yyToken);
645 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
661 var sect = (List<Attribute>) $1;
662 $$ = new Attributes (sect);
664 | attribute_sections attribute_section
666 Attributes attrs = $1 as Attributes;
667 var sect = (List<Attribute>) $2;
669 attrs = new Attributes (sect);
671 attrs.AddAttributes (sect);
679 PushLocation (GetLocation ($1));
680 lexer.parsing_attribute_section = true;
682 attribute_section_cont
684 lexer.parsing_attribute_section = false;
689 attribute_section_cont
690 : attribute_target COLON
692 current_attr_target = (string) $1;
693 if (current_attr_target == "assembly" || current_attr_target == "module") {
694 Lexer.check_incorrect_doc_comment ();
697 attribute_list opt_comma CLOSE_BRACKET
699 // when attribute target is invalid
700 if (current_attr_target == string.Empty)
701 $$ = new List<Attribute> (0);
705 lbag.InsertLocation ($$, 0, PopLocation ());
707 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
709 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
712 current_attr_target = null;
713 lexer.parsing_attribute_section = false;
715 | attribute_list opt_comma CLOSE_BRACKET
719 lbag.InsertLocation ($$, 0, PopLocation ());
721 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
723 lbag.AddLocation ($$, GetLocation($3));
728 Error_SyntaxError (yyToken);
730 var lt = (Tokenizer.LocatedToken) $1;
731 var tne = new SimpleName (lt.Value, null, lt.Location);
733 $$ = new List<Attribute> () {
734 new Attribute (null, tne, null, GetLocation ($1), false)
739 $$ = CheckAttributeTarget (GetTokenName (yyToken), GetLocation ($1));
747 var lt = (Tokenizer.LocatedToken) $1;
748 $$ = CheckAttributeTarget (lt.Value, lt.Location);
750 | EVENT { $$ = "event"; }
751 | RETURN { $$ = "return"; }
757 $$ = new List<Attribute> (4) { (Attribute) $1 };
759 | attribute_list COMMA attribute
761 var attrs = (List<Attribute>) $1;
763 attrs.Add ((Attribute) $3);
764 lbag.AppendTo (attrs, GetLocation ($2));
774 ++lexer.parsing_block;
776 opt_attribute_arguments
778 --lexer.parsing_block;
780 var tne = (ATypeNameExpression) $1;
781 if (tne.HasTypeArguments) {
782 report.Error (404, tne.Location, "Attributes cannot be generic");
785 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
790 : namespace_or_type_expr
793 opt_attribute_arguments
794 : /* empty */ { $$ = null; }
795 | OPEN_PARENS attribute_arguments CLOSE_PARENS
803 : /* empty */ { $$ = null; }
804 | positional_or_named_argument
806 Arguments a = new Arguments (4);
807 a.Add ((Argument) $1);
808 $$ = new Arguments [] { a, null };
810 | named_attribute_argument
812 Arguments a = new Arguments (4);
813 a.Add ((Argument) $1);
814 $$ = new Arguments [] { null, a };
816 | attribute_arguments COMMA positional_or_named_argument
818 Arguments[] o = (Arguments[]) $1;
820 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
821 o [0] = new Arguments (4);
824 Arguments args = ((Arguments) o [0]);
825 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
826 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
828 args.Add ((Argument) $3);
830 | attribute_arguments COMMA named_attribute_argument
832 Arguments[] o = (Arguments[]) $1;
834 o [1] = new Arguments (4);
837 ((Arguments) o [1]).Add ((Argument) $3);
841 positional_or_named_argument
844 $$ = new Argument ((Expression) $1);
849 Error_SyntaxError (yyToken);
854 named_attribute_argument
857 ++lexer.parsing_block;
861 --lexer.parsing_block;
862 var lt = (Tokenizer.LocatedToken) $1;
863 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
864 lbag.AddLocation ($$, GetLocation($2));
869 : identifier_inside_body COLON opt_named_modifier expression
871 if (lang_version <= LanguageVersion.V_3)
872 FeatureIsNotAvailable (GetLocation ($1), "named argument");
874 // Avoid boxing in common case (no modifier)
875 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
877 var lt = (Tokenizer.LocatedToken) $1;
878 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
879 lbag.AddLocation ($$, GetLocation($2));
884 : /* empty */ { $$ = null; }
887 $$ = Argument.AType.Ref;
891 $$ = Argument.AType.Out;
895 opt_class_member_declarations
897 | class_member_declarations
900 class_member_declarations
901 : class_member_declaration
903 lexer.parsing_modifiers = true;
905 | class_member_declarations class_member_declaration
907 lexer.parsing_modifiers = true;
911 class_member_declaration
912 : constant_declaration
915 | property_declaration
917 | indexer_declaration
918 | operator_declaration
919 | constructor_declaration
920 | destructor_declaration
922 | attributes_without_members
926 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
927 GetSymbolName (yyToken));
929 lexer.parsing_generic_declaration = false;
940 type_declaration_name
942 lexer.ConstraintsParsing = true;
943 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
946 opt_type_parameter_constraints_clauses
948 lexer.ConstraintsParsing = false;
951 current_container.SetConstraints ((List<Constraints>) $9);
954 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
956 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
958 lexer.parsing_modifiers = true;
963 Lexer.doc_state = XmlCommentState.Allowed;
965 opt_class_member_declarations CLOSE_BRACE
967 --lexer.parsing_declaration;
969 Lexer.doc_state = XmlCommentState.Allowed;
973 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
974 $$ = pop_current_class ();
976 | opt_attributes opt_modifiers opt_partial STRUCT error
978 Error_SyntaxError (yyToken);
985 CONST type IDENTIFIER
987 var lt = (Tokenizer.LocatedToken) $5;
988 var mod = (Modifiers) $2;
989 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
990 current_type.AddMember (current_field);
992 if ((mod & Modifiers.STATIC) != 0) {
993 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
998 constant_initializer opt_constant_declarators SEMICOLON
1001 current_field.DocComment = Lexer.consume_doc_comment ();
1002 Lexer.doc_state = XmlCommentState.Allowed;
1005 current_field.Initializer = (ConstInitializer) $7;
1006 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1007 current_field = null;
1013 Error_SyntaxError (yyToken);
1015 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1019 opt_constant_declarators
1021 | constant_declarators
1024 constant_declarators
1025 : constant_declarator
1027 current_field.AddDeclarator ((FieldDeclarator) $1);
1029 | constant_declarators constant_declarator
1031 current_field.AddDeclarator ((FieldDeclarator) $2);
1036 : COMMA IDENTIFIER constant_initializer
1038 var lt = (Tokenizer.LocatedToken) $2;
1039 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1040 lbag.AddLocation ($$, GetLocation ($1));
1044 constant_initializer
1047 ++lexer.parsing_block;
1049 constant_initializer_expr
1051 --lexer.parsing_block;
1052 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1056 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1061 constant_initializer_expr
1062 : constant_expression
1069 member_type IDENTIFIER
1071 lexer.parsing_generic_declaration = false;
1073 FullNamedExpression type = (FullNamedExpression) $3;
1074 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1075 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1077 var lt = (Tokenizer.LocatedToken) $4;
1078 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1079 current_type.AddField (current_field);
1082 opt_field_initializer
1083 opt_field_declarators
1087 current_field.DocComment = Lexer.consume_doc_comment ();
1088 Lexer.doc_state = XmlCommentState.Allowed;
1091 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1093 current_field = null;
1097 FIXED simple_type IDENTIFIER
1099 if (lang_version < LanguageVersion.ISO_2)
1100 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1102 var lt = (Tokenizer.LocatedToken) $5;
1103 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1104 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1106 current_type.AddField (current_field);
1108 fixed_field_size opt_fixed_field_declarators SEMICOLON
1111 current_field.DocComment = Lexer.consume_doc_comment ();
1112 Lexer.doc_state = XmlCommentState.Allowed;
1115 current_field.Initializer = (ConstInitializer) $7;
1116 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1118 current_field = null;
1122 FIXED simple_type error
1125 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1129 opt_field_initializer
1133 ++lexer.parsing_block;
1134 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1135 start_block (GetLocation ($1));
1137 variable_initializer
1139 --lexer.parsing_block;
1140 current_field.Initializer = (Expression) $3;
1141 end_block (lexer.Location);
1142 current_local_parameters = null;
1146 opt_field_declarators
1154 current_field.AddDeclarator ((FieldDeclarator) $1);
1156 | field_declarators field_declarator
1158 current_field.AddDeclarator ((FieldDeclarator) $2);
1165 var lt = (Tokenizer.LocatedToken) $2;
1166 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1167 lbag.AddLocation ($$, GetLocation ($1));
1169 | COMMA IDENTIFIER ASSIGN
1171 ++lexer.parsing_block;
1173 variable_initializer
1175 --lexer.parsing_block;
1176 var lt = (Tokenizer.LocatedToken) $2;
1177 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1178 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1182 opt_fixed_field_declarators
1184 | fixed_field_declarators
1187 fixed_field_declarators
1188 : fixed_field_declarator
1190 current_field.AddDeclarator ((FieldDeclarator) $1);
1192 | fixed_field_declarators fixed_field_declarator
1194 current_field.AddDeclarator ((FieldDeclarator) $2);
1198 fixed_field_declarator
1199 : COMMA IDENTIFIER fixed_field_size
1201 var lt = (Tokenizer.LocatedToken) $2;
1202 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1203 lbag.AddLocation ($$, GetLocation ($1));
1210 ++lexer.parsing_block;
1212 expression CLOSE_BRACKET
1214 --lexer.parsing_block;
1215 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1216 lbag.AddLocation ($$, GetLocation ($4));
1218 | OPEN_BRACKET error
1220 report.Error (443, lexer.Location, "Value or constant expected");
1225 variable_initializer
1230 // It has to be here for the parent to safely restore artificial block
1231 Error_SyntaxError (yyToken);
1240 Lexer.doc_state = XmlCommentState.NotAllowed;
1242 // Was added earlier in the case of body being eof for full ast
1246 Method method = (Method) $1;
1247 method.Block = (ToplevelBlock) $3;
1248 async_block = false;
1250 if (method.Block == null) {
1251 method.ParameterInfo.CheckParameters (method);
1253 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1254 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1255 method.GetSignatureForError ());
1258 if (current_container.Kind == MemberKind.Interface) {
1259 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1260 method.GetSignatureForError ());
1264 current_local_parameters = null;
1267 Lexer.doc_state = XmlCommentState.Allowed;
1275 method_declaration_name OPEN_PARENS
1277 valid_param_mod = ParameterModifierType.All;
1279 opt_formal_parameter_list CLOSE_PARENS
1281 valid_param_mod = 0;
1282 MemberName name = (MemberName) $4;
1283 current_local_parameters = (ParametersCompiled) $7;
1285 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1286 name, current_local_parameters, (Attributes) $1);
1288 current_type.AddMember (method);
1290 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1293 method.DocComment = Lexer.consume_doc_comment ();
1295 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1299 lexer.ConstraintsParsing = true;
1301 opt_type_parameter_constraints_clauses
1303 lexer.ConstraintsParsing = false;
1306 var method = (Method) $9;
1307 method.SetConstraints ((List<Constraints>) $10);
1317 lexer.parsing_generic_declaration = true;
1319 method_declaration_name
1322 lexer.parsing_generic_declaration = false;
1323 valid_param_mod = ParameterModifierType.All;
1325 opt_formal_parameter_list CLOSE_PARENS
1327 lexer.ConstraintsParsing = true;
1329 opt_type_parameter_constraints_clauses
1331 lexer.ConstraintsParsing = false;
1332 valid_param_mod = 0;
1334 MemberName name = (MemberName) $6;
1335 current_local_parameters = (ParametersCompiled) $9;
1337 var modifiers = (Modifiers) $2;
1338 modifiers |= Modifiers.PARTIAL;
1340 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1341 modifiers, name, current_local_parameters, (Attributes) $1);
1343 current_type.AddMember (method);
1346 method.SetConstraints ((List<Constraints>) $11);
1349 method.DocComment = Lexer.consume_doc_comment ();
1351 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1352 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1358 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1360 MemberName name = (MemberName) $5;
1361 report.Error (1585, name.Location,
1362 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1364 var method = Method.Create (current_type, (FullNamedExpression) $3,
1365 0, name, (ParametersCompiled) $7, (Attributes) $1);
1367 current_type.AddMember (method);
1369 current_local_parameters = (ParametersCompiled) $7;
1372 method.DocComment = Lexer.consume_doc_comment ();
1379 method_declaration_name error
1381 Error_SyntaxError (yyToken);
1382 current_local_parameters = ParametersCompiled.Undefined;
1384 MemberName name = (MemberName) $4;
1385 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1386 name, current_local_parameters, (Attributes) $1);
1388 current_type.AddMember (method);
1391 method.DocComment = Lexer.consume_doc_comment ();
1399 | SEMICOLON { $$ = null; }
1402 opt_formal_parameter_list
1403 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1404 | formal_parameter_list
1407 formal_parameter_list
1410 var pars_list = (List<Parameter>) $1;
1411 $$ = new ParametersCompiled (pars_list.ToArray ());
1413 | fixed_parameters COMMA parameter_array
1415 var pars_list = (List<Parameter>) $1;
1416 pars_list.Add ((Parameter) $3);
1418 $$ = new ParametersCompiled (pars_list.ToArray ());
1420 | fixed_parameters COMMA arglist_modifier
1422 var pars_list = (List<Parameter>) $1;
1423 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1424 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1426 | parameter_array COMMA error
1429 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1431 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1433 | fixed_parameters COMMA parameter_array COMMA error
1436 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1438 var pars_list = (List<Parameter>) $1;
1439 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1441 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1443 | arglist_modifier COMMA error
1445 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1447 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1449 | fixed_parameters COMMA ARGLIST COMMA error
1451 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1453 var pars_list = (List<Parameter>) $1;
1454 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1456 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1460 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1464 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1468 Error_SyntaxError (yyToken);
1469 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1476 parameters_bucket.Clear ();
1477 Parameter p = (Parameter) $1;
1478 parameters_bucket.Add (p);
1480 default_parameter_used = p.HasDefaultValue;
1481 $$ = parameters_bucket;
1483 | fixed_parameters COMMA fixed_parameter
1485 var pars = (List<Parameter>) $1;
1486 Parameter p = (Parameter) $3;
1488 if (p.HasExtensionMethodModifier)
1489 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1490 else if (!p.HasDefaultValue && default_parameter_used)
1491 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1493 default_parameter_used |= p.HasDefaultValue;
1496 lbag.AddLocation (p, GetLocation ($2));
1505 opt_parameter_modifier
1507 identifier_inside_body
1509 var lt = (Tokenizer.LocatedToken) $4;
1510 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1513 opt_parameter_modifier
1515 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1517 var lt = (Tokenizer.LocatedToken) $4;
1518 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1519 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1521 | attribute_sections error
1523 Error_SyntaxError (yyToken);
1524 Location l = GetLocation ($2);
1525 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1528 opt_parameter_modifier
1532 Error_SyntaxError (yyToken);
1533 Location l = GetLocation ($4);
1534 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1537 opt_parameter_modifier
1539 identifier_inside_body
1542 ++lexer.parsing_block;
1546 --lexer.parsing_block;
1547 if (lang_version <= LanguageVersion.V_3) {
1548 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1551 Parameter.Modifier mod = (Parameter.Modifier) $2;
1552 if (mod != Parameter.Modifier.NONE) {
1554 case Parameter.Modifier.REF:
1555 case Parameter.Modifier.OUT:
1556 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1557 Parameter.GetModifierSignature (mod));
1560 case Parameter.Modifier.This:
1561 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1562 Parameter.GetModifierSignature (mod));
1565 throw new NotImplementedException (mod.ToString ());
1568 mod = Parameter.Modifier.NONE;
1571 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1572 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1574 var lt = (Tokenizer.LocatedToken) $4;
1575 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1576 lbag.AddLocation ($$, GetLocation ($5));
1579 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1583 opt_parameter_modifier
1584 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1585 | parameter_modifiers
1589 : parameter_modifier
1593 | parameter_modifiers parameter_modifier
1595 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1596 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1597 if (((Parameter.Modifier)$1 & p2) == p2) {
1598 Error_DuplicateParameterModifier (lexer.Location, p2);
1600 switch (mod & ~Parameter.Modifier.This) {
1601 case Parameter.Modifier.REF:
1602 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1604 case Parameter.Modifier.OUT:
1605 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1608 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1619 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1620 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1622 $$ = Parameter.Modifier.REF;
1626 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1627 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1629 $$ = Parameter.Modifier.OUT;
1633 if ((valid_param_mod & ParameterModifierType.This) == 0)
1634 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1636 if (lang_version <= LanguageVersion.ISO_2)
1637 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1639 $$ = Parameter.Modifier.This;
1644 : opt_attributes params_modifier type IDENTIFIER
1646 var lt = (Tokenizer.LocatedToken) $4;
1647 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1649 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1651 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1653 var lt = (Tokenizer.LocatedToken) $4;
1654 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1656 | opt_attributes params_modifier type error
1658 Error_SyntaxError (yyToken);
1660 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1667 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1668 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1670 | PARAMS parameter_modifier
1672 Parameter.Modifier mod = (Parameter.Modifier)$2;
1673 if ((mod & Parameter.Modifier.This) != 0) {
1674 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1676 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1679 | PARAMS params_modifier
1681 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1688 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1689 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1693 property_declaration
1697 member_declaration_name
1700 tmpComment = Lexer.consume_doc_comment ();
1704 var type = (FullNamedExpression) $3;
1705 current_property = new Property (current_type, type, (Modifiers) $2,
1706 (MemberName) $4, (Attributes) $1);
1708 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1709 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1711 current_type.AddMember (current_property);
1712 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1714 lexer.PropertyParsing = true;
1716 accessor_declarations
1718 lexer.PropertyParsing = false;
1721 current_property.DocComment = ConsumeStoredComment ();
1725 lbag.AppendToMember (current_property, GetLocation ($10));
1726 current_property = null;
1732 : opt_attributes opt_modifiers
1733 member_type indexer_declaration_name OPEN_BRACKET
1735 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1737 opt_formal_parameter_list CLOSE_BRACKET
1739 valid_param_mod = 0;
1740 var type = (FullNamedExpression) $3;
1741 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1743 current_property = indexer;
1745 current_type.AddIndexer (indexer);
1746 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1748 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1749 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1751 if (indexer.ParameterInfo.IsEmpty) {
1752 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1756 tmpComment = Lexer.consume_doc_comment ();
1757 Lexer.doc_state = XmlCommentState.Allowed;
1760 lexer.PropertyParsing = true;
1762 OPEN_BRACE accessor_declarations
1764 lexer.PropertyParsing = false;
1768 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1769 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1772 current_property.DocComment = ConsumeStoredComment ();
1774 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1775 current_property = null;
1780 accessor_declarations
1781 : get_accessor_declaration
1782 | get_accessor_declaration accessor_declarations
1783 | set_accessor_declaration
1784 | set_accessor_declaration accessor_declarations
1787 if (yyToken == Token.CLOSE_BRACE) {
1788 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1790 if (yyToken == Token.SEMICOLON)
1791 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1793 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1798 get_accessor_declaration
1799 : opt_attributes opt_modifiers GET
1801 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1802 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1805 if (current_property.Get != null) {
1806 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1809 if (current_property is Indexer) {
1810 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1811 (Attributes) $1, GetLocation ($3));
1813 current_property.Get = new Property.GetMethod (current_property,
1814 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1817 current_local_parameters = current_property.Get.ParameterInfo;
1818 lbag.AddMember (current_property.Get, mod_locations);
1819 lexer.PropertyParsing = false;
1824 current_property.Get.Block = (ToplevelBlock) $5;
1826 if (current_container.Kind == MemberKind.Interface) {
1827 report.Error (531, current_property.Get.Block.StartLocation,
1828 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1832 current_local_parameters = null;
1833 lexer.PropertyParsing = true;
1836 if (Lexer.doc_state == XmlCommentState.Error)
1837 Lexer.doc_state = XmlCommentState.NotAllowed;
1841 set_accessor_declaration
1842 : opt_attributes opt_modifiers SET
1844 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1845 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1848 if (current_property.Set != null) {
1849 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1852 if (current_property is Indexer) {
1853 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1854 ParametersCompiled.MergeGenerated (compiler,
1855 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1856 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1858 (Attributes) $1, GetLocation ($3));
1860 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1861 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1862 (Attributes) $1, GetLocation ($3));
1865 current_local_parameters = current_property.Set.ParameterInfo;
1866 lbag.AddMember (current_property.Set, mod_locations);
1867 lexer.PropertyParsing = false;
1872 current_property.Set.Block = (ToplevelBlock) $5;
1874 if (current_container.Kind == MemberKind.Interface) {
1875 report.Error (531, current_property.Set.Block.StartLocation,
1876 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1880 current_local_parameters = null;
1881 lexer.PropertyParsing = true;
1884 && Lexer.doc_state == XmlCommentState.Error)
1885 Lexer.doc_state = XmlCommentState.NotAllowed;
1898 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1903 interface_declaration
1910 type_declaration_name
1912 lexer.ConstraintsParsing = true;
1913 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1914 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1917 opt_type_parameter_constraints_clauses
1919 lexer.ConstraintsParsing = false;
1922 current_container.SetConstraints ((List<Constraints>) $9);
1925 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1926 Lexer.doc_state = XmlCommentState.Allowed;
1929 lexer.parsing_modifiers = true;
1931 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1933 --lexer.parsing_declaration;
1935 Lexer.doc_state = XmlCommentState.Allowed;
1939 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1940 $$ = pop_current_class ();
1942 | opt_attributes opt_modifiers opt_partial INTERFACE error
1944 Error_SyntaxError (yyToken);
1948 opt_interface_member_declarations
1950 | interface_member_declarations
1953 interface_member_declarations
1954 : interface_member_declaration
1956 lexer.parsing_modifiers = true;
1958 | interface_member_declarations interface_member_declaration
1960 lexer.parsing_modifiers = true;
1964 interface_member_declaration
1965 : constant_declaration
1967 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1971 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1973 | method_declaration
1974 | property_declaration
1976 | indexer_declaration
1977 | operator_declaration
1979 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1981 | constructor_declaration
1983 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1987 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1991 operator_declaration
1992 : opt_attributes opt_modifiers operator_declarator
1997 OperatorDeclaration decl = (OperatorDeclaration) $3;
1999 Operator op = new Operator (
2000 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2001 current_local_parameters,
2002 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2004 if (op.Block == null)
2005 op.ParameterInfo.CheckParameters (op);
2008 op.DocComment = tmpComment;
2009 Lexer.doc_state = XmlCommentState.Allowed;
2012 // Note again, checking is done in semantic analysis
2013 current_type.AddOperator (op);
2015 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2018 current_local_parameters = null;
2024 | SEMICOLON { $$ = null; }
2028 : type_expression_or_array
2031 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2032 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2037 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2039 valid_param_mod = ParameterModifierType.DefaultValue;
2041 opt_formal_parameter_list CLOSE_PARENS
2043 valid_param_mod = 0;
2045 Location loc = GetLocation ($2);
2046 Operator.OpType op = (Operator.OpType) $3;
2047 current_local_parameters = (ParametersCompiled)$6;
2049 int p_count = current_local_parameters.Count;
2051 if (op == Operator.OpType.Addition)
2052 op = Operator.OpType.UnaryPlus;
2053 else if (op == Operator.OpType.Subtraction)
2054 op = Operator.OpType.UnaryNegation;
2057 if (IsUnaryOperator (op)) {
2059 report.Error (1020, loc, "Overloadable binary operator expected");
2060 } else if (p_count != 1) {
2061 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2062 Operator.GetName (op));
2066 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2067 Operator.GetName (op));
2068 } else if (p_count != 2) {
2069 report.Error (1019, loc, "Overloadable unary operator expected");
2074 tmpComment = Lexer.consume_doc_comment ();
2075 Lexer.doc_state = XmlCommentState.NotAllowed;
2078 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2079 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2081 | conversion_operator_declarator
2084 overloadable_operator
2086 : BANG { $$ = Operator.OpType.LogicalNot; }
2087 | TILDE { $$ = Operator.OpType.OnesComplement; }
2088 | OP_INC { $$ = Operator.OpType.Increment; }
2089 | OP_DEC { $$ = Operator.OpType.Decrement; }
2090 | TRUE { $$ = Operator.OpType.True; }
2091 | FALSE { $$ = Operator.OpType.False; }
2092 // Unary and binary:
2093 | PLUS { $$ = Operator.OpType.Addition; }
2094 | MINUS { $$ = Operator.OpType.Subtraction; }
2096 | STAR { $$ = Operator.OpType.Multiply; }
2097 | DIV { $$ = Operator.OpType.Division; }
2098 | PERCENT { $$ = Operator.OpType.Modulus; }
2099 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2100 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2101 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2102 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2103 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2104 | OP_EQ { $$ = Operator.OpType.Equality; }
2105 | OP_NE { $$ = Operator.OpType.Inequality; }
2106 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2107 | OP_LT { $$ = Operator.OpType.LessThan; }
2108 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2109 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2112 conversion_operator_declarator
2113 : IMPLICIT OPERATOR type OPEN_PARENS
2115 valid_param_mod = ParameterModifierType.DefaultValue;
2117 opt_formal_parameter_list CLOSE_PARENS
2119 valid_param_mod = 0;
2121 Location loc = GetLocation ($2);
2122 current_local_parameters = (ParametersCompiled)$6;
2124 if (current_local_parameters.Count != 1) {
2125 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2129 tmpComment = Lexer.consume_doc_comment ();
2130 Lexer.doc_state = XmlCommentState.NotAllowed;
2133 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2134 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2136 | EXPLICIT OPERATOR type OPEN_PARENS
2138 valid_param_mod = ParameterModifierType.DefaultValue;
2140 opt_formal_parameter_list CLOSE_PARENS
2142 valid_param_mod = 0;
2144 Location loc = GetLocation ($2);
2145 current_local_parameters = (ParametersCompiled)$6;
2147 if (current_local_parameters.Count != 1) {
2148 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2152 tmpComment = Lexer.consume_doc_comment ();
2153 Lexer.doc_state = XmlCommentState.NotAllowed;
2156 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2157 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2161 Error_SyntaxError (yyToken);
2162 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2163 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2167 Error_SyntaxError (yyToken);
2168 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2169 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2173 constructor_declaration
2174 : constructor_declarator
2177 Constructor c = (Constructor) $1;
2178 c.Block = (ToplevelBlock) $2;
2181 c.DocComment = ConsumeStoredComment ();
2183 current_local_parameters = null;
2185 Lexer.doc_state = XmlCommentState.Allowed;
2189 constructor_declarator
2195 tmpComment = Lexer.consume_doc_comment ();
2196 Lexer.doc_state = XmlCommentState.Allowed;
2199 valid_param_mod = ParameterModifierType.All;
2201 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2203 valid_param_mod = 0;
2204 current_local_parameters = (ParametersCompiled) $6;
2206 var lt = (Tokenizer.LocatedToken) $3;
2207 var mods = (Modifiers) $2;
2208 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2210 if (lt.Value != current_container.MemberName.Name) {
2211 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2212 } else if ((mods & Modifiers.STATIC) != 0) {
2213 if ((mods & Modifiers.AccessibilityMask) != 0){
2214 report.Error (515, c.Location,
2215 "`{0}': static constructor cannot have an access modifier",
2216 c.GetSignatureForError ());
2220 current_type.AddConstructor (c);
2221 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2225 // start block here, so possible anonymous methods inside
2226 // constructor initializer can get correct parent block
2228 start_block (lexer.Location);
2230 opt_constructor_initializer
2233 var c = (Constructor) $8;
2234 c.Initializer = (ConstructorInitializer) $9;
2237 report.Error (514, c.Location,
2238 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2239 c.GetSignatureForError ());
2249 | SEMICOLON { current_block = null; $$ = null; }
2252 opt_constructor_initializer
2254 | constructor_initializer
2257 constructor_initializer
2258 : COLON BASE OPEN_PARENS
2260 ++lexer.parsing_block;
2262 opt_argument_list CLOSE_PARENS
2264 --lexer.parsing_block;
2265 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2266 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2268 | COLON THIS OPEN_PARENS
2270 ++lexer.parsing_block;
2272 opt_argument_list CLOSE_PARENS
2274 --lexer.parsing_block;
2275 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2276 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2280 Error_SyntaxError (yyToken);
2281 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2282 lbag.AddLocation ($$, GetLocation ($1));
2286 Error_SyntaxError (yyToken);
2291 destructor_declaration
2292 : opt_attributes opt_modifiers TILDE
2295 tmpComment = Lexer.consume_doc_comment ();
2296 Lexer.doc_state = XmlCommentState.NotAllowed;
2299 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2301 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2303 var lt = (Tokenizer.LocatedToken) $5;
2304 if (lt.Value != current_container.MemberName.Name){
2305 report.Error (574, lt.Location, "Name of destructor must match name of class");
2306 } else if (current_container.Kind != MemberKind.Class){
2307 report.Error (575, lt.Location, "Only class types can contain destructor");
2310 Destructor d = new Destructor (current_type, (Modifiers) $2,
2311 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2313 d.DocComment = ConsumeStoredComment ();
2315 d.Block = (ToplevelBlock) $8;
2316 current_type.AddMember (d);
2317 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2319 current_local_parameters = null;
2326 EVENT type member_declaration_name
2328 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2329 current_type.AddMember (current_event_field);
2331 if (current_event_field.MemberName.ExplicitInterface != null) {
2332 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2333 current_event_field.GetSignatureForError ());
2336 $$ = current_event_field;
2338 opt_event_initializer
2339 opt_event_declarators
2343 current_event_field.DocComment = Lexer.consume_doc_comment ();
2344 Lexer.doc_state = XmlCommentState.Allowed;
2347 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2348 current_event_field = null;
2352 EVENT type member_declaration_name
2355 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2356 current_type.AddMember (current_event);
2357 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2359 lexer.EventParsing = true;
2361 event_accessor_declarations
2363 if (current_container.Kind == MemberKind.Interface)
2364 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2366 lexer.EventParsing = false;
2371 current_event.DocComment = Lexer.consume_doc_comment ();
2372 Lexer.doc_state = XmlCommentState.Allowed;
2375 lbag.AppendToMember (current_event, GetLocation ($9));
2376 current_event = null;
2377 current_local_parameters = null;
2383 Error_SyntaxError (yyToken);
2385 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2389 opt_event_initializer
2393 ++lexer.parsing_block;
2395 event_variable_initializer
2397 --lexer.parsing_block;
2398 current_event_field.Initializer = (Expression) $3;
2402 opt_event_declarators
2410 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2412 | event_declarators event_declarator
2414 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2421 var lt = (Tokenizer.LocatedToken) $2;
2422 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2423 lbag.AddLocation ($$, GetLocation ($1));
2425 | COMMA IDENTIFIER ASSIGN
2427 ++lexer.parsing_block;
2429 event_variable_initializer
2431 --lexer.parsing_block;
2432 var lt = (Tokenizer.LocatedToken) $2;
2433 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2434 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2438 event_variable_initializer
2440 if (current_container.Kind == MemberKind.Interface) {
2441 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2442 current_event_field.GetSignatureForError ());
2445 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2446 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2447 current_event_field.GetSignatureForError ());
2450 variable_initializer
2456 event_accessor_declarations
2457 : add_accessor_declaration remove_accessor_declaration
2458 | remove_accessor_declaration add_accessor_declaration
2459 | add_accessor_declaration
2461 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2462 current_event.GetSignatureForError ());
2464 | remove_accessor_declaration
2466 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2467 current_event.GetSignatureForError ());
2471 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2476 add_accessor_declaration
2477 : opt_attributes opt_modifiers ADD
2479 if ($2 != ModifierNone) {
2480 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2483 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2484 current_local_parameters = current_event.Add.ParameterInfo;
2486 lbag.AddMember (current_event.Add, mod_locations);
2487 lexer.EventParsing = false;
2489 event_accessor_block
2491 lexer.EventParsing = true;
2493 current_event.Add.Block = (ToplevelBlock) $5;
2495 if (current_container.Kind == MemberKind.Interface) {
2496 report.Error (531, current_event.Add.Block.StartLocation,
2497 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2500 current_local_parameters = null;
2504 remove_accessor_declaration
2505 : opt_attributes opt_modifiers REMOVE
2507 if ($2 != ModifierNone) {
2508 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2511 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2512 current_local_parameters = current_event.Remove.ParameterInfo;
2514 lbag.AddMember (current_event.Remove, mod_locations);
2515 lexer.EventParsing = false;
2517 event_accessor_block
2519 lexer.EventParsing = true;
2521 current_event.Remove.Block = (ToplevelBlock) $5;
2523 if (current_container.Kind == MemberKind.Interface) {
2524 report.Error (531, current_event.Remove.Block.StartLocation,
2525 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2528 current_local_parameters = null;
2532 event_accessor_block
2535 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2541 attributes_without_members
2542 : attribute_sections CLOSE_BRACE
2544 current_type.UnattachedAttributes = (Attributes) $1;
2545 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2546 lexer.putback ('}');
2550 // For full ast try to recover incomplete ambiguous member
2551 // declaration in form on class X { public int }
2553 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2555 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2557 lexer.putback ('}');
2559 lexer.parsing_generic_declaration = false;
2560 FullNamedExpression type = (FullNamedExpression) $3;
2561 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2562 current_type.AddField (current_field);
2570 ENUM type_declaration_name
2574 enumTypeComment = Lexer.consume_doc_comment ();
2579 Lexer.doc_state = XmlCommentState.Allowed;
2581 MemberName name = (MemberName) $4;
2582 if (name.IsGeneric) {
2583 report.Error (1675, name.Location, "Enums cannot have type parameters");
2586 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2588 opt_enum_member_declarations
2590 // here will be evaluated after CLOSE_BLACE is consumed.
2592 Lexer.doc_state = XmlCommentState.Allowed;
2594 CLOSE_BRACE opt_semicolon
2597 current_container.DocComment = enumTypeComment;
2599 --lexer.parsing_declaration;
2602 // em.DocComment = ev.DocComment;
2604 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2605 $$ = pop_current_class ();
2613 var te = $2 as TypeExpression;
2614 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2615 Enum.Error_1008 (GetLocation ($2), report);
2621 Error_TypeExpected (GetLocation ($1));
2626 opt_enum_member_declarations
2628 | enum_member_declarations
2629 | enum_member_declarations COMMA
2631 lbag.AddLocation ($1, GetLocation ($2));
2635 enum_member_declarations
2636 : enum_member_declaration
2637 | enum_member_declarations COMMA enum_member_declaration
2639 lbag.AddLocation ($1, GetLocation ($2));
2644 enum_member_declaration
2645 : opt_attributes IDENTIFIER
2647 var lt = (Tokenizer.LocatedToken) $2;
2648 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2649 ((Enum) current_type).AddEnumMember (em);
2652 em.DocComment = Lexer.consume_doc_comment ();
2653 Lexer.doc_state = XmlCommentState.Allowed;
2658 | opt_attributes IDENTIFIER
2660 ++lexer.parsing_block;
2662 tmpComment = Lexer.consume_doc_comment ();
2663 Lexer.doc_state = XmlCommentState.NotAllowed;
2666 ASSIGN constant_expression
2668 --lexer.parsing_block;
2670 var lt = (Tokenizer.LocatedToken) $2;
2671 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2672 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2673 ((Enum) current_type).AddEnumMember (em);
2676 em.DocComment = ConsumeStoredComment ();
2680 | opt_attributes IDENTIFIER error
2682 Error_SyntaxError (yyToken);
2684 var lt = (Tokenizer.LocatedToken) $2;
2685 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2686 ((Enum) current_type).AddEnumMember (em);
2689 em.DocComment = Lexer.consume_doc_comment ();
2690 Lexer.doc_state = XmlCommentState.Allowed;
2695 | attributes_without_members
2698 delegate_declaration
2702 member_type type_declaration_name
2705 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2707 opt_formal_parameter_list CLOSE_PARENS
2709 valid_param_mod = 0;
2711 ParametersCompiled p = (ParametersCompiled) $8;
2713 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2715 p.CheckParameters (del);
2717 current_container.AddTypeContainer (del);
2719 current_delegate = del;
2720 lexer.ConstraintsParsing = true;
2722 opt_type_parameter_constraints_clauses
2724 lexer.ConstraintsParsing = false;
2729 current_delegate.DocComment = Lexer.consume_doc_comment ();
2730 Lexer.doc_state = XmlCommentState.Allowed;
2734 current_delegate.SetConstraints ((List<Constraints>) $11);
2735 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2737 $$ = current_delegate;
2739 current_delegate = null;
2747 if (lang_version < LanguageVersion.ISO_2)
2748 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2750 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2754 namespace_or_type_expr
2756 | qualified_alias_member IDENTIFIER opt_type_argument_list
2758 var lt1 = (Tokenizer.LocatedToken) $1;
2759 var lt2 = (Tokenizer.LocatedToken) $2;
2761 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2762 lbag.AddLocation ($$, GetLocation ($2));
2768 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2770 var lt = (Tokenizer.LocatedToken) $3;
2771 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2772 lbag.AddLocation ($$, GetLocation ($2));
2777 : IDENTIFIER opt_type_argument_list
2779 var lt = (Tokenizer.LocatedToken) $1;
2780 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2785 // Generics arguments (any type, without attributes)
2787 opt_type_argument_list
2789 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2791 if (lang_version < LanguageVersion.ISO_2)
2792 FeatureIsNotAvailable (GetLocation ($1), "generics");
2796 | OP_GENERICS_LT error
2798 Error_TypeExpected (lexer.Location);
2799 $$ = new TypeArguments ();
2806 TypeArguments type_args = new TypeArguments ();
2807 type_args.Add ((FullNamedExpression) $1);
2810 | type_arguments COMMA type
2812 TypeArguments type_args = (TypeArguments) $1;
2813 type_args.Add ((FullNamedExpression) $3);
2819 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2821 type_declaration_name
2824 lexer.parsing_generic_declaration = true;
2826 opt_type_parameter_list
2828 lexer.parsing_generic_declaration = false;
2829 var lt = (Tokenizer.LocatedToken) $1;
2830 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2834 member_declaration_name
2835 : method_declaration_name
2837 MemberName mn = (MemberName)$1;
2838 if (mn.TypeParameters != null)
2839 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2840 mn.GetSignatureForError ()));
2844 method_declaration_name
2845 : type_declaration_name
2846 | explicit_interface IDENTIFIER opt_type_parameter_list
2848 lexer.parsing_generic_declaration = false;
2849 var lt = (Tokenizer.LocatedToken) $2;
2850 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2854 indexer_declaration_name
2857 lexer.parsing_generic_declaration = false;
2858 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2860 | explicit_interface THIS
2862 lexer.parsing_generic_declaration = false;
2863 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2868 : IDENTIFIER opt_type_argument_list DOT
2870 var lt = (Tokenizer.LocatedToken) $1;
2871 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2872 lbag.AddLocation ($$, GetLocation ($3));
2874 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2876 var lt1 = (Tokenizer.LocatedToken) $1;
2877 var lt2 = (Tokenizer.LocatedToken) $2;
2879 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2880 lbag.AddLocation ($$, GetLocation ($4));
2882 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2884 var lt = (Tokenizer.LocatedToken) $2;
2885 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2886 lbag.AddLocation ($$, GetLocation ($4));
2890 opt_type_parameter_list
2892 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2894 if (lang_version < LanguageVersion.ISO_2)
2895 FeatureIsNotAvailable (GetLocation ($1), "generics");
2898 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2905 var tparams = new TypeParameters ();
2906 tparams.Add ((TypeParameter)$1);
2909 | type_parameters COMMA type_parameter
2911 var tparams = (TypeParameters) $1;
2912 tparams.Add ((TypeParameter)$3);
2914 lbag.AddLocation ($3, GetLocation ($3));
2919 : opt_attributes opt_type_parameter_variance IDENTIFIER
2921 var lt = (Tokenizer.LocatedToken)$3;
2922 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2926 if (GetTokenName (yyToken) == "type")
2927 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2929 Error_SyntaxError (yyToken);
2931 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2936 // All types where void is allowed
2939 : type_expression_or_array
2942 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2949 lexer.parsing_generic_declaration = true;
2954 // A type which does not allow `void' to be used
2957 : type_expression_or_array
2960 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2961 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2969 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2970 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2975 : type_expression_or_array
2978 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2979 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2983 type_expression_or_array
2985 | type_expression rank_specifiers
2987 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2992 : namespace_or_type_expr opt_nullable
2995 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2997 var sn = $1 as SimpleName;
2998 if (sn != null && sn.Name == "var")
2999 $$ = new VarExpr (sn.Location);
3004 | namespace_or_type_expr pointer_stars
3006 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3008 | builtin_types opt_nullable
3011 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3013 | builtin_types pointer_stars
3015 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3017 | VOID pointer_stars
3019 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3026 var types = new List<FullNamedExpression> (2);
3027 types.Add ((FullNamedExpression) $1);
3030 | type_list COMMA base_type_name
3032 var types = (List<FullNamedExpression>) $1;
3033 types.Add ((FullNamedExpression) $3);
3041 if ($1 is ComposedCast) {
3042 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3049 * replaces all the productions for isolating the various
3050 * simple types, but we need this to reuse it easily in variable_type
3053 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3054 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3055 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3056 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3057 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3058 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3063 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3064 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3065 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3066 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3067 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3068 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3069 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3070 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3071 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3075 // Expressions, section 7.5
3080 : primary_expression_or_type
3082 | array_creation_expression
3083 | parenthesized_expression
3084 | default_value_expression
3085 | invocation_expression
3089 | post_increment_expression
3090 | post_decrement_expression
3091 | object_or_delegate_creation_expression
3092 | anonymous_type_expression
3095 | checked_expression
3096 | unchecked_expression
3097 | pointer_member_access
3098 | anonymous_method_expression
3099 | undocumented_expressions
3102 primary_expression_or_type
3103 : IDENTIFIER opt_type_argument_list
3105 var lt = (Tokenizer.LocatedToken) $1;
3106 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3108 | IDENTIFIER GENERATE_COMPLETION {
3109 var lt = (Tokenizer.LocatedToken) $1;
3110 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3118 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3122 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3123 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3128 // Here is the trick, tokenizer may think that parens is a special but
3129 // parser is interested in open parens only, so we merge them.
3130 // Consider: if (a)foo ();
3138 // Use this production to accept closing parenthesis or
3139 // performing completion
3143 | COMPLETE_COMPLETION
3147 parenthesized_expression
3148 : OPEN_PARENS expression CLOSE_PARENS
3150 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3151 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3153 | OPEN_PARENS expression COMPLETE_COMPLETION
3155 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3160 : primary_expression DOT identifier_inside_body opt_type_argument_list
3162 var lt = (Tokenizer.LocatedToken) $3;
3163 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3164 lbag.AddLocation ($$, GetLocation ($2));
3166 | builtin_types DOT identifier_inside_body opt_type_argument_list
3168 var lt = (Tokenizer.LocatedToken) $3;
3169 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3170 lbag.AddLocation ($$, GetLocation ($2));
3172 | BASE DOT identifier_inside_body opt_type_argument_list
3174 var lt = (Tokenizer.LocatedToken) $3;
3175 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3176 lbag.AddLocation ($$, GetLocation ($2));
3178 | qualified_alias_member identifier_inside_body opt_type_argument_list
3180 var lt1 = (Tokenizer.LocatedToken) $1;
3181 var lt2 = (Tokenizer.LocatedToken) $2;
3183 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3184 lbag.AddLocation ($$, GetLocation ($2));
3186 | primary_expression DOT GENERATE_COMPLETION {
3187 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3189 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3190 var lt = (Tokenizer.LocatedToken) $3;
3191 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3193 | builtin_types DOT GENERATE_COMPLETION
3195 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3197 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3198 var lt = (Tokenizer.LocatedToken) $3;
3199 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3203 invocation_expression
3204 : primary_expression open_parens_any opt_argument_list close_parens
3206 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3207 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3209 | primary_expression open_parens_any argument_list error
3211 Error_SyntaxError (yyToken);
3213 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3214 lbag.AddLocation ($$, GetLocation ($2));
3216 | primary_expression open_parens_any error
3218 Error_SyntaxError (yyToken);
3220 $$ = new Invocation ((Expression) $1, null);
3221 lbag.AddLocation ($$, GetLocation ($2));
3225 opt_object_or_collection_initializer
3226 : /* empty */ { $$ = null; }
3227 | object_or_collection_initializer
3230 object_or_collection_initializer
3231 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3234 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3236 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3238 lbag.AddLocation ($$, GetLocation ($3));
3240 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3242 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3243 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3247 opt_member_initializer_list
3248 : /* empty */ { $$ = null; }
3249 | member_initializer_list
3255 member_initializer_list
3256 : member_initializer
3258 var a = new List<Expression> ();
3259 a.Add ((Expression) $1);
3262 | member_initializer_list COMMA member_initializer
3264 var a = (List<Expression>)$1;
3265 a.Add ((Expression) $3);
3268 | member_initializer_list error {
3269 Error_SyntaxError (yyToken);
3275 : IDENTIFIER ASSIGN initializer_value
3277 var lt = (Tokenizer.LocatedToken) $1;
3278 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3279 lbag.AddLocation ($$, GetLocation ($2));
3281 | AWAIT ASSIGN initializer_value
3283 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
3284 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3285 lbag.AddLocation ($$, GetLocation ($2));
3287 | GENERATE_COMPLETION
3289 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3291 | non_assignment_expression opt_COMPLETE_COMPLETION {
3292 CompletionSimpleName csn = $1 as CompletionSimpleName;
3294 $$ = new CollectionElementInitializer ((Expression)$1);
3296 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3298 | OPEN_BRACE expression_list CLOSE_BRACE
3303 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3305 | OPEN_BRACE CLOSE_BRACE
3307 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3314 | object_or_collection_initializer
3318 : /* empty */ { $$ = null; }
3323 : argument_or_named_argument
3325 Arguments list = new Arguments (4);
3326 list.Add ((Argument) $1);
3329 | argument_list COMMA argument
3331 Arguments list = (Arguments) $1;
3332 if (list [list.Count - 1] is NamedArgument)
3333 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3335 list.Add ((Argument) $3);
3338 | argument_list COMMA named_argument
3340 Arguments list = (Arguments) $1;
3341 NamedArgument a = (NamedArgument) $3;
3342 for (int i = 0; i < list.Count; ++i) {
3343 NamedArgument na = list [i] as NamedArgument;
3344 if (na != null && na.Name == a.Name)
3345 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3352 | argument_list COMMA error
3354 if (lexer.putback_char == -1)
3355 lexer.putback (')'); // TODO: Wrong but what can I do
3356 Error_SyntaxError (yyToken);
3361 report.Error (839, GetLocation ($1), "An argument is missing");
3369 $$ = new Argument ((Expression) $1);
3371 | non_simple_argument
3374 argument_or_named_argument
3380 : REF variable_reference
3382 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3383 lbag.AddLocation ($$, GetLocation ($1));
3385 | OUT variable_reference
3387 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3388 lbag.AddLocation ($$, GetLocation ($1));
3390 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3392 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3393 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3395 | ARGLIST OPEN_PARENS CLOSE_PARENS
3397 $$ = new Argument (new Arglist (GetLocation ($1)));
3398 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3407 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3409 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3410 lbag.AddLocation ($$, GetLocation ($4));
3412 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3414 Error_SyntaxError (yyToken);
3415 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3417 | primary_expression OPEN_BRACKET_EXPR error
3419 Error_SyntaxError (yyToken);
3420 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3425 : expression_or_error
3427 var list = new List<Expression> (4);
3428 list.Add ((Expression) $1);
3431 | expression_list COMMA expression_or_error
3433 var list = (List<Expression>) $1;
3434 list.Add ((Expression) $3);
3439 expression_list_arguments
3440 : expression_list_argument
3442 Arguments args = new Arguments (4);
3443 args.Add ((Argument) $1);
3446 | expression_list_arguments COMMA expression_list_argument
3448 Arguments args = (Arguments) $1;
3449 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3450 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3452 args.Add ((Argument) $3);
3457 expression_list_argument
3460 $$ = new Argument ((Expression) $1);
3468 $$ = new This (GetLocation ($1));
3473 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3475 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3476 lbag.AddLocation ($$, GetLocation ($4));
3478 | BASE OPEN_BRACKET error
3480 Error_SyntaxError (yyToken);
3481 $$ = new ElementAccess (null, null, GetLocation ($2));
3485 post_increment_expression
3486 : primary_expression OP_INC
3488 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3492 post_decrement_expression
3493 : primary_expression OP_DEC
3495 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3499 object_or_delegate_creation_expression
3500 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3503 if (lang_version <= LanguageVersion.ISO_2)
3504 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3506 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3508 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3511 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3513 | NEW new_expr_type object_or_collection_initializer
3515 if (lang_version <= LanguageVersion.ISO_2)
3516 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3518 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3522 array_creation_expression
3523 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3525 opt_array_initializer
3527 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3528 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3529 Next = (ComposedTypeSpecifier) $6
3530 }, (ArrayInitializer) $7, GetLocation ($1));
3531 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3533 | NEW new_expr_type rank_specifiers opt_array_initializer
3536 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3538 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3540 | NEW rank_specifier array_initializer
3542 if (lang_version <= LanguageVersion.ISO_2)
3543 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3545 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3547 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3549 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3550 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3552 | NEW new_expr_type error
3554 Error_SyntaxError (yyToken);
3555 // It can be any of new expression, create the most common one
3556 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3562 ++lexer.parsing_type;
3566 --lexer.parsing_type;
3571 anonymous_type_expression
3572 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3574 if (lang_version <= LanguageVersion.ISO_2)
3575 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3577 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3579 // TODO: lbag comma location
3580 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3584 anonymous_type_parameters_opt_comma
3585 : anonymous_type_parameters_opt
3586 | anonymous_type_parameters COMMA
3589 anonymous_type_parameters_opt
3591 | anonymous_type_parameters
3594 anonymous_type_parameters
3595 : anonymous_type_parameter
3597 var a = new List<AnonymousTypeParameter> (4);
3598 a.Add ((AnonymousTypeParameter) $1);
3601 | anonymous_type_parameters COMMA anonymous_type_parameter
3603 var a = (List<AnonymousTypeParameter>) $1;
3604 a.Add ((AnonymousTypeParameter) $3);
3609 anonymous_type_parameter
3610 : identifier_inside_body ASSIGN variable_initializer
3612 var lt = (Tokenizer.LocatedToken)$1;
3613 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3614 lbag.AddLocation ($$, GetLocation ($2));
3616 | identifier_inside_body
3618 var lt = (Tokenizer.LocatedToken)$1;
3619 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3620 lt.Value, lt.Location);
3624 MemberAccess ma = (MemberAccess) $1;
3625 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3629 report.Error (746, lexer.Location,
3630 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3642 | rank_specifier rank_specifiers
3644 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3650 : OPEN_BRACKET CLOSE_BRACKET
3652 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3653 lbag.AddLocation ($$, GetLocation ($2));
3655 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3657 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3658 lbag.AddLocation ($$, GetLocation ($3));
3667 | dim_separators COMMA
3669 $$ = ((int) $1) + 1;
3673 opt_array_initializer
3685 : OPEN_BRACE CLOSE_BRACE
3687 var ai = new ArrayInitializer (0, GetLocation ($1));
3688 ai.VariableDeclaration = current_variable;
3689 lbag.AddLocation (ai, GetLocation ($2));
3692 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3694 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3695 ai.VariableDeclaration = current_variable;
3697 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3699 lbag.AddLocation (ai, GetLocation ($4));
3705 variable_initializer_list
3706 : variable_initializer
3708 var list = new List<Expression> (4);
3709 list.Add ((Expression) $1);
3712 | variable_initializer_list COMMA variable_initializer
3714 var list = (List<Expression>) $1;
3715 list.Add ((Expression) $3);
3723 lexer.TypeOfParsing = true;
3725 open_parens_any typeof_type_expression CLOSE_PARENS
3727 lexer.TypeOfParsing = false;
3728 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3729 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3733 typeof_type_expression
3738 Error_TypeExpected (lexer.Location);
3744 : identifier_inside_body generic_dimension
3746 var lt = (Tokenizer.LocatedToken) $1;
3748 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3750 | qualified_alias_member identifier_inside_body generic_dimension
3752 var lt1 = (Tokenizer.LocatedToken) $1;
3753 var lt2 = (Tokenizer.LocatedToken) $2;
3755 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3756 lbag.AddLocation ($$, GetLocation ($2));
3758 | unbound_type_name DOT identifier_inside_body
3760 var lt = (Tokenizer.LocatedToken) $3;
3762 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3764 | unbound_type_name DOT identifier_inside_body generic_dimension
3766 var lt = (Tokenizer.LocatedToken) $3;
3768 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3770 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3772 var tne = (ATypeNameExpression) $1;
3773 if (tne.HasTypeArguments)
3774 Error_TypeExpected (GetLocation ($4));
3776 var lt = (Tokenizer.LocatedToken) $3;
3777 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3784 if (lang_version < LanguageVersion.ISO_2)
3785 FeatureIsNotAvailable (GetLocation ($1), "generics");
3791 qualified_alias_member
3792 : IDENTIFIER DOUBLE_COLON
3794 var lt = (Tokenizer.LocatedToken) $1;
3795 if (lang_version == LanguageVersion.ISO_1)
3796 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3803 : SIZEOF open_parens_any type CLOSE_PARENS
3805 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3806 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3808 | SIZEOF open_parens_any type error
3810 Error_SyntaxError (yyToken);
3812 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3813 lbag.AddLocation ($$, GetLocation ($2));
3818 : CHECKED open_parens_any expression CLOSE_PARENS
3820 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3821 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3825 Error_SyntaxError (yyToken);
3827 $$ = new CheckedExpr (null, GetLocation ($1));
3831 unchecked_expression
3832 : UNCHECKED open_parens_any expression CLOSE_PARENS
3834 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3835 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3839 Error_SyntaxError (yyToken);
3841 $$ = new UnCheckedExpr (null, GetLocation ($1));
3845 pointer_member_access
3846 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3848 var lt = (Tokenizer.LocatedToken) $3;
3849 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3853 anonymous_method_expression
3854 : DELEGATE opt_anonymous_method_signature
3856 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3860 $$ = end_anonymous ((ParametersBlock) $4);
3862 | ASYNC DELEGATE opt_anonymous_method_signature
3864 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3868 $$ = end_anonymous ((ParametersBlock) $5);
3872 opt_anonymous_method_signature
3875 $$ = ParametersCompiled.Undefined;
3877 | anonymous_method_signature
3880 anonymous_method_signature
3883 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3885 opt_formal_parameter_list CLOSE_PARENS
3887 valid_param_mod = 0;
3892 default_value_expression
3893 : DEFAULT open_parens_any type CLOSE_PARENS
3895 if (lang_version < LanguageVersion.ISO_2)
3896 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3898 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3899 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3904 : primary_expression
3905 | BANG prefixed_unary_expression
3907 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3909 | TILDE prefixed_unary_expression
3911 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3913 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3915 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3916 lbag.AddLocation ($$, GetLocation ($3));
3918 | AWAIT prefixed_unary_expression
3921 if (current_anonymous_method is LambdaExpression) {
3922 report.Error (4034, GetLocation ($1),
3923 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3924 } else if (current_anonymous_method is AnonymousMethodExpression) {
3925 report.Error (4035, GetLocation ($1),
3926 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3928 report.Error (4033, GetLocation ($1),
3929 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3932 current_block.Explicit.RegisterAsyncAwait ();
3935 $$ = new Await ((Expression) $2, GetLocation ($1));
3939 Error_SyntaxError (yyToken);
3941 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3945 Error_SyntaxError (yyToken);
3947 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3949 | OPEN_PARENS_CAST type CLOSE_PARENS error
3951 Error_SyntaxError (yyToken);
3953 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3954 lbag.AddLocation ($$, GetLocation ($3));
3958 Error_SyntaxError (yyToken);
3960 $$ = new Await (null, GetLocation ($1));
3965 // The idea to split this out is from Rhys' grammar
3966 // to solve the problem with casts.
3968 prefixed_unary_expression
3970 | PLUS prefixed_unary_expression
3972 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3974 | MINUS prefixed_unary_expression
3976 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3978 | OP_INC prefixed_unary_expression
3980 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3982 | OP_DEC prefixed_unary_expression
3984 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3986 | STAR prefixed_unary_expression
3988 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3990 | BITWISE_AND prefixed_unary_expression
3992 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3996 Error_SyntaxError (yyToken);
3998 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4002 Error_SyntaxError (yyToken);
4004 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4008 Error_SyntaxError (yyToken);
4010 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4014 Error_SyntaxError (yyToken);
4016 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4020 Error_SyntaxError (yyToken);
4022 $$ = new Indirection (null, GetLocation ($1));
4026 Error_SyntaxError (yyToken);
4028 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4032 multiplicative_expression
4033 : prefixed_unary_expression
4034 | multiplicative_expression STAR prefixed_unary_expression
4036 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4037 lbag.AddLocation ($$, GetLocation ($2));
4039 | multiplicative_expression DIV prefixed_unary_expression
4041 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4042 lbag.AddLocation ($$, GetLocation ($2));
4044 | multiplicative_expression PERCENT prefixed_unary_expression
4046 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4047 lbag.AddLocation ($$, GetLocation ($2));
4049 | multiplicative_expression STAR error
4051 Error_SyntaxError (yyToken);
4053 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4054 lbag.AddLocation ($$, GetLocation ($2));
4056 | multiplicative_expression DIV error
4058 Error_SyntaxError (yyToken);
4060 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4061 lbag.AddLocation ($$, GetLocation ($2));
4063 | multiplicative_expression PERCENT error
4065 Error_SyntaxError (yyToken);
4067 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4068 lbag.AddLocation ($$, GetLocation ($2));
4073 : multiplicative_expression
4074 | additive_expression PLUS multiplicative_expression
4076 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4077 lbag.AddLocation ($$, GetLocation ($2));
4079 | additive_expression MINUS multiplicative_expression
4081 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4082 lbag.AddLocation ($$, GetLocation ($2));
4084 | additive_expression AS type
4086 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4088 | additive_expression IS type
4090 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4092 | additive_expression PLUS error
4094 Error_SyntaxError (yyToken);
4096 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4097 lbag.AddLocation ($$, GetLocation ($2));
4099 | additive_expression MINUS error
4101 Error_SyntaxError (yyToken);
4103 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4104 lbag.AddLocation ($$, GetLocation ($2));
4106 | additive_expression AS error
4108 Error_SyntaxError (yyToken);
4110 $$ = new As ((Expression) $1, null, GetLocation ($2));
4112 | additive_expression IS error
4114 Error_SyntaxError (yyToken);
4116 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4121 : additive_expression
4122 | shift_expression OP_SHIFT_LEFT additive_expression
4124 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4125 lbag.AddLocation ($$, GetLocation ($2));
4127 | shift_expression OP_SHIFT_RIGHT additive_expression
4129 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4130 lbag.AddLocation ($$, GetLocation ($2));
4132 | shift_expression OP_SHIFT_LEFT error
4134 Error_SyntaxError (yyToken);
4136 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4137 lbag.AddLocation ($$, GetLocation ($2));
4139 | shift_expression OP_SHIFT_RIGHT error
4141 Error_SyntaxError (yyToken);
4143 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4144 lbag.AddLocation ($$, GetLocation ($2));
4148 relational_expression
4150 | relational_expression OP_LT shift_expression
4152 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4153 lbag.AddLocation ($$, GetLocation ($2));
4155 | relational_expression OP_GT shift_expression
4157 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4158 lbag.AddLocation ($$, GetLocation ($2));
4160 | relational_expression OP_LE shift_expression
4162 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4163 lbag.AddLocation ($$, GetLocation ($2));
4165 | relational_expression OP_GE shift_expression
4167 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4168 lbag.AddLocation ($$, GetLocation ($2));
4170 | relational_expression OP_LT error
4172 Error_SyntaxError (yyToken);
4174 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4175 lbag.AddLocation ($$, GetLocation ($2));
4177 | relational_expression OP_GT error
4179 Error_SyntaxError (yyToken);
4181 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4182 lbag.AddLocation ($$, GetLocation ($2));
4184 | relational_expression OP_LE error
4186 Error_SyntaxError (yyToken);
4188 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4189 lbag.AddLocation ($$, GetLocation ($2));
4191 | relational_expression OP_GE error
4193 Error_SyntaxError (yyToken);
4195 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4196 lbag.AddLocation ($$, GetLocation ($2));
4201 : relational_expression
4202 | equality_expression OP_EQ relational_expression
4204 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4205 lbag.AddLocation ($$, GetLocation ($2));
4207 | equality_expression OP_NE relational_expression
4209 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4210 lbag.AddLocation ($$, GetLocation ($2));
4212 | equality_expression OP_EQ error
4214 Error_SyntaxError (yyToken);
4216 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4217 lbag.AddLocation ($$, GetLocation ($2));
4219 | equality_expression OP_NE error
4221 Error_SyntaxError (yyToken);
4223 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4224 lbag.AddLocation ($$, GetLocation ($2));
4229 : equality_expression
4230 | and_expression BITWISE_AND equality_expression
4232 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4233 lbag.AddLocation ($$, GetLocation ($2));
4235 | and_expression BITWISE_AND error
4237 Error_SyntaxError (yyToken);
4239 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4240 lbag.AddLocation ($$, GetLocation ($2));
4244 exclusive_or_expression
4246 | exclusive_or_expression CARRET and_expression
4248 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4249 lbag.AddLocation ($$, GetLocation ($2));
4251 | exclusive_or_expression CARRET error
4253 Error_SyntaxError (yyToken);
4255 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4256 lbag.AddLocation ($$, GetLocation ($2));
4260 inclusive_or_expression
4261 : exclusive_or_expression
4262 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4264 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4265 lbag.AddLocation ($$, GetLocation ($2));
4267 | inclusive_or_expression BITWISE_OR error
4269 Error_SyntaxError (yyToken);
4271 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4272 lbag.AddLocation ($$, GetLocation ($2));
4276 conditional_and_expression
4277 : inclusive_or_expression
4278 | conditional_and_expression OP_AND inclusive_or_expression
4280 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4281 lbag.AddLocation ($$, GetLocation ($2));
4283 | conditional_and_expression OP_AND error
4285 Error_SyntaxError (yyToken);
4287 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4288 lbag.AddLocation ($$, GetLocation ($2));
4292 conditional_or_expression
4293 : conditional_and_expression
4294 | conditional_or_expression OP_OR conditional_and_expression
4296 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4297 lbag.AddLocation ($$, GetLocation ($2));
4299 | conditional_or_expression OP_OR error
4301 Error_SyntaxError (yyToken);
4303 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4304 lbag.AddLocation ($$, GetLocation ($2));
4308 null_coalescing_expression
4309 : conditional_or_expression
4310 | conditional_or_expression OP_COALESCING null_coalescing_expression
4312 if (lang_version < LanguageVersion.ISO_2)
4313 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4315 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4316 lbag.AddLocation ($$, GetLocation ($2));
4320 conditional_expression
4321 : null_coalescing_expression
4322 | null_coalescing_expression INTERR expression COLON expression
4324 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4325 lbag.AddLocation ($$, GetLocation ($4));
4327 | null_coalescing_expression INTERR expression error
4329 Error_SyntaxError (yyToken);
4331 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4333 | null_coalescing_expression INTERR expression COLON error
4335 Error_SyntaxError (yyToken);
4337 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4338 lbag.AddLocation ($$, GetLocation ($4));
4342 assignment_expression
4343 : prefixed_unary_expression ASSIGN expression
4345 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4346 lbag.AddLocation ($$, GetLocation ($2));
4348 | prefixed_unary_expression OP_MULT_ASSIGN expression
4350 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4351 lbag.AddLocation ($$, GetLocation ($2));
4353 | prefixed_unary_expression OP_DIV_ASSIGN expression
4355 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4356 lbag.AddLocation ($$, GetLocation ($2));
4358 | prefixed_unary_expression OP_MOD_ASSIGN expression
4360 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4361 lbag.AddLocation ($$, GetLocation ($2));
4363 | prefixed_unary_expression OP_ADD_ASSIGN expression
4365 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4366 lbag.AddLocation ($$, GetLocation ($2));
4368 | prefixed_unary_expression OP_SUB_ASSIGN expression
4370 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4371 lbag.AddLocation ($$, GetLocation ($2));
4373 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4375 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4376 lbag.AddLocation ($$, GetLocation ($2));
4378 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4380 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4381 lbag.AddLocation ($$, GetLocation ($2));
4383 | prefixed_unary_expression OP_AND_ASSIGN expression
4385 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4386 lbag.AddLocation ($$, GetLocation ($2));
4388 | prefixed_unary_expression OP_OR_ASSIGN expression
4390 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4391 lbag.AddLocation ($$, GetLocation ($2));
4393 | prefixed_unary_expression OP_XOR_ASSIGN expression
4395 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4396 lbag.AddLocation ($$, GetLocation ($2));
4400 lambda_parameter_list
4403 var pars = new List<Parameter> (4);
4404 pars.Add ((Parameter) $1);
4408 | lambda_parameter_list COMMA lambda_parameter
4410 var pars = (List<Parameter>) $1;
4411 Parameter p = (Parameter)$3;
4412 if (pars[0].GetType () != p.GetType ()) {
4413 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4422 : parameter_modifier parameter_type identifier_inside_body
4424 var lt = (Tokenizer.LocatedToken) $3;
4426 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4428 | parameter_type identifier_inside_body
4430 var lt = (Tokenizer.LocatedToken) $2;
4432 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4436 var lt = (Tokenizer.LocatedToken) $1;
4437 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4441 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4442 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4446 opt_lambda_parameter_list
4447 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4448 | lambda_parameter_list {
4449 var pars_list = (List<Parameter>) $1;
4450 $$ = new ParametersCompiled (pars_list.ToArray ());
4454 lambda_expression_body
4456 start_block (Location.Null);
4458 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4460 Block b = end_block (Location.Null);
4461 b.IsCompilerGenerated = true;
4462 b.AddStatement (new ContextualReturn ((Expression) $2));
4468 // Handles only cases like foo = x.FirstOrDefault (l => );
4469 // where we must restore current_variable
4470 Block b = end_block (Location.Null);
4471 b.IsCompilerGenerated = true;
4473 Error_SyntaxError (yyToken);
4482 Error_SyntaxError (yyToken);
4490 var lt = (Tokenizer.LocatedToken) $1;
4491 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4492 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4494 lambda_expression_body
4496 $$ = end_anonymous ((ParametersBlock) $4);
4497 lbag.AddLocation ($$, GetLocation ($2));
4501 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4502 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4503 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4505 lambda_expression_body
4507 $$ = end_anonymous ((ParametersBlock) $4);
4508 lbag.AddLocation ($$, GetLocation ($2));
4510 | ASYNC identifier_inside_body ARROW
4512 var lt = (Tokenizer.LocatedToken) $2;
4513 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4514 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4516 lambda_expression_body
4518 $$ = end_anonymous ((ParametersBlock) $5);
4519 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4521 | OPEN_PARENS_LAMBDA
4523 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4525 opt_lambda_parameter_list CLOSE_PARENS ARROW
4527 valid_param_mod = 0;
4528 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4530 lambda_expression_body
4532 $$ = end_anonymous ((ParametersBlock) $7);
4533 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4535 | ASYNC OPEN_PARENS_LAMBDA
4537 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4539 opt_lambda_parameter_list CLOSE_PARENS ARROW
4541 valid_param_mod = 0;
4542 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4544 lambda_expression_body
4546 $$ = end_anonymous ((ParametersBlock) $8);
4547 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4552 : assignment_expression
4553 | non_assignment_expression
4556 non_assignment_expression
4557 : conditional_expression
4562 $$ = new ArglistAccess (GetLocation ($1));
4566 undocumented_expressions
4567 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4569 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4570 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4572 | REFTYPE open_parens_any expression CLOSE_PARENS
4574 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4575 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4577 | MAKEREF open_parens_any expression CLOSE_PARENS
4579 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4580 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4591 $$ = new BooleanExpression ((Expression) $1);
4605 type_declaration_name
4607 lexer.ConstraintsParsing = true;
4609 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4610 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4611 FeatureIsNotAvailable (c.Location, "static classes");
4614 push_current_container (c, $3);
4617 opt_type_parameter_constraints_clauses
4619 lexer.ConstraintsParsing = false;
4622 current_container.SetConstraints ((List<Constraints>) $9);
4623 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4626 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4627 Lexer.doc_state = XmlCommentState.Allowed;
4630 lexer.parsing_modifiers = true;
4632 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4634 --lexer.parsing_declaration;
4636 Lexer.doc_state = XmlCommentState.Allowed;
4640 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4641 $$ = pop_current_class ();
4649 { $$ = $1; } // location
4655 mod_locations = null;
4657 lexer.parsing_modifiers = false;
4661 lexer.parsing_modifiers = false;
4667 | modifiers modifier
4669 var m1 = (Modifiers) $1;
4670 var m2 = (Modifiers) $2;
4672 if ((m1 & m2) != 0) {
4673 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4674 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4675 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4676 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4677 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4678 "More than one protection modifier specified");
4689 StoreModifierLocation ($$, GetLocation ($1));
4691 if (current_container.Kind == MemberKind.Namespace)
4692 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4696 $$ = Modifiers.PUBLIC;
4697 StoreModifierLocation ($$, GetLocation ($1));
4701 $$ = Modifiers.PROTECTED;
4702 StoreModifierLocation ($$, GetLocation ($1));
4706 $$ = Modifiers.INTERNAL;
4707 StoreModifierLocation ($$, GetLocation ($1));
4711 $$ = Modifiers.PRIVATE;
4712 StoreModifierLocation ($$, GetLocation ($1));
4716 $$ = Modifiers.ABSTRACT;
4717 StoreModifierLocation ($$, GetLocation ($1));
4721 $$ = Modifiers.SEALED;
4722 StoreModifierLocation ($$, GetLocation ($1));
4726 $$ = Modifiers.STATIC;
4727 StoreModifierLocation ($$, GetLocation ($1));
4731 $$ = Modifiers.READONLY;
4732 StoreModifierLocation ($$, GetLocation ($1));
4736 $$ = Modifiers.VIRTUAL;
4737 StoreModifierLocation ($$, GetLocation ($1));
4741 $$ = Modifiers.OVERRIDE;
4742 StoreModifierLocation ($$, GetLocation ($1));
4746 $$ = Modifiers.EXTERN;
4747 StoreModifierLocation ($$, GetLocation ($1));
4751 $$ = Modifiers.VOLATILE;
4752 StoreModifierLocation ($$, GetLocation ($1));
4756 $$ = Modifiers.UNSAFE;
4757 StoreModifierLocation ($$, GetLocation ($1));
4758 if (!settings.Unsafe)
4759 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4763 $$ = Modifiers.ASYNC;
4764 StoreModifierLocation ($$, GetLocation ($1));
4772 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4774 | COLON type_list error
4776 Error_SyntaxError (yyToken);
4778 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4782 opt_type_parameter_constraints_clauses
4784 | type_parameter_constraints_clauses
4790 type_parameter_constraints_clauses
4791 : type_parameter_constraints_clause
4793 var constraints = new List<Constraints> (1);
4794 constraints.Add ((Constraints) $1);
4797 | type_parameter_constraints_clauses type_parameter_constraints_clause
4799 var constraints = (List<Constraints>) $1;
4800 Constraints new_constraint = (Constraints)$2;
4802 foreach (Constraints c in constraints) {
4803 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4804 report.Error (409, new_constraint.Location,
4805 "A constraint clause has already been specified for type parameter `{0}'",
4806 new_constraint.TypeParameter.Value);
4810 constraints.Add (new_constraint);
4815 type_parameter_constraints_clause
4816 : WHERE IDENTIFIER COLON type_parameter_constraints
4818 var lt = (Tokenizer.LocatedToken) $2;
4819 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4820 lbag.AddLocation ($$, GetLocation ($3));
4822 | WHERE IDENTIFIER error
4824 Error_SyntaxError (yyToken);
4826 var lt = (Tokenizer.LocatedToken) $2;
4827 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4831 type_parameter_constraints
4832 : type_parameter_constraint
4834 var constraints = new List<FullNamedExpression> (1);
4835 constraints.Add ((FullNamedExpression) $1);
4838 | type_parameter_constraints COMMA type_parameter_constraint
4840 var constraints = (List<FullNamedExpression>) $1;
4841 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4842 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4843 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4846 prev = $3 as SpecialContraintExpr;
4848 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4849 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4851 prev = constraints [0] as SpecialContraintExpr;
4852 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4853 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4858 constraints.Add ((FullNamedExpression) $3);
4863 type_parameter_constraint
4866 if ($1 is ComposedCast)
4867 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4871 | NEW OPEN_PARENS CLOSE_PARENS
4873 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4874 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4878 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4882 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4886 opt_type_parameter_variance
4891 | type_parameter_variance
4893 if (lang_version <= LanguageVersion.V_3)
4894 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4900 type_parameter_variance
4903 $$ = Variance.Covariant;
4907 $$ = Variance.Contravariant;
4916 // A block is "contained" on the following places:
4918 // property_declaration as part of the accessor body (get/set)
4919 // operator_declaration
4920 // constructor_declaration
4921 // destructor_declaration
4922 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4927 ++lexer.parsing_block;
4928 start_block (GetLocation ($1));
4930 opt_statement_list block_end
4939 --lexer.parsing_block;
4940 $$ = end_block (GetLocation ($1));
4942 | COMPLETE_COMPLETION
4944 --lexer.parsing_block;
4945 $$ = end_block (lexer.Location);
4953 ++lexer.parsing_block;
4954 current_block.StartLocation = GetLocation ($1);
4956 opt_statement_list CLOSE_BRACE
4958 --lexer.parsing_block;
4959 $$ = end_block (GetLocation ($4));
4970 | statement_list statement
4974 : block_variable_declaration
4976 current_block.AddStatement ((Statement) $1);
4978 | valid_declaration_statement
4980 current_block.AddStatement ((Statement) $1);
4985 Error_SyntaxError (yyToken);
4991 // The interactive_statement and its derivatives are only
4992 // used to provide a special version of `expression_statement'
4993 // that has a side effect of assigning the expression to
4996 interactive_statement_list
4997 : interactive_statement
4998 | interactive_statement_list interactive_statement
5001 interactive_statement
5002 : block_variable_declaration
5004 current_block.AddStatement ((Statement) $1);
5006 | interactive_valid_declaration_statement
5008 current_block.AddStatement ((Statement) $1);
5013 valid_declaration_statement
5016 | expression_statement
5017 | selection_statement
5018 | iteration_statement
5022 | unchecked_statement
5029 interactive_valid_declaration_statement
5032 | interactive_expression_statement
5033 | selection_statement
5034 | iteration_statement
5038 | unchecked_statement
5046 : valid_declaration_statement
5047 | block_variable_declaration
5049 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5054 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5059 Error_SyntaxError (yyToken);
5060 $$ = new EmptyStatement (GetLocation ($1));
5067 // Uses lexer.Location because semicolon location is not kept in quick mode
5068 $$ = new EmptyStatement (lexer.Location);
5073 : identifier_inside_body COLON
5075 var lt = (Tokenizer.LocatedToken) $1;
5076 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5077 lbag.AddLocation (labeled, GetLocation ($2));
5078 current_block.AddLabel (labeled);
5079 current_block.AddStatement (labeled);
5085 : variable_type_simple
5086 | variable_type_simple rank_specifiers
5089 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5091 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5096 * The following is from Rhys' grammar:
5097 * > Types in local variable declarations must be recognized as
5098 * > expressions to prevent reduce/reduce errors in the grammar.
5099 * > The expressions are converted into types during semantic analysis.
5101 variable_type_simple
5102 : primary_expression_or_type opt_nullable
5104 // Ok, the above "primary_expression" is there to get rid of
5105 // both reduce/reduce and shift/reduces in the grammar, it should
5106 // really just be "type_name". If you use type_name, a reduce/reduce
5107 // creeps up. If you use namespace_or_type_name (which is all we need
5108 // really) two shift/reduces appear.
5111 // So the super-trick is that primary_expression
5112 // can only be either a SimpleName or a MemberAccess.
5113 // The MemberAccess case arises when you have a fully qualified type-name like :
5115 // SimpleName is when you have
5118 Expression expr = (Expression) $1;
5120 SimpleName sn = expr as SimpleName;
5121 if (sn != null && sn.Name == "var")
5122 $$ = new VarExpr (sn.Location);
5125 } else if (expr is ATypeNameExpression) {
5126 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5128 Error_ExpectingTypeName (expr);
5132 | primary_expression_or_type pointer_stars
5134 ATypeNameExpression expr = $1 as ATypeNameExpression;
5137 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5139 Error_ExpectingTypeName ((Expression)$1);
5143 | builtin_types opt_nullable
5148 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5150 | builtin_types pointer_stars
5152 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5154 | VOID pointer_stars
5156 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5160 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5161 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5167 | pointer_star pointer_stars
5169 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5177 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5181 identifier_inside_body
5185 $$ = Error_AwaitAsIdentifier ($1);
5189 block_variable_declaration
5190 : variable_type identifier_inside_body
5192 var lt = (Tokenizer.LocatedToken) $2;
5193 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5194 current_block.AddLocalName (li);
5195 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5197 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5199 $$ = current_variable;
5200 current_variable = null;
5202 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5204 lbag.AddLocation ($$, GetLocation ($6));
5206 | CONST variable_type identifier_inside_body
5208 var lt = (Tokenizer.LocatedToken) $3;
5209 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5210 current_block.AddLocalName (li);
5211 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
5213 const_variable_initializer opt_const_declarators SEMICOLON
5215 $$ = current_variable;
5216 current_variable = null;
5217 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5221 opt_local_variable_initializer
5223 | ASSIGN block_variable_initializer
5225 current_variable.Initializer = (Expression) $2;
5226 PushLocation (GetLocation ($1));
5227 $$ = current_variable;
5231 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5232 report.Error (650, lexer.Location,
5233 "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");
5235 Error_SyntaxError (yyToken);
5240 opt_variable_declarators
5242 | variable_declarators
5245 opt_using_or_fixed_variable_declarators
5247 | variable_declarators
5249 foreach (var d in current_variable.Declarators) {
5250 if (d.Initializer == null)
5251 Error_MissingInitializer (d.Variable.Location);
5256 variable_declarators
5257 : variable_declarator
5258 | variable_declarators variable_declarator
5262 : COMMA identifier_inside_body
5264 var lt = (Tokenizer.LocatedToken) $2;
5265 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5266 var d = new BlockVariableDeclaration.Declarator (li, null);
5267 current_variable.AddDeclarator (d);
5268 current_block.AddLocalName (li);
5269 lbag.AddLocation (d, GetLocation ($1));
5271 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5273 var lt = (Tokenizer.LocatedToken) $2;
5274 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5275 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5276 current_variable.AddDeclarator (d);
5277 current_block.AddLocalName (li);
5278 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5282 const_variable_initializer
5285 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5287 | ASSIGN constant_initializer_expr
5289 current_variable.Initializer = (Expression) $2;
5293 opt_const_declarators
5300 | const_declarators const_declarator
5304 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5306 var lt = (Tokenizer.LocatedToken) $2;
5307 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5308 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5309 current_variable.AddDeclarator (d);
5310 current_block.AddLocalName (li);
5311 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5315 block_variable_initializer
5316 : variable_initializer
5317 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5319 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5320 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5322 | STACKALLOC simple_type
5324 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5325 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5329 expression_statement
5330 : statement_expression SEMICOLON
5333 lbag.AddStatement ($$, GetLocation ($2));
5335 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5336 | statement_expression CLOSE_BRACE
5339 report.Error (1002, GetLocation ($2), "; expected");
5340 lexer.putback ('}');
5344 interactive_expression_statement
5345 : interactive_statement_expression SEMICOLON { $$ = $1; }
5346 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5350 // We have to do the wrapping here and not in the case above,
5351 // because statement_expression is used for example in for_statement
5353 statement_expression
5356 ExpressionStatement s = $1 as ExpressionStatement;
5358 var expr = $1 as Expression;
5359 expr.Error_InvalidExpressionStatement (report);
5360 $$ = new StatementErrorExpression (expr);
5362 $$ = new StatementExpression (s);
5367 interactive_statement_expression
5370 Expression expr = (Expression) $1;
5371 ExpressionStatement s;
5373 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5374 $$ = new StatementExpression (s);
5378 Error_SyntaxError (yyToken);
5379 $$ = new EmptyStatement (GetLocation ($1));
5389 : IF open_parens_any boolean_expression CLOSE_PARENS
5392 if ($5 is EmptyStatement)
5393 Warning_EmptyStatement (GetLocation ($5));
5395 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5396 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5398 | IF open_parens_any boolean_expression CLOSE_PARENS
5399 embedded_statement ELSE embedded_statement
5401 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5402 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5404 if ($5 is EmptyStatement)
5405 Warning_EmptyStatement (GetLocation ($5));
5406 if ($7 is EmptyStatement)
5407 Warning_EmptyStatement (GetLocation ($7));
5409 | IF open_parens_any boolean_expression error
5411 Error_SyntaxError (yyToken);
5413 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5414 lbag.AddStatement ($$, GetLocation ($2));
5419 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5421 start_block (GetLocation ($5));
5423 opt_switch_sections CLOSE_BRACE
5425 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5426 end_block (GetLocation ($8));
5427 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5429 | SWITCH open_parens_any expression error
5431 Error_SyntaxError (yyToken);
5433 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5434 lbag.AddStatement ($$, GetLocation ($2));
5441 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5448 | switch_sections switch_section
5451 Error_SyntaxError (yyToken);
5456 : switch_labels statement_list
5462 var label = (SwitchLabel) $1;
5463 label.SectionStart = true;
5464 current_block.AddStatement (label);
5466 | switch_labels switch_label
5468 current_block.AddStatement ((Statement) $2);
5473 : CASE constant_expression COLON
5475 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5476 lbag.AddLocation ($$, GetLocation ($3));
5478 | CASE constant_expression error
5480 Error_SyntaxError (yyToken);
5481 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5485 $$ = new SwitchLabel (null, GetLocation ($1));
5497 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5499 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5500 Warning_EmptyStatement (GetLocation ($5));
5502 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5503 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5505 | WHILE open_parens_any boolean_expression error
5507 Error_SyntaxError (yyToken);
5509 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5510 lbag.AddStatement ($$, GetLocation ($2));
5515 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5517 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5518 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5520 | DO embedded_statement error
5522 Error_SyntaxError (yyToken);
5523 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5525 | DO embedded_statement WHILE open_parens_any boolean_expression error
5527 Error_SyntaxError (yyToken);
5529 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5530 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5535 : FOR open_parens_any
5537 start_block (GetLocation ($2));
5538 current_block.IsCompilerGenerated = true;
5539 For f = new For (GetLocation ($1));
5540 current_block.AddStatement (f);
5549 // Has to use be extra rule to recover started block
5551 : opt_for_initializer SEMICOLON
5553 ((For) $0).Initializer = (Statement) $1;
5555 // Pass the "For" object to the iterator_part4
5556 oob_stack.Push ($0);
5558 for_condition_and_iterator_part
5561 var locations = (Tuple<Location,Location>) $4;
5563 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5564 Warning_EmptyStatement (GetLocation ($5));
5567 f.Statement = (Statement) $5;
5568 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5570 $$ = end_block (GetLocation ($2));
5574 Error_SyntaxError (yyToken);
5575 $$ = end_block (current_block.StartLocation);
5579 for_condition_and_iterator_part
5580 : opt_for_condition SEMICOLON
5582 For f = (For) oob_stack.Peek ();
5583 f.Condition = (BooleanExpression) $1;
5586 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5589 // Handle errors in the case of opt_for_condition being followed by
5590 // a close parenthesis
5591 | opt_for_condition close_parens_close_brace {
5592 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5593 For f = (For) oob_stack.Peek ();
5594 f.Condition = (BooleanExpression) $1;
5595 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5600 : opt_for_iterator CLOSE_PARENS {
5601 For f = (For) oob_stack.Peek ();
5602 f.Iterator = (Statement) $1;
5603 $$ = GetLocation ($2);
5605 | opt_for_iterator CLOSE_BRACE {
5606 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5607 For f = (For) oob_stack.Peek ();
5608 f.Iterator = (Statement) $1;
5609 $$ = GetLocation ($2);
5613 close_parens_close_brace
5615 | CLOSE_BRACE { lexer.putback ('}'); }
5619 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5624 : variable_type identifier_inside_body
5626 var lt = (Tokenizer.LocatedToken) $2;
5627 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5628 current_block.AddLocalName (li);
5629 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5631 opt_local_variable_initializer opt_variable_declarators
5633 $$ = current_variable;
5635 lbag.AddLocation (current_variable, PopLocation ());
5637 current_variable = null;
5639 | statement_expression_list
5643 : /* empty */ { $$ = null; }
5644 | boolean_expression
5648 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5653 : statement_expression_list
5656 statement_expression_list
5657 : statement_expression
5658 | statement_expression_list COMMA statement_expression
5660 var sl = $1 as StatementList;
5662 sl = new StatementList ((Statement) $1, (Statement) $3);
5663 lbag.AddStatement (sl, GetLocation ($2));
5665 sl.Add ((Statement) $3);
5666 lbag.AppendTo (sl, GetLocation ($2));
5674 : FOREACH open_parens_any type error
5676 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5678 start_block (GetLocation ($2));
5679 current_block.IsCompilerGenerated = true;
5681 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5682 current_block.AddStatement (f);
5684 lbag.AddStatement (f, GetLocation ($2));
5685 $$ = end_block (GetLocation ($4));
5687 | FOREACH open_parens_any type identifier_inside_body error
5689 Error_SyntaxError (yyToken);
5691 start_block (GetLocation ($2));
5692 current_block.IsCompilerGenerated = true;
5694 var lt = (Tokenizer.LocatedToken) $4;
5695 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5696 current_block.AddLocalName (li);
5698 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5699 current_block.AddStatement (f);
5701 lbag.AddStatement (f, GetLocation ($2));
5702 $$ = end_block (GetLocation ($5));
5704 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5706 start_block (GetLocation ($2));
5707 current_block.IsCompilerGenerated = true;
5709 var lt = (Tokenizer.LocatedToken) $4;
5710 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5711 current_block.AddLocalName (li);
5716 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5717 Warning_EmptyStatement (GetLocation ($9));
5719 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5720 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5721 end_block (GetLocation ($7));
5729 | continue_statement
5739 $$ = new Break (GetLocation ($1));
5740 lbag.AddStatement ($$, GetLocation ($2));
5745 : CONTINUE SEMICOLON
5747 $$ = new Continue (GetLocation ($1));
5748 lbag.AddStatement ($$, GetLocation ($2));
5752 Error_SyntaxError (yyToken);
5753 $$ = new Continue (GetLocation ($1));
5758 : GOTO identifier_inside_body SEMICOLON
5760 var lt = (Tokenizer.LocatedToken) $2;
5761 $$ = new Goto (lt.Value, GetLocation ($1));
5762 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5764 | GOTO CASE constant_expression SEMICOLON
5766 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5767 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5769 | GOTO DEFAULT SEMICOLON
5771 $$ = new GotoDefault (GetLocation ($1));
5772 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5777 : RETURN opt_expression SEMICOLON
5779 $$ = new Return ((Expression) $2, GetLocation ($1));
5780 lbag.AddStatement ($$, GetLocation ($3));
5782 | RETURN expression error
5784 Error_SyntaxError (yyToken);
5785 $$ = new Return ((Expression) $2, GetLocation ($1));
5789 Error_SyntaxError (yyToken);
5790 $$ = new Return (null, GetLocation ($1));
5795 : THROW opt_expression SEMICOLON
5797 $$ = new Throw ((Expression) $2, GetLocation ($1));
5798 lbag.AddStatement ($$, GetLocation ($3));
5802 Error_SyntaxError (yyToken);
5803 $$ = new Throw (null, GetLocation ($1));
5808 : identifier_inside_body RETURN opt_expression SEMICOLON
5810 var lt = (Tokenizer.LocatedToken) $1;
5811 string s = lt.Value;
5813 report.Error (1003, lt.Location, "; expected");
5814 } else if ($3 == null) {
5815 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5816 } else if (lang_version == LanguageVersion.ISO_1){
5817 FeatureIsNotAvailable (lt.Location, "iterators");
5820 current_block.Explicit.RegisterIteratorYield ();
5821 $$ = new Yield ((Expression) $3, lt.Location);
5822 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5824 | identifier_inside_body RETURN expression error
5826 Error_SyntaxError (yyToken);
5828 var lt = (Tokenizer.LocatedToken) $1;
5829 string s = lt.Value;
5831 report.Error (1003, lt.Location, "; expected");
5832 } else if ($3 == null) {
5833 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5834 } else if (lang_version == LanguageVersion.ISO_1){
5835 FeatureIsNotAvailable (lt.Location, "iterators");
5838 current_block.Explicit.RegisterIteratorYield ();
5839 $$ = new Yield ((Expression) $3, lt.Location);
5840 lbag.AddStatement ($$, GetLocation ($2));
5842 | identifier_inside_body BREAK SEMICOLON
5844 var lt = (Tokenizer.LocatedToken) $1;
5845 string s = lt.Value;
5847 report.Error (1003, lt.Location, "; expected");
5848 } else if (lang_version == LanguageVersion.ISO_1){
5849 FeatureIsNotAvailable (lt.Location, "iterators");
5852 current_block.Explicit.RegisterIteratorYield ();
5853 $$ = new YieldBreak (lt.Location);
5854 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5864 : TRY block catch_clauses
5866 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5868 | TRY block FINALLY block
5870 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5871 lbag.AddStatement ($$, GetLocation ($3));
5873 | TRY block catch_clauses FINALLY block
5875 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5876 lbag.AddStatement ($$, GetLocation ($4));
5880 Error_SyntaxError (1524, yyToken);
5881 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5888 var l = new List<Catch> (2);
5893 | catch_clauses catch_clause
5895 var l = (List<Catch>) $1;
5897 Catch c = (Catch) $2;
5898 if (l [l.Count - 1].IsGeneral) {
5899 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5909 | identifier_inside_body
5915 $$ = new Catch ((Block) $2, GetLocation ($1));
5917 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5919 start_block (GetLocation ($2));
5920 var c = new Catch (current_block, GetLocation ($1));
5921 c.TypeExpression = (FullNamedExpression) $3;
5924 var lt = (Tokenizer.LocatedToken) $4;
5925 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5926 current_block.AddLocalName (c.Variable);
5929 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5936 | CATCH open_parens_any error
5938 if (yyToken == Token.CLOSE_PARENS) {
5939 report.Error (1015, lexer.Location,
5940 "A type that derives from `System.Exception', `object', or `string' expected");
5942 Error_SyntaxError (yyToken);
5945 $$ = new Catch (null, GetLocation ($1));
5947 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5949 Error_SyntaxError (yyToken);
5951 // Required otherwise missing block could not be detected because
5952 // start_block is run early
5953 var c = new Catch (null, GetLocation ($1));
5954 c.TypeExpression = (FullNamedExpression) $3;
5957 var lt = (Tokenizer.LocatedToken) $4;
5958 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5961 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5970 $$ = new Checked ((Block) $2, GetLocation ($1));
5977 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5984 if (!settings.Unsafe)
5985 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5987 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5992 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5994 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5995 Warning_EmptyStatement (GetLocation ($5));
5997 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5998 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6000 | LOCK open_parens_any expression error
6002 Error_SyntaxError (yyToken);
6004 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6005 lbag.AddStatement ($$, GetLocation ($2));
6010 : FIXED open_parens_any variable_type identifier_inside_body
6012 start_block (GetLocation ($2));
6014 current_block.IsCompilerGenerated = true;
6015 var lt = (Tokenizer.LocatedToken) $4;
6016 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6017 current_block.AddLocalName (li);
6018 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6020 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6022 $$ = current_variable;
6023 current_variable = null;
6027 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6028 Warning_EmptyStatement (GetLocation ($10));
6030 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6031 current_block.AddStatement (f);
6032 $$ = end_block (GetLocation ($8));
6037 : USING open_parens_any variable_type identifier_inside_body
6039 start_block (GetLocation ($2));
6041 current_block.IsCompilerGenerated = true;
6042 var lt = (Tokenizer.LocatedToken) $4;
6043 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6044 current_block.AddLocalName (li);
6045 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6047 using_initialization CLOSE_PARENS
6049 $$ = current_variable;
6050 current_variable = null;
6054 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6055 Warning_EmptyStatement (GetLocation ($9));
6057 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6058 current_block.AddStatement (u);
6059 $$ = end_block (GetLocation ($7));
6061 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6063 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6064 Warning_EmptyStatement (GetLocation ($5));
6066 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6067 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6069 | USING open_parens_any expression error
6071 Error_SyntaxError (yyToken);
6073 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6074 lbag.AddStatement ($$, GetLocation ($2));
6078 using_initialization
6079 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6082 // It has to be here for the parent to safely restore artificial block
6083 Error_SyntaxError (yyToken);
6087 using_or_fixed_variable_initializer
6090 Error_MissingInitializer (lexer.Location);
6092 | ASSIGN variable_initializer
6094 current_variable.Initializer = (Expression) $2;
6095 $$ = current_variable;
6103 : first_from_clause query_body
6105 lexer.query_parsing = false;
6107 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6109 from.Tail.Next = (Linq.AQueryClause)$2;
6112 current_block.SetEndLocation (lexer.Location);
6113 current_block = current_block.Parent;
6115 | nested_from_clause query_body
6117 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6119 from.Tail.Next = (Linq.AQueryClause)$2;
6122 current_block.SetEndLocation (lexer.Location);
6123 current_block = current_block.Parent;
6126 // Bubble up COMPLETE_COMPLETION productions
6127 | first_from_clause COMPLETE_COMPLETION {
6128 lexer.query_parsing = false;
6131 current_block.SetEndLocation (lexer.Location);
6132 current_block = current_block.Parent;
6134 | nested_from_clause COMPLETE_COMPLETION {
6136 current_block.SetEndLocation (lexer.Location);
6137 current_block = current_block.Parent;
6142 : FROM_FIRST identifier_inside_body IN expression
6144 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6146 var lt = (Tokenizer.LocatedToken) $2;
6147 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6148 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6150 | FROM_FIRST type identifier_inside_body IN expression
6152 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6154 var lt = (Tokenizer.LocatedToken) $3;
6155 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6156 $$ = new Linq.QueryExpression (
6157 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6158 IdentifierType = (FullNamedExpression)$2
6165 : FROM identifier_inside_body IN expression
6167 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6169 var lt = (Tokenizer.LocatedToken) $2;
6170 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6171 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6173 | FROM type identifier_inside_body IN expression
6175 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6177 var lt = (Tokenizer.LocatedToken) $3;
6178 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6179 $$ = new Linq.QueryExpression (
6180 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6181 IdentifierType = (FullNamedExpression)$2
6188 : FROM identifier_inside_body IN
6190 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6194 var lt = (Tokenizer.LocatedToken) $2;
6195 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6196 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6198 current_block.SetEndLocation (lexer.Location);
6199 current_block = current_block.Parent;
6201 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6203 | FROM type identifier_inside_body IN
6205 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6209 var lt = (Tokenizer.LocatedToken) $3;
6210 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6212 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6213 IdentifierType = (FullNamedExpression)$2
6216 current_block.SetEndLocation (lexer.Location);
6217 current_block = current_block.Parent;
6219 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6224 : query_body_clauses select_or_group_clause opt_query_continuation
6226 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6229 head.Next = (Linq.AQueryClause)$3;
6232 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6233 clause.Tail.Next = head;
6239 | select_or_group_clause opt_query_continuation
6241 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6244 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6245 clause.Tail.Next = head;
6251 | query_body_clauses COMPLETE_COMPLETION
6252 | query_body_clauses error
6254 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6259 Error_SyntaxError (yyToken);
6264 select_or_group_clause
6267 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6271 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6273 current_block.SetEndLocation (lexer.Location);
6274 current_block = current_block.Parent;
6278 if (linq_clause_blocks == null)
6279 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6281 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6282 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6286 current_block.SetEndLocation (lexer.Location);
6287 current_block = current_block.Parent;
6289 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6293 var obj = (object[]) $5;
6295 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6296 lbag.AddLocation ($$, (Location) obj[1]);
6298 current_block.SetEndLocation (lexer.Location);
6299 current_block = current_block.Parent;
6304 : BY expression_or_error
6306 $$ = new object[] { $2, GetLocation ($1) };
6310 Error_SyntaxError (yyToken);
6311 $$ = new object[2] { null, Location.Null };
6317 | query_body_clauses query_body_clause
6319 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6333 : LET identifier_inside_body ASSIGN
6335 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6339 var lt = (Tokenizer.LocatedToken) $2;
6340 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6341 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6342 lbag.AddLocation ($$, GetLocation ($3));
6344 current_block.SetEndLocation (lexer.Location);
6345 current_block = current_block.Parent;
6347 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6354 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6358 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6360 current_block.SetEndLocation (lexer.Location);
6361 current_block = current_block.Parent;
6366 : JOIN identifier_inside_body IN
6368 if (linq_clause_blocks == null)
6369 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6371 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6372 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6374 expression_or_error ON
6376 current_block.SetEndLocation (lexer.Location);
6377 current_block = current_block.Parent;
6379 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6380 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6382 expression_or_error EQUALS
6384 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6385 current_block.SetEndLocation (lexer.Location);
6386 current_block = current_block.Parent;
6388 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6390 expression_or_error opt_join_into
6392 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6393 current_block.SetEndLocation (lexer.Location);
6395 var outer_selector = linq_clause_blocks.Pop ();
6396 var block = linq_clause_blocks.Pop ();
6398 var lt = (Tokenizer.LocatedToken) $2;
6399 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6400 Linq.RangeVariable into;
6404 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6405 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6408 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6410 var parent = block.Parent;
6411 while (parent is Linq.QueryBlock) {
6412 parent = parent.Parent;
6414 current_block.Parent = parent;
6416 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6418 lt = (Tokenizer.LocatedToken) $12;
6419 into = new Linq.RangeVariable (lt.Value, lt.Location);
6421 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6422 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6425 current_block = block.Parent;
6426 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6428 | JOIN type identifier_inside_body IN
6430 if (linq_clause_blocks == null)
6431 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6433 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6434 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6436 expression_or_error ON
6438 current_block.SetEndLocation (lexer.Location);
6439 current_block = current_block.Parent;
6441 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6442 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6444 expression_or_error EQUALS
6446 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6447 current_block.SetEndLocation (lexer.Location);
6448 current_block = current_block.Parent;
6450 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6452 expression_or_error opt_join_into
6454 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6455 current_block.SetEndLocation (lexer.Location);
6457 var outer_selector = linq_clause_blocks.Pop ();
6458 var block = linq_clause_blocks.Pop ();
6460 var lt = (Tokenizer.LocatedToken) $3;
6461 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6462 Linq.RangeVariable into;
6466 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6467 IdentifierType = (FullNamedExpression)$2
6471 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6473 var parent = block.Parent;
6474 while (parent is Linq.QueryBlock) {
6475 parent = parent.Parent;
6477 current_block.Parent = parent;
6479 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6481 lt = (Tokenizer.LocatedToken) $13;
6482 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6484 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6485 IdentifierType = (FullNamedExpression)$2
6489 current_block = block.Parent;
6490 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6496 | INTO identifier_inside_body
6505 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6509 current_block.SetEndLocation (lexer.Location);
6510 current_block = current_block.Parent;
6520 current_block.SetEndLocation (lexer.Location);
6521 current_block = current_block.Parent;
6523 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6527 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6534 | orderings_then_by COMMA
6536 current_block.SetEndLocation (lexer.Location);
6537 current_block = current_block.Parent;
6539 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6543 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6551 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6553 | expression ASCENDING
6555 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6556 lbag.AddLocation ($$, GetLocation ($2));
6558 | expression DESCENDING
6560 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6561 lbag.AddLocation ($$, GetLocation ($2));
6568 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6570 | expression ASCENDING
6572 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6573 lbag.AddLocation ($$, GetLocation ($2));
6575 | expression DESCENDING
6577 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6578 lbag.AddLocation ($$, GetLocation ($2));
6583 opt_query_continuation
6585 | INTO identifier_inside_body
6587 // query continuation block is not linked with query block but with block
6588 // before. This means each query can use same range variable names for
6589 // different identifiers.
6591 current_block.SetEndLocation (GetLocation ($1));
6592 current_block = current_block.Parent;
6594 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6596 if (linq_clause_blocks == null)
6597 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6599 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6603 var current_block = linq_clause_blocks.Pop ();
6604 var lt = (Tokenizer.LocatedToken) $2;
6605 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6606 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6607 next = (Linq.AQueryClause)$4
6613 // Support for using the compiler as an interactive parser
6615 // The INTERACTIVE_PARSER token is first sent to parse our
6616 // productions; If the result is a Statement, the parsing
6617 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6618 // to setup the blocks in advance.
6620 // This setup is here so that in the future we can add
6621 // support for other constructs (type parsing, namespaces, etc)
6622 // that do not require a block to be setup in advance
6626 : EVAL_STATEMENT_PARSER EOF
6627 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6628 | EVAL_STATEMENT_PARSER
6630 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6632 // (ref object retval)
6633 Parameter [] mpar = new Parameter [1];
6634 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6636 ParametersCompiled pars = new ParametersCompiled (mpar);
6637 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6638 if (settings.Unsafe)
6639 mods |= Modifiers.UNSAFE;
6641 current_local_parameters = pars;
6642 Method method = new Method (
6644 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6646 new MemberName ("Host"),
6648 null /* attributes */);
6650 current_type.AddMember (method);
6652 oob_stack.Push (method);
6653 ++lexer.parsing_block;
6654 start_block (lexer.Location);
6656 interactive_statement_list opt_COMPLETE_COMPLETION
6658 --lexer.parsing_block;
6659 Method method = (Method) oob_stack.Pop ();
6661 method.Block = (ToplevelBlock) end_block(lexer.Location);
6663 InteractiveResult = (Class) pop_current_class ();
6664 current_local_parameters = null;
6666 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6669 interactive_compilation_unit
6670 : opt_extern_alias_directives opt_using_directives
6671 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6674 opt_COMPLETE_COMPLETION
6676 | COMPLETE_COMPLETION
6679 close_brace_or_complete_completion
6681 | COMPLETE_COMPLETION
6685 // XML documentation code references micro parser
6687 documentation_parsing
6690 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6695 : doc_type_declaration_name opt_doc_method_sig
6697 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6699 | builtin_types opt_doc_method_sig
6701 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6702 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6705 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6707 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6708 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6709 var lt = (Tokenizer.LocatedToken) $3;
6710 $$ = new MemberName (lt.Value);
6712 | doc_type_declaration_name DOT THIS
6714 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6716 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6718 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6720 opt_doc_parameters CLOSE_BRACKET
6722 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6723 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6725 | EXPLICIT OPERATOR type opt_doc_method_sig
6727 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6728 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6729 module.DocumentationBuilder.ParsedParameters = p;
6730 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6733 | IMPLICIT OPERATOR type opt_doc_method_sig
6735 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6736 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6737 module.DocumentationBuilder.ParsedParameters = p;
6738 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6741 | OPERATOR overloadable_operator opt_doc_method_sig
6743 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6744 module.DocumentationBuilder.ParsedParameters = p;
6745 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6750 doc_type_declaration_name
6751 : type_declaration_name
6752 | doc_type_declaration_name DOT type_declaration_name
6754 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6762 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6764 opt_doc_parameters CLOSE_PARENS
6773 $$ = new List<DocumentationParameter> (0);
6781 var parameters = new List<DocumentationParameter> ();
6782 parameters.Add ((DocumentationParameter) $1);
6785 | doc_parameters COMMA doc_parameter
6787 var parameters = $1 as List<DocumentationParameter>;
6788 parameters.Add ((DocumentationParameter) $3);
6794 : opt_parameter_modifier parameter_type
6797 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6799 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6806 // A class used to hold info about an operator declarator
6808 class OperatorDeclaration {
6809 public readonly Operator.OpType optype;
6810 public readonly FullNamedExpression ret_type;
6811 public readonly Location location;
6813 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6816 this.ret_type = ret_type;
6817 this.location = location;
6821 void Error_ExpectingTypeName (Expression expr)
6823 if (expr is Invocation){
6824 report.Error (1002, expr.Location, "Expecting `;'");
6826 expr.Error_InvalidExpressionStatement (report);
6830 void Error_ParameterModifierNotValid (string modifier, Location loc)
6832 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6836 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6838 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6839 Parameter.GetModifierSignature (mod));
6842 void Error_TypeExpected (Location loc)
6844 report.Error (1031, loc, "Type expected");
6847 void Error_UnsafeCodeNotAllowed (Location loc)
6849 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6852 void Warning_EmptyStatement (Location loc)
6854 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6857 void Error_NamedArgumentExpected (NamedArgument a)
6859 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6862 void Error_MissingInitializer (Location loc)
6864 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6867 object Error_AwaitAsIdentifier (object token)
6870 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6871 return new Tokenizer.LocatedToken ("await", GetLocation (token));
6877 void push_current_container (TypeDefinition tc, object partial_token)
6879 if (module.Evaluator != null){
6880 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6884 undo.AddTypeContainer (current_container, tc);
6887 if (partial_token != null)
6888 current_container.AddPartial (tc);
6890 current_container.AddTypeContainer (tc);
6892 ++lexer.parsing_declaration;
6893 current_container = tc;
6897 TypeContainer pop_current_class ()
6899 var retval = current_container;
6901 current_container = current_container.Parent;
6902 current_type = current_type.Parent as TypeDefinition;
6907 [System.Diagnostics.Conditional ("FULL_AST")]
6908 void StoreModifierLocation (object token, Location loc)
6913 if (mod_locations == null)
6914 mod_locations = new List<Tuple<Modifiers, Location>> ();
6916 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6919 [System.Diagnostics.Conditional ("FULL_AST")]
6920 void PushLocation (Location loc)
6922 if (location_stack == null)
6923 location_stack = new Stack<Location> ();
6925 location_stack.Push (loc);
6928 Location PopLocation ()
6930 if (location_stack == null)
6931 return Location.Null;
6933 return location_stack.Pop ();
6936 string CheckAttributeTarget (string a, Location l)
6939 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6943 report.Warning (658, 1, l,
6944 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6945 return string.Empty;
6948 static bool IsUnaryOperator (Operator.OpType op)
6952 case Operator.OpType.LogicalNot:
6953 case Operator.OpType.OnesComplement:
6954 case Operator.OpType.Increment:
6955 case Operator.OpType.Decrement:
6956 case Operator.OpType.True:
6957 case Operator.OpType.False:
6958 case Operator.OpType.UnaryPlus:
6959 case Operator.OpType.UnaryNegation:
6965 void syntax_error (Location l, string msg)
6967 report.Error (1003, l, "Syntax error, " + msg);
6972 public Tokenizer Lexer {
6978 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6979 : this (reader, file, file.Compiler.Report, session)
6983 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6986 current_container = current_namespace = file;
6988 this.module = file.Module;
6989 this.compiler = file.Compiler;
6990 this.settings = compiler.Settings;
6991 this.report = report;
6993 lang_version = settings.Version;
6994 yacc_verbose_flag = settings.VerboseParserFlag;
6995 doc_support = settings.DocumentationFile != null;
6996 lexer = new Tokenizer (reader, file, session);
6997 oob_stack = new Stack<object> ();
6998 lbag = session.LocationsBag;
6999 use_global_stacks = session.UseJayGlobalArrays;
7000 parameters_bucket = session.ParametersStack;
7003 public void parse ()
7005 eof_token = Token.EOF;
7008 if (yacc_verbose_flag > 1)
7009 yyparse (lexer, new yydebug.yyDebugSimple ());
7013 Tokenizer tokenizer = lexer as Tokenizer;
7014 tokenizer.cleanup ();
7015 } catch (Exception e){
7016 if (e is yyParser.yyUnexpectedEof) {
7017 Error_SyntaxError (yyToken);
7018 UnexpectedEOF = true;
7022 if (e is yyParser.yyException) {
7023 if (report.Errors == 0)
7024 report.Error (-25, lexer.Location, "Parsing error");
7026 // Used by compiler-tester to test internal errors
7027 if (yacc_verbose_flag > 0 || e is FatalException)
7030 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7035 void CheckToken (int error, int yyToken, string msg, Location loc)
7037 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7038 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7040 report.Error (error, loc, msg);
7043 string ConsumeStoredComment ()
7045 string s = tmpComment;
7047 Lexer.doc_state = XmlCommentState.Allowed;
7051 void FeatureIsNotAvailable (Location loc, string feature)
7053 report.FeatureIsNotAvailable (compiler, loc, feature);
7056 Location GetLocation (object obj)
7058 var lt = obj as Tokenizer.LocatedToken;
7062 var mn = obj as MemberName;
7066 var expr = obj as Expression;
7068 return expr.Location;
7070 return lexer.Location;
7073 void start_block (Location loc)
7075 if (current_block == null) {
7076 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7077 parsing_anonymous_method = false;
7078 } else if (parsing_anonymous_method) {
7079 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7080 parsing_anonymous_method = false;
7082 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7087 end_block (Location loc)
7089 Block retval = current_block.Explicit;
7090 retval.SetEndLocation (loc);
7091 current_block = retval.Parent;
7095 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7097 oob_stack.Push (current_anonymous_method);
7098 oob_stack.Push (current_local_parameters);
7099 oob_stack.Push (current_variable);
7100 oob_stack.Push (async_block);
7102 current_local_parameters = parameters;
7104 if (lang_version <= LanguageVersion.ISO_2)
7105 FeatureIsNotAvailable (loc, "lambda expressions");
7107 current_anonymous_method = new LambdaExpression (loc);
7109 if (lang_version == LanguageVersion.ISO_1)
7110 FeatureIsNotAvailable (loc, "anonymous methods");
7112 current_anonymous_method = new AnonymousMethodExpression (loc);
7115 async_block = isAsync;
7116 // Force the next block to be created as a ToplevelBlock
7117 parsing_anonymous_method = true;
7121 * Completes the anonymous method processing, if lambda_expr is null, this
7122 * means that we have a Statement instead of an Expression embedded
7124 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7126 AnonymousMethodExpression retval;
7129 anon_block.IsAsync = true;
7131 current_anonymous_method.Block = anon_block;
7132 retval = current_anonymous_method;
7134 async_block = (bool) oob_stack.Pop ();
7135 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
7136 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7137 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7142 void Error_SyntaxError (int token)
7144 Error_SyntaxError (0, token);
7147 void Error_SyntaxError (int error_code, int token)
7149 Error_SyntaxError (error_code, token, "Unexpected symbol");
7152 void Error_SyntaxError (int error_code, int token, string msg)
7154 Lexer.CompleteOnEOF = false;
7156 // An error message has been reported by tokenizer
7157 if (token == Token.ERROR)
7160 // Avoid duplicit error message after unterminated string literals
7161 if (token == Token.LITERAL && lexer.Location.Column == 0)
7164 string symbol = GetSymbolName (token);
7165 string expecting = GetExpecting ();
7166 var loc = lexer.Location - symbol.Length;
7168 if (error_code == 0) {
7169 if (expecting == "`identifier'") {
7170 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7171 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7176 expecting = "identifier";
7177 } else if (expecting == "`)'") {
7184 if (string.IsNullOrEmpty (expecting))
7185 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7187 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7190 string GetExpecting ()
7192 int [] tokens = yyExpectingTokens (yyExpectingState);
7193 var names = new List<string> (tokens.Length);
7194 bool has_type = false;
7195 bool has_identifier = false;
7196 for (int i = 0; i < tokens.Length; i++){
7197 int token = tokens [i];
7198 has_identifier |= token == Token.IDENTIFIER;
7200 string name = GetTokenName (token);
7201 if (name == "<internal>")
7204 has_type |= name == "type";
7205 if (names.Contains (name))
7212 // Too many tokens to enumerate
7214 if (names.Count > 8)
7217 if (has_type && has_identifier)
7218 names.Remove ("identifier");
7220 if (names.Count == 1)
7221 return "`" + GetTokenName (tokens [0]) + "'";
7223 StringBuilder sb = new StringBuilder ();
7225 int count = names.Count;
7226 for (int i = 0; i < count; i++){
7227 bool last = i + 1 == count;
7231 sb.Append (names [i]);
7232 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7234 return sb.ToString ();
7238 string GetSymbolName (int token)
7242 return ((Constant)lexer.Value).GetValue ().ToString ();
7243 case Token.IDENTIFIER:
7244 return ((Tokenizer.LocatedToken)lexer.Value).Value;
7286 case Token.BITWISE_AND:
7288 case Token.BITWISE_OR:
7302 case Token.OP_SHIFT_LEFT:
7304 case Token.OP_SHIFT_RIGHT:
7324 case Token.OP_COALESCING:
7326 case Token.OP_MULT_ASSIGN:
7328 case Token.OP_DIV_ASSIGN:
7330 case Token.OP_MOD_ASSIGN:
7332 case Token.OP_ADD_ASSIGN:
7334 case Token.OP_SUB_ASSIGN:
7336 case Token.OP_SHIFT_LEFT_ASSIGN:
7338 case Token.OP_SHIFT_RIGHT_ASSIGN:
7340 case Token.OP_AND_ASSIGN:
7342 case Token.OP_XOR_ASSIGN:
7344 case Token.OP_OR_ASSIGN:
7348 return GetTokenName (token);
7351 static string GetTokenName (int token)
7354 case Token.ABSTRACT:
7376 case Token.CONTINUE:
7380 case Token.DELEGATE:
7390 case Token.EXPLICIT:
7393 case Token.EXTERN_ALIAS:
7409 case Token.IMPLICIT:
7413 case Token.INTERFACE:
7415 case Token.INTERNAL:
7421 case Token.NAMESPACE:
7427 case Token.OPERATOR:
7431 case Token.OVERRIDE:
7437 case Token.PROTECTED:
7441 case Token.READONLY:
7453 case Token.STACKALLOC:
7454 return "stackalloc";
7471 case Token.UNCHECKED:
7479 case Token.VOLATILE:
7487 case Token.REFVALUE:
7488 return "__refvalue";
7498 case Token.FROM_FIRST:
7516 case Token.ASCENDING:
7518 case Token.DESCENDING:
7519 return "descending";
7526 case Token.OPEN_BRACE:
7528 case Token.CLOSE_BRACE:
7530 case Token.OPEN_BRACKET:
7531 case Token.OPEN_BRACKET_EXPR:
7533 case Token.CLOSE_BRACKET:
7535 case Token.OPEN_PARENS_CAST:
7536 case Token.OPEN_PARENS_LAMBDA:
7537 case Token.OPEN_PARENS:
7539 case Token.CLOSE_PARENS:
7545 case Token.DEFAULT_COLON:
7549 case Token.SEMICOLON:
7560 case Token.BITWISE_AND:
7561 case Token.BITWISE_OR:
7568 case Token.OP_SHIFT_LEFT:
7569 case Token.OP_SHIFT_RIGHT:
7577 case Token.OP_COALESCING:
7578 case Token.OP_MULT_ASSIGN:
7579 case Token.OP_DIV_ASSIGN:
7580 case Token.OP_MOD_ASSIGN:
7581 case Token.OP_ADD_ASSIGN:
7582 case Token.OP_SUB_ASSIGN:
7583 case Token.OP_SHIFT_LEFT_ASSIGN:
7584 case Token.OP_SHIFT_RIGHT_ASSIGN:
7585 case Token.OP_AND_ASSIGN:
7586 case Token.OP_XOR_ASSIGN:
7587 case Token.OP_OR_ASSIGN:
7588 return "<operator>";
7610 case Token.OP_GENERICS_LT:
7611 case Token.GENERIC_DIMENSION:
7613 case Token.OP_GENERICS_GT:
7616 case Token.INTERR_NULLABLE:
7618 case Token.DOUBLE_COLON:
7622 case Token.IDENTIFIER:
7624 return "identifier";
7627 return "end-of-file";
7629 // All of these are internal.
7632 case Token.FIRST_KEYWORD:
7633 case Token.EVAL_COMPILATION_UNIT_PARSER:
7634 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7635 case Token.EVAL_STATEMENT_PARSER:
7636 case Token.LAST_KEYWORD:
7637 case Token.GENERATE_COMPLETION:
7638 case Token.COMPLETE_COMPLETION:
7639 return "<internal>";
7641 // A bit more robust.
7643 return yyNames [token];