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 Xamarin Inc.
16 // (1) Figure out why error productions dont work. `type-declaration' is a
17 // great spot to put an `error' because you can reproduce it with this input:
24 using System.Collections.Generic;
31 public class CSharpParser
34 enum ParameterModifierType
41 DefaultValue = 1 << 6,
43 All = Ref | Out | This | Params | Arglist | DefaultValue
46 static readonly object ModifierNone = 0;
48 NamespaceContainer current_namespace;
49 TypeContainer current_container;
50 TypeDefinition current_type;
51 PropertyBase current_property;
52 EventProperty current_event;
53 EventField current_event_field;
54 FieldBase current_field;
57 /// Current block is used to add statements as we find
62 BlockVariableDeclaration current_variable;
64 Delegate current_delegate;
66 AnonymousMethodExpression current_anonymous_method;
69 /// This is used by the unary_expression code to resolve
70 /// a name against a parameter.
73 // FIXME: This is very ugly and it's very hard to reset it correctly
74 // on all places, especially when some parameters are autogenerated.
75 ParametersCompiled current_local_parameters;
77 bool parsing_anonymous_method;
82 /// An out-of-band stack.
84 static Stack<object> oob_stack;
87 /// Controls the verbosity of the errors produced by the parser
89 int yacc_verbose_flag;
92 /// Used by the interactive shell, flags whether EOF was reached
93 /// and an error was produced
95 public bool UnexpectedEOF;
100 readonly CompilationSourceFile file;
103 /// Temporary Xml documentation cache.
104 /// For enum types, we need one more temporary store.
107 string enumTypeComment;
109 /// Current attribute target
110 string current_attr_target;
112 ParameterModifierType valid_param_mod;
114 bool default_parameter_used;
116 /// When using the interactive parser, this holds the
117 /// resulting expression
118 public Class InteractiveResult;
121 // Keeps track of global data changes to undo on parser error
125 Stack<Linq.QueryBlock> linq_clause_blocks;
127 ModuleContainer module;
129 readonly CompilerContext compiler;
130 readonly LanguageVersion lang_version;
131 readonly bool doc_support;
132 readonly CompilerSettings settings;
133 readonly Report report;
136 // Instead of allocating carrier array everytime we
137 // share the bucket for very common constructs which can never
140 static List<Parameter> parameters_bucket = new List<Parameter> (6);
143 // Full AST support members
146 List<Tuple<Modifiers, Location>> mod_locations;
150 %token NONE /* This token is never returned by our lexer */
151 %token ERROR // This is used not by the parser, but by the tokenizer.
155 *These are the C# keywords
254 %token INTERR_NULLABLE
262 /* C# keywords which are not really keywords */
268 /* C# single character operators/punctuation. */
296 /* C# multi-character operators. */
301 %token OP_SHIFT_RIGHT
308 %token OP_MULT_ASSIGN
313 %token OP_SHIFT_LEFT_ASSIGN
314 %token OP_SHIFT_RIGHT_ASSIGN
321 /* Generics <,> tokens */
322 %token OP_GENERICS_LT
323 %token OP_GENERICS_LT_DECL
324 %token OP_GENERICS_GT
329 %token OPEN_PARENS_LAMBDA
330 %token OPEN_PARENS_CAST
331 %token GENERIC_DIMENSION
333 %token OPEN_BRACKET_EXPR
335 // Make the parser go into eval mode parsing (statements and compilation units).
336 %token EVAL_STATEMENT_PARSER
337 %token EVAL_COMPILATION_UNIT_PARSER
338 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
343 // This token is generated to trigger the completion engine at this point
345 %token GENERATE_COMPLETION
348 // This token is return repeatedly after the first GENERATE_COMPLETION
349 // token is produced and before the final EOF
351 %token COMPLETE_COMPLETION
353 /* Add precedence rules to solve dangling else s/r conflict */
357 /* Define the operator tokens and their precedences */
365 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
367 %left STAR DIV PERCENT
368 %right BANG CARRET UMINUS
369 %nonassoc OP_INC OP_DEC
371 %left OPEN_BRACKET OPEN_BRACE
374 %start compilation_unit
378 : outer_declaration opt_EOF
380 Lexer.check_incorrect_doc_comment ();
382 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
383 | documentation_parsing
387 : opt_extern_alias_directives opt_using_directives
388 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
391 Attributes attrs = (Attributes) $4;
392 report.Error (1730, attrs.Attrs [0].Location,
393 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
395 current_namespace.UnattachedAttributes = attrs;
398 | opt_extern_alias_directives opt_using_directives attribute_sections
400 module.AddAttributes ((Attributes) $3, current_namespace);
404 if (yyToken == Token.EXTERN_ALIAS)
405 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
407 Error_SyntaxError (yyToken);
416 extern_alias_directives
417 : extern_alias_directive
418 | extern_alias_directives extern_alias_directive
421 extern_alias_directive
422 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
424 var lt = (Tokenizer.LocatedToken) $2;
427 syntax_error (lt.Location, "`alias' expected");
429 if (lang_version == LanguageVersion.ISO_1)
430 FeatureIsNotAvailable (lt.Location, "external alias");
432 lt = (Tokenizer.LocatedToken) $3;
433 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
434 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
437 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
438 current_namespace.AddUsing (na);
440 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
445 Error_SyntaxError (yyToken);
451 | using_directives using_directive
458 Lexer.doc_state = XmlCommentState.Allowed;
463 : USING namespace_or_type_expr SEMICOLON
465 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
466 current_namespace.AddUsing (un);
468 lbag.AddLocation (un, GetLocation ($3));
470 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
472 var lt = (Tokenizer.LocatedToken) $2;
473 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
474 report.Warning (440, 2, lt.Location,
475 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
478 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
479 current_namespace.AddUsing (un);
481 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
485 Error_SyntaxError (yyToken);
491 // Strictly speaking, namespaces don't have attributes but
492 // we parse global attributes along with namespace declarations and then
495 namespace_declaration
496 : opt_attributes NAMESPACE namespace_name
498 Attributes attrs = (Attributes) $1;
499 var name = (MemberName) $3;
501 bool valid_global_attrs = true;
502 if ((current_namespace.DeclarationFound || current_namespace != file)) {
503 valid_global_attrs = false;
505 foreach (var a in attrs.Attrs) {
506 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
509 valid_global_attrs = false;
514 if (!valid_global_attrs)
515 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
518 module.AddAttributes (attrs, current_namespace);
520 var ns = new NamespaceContainer (name, current_namespace);
521 current_namespace.AddTypeContainer (ns);
522 current_container = current_namespace = ns;
527 Lexer.doc_state = XmlCommentState.Allowed;
529 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon
532 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
534 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
536 current_container = current_namespace = current_namespace.Parent;
543 var lt = (Tokenizer.LocatedToken) $1;
544 $$ = new MemberName (lt.Value, lt.Location);
546 | namespace_name DOT IDENTIFIER
548 var lt = (Tokenizer.LocatedToken) $3;
549 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
553 Error_SyntaxError (yyToken);
554 $$ = new MemberName ("<invalid>", lexer.Location);
573 opt_extern_alias_directives
575 | extern_alias_directives
578 opt_namespace_or_type_declarations
580 | namespace_or_type_declarations
583 namespace_or_type_declarations
584 : namespace_or_type_declaration
585 | namespace_or_type_declarations namespace_or_type_declaration
588 namespace_or_type_declaration
592 TypeContainer ds = (TypeContainer)$1;
594 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
595 report.Error (1527, ds.Location,
596 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
599 // Here is a trick, for explicit attributes we don't know where they belong to until
600 // we parse succeeding declaration hence we parse them as normal and re-attach them
601 // when we know whether they are global (assembly:, module:) or local (type:).
602 if (ds.OptAttributes != null) {
603 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
606 current_namespace.DeclarationFound = true;
608 | namespace_declaration
610 current_namespace.DeclarationFound = true;
612 | attribute_sections CLOSE_BRACE {
613 current_namespace.UnattachedAttributes = (Attributes) $1;
614 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
622 | interface_declaration
624 | delegate_declaration
626 // Enable this when we have handled all errors, because this acts as a generic fallback
629 // Console.WriteLine ("Token=" + yyToken);
630 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
646 var sect = (List<Attribute>) $1;
647 $$ = new Attributes (sect);
649 | attribute_sections attribute_section
651 Attributes attrs = $1 as Attributes;
652 var sect = (List<Attribute>) $2;
654 attrs = new Attributes (sect);
656 attrs.AddAttributes (sect);
664 lexer.parsing_attribute_section = true;
666 attribute_section_cont
668 lexer.parsing_attribute_section = false;
673 attribute_section_cont
674 : attribute_target COLON
676 current_attr_target = (string) $1;
677 if (current_attr_target == "assembly" || current_attr_target == "module") {
678 Lexer.check_incorrect_doc_comment ();
681 attribute_list opt_comma CLOSE_BRACKET
683 // when attribute target is invalid
684 if (current_attr_target == string.Empty)
685 $$ = new List<Attribute> (0);
689 current_attr_target = null;
690 lexer.parsing_attribute_section = false;
692 | attribute_list opt_comma CLOSE_BRACKET
701 var lt = (Tokenizer.LocatedToken) $1;
702 $$ = CheckAttributeTarget (lt.Value, lt.Location);
704 | EVENT { $$ = "event"; }
705 | RETURN { $$ = "return"; }
708 if (yyToken == Token.IDENTIFIER) {
709 Error_SyntaxError (yyToken);
712 string name = GetTokenName (yyToken);
713 $$ = CheckAttributeTarget (name, GetLocation ($1));
721 $$ = new List<Attribute> (4) { (Attribute) $1 };
723 | attribute_list COMMA attribute
725 var attrs = (List<Attribute>) $1;
726 attrs.Add ((Attribute) $3);
735 ++lexer.parsing_block;
737 opt_attribute_arguments
739 --lexer.parsing_block;
741 var tne = (ATypeNameExpression) $1;
742 if (tne.HasTypeArguments) {
743 report.Error (404, tne.Location, "Attributes cannot be generic");
746 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
751 : namespace_or_type_expr
754 opt_attribute_arguments
755 : /* empty */ { $$ = null; }
756 | OPEN_PARENS attribute_arguments CLOSE_PARENS
764 : /* empty */ { $$ = null; }
765 | positional_or_named_argument
767 Arguments a = new Arguments (4);
768 a.Add ((Argument) $1);
769 $$ = new Arguments [] { a, null };
771 | named_attribute_argument
773 Arguments a = new Arguments (4);
774 a.Add ((Argument) $1);
775 $$ = new Arguments [] { null, a };
777 | attribute_arguments COMMA positional_or_named_argument
779 Arguments[] o = (Arguments[]) $1;
781 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
782 o [0] = new Arguments (4);
785 Arguments args = ((Arguments) o [0]);
786 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
787 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
789 args.Add ((Argument) $3);
791 | attribute_arguments COMMA named_attribute_argument
793 Arguments[] o = (Arguments[]) $1;
795 o [1] = new Arguments (4);
798 ((Arguments) o [1]).Add ((Argument) $3);
802 positional_or_named_argument
805 $$ = new Argument ((Expression) $1);
810 named_attribute_argument
813 ++lexer.parsing_block;
817 --lexer.parsing_block;
818 var lt = (Tokenizer.LocatedToken) $1;
819 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
820 lbag.AddLocation ($$, GetLocation($2));
825 : identifier_inside_body COLON opt_named_modifier expression
827 if (lang_version <= LanguageVersion.V_3)
828 FeatureIsNotAvailable (GetLocation ($1), "named argument");
830 // Avoid boxing in common case (no modifier)
831 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
833 var lt = (Tokenizer.LocatedToken) $1;
834 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
835 lbag.AddLocation ($$, GetLocation($2));
840 : /* empty */ { $$ = null; }
843 $$ = Argument.AType.Ref;
847 $$ = Argument.AType.Out;
851 opt_class_member_declarations
853 | class_member_declarations
856 class_member_declarations
857 : class_member_declaration
859 lexer.parsing_modifiers = true;
861 | class_member_declarations class_member_declaration
863 lexer.parsing_modifiers = true;
867 class_member_declaration
868 : constant_declaration
871 | property_declaration
873 | indexer_declaration
874 | operator_declaration
875 | constructor_declaration
876 | destructor_declaration
878 | attributes_without_members
881 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
882 GetSymbolName (yyToken));
884 lexer.parsing_generic_declaration = false;
894 lexer.ConstraintsParsing = true;
896 type_declaration_name
898 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
901 opt_type_parameter_constraints_clauses
903 lexer.ConstraintsParsing = false;
906 current_container.SetConstraints ((List<Constraints>) $9);
909 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
911 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
913 lexer.parsing_modifiers = true;
918 Lexer.doc_state = XmlCommentState.Allowed;
920 opt_class_member_declarations CLOSE_BRACE
922 --lexer.parsing_declaration;
924 Lexer.doc_state = XmlCommentState.Allowed;
928 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
929 $$ = pop_current_class ();
931 | opt_attributes opt_modifiers opt_partial STRUCT error
933 Error_SyntaxError (yyToken);
940 CONST type IDENTIFIER
942 var lt = (Tokenizer.LocatedToken) $5;
943 var mod = (Modifiers) $2;
944 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
945 current_type.AddMember (current_field);
947 if ((mod & Modifiers.STATIC) != 0) {
948 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
953 constant_initializer opt_constant_declarators SEMICOLON
956 current_field.DocComment = Lexer.consume_doc_comment ();
957 Lexer.doc_state = XmlCommentState.Allowed;
960 current_field.Initializer = (ConstInitializer) $7;
961 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
962 current_field = null;
966 opt_constant_declarators
968 | constant_declarators
972 : constant_declarator
974 current_field.AddDeclarator ((FieldDeclarator) $1);
976 | constant_declarators constant_declarator
978 current_field.AddDeclarator ((FieldDeclarator) $2);
983 : COMMA IDENTIFIER constant_initializer
985 var lt = (Tokenizer.LocatedToken) $2;
986 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
987 lbag.AddLocation ($$, GetLocation ($1));
994 ++lexer.parsing_block;
996 constant_initializer_expr
998 --lexer.parsing_block;
999 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1003 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1008 constant_initializer_expr
1009 : constant_expression
1016 member_type IDENTIFIER
1018 lexer.parsing_generic_declaration = false;
1020 FullNamedExpression type = (FullNamedExpression) $3;
1021 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1022 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1024 var lt = (Tokenizer.LocatedToken) $4;
1025 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1026 current_type.AddField (current_field);
1029 opt_field_initializer
1030 opt_field_declarators
1034 current_field.DocComment = Lexer.consume_doc_comment ();
1035 Lexer.doc_state = XmlCommentState.Allowed;
1038 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1040 current_field = null;
1044 FIXED simple_type IDENTIFIER
1046 if (lang_version < LanguageVersion.ISO_2)
1047 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1049 var lt = (Tokenizer.LocatedToken) $5;
1050 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1051 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1053 current_type.AddField (current_field);
1055 fixed_field_size opt_fixed_field_declarators SEMICOLON
1058 current_field.DocComment = Lexer.consume_doc_comment ();
1059 Lexer.doc_state = XmlCommentState.Allowed;
1062 current_field.Initializer = (ConstInitializer) $7;
1063 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1065 current_field = null;
1069 FIXED simple_type error
1072 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1076 opt_field_initializer
1080 ++lexer.parsing_block;
1081 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1082 start_block (GetLocation ($1));
1084 variable_initializer
1086 --lexer.parsing_block;
1087 current_field.Initializer = (Expression) $3;
1088 end_block (lexer.Location);
1089 current_local_parameters = null;
1093 opt_field_declarators
1101 current_field.AddDeclarator ((FieldDeclarator) $1);
1103 | field_declarators field_declarator
1105 current_field.AddDeclarator ((FieldDeclarator) $2);
1112 var lt = (Tokenizer.LocatedToken) $2;
1113 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1114 lbag.AddLocation ($$, GetLocation ($1));
1116 | COMMA IDENTIFIER ASSIGN
1118 ++lexer.parsing_block;
1120 variable_initializer
1122 --lexer.parsing_block;
1123 var lt = (Tokenizer.LocatedToken) $2;
1124 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1125 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1129 opt_fixed_field_declarators
1131 | fixed_field_declarators
1134 fixed_field_declarators
1135 : fixed_field_declarator
1137 current_field.AddDeclarator ((FieldDeclarator) $1);
1139 | fixed_field_declarators fixed_field_declarator
1141 current_field.AddDeclarator ((FieldDeclarator) $2);
1145 fixed_field_declarator
1146 : COMMA IDENTIFIER fixed_field_size
1148 var lt = (Tokenizer.LocatedToken) $2;
1149 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1150 lbag.AddLocation ($$, GetLocation ($1));
1157 ++lexer.parsing_block;
1159 expression CLOSE_BRACKET
1161 --lexer.parsing_block;
1162 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1163 lbag.AddLocation ($$, GetLocation ($4));
1165 | OPEN_BRACKET error
1167 report.Error (443, lexer.Location, "Value or constant expected");
1172 variable_initializer
1177 // It has to be here for the parent to safely restore artificial block
1178 Error_SyntaxError (yyToken);
1187 Lexer.doc_state = XmlCommentState.NotAllowed;
1189 // Add it early in the case of body being eof for full ast
1190 Method m = (Method) $1;
1191 async_block = (m.ModFlags & Modifiers.ASYNC) != 0;
1192 current_type.AddMember (m);
1196 Method method = (Method) $1;
1197 method.Block = (ToplevelBlock) $3;
1198 async_block = false;
1200 if (method.Block == null) {
1201 method.ParameterInfo.CheckParameters (method);
1203 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1204 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1205 method.GetSignatureForError ());
1208 if (current_container.Kind == MemberKind.Interface) {
1209 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1210 method.GetSignatureForError ());
1214 current_local_parameters = null;
1217 Lexer.doc_state = XmlCommentState.Allowed;
1225 method_declaration_name OPEN_PARENS
1227 valid_param_mod = ParameterModifierType.All;
1229 opt_formal_parameter_list CLOSE_PARENS
1231 lexer.ConstraintsParsing = true;
1233 opt_type_parameter_constraints_clauses
1235 lexer.ConstraintsParsing = false;
1236 valid_param_mod = 0;
1237 MemberName name = (MemberName) $4;
1238 current_local_parameters = (ParametersCompiled) $7;
1240 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1241 name, current_local_parameters, (Attributes) $1, $10 != null);
1244 method.SetConstraints ((List<Constraints>) $10);
1247 method.DocComment = Lexer.consume_doc_comment ();
1249 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1257 lexer.parsing_generic_declaration = true;
1259 method_declaration_name
1262 lexer.parsing_generic_declaration = false;
1263 valid_param_mod = ParameterModifierType.All;
1265 opt_formal_parameter_list CLOSE_PARENS
1267 lexer.ConstraintsParsing = true;
1269 opt_type_parameter_constraints_clauses
1271 lexer.ConstraintsParsing = false;
1272 valid_param_mod = 0;
1274 MemberName name = (MemberName) $6;
1275 current_local_parameters = (ParametersCompiled) $9;
1277 var modifiers = (Modifiers) $2;
1278 modifiers |= Modifiers.PARTIAL;
1280 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1281 modifiers, name, current_local_parameters, (Attributes) $1, $11 != null);
1284 method.SetConstraints ((List<Constraints>) $11);
1287 method.DocComment = Lexer.consume_doc_comment ();
1289 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1290 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1296 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1298 MemberName name = (MemberName) $5;
1299 report.Error (1585, name.Location,
1300 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1302 var method = Method.Create (current_type, (FullNamedExpression) $3,
1303 0, name, (ParametersCompiled) $7, (Attributes) $1, false);
1305 current_local_parameters = (ParametersCompiled) $7;
1308 method.DocComment = Lexer.consume_doc_comment ();
1315 method_declaration_name error
1317 Error_SyntaxError (yyToken);
1318 current_local_parameters = ParametersCompiled.Undefined;
1320 MemberName name = (MemberName) $4;
1321 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1322 name, current_local_parameters, (Attributes) $1, false);
1325 method.DocComment = Lexer.consume_doc_comment ();
1333 | SEMICOLON { $$ = null; }
1336 opt_formal_parameter_list
1337 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1338 | formal_parameter_list
1341 formal_parameter_list
1344 var pars_list = (List<Parameter>) $1;
1345 $$ = new ParametersCompiled (pars_list.ToArray ());
1347 | fixed_parameters COMMA parameter_array
1349 var pars_list = (List<Parameter>) $1;
1350 pars_list.Add ((Parameter) $3);
1352 $$ = new ParametersCompiled (pars_list.ToArray ());
1354 | fixed_parameters COMMA arglist_modifier
1356 var pars_list = (List<Parameter>) $1;
1357 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1358 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1360 | parameter_array COMMA error
1363 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1365 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1367 | fixed_parameters COMMA parameter_array COMMA error
1370 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1372 var pars_list = (List<Parameter>) $1;
1373 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1375 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1377 | arglist_modifier COMMA error
1379 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1381 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1383 | fixed_parameters COMMA ARGLIST COMMA error
1385 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1387 var pars_list = (List<Parameter>) $1;
1388 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1390 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1394 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1398 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1402 Error_SyntaxError (yyToken);
1403 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1410 parameters_bucket.Clear ();
1411 Parameter p = (Parameter) $1;
1412 parameters_bucket.Add (p);
1414 default_parameter_used = p.HasDefaultValue;
1415 $$ = parameters_bucket;
1417 | fixed_parameters COMMA fixed_parameter
1419 var pars = (List<Parameter>) $1;
1420 Parameter p = (Parameter) $3;
1422 if (p.HasExtensionMethodModifier)
1423 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1424 else if (!p.HasDefaultValue && default_parameter_used)
1425 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1427 default_parameter_used |= p.HasDefaultValue;
1430 lbag.AddLocation (p, GetLocation ($2));
1439 opt_parameter_modifier
1443 var lt = (Tokenizer.LocatedToken) $4;
1444 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1447 opt_parameter_modifier
1449 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1451 var lt = (Tokenizer.LocatedToken) $4;
1452 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1453 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1455 | attribute_sections error
1457 Error_SyntaxError (yyToken);
1458 Location l = GetLocation ($2);
1459 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1462 opt_parameter_modifier
1466 Error_SyntaxError (yyToken);
1467 Location l = GetLocation ($4);
1468 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1471 opt_parameter_modifier
1476 ++lexer.parsing_block;
1480 --lexer.parsing_block;
1481 if (lang_version <= LanguageVersion.V_3) {
1482 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1485 Parameter.Modifier mod = (Parameter.Modifier) $2;
1486 if (mod != Parameter.Modifier.NONE) {
1488 case Parameter.Modifier.REF:
1489 case Parameter.Modifier.OUT:
1490 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1491 Parameter.GetModifierSignature (mod));
1494 case Parameter.Modifier.This:
1495 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1496 Parameter.GetModifierSignature (mod));
1499 throw new NotImplementedException (mod.ToString ());
1502 mod = Parameter.Modifier.NONE;
1505 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1506 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1508 var lt = (Tokenizer.LocatedToken) $4;
1509 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1510 lbag.AddLocation ($$, GetLocation ($5));
1513 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1517 opt_parameter_modifier
1518 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1519 | parameter_modifiers
1523 : parameter_modifier
1527 | parameter_modifiers parameter_modifier
1529 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1530 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1531 if (((Parameter.Modifier)$1 & p2) == p2) {
1532 Error_DuplicateParameterModifier (lexer.Location, p2);
1534 switch (mod & ~Parameter.Modifier.This) {
1535 case Parameter.Modifier.REF:
1536 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1538 case Parameter.Modifier.OUT:
1539 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1542 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1553 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1554 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1556 $$ = Parameter.Modifier.REF;
1560 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1561 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1563 $$ = Parameter.Modifier.OUT;
1567 if ((valid_param_mod & ParameterModifierType.This) == 0)
1568 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1570 if (lang_version <= LanguageVersion.ISO_2)
1571 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1573 $$ = Parameter.Modifier.This;
1578 : opt_attributes params_modifier type IDENTIFIER
1580 var lt = (Tokenizer.LocatedToken) $4;
1581 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1583 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1585 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1587 var lt = (Tokenizer.LocatedToken) $4;
1588 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1590 | opt_attributes params_modifier type error
1592 Error_SyntaxError (yyToken);
1600 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1601 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1603 | PARAMS parameter_modifier
1605 Parameter.Modifier mod = (Parameter.Modifier)$2;
1606 if ((mod & Parameter.Modifier.This) != 0) {
1607 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1609 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1612 | PARAMS params_modifier
1614 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1621 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1622 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1626 property_declaration
1630 member_declaration_name
1633 tmpComment = Lexer.consume_doc_comment ();
1637 var type = (FullNamedExpression) $3;
1638 current_property = new Property (current_type, type, (Modifiers) $2,
1639 (MemberName) $4, (Attributes) $1);
1641 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1642 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1644 current_type.AddMember (current_property);
1645 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1647 lexer.PropertyParsing = true;
1649 accessor_declarations
1651 lexer.PropertyParsing = false;
1654 current_property.DocComment = ConsumeStoredComment ();
1658 lbag.AppendToMember (current_property, GetLocation ($10));
1659 current_property = null;
1665 : opt_attributes opt_modifiers
1666 member_type indexer_declaration_name OPEN_BRACKET
1668 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1670 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1672 valid_param_mod = 0;
1673 var type = (FullNamedExpression) $3;
1674 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1676 current_property = indexer;
1678 current_type.AddIndexer (indexer);
1679 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1681 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1682 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1684 if (indexer.ParameterInfo.IsEmpty) {
1685 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1689 tmpComment = Lexer.consume_doc_comment ();
1690 Lexer.doc_state = XmlCommentState.Allowed;
1693 lexer.PropertyParsing = true;
1695 accessor_declarations
1697 lexer.PropertyParsing = false;
1701 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1702 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1705 current_property.DocComment = ConsumeStoredComment ();
1707 lbag.AppendToMember (current_property, GetLocation ($12));
1708 current_property = null;
1713 accessor_declarations
1714 : get_accessor_declaration
1715 | get_accessor_declaration accessor_declarations
1716 | set_accessor_declaration
1717 | set_accessor_declaration accessor_declarations
1720 if (yyToken == Token.CLOSE_BRACE) {
1721 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1723 if (yyToken == Token.SEMICOLON)
1724 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1726 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1731 get_accessor_declaration
1732 : opt_attributes opt_modifiers GET
1734 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1735 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1738 if (current_property.Get != null) {
1739 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1742 if (current_property is Indexer) {
1743 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1744 (Attributes) $1, GetLocation ($3));
1746 current_property.Get = new Property.GetMethod (current_property,
1747 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1750 current_local_parameters = current_property.Get.ParameterInfo;
1751 lbag.AddMember (current_property.Get, mod_locations);
1752 lexer.PropertyParsing = false;
1757 current_property.Get.Block = (ToplevelBlock) $5;
1759 if (current_container.Kind == MemberKind.Interface) {
1760 report.Error (531, current_property.Get.Block.StartLocation,
1761 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1765 current_local_parameters = null;
1766 lexer.PropertyParsing = true;
1769 if (Lexer.doc_state == XmlCommentState.Error)
1770 Lexer.doc_state = XmlCommentState.NotAllowed;
1774 set_accessor_declaration
1775 : opt_attributes opt_modifiers SET
1777 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1778 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1781 if (current_property.Set != null) {
1782 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1785 if (current_property is Indexer) {
1786 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1787 ParametersCompiled.MergeGenerated (compiler,
1788 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1789 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1791 (Attributes) $1, GetLocation ($3));
1793 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1794 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1795 (Attributes) $1, GetLocation ($3));
1798 current_local_parameters = current_property.Set.ParameterInfo;
1799 lbag.AddMember (current_property.Set, mod_locations);
1800 lexer.PropertyParsing = false;
1805 current_property.Set.Block = (ToplevelBlock) $5;
1807 if (current_container.Kind == MemberKind.Interface) {
1808 report.Error (531, current_property.Set.Block.StartLocation,
1809 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1813 current_local_parameters = null;
1814 lexer.PropertyParsing = true;
1817 && Lexer.doc_state == XmlCommentState.Error)
1818 Lexer.doc_state = XmlCommentState.NotAllowed;
1831 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1836 interface_declaration
1842 lexer.ConstraintsParsing = true;
1844 type_declaration_name
1846 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1847 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1850 opt_type_parameter_constraints_clauses
1852 lexer.ConstraintsParsing = false;
1855 current_container.SetConstraints ((List<Constraints>) $9);
1858 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1859 Lexer.doc_state = XmlCommentState.Allowed;
1862 lexer.parsing_modifiers = true;
1864 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1866 --lexer.parsing_declaration;
1868 Lexer.doc_state = XmlCommentState.Allowed;
1872 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1873 $$ = pop_current_class ();
1875 | opt_attributes opt_modifiers opt_partial INTERFACE error
1877 Error_SyntaxError (yyToken);
1881 opt_interface_member_declarations
1883 | interface_member_declarations
1886 interface_member_declarations
1887 : interface_member_declaration
1889 lexer.parsing_modifiers = true;
1891 | interface_member_declarations interface_member_declaration
1893 lexer.parsing_modifiers = true;
1897 interface_member_declaration
1898 : constant_declaration
1900 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1904 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1906 | method_declaration
1907 | property_declaration
1909 | indexer_declaration
1910 | operator_declaration
1912 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1914 | constructor_declaration
1916 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1920 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1924 operator_declaration
1925 : opt_attributes opt_modifiers operator_declarator
1930 OperatorDeclaration decl = (OperatorDeclaration) $3;
1932 Operator op = new Operator (
1933 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1934 current_local_parameters,
1935 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1937 if (op.Block == null)
1938 op.ParameterInfo.CheckParameters (op);
1941 op.DocComment = tmpComment;
1942 Lexer.doc_state = XmlCommentState.Allowed;
1945 // Note again, checking is done in semantic analysis
1946 current_type.AddOperator (op);
1948 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1951 current_local_parameters = null;
1957 | SEMICOLON { $$ = null; }
1961 : type_expression_or_array
1964 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1965 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
1970 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1972 valid_param_mod = ParameterModifierType.DefaultValue;
1974 opt_formal_parameter_list CLOSE_PARENS
1976 valid_param_mod = 0;
1978 Location loc = GetLocation ($2);
1979 Operator.OpType op = (Operator.OpType) $3;
1980 current_local_parameters = (ParametersCompiled)$6;
1982 int p_count = current_local_parameters.Count;
1984 if (op == Operator.OpType.Addition)
1985 op = Operator.OpType.UnaryPlus;
1986 else if (op == Operator.OpType.Subtraction)
1987 op = Operator.OpType.UnaryNegation;
1990 if (IsUnaryOperator (op)) {
1992 report.Error (1020, loc, "Overloadable binary operator expected");
1993 } else if (p_count != 1) {
1994 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1995 Operator.GetName (op));
1999 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2000 Operator.GetName (op));
2001 } else if (p_count != 2) {
2002 report.Error (1019, loc, "Overloadable unary operator expected");
2007 tmpComment = Lexer.consume_doc_comment ();
2008 Lexer.doc_state = XmlCommentState.NotAllowed;
2011 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2012 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2014 | conversion_operator_declarator
2017 overloadable_operator
2019 : BANG { $$ = Operator.OpType.LogicalNot; }
2020 | TILDE { $$ = Operator.OpType.OnesComplement; }
2021 | OP_INC { $$ = Operator.OpType.Increment; }
2022 | OP_DEC { $$ = Operator.OpType.Decrement; }
2023 | TRUE { $$ = Operator.OpType.True; }
2024 | FALSE { $$ = Operator.OpType.False; }
2025 // Unary and binary:
2026 | PLUS { $$ = Operator.OpType.Addition; }
2027 | MINUS { $$ = Operator.OpType.Subtraction; }
2029 | STAR { $$ = Operator.OpType.Multiply; }
2030 | DIV { $$ = Operator.OpType.Division; }
2031 | PERCENT { $$ = Operator.OpType.Modulus; }
2032 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2033 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2034 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2035 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2036 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2037 | OP_EQ { $$ = Operator.OpType.Equality; }
2038 | OP_NE { $$ = Operator.OpType.Inequality; }
2039 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2040 | OP_LT { $$ = Operator.OpType.LessThan; }
2041 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2042 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2045 conversion_operator_declarator
2046 : IMPLICIT OPERATOR type OPEN_PARENS
2048 valid_param_mod = ParameterModifierType.DefaultValue;
2050 opt_formal_parameter_list CLOSE_PARENS
2052 valid_param_mod = 0;
2054 Location loc = GetLocation ($2);
2055 current_local_parameters = (ParametersCompiled)$6;
2058 tmpComment = Lexer.consume_doc_comment ();
2059 Lexer.doc_state = XmlCommentState.NotAllowed;
2062 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2063 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2065 | EXPLICIT OPERATOR type OPEN_PARENS
2067 valid_param_mod = ParameterModifierType.DefaultValue;
2069 opt_formal_parameter_list CLOSE_PARENS
2071 valid_param_mod = 0;
2073 Location loc = GetLocation ($2);
2074 current_local_parameters = (ParametersCompiled)$6;
2077 tmpComment = Lexer.consume_doc_comment ();
2078 Lexer.doc_state = XmlCommentState.NotAllowed;
2081 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2082 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2086 Error_SyntaxError (yyToken);
2087 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2088 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2092 Error_SyntaxError (yyToken);
2093 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2094 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2098 constructor_declaration
2099 : constructor_declarator
2102 Constructor c = (Constructor) $1;
2103 c.Block = (ToplevelBlock) $2;
2106 c.DocComment = ConsumeStoredComment ();
2108 current_local_parameters = null;
2110 Lexer.doc_state = XmlCommentState.Allowed;
2114 constructor_declarator
2120 tmpComment = Lexer.consume_doc_comment ();
2121 Lexer.doc_state = XmlCommentState.Allowed;
2124 valid_param_mod = ParameterModifierType.All;
2126 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2128 valid_param_mod = 0;
2129 current_local_parameters = (ParametersCompiled) $6;
2131 var lt = (Tokenizer.LocatedToken) $3;
2132 var mods = (Modifiers) $2;
2133 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2135 if (lt.Value != current_container.MemberName.Name) {
2136 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2137 } else if ((mods & Modifiers.STATIC) != 0) {
2138 if ((mods & Modifiers.AccessibilityMask) != 0){
2139 report.Error (515, c.Location,
2140 "`{0}': static constructor cannot have an access modifier",
2141 c.GetSignatureForError ());
2145 current_type.AddConstructor (c);
2146 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2150 // start block here, so possible anonymous methods inside
2151 // constructor initializer can get correct parent block
2153 start_block (lexer.Location);
2155 opt_constructor_initializer
2158 var c = (Constructor) $8;
2159 c.Initializer = (ConstructorInitializer) $9;
2162 report.Error (514, c.Location,
2163 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2164 c.GetSignatureForError ());
2174 | SEMICOLON { current_block = null; $$ = null; }
2177 opt_constructor_initializer
2179 | constructor_initializer
2182 constructor_initializer
2183 : COLON BASE OPEN_PARENS
2185 ++lexer.parsing_block;
2187 opt_argument_list CLOSE_PARENS
2189 --lexer.parsing_block;
2190 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2191 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2193 | COLON THIS OPEN_PARENS
2195 ++lexer.parsing_block;
2197 opt_argument_list CLOSE_PARENS
2199 --lexer.parsing_block;
2200 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2201 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2205 Error_SyntaxError (yyToken);
2206 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2207 lbag.AddLocation ($$, GetLocation ($1));
2211 Error_SyntaxError (yyToken);
2216 destructor_declaration
2217 : opt_attributes opt_modifiers TILDE
2220 tmpComment = Lexer.consume_doc_comment ();
2221 Lexer.doc_state = XmlCommentState.NotAllowed;
2224 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2226 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2228 var lt = (Tokenizer.LocatedToken) $5;
2229 if (lt.Value != current_container.MemberName.Name){
2230 report.Error (574, lt.Location, "Name of destructor must match name of class");
2231 } else if (current_container.Kind != MemberKind.Class){
2232 report.Error (575, lt.Location, "Only class types can contain destructor");
2235 Destructor d = new Destructor (current_type, (Modifiers) $2,
2236 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2238 d.DocComment = ConsumeStoredComment ();
2240 d.Block = (ToplevelBlock) $8;
2241 current_type.AddMember (d);
2242 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2244 current_local_parameters = null;
2251 EVENT type member_declaration_name
2253 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2254 current_type.AddMember (current_event_field);
2256 if (current_event_field.MemberName.ExplicitInterface != null) {
2257 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2258 current_event_field.GetSignatureForError ());
2261 $$ = current_event_field;
2263 opt_event_initializer
2264 opt_event_declarators
2268 current_event_field.DocComment = Lexer.consume_doc_comment ();
2269 Lexer.doc_state = XmlCommentState.Allowed;
2272 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2273 current_event_field = null;
2277 EVENT type member_declaration_name
2280 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2281 current_type.AddMember (current_event);
2282 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2284 lexer.EventParsing = true;
2286 event_accessor_declarations
2288 if (current_container.Kind == MemberKind.Interface)
2289 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2291 lexer.EventParsing = false;
2296 current_event.DocComment = Lexer.consume_doc_comment ();
2297 Lexer.doc_state = XmlCommentState.Allowed;
2300 lbag.AppendToMember (current_event, GetLocation ($9));
2301 current_event = null;
2302 current_local_parameters = null;
2306 opt_event_initializer
2310 ++lexer.parsing_block;
2312 event_variable_initializer
2314 --lexer.parsing_block;
2315 current_event_field.Initializer = (Expression) $3;
2319 opt_event_declarators
2327 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2329 | event_declarators event_declarator
2331 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2338 var lt = (Tokenizer.LocatedToken) $2;
2339 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2340 lbag.AddLocation ($$, GetLocation ($1));
2342 | COMMA IDENTIFIER ASSIGN
2344 ++lexer.parsing_block;
2346 event_variable_initializer
2348 --lexer.parsing_block;
2349 var lt = (Tokenizer.LocatedToken) $2;
2350 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2351 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2355 event_variable_initializer
2357 if (current_container.Kind == MemberKind.Interface) {
2358 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2359 current_event_field.GetSignatureForError ());
2362 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2363 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2364 current_event_field.GetSignatureForError ());
2367 variable_initializer
2373 event_accessor_declarations
2374 : add_accessor_declaration remove_accessor_declaration
2375 | remove_accessor_declaration add_accessor_declaration
2376 | add_accessor_declaration
2378 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2379 current_event.GetSignatureForError ());
2381 | remove_accessor_declaration
2383 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2384 current_event.GetSignatureForError ());
2388 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2393 add_accessor_declaration
2394 : opt_attributes opt_modifiers ADD
2396 if ($2 != ModifierNone) {
2397 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2400 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2401 current_local_parameters = current_event.Add.ParameterInfo;
2403 lbag.AddMember (current_event.Add, mod_locations);
2404 lexer.EventParsing = false;
2406 event_accessor_block
2408 lexer.EventParsing = true;
2410 current_event.Add.Block = (ToplevelBlock) $5;
2412 if (current_container.Kind == MemberKind.Interface) {
2413 report.Error (531, current_event.Add.Block.StartLocation,
2414 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2417 current_local_parameters = null;
2421 remove_accessor_declaration
2422 : opt_attributes opt_modifiers REMOVE
2424 if ($2 != ModifierNone) {
2425 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2428 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2429 current_local_parameters = current_event.Remove.ParameterInfo;
2431 lbag.AddMember (current_event.Remove, mod_locations);
2432 lexer.EventParsing = false;
2434 event_accessor_block
2436 lexer.EventParsing = true;
2438 current_event.Remove.Block = (ToplevelBlock) $5;
2440 if (current_container.Kind == MemberKind.Interface) {
2441 report.Error (531, current_event.Remove.Block.StartLocation,
2442 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2445 current_local_parameters = null;
2449 event_accessor_block
2452 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2458 attributes_without_members
2459 : attribute_sections CLOSE_BRACE
2461 current_type.UnattachedAttributes = (Attributes) $1;
2462 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2463 lexer.putback ('}');
2470 ENUM type_declaration_name
2474 enumTypeComment = Lexer.consume_doc_comment ();
2479 Lexer.doc_state = XmlCommentState.Allowed;
2481 MemberName name = (MemberName) $4;
2482 if (name.IsGeneric) {
2483 report.Error (1675, name.Location, "Enums cannot have type parameters");
2486 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2488 opt_enum_member_declarations
2490 // here will be evaluated after CLOSE_BLACE is consumed.
2492 Lexer.doc_state = XmlCommentState.Allowed;
2494 CLOSE_BRACE opt_semicolon
2497 current_container.DocComment = enumTypeComment;
2499 --lexer.parsing_declaration;
2502 // em.DocComment = ev.DocComment;
2504 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2505 $$ = pop_current_class ();
2513 var te = $2 as TypeExpression;
2514 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2515 Enum.Error_1008 (GetLocation ($2), report);
2521 Error_TypeExpected (GetLocation ($1));
2526 opt_enum_member_declarations
2528 | enum_member_declarations
2529 | enum_member_declarations COMMA
2531 lbag.AddLocation ($1, GetLocation ($2));
2535 enum_member_declarations
2536 : enum_member_declaration
2537 | enum_member_declarations COMMA enum_member_declaration
2539 lbag.AddLocation ($1, GetLocation ($2));
2544 enum_member_declaration
2545 : opt_attributes IDENTIFIER
2547 var lt = (Tokenizer.LocatedToken) $2;
2548 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2549 ((Enum) current_type).AddEnumMember (em);
2552 em.DocComment = Lexer.consume_doc_comment ();
2553 Lexer.doc_state = XmlCommentState.Allowed;
2558 | opt_attributes IDENTIFIER
2560 ++lexer.parsing_block;
2562 tmpComment = Lexer.consume_doc_comment ();
2563 Lexer.doc_state = XmlCommentState.NotAllowed;
2566 ASSIGN constant_expression
2568 --lexer.parsing_block;
2570 var lt = (Tokenizer.LocatedToken) $2;
2571 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2572 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2573 ((Enum) current_type).AddEnumMember (em);
2576 em.DocComment = ConsumeStoredComment ();
2582 delegate_declaration
2586 member_type type_declaration_name
2589 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2591 opt_formal_parameter_list CLOSE_PARENS
2593 valid_param_mod = 0;
2595 ParametersCompiled p = (ParametersCompiled) $8;
2597 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2599 p.CheckParameters (del);
2601 current_container.AddTypeContainer (del);
2603 current_delegate = del;
2604 lexer.ConstraintsParsing = true;
2606 opt_type_parameter_constraints_clauses
2608 lexer.ConstraintsParsing = false;
2613 current_delegate.DocComment = Lexer.consume_doc_comment ();
2614 Lexer.doc_state = XmlCommentState.Allowed;
2618 current_delegate.SetConstraints ((List<Constraints>) $11);
2619 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2621 $$ = current_delegate;
2623 current_delegate = null;
2631 if (lang_version < LanguageVersion.ISO_2)
2632 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2634 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2638 namespace_or_type_expr
2640 | qualified_alias_member IDENTIFIER opt_type_argument_list
2642 var lt1 = (Tokenizer.LocatedToken) $1;
2643 var lt2 = (Tokenizer.LocatedToken) $2;
2645 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2646 lbag.AddLocation ($$, GetLocation ($2));
2652 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2654 var lt = (Tokenizer.LocatedToken) $3;
2655 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2656 lbag.AddLocation ($$, GetLocation ($2));
2661 : IDENTIFIER opt_type_argument_list
2663 var lt = (Tokenizer.LocatedToken) $1;
2664 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2669 // Generics arguments (any type, without attributes)
2671 opt_type_argument_list
2673 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2675 if (lang_version < LanguageVersion.ISO_2)
2676 FeatureIsNotAvailable (GetLocation ($1), "generics");
2680 | OP_GENERICS_LT error
2682 Error_TypeExpected (lexer.Location);
2683 $$ = new TypeArguments ();
2690 TypeArguments type_args = new TypeArguments ();
2691 type_args.Add ((FullNamedExpression) $1);
2694 | type_arguments COMMA type
2696 TypeArguments type_args = (TypeArguments) $1;
2697 type_args.Add ((FullNamedExpression) $3);
2703 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2705 type_declaration_name
2708 lexer.parsing_generic_declaration = true;
2710 opt_type_parameter_list
2712 lexer.parsing_generic_declaration = false;
2713 var lt = (Tokenizer.LocatedToken) $1;
2714 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2718 member_declaration_name
2719 : method_declaration_name
2721 MemberName mn = (MemberName)$1;
2722 if (mn.TypeParameters != null)
2723 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2724 mn.GetSignatureForError ()));
2728 method_declaration_name
2729 : type_declaration_name
2730 | explicit_interface IDENTIFIER opt_type_parameter_list
2732 lexer.parsing_generic_declaration = false;
2733 var lt = (Tokenizer.LocatedToken) $2;
2734 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2738 indexer_declaration_name
2741 lexer.parsing_generic_declaration = false;
2742 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2744 | explicit_interface THIS
2746 lexer.parsing_generic_declaration = false;
2747 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2752 : IDENTIFIER opt_type_argument_list DOT
2754 var lt = (Tokenizer.LocatedToken) $1;
2755 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2756 lbag.AddLocation ($$, GetLocation ($3));
2758 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2760 var lt1 = (Tokenizer.LocatedToken) $1;
2761 var lt2 = (Tokenizer.LocatedToken) $2;
2763 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2764 lbag.AddLocation ($$, GetLocation ($4));
2766 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2768 var lt = (Tokenizer.LocatedToken) $2;
2769 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2770 lbag.AddLocation ($$, GetLocation ($4));
2774 opt_type_parameter_list
2776 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2778 if (lang_version < LanguageVersion.ISO_2)
2779 FeatureIsNotAvailable (GetLocation ($1), "generics");
2782 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2789 var tparams = new TypeParameters ();
2790 tparams.Add ((TypeParameter)$1);
2793 | type_parameters COMMA type_parameter
2795 var tparams = (TypeParameters) $1;
2796 tparams.Add ((TypeParameter)$3);
2798 lbag.AddLocation ($3, GetLocation ($3));
2803 : opt_attributes opt_type_parameter_variance IDENTIFIER
2805 var lt = (Tokenizer.LocatedToken)$3;
2806 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2810 if (GetTokenName (yyToken) == "type")
2811 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2813 Error_SyntaxError (yyToken);
2815 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2820 // All types where void is allowed
2823 : type_expression_or_array
2826 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2833 lexer.parsing_generic_declaration = true;
2838 // A type which does not allow `void' to be used
2841 : type_expression_or_array
2844 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2845 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2853 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2854 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2859 : type_expression_or_array
2862 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2863 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2867 type_expression_or_array
2869 | type_expression rank_specifiers
2871 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2876 : namespace_or_type_expr opt_nullable
2879 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2881 var sn = $1 as SimpleName;
2882 if (sn != null && sn.Name == "var")
2883 $$ = new VarExpr (sn.Location);
2888 | namespace_or_type_expr pointer_stars
2890 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2892 | builtin_types opt_nullable
2895 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2897 | builtin_types pointer_stars
2899 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2901 | VOID pointer_stars
2903 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2910 var types = new List<FullNamedExpression> (2);
2911 types.Add ((FullNamedExpression) $1);
2914 | type_list COMMA base_type_name
2916 var types = (List<FullNamedExpression>) $1;
2917 types.Add ((FullNamedExpression) $3);
2925 if ($1 is ComposedCast) {
2926 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2933 * replaces all the productions for isolating the various
2934 * simple types, but we need this to reuse it easily in variable_type
2937 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2938 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2939 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2940 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2941 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2942 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2947 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2948 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2949 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2950 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2951 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2952 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2953 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2954 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2955 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2959 // Expressions, section 7.5
2964 : primary_expression_or_type
2966 | array_creation_expression
2967 | parenthesized_expression
2968 | default_value_expression
2969 | invocation_expression
2973 | post_increment_expression
2974 | post_decrement_expression
2975 | object_or_delegate_creation_expression
2976 | anonymous_type_expression
2979 | checked_expression
2980 | unchecked_expression
2981 | pointer_member_access
2982 | anonymous_method_expression
2983 | undocumented_expressions
2986 primary_expression_or_type
2987 : IDENTIFIER opt_type_argument_list
2989 var lt = (Tokenizer.LocatedToken) $1;
2990 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2992 | IDENTIFIER GENERATE_COMPLETION {
2993 var lt = (Tokenizer.LocatedToken) $1;
2994 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3002 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3006 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3007 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3012 // Here is the trick, tokenizer may think that parens is a special but
3013 // parser is interested in open parens only, so we merge them.
3014 // Consider: if (a)foo ();
3022 // Use this production to accept closing parenthesis or
3023 // performing completion
3027 | COMPLETE_COMPLETION
3031 parenthesized_expression
3032 : OPEN_PARENS expression CLOSE_PARENS
3034 $$ = new ParenthesizedExpression ((Expression) $2);
3035 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3037 | OPEN_PARENS expression COMPLETE_COMPLETION
3039 $$ = new ParenthesizedExpression ((Expression) $2);
3044 : primary_expression DOT IDENTIFIER opt_type_argument_list
3046 var lt = (Tokenizer.LocatedToken) $3;
3047 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3048 lbag.AddLocation ($$, GetLocation ($2));
3050 | builtin_types DOT IDENTIFIER opt_type_argument_list
3052 var lt = (Tokenizer.LocatedToken) $3;
3053 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3054 lbag.AddLocation ($$, GetLocation ($2));
3056 | BASE DOT IDENTIFIER opt_type_argument_list
3058 var lt = (Tokenizer.LocatedToken) $3;
3059 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3060 lbag.AddLocation ($$, GetLocation ($2));
3062 | qualified_alias_member IDENTIFIER opt_type_argument_list
3064 var lt1 = (Tokenizer.LocatedToken) $1;
3065 var lt2 = (Tokenizer.LocatedToken) $2;
3067 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3068 lbag.AddLocation ($$, GetLocation ($2));
3070 | primary_expression DOT GENERATE_COMPLETION {
3071 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3073 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3074 var lt = (Tokenizer.LocatedToken) $3;
3075 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3077 | builtin_types DOT GENERATE_COMPLETION
3079 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3081 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3082 var lt = (Tokenizer.LocatedToken) $3;
3083 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3087 invocation_expression
3088 : primary_expression open_parens_any opt_argument_list close_parens
3090 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3091 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3095 opt_object_or_collection_initializer
3096 : /* empty */ { $$ = null; }
3097 | object_or_collection_initializer
3100 object_or_collection_initializer
3101 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3104 $$ = CollectionOrObjectInitializers.Empty;
3107 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3108 lbag.AddLocation ($$, GetLocation ($3));
3111 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3113 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3114 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3118 opt_member_initializer_list
3119 : /* empty */ { $$ = null; }
3120 | member_initializer_list
3126 member_initializer_list
3127 : member_initializer
3129 var a = new List<Expression> ();
3130 a.Add ((Expression) $1);
3133 | member_initializer_list COMMA member_initializer
3135 var a = (List<Expression>)$1;
3136 a.Add ((Expression) $3);
3139 | member_initializer_list error {
3140 Error_SyntaxError (yyToken);
3146 : IDENTIFIER ASSIGN initializer_value
3148 var lt = (Tokenizer.LocatedToken) $1;
3149 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3150 lbag.AddLocation ($$, GetLocation ($2));
3152 | GENERATE_COMPLETION
3154 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3156 | non_assignment_expression opt_COMPLETE_COMPLETION {
3157 CompletionSimpleName csn = $1 as CompletionSimpleName;
3159 $$ = new CollectionElementInitializer ((Expression)$1);
3161 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3163 | OPEN_BRACE expression_list CLOSE_BRACE
3168 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3170 | OPEN_BRACE CLOSE_BRACE
3172 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3179 | object_or_collection_initializer
3183 : /* empty */ { $$ = null; }
3188 : argument_or_named_argument
3190 Arguments list = new Arguments (4);
3191 list.Add ((Argument) $1);
3194 | argument_list COMMA argument
3196 Arguments list = (Arguments) $1;
3197 if (list [list.Count - 1] is NamedArgument)
3198 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3200 list.Add ((Argument) $3);
3203 | argument_list COMMA named_argument
3205 Arguments list = (Arguments) $1;
3206 NamedArgument a = (NamedArgument) $3;
3207 for (int i = 0; i < list.Count; ++i) {
3208 NamedArgument na = list [i] as NamedArgument;
3209 if (na != null && na.Name == a.Name)
3210 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3217 | argument_list COMMA error
3219 lexer.putback (')'); // TODO: Wrong but what can I do
3220 Error_SyntaxError (yyToken);
3225 report.Error (839, GetLocation ($1), "An argument is missing");
3233 $$ = new Argument ((Expression) $1);
3235 | non_simple_argument
3238 argument_or_named_argument
3244 : REF variable_reference
3246 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3247 lbag.AddLocation ($$, GetLocation ($1));
3249 | OUT variable_reference
3251 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3252 lbag.AddLocation ($$, GetLocation ($1));
3254 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3256 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3257 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3259 | ARGLIST OPEN_PARENS CLOSE_PARENS
3261 $$ = new Argument (new Arglist (GetLocation ($1)));
3262 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3271 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3273 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3274 lbag.AddLocation ($$, GetLocation ($4));
3276 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3278 Error_SyntaxError (yyToken);
3279 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3281 | primary_expression OPEN_BRACKET_EXPR error
3283 Error_SyntaxError (yyToken);
3284 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3291 var list = new List<Expression> (4);
3292 list.Add ((Expression) $1);
3295 | expression_list COMMA expression
3297 var list = (List<Expression>) $1;
3298 list.Add ((Expression) $3);
3301 | expression_list error {
3302 Error_SyntaxError (yyToken);
3307 expression_list_arguments
3308 : expression_list_argument
3310 Arguments args = new Arguments (4);
3311 args.Add ((Argument) $1);
3314 | expression_list_arguments COMMA expression_list_argument
3316 Arguments args = (Arguments) $1;
3317 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3318 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3320 args.Add ((Argument) $3);
3325 expression_list_argument
3328 $$ = new Argument ((Expression) $1);
3336 $$ = new This (GetLocation ($1));
3341 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3343 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3344 lbag.AddLocation ($$, GetLocation ($4));
3346 | BASE OPEN_BRACKET error
3348 Error_SyntaxError (yyToken);
3349 $$ = new ElementAccess (null, null, GetLocation ($2));
3353 post_increment_expression
3354 : primary_expression OP_INC
3356 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3360 post_decrement_expression
3361 : primary_expression OP_DEC
3363 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3367 object_or_delegate_creation_expression
3368 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3371 if (lang_version <= LanguageVersion.ISO_2)
3372 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3374 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3376 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3379 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3381 | NEW new_expr_type object_or_collection_initializer
3383 if (lang_version <= LanguageVersion.ISO_2)
3384 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3386 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3390 array_creation_expression
3391 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3393 opt_array_initializer
3395 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3396 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3397 Next = (ComposedTypeSpecifier) $6
3398 }, (ArrayInitializer) $7, GetLocation ($1));
3399 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3401 | NEW new_expr_type rank_specifiers opt_array_initializer
3404 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3406 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3408 | NEW rank_specifier array_initializer
3410 if (lang_version <= LanguageVersion.ISO_2)
3411 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3413 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3415 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3417 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3418 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3420 | NEW new_expr_type error
3422 Error_SyntaxError (yyToken);
3423 // It can be any of new expression, create the most common one
3424 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3430 ++lexer.parsing_type;
3434 --lexer.parsing_type;
3439 anonymous_type_expression
3440 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3442 if (lang_version <= LanguageVersion.ISO_2)
3443 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3445 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3447 // TODO: lbag comma location
3448 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3452 anonymous_type_parameters_opt_comma
3453 : anonymous_type_parameters_opt
3454 | anonymous_type_parameters COMMA
3457 anonymous_type_parameters_opt
3459 | anonymous_type_parameters
3462 anonymous_type_parameters
3463 : anonymous_type_parameter
3465 var a = new List<AnonymousTypeParameter> (4);
3466 a.Add ((AnonymousTypeParameter) $1);
3469 | anonymous_type_parameters COMMA anonymous_type_parameter
3471 var a = (List<AnonymousTypeParameter>) $1;
3472 a.Add ((AnonymousTypeParameter) $3);
3477 anonymous_type_parameter
3478 : IDENTIFIER ASSIGN variable_initializer
3480 var lt = (Tokenizer.LocatedToken)$1;
3481 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3482 lbag.AddLocation ($$, GetLocation ($2));
3486 var lt = (Tokenizer.LocatedToken)$1;
3487 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3488 lt.Value, lt.Location);
3492 MemberAccess ma = (MemberAccess) $1;
3493 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3497 report.Error (746, lexer.Location,
3498 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3510 | rank_specifier rank_specifiers
3512 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3518 : OPEN_BRACKET CLOSE_BRACKET
3520 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3521 lbag.AddLocation ($$, GetLocation ($2));
3523 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3525 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3526 lbag.AddLocation ($$, GetLocation ($3));
3535 | dim_separators COMMA
3537 $$ = ((int) $1) + 1;
3541 opt_array_initializer
3553 : OPEN_BRACE CLOSE_BRACE
3555 var ai = new ArrayInitializer (0, GetLocation ($1));
3556 ai.VariableDeclaration = current_variable;
3557 lbag.AddLocation (ai, GetLocation ($2));
3560 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3562 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3563 ai.VariableDeclaration = current_variable;
3565 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3567 lbag.AddLocation (ai, GetLocation ($4));
3573 variable_initializer_list
3574 : variable_initializer
3576 var list = new List<Expression> (4);
3577 list.Add ((Expression) $1);
3580 | variable_initializer_list COMMA variable_initializer
3582 var list = (List<Expression>) $1;
3583 list.Add ((Expression) $3);
3591 lexer.TypeOfParsing = true;
3593 open_parens_any typeof_type_expression CLOSE_PARENS
3595 lexer.TypeOfParsing = false;
3596 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3597 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3601 typeof_type_expression
3606 Error_TypeExpected (lexer.Location);
3612 : identifier_inside_body generic_dimension
3614 var lt = (Tokenizer.LocatedToken) $1;
3616 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3618 | qualified_alias_member identifier_inside_body generic_dimension
3620 var lt1 = (Tokenizer.LocatedToken) $1;
3621 var lt2 = (Tokenizer.LocatedToken) $2;
3623 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3624 lbag.AddLocation ($$, GetLocation ($2));
3626 | unbound_type_name DOT identifier_inside_body
3628 var lt = (Tokenizer.LocatedToken) $3;
3630 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3632 | unbound_type_name DOT identifier_inside_body generic_dimension
3634 var lt = (Tokenizer.LocatedToken) $3;
3636 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3638 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3640 var tne = (ATypeNameExpression) $1;
3641 if (tne.HasTypeArguments)
3642 Error_TypeExpected (GetLocation ($4));
3644 var lt = (Tokenizer.LocatedToken) $3;
3645 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3652 if (lang_version < LanguageVersion.ISO_2)
3653 FeatureIsNotAvailable (GetLocation ($1), "generics");
3659 qualified_alias_member
3660 : IDENTIFIER DOUBLE_COLON
3662 var lt = (Tokenizer.LocatedToken) $1;
3663 if (lang_version == LanguageVersion.ISO_1)
3664 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3671 : SIZEOF open_parens_any type CLOSE_PARENS
3673 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3674 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3679 : CHECKED open_parens_any expression CLOSE_PARENS
3681 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3682 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3686 unchecked_expression
3687 : UNCHECKED open_parens_any expression CLOSE_PARENS
3689 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3690 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3694 pointer_member_access
3695 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3697 var lt = (Tokenizer.LocatedToken) $3;
3698 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3702 anonymous_method_expression
3703 : DELEGATE opt_anonymous_method_signature
3705 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3709 $$ = end_anonymous ((ParametersBlock) $4);
3711 | ASYNC DELEGATE opt_anonymous_method_signature
3713 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3717 $$ = end_anonymous ((ParametersBlock) $5);
3721 opt_anonymous_method_signature
3724 $$ = ParametersCompiled.Undefined;
3726 | anonymous_method_signature
3729 anonymous_method_signature
3732 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3734 opt_formal_parameter_list CLOSE_PARENS
3736 valid_param_mod = 0;
3741 default_value_expression
3742 : DEFAULT open_parens_any type CLOSE_PARENS
3744 if (lang_version < LanguageVersion.ISO_2)
3745 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3747 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3748 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3753 : primary_expression
3754 | BANG prefixed_unary_expression
3756 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3758 | TILDE prefixed_unary_expression
3760 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3762 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3764 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3765 lbag.AddLocation ($$, GetLocation ($3));
3767 | AWAIT prefixed_unary_expression
3770 if (current_anonymous_method is LambdaExpression) {
3771 report.Error (4034, GetLocation ($1),
3772 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3773 } else if (current_anonymous_method is AnonymousMethodExpression) {
3774 report.Error (4035, GetLocation ($1),
3775 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3777 report.Error (4033, GetLocation ($1),
3778 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3781 current_block.Explicit.RegisterAsyncAwait ();
3784 $$ = new Await ((Expression) $2, GetLocation ($1));
3789 // The idea to split this out is from Rhys' grammar
3790 // to solve the problem with casts.
3792 prefixed_unary_expression
3794 | PLUS prefixed_unary_expression
3796 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3798 | MINUS prefixed_unary_expression
3800 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3802 | OP_INC prefixed_unary_expression
3804 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3806 | OP_DEC prefixed_unary_expression
3808 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3810 | STAR prefixed_unary_expression
3812 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3814 | BITWISE_AND prefixed_unary_expression
3816 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3820 multiplicative_expression
3821 : prefixed_unary_expression
3822 | multiplicative_expression STAR prefixed_unary_expression
3824 $$ = new Binary (Binary.Operator.Multiply,
3825 (Expression) $1, (Expression) $3, GetLocation ($2));
3827 | multiplicative_expression DIV prefixed_unary_expression
3829 $$ = new Binary (Binary.Operator.Division,
3830 (Expression) $1, (Expression) $3, GetLocation ($2));
3832 | multiplicative_expression PERCENT prefixed_unary_expression
3834 $$ = new Binary (Binary.Operator.Modulus,
3835 (Expression) $1, (Expression) $3, GetLocation ($2));
3840 : multiplicative_expression
3841 | additive_expression PLUS multiplicative_expression
3843 $$ = new Binary (Binary.Operator.Addition,
3844 (Expression) $1, (Expression) $3, GetLocation ($2));
3846 | additive_expression MINUS multiplicative_expression
3848 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3850 | parenthesized_expression MINUS multiplicative_expression
3852 // Shift/Reduce conflict
3853 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3855 | additive_expression AS type
3857 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3859 | additive_expression IS type
3861 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3866 : additive_expression
3867 | shift_expression OP_SHIFT_LEFT additive_expression
3869 $$ = new Binary (Binary.Operator.LeftShift,
3870 (Expression) $1, (Expression) $3, GetLocation ($2));
3872 | shift_expression OP_SHIFT_RIGHT additive_expression
3874 $$ = new Binary (Binary.Operator.RightShift,
3875 (Expression) $1, (Expression) $3, GetLocation ($2));
3879 relational_expression
3881 | relational_expression OP_LT shift_expression
3883 $$ = new Binary (Binary.Operator.LessThan,
3884 (Expression) $1, (Expression) $3, GetLocation ($2));
3886 | relational_expression OP_GT shift_expression
3888 $$ = new Binary (Binary.Operator.GreaterThan,
3889 (Expression) $1, (Expression) $3, GetLocation ($2));
3891 | relational_expression OP_LE shift_expression
3893 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3894 (Expression) $1, (Expression) $3, GetLocation ($2));
3896 | relational_expression OP_GE shift_expression
3898 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3899 (Expression) $1, (Expression) $3, GetLocation ($2));
3904 : relational_expression
3905 | equality_expression OP_EQ relational_expression
3907 $$ = new Binary (Binary.Operator.Equality,
3908 (Expression) $1, (Expression) $3, GetLocation ($2));
3910 | equality_expression OP_NE relational_expression
3912 $$ = new Binary (Binary.Operator.Inequality,
3913 (Expression) $1, (Expression) $3, GetLocation ($2));
3918 : equality_expression
3919 | and_expression BITWISE_AND equality_expression
3921 $$ = new Binary (Binary.Operator.BitwiseAnd,
3922 (Expression) $1, (Expression) $3, GetLocation ($2));
3926 exclusive_or_expression
3928 | exclusive_or_expression CARRET and_expression
3930 $$ = new Binary (Binary.Operator.ExclusiveOr,
3931 (Expression) $1, (Expression) $3, GetLocation ($2));
3935 inclusive_or_expression
3936 : exclusive_or_expression
3937 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3939 $$ = new Binary (Binary.Operator.BitwiseOr,
3940 (Expression) $1, (Expression) $3, GetLocation ($2));
3944 conditional_and_expression
3945 : inclusive_or_expression
3946 | conditional_and_expression OP_AND inclusive_or_expression
3948 $$ = new Binary (Binary.Operator.LogicalAnd,
3949 (Expression) $1, (Expression) $3, GetLocation ($2));
3953 conditional_or_expression
3954 : conditional_and_expression
3955 | conditional_or_expression OP_OR conditional_and_expression
3957 $$ = new Binary (Binary.Operator.LogicalOr,
3958 (Expression) $1, (Expression) $3, GetLocation ($2));
3962 null_coalescing_expression
3963 : conditional_or_expression
3964 | conditional_or_expression OP_COALESCING null_coalescing_expression
3966 if (lang_version < LanguageVersion.ISO_2)
3967 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3969 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3973 conditional_expression
3974 : null_coalescing_expression
3975 | null_coalescing_expression INTERR expression COLON expression_or_error
3977 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3978 lbag.AddLocation ($$, GetLocation ($4));
3980 | null_coalescing_expression INTERR expression error
3982 Error_SyntaxError (yyToken);
3983 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
3987 assignment_expression
3988 : prefixed_unary_expression ASSIGN expression
3990 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3992 | prefixed_unary_expression OP_MULT_ASSIGN expression
3994 $$ = new CompoundAssign (
3995 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3997 | prefixed_unary_expression OP_DIV_ASSIGN expression
3999 $$ = new CompoundAssign (
4000 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
4002 | prefixed_unary_expression OP_MOD_ASSIGN expression
4004 $$ = new CompoundAssign (
4005 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
4007 | prefixed_unary_expression OP_ADD_ASSIGN expression
4009 $$ = new CompoundAssign (
4010 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
4012 | prefixed_unary_expression OP_SUB_ASSIGN expression
4014 $$ = new CompoundAssign (
4015 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4017 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4019 $$ = new CompoundAssign (
4020 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4022 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4024 $$ = new CompoundAssign (
4025 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4027 | prefixed_unary_expression OP_AND_ASSIGN expression
4029 $$ = new CompoundAssign (
4030 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4032 | prefixed_unary_expression OP_OR_ASSIGN expression
4034 $$ = new CompoundAssign (
4035 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4037 | prefixed_unary_expression OP_XOR_ASSIGN expression
4039 $$ = new CompoundAssign (
4040 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4044 lambda_parameter_list
4047 var pars = new List<Parameter> (4);
4048 pars.Add ((Parameter) $1);
4052 | lambda_parameter_list COMMA lambda_parameter
4054 var pars = (List<Parameter>) $1;
4055 Parameter p = (Parameter)$3;
4056 if (pars[0].GetType () != p.GetType ()) {
4057 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4066 : parameter_modifier parameter_type identifier_inside_body
4068 var lt = (Tokenizer.LocatedToken) $3;
4070 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4072 | parameter_type identifier_inside_body
4074 var lt = (Tokenizer.LocatedToken) $2;
4076 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4080 var lt = (Tokenizer.LocatedToken) $1;
4081 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4085 opt_lambda_parameter_list
4086 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4087 | lambda_parameter_list {
4088 var pars_list = (List<Parameter>) $1;
4089 $$ = new ParametersCompiled (pars_list.ToArray ());
4093 lambda_expression_body
4094 : lambda_expression_body_simple
4098 lambda_expression_body_simple
4100 start_block (Location.Null);
4102 expression_or_error // Have to close block when error occurs
4104 Block b = end_block (Location.Null);
4105 b.IsCompilerGenerated = true;
4106 b.AddStatement (new ContextualReturn ((Expression) $2));
4115 Error_SyntaxError (yyToken);
4116 $$ = EmptyExpression.Null;
4123 var lt = (Tokenizer.LocatedToken) $1;
4124 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4125 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4127 lambda_expression_body
4129 $$ = end_anonymous ((ParametersBlock) $4);
4130 lbag.AddLocation ($$, GetLocation ($2));
4132 | ASYNC identifier_inside_body ARROW
4134 var lt = (Tokenizer.LocatedToken) $2;
4135 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4136 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4138 lambda_expression_body
4140 $$ = end_anonymous ((ParametersBlock) $5);
4141 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4143 | OPEN_PARENS_LAMBDA
4145 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4147 opt_lambda_parameter_list CLOSE_PARENS ARROW
4149 valid_param_mod = 0;
4150 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4152 lambda_expression_body
4154 $$ = end_anonymous ((ParametersBlock) $7);
4155 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4157 | ASYNC OPEN_PARENS_LAMBDA
4159 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4161 opt_lambda_parameter_list CLOSE_PARENS ARROW
4163 valid_param_mod = 0;
4164 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4166 lambda_expression_body
4168 $$ = end_anonymous ((ParametersBlock) $8);
4169 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4174 : assignment_expression
4175 | non_assignment_expression
4178 non_assignment_expression
4179 : conditional_expression
4184 $$ = new ArglistAccess (GetLocation ($1));
4188 undocumented_expressions
4189 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4191 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4192 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4194 | REFTYPE open_parens_any expression CLOSE_PARENS
4196 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4197 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4199 | MAKEREF open_parens_any expression CLOSE_PARENS
4201 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4202 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4213 $$ = new BooleanExpression ((Expression) $1);
4226 lexer.ConstraintsParsing = true;
4228 type_declaration_name
4230 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4231 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4232 FeatureIsNotAvailable (c.Location, "static classes");
4235 push_current_container (c, $3);
4238 opt_type_parameter_constraints_clauses
4240 lexer.ConstraintsParsing = false;
4243 current_container.SetConstraints ((List<Constraints>) $9);
4244 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4247 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4248 Lexer.doc_state = XmlCommentState.Allowed;
4251 lexer.parsing_modifiers = true;
4253 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4255 --lexer.parsing_declaration;
4257 Lexer.doc_state = XmlCommentState.Allowed;
4261 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4262 $$ = pop_current_class ();
4270 { $$ = $1; } // location
4276 mod_locations = null;
4278 lexer.parsing_modifiers = false;
4282 lexer.parsing_modifiers = false;
4288 | modifiers modifier
4290 var m1 = (Modifiers) $1;
4291 var m2 = (Modifiers) $2;
4293 if ((m1 & m2) != 0) {
4294 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4295 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4296 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4297 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4298 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4299 "More than one protection modifier specified");
4310 StoreModifierLocation ($$, GetLocation ($1));
4312 if (current_container.Kind == MemberKind.Namespace)
4313 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4317 $$ = Modifiers.PUBLIC;
4318 StoreModifierLocation ($$, GetLocation ($1));
4322 $$ = Modifiers.PROTECTED;
4323 StoreModifierLocation ($$, GetLocation ($1));
4327 $$ = Modifiers.INTERNAL;
4328 StoreModifierLocation ($$, GetLocation ($1));
4332 $$ = Modifiers.PRIVATE;
4333 StoreModifierLocation ($$, GetLocation ($1));
4337 $$ = Modifiers.ABSTRACT;
4338 StoreModifierLocation ($$, GetLocation ($1));
4342 $$ = Modifiers.SEALED;
4343 StoreModifierLocation ($$, GetLocation ($1));
4347 $$ = Modifiers.STATIC;
4348 StoreModifierLocation ($$, GetLocation ($1));
4352 $$ = Modifiers.READONLY;
4353 StoreModifierLocation ($$, GetLocation ($1));
4357 $$ = Modifiers.VIRTUAL;
4358 StoreModifierLocation ($$, GetLocation ($1));
4362 $$ = Modifiers.OVERRIDE;
4363 StoreModifierLocation ($$, GetLocation ($1));
4367 $$ = Modifiers.EXTERN;
4368 StoreModifierLocation ($$, GetLocation ($1));
4372 $$ = Modifiers.VOLATILE;
4373 StoreModifierLocation ($$, GetLocation ($1));
4377 $$ = Modifiers.UNSAFE;
4378 StoreModifierLocation ($$, GetLocation ($1));
4379 if (!settings.Unsafe)
4380 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4384 $$ = Modifiers.ASYNC;
4385 StoreModifierLocation ($$, GetLocation ($1));
4393 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4395 | COLON type_list error
4397 Error_SyntaxError (yyToken);
4399 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4403 opt_type_parameter_constraints_clauses
4405 | type_parameter_constraints_clauses
4411 type_parameter_constraints_clauses
4412 : type_parameter_constraints_clause
4414 var constraints = new List<Constraints> (1);
4415 constraints.Add ((Constraints) $1);
4418 | type_parameter_constraints_clauses type_parameter_constraints_clause
4420 var constraints = (List<Constraints>) $1;
4421 Constraints new_constraint = (Constraints)$2;
4423 foreach (Constraints c in constraints) {
4424 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4425 report.Error (409, new_constraint.Location,
4426 "A constraint clause has already been specified for type parameter `{0}'",
4427 new_constraint.TypeParameter.Value);
4431 constraints.Add (new_constraint);
4436 type_parameter_constraints_clause
4437 : WHERE IDENTIFIER COLON type_parameter_constraints
4439 var lt = (Tokenizer.LocatedToken) $2;
4440 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4441 lbag.AddLocation ($$, GetLocation ($3));
4443 | WHERE IDENTIFIER error
4445 Error_SyntaxError (yyToken);
4447 var lt = (Tokenizer.LocatedToken) $2;
4448 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4452 type_parameter_constraints
4453 : type_parameter_constraint
4455 var constraints = new List<FullNamedExpression> (1);
4456 constraints.Add ((FullNamedExpression) $1);
4459 | type_parameter_constraints COMMA type_parameter_constraint
4461 var constraints = (List<FullNamedExpression>) $1;
4462 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4463 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4464 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4467 prev = $3 as SpecialContraintExpr;
4469 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4470 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4472 prev = constraints [0] as SpecialContraintExpr;
4473 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4474 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4479 constraints.Add ((FullNamedExpression) $3);
4484 type_parameter_constraint
4487 if ($1 is ComposedCast)
4488 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4492 | NEW OPEN_PARENS CLOSE_PARENS
4494 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4495 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4499 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4503 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4507 opt_type_parameter_variance
4512 | type_parameter_variance
4514 if (lang_version <= LanguageVersion.V_3)
4515 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4521 type_parameter_variance
4524 $$ = Variance.Covariant;
4528 $$ = Variance.Contravariant;
4537 // A block is "contained" on the following places:
4539 // property_declaration as part of the accessor body (get/set)
4540 // operator_declaration
4541 // constructor_declaration
4542 // destructor_declaration
4543 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4548 ++lexer.parsing_block;
4549 start_block (GetLocation ($1));
4551 opt_statement_list block_end
4560 --lexer.parsing_block;
4561 $$ = end_block (GetLocation ($1));
4563 | COMPLETE_COMPLETION
4565 --lexer.parsing_block;
4566 $$ = end_block (lexer.Location);
4574 ++lexer.parsing_block;
4575 current_block.StartLocation = GetLocation ($1);
4577 opt_statement_list CLOSE_BRACE
4579 --lexer.parsing_block;
4580 $$ = end_block (GetLocation ($4));
4591 | statement_list statement
4595 : block_variable_declaration
4597 current_block.AddStatement ((Statement) $1);
4599 | valid_declaration_statement
4601 current_block.AddStatement ((Statement) $1);
4606 Error_SyntaxError (yyToken);
4612 // The interactive_statement and its derivatives are only
4613 // used to provide a special version of `expression_statement'
4614 // that has a side effect of assigning the expression to
4617 interactive_statement_list
4618 : interactive_statement
4619 | interactive_statement_list interactive_statement
4622 interactive_statement
4623 : block_variable_declaration
4625 current_block.AddStatement ((Statement) $1);
4627 | interactive_valid_declaration_statement
4629 current_block.AddStatement ((Statement) $1);
4634 valid_declaration_statement
4637 | expression_statement
4638 | selection_statement
4639 | iteration_statement
4643 | unchecked_statement
4650 interactive_valid_declaration_statement
4653 | interactive_expression_statement
4654 | selection_statement
4655 | iteration_statement
4659 | unchecked_statement
4667 : valid_declaration_statement
4668 | block_variable_declaration
4670 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4675 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4680 Error_SyntaxError (yyToken);
4681 $$ = new EmptyStatement (GetLocation ($1));
4688 // Uses lexer.Location because semicolon location is not kept in quick mode
4689 $$ = new EmptyStatement (lexer.Location);
4694 : identifier_inside_body COLON
4696 var lt = (Tokenizer.LocatedToken) $1;
4697 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4698 lbag.AddLocation (labeled, GetLocation ($2));
4699 current_block.AddLabel (labeled);
4700 current_block.AddStatement (labeled);
4706 : variable_type_simple
4707 | variable_type_simple rank_specifiers
4710 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4712 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4717 * The following is from Rhys' grammar:
4718 * > Types in local variable declarations must be recognized as
4719 * > expressions to prevent reduce/reduce errors in the grammar.
4720 * > The expressions are converted into types during semantic analysis.
4722 variable_type_simple
4723 : primary_expression_or_type opt_nullable
4725 // Ok, the above "primary_expression" is there to get rid of
4726 // both reduce/reduce and shift/reduces in the grammar, it should
4727 // really just be "type_name". If you use type_name, a reduce/reduce
4728 // creeps up. If you use namespace_or_type_name (which is all we need
4729 // really) two shift/reduces appear.
4732 // So the super-trick is that primary_expression
4733 // can only be either a SimpleName or a MemberAccess.
4734 // The MemberAccess case arises when you have a fully qualified type-name like :
4736 // SimpleName is when you have
4739 Expression expr = (Expression) $1;
4741 SimpleName sn = expr as SimpleName;
4742 if (sn != null && sn.Name == "var")
4743 $$ = new VarExpr (sn.Location);
4746 } else if (expr is ATypeNameExpression) {
4747 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4749 Error_ExpectingTypeName (expr);
4753 | primary_expression_or_type pointer_stars
4755 ATypeNameExpression expr = $1 as ATypeNameExpression;
4758 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4760 Error_ExpectingTypeName ((Expression)$1);
4764 | builtin_types opt_nullable
4769 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4771 | builtin_types pointer_stars
4773 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4775 | VOID pointer_stars
4777 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4781 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4782 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4788 | pointer_star pointer_stars
4790 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4798 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4802 identifier_inside_body
4807 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
4808 $$ = Tokenizer.LocatedToken.Create ("await", GetLocation ($1));
4813 block_variable_declaration
4814 : variable_type identifier_inside_body
4816 var lt = (Tokenizer.LocatedToken) $2;
4817 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4818 current_block.AddLocalName (li);
4819 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4821 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4823 $$ = current_variable;
4824 current_variable = null;
4825 lbag.AddLocation ($$, GetLocation ($6));
4827 | CONST variable_type identifier_inside_body
4829 var lt = (Tokenizer.LocatedToken) $3;
4830 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4831 current_block.AddLocalName (li);
4832 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4834 const_variable_initializer opt_const_declarators SEMICOLON
4836 $$ = current_variable;
4837 current_variable = null;
4838 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4842 opt_local_variable_initializer
4844 | ASSIGN block_variable_initializer
4846 current_variable.Initializer = (Expression) $2;
4851 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4852 report.Error (650, lexer.Location,
4853 "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");
4855 Error_SyntaxError (yyToken);
4860 opt_variable_declarators
4862 | variable_declarators
4865 opt_using_or_fixed_variable_declarators
4867 | variable_declarators
4869 foreach (var d in current_variable.Declarators) {
4870 if (d.Initializer == null)
4871 Error_MissingInitializer (d.Variable.Location);
4876 variable_declarators
4877 : variable_declarator
4878 | variable_declarators variable_declarator
4882 : COMMA identifier_inside_body
4884 var lt = (Tokenizer.LocatedToken) $2;
4885 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4886 var d = new BlockVariableDeclaration.Declarator (li, null);
4887 current_variable.AddDeclarator (d);
4888 current_block.AddLocalName (li);
4889 lbag.AddLocation (d, GetLocation ($1));
4891 | COMMA identifier_inside_body ASSIGN block_variable_initializer
4893 var lt = (Tokenizer.LocatedToken) $2;
4894 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4895 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4896 current_variable.AddDeclarator (d);
4897 current_block.AddLocalName (li);
4898 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4902 const_variable_initializer
4905 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4907 | ASSIGN constant_initializer_expr
4909 current_variable.Initializer = (Expression) $2;
4913 opt_const_declarators
4920 | const_declarators const_declarator
4924 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
4926 var lt = (Tokenizer.LocatedToken) $2;
4927 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4928 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4929 current_variable.AddDeclarator (d);
4930 current_block.AddLocalName (li);
4931 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4935 block_variable_initializer
4936 : variable_initializer
4937 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4939 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4940 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4942 | STACKALLOC simple_type
4944 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4945 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4949 expression_statement
4950 : statement_expression SEMICOLON
4953 lbag.AddStatement ($$, GetLocation ($2));
4955 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4956 | statement_expression CLOSE_BRACE
4959 report.Error (1002, GetLocation ($2), "; expected");
4960 lexer.putback ('}');
4964 interactive_expression_statement
4965 : interactive_statement_expression SEMICOLON { $$ = $1; }
4966 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4970 // We have to do the wrapping here and not in the case above,
4971 // because statement_expression is used for example in for_statement
4973 statement_expression
4976 ExpressionStatement s = $1 as ExpressionStatement;
4978 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4979 $$ = new StatementErrorExpression ($1 as Expression);
4981 $$ = new StatementExpression (s);
4986 interactive_statement_expression
4989 Expression expr = (Expression) $1;
4990 ExpressionStatement s;
4992 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4993 $$ = new StatementExpression (s);
4997 Error_SyntaxError (yyToken);
4998 $$ = new EmptyStatement (GetLocation ($1));
5008 : IF open_parens_any boolean_expression CLOSE_PARENS
5011 if ($5 is EmptyStatement)
5012 Warning_EmptyStatement (GetLocation ($5));
5014 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5015 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5017 | IF open_parens_any boolean_expression CLOSE_PARENS
5018 embedded_statement ELSE embedded_statement
5020 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5021 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5023 if ($5 is EmptyStatement)
5024 Warning_EmptyStatement (GetLocation ($5));
5025 if ($7 is EmptyStatement)
5026 Warning_EmptyStatement (GetLocation ($7));
5028 | IF open_parens_any boolean_expression error
5030 Error_SyntaxError (yyToken);
5032 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5033 lbag.AddStatement ($$, GetLocation ($2));
5038 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5040 start_block (GetLocation ($5));
5042 opt_switch_sections CLOSE_BRACE
5044 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5045 end_block (GetLocation ($8));
5046 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5048 | SWITCH open_parens_any expression error
5050 Error_SyntaxError (yyToken);
5052 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5053 lbag.AddStatement ($$, GetLocation ($2));
5060 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5061 $$ = new List<SwitchSection> ();
5069 var sections = new List<SwitchSection> (4);
5071 sections.Add ((SwitchSection) $1);
5074 | switch_sections switch_section
5076 var sections = (List<SwitchSection>) $1;
5078 sections.Add ((SwitchSection) $2);
5083 Error_SyntaxError (yyToken);
5084 $$ = new List<SwitchSection> ();
5091 current_block = current_block.CreateSwitchBlock (lexer.Location);
5095 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5102 var labels = new List<SwitchLabel> (2);
5104 labels.Add ((SwitchLabel) $1);
5107 | switch_labels switch_label
5109 var labels = (List<SwitchLabel>) ($1);
5110 labels.Add ((SwitchLabel) $2);
5117 : CASE constant_expression COLON
5119 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5120 lbag.AddLocation ($$, GetLocation ($3));
5122 | CASE constant_expression error
5124 Error_SyntaxError (yyToken);
5125 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5129 $$ = new SwitchLabel (null, GetLocation ($1));
5141 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5143 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5144 Warning_EmptyStatement (GetLocation ($5));
5146 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5147 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5149 | WHILE open_parens_any boolean_expression error
5151 Error_SyntaxError (yyToken);
5153 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5154 lbag.AddStatement ($$, GetLocation ($2));
5159 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5161 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5162 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5164 | DO embedded_statement error
5166 Error_SyntaxError (yyToken);
5167 $$ = new Do ((Statement) $2, null, GetLocation ($1));
5169 | DO embedded_statement WHILE open_parens_any boolean_expression error
5171 Error_SyntaxError (yyToken);
5173 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5174 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5179 : FOR open_parens_any
5181 start_block (GetLocation ($2));
5182 current_block.IsCompilerGenerated = true;
5183 For f = new For (GetLocation ($1));
5184 current_block.AddStatement (f);
5193 // Has to use be extra rule to recover started block
5195 : opt_for_initializer SEMICOLON
5197 ((For) $0).Initializer = (Statement) $1;
5199 // Pass the "For" object to the iterator_part4
5200 oob_stack.Push ($0);
5202 for_condition_and_iterator_part
5205 var locations = (Tuple<Location,Location>) $4;
5207 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5208 Warning_EmptyStatement (GetLocation ($5));
5211 f.Statement = (Statement) $5;
5212 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5214 $$ = end_block (GetLocation ($2));
5218 Error_SyntaxError (yyToken);
5219 $$ = end_block (current_block.StartLocation);
5223 for_condition_and_iterator_part
5224 : opt_for_condition SEMICOLON
5226 For f = (For) oob_stack.Peek ();
5227 f.Condition = (BooleanExpression) $1;
5230 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5233 // Handle errors in the case of opt_for_condition being followed by
5234 // a close parenthesis
5235 | opt_for_condition close_parens_close_brace {
5236 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5237 For f = (For) oob_stack.Peek ();
5238 f.Condition = (BooleanExpression) $1;
5239 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5244 : opt_for_iterator CLOSE_PARENS {
5245 For f = (For) oob_stack.Peek ();
5246 f.Iterator = (Statement) $1;
5247 $$ = GetLocation ($2);
5249 | opt_for_iterator CLOSE_BRACE {
5250 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5251 For f = (For) oob_stack.Peek ();
5252 f.Iterator = (Statement) $1;
5253 $$ = GetLocation ($2);
5257 close_parens_close_brace
5259 | CLOSE_BRACE { lexer.putback ('}'); }
5263 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5268 : variable_type identifier_inside_body
5270 var lt = (Tokenizer.LocatedToken) $2;
5271 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5272 current_block.AddLocalName (li);
5273 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5275 opt_local_variable_initializer opt_variable_declarators
5277 $$ = current_variable;
5278 current_variable = null;
5280 | statement_expression_list
5284 : /* empty */ { $$ = null; }
5285 | boolean_expression
5289 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5294 : statement_expression_list
5297 statement_expression_list
5298 : statement_expression
5299 | statement_expression_list COMMA statement_expression
5301 var sl = $1 as StatementList;
5303 sl = new StatementList ((Statement) $1, (Statement) $3);
5304 lbag.AddStatement (sl, GetLocation ($2));
5306 sl.Add ((Statement) $3);
5307 lbag.AppendTo (sl, GetLocation ($2));
5315 : FOREACH open_parens_any type error
5317 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5319 start_block (GetLocation ($2));
5320 current_block.IsCompilerGenerated = true;
5322 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5323 current_block.AddStatement (f);
5325 lbag.AddStatement (f, GetLocation ($2));
5326 $$ = end_block (GetLocation ($4));
5328 | FOREACH open_parens_any type identifier_inside_body error
5330 Error_SyntaxError (yyToken);
5332 start_block (GetLocation ($2));
5333 current_block.IsCompilerGenerated = true;
5335 var lt = (Tokenizer.LocatedToken) $4;
5336 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5337 current_block.AddLocalName (li);
5339 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5340 current_block.AddStatement (f);
5342 lbag.AddStatement (f, GetLocation ($2));
5343 $$ = end_block (GetLocation ($5));
5345 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5347 start_block (GetLocation ($2));
5348 current_block.IsCompilerGenerated = true;
5350 var lt = (Tokenizer.LocatedToken) $4;
5351 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5352 current_block.AddLocalName (li);
5357 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5358 Warning_EmptyStatement (GetLocation ($9));
5360 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5361 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5362 end_block (GetLocation ($7));
5370 | continue_statement
5380 $$ = new Break (GetLocation ($1));
5381 lbag.AddStatement ($$, GetLocation ($2));
5386 : CONTINUE SEMICOLON
5388 $$ = new Continue (GetLocation ($1));
5389 lbag.AddStatement ($$, GetLocation ($2));
5393 Error_SyntaxError (yyToken);
5394 $$ = new Continue (GetLocation ($1));
5399 : GOTO identifier_inside_body SEMICOLON
5401 var lt = (Tokenizer.LocatedToken) $2;
5402 $$ = new Goto (lt.Value, GetLocation ($1));
5403 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5405 | GOTO CASE constant_expression SEMICOLON
5407 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5408 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5410 | GOTO DEFAULT SEMICOLON
5412 $$ = new GotoDefault (GetLocation ($1));
5413 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5418 : RETURN opt_expression SEMICOLON
5420 $$ = new Return ((Expression) $2, GetLocation ($1));
5421 lbag.AddStatement ($$, GetLocation ($3));
5425 Error_SyntaxError (yyToken);
5426 $$ = new Return (null, GetLocation ($1));
5431 : THROW opt_expression SEMICOLON
5433 $$ = new Throw ((Expression) $2, GetLocation ($1));
5434 lbag.AddStatement ($$, GetLocation ($3));
5438 Error_SyntaxError (yyToken);
5439 $$ = new Throw (null, GetLocation ($1));
5444 : identifier_inside_body RETURN opt_expression SEMICOLON
5446 var lt = (Tokenizer.LocatedToken) $1;
5447 string s = lt.Value;
5449 report.Error (1003, lt.Location, "; expected");
5450 } else if ($3 == null) {
5451 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5452 } else if (lang_version == LanguageVersion.ISO_1){
5453 FeatureIsNotAvailable (lt.Location, "iterators");
5456 current_block.Explicit.RegisterIteratorYield ();
5457 $$ = new Yield ((Expression) $3, lt.Location);
5458 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5460 | identifier_inside_body BREAK SEMICOLON
5462 var lt = (Tokenizer.LocatedToken) $1;
5463 string s = lt.Value;
5465 report.Error (1003, lt.Location, "; expected");
5466 } else if (lang_version == LanguageVersion.ISO_1){
5467 FeatureIsNotAvailable (lt.Location, "iterators");
5470 current_block.Explicit.RegisterIteratorYield ();
5471 $$ = new YieldBreak (lt.Location);
5472 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5482 : TRY block catch_clauses
5484 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5486 | TRY block FINALLY block
5488 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5489 lbag.AddStatement ($$, GetLocation ($3));
5491 | TRY block catch_clauses FINALLY block
5493 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5494 lbag.AddStatement ($$, GetLocation ($4));
5498 Error_SyntaxError (1524, yyToken);
5499 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5506 var l = new List<Catch> (2);
5511 | catch_clauses catch_clause
5513 var l = (List<Catch>) $1;
5515 Catch c = (Catch) $2;
5516 if (l [l.Count - 1].IsGeneral) {
5517 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5527 | identifier_inside_body
5533 $$ = new Catch ((Block) $2, GetLocation ($1));
5535 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5537 start_block (GetLocation ($2));
5538 var c = new Catch (current_block, GetLocation ($1));
5539 c.TypeExpression = (FullNamedExpression) $3;
5542 var lt = (Tokenizer.LocatedToken) $4;
5543 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5544 current_block.AddLocalName (c.Variable);
5547 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5554 | CATCH open_parens_any error
5556 if (yyToken == Token.CLOSE_PARENS) {
5557 report.Error (1015, lexer.Location,
5558 "A type that derives from `System.Exception', `object', or `string' expected");
5560 Error_SyntaxError (yyToken);
5563 $$ = new Catch (null, GetLocation ($1));
5570 $$ = new Checked ((Block) $2, GetLocation ($1));
5577 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5584 if (!settings.Unsafe)
5585 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5587 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5592 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5594 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5595 Warning_EmptyStatement (GetLocation ($5));
5597 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5598 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5600 | LOCK open_parens_any expression error
5602 Error_SyntaxError (yyToken);
5604 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5605 lbag.AddStatement ($$, GetLocation ($2));
5610 : FIXED open_parens_any variable_type identifier_inside_body
5612 start_block (GetLocation ($2));
5614 current_block.IsCompilerGenerated = true;
5615 var lt = (Tokenizer.LocatedToken) $4;
5616 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5617 current_block.AddLocalName (li);
5618 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5620 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5622 $$ = current_variable;
5623 current_variable = null;
5627 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5628 Warning_EmptyStatement (GetLocation ($10));
5630 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5631 current_block.AddStatement (f);
5632 $$ = end_block (GetLocation ($8));
5637 : USING open_parens_any variable_type identifier_inside_body
5639 start_block (GetLocation ($2));
5641 current_block.IsCompilerGenerated = true;
5642 var lt = (Tokenizer.LocatedToken) $4;
5643 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5644 current_block.AddLocalName (li);
5645 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5647 using_initialization CLOSE_PARENS
5649 $$ = current_variable;
5650 current_variable = null;
5654 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5655 Warning_EmptyStatement (GetLocation ($9));
5657 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
5658 current_block.AddStatement (u);
5659 $$ = end_block (GetLocation ($7));
5661 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5663 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5664 Warning_EmptyStatement (GetLocation ($5));
5666 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5667 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5669 | USING open_parens_any expression error
5671 Error_SyntaxError (yyToken);
5673 $$ = new Using ((Expression) $3, null, GetLocation ($1));
5674 lbag.AddStatement ($$, GetLocation ($2));
5678 using_initialization
5679 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
5682 // It has to be here for the parent to safely restore artificial block
5683 Error_SyntaxError (yyToken);
5687 using_or_fixed_variable_initializer
5690 Error_MissingInitializer (lexer.Location);
5692 | ASSIGN variable_initializer
5694 current_variable.Initializer = (Expression) $2;
5695 $$ = current_variable;
5703 : first_from_clause query_body
5705 lexer.query_parsing = false;
5707 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5709 from.Tail.Next = (Linq.AQueryClause)$2;
5712 current_block.SetEndLocation (lexer.Location);
5713 current_block = current_block.Parent;
5715 | nested_from_clause query_body
5717 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5719 from.Tail.Next = (Linq.AQueryClause)$2;
5722 current_block.SetEndLocation (lexer.Location);
5723 current_block = current_block.Parent;
5726 // Bubble up COMPLETE_COMPLETION productions
5727 | first_from_clause COMPLETE_COMPLETION {
5728 lexer.query_parsing = false;
5731 current_block.SetEndLocation (lexer.Location);
5732 current_block = current_block.Parent;
5734 | nested_from_clause COMPLETE_COMPLETION {
5736 current_block.SetEndLocation (lexer.Location);
5737 current_block = current_block.Parent;
5742 : FROM_FIRST identifier_inside_body IN expression
5744 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5746 var lt = (Tokenizer.LocatedToken) $2;
5747 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5748 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5750 | FROM_FIRST type identifier_inside_body IN expression
5752 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5754 var lt = (Tokenizer.LocatedToken) $3;
5755 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5756 $$ = new Linq.QueryExpression (
5757 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5758 IdentifierType = (FullNamedExpression)$2
5765 : FROM identifier_inside_body IN expression
5767 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5769 var lt = (Tokenizer.LocatedToken) $2;
5770 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5771 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5773 | FROM type identifier_inside_body IN expression
5775 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5777 var lt = (Tokenizer.LocatedToken) $3;
5778 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5779 $$ = new Linq.QueryExpression (
5780 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5781 IdentifierType = (FullNamedExpression)$2
5788 : FROM identifier_inside_body IN
5790 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5794 var lt = (Tokenizer.LocatedToken) $2;
5795 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5796 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5798 current_block.SetEndLocation (lexer.Location);
5799 current_block = current_block.Parent;
5801 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5803 | FROM type identifier_inside_body IN
5805 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5809 var lt = (Tokenizer.LocatedToken) $3;
5810 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5812 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5813 IdentifierType = (FullNamedExpression)$2
5816 current_block.SetEndLocation (lexer.Location);
5817 current_block = current_block.Parent;
5819 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5824 : query_body_clauses select_or_group_clause opt_query_continuation
5826 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5829 head.Next = (Linq.AQueryClause)$3;
5832 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5833 clause.Tail.Next = head;
5839 | select_or_group_clause opt_query_continuation
5841 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5844 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5845 clause.Tail.Next = head;
5851 | query_body_clauses COMPLETE_COMPLETION
5852 | query_body_clauses error
5854 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
5859 Error_SyntaxError (yyToken);
5864 select_or_group_clause
5867 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5871 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5873 current_block.SetEndLocation (lexer.Location);
5874 current_block = current_block.Parent;
5878 if (linq_clause_blocks == null)
5879 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5881 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5882 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5886 current_block.SetEndLocation (lexer.Location);
5887 current_block = current_block.Parent;
5889 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5891 BY expression_or_error
5893 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5894 lbag.AddLocation ($$, GetLocation ($5));
5896 current_block.SetEndLocation (lexer.Location);
5897 current_block = current_block.Parent;
5903 | query_body_clauses query_body_clause
5905 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5919 : LET identifier_inside_body ASSIGN
5921 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5925 var lt = (Tokenizer.LocatedToken) $2;
5926 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5927 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5928 lbag.AddLocation ($$, GetLocation ($3));
5930 current_block.SetEndLocation (lexer.Location);
5931 current_block = current_block.Parent;
5933 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5940 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5944 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5946 current_block.SetEndLocation (lexer.Location);
5947 current_block = current_block.Parent;
5952 : JOIN identifier_inside_body IN
5954 if (linq_clause_blocks == null)
5955 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5957 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5958 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5960 expression_or_error ON
5962 current_block.SetEndLocation (lexer.Location);
5963 current_block = current_block.Parent;
5965 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5966 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5968 expression_or_error EQUALS
5970 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5971 current_block.SetEndLocation (lexer.Location);
5972 current_block = current_block.Parent;
5974 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5976 expression_or_error opt_join_into
5978 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5979 current_block.SetEndLocation (lexer.Location);
5981 var outer_selector = linq_clause_blocks.Pop ();
5982 var block = linq_clause_blocks.Pop ();
5984 var lt = (Tokenizer.LocatedToken) $2;
5985 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5986 Linq.RangeVariable into;
5990 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5991 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
5994 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5996 var parent = block.Parent;
5997 while (parent is Linq.QueryBlock) {
5998 parent = parent.Parent;
6000 current_block.Parent = parent;
6002 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6004 lt = (Tokenizer.LocatedToken) $12;
6005 into = new Linq.RangeVariable (lt.Value, lt.Location);
6007 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6008 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6011 current_block = block.Parent;
6012 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6014 | JOIN type identifier_inside_body IN
6016 if (linq_clause_blocks == null)
6017 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6019 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6020 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6022 expression_or_error ON
6024 current_block.SetEndLocation (lexer.Location);
6025 current_block = current_block.Parent;
6027 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6028 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6030 expression_or_error EQUALS
6032 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6033 current_block.SetEndLocation (lexer.Location);
6034 current_block = current_block.Parent;
6036 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6038 expression_or_error opt_join_into
6040 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6041 current_block.SetEndLocation (lexer.Location);
6043 var outer_selector = linq_clause_blocks.Pop ();
6044 var block = linq_clause_blocks.Pop ();
6046 var lt = (Tokenizer.LocatedToken) $3;
6047 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6048 Linq.RangeVariable into;
6052 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6053 IdentifierType = (FullNamedExpression)$2
6057 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6059 var parent = block.Parent;
6060 while (parent is Linq.QueryBlock) {
6061 parent = parent.Parent;
6063 current_block.Parent = parent;
6065 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6067 lt = (Tokenizer.LocatedToken) $13;
6068 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6070 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6071 IdentifierType = (FullNamedExpression)$2
6075 current_block = block.Parent;
6076 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6082 | INTO identifier_inside_body
6091 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6095 current_block.SetEndLocation (lexer.Location);
6096 current_block = current_block.Parent;
6106 current_block.SetEndLocation (lexer.Location);
6107 current_block = current_block.Parent;
6109 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6113 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6120 | orderings_then_by COMMA
6122 current_block.SetEndLocation (lexer.Location);
6123 current_block = current_block.Parent;
6125 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6129 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6137 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6139 | expression ASCENDING
6141 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6142 lbag.AddLocation ($$, GetLocation ($2));
6144 | expression DESCENDING
6146 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6147 lbag.AddLocation ($$, GetLocation ($2));
6154 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6156 | expression ASCENDING
6158 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6159 lbag.AddLocation ($$, GetLocation ($2));
6161 | expression DESCENDING
6163 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6164 lbag.AddLocation ($$, GetLocation ($2));
6169 opt_query_continuation
6171 | INTO identifier_inside_body
6173 // query continuation block is not linked with query block but with block
6174 // before. This means each query can use same range variable names for
6175 // different identifiers.
6177 current_block.SetEndLocation (GetLocation ($1));
6178 current_block = current_block.Parent;
6180 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6182 if (linq_clause_blocks == null)
6183 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6185 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6189 var current_block = linq_clause_blocks.Pop ();
6190 var lt = (Tokenizer.LocatedToken) $2;
6191 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6192 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6193 next = (Linq.AQueryClause)$4
6199 // Support for using the compiler as an interactive parser
6201 // The INTERACTIVE_PARSER token is first sent to parse our
6202 // productions; If the result is a Statement, the parsing
6203 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6204 // to setup the blocks in advance.
6206 // This setup is here so that in the future we can add
6207 // support for other constructs (type parsing, namespaces, etc)
6208 // that do not require a block to be setup in advance
6212 : EVAL_STATEMENT_PARSER EOF
6213 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6214 | EVAL_STATEMENT_PARSER
6216 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6218 // (ref object retval)
6219 Parameter [] mpar = new Parameter [1];
6220 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6222 ParametersCompiled pars = new ParametersCompiled (mpar);
6223 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6224 if (settings.Unsafe)
6225 mods |= Modifiers.UNSAFE;
6227 current_local_parameters = pars;
6228 Method method = new Method (
6230 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6232 new MemberName ("Host"),
6234 null /* attributes */);
6236 current_type.AddMember (method);
6238 oob_stack.Push (method);
6239 ++lexer.parsing_block;
6240 start_block (lexer.Location);
6242 interactive_statement_list opt_COMPLETE_COMPLETION
6244 --lexer.parsing_block;
6245 Method method = (Method) oob_stack.Pop ();
6247 method.Block = (ToplevelBlock) end_block(lexer.Location);
6249 InteractiveResult = (Class) pop_current_class ();
6250 current_local_parameters = null;
6252 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6255 interactive_compilation_unit
6256 : opt_extern_alias_directives opt_using_directives
6257 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6260 opt_COMPLETE_COMPLETION
6262 | COMPLETE_COMPLETION
6265 close_brace_or_complete_completion
6267 | COMPLETE_COMPLETION
6271 // XML documentation code references micro parser
6273 documentation_parsing
6276 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6281 : doc_type_declaration_name opt_doc_method_sig
6283 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6285 | builtin_types opt_doc_method_sig
6287 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6288 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6291 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6293 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6294 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6295 var lt = (Tokenizer.LocatedToken) $3;
6296 $$ = new MemberName (lt.Value);
6298 | doc_type_declaration_name DOT THIS
6300 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6302 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6304 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6306 opt_doc_parameters CLOSE_BRACKET
6308 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6309 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6311 | EXPLICIT OPERATOR type opt_doc_method_sig
6313 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6314 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6315 module.DocumentationBuilder.ParsedParameters = p;
6316 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6319 | IMPLICIT OPERATOR type opt_doc_method_sig
6321 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6322 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6323 module.DocumentationBuilder.ParsedParameters = p;
6324 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6327 | OPERATOR overloadable_operator opt_doc_method_sig
6329 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6330 module.DocumentationBuilder.ParsedParameters = p;
6331 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6336 doc_type_declaration_name
6337 : type_declaration_name
6338 | doc_type_declaration_name DOT type_declaration_name
6340 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6348 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6350 opt_doc_parameters CLOSE_PARENS
6359 $$ = new List<DocumentationParameter> (0);
6367 var parameters = new List<DocumentationParameter> ();
6368 parameters.Add ((DocumentationParameter) $1);
6371 | doc_parameters COMMA doc_parameter
6373 var parameters = $1 as List<DocumentationParameter>;
6374 parameters.Add ((DocumentationParameter) $3);
6380 : opt_parameter_modifier parameter_type
6383 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6385 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6392 // A class used to hold info about an operator declarator
6394 class OperatorDeclaration {
6395 public readonly Operator.OpType optype;
6396 public readonly FullNamedExpression ret_type;
6397 public readonly Location location;
6399 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6402 this.ret_type = ret_type;
6403 this.location = location;
6407 void Error_ExpectingTypeName (Expression expr)
6409 if (expr is Invocation){
6410 report.Error (1002, expr.Location, "Expecting `;'");
6412 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6416 void Error_ParameterModifierNotValid (string modifier, Location loc)
6418 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6422 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6424 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6425 Parameter.GetModifierSignature (mod));
6428 void Error_TypeExpected (Location loc)
6430 report.Error (1031, loc, "Type expected");
6433 void Error_UnsafeCodeNotAllowed (Location loc)
6435 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6438 void Warning_EmptyStatement (Location loc)
6440 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6443 void Error_NamedArgumentExpected (NamedArgument a)
6445 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6448 void Error_MissingInitializer (Location loc)
6450 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6453 void push_current_container (TypeDefinition tc, object partial_token)
6455 if (module.Evaluator != null){
6456 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6460 undo.AddTypeContainer (current_container, tc);
6463 if (partial_token != null)
6464 current_container.AddPartial (tc);
6466 current_container.AddTypeContainer (tc);
6468 ++lexer.parsing_declaration;
6469 current_container = tc;
6473 TypeContainer pop_current_class ()
6475 var retval = current_container;
6477 current_container = current_container.Parent;
6478 current_type = current_type.Parent as TypeDefinition;
6483 [System.Diagnostics.Conditional ("FULL_AST")]
6484 void StoreModifierLocation (object token, Location loc)
6489 if (mod_locations == null)
6490 mod_locations = new List<Tuple<Modifiers, Location>> ();
6492 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6495 string CheckAttributeTarget (string a, Location l)
6498 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6502 report.Warning (658, 1, l,
6503 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6504 return string.Empty;
6507 static bool IsUnaryOperator (Operator.OpType op)
6511 case Operator.OpType.LogicalNot:
6512 case Operator.OpType.OnesComplement:
6513 case Operator.OpType.Increment:
6514 case Operator.OpType.Decrement:
6515 case Operator.OpType.True:
6516 case Operator.OpType.False:
6517 case Operator.OpType.UnaryPlus:
6518 case Operator.OpType.UnaryNegation:
6524 void syntax_error (Location l, string msg)
6526 report.Error (1003, l, "Syntax error, " + msg);
6531 public Tokenizer Lexer {
6537 static CSharpParser ()
6539 oob_stack = new Stack<object> ();
6542 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
6543 : this (reader, file, file.Compiler.Report)
6547 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
6550 current_container = current_namespace = file;
6552 this.module = file.Module;
6553 this.compiler = file.Compiler;
6554 this.settings = compiler.Settings;
6555 this.report = report;
6557 lang_version = settings.Version;
6558 yacc_verbose_flag = settings.VerboseParserFlag;
6559 doc_support = settings.DocumentationFile != null;
6561 lexer = new Tokenizer (reader, file);
6564 lbag = new LocationsBag ();
6569 use_global_stacks = true;
6572 public void parse ()
6574 eof_token = Token.EOF;
6575 Tokenizer.LocatedToken.Initialize ();
6578 if (yacc_verbose_flag > 1)
6579 yyparse (lexer, new yydebug.yyDebugSimple ());
6583 Tokenizer tokenizer = lexer as Tokenizer;
6584 tokenizer.cleanup ();
6585 } catch (Exception e){
6586 if (e is yyParser.yyUnexpectedEof) {
6587 Error_SyntaxError (yyToken);
6588 UnexpectedEOF = true;
6592 if (e is yyParser.yyException) {
6593 report.Error (-25, lexer.Location, "Parsing error");
6595 // Used by compiler-tester to test internal errors
6596 if (yacc_verbose_flag > 0 || e is FatalException)
6599 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6604 void CheckToken (int error, int yyToken, string msg, Location loc)
6606 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6607 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6609 report.Error (error, loc, msg);
6612 string ConsumeStoredComment ()
6614 string s = tmpComment;
6616 Lexer.doc_state = XmlCommentState.Allowed;
6620 void FeatureIsNotAvailable (Location loc, string feature)
6622 report.FeatureIsNotAvailable (compiler, loc, feature);
6625 Location GetLocation (object obj)
6627 var lt = obj as Tokenizer.LocatedToken;
6631 var mn = obj as MemberName;
6635 var expr = obj as Expression;
6637 return expr.Location;
6639 return lexer.Location;
6642 public LocationsBag LocationsBag {
6648 void start_block (Location loc)
6650 if (current_block == null) {
6651 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6652 parsing_anonymous_method = false;
6653 } else if (parsing_anonymous_method) {
6654 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6655 parsing_anonymous_method = false;
6657 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6662 end_block (Location loc)
6664 Block retval = current_block.Explicit;
6665 retval.SetEndLocation (loc);
6666 current_block = retval.Parent;
6670 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6672 oob_stack.Push (current_anonymous_method);
6673 oob_stack.Push (current_local_parameters);
6674 oob_stack.Push (current_variable);
6675 oob_stack.Push (async_block);
6677 current_local_parameters = parameters;
6679 if (lang_version <= LanguageVersion.ISO_2)
6680 FeatureIsNotAvailable (loc, "lambda expressions");
6682 current_anonymous_method = new LambdaExpression (loc);
6684 if (lang_version == LanguageVersion.ISO_1)
6685 FeatureIsNotAvailable (loc, "anonymous methods");
6687 current_anonymous_method = new AnonymousMethodExpression (loc);
6690 async_block = isAsync;
6691 // Force the next block to be created as a ToplevelBlock
6692 parsing_anonymous_method = true;
6696 * Completes the anonymous method processing, if lambda_expr is null, this
6697 * means that we have a Statement instead of an Expression embedded
6699 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6701 AnonymousMethodExpression retval;
6704 anon_block.IsAsync = true;
6706 current_anonymous_method.Block = anon_block;
6707 retval = current_anonymous_method;
6709 async_block = (bool) oob_stack.Pop ();
6710 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6711 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6712 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6717 void Error_SyntaxError (int token)
6719 Error_SyntaxError (0, token);
6722 void Error_SyntaxError (int error_code, int token)
6724 Error_SyntaxError (error_code, token, "Unexpected symbol");
6727 void Error_SyntaxError (int error_code, int token, string msg)
6729 Lexer.CompleteOnEOF = false;
6731 // An error message has been reported by tokenizer
6732 if (token == Token.ERROR)
6735 string symbol = GetSymbolName (token);
6736 string expecting = GetExpecting ();
6737 var loc = lexer.Location - symbol.Length;
6739 if (error_code == 0) {
6740 if (expecting == "`identifier'") {
6741 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6742 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6747 expecting = "identifier";
6748 } else if (expecting == "`)'") {
6755 if (string.IsNullOrEmpty (expecting))
6756 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6758 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6761 string GetExpecting ()
6763 int [] tokens = yyExpectingTokens (yyExpectingState);
6764 var names = new List<string> (tokens.Length);
6765 bool has_type = false;
6766 bool has_identifier = false;
6767 for (int i = 0; i < tokens.Length; i++){
6768 int token = tokens [i];
6769 has_identifier |= token == Token.IDENTIFIER;
6771 string name = GetTokenName (token);
6772 if (name == "<internal>")
6775 has_type |= name == "type";
6776 if (names.Contains (name))
6783 // Too many tokens to enumerate
6785 if (names.Count > 8)
6788 if (has_type && has_identifier)
6789 names.Remove ("identifier");
6791 if (names.Count == 1)
6792 return "`" + GetTokenName (tokens [0]) + "'";
6794 StringBuilder sb = new StringBuilder ();
6796 int count = names.Count;
6797 for (int i = 0; i < count; i++){
6798 bool last = i + 1 == count;
6802 sb.Append (names [i]);
6803 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6805 return sb.ToString ();
6809 string GetSymbolName (int token)
6813 return ((Constant)lexer.Value).GetValue ().ToString ();
6814 case Token.IDENTIFIER:
6815 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6857 case Token.BITWISE_AND:
6859 case Token.BITWISE_OR:
6873 case Token.OP_SHIFT_LEFT:
6875 case Token.OP_SHIFT_RIGHT:
6895 case Token.OP_COALESCING:
6897 case Token.OP_MULT_ASSIGN:
6899 case Token.OP_DIV_ASSIGN:
6901 case Token.OP_MOD_ASSIGN:
6903 case Token.OP_ADD_ASSIGN:
6905 case Token.OP_SUB_ASSIGN:
6907 case Token.OP_SHIFT_LEFT_ASSIGN:
6909 case Token.OP_SHIFT_RIGHT_ASSIGN:
6911 case Token.OP_AND_ASSIGN:
6913 case Token.OP_XOR_ASSIGN:
6915 case Token.OP_OR_ASSIGN:
6919 return GetTokenName (token);
6922 static string GetTokenName (int token)
6925 case Token.ABSTRACT:
6947 case Token.CONTINUE:
6951 case Token.DELEGATE:
6961 case Token.EXPLICIT:
6964 case Token.EXTERN_ALIAS:
6980 case Token.IMPLICIT:
6984 case Token.INTERFACE:
6986 case Token.INTERNAL:
6992 case Token.NAMESPACE:
6998 case Token.OPERATOR:
7002 case Token.OVERRIDE:
7008 case Token.PROTECTED:
7012 case Token.READONLY:
7024 case Token.STACKALLOC:
7025 return "stackalloc";
7042 case Token.UNCHECKED:
7050 case Token.VOLATILE:
7058 case Token.REFVALUE:
7059 return "__refvalue";
7069 case Token.FROM_FIRST:
7087 case Token.ASCENDING:
7089 case Token.DESCENDING:
7090 return "descending";
7097 case Token.OPEN_BRACE:
7099 case Token.CLOSE_BRACE:
7101 case Token.OPEN_BRACKET:
7102 case Token.OPEN_BRACKET_EXPR:
7104 case Token.CLOSE_BRACKET:
7106 case Token.OPEN_PARENS_CAST:
7107 case Token.OPEN_PARENS_LAMBDA:
7108 case Token.OPEN_PARENS:
7110 case Token.CLOSE_PARENS:
7116 case Token.DEFAULT_COLON:
7120 case Token.SEMICOLON:
7131 case Token.BITWISE_AND:
7132 case Token.BITWISE_OR:
7139 case Token.OP_SHIFT_LEFT:
7140 case Token.OP_SHIFT_RIGHT:
7148 case Token.OP_COALESCING:
7149 case Token.OP_MULT_ASSIGN:
7150 case Token.OP_DIV_ASSIGN:
7151 case Token.OP_MOD_ASSIGN:
7152 case Token.OP_ADD_ASSIGN:
7153 case Token.OP_SUB_ASSIGN:
7154 case Token.OP_SHIFT_LEFT_ASSIGN:
7155 case Token.OP_SHIFT_RIGHT_ASSIGN:
7156 case Token.OP_AND_ASSIGN:
7157 case Token.OP_XOR_ASSIGN:
7158 case Token.OP_OR_ASSIGN:
7159 return "<operator>";
7181 case Token.OP_GENERICS_LT:
7182 case Token.GENERIC_DIMENSION:
7184 case Token.OP_GENERICS_GT:
7187 case Token.INTERR_NULLABLE:
7189 case Token.DOUBLE_COLON:
7193 case Token.IDENTIFIER:
7195 return "identifier";
7198 return "end-of-file";
7200 // All of these are internal.
7203 case Token.FIRST_KEYWORD:
7204 case Token.EVAL_COMPILATION_UNIT_PARSER:
7205 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7206 case Token.EVAL_STATEMENT_PARSER:
7207 case Token.LAST_KEYWORD:
7208 case Token.GENERATE_COMPLETION:
7209 case Token.COMPLETE_COMPLETION:
7210 return "<internal>";
7212 // A bit more robust.
7214 return yyNames [token];