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);
1456 opt_parameter_modifier
1460 Error_SyntaxError (yyToken);
1461 Location l = GetLocation ($4);
1462 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1465 opt_parameter_modifier
1470 ++lexer.parsing_block;
1474 --lexer.parsing_block;
1475 if (lang_version <= LanguageVersion.V_3) {
1476 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1479 Parameter.Modifier mod = (Parameter.Modifier) $2;
1480 if (mod != Parameter.Modifier.NONE) {
1482 case Parameter.Modifier.REF:
1483 case Parameter.Modifier.OUT:
1484 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1485 Parameter.GetModifierSignature (mod));
1488 case Parameter.Modifier.This:
1489 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1490 Parameter.GetModifierSignature (mod));
1493 throw new NotImplementedException (mod.ToString ());
1496 mod = Parameter.Modifier.NONE;
1499 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1500 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1502 var lt = (Tokenizer.LocatedToken) $4;
1503 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1504 lbag.AddLocation ($$, GetLocation ($5));
1507 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1511 opt_parameter_modifier
1512 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1513 | parameter_modifiers
1517 : parameter_modifier
1521 | parameter_modifiers parameter_modifier
1523 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1524 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1525 if (((Parameter.Modifier)$1 & p2) == p2) {
1526 Error_DuplicateParameterModifier (lexer.Location, p2);
1528 switch (mod & ~Parameter.Modifier.This) {
1529 case Parameter.Modifier.REF:
1530 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1532 case Parameter.Modifier.OUT:
1533 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1536 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1547 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1548 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1550 $$ = Parameter.Modifier.REF;
1554 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1555 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1557 $$ = Parameter.Modifier.OUT;
1561 if ((valid_param_mod & ParameterModifierType.This) == 0)
1562 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1564 if (lang_version <= LanguageVersion.ISO_2)
1565 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1567 $$ = Parameter.Modifier.This;
1572 : opt_attributes params_modifier type IDENTIFIER
1574 var lt = (Tokenizer.LocatedToken) $4;
1575 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1577 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1579 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1581 var lt = (Tokenizer.LocatedToken) $4;
1582 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1584 | opt_attributes params_modifier type error
1586 Error_SyntaxError (yyToken);
1594 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1595 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1597 | PARAMS parameter_modifier
1599 Parameter.Modifier mod = (Parameter.Modifier)$2;
1600 if ((mod & Parameter.Modifier.This) != 0) {
1601 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1603 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1606 | PARAMS params_modifier
1608 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1615 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1616 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1620 property_declaration
1624 member_declaration_name
1627 tmpComment = Lexer.consume_doc_comment ();
1631 var type = (FullNamedExpression) $3;
1632 current_property = new Property (current_type, type, (Modifiers) $2,
1633 (MemberName) $4, (Attributes) $1);
1635 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1636 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1638 current_type.AddMember (current_property);
1639 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1641 lexer.PropertyParsing = true;
1643 accessor_declarations
1645 lexer.PropertyParsing = false;
1648 current_property.DocComment = ConsumeStoredComment ();
1652 lbag.AppendToMember (current_property, GetLocation ($10));
1653 current_property = null;
1659 : opt_attributes opt_modifiers
1660 member_type indexer_declaration_name OPEN_BRACKET
1662 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1664 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1666 valid_param_mod = 0;
1667 var type = (FullNamedExpression) $3;
1668 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1670 current_property = indexer;
1672 current_type.AddIndexer (indexer);
1673 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1675 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1676 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1678 if (indexer.ParameterInfo.IsEmpty) {
1679 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1683 tmpComment = Lexer.consume_doc_comment ();
1684 Lexer.doc_state = XmlCommentState.Allowed;
1687 lexer.PropertyParsing = true;
1689 accessor_declarations
1691 lexer.PropertyParsing = false;
1695 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1696 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1699 current_property.DocComment = ConsumeStoredComment ();
1701 lbag.AppendToMember (current_property, GetLocation ($12));
1702 current_property = null;
1707 accessor_declarations
1708 : get_accessor_declaration
1709 | get_accessor_declaration accessor_declarations
1710 | set_accessor_declaration
1711 | set_accessor_declaration accessor_declarations
1714 if (yyToken == Token.CLOSE_BRACE) {
1715 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1717 if (yyToken == Token.SEMICOLON)
1718 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1720 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1725 get_accessor_declaration
1726 : opt_attributes opt_modifiers GET
1728 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1729 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1732 if (current_property.Get != null) {
1733 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1736 if (current_property is Indexer) {
1737 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1738 (Attributes) $1, GetLocation ($3));
1740 current_property.Get = new Property.GetMethod (current_property,
1741 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1744 current_local_parameters = current_property.Get.ParameterInfo;
1745 lbag.AddMember (current_property.Get, mod_locations);
1746 lexer.PropertyParsing = false;
1751 current_property.Get.Block = (ToplevelBlock) $5;
1753 if (current_container.Kind == MemberKind.Interface) {
1754 report.Error (531, current_property.Get.Block.StartLocation,
1755 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1759 current_local_parameters = null;
1760 lexer.PropertyParsing = true;
1763 if (Lexer.doc_state == XmlCommentState.Error)
1764 Lexer.doc_state = XmlCommentState.NotAllowed;
1768 set_accessor_declaration
1769 : opt_attributes opt_modifiers SET
1771 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1772 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1775 if (current_property.Set != null) {
1776 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1779 if (current_property is Indexer) {
1780 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1781 ParametersCompiled.MergeGenerated (compiler,
1782 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1783 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1785 (Attributes) $1, GetLocation ($3));
1787 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1788 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1789 (Attributes) $1, GetLocation ($3));
1792 current_local_parameters = current_property.Set.ParameterInfo;
1793 lbag.AddMember (current_property.Set, mod_locations);
1794 lexer.PropertyParsing = false;
1799 current_property.Set.Block = (ToplevelBlock) $5;
1801 if (current_container.Kind == MemberKind.Interface) {
1802 report.Error (531, current_property.Set.Block.StartLocation,
1803 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1807 current_local_parameters = null;
1808 lexer.PropertyParsing = true;
1811 && Lexer.doc_state == XmlCommentState.Error)
1812 Lexer.doc_state = XmlCommentState.NotAllowed;
1825 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1830 interface_declaration
1836 lexer.ConstraintsParsing = true;
1838 type_declaration_name
1840 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1841 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1844 opt_type_parameter_constraints_clauses
1846 lexer.ConstraintsParsing = false;
1849 current_container.SetConstraints ((List<Constraints>) $9);
1852 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1853 Lexer.doc_state = XmlCommentState.Allowed;
1856 lexer.parsing_modifiers = true;
1858 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1860 --lexer.parsing_declaration;
1862 Lexer.doc_state = XmlCommentState.Allowed;
1866 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1867 $$ = pop_current_class ();
1869 | opt_attributes opt_modifiers opt_partial INTERFACE error
1871 Error_SyntaxError (yyToken);
1875 opt_interface_member_declarations
1877 | interface_member_declarations
1880 interface_member_declarations
1881 : interface_member_declaration
1883 lexer.parsing_modifiers = true;
1885 | interface_member_declarations interface_member_declaration
1887 lexer.parsing_modifiers = true;
1891 interface_member_declaration
1892 : constant_declaration
1894 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1898 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1900 | method_declaration
1901 | property_declaration
1903 | indexer_declaration
1904 | operator_declaration
1906 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1908 | constructor_declaration
1910 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1914 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1918 operator_declaration
1919 : opt_attributes opt_modifiers operator_declarator
1924 OperatorDeclaration decl = (OperatorDeclaration) $3;
1926 Operator op = new Operator (
1927 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1928 current_local_parameters,
1929 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1931 if (op.Block == null)
1932 op.ParameterInfo.CheckParameters (op);
1935 op.DocComment = tmpComment;
1936 Lexer.doc_state = XmlCommentState.Allowed;
1939 // Note again, checking is done in semantic analysis
1940 current_type.AddOperator (op);
1942 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1945 current_local_parameters = null;
1951 | SEMICOLON { $$ = null; }
1955 : type_expression_or_array
1958 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1959 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
1964 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1966 valid_param_mod = ParameterModifierType.DefaultValue;
1968 opt_formal_parameter_list CLOSE_PARENS
1970 valid_param_mod = 0;
1972 Location loc = GetLocation ($2);
1973 Operator.OpType op = (Operator.OpType) $3;
1974 current_local_parameters = (ParametersCompiled)$6;
1976 int p_count = current_local_parameters.Count;
1978 if (op == Operator.OpType.Addition)
1979 op = Operator.OpType.UnaryPlus;
1980 else if (op == Operator.OpType.Subtraction)
1981 op = Operator.OpType.UnaryNegation;
1984 if (IsUnaryOperator (op)) {
1986 report.Error (1020, loc, "Overloadable binary operator expected");
1987 } else if (p_count != 1) {
1988 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1989 Operator.GetName (op));
1993 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1994 Operator.GetName (op));
1995 } else if (p_count != 2) {
1996 report.Error (1019, loc, "Overloadable unary operator expected");
2001 tmpComment = Lexer.consume_doc_comment ();
2002 Lexer.doc_state = XmlCommentState.NotAllowed;
2005 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2006 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2008 | conversion_operator_declarator
2011 overloadable_operator
2013 : BANG { $$ = Operator.OpType.LogicalNot; }
2014 | TILDE { $$ = Operator.OpType.OnesComplement; }
2015 | OP_INC { $$ = Operator.OpType.Increment; }
2016 | OP_DEC { $$ = Operator.OpType.Decrement; }
2017 | TRUE { $$ = Operator.OpType.True; }
2018 | FALSE { $$ = Operator.OpType.False; }
2019 // Unary and binary:
2020 | PLUS { $$ = Operator.OpType.Addition; }
2021 | MINUS { $$ = Operator.OpType.Subtraction; }
2023 | STAR { $$ = Operator.OpType.Multiply; }
2024 | DIV { $$ = Operator.OpType.Division; }
2025 | PERCENT { $$ = Operator.OpType.Modulus; }
2026 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2027 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2028 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2029 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2030 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2031 | OP_EQ { $$ = Operator.OpType.Equality; }
2032 | OP_NE { $$ = Operator.OpType.Inequality; }
2033 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2034 | OP_LT { $$ = Operator.OpType.LessThan; }
2035 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2036 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2039 conversion_operator_declarator
2040 : IMPLICIT OPERATOR type OPEN_PARENS
2042 valid_param_mod = ParameterModifierType.DefaultValue;
2044 opt_formal_parameter_list CLOSE_PARENS
2046 valid_param_mod = 0;
2048 Location loc = GetLocation ($2);
2049 current_local_parameters = (ParametersCompiled)$6;
2052 tmpComment = Lexer.consume_doc_comment ();
2053 Lexer.doc_state = XmlCommentState.NotAllowed;
2056 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2057 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2059 | EXPLICIT OPERATOR type OPEN_PARENS
2061 valid_param_mod = ParameterModifierType.DefaultValue;
2063 opt_formal_parameter_list CLOSE_PARENS
2065 valid_param_mod = 0;
2067 Location loc = GetLocation ($2);
2068 current_local_parameters = (ParametersCompiled)$6;
2071 tmpComment = Lexer.consume_doc_comment ();
2072 Lexer.doc_state = XmlCommentState.NotAllowed;
2075 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2076 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2080 Error_SyntaxError (yyToken);
2081 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2082 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2086 Error_SyntaxError (yyToken);
2087 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2088 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2092 constructor_declaration
2093 : constructor_declarator
2096 Constructor c = (Constructor) $1;
2097 c.Block = (ToplevelBlock) $2;
2100 c.DocComment = ConsumeStoredComment ();
2102 current_local_parameters = null;
2104 Lexer.doc_state = XmlCommentState.Allowed;
2108 constructor_declarator
2114 tmpComment = Lexer.consume_doc_comment ();
2115 Lexer.doc_state = XmlCommentState.Allowed;
2118 valid_param_mod = ParameterModifierType.All;
2120 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2122 valid_param_mod = 0;
2123 current_local_parameters = (ParametersCompiled) $6;
2125 var lt = (Tokenizer.LocatedToken) $3;
2126 var mods = (Modifiers) $2;
2127 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2129 if (lt.Value != current_container.MemberName.Name) {
2130 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2131 } else if ((mods & Modifiers.STATIC) != 0) {
2132 if ((mods & Modifiers.AccessibilityMask) != 0){
2133 report.Error (515, c.Location,
2134 "`{0}': static constructor cannot have an access modifier",
2135 c.GetSignatureForError ());
2139 current_type.AddConstructor (c);
2140 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2144 // start block here, so possible anonymous methods inside
2145 // constructor initializer can get correct parent block
2147 start_block (lexer.Location);
2149 opt_constructor_initializer
2152 var c = (Constructor) $8;
2153 c.Initializer = (ConstructorInitializer) $9;
2156 report.Error (514, c.Location,
2157 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2158 c.GetSignatureForError ());
2168 | SEMICOLON { current_block = null; $$ = null; }
2171 opt_constructor_initializer
2173 | constructor_initializer
2176 constructor_initializer
2177 : COLON BASE OPEN_PARENS
2179 ++lexer.parsing_block;
2181 opt_argument_list CLOSE_PARENS
2183 --lexer.parsing_block;
2184 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2185 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2187 | COLON THIS OPEN_PARENS
2189 ++lexer.parsing_block;
2191 opt_argument_list CLOSE_PARENS
2193 --lexer.parsing_block;
2194 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2195 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2199 Error_SyntaxError (yyToken);
2200 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2201 lbag.AddLocation ($$, GetLocation ($1));
2205 Error_SyntaxError (yyToken);
2210 destructor_declaration
2211 : opt_attributes opt_modifiers TILDE
2214 tmpComment = Lexer.consume_doc_comment ();
2215 Lexer.doc_state = XmlCommentState.NotAllowed;
2218 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2220 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2222 var lt = (Tokenizer.LocatedToken) $5;
2223 if (lt.Value != current_container.MemberName.Name){
2224 report.Error (574, lt.Location, "Name of destructor must match name of class");
2225 } else if (current_container.Kind != MemberKind.Class){
2226 report.Error (575, lt.Location, "Only class types can contain destructor");
2229 Destructor d = new Destructor (current_type, (Modifiers) $2,
2230 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2232 d.DocComment = ConsumeStoredComment ();
2234 d.Block = (ToplevelBlock) $8;
2235 current_type.AddMember (d);
2236 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2238 current_local_parameters = null;
2245 EVENT type member_declaration_name
2247 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2248 current_type.AddMember (current_event_field);
2250 if (current_event_field.MemberName.ExplicitInterface != null) {
2251 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2252 current_event_field.GetSignatureForError ());
2255 $$ = current_event_field;
2257 opt_event_initializer
2258 opt_event_declarators
2262 current_event_field.DocComment = Lexer.consume_doc_comment ();
2263 Lexer.doc_state = XmlCommentState.Allowed;
2266 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2267 current_event_field = null;
2271 EVENT type member_declaration_name
2274 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2275 current_type.AddMember (current_event);
2276 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2278 lexer.EventParsing = true;
2280 event_accessor_declarations
2282 if (current_container.Kind == MemberKind.Interface)
2283 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2285 lexer.EventParsing = false;
2290 current_event.DocComment = Lexer.consume_doc_comment ();
2291 Lexer.doc_state = XmlCommentState.Allowed;
2294 lbag.AppendToMember (current_event, GetLocation ($9));
2295 current_event = null;
2296 current_local_parameters = null;
2300 opt_event_initializer
2304 ++lexer.parsing_block;
2306 event_variable_initializer
2308 --lexer.parsing_block;
2309 current_event_field.Initializer = (Expression) $3;
2313 opt_event_declarators
2321 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2323 | event_declarators event_declarator
2325 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2332 var lt = (Tokenizer.LocatedToken) $2;
2333 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2334 lbag.AddLocation ($$, GetLocation ($1));
2336 | COMMA IDENTIFIER ASSIGN
2338 ++lexer.parsing_block;
2340 event_variable_initializer
2342 --lexer.parsing_block;
2343 var lt = (Tokenizer.LocatedToken) $2;
2344 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2345 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2349 event_variable_initializer
2351 if (current_container.Kind == MemberKind.Interface) {
2352 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2353 current_event_field.GetSignatureForError ());
2356 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2357 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2358 current_event_field.GetSignatureForError ());
2361 variable_initializer
2367 event_accessor_declarations
2368 : add_accessor_declaration remove_accessor_declaration
2369 | remove_accessor_declaration add_accessor_declaration
2370 | add_accessor_declaration
2372 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2373 current_event.GetSignatureForError ());
2375 | remove_accessor_declaration
2377 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2378 current_event.GetSignatureForError ());
2382 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2387 add_accessor_declaration
2388 : opt_attributes opt_modifiers ADD
2390 if ($2 != ModifierNone) {
2391 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2394 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2395 current_local_parameters = current_event.Add.ParameterInfo;
2397 lbag.AddMember (current_event.Add, mod_locations);
2398 lexer.EventParsing = false;
2400 event_accessor_block
2402 lexer.EventParsing = true;
2404 current_event.Add.Block = (ToplevelBlock) $5;
2406 if (current_container.Kind == MemberKind.Interface) {
2407 report.Error (531, current_event.Add.Block.StartLocation,
2408 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2411 current_local_parameters = null;
2415 remove_accessor_declaration
2416 : opt_attributes opt_modifiers REMOVE
2418 if ($2 != ModifierNone) {
2419 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2422 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2423 current_local_parameters = current_event.Remove.ParameterInfo;
2425 lbag.AddMember (current_event.Remove, mod_locations);
2426 lexer.EventParsing = false;
2428 event_accessor_block
2430 lexer.EventParsing = true;
2432 current_event.Remove.Block = (ToplevelBlock) $5;
2434 if (current_container.Kind == MemberKind.Interface) {
2435 report.Error (531, current_event.Remove.Block.StartLocation,
2436 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2439 current_local_parameters = null;
2443 event_accessor_block
2446 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2452 attributes_without_members
2453 : attribute_sections CLOSE_BRACE
2455 current_type.UnattachedAttributes = (Attributes) $1;
2456 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2457 lexer.putback ('}');
2464 ENUM type_declaration_name
2468 enumTypeComment = Lexer.consume_doc_comment ();
2473 Lexer.doc_state = XmlCommentState.Allowed;
2475 MemberName name = (MemberName) $4;
2476 if (name.IsGeneric) {
2477 report.Error (1675, name.Location, "Enums cannot have type parameters");
2480 push_current_container (new Enum (current_container, (TypeExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2482 opt_enum_member_declarations
2484 // here will be evaluated after CLOSE_BLACE is consumed.
2486 Lexer.doc_state = XmlCommentState.Allowed;
2488 CLOSE_BRACE opt_semicolon
2491 current_container.DocComment = enumTypeComment;
2493 --lexer.parsing_declaration;
2496 // em.DocComment = ev.DocComment;
2498 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2499 $$ = pop_current_class ();
2507 var te = $2 as TypeExpression;
2508 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2509 Enum.Error_1008 (GetLocation ($2), report);
2517 Error_TypeExpected (GetLocation ($1));
2522 opt_enum_member_declarations
2524 | enum_member_declarations
2525 | enum_member_declarations COMMA
2527 lbag.AddLocation ($1, GetLocation ($2));
2531 enum_member_declarations
2532 : enum_member_declaration
2533 | enum_member_declarations COMMA enum_member_declaration
2535 lbag.AddLocation ($1, GetLocation ($2));
2540 enum_member_declaration
2541 : opt_attributes IDENTIFIER
2543 var lt = (Tokenizer.LocatedToken) $2;
2544 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2545 ((Enum) current_type).AddEnumMember (em);
2548 em.DocComment = Lexer.consume_doc_comment ();
2549 Lexer.doc_state = XmlCommentState.Allowed;
2554 | opt_attributes IDENTIFIER
2556 ++lexer.parsing_block;
2558 tmpComment = Lexer.consume_doc_comment ();
2559 Lexer.doc_state = XmlCommentState.NotAllowed;
2562 ASSIGN constant_expression
2564 --lexer.parsing_block;
2566 var lt = (Tokenizer.LocatedToken) $2;
2567 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2568 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2569 ((Enum) current_type).AddEnumMember (em);
2572 em.DocComment = ConsumeStoredComment ();
2578 delegate_declaration
2582 member_type type_declaration_name
2585 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2587 opt_formal_parameter_list CLOSE_PARENS
2589 valid_param_mod = 0;
2591 ParametersCompiled p = (ParametersCompiled) $8;
2593 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2595 p.CheckParameters (del);
2597 current_container.AddTypeContainer (del);
2599 current_delegate = del;
2600 lexer.ConstraintsParsing = true;
2602 opt_type_parameter_constraints_clauses
2604 lexer.ConstraintsParsing = false;
2609 current_delegate.DocComment = Lexer.consume_doc_comment ();
2610 Lexer.doc_state = XmlCommentState.Allowed;
2614 current_delegate.SetConstraints ((List<Constraints>) $11);
2615 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2617 $$ = current_delegate;
2619 current_delegate = null;
2627 if (lang_version < LanguageVersion.ISO_2)
2628 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2630 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2634 namespace_or_type_expr
2636 | qualified_alias_member IDENTIFIER opt_type_argument_list
2638 var lt1 = (Tokenizer.LocatedToken) $1;
2639 var lt2 = (Tokenizer.LocatedToken) $2;
2641 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2642 lbag.AddLocation ($$, GetLocation ($2));
2648 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2650 var lt = (Tokenizer.LocatedToken) $3;
2651 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2652 lbag.AddLocation ($$, GetLocation ($2));
2657 : IDENTIFIER opt_type_argument_list
2659 var lt = (Tokenizer.LocatedToken) $1;
2660 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2665 // Generics arguments (any type, without attributes)
2667 opt_type_argument_list
2669 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2671 if (lang_version < LanguageVersion.ISO_2)
2672 FeatureIsNotAvailable (GetLocation ($1), "generics");
2676 | OP_GENERICS_LT error
2678 Error_TypeExpected (lexer.Location);
2679 $$ = new TypeArguments ();
2686 TypeArguments type_args = new TypeArguments ();
2687 type_args.Add ((FullNamedExpression) $1);
2690 | type_arguments COMMA type
2692 TypeArguments type_args = (TypeArguments) $1;
2693 type_args.Add ((FullNamedExpression) $3);
2699 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2701 type_declaration_name
2704 lexer.parsing_generic_declaration = true;
2706 opt_type_parameter_list
2708 lexer.parsing_generic_declaration = false;
2709 var lt = (Tokenizer.LocatedToken) $1;
2710 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2714 member_declaration_name
2715 : method_declaration_name
2717 MemberName mn = (MemberName)$1;
2718 if (mn.TypeParameters != null)
2719 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2720 mn.GetSignatureForError ()));
2724 method_declaration_name
2725 : type_declaration_name
2726 | explicit_interface IDENTIFIER opt_type_parameter_list
2728 lexer.parsing_generic_declaration = false;
2729 var lt = (Tokenizer.LocatedToken) $2;
2730 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2734 indexer_declaration_name
2737 lexer.parsing_generic_declaration = false;
2738 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2740 | explicit_interface THIS
2742 lexer.parsing_generic_declaration = false;
2743 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2748 : IDENTIFIER opt_type_argument_list DOT
2750 var lt = (Tokenizer.LocatedToken) $1;
2751 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2752 lbag.AddLocation ($$, GetLocation ($3));
2754 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2756 var lt1 = (Tokenizer.LocatedToken) $1;
2757 var lt2 = (Tokenizer.LocatedToken) $2;
2759 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2760 lbag.AddLocation ($$, GetLocation ($4));
2762 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2764 var lt = (Tokenizer.LocatedToken) $2;
2765 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2766 lbag.AddLocation ($$, GetLocation ($4));
2770 opt_type_parameter_list
2772 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2774 if (lang_version < LanguageVersion.ISO_2)
2775 FeatureIsNotAvailable (GetLocation ($1), "generics");
2778 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2785 var tparams = new TypeParameters ();
2786 tparams.Add ((TypeParameter)$1);
2789 | type_parameters COMMA type_parameter
2791 var tparams = (TypeParameters) $1;
2792 tparams.Add ((TypeParameter)$3);
2794 lbag.AddLocation ($3, GetLocation ($3));
2799 : opt_attributes opt_type_parameter_variance IDENTIFIER
2801 var lt = (Tokenizer.LocatedToken)$3;
2802 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2806 if (GetTokenName (yyToken) == "type")
2807 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2809 Error_SyntaxError (yyToken);
2811 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2816 // All types where void is allowed
2819 : type_expression_or_array
2822 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2829 lexer.parsing_generic_declaration = true;
2834 // A type which does not allow `void' to be used
2837 : type_expression_or_array
2840 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2841 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2849 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2850 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2855 : type_expression_or_array
2858 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2859 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2863 type_expression_or_array
2865 | type_expression rank_specifiers
2867 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2872 : namespace_or_type_expr opt_nullable
2875 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2877 var sn = $1 as SimpleName;
2878 if (sn != null && sn.Name == "var")
2879 $$ = new VarExpr (sn.Location);
2884 | namespace_or_type_expr pointer_stars
2886 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2888 | builtin_types opt_nullable
2891 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2893 | builtin_types pointer_stars
2895 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2897 | VOID pointer_stars
2899 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2906 var types = new List<FullNamedExpression> (2);
2907 types.Add ((FullNamedExpression) $1);
2910 | type_list COMMA base_type_name
2912 var types = (List<FullNamedExpression>) $1;
2913 types.Add ((FullNamedExpression) $3);
2921 if ($1 is ComposedCast) {
2922 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2929 * replaces all the productions for isolating the various
2930 * simple types, but we need this to reuse it easily in variable_type
2933 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2934 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2935 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2936 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2937 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2938 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2943 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2944 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2945 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2946 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2947 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2948 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2949 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2950 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2951 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2955 // Expressions, section 7.5
2960 : primary_expression_or_type
2962 | array_creation_expression
2963 | parenthesized_expression
2964 | default_value_expression
2965 | invocation_expression
2969 | post_increment_expression
2970 | post_decrement_expression
2971 | object_or_delegate_creation_expression
2972 | anonymous_type_expression
2975 | checked_expression
2976 | unchecked_expression
2977 | pointer_member_access
2978 | anonymous_method_expression
2979 | undocumented_expressions
2982 primary_expression_or_type
2983 : IDENTIFIER opt_type_argument_list
2985 var lt = (Tokenizer.LocatedToken) $1;
2986 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2988 | IDENTIFIER GENERATE_COMPLETION {
2989 var lt = (Tokenizer.LocatedToken) $1;
2990 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
2998 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3002 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3003 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3008 // Here is the trick, tokenizer may think that parens is a special but
3009 // parser is interested in open parens only, so we merge them.
3010 // Consider: if (a)foo ();
3018 // Use this production to accept closing parenthesis or
3019 // performing completion
3023 | COMPLETE_COMPLETION
3027 parenthesized_expression
3028 : OPEN_PARENS expression CLOSE_PARENS
3030 $$ = new ParenthesizedExpression ((Expression) $2);
3031 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3033 | OPEN_PARENS expression COMPLETE_COMPLETION
3035 $$ = new ParenthesizedExpression ((Expression) $2);
3040 : primary_expression DOT IDENTIFIER opt_type_argument_list
3042 var lt = (Tokenizer.LocatedToken) $3;
3043 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3044 lbag.AddLocation ($$, GetLocation ($2));
3046 | builtin_types DOT IDENTIFIER opt_type_argument_list
3048 var lt = (Tokenizer.LocatedToken) $3;
3049 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3050 lbag.AddLocation ($$, GetLocation ($2));
3052 | BASE DOT IDENTIFIER opt_type_argument_list
3054 var lt = (Tokenizer.LocatedToken) $3;
3055 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3056 lbag.AddLocation ($$, GetLocation ($2));
3058 | qualified_alias_member IDENTIFIER opt_type_argument_list
3060 var lt1 = (Tokenizer.LocatedToken) $1;
3061 var lt2 = (Tokenizer.LocatedToken) $2;
3063 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3064 lbag.AddLocation ($$, GetLocation ($2));
3066 | primary_expression DOT GENERATE_COMPLETION {
3067 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3069 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3070 var lt = (Tokenizer.LocatedToken) $3;
3071 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3073 | builtin_types DOT GENERATE_COMPLETION
3075 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3077 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3078 var lt = (Tokenizer.LocatedToken) $3;
3079 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3083 invocation_expression
3084 : primary_expression open_parens_any opt_argument_list close_parens
3086 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3087 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3091 opt_object_or_collection_initializer
3092 : /* empty */ { $$ = null; }
3093 | object_or_collection_initializer
3096 object_or_collection_initializer
3097 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3100 $$ = CollectionOrObjectInitializers.Empty;
3103 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3104 lbag.AddLocation ($$, GetLocation ($3));
3107 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3109 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3110 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3114 opt_member_initializer_list
3115 : /* empty */ { $$ = null; }
3116 | member_initializer_list
3122 member_initializer_list
3123 : member_initializer
3125 var a = new List<Expression> ();
3126 a.Add ((Expression) $1);
3129 | member_initializer_list COMMA member_initializer
3131 var a = (List<Expression>)$1;
3132 a.Add ((Expression) $3);
3135 | member_initializer_list error {
3136 Error_SyntaxError (yyToken);
3142 : IDENTIFIER ASSIGN initializer_value
3144 var lt = (Tokenizer.LocatedToken) $1;
3145 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3146 lbag.AddLocation ($$, GetLocation ($2));
3148 | GENERATE_COMPLETION
3150 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3152 | non_assignment_expression opt_COMPLETE_COMPLETION {
3153 CompletionSimpleName csn = $1 as CompletionSimpleName;
3155 $$ = new CollectionElementInitializer ((Expression)$1);
3157 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3159 | OPEN_BRACE expression_list CLOSE_BRACE
3164 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3166 | OPEN_BRACE CLOSE_BRACE
3168 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3175 | object_or_collection_initializer
3179 : /* empty */ { $$ = null; }
3184 : argument_or_named_argument
3186 Arguments list = new Arguments (4);
3187 list.Add ((Argument) $1);
3190 | argument_list COMMA argument
3192 Arguments list = (Arguments) $1;
3193 if (list [list.Count - 1] is NamedArgument)
3194 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3196 list.Add ((Argument) $3);
3199 | argument_list COMMA named_argument
3201 Arguments list = (Arguments) $1;
3202 NamedArgument a = (NamedArgument) $3;
3203 for (int i = 0; i < list.Count; ++i) {
3204 NamedArgument na = list [i] as NamedArgument;
3205 if (na != null && na.Name == a.Name)
3206 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3213 | argument_list COMMA
3215 report.Error (839, GetLocation ($2), "An argument is missing");
3220 report.Error (839, GetLocation ($1), "An argument is missing");
3228 $$ = new Argument ((Expression) $1);
3230 | non_simple_argument
3233 argument_or_named_argument
3239 : REF variable_reference
3241 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3242 lbag.AddLocation ($$, GetLocation ($1));
3244 | OUT variable_reference
3246 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3247 lbag.AddLocation ($$, GetLocation ($1));
3249 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3251 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3252 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3254 | ARGLIST OPEN_PARENS CLOSE_PARENS
3256 $$ = new Argument (new Arglist (GetLocation ($1)));
3257 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3266 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3268 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3269 lbag.AddLocation ($$, GetLocation ($4));
3271 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3273 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3275 | primary_expression OPEN_BRACKET_EXPR error
3277 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3284 var list = new List<Expression> (4);
3285 list.Add ((Expression) $1);
3288 | expression_list COMMA expression
3290 var list = (List<Expression>) $1;
3291 list.Add ((Expression) $3);
3294 | expression_list error {
3295 Error_SyntaxError (yyToken);
3300 expression_list_arguments
3301 : expression_list_argument
3303 Arguments args = new Arguments (4);
3304 args.Add ((Argument) $1);
3307 | expression_list_arguments COMMA expression_list_argument
3309 Arguments args = (Arguments) $1;
3310 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3311 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3313 args.Add ((Argument) $3);
3318 expression_list_argument
3321 $$ = new Argument ((Expression) $1);
3329 $$ = new This (GetLocation ($1));
3334 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3336 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3337 lbag.AddLocation ($$, GetLocation ($4));
3339 | BASE OPEN_BRACKET error
3341 Error_SyntaxError (yyToken);
3342 $$ = new ElementAccess (null, null, GetLocation ($2));
3346 post_increment_expression
3347 : primary_expression OP_INC
3349 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3353 post_decrement_expression
3354 : primary_expression OP_DEC
3356 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3360 object_or_delegate_creation_expression
3361 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3364 if (lang_version <= LanguageVersion.ISO_2)
3365 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3367 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3369 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3372 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3374 | NEW new_expr_type object_or_collection_initializer
3376 if (lang_version <= LanguageVersion.ISO_2)
3377 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3379 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3383 array_creation_expression
3384 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3386 opt_array_initializer
3388 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3389 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3390 Next = (ComposedTypeSpecifier) $6
3391 }, (ArrayInitializer) $7, GetLocation ($1));
3392 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3394 | NEW new_expr_type rank_specifiers opt_array_initializer
3397 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3399 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3401 | NEW rank_specifier array_initializer
3403 if (lang_version <= LanguageVersion.ISO_2)
3404 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3406 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3408 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3410 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3411 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3413 | NEW new_expr_type error
3415 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3416 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3422 ++lexer.parsing_type;
3426 --lexer.parsing_type;
3431 anonymous_type_expression
3432 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3434 if (lang_version <= LanguageVersion.ISO_2)
3435 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3437 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3439 // TODO: lbag comma location
3440 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3444 anonymous_type_parameters_opt_comma
3445 : anonymous_type_parameters_opt
3446 | anonymous_type_parameters COMMA
3449 anonymous_type_parameters_opt
3451 | anonymous_type_parameters
3454 anonymous_type_parameters
3455 : anonymous_type_parameter
3457 var a = new List<AnonymousTypeParameter> (4);
3458 a.Add ((AnonymousTypeParameter) $1);
3461 | anonymous_type_parameters COMMA anonymous_type_parameter
3463 var a = (List<AnonymousTypeParameter>) $1;
3464 a.Add ((AnonymousTypeParameter) $3);
3469 anonymous_type_parameter
3470 : IDENTIFIER ASSIGN variable_initializer
3472 var lt = (Tokenizer.LocatedToken)$1;
3473 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3474 lbag.AddLocation ($$, GetLocation ($2));
3478 var lt = (Tokenizer.LocatedToken)$1;
3479 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3480 lt.Value, lt.Location);
3484 MemberAccess ma = (MemberAccess) $1;
3485 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3489 report.Error (746, lexer.Location,
3490 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3502 | rank_specifier rank_specifiers
3504 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3510 : OPEN_BRACKET CLOSE_BRACKET
3512 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3513 lbag.AddLocation ($$, GetLocation ($2));
3515 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3517 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3518 lbag.AddLocation ($$, GetLocation ($3));
3527 | dim_separators COMMA
3529 $$ = ((int) $1) + 1;
3533 opt_array_initializer
3545 : OPEN_BRACE CLOSE_BRACE
3547 var ai = new ArrayInitializer (0, GetLocation ($1));
3548 ai.VariableDeclaration = current_variable;
3549 lbag.AddLocation (ai, GetLocation ($2));
3552 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3554 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3555 ai.VariableDeclaration = current_variable;
3557 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3559 lbag.AddLocation (ai, GetLocation ($4));
3565 variable_initializer_list
3566 : variable_initializer
3568 var list = new List<Expression> (4);
3569 list.Add ((Expression) $1);
3572 | variable_initializer_list COMMA variable_initializer
3574 var list = (List<Expression>) $1;
3575 list.Add ((Expression) $3);
3583 lexer.TypeOfParsing = true;
3585 open_parens_any typeof_type_expression CLOSE_PARENS
3587 lexer.TypeOfParsing = false;
3588 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3589 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3593 typeof_type_expression
3598 Error_TypeExpected (lexer.Location);
3604 : identifier_inside_body generic_dimension
3606 var lt = (Tokenizer.LocatedToken) $1;
3608 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3610 | qualified_alias_member identifier_inside_body generic_dimension
3612 var lt1 = (Tokenizer.LocatedToken) $1;
3613 var lt2 = (Tokenizer.LocatedToken) $2;
3615 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3616 lbag.AddLocation ($$, GetLocation ($2));
3618 | unbound_type_name DOT identifier_inside_body
3620 var lt = (Tokenizer.LocatedToken) $3;
3622 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3624 | unbound_type_name DOT identifier_inside_body generic_dimension
3626 var lt = (Tokenizer.LocatedToken) $3;
3628 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3630 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3632 var tne = (ATypeNameExpression) $1;
3633 if (tne.HasTypeArguments)
3634 Error_TypeExpected (GetLocation ($4));
3636 var lt = (Tokenizer.LocatedToken) $3;
3637 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3644 if (lang_version < LanguageVersion.ISO_2)
3645 FeatureIsNotAvailable (GetLocation ($1), "generics");
3651 qualified_alias_member
3652 : IDENTIFIER DOUBLE_COLON
3654 var lt = (Tokenizer.LocatedToken) $1;
3655 if (lang_version == LanguageVersion.ISO_1)
3656 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3663 : SIZEOF open_parens_any type CLOSE_PARENS
3665 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3666 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3671 : CHECKED open_parens_any expression CLOSE_PARENS
3673 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3674 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3678 unchecked_expression
3679 : UNCHECKED open_parens_any expression CLOSE_PARENS
3681 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3682 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3686 pointer_member_access
3687 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3689 var lt = (Tokenizer.LocatedToken) $3;
3690 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3694 anonymous_method_expression
3695 : DELEGATE opt_anonymous_method_signature
3697 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3701 $$ = end_anonymous ((ParametersBlock) $4);
3703 | ASYNC DELEGATE opt_anonymous_method_signature
3705 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3709 $$ = end_anonymous ((ParametersBlock) $5);
3713 opt_anonymous_method_signature
3716 $$ = ParametersCompiled.Undefined;
3718 | anonymous_method_signature
3721 anonymous_method_signature
3724 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3726 opt_formal_parameter_list CLOSE_PARENS
3728 valid_param_mod = 0;
3733 default_value_expression
3734 : DEFAULT open_parens_any type CLOSE_PARENS
3736 if (lang_version < LanguageVersion.ISO_2)
3737 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3739 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3740 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3745 : primary_expression
3746 | BANG prefixed_unary_expression
3748 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3750 | TILDE prefixed_unary_expression
3752 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3754 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3756 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3757 lbag.AddLocation ($$, GetLocation ($3));
3759 | AWAIT prefixed_unary_expression
3762 if (current_anonymous_method is LambdaExpression) {
3763 report.Error (4034, GetLocation ($1),
3764 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3765 } else if (current_anonymous_method is AnonymousMethodExpression) {
3766 report.Error (4035, GetLocation ($1),
3767 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3769 report.Error (4033, GetLocation ($1),
3770 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3773 current_block.Explicit.RegisterAsyncAwait ();
3776 $$ = new Await ((Expression) $2, GetLocation ($1));
3781 // The idea to split this out is from Rhys' grammar
3782 // to solve the problem with casts.
3784 prefixed_unary_expression
3786 | PLUS prefixed_unary_expression
3788 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3790 | MINUS prefixed_unary_expression
3792 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3794 | OP_INC prefixed_unary_expression
3796 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3798 | OP_DEC prefixed_unary_expression
3800 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3802 | STAR prefixed_unary_expression
3804 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3806 | BITWISE_AND prefixed_unary_expression
3808 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3812 multiplicative_expression
3813 : prefixed_unary_expression
3814 | multiplicative_expression STAR prefixed_unary_expression
3816 $$ = new Binary (Binary.Operator.Multiply,
3817 (Expression) $1, (Expression) $3, GetLocation ($2));
3819 | multiplicative_expression DIV prefixed_unary_expression
3821 $$ = new Binary (Binary.Operator.Division,
3822 (Expression) $1, (Expression) $3, GetLocation ($2));
3824 | multiplicative_expression PERCENT prefixed_unary_expression
3826 $$ = new Binary (Binary.Operator.Modulus,
3827 (Expression) $1, (Expression) $3, GetLocation ($2));
3832 : multiplicative_expression
3833 | additive_expression PLUS multiplicative_expression
3835 $$ = new Binary (Binary.Operator.Addition,
3836 (Expression) $1, (Expression) $3, GetLocation ($2));
3838 | additive_expression MINUS multiplicative_expression
3840 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3842 | parenthesized_expression MINUS multiplicative_expression
3844 // Shift/Reduce conflict
3845 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3847 | additive_expression AS type
3849 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3851 | additive_expression IS type
3853 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3858 : additive_expression
3859 | shift_expression OP_SHIFT_LEFT additive_expression
3861 $$ = new Binary (Binary.Operator.LeftShift,
3862 (Expression) $1, (Expression) $3, GetLocation ($2));
3864 | shift_expression OP_SHIFT_RIGHT additive_expression
3866 $$ = new Binary (Binary.Operator.RightShift,
3867 (Expression) $1, (Expression) $3, GetLocation ($2));
3871 relational_expression
3873 | relational_expression OP_LT shift_expression
3875 $$ = new Binary (Binary.Operator.LessThan,
3876 (Expression) $1, (Expression) $3, GetLocation ($2));
3878 | relational_expression OP_GT shift_expression
3880 $$ = new Binary (Binary.Operator.GreaterThan,
3881 (Expression) $1, (Expression) $3, GetLocation ($2));
3883 | relational_expression OP_LE shift_expression
3885 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3886 (Expression) $1, (Expression) $3, GetLocation ($2));
3888 | relational_expression OP_GE shift_expression
3890 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3891 (Expression) $1, (Expression) $3, GetLocation ($2));
3896 : relational_expression
3897 | equality_expression OP_EQ relational_expression
3899 $$ = new Binary (Binary.Operator.Equality,
3900 (Expression) $1, (Expression) $3, GetLocation ($2));
3902 | equality_expression OP_NE relational_expression
3904 $$ = new Binary (Binary.Operator.Inequality,
3905 (Expression) $1, (Expression) $3, GetLocation ($2));
3910 : equality_expression
3911 | and_expression BITWISE_AND equality_expression
3913 $$ = new Binary (Binary.Operator.BitwiseAnd,
3914 (Expression) $1, (Expression) $3, GetLocation ($2));
3918 exclusive_or_expression
3920 | exclusive_or_expression CARRET and_expression
3922 $$ = new Binary (Binary.Operator.ExclusiveOr,
3923 (Expression) $1, (Expression) $3, GetLocation ($2));
3927 inclusive_or_expression
3928 : exclusive_or_expression
3929 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3931 $$ = new Binary (Binary.Operator.BitwiseOr,
3932 (Expression) $1, (Expression) $3, GetLocation ($2));
3936 conditional_and_expression
3937 : inclusive_or_expression
3938 | conditional_and_expression OP_AND inclusive_or_expression
3940 $$ = new Binary (Binary.Operator.LogicalAnd,
3941 (Expression) $1, (Expression) $3, GetLocation ($2));
3945 conditional_or_expression
3946 : conditional_and_expression
3947 | conditional_or_expression OP_OR conditional_and_expression
3949 $$ = new Binary (Binary.Operator.LogicalOr,
3950 (Expression) $1, (Expression) $3, GetLocation ($2));
3954 null_coalescing_expression
3955 : conditional_or_expression
3956 | conditional_or_expression OP_COALESCING null_coalescing_expression
3958 if (lang_version < LanguageVersion.ISO_2)
3959 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3961 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3965 conditional_expression
3966 : null_coalescing_expression
3967 | null_coalescing_expression INTERR expression COLON expression_or_error
3969 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3970 lbag.AddLocation ($$, GetLocation ($4));
3974 assignment_expression
3975 : prefixed_unary_expression ASSIGN expression
3977 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3979 | prefixed_unary_expression OP_MULT_ASSIGN expression
3981 $$ = new CompoundAssign (
3982 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3984 | prefixed_unary_expression OP_DIV_ASSIGN expression
3986 $$ = new CompoundAssign (
3987 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3989 | prefixed_unary_expression OP_MOD_ASSIGN expression
3991 $$ = new CompoundAssign (
3992 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
3994 | prefixed_unary_expression OP_ADD_ASSIGN expression
3996 $$ = new CompoundAssign (
3997 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
3999 | prefixed_unary_expression OP_SUB_ASSIGN expression
4001 $$ = new CompoundAssign (
4002 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4004 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4006 $$ = new CompoundAssign (
4007 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4009 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4011 $$ = new CompoundAssign (
4012 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4014 | prefixed_unary_expression OP_AND_ASSIGN expression
4016 $$ = new CompoundAssign (
4017 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4019 | prefixed_unary_expression OP_OR_ASSIGN expression
4021 $$ = new CompoundAssign (
4022 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4024 | prefixed_unary_expression OP_XOR_ASSIGN expression
4026 $$ = new CompoundAssign (
4027 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4031 lambda_parameter_list
4034 var pars = new List<Parameter> (4);
4035 pars.Add ((Parameter) $1);
4039 | lambda_parameter_list COMMA lambda_parameter
4041 var pars = (List<Parameter>) $1;
4042 Parameter p = (Parameter)$3;
4043 if (pars[0].GetType () != p.GetType ()) {
4044 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4053 : parameter_modifier parameter_type identifier_inside_body
4055 var lt = (Tokenizer.LocatedToken) $3;
4057 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4059 | parameter_type identifier_inside_body
4061 var lt = (Tokenizer.LocatedToken) $2;
4063 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4067 var lt = (Tokenizer.LocatedToken) $1;
4068 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4072 opt_lambda_parameter_list
4073 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4074 | lambda_parameter_list {
4075 var pars_list = (List<Parameter>) $1;
4076 $$ = new ParametersCompiled (pars_list.ToArray ());
4080 lambda_expression_body
4081 : lambda_expression_body_simple
4085 lambda_expression_body_simple
4087 start_block (Location.Null);
4089 expression_or_error // Have to close block when error occurs
4091 Block b = end_block (Location.Null);
4092 b.IsCompilerGenerated = true;
4093 b.AddStatement (new ContextualReturn ((Expression) $2));
4102 Error_SyntaxError (yyToken);
4103 $$ = EmptyExpression.Null;
4110 var lt = (Tokenizer.LocatedToken) $1;
4111 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4112 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4114 lambda_expression_body
4116 $$ = end_anonymous ((ParametersBlock) $4);
4117 lbag.AddLocation ($$, GetLocation ($2));
4119 | ASYNC identifier_inside_body ARROW
4121 var lt = (Tokenizer.LocatedToken) $2;
4122 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4123 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4125 lambda_expression_body
4127 $$ = end_anonymous ((ParametersBlock) $5);
4128 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4130 | OPEN_PARENS_LAMBDA
4132 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4134 opt_lambda_parameter_list CLOSE_PARENS ARROW
4136 valid_param_mod = 0;
4137 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4139 lambda_expression_body
4141 $$ = end_anonymous ((ParametersBlock) $7);
4142 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4144 | ASYNC OPEN_PARENS_LAMBDA
4146 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4148 opt_lambda_parameter_list CLOSE_PARENS ARROW
4150 valid_param_mod = 0;
4151 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4153 lambda_expression_body
4155 $$ = end_anonymous ((ParametersBlock) $8);
4156 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4161 : assignment_expression
4162 | non_assignment_expression
4165 non_assignment_expression
4166 : conditional_expression
4171 $$ = new ArglistAccess (GetLocation ($1));
4175 undocumented_expressions
4176 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4178 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4179 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4181 | REFTYPE open_parens_any expression CLOSE_PARENS
4183 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4184 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4186 | MAKEREF open_parens_any expression CLOSE_PARENS
4188 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4189 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4200 $$ = new BooleanExpression ((Expression) $1);
4213 lexer.ConstraintsParsing = true;
4215 type_declaration_name
4217 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4218 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4219 FeatureIsNotAvailable (c.Location, "static classes");
4222 push_current_container (c, $3);
4225 opt_type_parameter_constraints_clauses
4227 lexer.ConstraintsParsing = false;
4230 current_container.SetConstraints ((List<Constraints>) $9);
4231 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4234 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4235 Lexer.doc_state = XmlCommentState.Allowed;
4238 lexer.parsing_modifiers = true;
4240 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4242 --lexer.parsing_declaration;
4244 Lexer.doc_state = XmlCommentState.Allowed;
4248 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4249 $$ = pop_current_class ();
4257 { $$ = $1; } // location
4263 mod_locations = null;
4265 lexer.parsing_modifiers = false;
4269 lexer.parsing_modifiers = false;
4275 | modifiers modifier
4277 var m1 = (Modifiers) $1;
4278 var m2 = (Modifiers) $2;
4280 if ((m1 & m2) != 0) {
4281 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4282 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4283 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4284 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4285 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4286 "More than one protection modifier specified");
4297 StoreModifierLocation ($$, GetLocation ($1));
4299 if (current_container.Kind == MemberKind.Namespace)
4300 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4304 $$ = Modifiers.PUBLIC;
4305 StoreModifierLocation ($$, GetLocation ($1));
4309 $$ = Modifiers.PROTECTED;
4310 StoreModifierLocation ($$, GetLocation ($1));
4314 $$ = Modifiers.INTERNAL;
4315 StoreModifierLocation ($$, GetLocation ($1));
4319 $$ = Modifiers.PRIVATE;
4320 StoreModifierLocation ($$, GetLocation ($1));
4324 $$ = Modifiers.ABSTRACT;
4325 StoreModifierLocation ($$, GetLocation ($1));
4329 $$ = Modifiers.SEALED;
4330 StoreModifierLocation ($$, GetLocation ($1));
4334 $$ = Modifiers.STATIC;
4335 StoreModifierLocation ($$, GetLocation ($1));
4339 $$ = Modifiers.READONLY;
4340 StoreModifierLocation ($$, GetLocation ($1));
4344 $$ = Modifiers.VIRTUAL;
4345 StoreModifierLocation ($$, GetLocation ($1));
4349 $$ = Modifiers.OVERRIDE;
4350 StoreModifierLocation ($$, GetLocation ($1));
4354 $$ = Modifiers.EXTERN;
4355 StoreModifierLocation ($$, GetLocation ($1));
4359 $$ = Modifiers.VOLATILE;
4360 StoreModifierLocation ($$, GetLocation ($1));
4364 $$ = Modifiers.UNSAFE;
4365 StoreModifierLocation ($$, GetLocation ($1));
4366 if (!settings.Unsafe)
4367 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4371 $$ = Modifiers.ASYNC;
4372 StoreModifierLocation ($$, GetLocation ($1));
4380 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4382 | COLON type_list error
4384 Error_SyntaxError (yyToken);
4386 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4390 opt_type_parameter_constraints_clauses
4392 | type_parameter_constraints_clauses
4398 type_parameter_constraints_clauses
4399 : type_parameter_constraints_clause
4401 var constraints = new List<Constraints> (1);
4402 constraints.Add ((Constraints) $1);
4405 | type_parameter_constraints_clauses type_parameter_constraints_clause
4407 var constraints = (List<Constraints>) $1;
4408 Constraints new_constraint = (Constraints)$2;
4410 foreach (Constraints c in constraints) {
4411 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4412 report.Error (409, new_constraint.Location,
4413 "A constraint clause has already been specified for type parameter `{0}'",
4414 new_constraint.TypeParameter.Value);
4418 constraints.Add (new_constraint);
4423 type_parameter_constraints_clause
4424 : WHERE IDENTIFIER COLON type_parameter_constraints
4426 var lt = (Tokenizer.LocatedToken) $2;
4427 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4428 lbag.AddLocation ($$, GetLocation ($3));
4430 | WHERE IDENTIFIER error
4432 Error_SyntaxError (yyToken);
4434 var lt = (Tokenizer.LocatedToken) $2;
4435 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4439 type_parameter_constraints
4440 : type_parameter_constraint
4442 var constraints = new List<FullNamedExpression> (1);
4443 constraints.Add ((FullNamedExpression) $1);
4446 | type_parameter_constraints COMMA type_parameter_constraint
4448 var constraints = (List<FullNamedExpression>) $1;
4449 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4450 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4451 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4454 prev = $3 as SpecialContraintExpr;
4456 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4457 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4459 prev = constraints [0] as SpecialContraintExpr;
4460 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4461 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4466 constraints.Add ((FullNamedExpression) $3);
4471 type_parameter_constraint
4474 if ($1 is ComposedCast)
4475 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4479 | NEW OPEN_PARENS CLOSE_PARENS
4481 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4482 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4486 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4490 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4494 opt_type_parameter_variance
4499 | type_parameter_variance
4501 if (lang_version <= LanguageVersion.V_3)
4502 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4508 type_parameter_variance
4511 $$ = Variance.Covariant;
4515 $$ = Variance.Contravariant;
4524 // A block is "contained" on the following places:
4526 // property_declaration as part of the accessor body (get/set)
4527 // operator_declaration
4528 // constructor_declaration
4529 // destructor_declaration
4530 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4535 ++lexer.parsing_block;
4536 start_block (GetLocation ($1));
4538 opt_statement_list block_end
4547 --lexer.parsing_block;
4548 $$ = end_block (GetLocation ($1));
4550 | COMPLETE_COMPLETION
4552 --lexer.parsing_block;
4553 $$ = end_block (lexer.Location);
4561 ++lexer.parsing_block;
4562 current_block.StartLocation = GetLocation ($1);
4564 opt_statement_list CLOSE_BRACE
4566 --lexer.parsing_block;
4567 $$ = end_block (GetLocation ($4));
4578 | statement_list statement
4582 : block_variable_declaration
4584 current_block.AddStatement ((Statement) $1);
4586 | valid_declaration_statement
4588 current_block.AddStatement ((Statement) $1);
4593 Error_SyntaxError (yyToken);
4599 // The interactive_statement and its derivatives are only
4600 // used to provide a special version of `expression_statement'
4601 // that has a side effect of assigning the expression to
4604 interactive_statement_list
4605 : interactive_statement
4606 | interactive_statement_list interactive_statement
4609 interactive_statement
4610 : block_variable_declaration
4612 current_block.AddStatement ((Statement) $1);
4614 | interactive_valid_declaration_statement
4616 current_block.AddStatement ((Statement) $1);
4621 valid_declaration_statement
4624 | expression_statement
4625 | selection_statement
4626 | iteration_statement
4630 | unchecked_statement
4637 interactive_valid_declaration_statement
4640 | interactive_expression_statement
4641 | selection_statement
4642 | iteration_statement
4646 | unchecked_statement
4654 : valid_declaration_statement
4655 | block_variable_declaration
4657 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4662 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4667 Error_SyntaxError (yyToken);
4668 $$ = new EmptyStatement (GetLocation ($1));
4675 // Uses lexer.Location because semicolon location is not kept in quick mode
4676 $$ = new EmptyStatement (lexer.Location);
4681 : identifier_inside_body COLON
4683 var lt = (Tokenizer.LocatedToken) $1;
4684 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4685 lbag.AddLocation (labeled, GetLocation ($2));
4686 current_block.AddLabel (labeled);
4687 current_block.AddStatement (labeled);
4693 : variable_type_simple
4694 | variable_type_simple rank_specifiers
4697 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4699 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4704 * The following is from Rhys' grammar:
4705 * > Types in local variable declarations must be recognized as
4706 * > expressions to prevent reduce/reduce errors in the grammar.
4707 * > The expressions are converted into types during semantic analysis.
4709 variable_type_simple
4710 : primary_expression_or_type opt_nullable
4712 // Ok, the above "primary_expression" is there to get rid of
4713 // both reduce/reduce and shift/reduces in the grammar, it should
4714 // really just be "type_name". If you use type_name, a reduce/reduce
4715 // creeps up. If you use namespace_or_type_name (which is all we need
4716 // really) two shift/reduces appear.
4719 // So the super-trick is that primary_expression
4720 // can only be either a SimpleName or a MemberAccess.
4721 // The MemberAccess case arises when you have a fully qualified type-name like :
4723 // SimpleName is when you have
4726 Expression expr = (Expression) $1;
4728 SimpleName sn = expr as SimpleName;
4729 if (sn != null && sn.Name == "var")
4730 $$ = new VarExpr (sn.Location);
4733 } else if (expr is ATypeNameExpression) {
4734 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4736 Error_ExpectingTypeName (expr);
4740 | primary_expression_or_type pointer_stars
4742 ATypeNameExpression expr = $1 as ATypeNameExpression;
4745 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4747 Error_ExpectingTypeName ((Expression)$1);
4751 | builtin_types opt_nullable
4756 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4758 | builtin_types pointer_stars
4760 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4762 | VOID pointer_stars
4764 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4768 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4769 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4775 | pointer_star pointer_stars
4777 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4785 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4789 identifier_inside_body
4794 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
4795 $$ = Tokenizer.LocatedToken.Create ("await", GetLocation ($1));
4800 block_variable_declaration
4801 : variable_type identifier_inside_body
4803 var lt = (Tokenizer.LocatedToken) $2;
4804 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4805 current_block.AddLocalName (li);
4806 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4808 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4810 $$ = current_variable;
4811 current_variable = null;
4812 lbag.AddLocation ($$, GetLocation ($6));
4814 | CONST variable_type identifier_inside_body
4816 var lt = (Tokenizer.LocatedToken) $3;
4817 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4818 current_block.AddLocalName (li);
4819 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4821 const_variable_initializer opt_const_declarators SEMICOLON
4823 $$ = current_variable;
4824 current_variable = null;
4825 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4829 opt_local_variable_initializer
4831 | ASSIGN block_variable_initializer
4833 current_variable.Initializer = (Expression) $2;
4838 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4839 report.Error (650, lexer.Location,
4840 "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");
4842 Error_SyntaxError (yyToken);
4847 opt_variable_declarators
4849 | variable_declarators
4852 opt_using_or_fixed_variable_declarators
4854 | variable_declarators
4856 foreach (var d in current_variable.Declarators) {
4857 if (d.Initializer == null)
4858 Error_MissingInitializer (d.Variable.Location);
4863 variable_declarators
4864 : variable_declarator
4865 | variable_declarators variable_declarator
4869 : COMMA identifier_inside_body
4871 var lt = (Tokenizer.LocatedToken) $2;
4872 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4873 var d = new BlockVariableDeclaration.Declarator (li, null);
4874 current_variable.AddDeclarator (d);
4875 current_block.AddLocalName (li);
4876 lbag.AddLocation (d, GetLocation ($1));
4878 | COMMA identifier_inside_body ASSIGN block_variable_initializer
4880 var lt = (Tokenizer.LocatedToken) $2;
4881 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4882 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4883 current_variable.AddDeclarator (d);
4884 current_block.AddLocalName (li);
4885 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4889 const_variable_initializer
4892 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4894 | ASSIGN constant_initializer_expr
4896 current_variable.Initializer = (Expression) $2;
4900 opt_const_declarators
4907 | const_declarators const_declarator
4911 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
4913 var lt = (Tokenizer.LocatedToken) $2;
4914 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4915 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4916 current_variable.AddDeclarator (d);
4917 current_block.AddLocalName (li);
4918 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4922 block_variable_initializer
4923 : variable_initializer
4924 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4926 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4927 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4929 | STACKALLOC simple_type
4931 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4932 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4936 expression_statement
4937 : statement_expression SEMICOLON
4940 lbag.AddStatement ($$, GetLocation ($2));
4942 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4943 | statement_expression CLOSE_BRACE
4946 report.Error (1002, GetLocation ($2), "; expected");
4947 lexer.putback ('}');
4951 interactive_expression_statement
4952 : interactive_statement_expression SEMICOLON { $$ = $1; }
4953 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4957 // We have to do the wrapping here and not in the case above,
4958 // because statement_expression is used for example in for_statement
4960 statement_expression
4963 ExpressionStatement s = $1 as ExpressionStatement;
4965 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4966 $$ = new StatementErrorExpression ($1 as Expression);
4968 $$ = new StatementExpression (s);
4973 interactive_statement_expression
4976 Expression expr = (Expression) $1;
4977 ExpressionStatement s;
4979 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4980 $$ = new StatementExpression (s);
4984 Error_SyntaxError (yyToken);
4985 $$ = new EmptyStatement (GetLocation ($1));
4995 : IF open_parens_any boolean_expression CLOSE_PARENS
4998 if ($5 is EmptyStatement)
4999 Warning_EmptyStatement (GetLocation ($5));
5001 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5002 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5004 | IF open_parens_any boolean_expression CLOSE_PARENS
5005 embedded_statement ELSE embedded_statement
5007 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5008 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5010 if ($5 is EmptyStatement)
5011 Warning_EmptyStatement (GetLocation ($5));
5012 if ($7 is EmptyStatement)
5013 Warning_EmptyStatement (GetLocation ($7));
5015 | IF open_parens_any boolean_expression error
5017 Error_SyntaxError (yyToken);
5019 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5020 lbag.AddStatement ($$, GetLocation ($2));
5025 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5027 start_block (GetLocation ($5));
5029 opt_switch_sections CLOSE_BRACE
5031 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5032 end_block (GetLocation ($8));
5033 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5035 | SWITCH open_parens_any expression error
5037 Error_SyntaxError (yyToken);
5039 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5040 lbag.AddStatement ($$, GetLocation ($2));
5047 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5048 $$ = new List<SwitchSection> ();
5056 var sections = new List<SwitchSection> (4);
5058 sections.Add ((SwitchSection) $1);
5061 | switch_sections switch_section
5063 var sections = (List<SwitchSection>) $1;
5065 sections.Add ((SwitchSection) $2);
5070 Error_SyntaxError (yyToken);
5071 $$ = new List<SwitchSection> ();
5078 current_block = current_block.CreateSwitchBlock (lexer.Location);
5082 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5089 var labels = new List<SwitchLabel> (2);
5091 labels.Add ((SwitchLabel) $1);
5094 | switch_labels switch_label
5096 var labels = (List<SwitchLabel>) ($1);
5097 labels.Add ((SwitchLabel) $2);
5104 : CASE constant_expression COLON
5106 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5107 lbag.AddLocation ($$, GetLocation ($3));
5111 $$ = new SwitchLabel (null, GetLocation ($1));
5123 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5125 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5126 Warning_EmptyStatement (GetLocation ($5));
5128 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5129 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5131 | WHILE open_parens_any boolean_expression error
5133 Error_SyntaxError (yyToken);
5135 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5136 lbag.AddStatement ($$, GetLocation ($2));
5141 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5143 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5144 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5146 | DO embedded_statement error
5148 Error_SyntaxError (yyToken);
5149 $$ = new Do ((Statement) $2, null, GetLocation ($1));
5151 | DO embedded_statement WHILE open_parens_any boolean_expression error
5153 Error_SyntaxError (yyToken);
5155 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5156 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5161 : FOR open_parens_any
5163 start_block (GetLocation ($2));
5164 current_block.IsCompilerGenerated = true;
5165 For f = new For (GetLocation ($1));
5166 current_block.AddStatement (f);
5175 // Has to use be extra rule to recover started block
5177 : opt_for_initializer SEMICOLON
5179 ((For) $0).Initializer = (Statement) $1;
5181 // Pass the "For" object to the iterator_part4
5182 oob_stack.Push ($0);
5184 for_condition_and_iterator_part
5187 var locations = (Tuple<Location,Location>) $4;
5189 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5190 Warning_EmptyStatement (GetLocation ($5));
5193 f.Statement = (Statement) $5;
5194 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5196 $$ = end_block (GetLocation ($2));
5200 Error_SyntaxError (yyToken);
5201 $$ = end_block (current_block.StartLocation);
5205 for_condition_and_iterator_part
5206 : opt_for_condition SEMICOLON
5208 For f = (For) oob_stack.Peek ();
5209 f.Condition = (BooleanExpression) $1;
5212 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5215 // Handle errors in the case of opt_for_condition being followed by
5216 // a close parenthesis
5217 | opt_for_condition close_parens_close_brace {
5218 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ';'");
5219 For f = (For) oob_stack.Peek ();
5220 f.Condition = (BooleanExpression) $1;
5221 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5226 : opt_for_iterator CLOSE_PARENS {
5227 For f = (For) oob_stack.Peek ();
5228 f.Iterator = (Statement) $1;
5229 $$ = GetLocation ($2);
5231 | opt_for_iterator CLOSE_BRACE {
5232 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5233 For f = (For) oob_stack.Peek ();
5234 f.Iterator = (Statement) $1;
5235 $$ = GetLocation ($2);
5239 close_parens_close_brace
5241 | CLOSE_BRACE { lexer.putback ('}'); }
5245 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5250 : variable_type identifier_inside_body
5252 var lt = (Tokenizer.LocatedToken) $2;
5253 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5254 current_block.AddLocalName (li);
5255 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5257 opt_local_variable_initializer opt_variable_declarators
5259 $$ = current_variable;
5260 current_variable = null;
5262 | statement_expression_list
5266 : /* empty */ { $$ = null; }
5267 | boolean_expression
5271 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5276 : statement_expression_list
5279 statement_expression_list
5280 : statement_expression
5281 | statement_expression_list COMMA statement_expression
5283 var sl = $1 as StatementList;
5285 sl = new StatementList ((Statement) $1, (Statement) $3);
5286 lbag.AddStatement (sl, GetLocation ($2));
5288 sl.Add ((Statement) $3);
5289 lbag.AppendTo (sl, GetLocation ($2));
5297 : FOREACH open_parens_any type error
5299 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5301 start_block (GetLocation ($2));
5302 current_block.IsCompilerGenerated = true;
5304 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5305 current_block.AddStatement (f);
5307 lbag.AddStatement (f, GetLocation ($2));
5308 $$ = end_block (GetLocation ($4));
5310 | FOREACH open_parens_any type identifier_inside_body error
5312 Error_SyntaxError (yyToken);
5314 start_block (GetLocation ($2));
5315 current_block.IsCompilerGenerated = true;
5317 var lt = (Tokenizer.LocatedToken) $4;
5318 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5319 current_block.AddLocalName (li);
5321 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5322 current_block.AddStatement (f);
5324 lbag.AddStatement (f, GetLocation ($2));
5325 $$ = end_block (GetLocation ($5));
5327 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5329 start_block (GetLocation ($2));
5330 current_block.IsCompilerGenerated = true;
5332 var lt = (Tokenizer.LocatedToken) $4;
5333 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5334 current_block.AddLocalName (li);
5339 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5340 Warning_EmptyStatement (GetLocation ($9));
5342 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5343 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5344 end_block (GetLocation ($7));
5352 | continue_statement
5362 $$ = new Break (GetLocation ($1));
5363 lbag.AddStatement ($$, GetLocation ($2));
5368 : CONTINUE SEMICOLON
5370 $$ = new Continue (GetLocation ($1));
5371 lbag.AddStatement ($$, GetLocation ($2));
5376 : GOTO identifier_inside_body SEMICOLON
5378 var lt = (Tokenizer.LocatedToken) $2;
5379 $$ = new Goto (lt.Value, GetLocation ($1));
5380 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5382 | GOTO CASE constant_expression SEMICOLON
5384 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5385 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5387 | GOTO DEFAULT SEMICOLON
5389 $$ = new GotoDefault (GetLocation ($1));
5390 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5395 : RETURN opt_expression SEMICOLON
5397 $$ = new Return ((Expression) $2, GetLocation ($1));
5398 lbag.AddStatement ($$, GetLocation ($3));
5403 : THROW opt_expression SEMICOLON
5405 $$ = new Throw ((Expression) $2, GetLocation ($1));
5406 lbag.AddStatement ($$, GetLocation ($3));
5411 : identifier_inside_body RETURN opt_expression SEMICOLON
5413 var lt = (Tokenizer.LocatedToken) $1;
5414 string s = lt.Value;
5416 report.Error (1003, lt.Location, "; expected");
5417 } else if ($3 == null) {
5418 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5419 } else if (lang_version == LanguageVersion.ISO_1){
5420 FeatureIsNotAvailable (lt.Location, "iterators");
5423 current_block.Explicit.RegisterIteratorYield ();
5424 $$ = new Yield ((Expression) $3, lt.Location);
5425 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5427 | identifier_inside_body BREAK SEMICOLON
5429 var lt = (Tokenizer.LocatedToken) $1;
5430 string s = lt.Value;
5432 report.Error (1003, lt.Location, "; expected");
5433 } else if (lang_version == LanguageVersion.ISO_1){
5434 FeatureIsNotAvailable (lt.Location, "iterators");
5437 current_block.Explicit.RegisterIteratorYield ();
5438 $$ = new YieldBreak (lt.Location);
5439 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5449 : TRY block catch_clauses
5451 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5453 | TRY block FINALLY block
5455 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5456 lbag.AddStatement ($$, GetLocation ($3));
5458 | TRY block catch_clauses FINALLY block
5460 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5461 lbag.AddStatement ($$, GetLocation ($4));
5465 Error_SyntaxError (1524, yyToken);
5466 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5473 var l = new List<Catch> (2);
5478 | catch_clauses catch_clause
5480 var l = (List<Catch>) $1;
5482 Catch c = (Catch) $2;
5483 if (l [l.Count - 1].IsGeneral) {
5484 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5494 | identifier_inside_body
5500 $$ = new Catch ((Block) $2, GetLocation ($1));
5502 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5504 start_block (GetLocation ($2));
5505 var c = new Catch (current_block, GetLocation ($1));
5506 c.TypeExpression = (FullNamedExpression) $3;
5509 var lt = (Tokenizer.LocatedToken) $4;
5510 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5511 current_block.AddLocalName (c.Variable);
5514 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5521 | CATCH open_parens_any error
5523 if (yyToken == Token.CLOSE_PARENS) {
5524 report.Error (1015, lexer.Location,
5525 "A type that derives from `System.Exception', `object', or `string' expected");
5527 Error_SyntaxError (yyToken);
5530 $$ = new Catch (null, GetLocation ($1));
5537 $$ = new Checked ((Block) $2, GetLocation ($1));
5544 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5551 if (!settings.Unsafe)
5552 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5554 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5559 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5561 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5562 Warning_EmptyStatement (GetLocation ($5));
5564 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5565 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5567 | LOCK open_parens_any expression error
5569 Error_SyntaxError (yyToken);
5571 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5572 lbag.AddStatement ($$, GetLocation ($2));
5577 : FIXED open_parens_any variable_type identifier_inside_body
5579 start_block (GetLocation ($2));
5581 current_block.IsCompilerGenerated = true;
5582 var lt = (Tokenizer.LocatedToken) $4;
5583 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5584 current_block.AddLocalName (li);
5585 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5587 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5589 $$ = current_variable;
5590 current_variable = null;
5594 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5595 Warning_EmptyStatement (GetLocation ($10));
5597 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5598 current_block.AddStatement (f);
5599 $$ = end_block (GetLocation ($8));
5604 : USING open_parens_any variable_type identifier_inside_body
5606 start_block (GetLocation ($2));
5608 current_block.IsCompilerGenerated = true;
5609 var lt = (Tokenizer.LocatedToken) $4;
5610 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5611 current_block.AddLocalName (li);
5612 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5614 using_initialization CLOSE_PARENS
5616 $$ = current_variable;
5617 current_variable = null;
5621 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5622 Warning_EmptyStatement (GetLocation ($9));
5624 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
5625 current_block.AddStatement (u);
5626 $$ = end_block (GetLocation ($7));
5628 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5630 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5631 Warning_EmptyStatement (GetLocation ($5));
5633 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5634 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5636 | USING open_parens_any expression error
5638 Error_SyntaxError (yyToken);
5640 $$ = new Using ((Expression) $3, null, GetLocation ($1));
5641 lbag.AddStatement ($$, GetLocation ($2));
5645 using_initialization
5646 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
5649 // It has to be here for the parent to safely restore artificial block
5650 Error_SyntaxError (yyToken);
5654 using_or_fixed_variable_initializer
5657 Error_MissingInitializer (lexer.Location);
5659 | ASSIGN variable_initializer
5661 current_variable.Initializer = (Expression) $2;
5662 $$ = current_variable;
5670 : first_from_clause query_body
5672 lexer.query_parsing = false;
5674 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5676 from.Tail.Next = (Linq.AQueryClause)$2;
5679 current_block.SetEndLocation (lexer.Location);
5680 current_block = current_block.Parent;
5682 | nested_from_clause query_body
5684 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5686 from.Tail.Next = (Linq.AQueryClause)$2;
5689 current_block.SetEndLocation (lexer.Location);
5690 current_block = current_block.Parent;
5693 // Bubble up COMPLETE_COMPLETION productions
5694 | first_from_clause COMPLETE_COMPLETION {
5695 lexer.query_parsing = false;
5698 current_block.SetEndLocation (lexer.Location);
5699 current_block = current_block.Parent;
5701 | nested_from_clause COMPLETE_COMPLETION {
5703 current_block.SetEndLocation (lexer.Location);
5704 current_block = current_block.Parent;
5709 : FROM_FIRST identifier_inside_body IN expression
5711 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5713 var lt = (Tokenizer.LocatedToken) $2;
5714 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5715 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5717 | FROM_FIRST type identifier_inside_body IN expression
5719 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5721 var lt = (Tokenizer.LocatedToken) $3;
5722 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5723 $$ = new Linq.QueryExpression (
5724 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5725 IdentifierType = (FullNamedExpression)$2
5732 : FROM identifier_inside_body IN expression
5734 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5736 var lt = (Tokenizer.LocatedToken) $2;
5737 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5738 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5740 | FROM type identifier_inside_body IN expression
5742 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5744 var lt = (Tokenizer.LocatedToken) $3;
5745 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5746 $$ = new Linq.QueryExpression (
5747 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5748 IdentifierType = (FullNamedExpression)$2
5755 : FROM identifier_inside_body IN
5757 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5761 var lt = (Tokenizer.LocatedToken) $2;
5762 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5763 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5765 current_block.SetEndLocation (lexer.Location);
5766 current_block = current_block.Parent;
5768 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5770 | FROM type identifier_inside_body IN
5772 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5776 var lt = (Tokenizer.LocatedToken) $3;
5777 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5779 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5780 IdentifierType = (FullNamedExpression)$2
5783 current_block.SetEndLocation (lexer.Location);
5784 current_block = current_block.Parent;
5786 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5791 : query_body_clauses select_or_group_clause opt_query_continuation
5793 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5796 head.Next = (Linq.AQueryClause)$3;
5799 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5800 clause.Tail.Next = head;
5806 | select_or_group_clause opt_query_continuation
5808 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5811 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5812 clause.Tail.Next = head;
5818 | query_body_clauses COMPLETE_COMPLETION
5819 | query_body_clauses error
5821 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
5826 Error_SyntaxError (yyToken);
5831 select_or_group_clause
5834 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5838 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5840 current_block.SetEndLocation (lexer.Location);
5841 current_block = current_block.Parent;
5845 if (linq_clause_blocks == null)
5846 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5848 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5849 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5853 current_block.SetEndLocation (lexer.Location);
5854 current_block = current_block.Parent;
5856 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5858 BY expression_or_error
5860 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5861 lbag.AddLocation ($$, GetLocation ($5));
5863 current_block.SetEndLocation (lexer.Location);
5864 current_block = current_block.Parent;
5870 | query_body_clauses query_body_clause
5872 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5886 : LET identifier_inside_body ASSIGN
5888 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5892 var lt = (Tokenizer.LocatedToken) $2;
5893 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5894 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5895 lbag.AddLocation ($$, GetLocation ($3));
5897 current_block.SetEndLocation (lexer.Location);
5898 current_block = current_block.Parent;
5900 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5907 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5911 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5913 current_block.SetEndLocation (lexer.Location);
5914 current_block = current_block.Parent;
5919 : JOIN identifier_inside_body IN
5921 if (linq_clause_blocks == null)
5922 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5924 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5925 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5927 expression_or_error ON
5929 current_block.SetEndLocation (lexer.Location);
5930 current_block = current_block.Parent;
5932 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5933 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5935 expression_or_error EQUALS
5937 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5938 current_block.SetEndLocation (lexer.Location);
5939 current_block = current_block.Parent;
5941 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5943 expression_or_error opt_join_into
5945 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5946 current_block.SetEndLocation (lexer.Location);
5948 var outer_selector = linq_clause_blocks.Pop ();
5949 var block = linq_clause_blocks.Pop ();
5951 var lt = (Tokenizer.LocatedToken) $2;
5952 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5953 Linq.RangeVariable into;
5957 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5958 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
5961 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5963 var parent = block.Parent;
5964 while (parent is Linq.QueryBlock) {
5965 parent = parent.Parent;
5967 current_block.Parent = parent;
5969 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5971 lt = (Tokenizer.LocatedToken) $12;
5972 into = new Linq.RangeVariable (lt.Value, lt.Location);
5974 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5975 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
5978 current_block = block.Parent;
5979 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5981 | JOIN type identifier_inside_body IN
5983 if (linq_clause_blocks == null)
5984 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5986 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5987 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5989 expression_or_error ON
5991 current_block.SetEndLocation (lexer.Location);
5992 current_block = current_block.Parent;
5994 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5995 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5997 expression_or_error EQUALS
5999 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6000 current_block.SetEndLocation (lexer.Location);
6001 current_block = current_block.Parent;
6003 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6005 expression_or_error opt_join_into
6007 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6008 current_block.SetEndLocation (lexer.Location);
6010 var outer_selector = linq_clause_blocks.Pop ();
6011 var block = linq_clause_blocks.Pop ();
6013 var lt = (Tokenizer.LocatedToken) $3;
6014 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6015 Linq.RangeVariable into;
6019 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6020 IdentifierType = (FullNamedExpression)$2
6024 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6026 var parent = block.Parent;
6027 while (parent is Linq.QueryBlock) {
6028 parent = parent.Parent;
6030 current_block.Parent = parent;
6032 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6034 lt = (Tokenizer.LocatedToken) $13;
6035 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6037 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6038 IdentifierType = (FullNamedExpression)$2
6042 current_block = block.Parent;
6043 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6049 | INTO identifier_inside_body
6058 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6062 current_block.SetEndLocation (lexer.Location);
6063 current_block = current_block.Parent;
6073 current_block.SetEndLocation (lexer.Location);
6074 current_block = current_block.Parent;
6076 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6080 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6087 | orderings_then_by COMMA
6089 current_block.SetEndLocation (lexer.Location);
6090 current_block = current_block.Parent;
6092 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6096 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6104 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6106 | expression ASCENDING
6108 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6109 lbag.AddLocation ($$, GetLocation ($2));
6111 | expression DESCENDING
6113 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6114 lbag.AddLocation ($$, GetLocation ($2));
6121 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6123 | expression ASCENDING
6125 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6126 lbag.AddLocation ($$, GetLocation ($2));
6128 | expression DESCENDING
6130 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6131 lbag.AddLocation ($$, GetLocation ($2));
6136 opt_query_continuation
6138 | INTO identifier_inside_body
6140 // query continuation block is not linked with query block but with block
6141 // before. This means each query can use same range variable names for
6142 // different identifiers.
6144 current_block.SetEndLocation (GetLocation ($1));
6145 current_block = current_block.Parent;
6147 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6149 if (linq_clause_blocks == null)
6150 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6152 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6156 var current_block = linq_clause_blocks.Pop ();
6157 var lt = (Tokenizer.LocatedToken) $2;
6158 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6159 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6160 next = (Linq.AQueryClause)$4
6166 // Support for using the compiler as an interactive parser
6168 // The INTERACTIVE_PARSER token is first sent to parse our
6169 // productions; If the result is a Statement, the parsing
6170 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6171 // to setup the blocks in advance.
6173 // This setup is here so that in the future we can add
6174 // support for other constructs (type parsing, namespaces, etc)
6175 // that do not require a block to be setup in advance
6179 : EVAL_STATEMENT_PARSER EOF
6180 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6181 | EVAL_STATEMENT_PARSER
6183 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6185 // (ref object retval)
6186 Parameter [] mpar = new Parameter [1];
6187 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6189 ParametersCompiled pars = new ParametersCompiled (mpar);
6190 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6191 if (settings.Unsafe)
6192 mods |= Modifiers.UNSAFE;
6194 current_local_parameters = pars;
6195 Method method = new Method (
6197 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6199 new MemberName ("Host"),
6201 null /* attributes */);
6203 current_type.AddMember (method);
6205 oob_stack.Push (method);
6206 ++lexer.parsing_block;
6207 start_block (lexer.Location);
6209 interactive_statement_list opt_COMPLETE_COMPLETION
6211 --lexer.parsing_block;
6212 Method method = (Method) oob_stack.Pop ();
6214 method.Block = (ToplevelBlock) end_block(lexer.Location);
6216 InteractiveResult = (Class) pop_current_class ();
6217 current_local_parameters = null;
6219 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6222 interactive_compilation_unit
6223 : opt_extern_alias_directives opt_using_directives
6224 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6227 opt_COMPLETE_COMPLETION
6229 | COMPLETE_COMPLETION
6232 close_brace_or_complete_completion
6234 | COMPLETE_COMPLETION
6238 // XML documentation code references micro parser
6240 documentation_parsing
6243 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6248 : doc_type_declaration_name opt_doc_method_sig
6250 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6252 | builtin_types opt_doc_method_sig
6254 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6255 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6258 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6260 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6261 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6262 var lt = (Tokenizer.LocatedToken) $3;
6263 $$ = new MemberName (lt.Value);
6265 | doc_type_declaration_name DOT THIS
6267 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6269 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6271 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6273 opt_doc_parameters CLOSE_BRACKET
6275 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6276 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6278 | EXPLICIT OPERATOR type opt_doc_method_sig
6280 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6281 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6282 module.DocumentationBuilder.ParsedParameters = p;
6283 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6286 | IMPLICIT OPERATOR type opt_doc_method_sig
6288 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6289 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6290 module.DocumentationBuilder.ParsedParameters = p;
6291 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6294 | OPERATOR overloadable_operator opt_doc_method_sig
6296 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6297 module.DocumentationBuilder.ParsedParameters = p;
6298 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6303 doc_type_declaration_name
6304 : type_declaration_name
6305 | doc_type_declaration_name DOT type_declaration_name
6307 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6315 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6317 opt_doc_parameters CLOSE_PARENS
6326 $$ = new List<DocumentationParameter> (0);
6334 var parameters = new List<DocumentationParameter> ();
6335 parameters.Add ((DocumentationParameter) $1);
6338 | doc_parameters COMMA doc_parameter
6340 var parameters = $1 as List<DocumentationParameter>;
6341 parameters.Add ((DocumentationParameter) $3);
6347 : opt_parameter_modifier parameter_type
6350 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6352 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6359 // A class used to hold info about an operator declarator
6361 class OperatorDeclaration {
6362 public readonly Operator.OpType optype;
6363 public readonly FullNamedExpression ret_type;
6364 public readonly Location location;
6366 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6369 this.ret_type = ret_type;
6370 this.location = location;
6374 void Error_ExpectingTypeName (Expression expr)
6376 if (expr is Invocation){
6377 report.Error (1002, expr.Location, "Expecting `;'");
6379 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6383 void Error_ParameterModifierNotValid (string modifier, Location loc)
6385 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6389 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6391 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6392 Parameter.GetModifierSignature (mod));
6395 void Error_TypeExpected (Location loc)
6397 report.Error (1031, loc, "Type expected");
6400 void Error_UnsafeCodeNotAllowed (Location loc)
6402 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6405 void Warning_EmptyStatement (Location loc)
6407 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6410 void Error_NamedArgumentExpected (NamedArgument a)
6412 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6415 void Error_MissingInitializer (Location loc)
6417 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6420 void push_current_container (TypeDefinition tc, object partial_token)
6422 if (module.Evaluator != null){
6423 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6427 undo.AddTypeContainer (current_container, tc);
6430 if (partial_token != null)
6431 current_container.AddPartial (tc);
6433 current_container.AddTypeContainer (tc);
6435 ++lexer.parsing_declaration;
6436 current_container = tc;
6440 TypeContainer pop_current_class ()
6442 var retval = current_container;
6444 current_container = current_container.Parent;
6445 current_type = current_type.Parent as TypeDefinition;
6450 [System.Diagnostics.Conditional ("FULL_AST")]
6451 void StoreModifierLocation (object token, Location loc)
6456 if (mod_locations == null)
6457 mod_locations = new List<Tuple<Modifiers, Location>> ();
6459 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6462 string CheckAttributeTarget (string a, Location l)
6465 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6469 report.Warning (658, 1, l,
6470 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6471 return string.Empty;
6474 static bool IsUnaryOperator (Operator.OpType op)
6478 case Operator.OpType.LogicalNot:
6479 case Operator.OpType.OnesComplement:
6480 case Operator.OpType.Increment:
6481 case Operator.OpType.Decrement:
6482 case Operator.OpType.True:
6483 case Operator.OpType.False:
6484 case Operator.OpType.UnaryPlus:
6485 case Operator.OpType.UnaryNegation:
6491 void syntax_error (Location l, string msg)
6493 report.Error (1003, l, "Syntax error, " + msg);
6498 public Tokenizer Lexer {
6504 static CSharpParser ()
6506 oob_stack = new Stack<object> ();
6509 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
6510 : this (reader, file, file.Compiler.Report)
6514 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
6517 current_container = current_namespace = file;
6519 this.module = file.Module;
6520 this.compiler = file.Compiler;
6521 this.settings = compiler.Settings;
6522 this.report = report;
6524 lang_version = settings.Version;
6525 yacc_verbose_flag = settings.VerboseParserFlag;
6526 doc_support = settings.DocumentationFile != null;
6528 lexer = new Tokenizer (reader, file);
6531 lbag = new LocationsBag ();
6536 use_global_stacks = true;
6539 public void parse ()
6541 eof_token = Token.EOF;
6542 Tokenizer.LocatedToken.Initialize ();
6545 if (yacc_verbose_flag > 1)
6546 yyparse (lexer, new yydebug.yyDebugSimple ());
6550 Tokenizer tokenizer = lexer as Tokenizer;
6551 tokenizer.cleanup ();
6552 } catch (Exception e){
6553 if (e is yyParser.yyUnexpectedEof) {
6554 Error_SyntaxError (yyToken);
6555 UnexpectedEOF = true;
6559 if (e is yyParser.yyException) {
6560 report.Error (-25, lexer.Location, "Parsing error");
6562 // Used by compiler-tester to test internal errors
6563 if (yacc_verbose_flag > 0)
6566 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6571 void CheckToken (int error, int yyToken, string msg, Location loc)
6573 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6574 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6576 report.Error (error, loc, msg);
6579 string ConsumeStoredComment ()
6581 string s = tmpComment;
6583 Lexer.doc_state = XmlCommentState.Allowed;
6587 void FeatureIsNotAvailable (Location loc, string feature)
6589 report.FeatureIsNotAvailable (compiler, loc, feature);
6592 Location GetLocation (object obj)
6594 var lt = obj as Tokenizer.LocatedToken;
6598 var mn = obj as MemberName;
6602 var expr = obj as Expression;
6604 return expr.Location;
6606 return lexer.Location;
6609 public LocationsBag LocationsBag {
6615 void start_block (Location loc)
6617 if (current_block == null) {
6618 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6619 parsing_anonymous_method = false;
6620 } else if (parsing_anonymous_method) {
6621 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6622 parsing_anonymous_method = false;
6624 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6629 end_block (Location loc)
6631 Block retval = current_block.Explicit;
6632 retval.SetEndLocation (loc);
6633 current_block = retval.Parent;
6637 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6639 oob_stack.Push (current_anonymous_method);
6640 oob_stack.Push (current_local_parameters);
6641 oob_stack.Push (current_variable);
6642 oob_stack.Push (async_block);
6644 current_local_parameters = parameters;
6646 if (lang_version <= LanguageVersion.ISO_2)
6647 FeatureIsNotAvailable (loc, "lambda expressions");
6649 current_anonymous_method = new LambdaExpression (loc);
6651 if (lang_version == LanguageVersion.ISO_1)
6652 FeatureIsNotAvailable (loc, "anonymous methods");
6654 current_anonymous_method = new AnonymousMethodExpression (loc);
6657 async_block = isAsync;
6658 // Force the next block to be created as a ToplevelBlock
6659 parsing_anonymous_method = true;
6663 * Completes the anonymous method processing, if lambda_expr is null, this
6664 * means that we have a Statement instead of an Expression embedded
6666 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6668 AnonymousMethodExpression retval;
6671 anon_block.IsAsync = true;
6673 current_anonymous_method.Block = anon_block;
6674 retval = current_anonymous_method;
6676 async_block = (bool) oob_stack.Pop ();
6677 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6678 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6679 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6684 void Error_SyntaxError (int token)
6686 Error_SyntaxError (0, token);
6689 void Error_SyntaxError (int error_code, int token)
6691 Error_SyntaxError (error_code, token, "Unexpected symbol");
6694 void Error_SyntaxError (int error_code, int token, string msg)
6696 Lexer.CompleteOnEOF = false;
6698 // An error message has been reported by tokenizer
6699 if (token == Token.ERROR)
6702 string symbol = GetSymbolName (token);
6703 string expecting = GetExpecting ();
6704 var loc = lexer.Location - symbol.Length;
6706 if (error_code == 0) {
6707 if (expecting == "`identifier'") {
6708 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6709 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6714 expecting = "identifier";
6715 } else if (expecting == "`)'") {
6722 if (string.IsNullOrEmpty (expecting))
6723 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6725 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6728 string GetExpecting ()
6730 int [] tokens = yyExpectingTokens (yyExpectingState);
6731 var names = new List<string> (tokens.Length);
6732 bool has_type = false;
6733 bool has_identifier = false;
6734 for (int i = 0; i < tokens.Length; i++){
6735 int token = tokens [i];
6736 has_identifier |= token == Token.IDENTIFIER;
6738 string name = GetTokenName (token);
6739 if (name == "<internal>")
6742 has_type |= name == "type";
6743 if (names.Contains (name))
6750 // Too many tokens to enumerate
6752 if (names.Count > 8)
6755 if (has_type && has_identifier)
6756 names.Remove ("identifier");
6758 if (names.Count == 1)
6759 return "`" + GetTokenName (tokens [0]) + "'";
6761 StringBuilder sb = new StringBuilder ();
6763 int count = names.Count;
6764 for (int i = 0; i < count; i++){
6765 bool last = i + 1 == count;
6769 sb.Append (names [i]);
6770 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6772 return sb.ToString ();
6776 string GetSymbolName (int token)
6780 return ((Constant)lexer.Value).GetValue ().ToString ();
6781 case Token.IDENTIFIER:
6782 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6824 case Token.BITWISE_AND:
6826 case Token.BITWISE_OR:
6840 case Token.OP_SHIFT_LEFT:
6842 case Token.OP_SHIFT_RIGHT:
6862 case Token.OP_COALESCING:
6864 case Token.OP_MULT_ASSIGN:
6866 case Token.OP_DIV_ASSIGN:
6868 case Token.OP_MOD_ASSIGN:
6870 case Token.OP_ADD_ASSIGN:
6872 case Token.OP_SUB_ASSIGN:
6874 case Token.OP_SHIFT_LEFT_ASSIGN:
6876 case Token.OP_SHIFT_RIGHT_ASSIGN:
6878 case Token.OP_AND_ASSIGN:
6880 case Token.OP_XOR_ASSIGN:
6882 case Token.OP_OR_ASSIGN:
6886 return GetTokenName (token);
6889 static string GetTokenName (int token)
6892 case Token.ABSTRACT:
6914 case Token.CONTINUE:
6918 case Token.DELEGATE:
6928 case Token.EXPLICIT:
6931 case Token.EXTERN_ALIAS:
6947 case Token.IMPLICIT:
6951 case Token.INTERFACE:
6953 case Token.INTERNAL:
6959 case Token.NAMESPACE:
6965 case Token.OPERATOR:
6969 case Token.OVERRIDE:
6975 case Token.PROTECTED:
6979 case Token.READONLY:
6991 case Token.STACKALLOC:
6992 return "stackalloc";
7009 case Token.UNCHECKED:
7017 case Token.VOLATILE:
7025 case Token.REFVALUE:
7026 return "__refvalue";
7036 case Token.FROM_FIRST:
7054 case Token.ASCENDING:
7056 case Token.DESCENDING:
7057 return "descending";
7064 case Token.OPEN_BRACE:
7066 case Token.CLOSE_BRACE:
7068 case Token.OPEN_BRACKET:
7069 case Token.OPEN_BRACKET_EXPR:
7071 case Token.CLOSE_BRACKET:
7073 case Token.OPEN_PARENS_CAST:
7074 case Token.OPEN_PARENS_LAMBDA:
7075 case Token.OPEN_PARENS:
7077 case Token.CLOSE_PARENS:
7083 case Token.DEFAULT_COLON:
7087 case Token.SEMICOLON:
7098 case Token.BITWISE_AND:
7099 case Token.BITWISE_OR:
7106 case Token.OP_SHIFT_LEFT:
7107 case Token.OP_SHIFT_RIGHT:
7115 case Token.OP_COALESCING:
7116 case Token.OP_MULT_ASSIGN:
7117 case Token.OP_DIV_ASSIGN:
7118 case Token.OP_MOD_ASSIGN:
7119 case Token.OP_ADD_ASSIGN:
7120 case Token.OP_SUB_ASSIGN:
7121 case Token.OP_SHIFT_LEFT_ASSIGN:
7122 case Token.OP_SHIFT_RIGHT_ASSIGN:
7123 case Token.OP_AND_ASSIGN:
7124 case Token.OP_XOR_ASSIGN:
7125 case Token.OP_OR_ASSIGN:
7126 return "<operator>";
7148 case Token.OP_GENERICS_LT:
7149 case Token.GENERIC_DIMENSION:
7151 case Token.OP_GENERICS_GT:
7154 case Token.INTERR_NULLABLE:
7156 case Token.DOUBLE_COLON:
7160 case Token.IDENTIFIER:
7162 return "identifier";
7165 return "end-of-file";
7167 // All of these are internal.
7170 case Token.FIRST_KEYWORD:
7171 case Token.EVAL_COMPILATION_UNIT_PARSER:
7172 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7173 case Token.EVAL_STATEMENT_PARSER:
7174 case Token.LAST_KEYWORD:
7175 case Token.GENERATE_COMPLETION:
7176 case Token.COMPLETE_COMPLETION:
7177 return "<internal>";
7179 // A bit more robust.
7181 return yyNames [token];