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));
4340 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4342 Error_SyntaxError (Token.CLOSE_BRACE);
4344 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4345 lbag.AddLocation ($$, GetLocation ($4));
4346 lexer.putback ('}');
4350 assignment_expression
4351 : prefixed_unary_expression ASSIGN expression
4353 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4354 lbag.AddLocation ($$, GetLocation ($2));
4356 | prefixed_unary_expression OP_MULT_ASSIGN expression
4358 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4359 lbag.AddLocation ($$, GetLocation ($2));
4361 | prefixed_unary_expression OP_DIV_ASSIGN expression
4363 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4364 lbag.AddLocation ($$, GetLocation ($2));
4366 | prefixed_unary_expression OP_MOD_ASSIGN expression
4368 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4369 lbag.AddLocation ($$, GetLocation ($2));
4371 | prefixed_unary_expression OP_ADD_ASSIGN expression
4373 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4374 lbag.AddLocation ($$, GetLocation ($2));
4376 | prefixed_unary_expression OP_SUB_ASSIGN expression
4378 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4379 lbag.AddLocation ($$, GetLocation ($2));
4381 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4383 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4384 lbag.AddLocation ($$, GetLocation ($2));
4386 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4388 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4389 lbag.AddLocation ($$, GetLocation ($2));
4391 | prefixed_unary_expression OP_AND_ASSIGN expression
4393 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4394 lbag.AddLocation ($$, GetLocation ($2));
4396 | prefixed_unary_expression OP_OR_ASSIGN expression
4398 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4399 lbag.AddLocation ($$, GetLocation ($2));
4401 | prefixed_unary_expression OP_XOR_ASSIGN expression
4403 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4404 lbag.AddLocation ($$, GetLocation ($2));
4408 lambda_parameter_list
4411 var pars = new List<Parameter> (4);
4412 pars.Add ((Parameter) $1);
4416 | lambda_parameter_list COMMA lambda_parameter
4418 var pars = (List<Parameter>) $1;
4419 Parameter p = (Parameter)$3;
4420 if (pars[0].GetType () != p.GetType ()) {
4421 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4430 : parameter_modifier parameter_type identifier_inside_body
4432 var lt = (Tokenizer.LocatedToken) $3;
4434 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4436 | parameter_type identifier_inside_body
4438 var lt = (Tokenizer.LocatedToken) $2;
4440 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4444 var lt = (Tokenizer.LocatedToken) $1;
4445 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4449 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4450 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4454 opt_lambda_parameter_list
4455 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4456 | lambda_parameter_list {
4457 var pars_list = (List<Parameter>) $1;
4458 $$ = new ParametersCompiled (pars_list.ToArray ());
4462 lambda_expression_body
4464 start_block (Location.Null);
4466 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4468 Block b = end_block (Location.Null);
4469 b.IsCompilerGenerated = true;
4470 b.AddStatement (new ContextualReturn ((Expression) $2));
4476 // Handles only cases like foo = x.FirstOrDefault (l => );
4477 // where we must restore current_variable
4478 Block b = end_block (Location.Null);
4479 b.IsCompilerGenerated = true;
4481 Error_SyntaxError (yyToken);
4490 Error_SyntaxError (yyToken);
4498 var lt = (Tokenizer.LocatedToken) $1;
4499 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4500 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4502 lambda_expression_body
4504 $$ = end_anonymous ((ParametersBlock) $4);
4505 lbag.AddLocation ($$, GetLocation ($2));
4509 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4510 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4511 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4513 lambda_expression_body
4515 $$ = end_anonymous ((ParametersBlock) $4);
4516 lbag.AddLocation ($$, GetLocation ($2));
4518 | ASYNC identifier_inside_body ARROW
4520 var lt = (Tokenizer.LocatedToken) $2;
4521 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4522 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4524 lambda_expression_body
4526 $$ = end_anonymous ((ParametersBlock) $5);
4527 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4529 | OPEN_PARENS_LAMBDA
4531 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4533 opt_lambda_parameter_list CLOSE_PARENS ARROW
4535 valid_param_mod = 0;
4536 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4538 lambda_expression_body
4540 $$ = end_anonymous ((ParametersBlock) $7);
4541 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4543 | ASYNC OPEN_PARENS_LAMBDA
4545 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4547 opt_lambda_parameter_list CLOSE_PARENS ARROW
4549 valid_param_mod = 0;
4550 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4552 lambda_expression_body
4554 $$ = end_anonymous ((ParametersBlock) $8);
4555 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4560 : assignment_expression
4561 | non_assignment_expression
4564 non_assignment_expression
4565 : conditional_expression
4570 $$ = new ArglistAccess (GetLocation ($1));
4574 undocumented_expressions
4575 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4577 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4578 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4580 | REFTYPE open_parens_any expression CLOSE_PARENS
4582 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4583 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4585 | MAKEREF open_parens_any expression CLOSE_PARENS
4587 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4588 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4599 $$ = new BooleanExpression ((Expression) $1);
4613 type_declaration_name
4615 lexer.ConstraintsParsing = true;
4617 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4618 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4619 FeatureIsNotAvailable (c.Location, "static classes");
4622 push_current_container (c, $3);
4625 opt_type_parameter_constraints_clauses
4627 lexer.ConstraintsParsing = false;
4630 current_container.SetConstraints ((List<Constraints>) $9);
4631 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4634 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4635 Lexer.doc_state = XmlCommentState.Allowed;
4638 lexer.parsing_modifiers = true;
4640 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4642 --lexer.parsing_declaration;
4644 Lexer.doc_state = XmlCommentState.Allowed;
4648 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4649 $$ = pop_current_class ();
4657 { $$ = $1; } // location
4663 mod_locations = null;
4665 lexer.parsing_modifiers = false;
4669 lexer.parsing_modifiers = false;
4675 | modifiers modifier
4677 var m1 = (Modifiers) $1;
4678 var m2 = (Modifiers) $2;
4680 if ((m1 & m2) != 0) {
4681 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4682 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4683 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4684 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4685 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4686 "More than one protection modifier specified");
4697 StoreModifierLocation ($$, GetLocation ($1));
4699 if (current_container.Kind == MemberKind.Namespace)
4700 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4704 $$ = Modifiers.PUBLIC;
4705 StoreModifierLocation ($$, GetLocation ($1));
4709 $$ = Modifiers.PROTECTED;
4710 StoreModifierLocation ($$, GetLocation ($1));
4714 $$ = Modifiers.INTERNAL;
4715 StoreModifierLocation ($$, GetLocation ($1));
4719 $$ = Modifiers.PRIVATE;
4720 StoreModifierLocation ($$, GetLocation ($1));
4724 $$ = Modifiers.ABSTRACT;
4725 StoreModifierLocation ($$, GetLocation ($1));
4729 $$ = Modifiers.SEALED;
4730 StoreModifierLocation ($$, GetLocation ($1));
4734 $$ = Modifiers.STATIC;
4735 StoreModifierLocation ($$, GetLocation ($1));
4739 $$ = Modifiers.READONLY;
4740 StoreModifierLocation ($$, GetLocation ($1));
4744 $$ = Modifiers.VIRTUAL;
4745 StoreModifierLocation ($$, GetLocation ($1));
4749 $$ = Modifiers.OVERRIDE;
4750 StoreModifierLocation ($$, GetLocation ($1));
4754 $$ = Modifiers.EXTERN;
4755 StoreModifierLocation ($$, GetLocation ($1));
4759 $$ = Modifiers.VOLATILE;
4760 StoreModifierLocation ($$, GetLocation ($1));
4764 $$ = Modifiers.UNSAFE;
4765 StoreModifierLocation ($$, GetLocation ($1));
4766 if (!settings.Unsafe)
4767 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4771 $$ = Modifiers.ASYNC;
4772 StoreModifierLocation ($$, GetLocation ($1));
4780 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4782 | COLON type_list error
4784 Error_SyntaxError (yyToken);
4786 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4790 opt_type_parameter_constraints_clauses
4792 | type_parameter_constraints_clauses
4798 type_parameter_constraints_clauses
4799 : type_parameter_constraints_clause
4801 var constraints = new List<Constraints> (1);
4802 constraints.Add ((Constraints) $1);
4805 | type_parameter_constraints_clauses type_parameter_constraints_clause
4807 var constraints = (List<Constraints>) $1;
4808 Constraints new_constraint = (Constraints)$2;
4810 foreach (Constraints c in constraints) {
4811 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4812 report.Error (409, new_constraint.Location,
4813 "A constraint clause has already been specified for type parameter `{0}'",
4814 new_constraint.TypeParameter.Value);
4818 constraints.Add (new_constraint);
4823 type_parameter_constraints_clause
4824 : WHERE IDENTIFIER COLON type_parameter_constraints
4826 var lt = (Tokenizer.LocatedToken) $2;
4827 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4828 lbag.AddLocation ($$, GetLocation ($3));
4830 | WHERE IDENTIFIER error
4832 Error_SyntaxError (yyToken);
4834 var lt = (Tokenizer.LocatedToken) $2;
4835 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4839 type_parameter_constraints
4840 : type_parameter_constraint
4842 var constraints = new List<FullNamedExpression> (1);
4843 constraints.Add ((FullNamedExpression) $1);
4846 | type_parameter_constraints COMMA type_parameter_constraint
4848 var constraints = (List<FullNamedExpression>) $1;
4849 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4850 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4851 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4854 prev = $3 as SpecialContraintExpr;
4856 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4857 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4859 prev = constraints [0] as SpecialContraintExpr;
4860 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4861 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4866 constraints.Add ((FullNamedExpression) $3);
4871 type_parameter_constraint
4874 if ($1 is ComposedCast)
4875 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4879 | NEW OPEN_PARENS CLOSE_PARENS
4881 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4882 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4886 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4890 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4894 opt_type_parameter_variance
4899 | type_parameter_variance
4901 if (lang_version <= LanguageVersion.V_3)
4902 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4908 type_parameter_variance
4911 $$ = Variance.Covariant;
4915 $$ = Variance.Contravariant;
4924 // A block is "contained" on the following places:
4926 // property_declaration as part of the accessor body (get/set)
4927 // operator_declaration
4928 // constructor_declaration
4929 // destructor_declaration
4930 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4935 ++lexer.parsing_block;
4936 start_block (GetLocation ($1));
4938 opt_statement_list block_end
4947 --lexer.parsing_block;
4948 $$ = end_block (GetLocation ($1));
4950 | COMPLETE_COMPLETION
4952 --lexer.parsing_block;
4953 $$ = end_block (lexer.Location);
4961 ++lexer.parsing_block;
4962 current_block.StartLocation = GetLocation ($1);
4964 opt_statement_list CLOSE_BRACE
4966 --lexer.parsing_block;
4967 $$ = end_block (GetLocation ($4));
4978 | statement_list statement
4982 : block_variable_declaration
4984 current_block.AddStatement ((Statement) $1);
4986 | valid_declaration_statement
4988 current_block.AddStatement ((Statement) $1);
4993 Error_SyntaxError (yyToken);
4999 // The interactive_statement and its derivatives are only
5000 // used to provide a special version of `expression_statement'
5001 // that has a side effect of assigning the expression to
5004 interactive_statement_list
5005 : interactive_statement
5006 | interactive_statement_list interactive_statement
5009 interactive_statement
5010 : block_variable_declaration
5012 current_block.AddStatement ((Statement) $1);
5014 | interactive_valid_declaration_statement
5016 current_block.AddStatement ((Statement) $1);
5021 valid_declaration_statement
5024 | expression_statement
5025 | selection_statement
5026 | iteration_statement
5030 | unchecked_statement
5037 interactive_valid_declaration_statement
5040 | interactive_expression_statement
5041 | selection_statement
5042 | iteration_statement
5046 | unchecked_statement
5054 : valid_declaration_statement
5055 | block_variable_declaration
5057 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5062 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5067 Error_SyntaxError (yyToken);
5068 $$ = new EmptyStatement (GetLocation ($1));
5075 // Uses lexer.Location because semicolon location is not kept in quick mode
5076 $$ = new EmptyStatement (lexer.Location);
5081 : identifier_inside_body COLON
5083 var lt = (Tokenizer.LocatedToken) $1;
5084 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5085 lbag.AddLocation (labeled, GetLocation ($2));
5086 current_block.AddLabel (labeled);
5087 current_block.AddStatement (labeled);
5093 : variable_type_simple
5094 | variable_type_simple rank_specifiers
5097 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5099 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5104 * The following is from Rhys' grammar:
5105 * > Types in local variable declarations must be recognized as
5106 * > expressions to prevent reduce/reduce errors in the grammar.
5107 * > The expressions are converted into types during semantic analysis.
5109 variable_type_simple
5110 : primary_expression_or_type opt_nullable
5112 // Ok, the above "primary_expression" is there to get rid of
5113 // both reduce/reduce and shift/reduces in the grammar, it should
5114 // really just be "type_name". If you use type_name, a reduce/reduce
5115 // creeps up. If you use namespace_or_type_name (which is all we need
5116 // really) two shift/reduces appear.
5119 // So the super-trick is that primary_expression
5120 // can only be either a SimpleName or a MemberAccess.
5121 // The MemberAccess case arises when you have a fully qualified type-name like :
5123 // SimpleName is when you have
5126 Expression expr = (Expression) $1;
5128 SimpleName sn = expr as SimpleName;
5129 if (sn != null && sn.Name == "var")
5130 $$ = new VarExpr (sn.Location);
5133 } else if (expr is ATypeNameExpression) {
5134 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5136 Error_ExpectingTypeName (expr);
5140 | primary_expression_or_type pointer_stars
5142 ATypeNameExpression expr = $1 as ATypeNameExpression;
5145 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5147 Error_ExpectingTypeName ((Expression)$1);
5151 | builtin_types opt_nullable
5156 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5158 | builtin_types pointer_stars
5160 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5162 | VOID pointer_stars
5164 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5168 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5169 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5175 | pointer_star pointer_stars
5177 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5185 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5189 identifier_inside_body
5193 $$ = Error_AwaitAsIdentifier ($1);
5197 block_variable_declaration
5198 : variable_type identifier_inside_body
5200 var lt = (Tokenizer.LocatedToken) $2;
5201 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5202 current_block.AddLocalName (li);
5203 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5205 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5207 $$ = current_variable;
5208 current_variable = null;
5210 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5212 lbag.AddLocation ($$, GetLocation ($6));
5214 | CONST variable_type identifier_inside_body
5216 var lt = (Tokenizer.LocatedToken) $3;
5217 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5218 current_block.AddLocalName (li);
5219 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
5221 const_variable_initializer opt_const_declarators SEMICOLON
5223 $$ = current_variable;
5224 current_variable = null;
5225 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5229 opt_local_variable_initializer
5231 | ASSIGN block_variable_initializer
5233 current_variable.Initializer = (Expression) $2;
5234 PushLocation (GetLocation ($1));
5235 $$ = current_variable;
5239 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5240 report.Error (650, lexer.Location,
5241 "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");
5243 Error_SyntaxError (yyToken);
5248 opt_variable_declarators
5250 | variable_declarators
5253 opt_using_or_fixed_variable_declarators
5255 | variable_declarators
5257 foreach (var d in current_variable.Declarators) {
5258 if (d.Initializer == null)
5259 Error_MissingInitializer (d.Variable.Location);
5264 variable_declarators
5265 : variable_declarator
5266 | variable_declarators variable_declarator
5270 : COMMA identifier_inside_body
5272 var lt = (Tokenizer.LocatedToken) $2;
5273 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5274 var d = new BlockVariableDeclaration.Declarator (li, null);
5275 current_variable.AddDeclarator (d);
5276 current_block.AddLocalName (li);
5277 lbag.AddLocation (d, GetLocation ($1));
5279 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5281 var lt = (Tokenizer.LocatedToken) $2;
5282 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5283 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5284 current_variable.AddDeclarator (d);
5285 current_block.AddLocalName (li);
5286 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5290 const_variable_initializer
5293 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5295 | ASSIGN constant_initializer_expr
5297 current_variable.Initializer = (Expression) $2;
5301 opt_const_declarators
5308 | const_declarators const_declarator
5312 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5314 var lt = (Tokenizer.LocatedToken) $2;
5315 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5316 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5317 current_variable.AddDeclarator (d);
5318 current_block.AddLocalName (li);
5319 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5323 block_variable_initializer
5324 : variable_initializer
5325 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5327 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5328 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5330 | STACKALLOC simple_type
5332 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5333 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5337 expression_statement
5338 : statement_expression SEMICOLON
5341 lbag.AddStatement ($$, GetLocation ($2));
5343 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5344 | statement_expression CLOSE_BRACE
5347 report.Error (1002, GetLocation ($2), "; expected");
5348 lexer.putback ('}');
5352 interactive_expression_statement
5353 : interactive_statement_expression SEMICOLON { $$ = $1; }
5354 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5358 // We have to do the wrapping here and not in the case above,
5359 // because statement_expression is used for example in for_statement
5361 statement_expression
5364 ExpressionStatement s = $1 as ExpressionStatement;
5366 var expr = $1 as Expression;
5367 expr.Error_InvalidExpressionStatement (report);
5368 $$ = new StatementErrorExpression (expr);
5370 $$ = new StatementExpression (s);
5375 interactive_statement_expression
5378 Expression expr = (Expression) $1;
5379 ExpressionStatement s;
5381 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5382 $$ = new StatementExpression (s);
5386 Error_SyntaxError (yyToken);
5387 $$ = new EmptyStatement (GetLocation ($1));
5397 : IF open_parens_any boolean_expression CLOSE_PARENS
5400 if ($5 is EmptyStatement)
5401 Warning_EmptyStatement (GetLocation ($5));
5403 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5404 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5406 | IF open_parens_any boolean_expression CLOSE_PARENS
5407 embedded_statement ELSE embedded_statement
5409 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5410 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5412 if ($5 is EmptyStatement)
5413 Warning_EmptyStatement (GetLocation ($5));
5414 if ($7 is EmptyStatement)
5415 Warning_EmptyStatement (GetLocation ($7));
5417 | IF open_parens_any boolean_expression error
5419 Error_SyntaxError (yyToken);
5421 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5422 lbag.AddStatement ($$, GetLocation ($2));
5427 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5429 start_block (GetLocation ($5));
5431 opt_switch_sections CLOSE_BRACE
5433 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5434 end_block (GetLocation ($8));
5435 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5437 | SWITCH open_parens_any expression error
5439 Error_SyntaxError (yyToken);
5441 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5442 lbag.AddStatement ($$, GetLocation ($2));
5449 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5456 | switch_sections switch_section
5459 Error_SyntaxError (yyToken);
5464 : switch_labels statement_list
5470 var label = (SwitchLabel) $1;
5471 label.SectionStart = true;
5472 current_block.AddStatement (label);
5474 | switch_labels switch_label
5476 current_block.AddStatement ((Statement) $2);
5481 : CASE constant_expression COLON
5483 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5484 lbag.AddLocation ($$, GetLocation ($3));
5486 | CASE constant_expression error
5488 Error_SyntaxError (yyToken);
5489 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5493 $$ = new SwitchLabel (null, GetLocation ($1));
5505 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5507 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5508 Warning_EmptyStatement (GetLocation ($5));
5510 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5511 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5513 | WHILE open_parens_any boolean_expression error
5515 Error_SyntaxError (yyToken);
5517 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5518 lbag.AddStatement ($$, GetLocation ($2));
5523 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5525 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5526 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5528 | DO embedded_statement error
5530 Error_SyntaxError (yyToken);
5531 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5533 | DO embedded_statement WHILE open_parens_any boolean_expression error
5535 Error_SyntaxError (yyToken);
5537 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5538 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5543 : FOR open_parens_any
5545 start_block (GetLocation ($2));
5546 current_block.IsCompilerGenerated = true;
5547 For f = new For (GetLocation ($1));
5548 current_block.AddStatement (f);
5557 // Has to use be extra rule to recover started block
5559 : opt_for_initializer SEMICOLON
5561 ((For) $0).Initializer = (Statement) $1;
5563 // Pass the "For" object to the iterator_part4
5564 oob_stack.Push ($0);
5566 for_condition_and_iterator_part
5569 var locations = (Tuple<Location,Location>) $4;
5571 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5572 Warning_EmptyStatement (GetLocation ($5));
5575 f.Statement = (Statement) $5;
5576 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5578 $$ = end_block (GetLocation ($2));
5582 Error_SyntaxError (yyToken);
5583 $$ = end_block (current_block.StartLocation);
5587 for_condition_and_iterator_part
5588 : opt_for_condition SEMICOLON
5590 For f = (For) oob_stack.Peek ();
5591 f.Condition = (BooleanExpression) $1;
5594 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5597 // Handle errors in the case of opt_for_condition being followed by
5598 // a close parenthesis
5599 | opt_for_condition close_parens_close_brace {
5600 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5601 For f = (For) oob_stack.Peek ();
5602 f.Condition = (BooleanExpression) $1;
5603 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5608 : opt_for_iterator CLOSE_PARENS {
5609 For f = (For) oob_stack.Peek ();
5610 f.Iterator = (Statement) $1;
5611 $$ = GetLocation ($2);
5613 | opt_for_iterator CLOSE_BRACE {
5614 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5615 For f = (For) oob_stack.Peek ();
5616 f.Iterator = (Statement) $1;
5617 $$ = GetLocation ($2);
5621 close_parens_close_brace
5623 | CLOSE_BRACE { lexer.putback ('}'); }
5627 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5632 : variable_type identifier_inside_body
5634 var lt = (Tokenizer.LocatedToken) $2;
5635 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5636 current_block.AddLocalName (li);
5637 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5639 opt_local_variable_initializer opt_variable_declarators
5641 $$ = current_variable;
5643 lbag.AddLocation (current_variable, PopLocation ());
5645 current_variable = null;
5647 | statement_expression_list
5651 : /* empty */ { $$ = null; }
5652 | boolean_expression
5656 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5661 : statement_expression_list
5664 statement_expression_list
5665 : statement_expression
5666 | statement_expression_list COMMA statement_expression
5668 var sl = $1 as StatementList;
5670 sl = new StatementList ((Statement) $1, (Statement) $3);
5671 lbag.AddStatement (sl, GetLocation ($2));
5673 sl.Add ((Statement) $3);
5674 lbag.AppendTo (sl, GetLocation ($2));
5682 : FOREACH open_parens_any type error
5684 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5686 start_block (GetLocation ($2));
5687 current_block.IsCompilerGenerated = true;
5689 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5690 current_block.AddStatement (f);
5692 lbag.AddStatement (f, GetLocation ($2));
5693 $$ = end_block (GetLocation ($4));
5695 | FOREACH open_parens_any type identifier_inside_body error
5697 Error_SyntaxError (yyToken);
5699 start_block (GetLocation ($2));
5700 current_block.IsCompilerGenerated = true;
5702 var lt = (Tokenizer.LocatedToken) $4;
5703 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5704 current_block.AddLocalName (li);
5706 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5707 current_block.AddStatement (f);
5709 lbag.AddStatement (f, GetLocation ($2));
5710 $$ = end_block (GetLocation ($5));
5712 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5714 start_block (GetLocation ($2));
5715 current_block.IsCompilerGenerated = true;
5717 var lt = (Tokenizer.LocatedToken) $4;
5718 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5719 current_block.AddLocalName (li);
5724 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5725 Warning_EmptyStatement (GetLocation ($9));
5727 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5728 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5729 end_block (GetLocation ($7));
5737 | continue_statement
5747 $$ = new Break (GetLocation ($1));
5748 lbag.AddStatement ($$, GetLocation ($2));
5753 : CONTINUE SEMICOLON
5755 $$ = new Continue (GetLocation ($1));
5756 lbag.AddStatement ($$, GetLocation ($2));
5760 Error_SyntaxError (yyToken);
5761 $$ = new Continue (GetLocation ($1));
5766 : GOTO identifier_inside_body SEMICOLON
5768 var lt = (Tokenizer.LocatedToken) $2;
5769 $$ = new Goto (lt.Value, GetLocation ($1));
5770 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5772 | GOTO CASE constant_expression SEMICOLON
5774 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5775 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5777 | GOTO DEFAULT SEMICOLON
5779 $$ = new GotoDefault (GetLocation ($1));
5780 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5785 : RETURN opt_expression SEMICOLON
5787 $$ = new Return ((Expression) $2, GetLocation ($1));
5788 lbag.AddStatement ($$, GetLocation ($3));
5790 | RETURN expression error
5792 Error_SyntaxError (yyToken);
5793 $$ = new Return ((Expression) $2, GetLocation ($1));
5797 Error_SyntaxError (yyToken);
5798 $$ = new Return (null, GetLocation ($1));
5803 : THROW opt_expression SEMICOLON
5805 $$ = new Throw ((Expression) $2, GetLocation ($1));
5806 lbag.AddStatement ($$, GetLocation ($3));
5810 Error_SyntaxError (yyToken);
5811 $$ = new Throw (null, GetLocation ($1));
5816 : identifier_inside_body RETURN opt_expression SEMICOLON
5818 var lt = (Tokenizer.LocatedToken) $1;
5819 string s = lt.Value;
5821 report.Error (1003, lt.Location, "; expected");
5822 } else if ($3 == null) {
5823 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5824 } else if (lang_version == LanguageVersion.ISO_1){
5825 FeatureIsNotAvailable (lt.Location, "iterators");
5828 current_block.Explicit.RegisterIteratorYield ();
5829 $$ = new Yield ((Expression) $3, lt.Location);
5830 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5832 | identifier_inside_body RETURN expression error
5834 Error_SyntaxError (yyToken);
5836 var lt = (Tokenizer.LocatedToken) $1;
5837 string s = lt.Value;
5839 report.Error (1003, lt.Location, "; expected");
5840 } else if ($3 == null) {
5841 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5842 } else if (lang_version == LanguageVersion.ISO_1){
5843 FeatureIsNotAvailable (lt.Location, "iterators");
5846 current_block.Explicit.RegisterIteratorYield ();
5847 $$ = new Yield ((Expression) $3, lt.Location);
5848 lbag.AddStatement ($$, GetLocation ($2));
5850 | identifier_inside_body BREAK SEMICOLON
5852 var lt = (Tokenizer.LocatedToken) $1;
5853 string s = lt.Value;
5855 report.Error (1003, lt.Location, "; expected");
5856 } else if (lang_version == LanguageVersion.ISO_1){
5857 FeatureIsNotAvailable (lt.Location, "iterators");
5860 current_block.ParametersBlock.TopBlock.IsIterator = true;
5861 $$ = new YieldBreak (lt.Location);
5862 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5872 : TRY block catch_clauses
5874 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5876 | TRY block FINALLY block
5878 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5879 lbag.AddStatement ($$, GetLocation ($3));
5881 | TRY block catch_clauses FINALLY block
5883 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5884 lbag.AddStatement ($$, GetLocation ($4));
5888 Error_SyntaxError (1524, yyToken);
5889 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5896 var l = new List<Catch> (2);
5901 | catch_clauses catch_clause
5903 var l = (List<Catch>) $1;
5905 Catch c = (Catch) $2;
5906 if (l [l.Count - 1].IsGeneral) {
5907 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5917 | identifier_inside_body
5923 $$ = new Catch ((Block) $2, GetLocation ($1));
5925 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5927 start_block (GetLocation ($2));
5928 var c = new Catch (current_block, GetLocation ($1));
5929 c.TypeExpression = (FullNamedExpression) $3;
5932 var lt = (Tokenizer.LocatedToken) $4;
5933 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5934 current_block.AddLocalName (c.Variable);
5937 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5944 | CATCH open_parens_any error
5946 if (yyToken == Token.CLOSE_PARENS) {
5947 report.Error (1015, lexer.Location,
5948 "A type that derives from `System.Exception', `object', or `string' expected");
5950 Error_SyntaxError (yyToken);
5953 $$ = new Catch (null, GetLocation ($1));
5955 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5957 Error_SyntaxError (yyToken);
5959 // Required otherwise missing block could not be detected because
5960 // start_block is run early
5961 var c = new Catch (null, GetLocation ($1));
5962 c.TypeExpression = (FullNamedExpression) $3;
5965 var lt = (Tokenizer.LocatedToken) $4;
5966 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5969 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5978 $$ = new Checked ((Block) $2, GetLocation ($1));
5985 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5992 if (!settings.Unsafe)
5993 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5995 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6000 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6002 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6003 Warning_EmptyStatement (GetLocation ($5));
6005 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6006 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6008 | LOCK open_parens_any expression error
6010 Error_SyntaxError (yyToken);
6012 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6013 lbag.AddStatement ($$, GetLocation ($2));
6018 : FIXED open_parens_any variable_type identifier_inside_body
6020 start_block (GetLocation ($2));
6022 current_block.IsCompilerGenerated = true;
6023 var lt = (Tokenizer.LocatedToken) $4;
6024 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6025 current_block.AddLocalName (li);
6026 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6028 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6030 $$ = current_variable;
6031 current_variable = null;
6035 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6036 Warning_EmptyStatement (GetLocation ($10));
6038 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6039 current_block.AddStatement (f);
6040 $$ = end_block (GetLocation ($8));
6045 : USING open_parens_any variable_type identifier_inside_body
6047 start_block (GetLocation ($2));
6049 current_block.IsCompilerGenerated = true;
6050 var lt = (Tokenizer.LocatedToken) $4;
6051 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6052 current_block.AddLocalName (li);
6053 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6055 using_initialization CLOSE_PARENS
6057 $$ = current_variable;
6058 current_variable = null;
6062 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6063 Warning_EmptyStatement (GetLocation ($9));
6065 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6066 current_block.AddStatement (u);
6067 $$ = end_block (GetLocation ($7));
6069 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6071 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6072 Warning_EmptyStatement (GetLocation ($5));
6074 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6075 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6077 | USING open_parens_any expression error
6079 Error_SyntaxError (yyToken);
6081 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6082 lbag.AddStatement ($$, GetLocation ($2));
6086 using_initialization
6087 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6090 // It has to be here for the parent to safely restore artificial block
6091 Error_SyntaxError (yyToken);
6095 using_or_fixed_variable_initializer
6098 Error_MissingInitializer (lexer.Location);
6100 | ASSIGN variable_initializer
6102 current_variable.Initializer = (Expression) $2;
6103 $$ = current_variable;
6111 : first_from_clause query_body
6113 lexer.query_parsing = false;
6115 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6117 from.Tail.Next = (Linq.AQueryClause)$2;
6120 current_block.SetEndLocation (lexer.Location);
6121 current_block = current_block.Parent;
6123 | nested_from_clause query_body
6125 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6127 from.Tail.Next = (Linq.AQueryClause)$2;
6130 current_block.SetEndLocation (lexer.Location);
6131 current_block = current_block.Parent;
6134 // Bubble up COMPLETE_COMPLETION productions
6135 | first_from_clause COMPLETE_COMPLETION {
6136 lexer.query_parsing = false;
6139 current_block.SetEndLocation (lexer.Location);
6140 current_block = current_block.Parent;
6142 | nested_from_clause COMPLETE_COMPLETION {
6144 current_block.SetEndLocation (lexer.Location);
6145 current_block = current_block.Parent;
6150 : FROM_FIRST identifier_inside_body IN expression
6152 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6154 var lt = (Tokenizer.LocatedToken) $2;
6155 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6156 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6158 | FROM_FIRST type identifier_inside_body IN expression
6160 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6162 var lt = (Tokenizer.LocatedToken) $3;
6163 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6164 $$ = new Linq.QueryExpression (
6165 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6166 IdentifierType = (FullNamedExpression)$2
6173 : FROM identifier_inside_body IN expression
6175 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6177 var lt = (Tokenizer.LocatedToken) $2;
6178 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6179 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6181 | FROM type identifier_inside_body IN expression
6183 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6185 var lt = (Tokenizer.LocatedToken) $3;
6186 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6187 $$ = new Linq.QueryExpression (
6188 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6189 IdentifierType = (FullNamedExpression)$2
6196 : FROM identifier_inside_body IN
6198 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6202 var lt = (Tokenizer.LocatedToken) $2;
6203 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6204 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6206 current_block.SetEndLocation (lexer.Location);
6207 current_block = current_block.Parent;
6209 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6211 | FROM type identifier_inside_body IN
6213 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6217 var lt = (Tokenizer.LocatedToken) $3;
6218 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6220 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6221 IdentifierType = (FullNamedExpression)$2
6224 current_block.SetEndLocation (lexer.Location);
6225 current_block = current_block.Parent;
6227 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6232 : query_body_clauses select_or_group_clause opt_query_continuation
6234 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6237 head.Next = (Linq.AQueryClause)$3;
6240 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6241 clause.Tail.Next = head;
6247 | select_or_group_clause opt_query_continuation
6249 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6252 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6253 clause.Tail.Next = head;
6259 | query_body_clauses COMPLETE_COMPLETION
6260 | query_body_clauses error
6262 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6267 Error_SyntaxError (yyToken);
6272 select_or_group_clause
6275 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6279 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6281 current_block.SetEndLocation (lexer.Location);
6282 current_block = current_block.Parent;
6286 if (linq_clause_blocks == null)
6287 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6289 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6290 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6294 current_block.SetEndLocation (lexer.Location);
6295 current_block = current_block.Parent;
6297 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6301 var obj = (object[]) $5;
6303 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6304 lbag.AddLocation ($$, (Location) obj[1]);
6306 current_block.SetEndLocation (lexer.Location);
6307 current_block = current_block.Parent;
6312 : BY expression_or_error
6314 $$ = new object[] { $2, GetLocation ($1) };
6318 Error_SyntaxError (yyToken);
6319 $$ = new object[2] { null, Location.Null };
6325 | query_body_clauses query_body_clause
6327 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6341 : LET identifier_inside_body ASSIGN
6343 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6347 var lt = (Tokenizer.LocatedToken) $2;
6348 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6349 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6350 lbag.AddLocation ($$, GetLocation ($3));
6352 current_block.SetEndLocation (lexer.Location);
6353 current_block = current_block.Parent;
6355 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6362 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6366 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6368 current_block.SetEndLocation (lexer.Location);
6369 current_block = current_block.Parent;
6374 : JOIN identifier_inside_body IN
6376 if (linq_clause_blocks == null)
6377 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6379 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6380 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6382 expression_or_error ON
6384 current_block.SetEndLocation (lexer.Location);
6385 current_block = current_block.Parent;
6387 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6388 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6390 expression_or_error EQUALS
6392 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6393 current_block.SetEndLocation (lexer.Location);
6394 current_block = current_block.Parent;
6396 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6398 expression_or_error opt_join_into
6400 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6401 current_block.SetEndLocation (lexer.Location);
6403 var outer_selector = linq_clause_blocks.Pop ();
6404 var block = linq_clause_blocks.Pop ();
6406 var lt = (Tokenizer.LocatedToken) $2;
6407 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6408 Linq.RangeVariable into;
6412 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6413 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6416 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6418 var parent = block.Parent;
6419 while (parent is Linq.QueryBlock) {
6420 parent = parent.Parent;
6422 current_block.Parent = parent;
6424 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6426 lt = (Tokenizer.LocatedToken) $12;
6427 into = new Linq.RangeVariable (lt.Value, lt.Location);
6429 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6430 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6433 current_block = block.Parent;
6434 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6436 | JOIN type identifier_inside_body IN
6438 if (linq_clause_blocks == null)
6439 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6441 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6442 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6444 expression_or_error ON
6446 current_block.SetEndLocation (lexer.Location);
6447 current_block = current_block.Parent;
6449 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6450 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6452 expression_or_error EQUALS
6454 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6455 current_block.SetEndLocation (lexer.Location);
6456 current_block = current_block.Parent;
6458 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6460 expression_or_error opt_join_into
6462 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6463 current_block.SetEndLocation (lexer.Location);
6465 var outer_selector = linq_clause_blocks.Pop ();
6466 var block = linq_clause_blocks.Pop ();
6468 var lt = (Tokenizer.LocatedToken) $3;
6469 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6470 Linq.RangeVariable into;
6474 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6475 IdentifierType = (FullNamedExpression)$2
6479 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6481 var parent = block.Parent;
6482 while (parent is Linq.QueryBlock) {
6483 parent = parent.Parent;
6485 current_block.Parent = parent;
6487 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6489 lt = (Tokenizer.LocatedToken) $13;
6490 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6492 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6493 IdentifierType = (FullNamedExpression)$2
6497 current_block = block.Parent;
6498 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6504 | INTO identifier_inside_body
6513 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6517 current_block.SetEndLocation (lexer.Location);
6518 current_block = current_block.Parent;
6528 current_block.SetEndLocation (lexer.Location);
6529 current_block = current_block.Parent;
6531 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6535 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6542 | orderings_then_by COMMA
6544 current_block.SetEndLocation (lexer.Location);
6545 current_block = current_block.Parent;
6547 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6551 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6559 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6561 | expression ASCENDING
6563 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6564 lbag.AddLocation ($$, GetLocation ($2));
6566 | expression DESCENDING
6568 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6569 lbag.AddLocation ($$, GetLocation ($2));
6576 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6578 | expression ASCENDING
6580 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6581 lbag.AddLocation ($$, GetLocation ($2));
6583 | expression DESCENDING
6585 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6586 lbag.AddLocation ($$, GetLocation ($2));
6591 opt_query_continuation
6593 | INTO identifier_inside_body
6595 // query continuation block is not linked with query block but with block
6596 // before. This means each query can use same range variable names for
6597 // different identifiers.
6599 current_block.SetEndLocation (GetLocation ($1));
6600 current_block = current_block.Parent;
6602 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6604 if (linq_clause_blocks == null)
6605 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6607 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6611 var current_block = linq_clause_blocks.Pop ();
6612 var lt = (Tokenizer.LocatedToken) $2;
6613 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6614 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6615 next = (Linq.AQueryClause)$4
6621 // Support for using the compiler as an interactive parser
6623 // The INTERACTIVE_PARSER token is first sent to parse our
6624 // productions; If the result is a Statement, the parsing
6625 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6626 // to setup the blocks in advance.
6628 // This setup is here so that in the future we can add
6629 // support for other constructs (type parsing, namespaces, etc)
6630 // that do not require a block to be setup in advance
6634 : EVAL_STATEMENT_PARSER EOF
6635 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6636 | EVAL_STATEMENT_PARSER
6638 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6640 // (ref object retval)
6641 Parameter [] mpar = new Parameter [1];
6642 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6644 ParametersCompiled pars = new ParametersCompiled (mpar);
6645 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6646 if (settings.Unsafe)
6647 mods |= Modifiers.UNSAFE;
6649 current_local_parameters = pars;
6650 Method method = new Method (
6652 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6654 new MemberName ("Host"),
6656 null /* attributes */);
6658 current_type.AddMember (method);
6660 oob_stack.Push (method);
6661 ++lexer.parsing_block;
6662 start_block (lexer.Location);
6664 interactive_statement_list opt_COMPLETE_COMPLETION
6666 --lexer.parsing_block;
6667 Method method = (Method) oob_stack.Pop ();
6669 method.Block = (ToplevelBlock) end_block(lexer.Location);
6671 InteractiveResult = (Class) pop_current_class ();
6672 current_local_parameters = null;
6674 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6677 interactive_compilation_unit
6678 : opt_extern_alias_directives opt_using_directives
6679 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6682 opt_COMPLETE_COMPLETION
6684 | COMPLETE_COMPLETION
6687 close_brace_or_complete_completion
6689 | COMPLETE_COMPLETION
6693 // XML documentation code references micro parser
6695 documentation_parsing
6698 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6703 : doc_type_declaration_name opt_doc_method_sig
6705 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6707 | builtin_types opt_doc_method_sig
6709 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6710 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6713 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6715 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6716 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6717 var lt = (Tokenizer.LocatedToken) $3;
6718 $$ = new MemberName (lt.Value);
6720 | doc_type_declaration_name DOT THIS
6722 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6724 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6726 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6728 opt_doc_parameters CLOSE_BRACKET
6730 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6731 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6733 | EXPLICIT 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.Explicit;
6741 | IMPLICIT OPERATOR type opt_doc_method_sig
6743 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6744 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6745 module.DocumentationBuilder.ParsedParameters = p;
6746 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6749 | OPERATOR overloadable_operator opt_doc_method_sig
6751 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6752 module.DocumentationBuilder.ParsedParameters = p;
6753 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6758 doc_type_declaration_name
6759 : type_declaration_name
6760 | doc_type_declaration_name DOT type_declaration_name
6762 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6770 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6772 opt_doc_parameters CLOSE_PARENS
6781 $$ = new List<DocumentationParameter> (0);
6789 var parameters = new List<DocumentationParameter> ();
6790 parameters.Add ((DocumentationParameter) $1);
6793 | doc_parameters COMMA doc_parameter
6795 var parameters = $1 as List<DocumentationParameter>;
6796 parameters.Add ((DocumentationParameter) $3);
6802 : opt_parameter_modifier parameter_type
6805 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6807 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6814 // A class used to hold info about an operator declarator
6816 class OperatorDeclaration {
6817 public readonly Operator.OpType optype;
6818 public readonly FullNamedExpression ret_type;
6819 public readonly Location location;
6821 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6824 this.ret_type = ret_type;
6825 this.location = location;
6829 void Error_ExpectingTypeName (Expression expr)
6831 if (expr is Invocation){
6832 report.Error (1002, expr.Location, "Expecting `;'");
6834 expr.Error_InvalidExpressionStatement (report);
6838 void Error_ParameterModifierNotValid (string modifier, Location loc)
6840 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6844 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6846 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6847 Parameter.GetModifierSignature (mod));
6850 void Error_TypeExpected (Location loc)
6852 report.Error (1031, loc, "Type expected");
6855 void Error_UnsafeCodeNotAllowed (Location loc)
6857 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6860 void Warning_EmptyStatement (Location loc)
6862 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6865 void Error_NamedArgumentExpected (NamedArgument a)
6867 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6870 void Error_MissingInitializer (Location loc)
6872 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6875 object Error_AwaitAsIdentifier (object token)
6878 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6879 return new Tokenizer.LocatedToken ("await", GetLocation (token));
6885 void push_current_container (TypeDefinition tc, object partial_token)
6887 if (module.Evaluator != null){
6888 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6892 undo.AddTypeContainer (current_container, tc);
6895 if (partial_token != null)
6896 current_container.AddPartial (tc);
6898 current_container.AddTypeContainer (tc);
6900 ++lexer.parsing_declaration;
6901 current_container = tc;
6905 TypeContainer pop_current_class ()
6907 var retval = current_container;
6909 current_container = current_container.Parent;
6910 current_type = current_type.Parent as TypeDefinition;
6915 [System.Diagnostics.Conditional ("FULL_AST")]
6916 void StoreModifierLocation (object token, Location loc)
6921 if (mod_locations == null)
6922 mod_locations = new List<Tuple<Modifiers, Location>> ();
6924 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6927 [System.Diagnostics.Conditional ("FULL_AST")]
6928 void PushLocation (Location loc)
6930 if (location_stack == null)
6931 location_stack = new Stack<Location> ();
6933 location_stack.Push (loc);
6936 Location PopLocation ()
6938 if (location_stack == null)
6939 return Location.Null;
6941 return location_stack.Pop ();
6944 string CheckAttributeTarget (string a, Location l)
6947 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6951 report.Warning (658, 1, l,
6952 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6953 return string.Empty;
6956 static bool IsUnaryOperator (Operator.OpType op)
6960 case Operator.OpType.LogicalNot:
6961 case Operator.OpType.OnesComplement:
6962 case Operator.OpType.Increment:
6963 case Operator.OpType.Decrement:
6964 case Operator.OpType.True:
6965 case Operator.OpType.False:
6966 case Operator.OpType.UnaryPlus:
6967 case Operator.OpType.UnaryNegation:
6973 void syntax_error (Location l, string msg)
6975 report.Error (1003, l, "Syntax error, " + msg);
6980 public Tokenizer Lexer {
6986 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6987 : this (reader, file, file.Compiler.Report, session)
6991 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6994 current_container = current_namespace = file;
6996 this.module = file.Module;
6997 this.compiler = file.Compiler;
6998 this.settings = compiler.Settings;
6999 this.report = report;
7001 lang_version = settings.Version;
7002 yacc_verbose_flag = settings.VerboseParserFlag;
7003 doc_support = settings.DocumentationFile != null;
7004 lexer = new Tokenizer (reader, file, session);
7005 oob_stack = new Stack<object> ();
7006 lbag = session.LocationsBag;
7007 use_global_stacks = session.UseJayGlobalArrays;
7008 parameters_bucket = session.ParametersStack;
7011 public void parse ()
7013 eof_token = Token.EOF;
7016 if (yacc_verbose_flag > 1)
7017 yyparse (lexer, new yydebug.yyDebugSimple ());
7021 Tokenizer tokenizer = lexer as Tokenizer;
7022 tokenizer.cleanup ();
7023 } catch (Exception e){
7024 if (e is yyParser.yyUnexpectedEof) {
7025 Error_SyntaxError (yyToken);
7026 UnexpectedEOF = true;
7030 if (e is yyParser.yyException) {
7031 if (report.Errors == 0)
7032 report.Error (-25, lexer.Location, "Parsing error");
7034 // Used by compiler-tester to test internal errors
7035 if (yacc_verbose_flag > 0 || e is FatalException)
7038 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7043 void CheckToken (int error, int yyToken, string msg, Location loc)
7045 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7046 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7048 report.Error (error, loc, msg);
7051 string ConsumeStoredComment ()
7053 string s = tmpComment;
7055 Lexer.doc_state = XmlCommentState.Allowed;
7059 void FeatureIsNotAvailable (Location loc, string feature)
7061 report.FeatureIsNotAvailable (compiler, loc, feature);
7064 Location GetLocation (object obj)
7066 var lt = obj as Tokenizer.LocatedToken;
7070 var mn = obj as MemberName;
7074 var expr = obj as Expression;
7076 return expr.Location;
7078 return lexer.Location;
7081 void start_block (Location loc)
7083 if (current_block == null) {
7084 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7085 parsing_anonymous_method = false;
7086 } else if (parsing_anonymous_method) {
7087 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7088 parsing_anonymous_method = false;
7090 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7095 end_block (Location loc)
7097 Block retval = current_block.Explicit;
7098 retval.SetEndLocation (loc);
7099 current_block = retval.Parent;
7103 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7105 oob_stack.Push (current_anonymous_method);
7106 oob_stack.Push (current_local_parameters);
7107 oob_stack.Push (current_variable);
7108 oob_stack.Push (async_block);
7110 current_local_parameters = parameters;
7112 if (lang_version <= LanguageVersion.ISO_2)
7113 FeatureIsNotAvailable (loc, "lambda expressions");
7115 current_anonymous_method = new LambdaExpression (loc);
7117 if (lang_version == LanguageVersion.ISO_1)
7118 FeatureIsNotAvailable (loc, "anonymous methods");
7120 current_anonymous_method = new AnonymousMethodExpression (loc);
7123 async_block = isAsync;
7124 // Force the next block to be created as a ToplevelBlock
7125 parsing_anonymous_method = true;
7129 * Completes the anonymous method processing, if lambda_expr is null, this
7130 * means that we have a Statement instead of an Expression embedded
7132 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7134 AnonymousMethodExpression retval;
7137 anon_block.IsAsync = true;
7139 current_anonymous_method.Block = anon_block;
7140 retval = current_anonymous_method;
7142 async_block = (bool) oob_stack.Pop ();
7143 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
7144 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7145 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7150 void Error_SyntaxError (int token)
7152 Error_SyntaxError (0, token);
7155 void Error_SyntaxError (int error_code, int token)
7157 Error_SyntaxError (error_code, token, "Unexpected symbol");
7160 void Error_SyntaxError (int error_code, int token, string msg)
7162 Lexer.CompleteOnEOF = false;
7164 // An error message has been reported by tokenizer
7165 if (token == Token.ERROR)
7168 // Avoid duplicit error message after unterminated string literals
7169 if (token == Token.LITERAL && lexer.Location.Column == 0)
7172 string symbol = GetSymbolName (token);
7173 string expecting = GetExpecting ();
7174 var loc = lexer.Location - symbol.Length;
7176 if (error_code == 0) {
7177 if (expecting == "`identifier'") {
7178 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7179 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7184 expecting = "identifier";
7185 } else if (expecting == "`)'") {
7192 if (string.IsNullOrEmpty (expecting))
7193 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7195 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7198 string GetExpecting ()
7200 int [] tokens = yyExpectingTokens (yyExpectingState);
7201 var names = new List<string> (tokens.Length);
7202 bool has_type = false;
7203 bool has_identifier = false;
7204 for (int i = 0; i < tokens.Length; i++){
7205 int token = tokens [i];
7206 has_identifier |= token == Token.IDENTIFIER;
7208 string name = GetTokenName (token);
7209 if (name == "<internal>")
7212 has_type |= name == "type";
7213 if (names.Contains (name))
7220 // Too many tokens to enumerate
7222 if (names.Count > 8)
7225 if (has_type && has_identifier)
7226 names.Remove ("identifier");
7228 if (names.Count == 1)
7229 return "`" + GetTokenName (tokens [0]) + "'";
7231 StringBuilder sb = new StringBuilder ();
7233 int count = names.Count;
7234 for (int i = 0; i < count; i++){
7235 bool last = i + 1 == count;
7239 sb.Append (names [i]);
7240 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7242 return sb.ToString ();
7246 string GetSymbolName (int token)
7250 return ((Constant)lexer.Value).GetValue ().ToString ();
7251 case Token.IDENTIFIER:
7252 return ((Tokenizer.LocatedToken)lexer.Value).Value;
7294 case Token.BITWISE_AND:
7296 case Token.BITWISE_OR:
7310 case Token.OP_SHIFT_LEFT:
7312 case Token.OP_SHIFT_RIGHT:
7332 case Token.OP_COALESCING:
7334 case Token.OP_MULT_ASSIGN:
7336 case Token.OP_DIV_ASSIGN:
7338 case Token.OP_MOD_ASSIGN:
7340 case Token.OP_ADD_ASSIGN:
7342 case Token.OP_SUB_ASSIGN:
7344 case Token.OP_SHIFT_LEFT_ASSIGN:
7346 case Token.OP_SHIFT_RIGHT_ASSIGN:
7348 case Token.OP_AND_ASSIGN:
7350 case Token.OP_XOR_ASSIGN:
7352 case Token.OP_OR_ASSIGN:
7356 return GetTokenName (token);
7359 static string GetTokenName (int token)
7362 case Token.ABSTRACT:
7384 case Token.CONTINUE:
7388 case Token.DELEGATE:
7398 case Token.EXPLICIT:
7401 case Token.EXTERN_ALIAS:
7417 case Token.IMPLICIT:
7421 case Token.INTERFACE:
7423 case Token.INTERNAL:
7429 case Token.NAMESPACE:
7435 case Token.OPERATOR:
7439 case Token.OVERRIDE:
7445 case Token.PROTECTED:
7449 case Token.READONLY:
7461 case Token.STACKALLOC:
7462 return "stackalloc";
7479 case Token.UNCHECKED:
7487 case Token.VOLATILE:
7495 case Token.REFVALUE:
7496 return "__refvalue";
7506 case Token.FROM_FIRST:
7524 case Token.ASCENDING:
7526 case Token.DESCENDING:
7527 return "descending";
7534 case Token.OPEN_BRACE:
7536 case Token.CLOSE_BRACE:
7538 case Token.OPEN_BRACKET:
7539 case Token.OPEN_BRACKET_EXPR:
7541 case Token.CLOSE_BRACKET:
7543 case Token.OPEN_PARENS_CAST:
7544 case Token.OPEN_PARENS_LAMBDA:
7545 case Token.OPEN_PARENS:
7547 case Token.CLOSE_PARENS:
7553 case Token.DEFAULT_COLON:
7557 case Token.SEMICOLON:
7568 case Token.BITWISE_AND:
7569 case Token.BITWISE_OR:
7576 case Token.OP_SHIFT_LEFT:
7577 case Token.OP_SHIFT_RIGHT:
7585 case Token.OP_COALESCING:
7586 case Token.OP_MULT_ASSIGN:
7587 case Token.OP_DIV_ASSIGN:
7588 case Token.OP_MOD_ASSIGN:
7589 case Token.OP_ADD_ASSIGN:
7590 case Token.OP_SUB_ASSIGN:
7591 case Token.OP_SHIFT_LEFT_ASSIGN:
7592 case Token.OP_SHIFT_RIGHT_ASSIGN:
7593 case Token.OP_AND_ASSIGN:
7594 case Token.OP_XOR_ASSIGN:
7595 case Token.OP_OR_ASSIGN:
7596 return "<operator>";
7618 case Token.OP_GENERICS_LT:
7619 case Token.GENERIC_DIMENSION:
7621 case Token.OP_GENERICS_GT:
7624 case Token.INTERR_NULLABLE:
7626 case Token.DOUBLE_COLON:
7630 case Token.IDENTIFIER:
7632 return "identifier";
7635 return "end-of-file";
7637 // All of these are internal.
7640 case Token.FIRST_KEYWORD:
7641 case Token.EVAL_COMPILATION_UNIT_PARSER:
7642 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7643 case Token.EVAL_STATEMENT_PARSER:
7644 case Token.LAST_KEYWORD:
7645 case Token.GENERATE_COMPLETION:
7646 case Token.COMPLETE_COMPLETION:
7647 return "<internal>";
7649 // A bit more robust.
7651 return yyNames [token];