3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue
41 static readonly object ModifierNone = 0;
43 NamespaceContainer current_namespace;
44 TypeContainer current_container;
45 TypeDefinition current_type;
46 PropertyBase current_property;
47 EventProperty current_event;
48 EventField current_event_field;
49 FieldBase current_field;
52 /// Current block is used to add statements as we find
57 BlockVariableDeclaration current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 static Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 Stack<Linq.QueryBlock> linq_clause_blocks;
122 ModuleContainer module;
124 readonly CompilerContext compiler;
125 readonly LanguageVersion lang_version;
126 readonly bool doc_support;
127 readonly CompilerSettings settings;
128 readonly Report report;
131 // Instead of allocating carrier array everytime we
132 // share the bucket for very common constructs which can never
135 static List<Parameter> parameters_bucket = new List<Parameter> (6);
138 // Full AST support members
141 List<Tuple<Modifiers, Location>> mod_locations;
145 %token NONE /* This token is never returned by our lexer */
146 %token ERROR // This is used not by the parser, but by the tokenizer.
150 *These are the C# keywords
249 %token INTERR_NULLABLE
257 /* C# keywords which are not really keywords */
263 /* C# single character operators/punctuation. */
291 /* C# multi-character operators. */
296 %token OP_SHIFT_RIGHT
303 %token OP_MULT_ASSIGN
308 %token OP_SHIFT_LEFT_ASSIGN
309 %token OP_SHIFT_RIGHT_ASSIGN
316 /* Generics <,> tokens */
317 %token OP_GENERICS_LT
318 %token OP_GENERICS_LT_DECL
319 %token OP_GENERICS_GT
324 %token OPEN_PARENS_LAMBDA
325 %token OPEN_PARENS_CAST
326 %token GENERIC_DIMENSION
328 %token OPEN_BRACKET_EXPR
330 // Make the parser go into eval mode parsing (statements and compilation units).
331 %token EVAL_STATEMENT_PARSER
332 %token EVAL_COMPILATION_UNIT_PARSER
333 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
338 // This token is generated to trigger the completion engine at this point
340 %token GENERATE_COMPLETION
343 // This token is return repeatedly after the first GENERATE_COMPLETION
344 // token is produced and before the final EOF
346 %token COMPLETE_COMPLETION
348 /* Add precedence rules to solve dangling else s/r conflict */
352 /* Define the operator tokens and their precedences */
360 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
362 %left STAR DIV PERCENT
363 %right BANG CARRET UMINUS
364 %nonassoc OP_INC OP_DEC
366 %left OPEN_BRACKET OPEN_BRACE
369 %start compilation_unit
373 : outer_declaration opt_EOF
375 Lexer.check_incorrect_doc_comment ();
377 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
378 | documentation_parsing
382 : opt_extern_alias_directives opt_using_directives
383 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
386 Attributes attrs = (Attributes) $4;
387 report.Error (1730, attrs.Attrs [0].Location,
388 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
390 current_namespace.UnattachedAttributes = attrs;
393 | opt_extern_alias_directives opt_using_directives attribute_sections
395 module.AddAttributes ((Attributes) $3, current_namespace);
399 if (yyToken == Token.EXTERN_ALIAS)
400 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
402 Error_SyntaxError (yyToken);
411 extern_alias_directives
412 : extern_alias_directive
413 | extern_alias_directives extern_alias_directive
416 extern_alias_directive
417 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
419 var lt = (Tokenizer.LocatedToken) $2;
422 syntax_error (lt.Location, "`alias' expected");
424 if (lang_version == LanguageVersion.ISO_1)
425 FeatureIsNotAvailable (lt.Location, "external alias");
427 lt = (Tokenizer.LocatedToken) $3;
428 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
429 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
432 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
433 current_namespace.AddUsing (na);
435 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
440 Error_SyntaxError (yyToken);
446 | using_directives using_directive
453 Lexer.doc_state = XmlCommentState.Allowed;
458 : USING namespace_or_type_expr SEMICOLON
460 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
461 current_namespace.AddUsing (un);
463 lbag.AddLocation (un, GetLocation ($3));
465 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
467 var lt = (Tokenizer.LocatedToken) $2;
468 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
469 report.Warning (440, 2, lt.Location,
470 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
473 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
474 current_namespace.AddUsing (un);
476 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
480 Error_SyntaxError (yyToken);
486 // Strictly speaking, namespaces don't have attributes but
487 // we parse global attributes along with namespace declarations and then
490 namespace_declaration
491 : opt_attributes NAMESPACE namespace_name
493 Attributes attrs = (Attributes) $1;
494 var name = (MemberName) $3;
496 bool valid_global_attrs = true;
497 if ((current_namespace.DeclarationFound || current_namespace != file)) {
498 valid_global_attrs = false;
500 foreach (var a in attrs.Attrs) {
501 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
504 valid_global_attrs = false;
509 if (!valid_global_attrs)
510 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
513 module.AddAttributes (attrs, current_namespace);
515 var ns = new NamespaceContainer (name, current_namespace);
516 current_namespace.AddTypeContainer (ns);
517 current_container = current_namespace = ns;
522 Lexer.doc_state = XmlCommentState.Allowed;
524 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon
527 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
529 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
531 current_container = current_namespace = current_namespace.Parent;
538 var lt = (Tokenizer.LocatedToken) $1;
539 $$ = new MemberName (lt.Value, lt.Location);
541 | namespace_name DOT IDENTIFIER
543 var lt = (Tokenizer.LocatedToken) $3;
544 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
548 Error_SyntaxError (yyToken);
549 $$ = new MemberName ("<invalid>", lexer.Location);
568 opt_extern_alias_directives
570 | extern_alias_directives
573 opt_namespace_or_type_declarations
575 | namespace_or_type_declarations
578 namespace_or_type_declarations
579 : namespace_or_type_declaration
580 | namespace_or_type_declarations namespace_or_type_declaration
583 namespace_or_type_declaration
587 TypeContainer ds = (TypeContainer)$1;
589 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
590 report.Error (1527, ds.Location,
591 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
594 // Here is a trick, for explicit attributes we don't know where they belong to until
595 // we parse succeeding declaration hence we parse them as normal and re-attach them
596 // when we know whether they are global (assembly:, module:) or local (type:).
597 if (ds.OptAttributes != null) {
598 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
601 current_namespace.DeclarationFound = true;
603 | namespace_declaration
605 current_namespace.DeclarationFound = true;
607 | attribute_sections CLOSE_BRACE {
608 current_namespace.UnattachedAttributes = (Attributes) $1;
609 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
617 | interface_declaration
619 | delegate_declaration
621 // Enable this when we have handled all errors, because this acts as a generic fallback
624 // Console.WriteLine ("Token=" + yyToken);
625 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
641 var sect = (List<Attribute>) $1;
642 $$ = new Attributes (sect);
644 | attribute_sections attribute_section
646 Attributes attrs = $1 as Attributes;
647 var sect = (List<Attribute>) $2;
649 attrs = new Attributes (sect);
651 attrs.AddAttributes (sect);
659 lexer.parsing_attribute_section = true;
661 attribute_section_cont
663 lexer.parsing_attribute_section = false;
668 attribute_section_cont
669 : attribute_target COLON
671 current_attr_target = (string) $1;
672 if (current_attr_target == "assembly" || current_attr_target == "module") {
673 Lexer.check_incorrect_doc_comment ();
676 attribute_list opt_comma CLOSE_BRACKET
678 // when attribute target is invalid
679 if (current_attr_target == string.Empty)
680 $$ = new List<Attribute> (0);
684 current_attr_target = null;
685 lexer.parsing_attribute_section = false;
687 | attribute_list opt_comma CLOSE_BRACKET
696 var lt = (Tokenizer.LocatedToken) $1;
697 $$ = CheckAttributeTarget (lt.Value, lt.Location);
699 | EVENT { $$ = "event"; }
700 | RETURN { $$ = "return"; }
703 if (yyToken == Token.IDENTIFIER) {
704 Error_SyntaxError (yyToken);
707 string name = GetTokenName (yyToken);
708 $$ = CheckAttributeTarget (name, GetLocation ($1));
716 $$ = new List<Attribute> (4) { (Attribute) $1 };
718 | attribute_list COMMA attribute
720 var attrs = (List<Attribute>) $1;
721 attrs.Add ((Attribute) $3);
730 ++lexer.parsing_block;
732 opt_attribute_arguments
734 --lexer.parsing_block;
736 var tne = (ATypeNameExpression) $1;
737 if (tne.HasTypeArguments) {
738 report.Error (404, tne.Location, "Attributes cannot be generic");
741 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
746 : namespace_or_type_expr
749 opt_attribute_arguments
750 : /* empty */ { $$ = null; }
751 | OPEN_PARENS attribute_arguments CLOSE_PARENS
759 : /* empty */ { $$ = null; }
760 | positional_or_named_argument
762 Arguments a = new Arguments (4);
763 a.Add ((Argument) $1);
764 $$ = new Arguments [] { a, null };
766 | named_attribute_argument
768 Arguments a = new Arguments (4);
769 a.Add ((Argument) $1);
770 $$ = new Arguments [] { null, a };
772 | attribute_arguments COMMA positional_or_named_argument
774 Arguments[] o = (Arguments[]) $1;
776 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
777 o [0] = new Arguments (4);
780 Arguments args = ((Arguments) o [0]);
781 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
782 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
784 args.Add ((Argument) $3);
786 | attribute_arguments COMMA named_attribute_argument
788 Arguments[] o = (Arguments[]) $1;
790 o [1] = new Arguments (4);
793 ((Arguments) o [1]).Add ((Argument) $3);
797 positional_or_named_argument
800 $$ = new Argument ((Expression) $1);
805 named_attribute_argument
808 ++lexer.parsing_block;
812 --lexer.parsing_block;
813 var lt = (Tokenizer.LocatedToken) $1;
814 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
815 lbag.AddLocation ($$, GetLocation($2));
820 : identifier_inside_body COLON opt_named_modifier expression
822 if (lang_version <= LanguageVersion.V_3)
823 FeatureIsNotAvailable (GetLocation ($1), "named argument");
825 // Avoid boxing in common case (no modifier)
826 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
828 var lt = (Tokenizer.LocatedToken) $1;
829 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
830 lbag.AddLocation ($$, GetLocation($2));
835 : /* empty */ { $$ = null; }
838 $$ = Argument.AType.Ref;
842 $$ = Argument.AType.Out;
846 opt_class_member_declarations
848 | class_member_declarations
851 class_member_declarations
852 : class_member_declaration
854 lexer.parsing_modifiers = true;
856 | class_member_declarations class_member_declaration
858 lexer.parsing_modifiers = true;
862 class_member_declaration
863 : constant_declaration
866 | property_declaration
868 | indexer_declaration
869 | operator_declaration
870 | constructor_declaration
871 | destructor_declaration
873 | attributes_without_members
876 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
877 GetSymbolName (yyToken));
879 lexer.parsing_generic_declaration = false;
889 lexer.ConstraintsParsing = true;
891 type_declaration_name
893 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
896 opt_type_parameter_constraints_clauses
898 lexer.ConstraintsParsing = false;
901 current_container.SetConstraints ((List<Constraints>) $9);
904 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
906 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
908 lexer.parsing_modifiers = true;
913 Lexer.doc_state = XmlCommentState.Allowed;
915 opt_class_member_declarations CLOSE_BRACE
917 --lexer.parsing_declaration;
919 Lexer.doc_state = XmlCommentState.Allowed;
923 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
924 $$ = pop_current_class ();
926 | opt_attributes opt_modifiers opt_partial STRUCT error
928 Error_SyntaxError (yyToken);
935 CONST type IDENTIFIER
937 var lt = (Tokenizer.LocatedToken) $5;
938 var mod = (Modifiers) $2;
939 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
940 current_type.AddMember (current_field);
942 if ((mod & Modifiers.STATIC) != 0) {
943 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
948 constant_initializer opt_constant_declarators SEMICOLON
951 current_field.DocComment = Lexer.consume_doc_comment ();
952 Lexer.doc_state = XmlCommentState.Allowed;
955 current_field.Initializer = (ConstInitializer) $7;
956 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
957 current_field = null;
961 opt_constant_declarators
963 | constant_declarators
967 : constant_declarator
969 current_field.AddDeclarator ((FieldDeclarator) $1);
971 | constant_declarators constant_declarator
973 current_field.AddDeclarator ((FieldDeclarator) $2);
978 : COMMA IDENTIFIER constant_initializer
980 var lt = (Tokenizer.LocatedToken) $2;
981 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
982 lbag.AddLocation ($$, GetLocation ($1));
989 ++lexer.parsing_block;
991 constant_initializer_expr
993 --lexer.parsing_block;
994 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
998 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1003 constant_initializer_expr
1004 : constant_expression
1011 member_type IDENTIFIER
1013 lexer.parsing_generic_declaration = false;
1015 FullNamedExpression type = (FullNamedExpression) $3;
1016 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1017 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1019 var lt = (Tokenizer.LocatedToken) $4;
1020 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1021 current_type.AddField (current_field);
1024 opt_field_initializer
1025 opt_field_declarators
1029 current_field.DocComment = Lexer.consume_doc_comment ();
1030 Lexer.doc_state = XmlCommentState.Allowed;
1033 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1035 current_field = null;
1039 FIXED simple_type IDENTIFIER
1041 if (lang_version < LanguageVersion.ISO_2)
1042 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1044 var lt = (Tokenizer.LocatedToken) $5;
1045 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1046 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1048 current_type.AddField (current_field);
1050 fixed_field_size opt_fixed_field_declarators SEMICOLON
1053 current_field.DocComment = Lexer.consume_doc_comment ();
1054 Lexer.doc_state = XmlCommentState.Allowed;
1057 current_field.Initializer = (ConstInitializer) $7;
1058 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1060 current_field = null;
1064 FIXED simple_type error
1067 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1071 opt_field_initializer
1075 ++lexer.parsing_block;
1076 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1077 start_block (GetLocation ($1));
1079 variable_initializer
1081 --lexer.parsing_block;
1082 current_field.Initializer = (Expression) $3;
1083 end_block (lexer.Location);
1084 current_local_parameters = null;
1088 opt_field_declarators
1096 current_field.AddDeclarator ((FieldDeclarator) $1);
1098 | field_declarators field_declarator
1100 current_field.AddDeclarator ((FieldDeclarator) $2);
1107 var lt = (Tokenizer.LocatedToken) $2;
1108 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1109 lbag.AddLocation ($$, GetLocation ($1));
1111 | COMMA IDENTIFIER ASSIGN
1113 ++lexer.parsing_block;
1115 variable_initializer
1117 --lexer.parsing_block;
1118 var lt = (Tokenizer.LocatedToken) $2;
1119 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1120 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1124 opt_fixed_field_declarators
1126 | fixed_field_declarators
1129 fixed_field_declarators
1130 : fixed_field_declarator
1132 current_field.AddDeclarator ((FieldDeclarator) $1);
1134 | fixed_field_declarators fixed_field_declarator
1136 current_field.AddDeclarator ((FieldDeclarator) $2);
1140 fixed_field_declarator
1141 : COMMA IDENTIFIER fixed_field_size
1143 var lt = (Tokenizer.LocatedToken) $2;
1144 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1145 lbag.AddLocation ($$, GetLocation ($1));
1152 ++lexer.parsing_block;
1154 expression CLOSE_BRACKET
1156 --lexer.parsing_block;
1157 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1158 lbag.AddLocation ($$, GetLocation ($4));
1160 | OPEN_BRACKET error
1162 report.Error (443, lexer.Location, "Value or constant expected");
1167 variable_initializer
1172 // It has to be here for the parent to safely restore artificial block
1173 Error_SyntaxError (yyToken);
1182 Lexer.doc_state = XmlCommentState.NotAllowed;
1184 // Add it early in the case of body being eof for full ast
1185 Method m = (Method) $1;
1186 async_block = (m.ModFlags & Modifiers.ASYNC) != 0;
1187 current_type.AddMember (m);
1191 Method method = (Method) $1;
1192 method.Block = (ToplevelBlock) $3;
1193 async_block = false;
1195 if (method.Block == null) {
1196 method.ParameterInfo.CheckParameters (method);
1198 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1199 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1200 method.GetSignatureForError ());
1203 if (current_container.Kind == MemberKind.Interface) {
1204 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1205 method.GetSignatureForError ());
1209 current_local_parameters = null;
1212 Lexer.doc_state = XmlCommentState.Allowed;
1220 method_declaration_name OPEN_PARENS
1222 valid_param_mod = ParameterModifierType.All;
1224 opt_formal_parameter_list CLOSE_PARENS
1226 lexer.ConstraintsParsing = true;
1228 opt_type_parameter_constraints_clauses
1230 lexer.ConstraintsParsing = false;
1231 valid_param_mod = 0;
1232 MemberName name = (MemberName) $4;
1233 current_local_parameters = (ParametersCompiled) $7;
1235 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1236 name, current_local_parameters, (Attributes) $1, $10 != null);
1239 method.SetConstraints ((List<Constraints>) $10);
1242 method.DocComment = Lexer.consume_doc_comment ();
1244 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1252 lexer.parsing_generic_declaration = true;
1254 method_declaration_name
1257 lexer.parsing_generic_declaration = false;
1258 valid_param_mod = ParameterModifierType.All;
1260 opt_formal_parameter_list CLOSE_PARENS
1262 lexer.ConstraintsParsing = true;
1264 opt_type_parameter_constraints_clauses
1266 lexer.ConstraintsParsing = false;
1267 valid_param_mod = 0;
1269 MemberName name = (MemberName) $6;
1270 current_local_parameters = (ParametersCompiled) $9;
1272 var modifiers = (Modifiers) $2;
1273 modifiers |= Modifiers.PARTIAL;
1275 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1276 modifiers, name, current_local_parameters, (Attributes) $1, $11 != null);
1279 method.SetConstraints ((List<Constraints>) $11);
1282 method.DocComment = Lexer.consume_doc_comment ();
1284 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1285 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1291 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1293 MemberName name = (MemberName) $5;
1294 report.Error (1585, name.Location,
1295 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1297 var method = Method.Create (current_type, (FullNamedExpression) $3,
1298 0, name, (ParametersCompiled) $7, (Attributes) $1, false);
1300 current_local_parameters = (ParametersCompiled) $7;
1303 method.DocComment = Lexer.consume_doc_comment ();
1310 method_declaration_name error
1312 Error_SyntaxError (yyToken);
1313 current_local_parameters = ParametersCompiled.Undefined;
1315 MemberName name = (MemberName) $4;
1316 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1317 name, current_local_parameters, (Attributes) $1, false);
1320 method.DocComment = Lexer.consume_doc_comment ();
1328 | SEMICOLON { $$ = null; }
1331 opt_formal_parameter_list
1332 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1333 | formal_parameter_list
1336 formal_parameter_list
1339 var pars_list = (List<Parameter>) $1;
1340 $$ = new ParametersCompiled (pars_list.ToArray ());
1342 | fixed_parameters COMMA parameter_array
1344 var pars_list = (List<Parameter>) $1;
1345 pars_list.Add ((Parameter) $3);
1347 $$ = new ParametersCompiled (pars_list.ToArray ());
1349 | fixed_parameters COMMA arglist_modifier
1351 var pars_list = (List<Parameter>) $1;
1352 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1353 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1355 | parameter_array COMMA error
1358 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1360 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1362 | fixed_parameters COMMA parameter_array COMMA error
1365 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1367 var pars_list = (List<Parameter>) $1;
1368 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1370 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1372 | arglist_modifier COMMA error
1374 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1376 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1378 | fixed_parameters COMMA ARGLIST COMMA error
1380 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1382 var pars_list = (List<Parameter>) $1;
1383 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1385 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1389 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1393 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1397 Error_SyntaxError (yyToken);
1398 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1405 parameters_bucket.Clear ();
1406 Parameter p = (Parameter) $1;
1407 parameters_bucket.Add (p);
1409 default_parameter_used = p.HasDefaultValue;
1410 $$ = parameters_bucket;
1412 | fixed_parameters COMMA fixed_parameter
1414 var pars = (List<Parameter>) $1;
1415 Parameter p = (Parameter) $3;
1417 if (p.HasExtensionMethodModifier)
1418 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1419 else if (!p.HasDefaultValue && default_parameter_used)
1420 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1422 default_parameter_used |= p.HasDefaultValue;
1425 lbag.AddLocation (p, GetLocation ($2));
1434 opt_parameter_modifier
1438 var lt = (Tokenizer.LocatedToken) $4;
1439 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1442 opt_parameter_modifier
1444 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1446 var lt = (Tokenizer.LocatedToken) $4;
1447 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1448 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1450 | attribute_sections error
1452 Error_SyntaxError (yyToken);
1453 Location l = GetLocation ($2);
1454 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1457 opt_parameter_modifier
1461 Error_SyntaxError (yyToken);
1462 Location l = GetLocation ($4);
1463 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1466 opt_parameter_modifier
1471 ++lexer.parsing_block;
1475 --lexer.parsing_block;
1476 if (lang_version <= LanguageVersion.V_3) {
1477 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1480 Parameter.Modifier mod = (Parameter.Modifier) $2;
1481 if (mod != Parameter.Modifier.NONE) {
1483 case Parameter.Modifier.REF:
1484 case Parameter.Modifier.OUT:
1485 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1486 Parameter.GetModifierSignature (mod));
1489 case Parameter.Modifier.This:
1490 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1491 Parameter.GetModifierSignature (mod));
1494 throw new NotImplementedException (mod.ToString ());
1497 mod = Parameter.Modifier.NONE;
1500 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1501 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1503 var lt = (Tokenizer.LocatedToken) $4;
1504 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1505 lbag.AddLocation ($$, GetLocation ($5));
1508 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1512 opt_parameter_modifier
1513 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1514 | parameter_modifiers
1518 : parameter_modifier
1522 | parameter_modifiers parameter_modifier
1524 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1525 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1526 if (((Parameter.Modifier)$1 & p2) == p2) {
1527 Error_DuplicateParameterModifier (lexer.Location, p2);
1529 switch (mod & ~Parameter.Modifier.This) {
1530 case Parameter.Modifier.REF:
1531 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1533 case Parameter.Modifier.OUT:
1534 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1537 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1548 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1549 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1551 $$ = Parameter.Modifier.REF;
1555 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1556 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1558 $$ = Parameter.Modifier.OUT;
1562 if ((valid_param_mod & ParameterModifierType.This) == 0)
1563 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1565 if (lang_version <= LanguageVersion.ISO_2)
1566 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1568 $$ = Parameter.Modifier.This;
1573 : opt_attributes params_modifier type IDENTIFIER
1575 var lt = (Tokenizer.LocatedToken) $4;
1576 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1578 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1580 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1582 var lt = (Tokenizer.LocatedToken) $4;
1583 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1585 | opt_attributes params_modifier type error
1587 Error_SyntaxError (yyToken);
1595 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1596 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1598 | PARAMS parameter_modifier
1600 Parameter.Modifier mod = (Parameter.Modifier)$2;
1601 if ((mod & Parameter.Modifier.This) != 0) {
1602 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1604 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1607 | PARAMS params_modifier
1609 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1616 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1617 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1621 property_declaration
1625 member_declaration_name
1628 tmpComment = Lexer.consume_doc_comment ();
1632 var type = (FullNamedExpression) $3;
1633 current_property = new Property (current_type, type, (Modifiers) $2,
1634 (MemberName) $4, (Attributes) $1);
1636 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1637 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1639 current_type.AddMember (current_property);
1640 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1642 lexer.PropertyParsing = true;
1644 accessor_declarations
1646 lexer.PropertyParsing = false;
1649 current_property.DocComment = ConsumeStoredComment ();
1653 lbag.AppendToMember (current_property, GetLocation ($10));
1654 current_property = null;
1660 : opt_attributes opt_modifiers
1661 member_type indexer_declaration_name OPEN_BRACKET
1663 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1665 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1667 valid_param_mod = 0;
1668 var type = (FullNamedExpression) $3;
1669 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1671 current_property = indexer;
1673 current_type.AddIndexer (indexer);
1674 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1676 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1677 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1679 if (indexer.ParameterInfo.IsEmpty) {
1680 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1684 tmpComment = Lexer.consume_doc_comment ();
1685 Lexer.doc_state = XmlCommentState.Allowed;
1688 lexer.PropertyParsing = true;
1690 accessor_declarations
1692 lexer.PropertyParsing = false;
1696 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1697 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1700 current_property.DocComment = ConsumeStoredComment ();
1702 lbag.AppendToMember (current_property, GetLocation ($12));
1703 current_property = null;
1708 accessor_declarations
1709 : get_accessor_declaration
1710 | get_accessor_declaration accessor_declarations
1711 | set_accessor_declaration
1712 | set_accessor_declaration accessor_declarations
1715 if (yyToken == Token.CLOSE_BRACE) {
1716 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1718 if (yyToken == Token.SEMICOLON)
1719 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1721 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1726 get_accessor_declaration
1727 : opt_attributes opt_modifiers GET
1729 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1730 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1733 if (current_property.Get != null) {
1734 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1737 if (current_property is Indexer) {
1738 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1739 (Attributes) $1, GetLocation ($3));
1741 current_property.Get = new Property.GetMethod (current_property,
1742 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1745 current_local_parameters = current_property.Get.ParameterInfo;
1746 lbag.AddMember (current_property.Get, mod_locations);
1747 lexer.PropertyParsing = false;
1752 current_property.Get.Block = (ToplevelBlock) $5;
1754 if (current_container.Kind == MemberKind.Interface) {
1755 report.Error (531, current_property.Get.Block.StartLocation,
1756 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1760 current_local_parameters = null;
1761 lexer.PropertyParsing = true;
1764 if (Lexer.doc_state == XmlCommentState.Error)
1765 Lexer.doc_state = XmlCommentState.NotAllowed;
1769 set_accessor_declaration
1770 : opt_attributes opt_modifiers SET
1772 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1773 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1776 if (current_property.Set != null) {
1777 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1780 if (current_property is Indexer) {
1781 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1782 ParametersCompiled.MergeGenerated (compiler,
1783 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1784 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1786 (Attributes) $1, GetLocation ($3));
1788 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1789 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1790 (Attributes) $1, GetLocation ($3));
1793 current_local_parameters = current_property.Set.ParameterInfo;
1794 lbag.AddMember (current_property.Set, mod_locations);
1795 lexer.PropertyParsing = false;
1800 current_property.Set.Block = (ToplevelBlock) $5;
1802 if (current_container.Kind == MemberKind.Interface) {
1803 report.Error (531, current_property.Set.Block.StartLocation,
1804 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1808 current_local_parameters = null;
1809 lexer.PropertyParsing = true;
1812 && Lexer.doc_state == XmlCommentState.Error)
1813 Lexer.doc_state = XmlCommentState.NotAllowed;
1826 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1831 interface_declaration
1837 lexer.ConstraintsParsing = true;
1839 type_declaration_name
1841 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1842 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1845 opt_type_parameter_constraints_clauses
1847 lexer.ConstraintsParsing = false;
1850 current_container.SetConstraints ((List<Constraints>) $9);
1853 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1854 Lexer.doc_state = XmlCommentState.Allowed;
1857 lexer.parsing_modifiers = true;
1859 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1861 --lexer.parsing_declaration;
1863 Lexer.doc_state = XmlCommentState.Allowed;
1867 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1868 $$ = pop_current_class ();
1870 | opt_attributes opt_modifiers opt_partial INTERFACE error
1872 Error_SyntaxError (yyToken);
1876 opt_interface_member_declarations
1878 | interface_member_declarations
1881 interface_member_declarations
1882 : interface_member_declaration
1884 lexer.parsing_modifiers = true;
1886 | interface_member_declarations interface_member_declaration
1888 lexer.parsing_modifiers = true;
1892 interface_member_declaration
1893 : constant_declaration
1895 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1899 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1901 | method_declaration
1902 | property_declaration
1904 | indexer_declaration
1905 | operator_declaration
1907 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1909 | constructor_declaration
1911 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1915 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1919 operator_declaration
1920 : opt_attributes opt_modifiers operator_declarator
1925 OperatorDeclaration decl = (OperatorDeclaration) $3;
1927 Operator op = new Operator (
1928 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1929 current_local_parameters,
1930 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1932 if (op.Block == null)
1933 op.ParameterInfo.CheckParameters (op);
1936 op.DocComment = tmpComment;
1937 Lexer.doc_state = XmlCommentState.Allowed;
1940 // Note again, checking is done in semantic analysis
1941 current_type.AddOperator (op);
1943 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1946 current_local_parameters = null;
1952 | SEMICOLON { $$ = null; }
1956 : type_expression_or_array
1959 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1960 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
1965 : operator_type OPERATOR overloadable_operator OPEN_PARENS
1967 valid_param_mod = ParameterModifierType.DefaultValue;
1969 opt_formal_parameter_list CLOSE_PARENS
1971 valid_param_mod = 0;
1973 Location loc = GetLocation ($2);
1974 Operator.OpType op = (Operator.OpType) $3;
1975 current_local_parameters = (ParametersCompiled)$6;
1977 int p_count = current_local_parameters.Count;
1979 if (op == Operator.OpType.Addition)
1980 op = Operator.OpType.UnaryPlus;
1981 else if (op == Operator.OpType.Subtraction)
1982 op = Operator.OpType.UnaryNegation;
1985 if (IsUnaryOperator (op)) {
1987 report.Error (1020, loc, "Overloadable binary operator expected");
1988 } else if (p_count != 1) {
1989 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
1990 Operator.GetName (op));
1994 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
1995 Operator.GetName (op));
1996 } else if (p_count != 2) {
1997 report.Error (1019, loc, "Overloadable unary operator expected");
2002 tmpComment = Lexer.consume_doc_comment ();
2003 Lexer.doc_state = XmlCommentState.NotAllowed;
2006 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2007 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2009 | conversion_operator_declarator
2012 overloadable_operator
2014 : BANG { $$ = Operator.OpType.LogicalNot; }
2015 | TILDE { $$ = Operator.OpType.OnesComplement; }
2016 | OP_INC { $$ = Operator.OpType.Increment; }
2017 | OP_DEC { $$ = Operator.OpType.Decrement; }
2018 | TRUE { $$ = Operator.OpType.True; }
2019 | FALSE { $$ = Operator.OpType.False; }
2020 // Unary and binary:
2021 | PLUS { $$ = Operator.OpType.Addition; }
2022 | MINUS { $$ = Operator.OpType.Subtraction; }
2024 | STAR { $$ = Operator.OpType.Multiply; }
2025 | DIV { $$ = Operator.OpType.Division; }
2026 | PERCENT { $$ = Operator.OpType.Modulus; }
2027 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2028 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2029 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2030 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2031 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2032 | OP_EQ { $$ = Operator.OpType.Equality; }
2033 | OP_NE { $$ = Operator.OpType.Inequality; }
2034 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2035 | OP_LT { $$ = Operator.OpType.LessThan; }
2036 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2037 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2040 conversion_operator_declarator
2041 : IMPLICIT OPERATOR type OPEN_PARENS
2043 valid_param_mod = ParameterModifierType.DefaultValue;
2045 opt_formal_parameter_list CLOSE_PARENS
2047 valid_param_mod = 0;
2049 Location loc = GetLocation ($2);
2050 current_local_parameters = (ParametersCompiled)$6;
2053 tmpComment = Lexer.consume_doc_comment ();
2054 Lexer.doc_state = XmlCommentState.NotAllowed;
2057 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2058 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2060 | EXPLICIT OPERATOR type OPEN_PARENS
2062 valid_param_mod = ParameterModifierType.DefaultValue;
2064 opt_formal_parameter_list CLOSE_PARENS
2066 valid_param_mod = 0;
2068 Location loc = GetLocation ($2);
2069 current_local_parameters = (ParametersCompiled)$6;
2072 tmpComment = Lexer.consume_doc_comment ();
2073 Lexer.doc_state = XmlCommentState.NotAllowed;
2076 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2077 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2081 Error_SyntaxError (yyToken);
2082 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2083 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2087 Error_SyntaxError (yyToken);
2088 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2089 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2093 constructor_declaration
2094 : constructor_declarator
2097 Constructor c = (Constructor) $1;
2098 c.Block = (ToplevelBlock) $2;
2101 c.DocComment = ConsumeStoredComment ();
2103 current_local_parameters = null;
2105 Lexer.doc_state = XmlCommentState.Allowed;
2109 constructor_declarator
2115 tmpComment = Lexer.consume_doc_comment ();
2116 Lexer.doc_state = XmlCommentState.Allowed;
2119 valid_param_mod = ParameterModifierType.All;
2121 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2123 valid_param_mod = 0;
2124 current_local_parameters = (ParametersCompiled) $6;
2126 var lt = (Tokenizer.LocatedToken) $3;
2127 var mods = (Modifiers) $2;
2128 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2130 if (lt.Value != current_container.MemberName.Name) {
2131 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2132 } else if ((mods & Modifiers.STATIC) != 0) {
2133 if ((mods & Modifiers.AccessibilityMask) != 0){
2134 report.Error (515, c.Location,
2135 "`{0}': static constructor cannot have an access modifier",
2136 c.GetSignatureForError ());
2140 current_type.AddConstructor (c);
2141 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2145 // start block here, so possible anonymous methods inside
2146 // constructor initializer can get correct parent block
2148 start_block (lexer.Location);
2150 opt_constructor_initializer
2153 var c = (Constructor) $8;
2154 c.Initializer = (ConstructorInitializer) $9;
2157 report.Error (514, c.Location,
2158 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2159 c.GetSignatureForError ());
2169 | SEMICOLON { current_block = null; $$ = null; }
2172 opt_constructor_initializer
2174 | constructor_initializer
2177 constructor_initializer
2178 : COLON BASE OPEN_PARENS
2180 ++lexer.parsing_block;
2182 opt_argument_list CLOSE_PARENS
2184 --lexer.parsing_block;
2185 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2186 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2188 | COLON THIS OPEN_PARENS
2190 ++lexer.parsing_block;
2192 opt_argument_list CLOSE_PARENS
2194 --lexer.parsing_block;
2195 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2196 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2200 Error_SyntaxError (yyToken);
2201 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2202 lbag.AddLocation ($$, GetLocation ($1));
2206 Error_SyntaxError (yyToken);
2211 destructor_declaration
2212 : opt_attributes opt_modifiers TILDE
2215 tmpComment = Lexer.consume_doc_comment ();
2216 Lexer.doc_state = XmlCommentState.NotAllowed;
2219 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2221 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2223 var lt = (Tokenizer.LocatedToken) $5;
2224 if (lt.Value != current_container.MemberName.Name){
2225 report.Error (574, lt.Location, "Name of destructor must match name of class");
2226 } else if (current_container.Kind != MemberKind.Class){
2227 report.Error (575, lt.Location, "Only class types can contain destructor");
2230 Destructor d = new Destructor (current_type, (Modifiers) $2,
2231 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2233 d.DocComment = ConsumeStoredComment ();
2235 d.Block = (ToplevelBlock) $8;
2236 current_type.AddMember (d);
2237 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2239 current_local_parameters = null;
2246 EVENT type member_declaration_name
2248 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2249 current_type.AddMember (current_event_field);
2251 if (current_event_field.MemberName.ExplicitInterface != null) {
2252 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2253 current_event_field.GetSignatureForError ());
2256 $$ = current_event_field;
2258 opt_event_initializer
2259 opt_event_declarators
2263 current_event_field.DocComment = Lexer.consume_doc_comment ();
2264 Lexer.doc_state = XmlCommentState.Allowed;
2267 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2268 current_event_field = null;
2272 EVENT type member_declaration_name
2275 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2276 current_type.AddMember (current_event);
2277 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2279 lexer.EventParsing = true;
2281 event_accessor_declarations
2283 if (current_container.Kind == MemberKind.Interface)
2284 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2286 lexer.EventParsing = false;
2291 current_event.DocComment = Lexer.consume_doc_comment ();
2292 Lexer.doc_state = XmlCommentState.Allowed;
2295 lbag.AppendToMember (current_event, GetLocation ($9));
2296 current_event = null;
2297 current_local_parameters = null;
2301 opt_event_initializer
2305 ++lexer.parsing_block;
2307 event_variable_initializer
2309 --lexer.parsing_block;
2310 current_event_field.Initializer = (Expression) $3;
2314 opt_event_declarators
2322 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2324 | event_declarators event_declarator
2326 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2333 var lt = (Tokenizer.LocatedToken) $2;
2334 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2335 lbag.AddLocation ($$, GetLocation ($1));
2337 | COMMA IDENTIFIER ASSIGN
2339 ++lexer.parsing_block;
2341 event_variable_initializer
2343 --lexer.parsing_block;
2344 var lt = (Tokenizer.LocatedToken) $2;
2345 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2346 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2350 event_variable_initializer
2352 if (current_container.Kind == MemberKind.Interface) {
2353 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2354 current_event_field.GetSignatureForError ());
2357 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2358 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2359 current_event_field.GetSignatureForError ());
2362 variable_initializer
2368 event_accessor_declarations
2369 : add_accessor_declaration remove_accessor_declaration
2370 | remove_accessor_declaration add_accessor_declaration
2371 | add_accessor_declaration
2373 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2374 current_event.GetSignatureForError ());
2376 | remove_accessor_declaration
2378 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2379 current_event.GetSignatureForError ());
2383 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2388 add_accessor_declaration
2389 : opt_attributes opt_modifiers ADD
2391 if ($2 != ModifierNone) {
2392 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2395 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2396 current_local_parameters = current_event.Add.ParameterInfo;
2398 lbag.AddMember (current_event.Add, mod_locations);
2399 lexer.EventParsing = false;
2401 event_accessor_block
2403 lexer.EventParsing = true;
2405 current_event.Add.Block = (ToplevelBlock) $5;
2407 if (current_container.Kind == MemberKind.Interface) {
2408 report.Error (531, current_event.Add.Block.StartLocation,
2409 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2412 current_local_parameters = null;
2416 remove_accessor_declaration
2417 : opt_attributes opt_modifiers REMOVE
2419 if ($2 != ModifierNone) {
2420 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2423 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2424 current_local_parameters = current_event.Remove.ParameterInfo;
2426 lbag.AddMember (current_event.Remove, mod_locations);
2427 lexer.EventParsing = false;
2429 event_accessor_block
2431 lexer.EventParsing = true;
2433 current_event.Remove.Block = (ToplevelBlock) $5;
2435 if (current_container.Kind == MemberKind.Interface) {
2436 report.Error (531, current_event.Remove.Block.StartLocation,
2437 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2440 current_local_parameters = null;
2444 event_accessor_block
2447 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2453 attributes_without_members
2454 : attribute_sections CLOSE_BRACE
2456 current_type.UnattachedAttributes = (Attributes) $1;
2457 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2458 lexer.putback ('}');
2465 ENUM type_declaration_name
2469 enumTypeComment = Lexer.consume_doc_comment ();
2474 Lexer.doc_state = XmlCommentState.Allowed;
2476 MemberName name = (MemberName) $4;
2477 if (name.IsGeneric) {
2478 report.Error (1675, name.Location, "Enums cannot have type parameters");
2481 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2483 opt_enum_member_declarations
2485 // here will be evaluated after CLOSE_BLACE is consumed.
2487 Lexer.doc_state = XmlCommentState.Allowed;
2489 CLOSE_BRACE opt_semicolon
2492 current_container.DocComment = enumTypeComment;
2494 --lexer.parsing_declaration;
2497 // em.DocComment = ev.DocComment;
2499 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2500 $$ = pop_current_class ();
2508 var te = $2 as TypeExpression;
2509 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2510 Enum.Error_1008 (GetLocation ($2), report);
2516 Error_TypeExpected (GetLocation ($1));
2521 opt_enum_member_declarations
2523 | enum_member_declarations
2524 | enum_member_declarations COMMA
2526 lbag.AddLocation ($1, GetLocation ($2));
2530 enum_member_declarations
2531 : enum_member_declaration
2532 | enum_member_declarations COMMA enum_member_declaration
2534 lbag.AddLocation ($1, GetLocation ($2));
2539 enum_member_declaration
2540 : opt_attributes IDENTIFIER
2542 var lt = (Tokenizer.LocatedToken) $2;
2543 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2544 ((Enum) current_type).AddEnumMember (em);
2547 em.DocComment = Lexer.consume_doc_comment ();
2548 Lexer.doc_state = XmlCommentState.Allowed;
2553 | opt_attributes IDENTIFIER
2555 ++lexer.parsing_block;
2557 tmpComment = Lexer.consume_doc_comment ();
2558 Lexer.doc_state = XmlCommentState.NotAllowed;
2561 ASSIGN constant_expression
2563 --lexer.parsing_block;
2565 var lt = (Tokenizer.LocatedToken) $2;
2566 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2567 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2568 ((Enum) current_type).AddEnumMember (em);
2571 em.DocComment = ConsumeStoredComment ();
2575 | opt_attributes IDENTIFIER error
2577 Error_SyntaxError (yyToken);
2579 var lt = (Tokenizer.LocatedToken) $2;
2580 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2581 ((Enum) current_type).AddEnumMember (em);
2584 em.DocComment = Lexer.consume_doc_comment ();
2585 Lexer.doc_state = XmlCommentState.Allowed;
2590 | attributes_without_members
2593 delegate_declaration
2597 member_type type_declaration_name
2600 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2602 opt_formal_parameter_list CLOSE_PARENS
2604 valid_param_mod = 0;
2606 ParametersCompiled p = (ParametersCompiled) $8;
2608 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2610 p.CheckParameters (del);
2612 current_container.AddTypeContainer (del);
2614 current_delegate = del;
2615 lexer.ConstraintsParsing = true;
2617 opt_type_parameter_constraints_clauses
2619 lexer.ConstraintsParsing = false;
2624 current_delegate.DocComment = Lexer.consume_doc_comment ();
2625 Lexer.doc_state = XmlCommentState.Allowed;
2629 current_delegate.SetConstraints ((List<Constraints>) $11);
2630 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2632 $$ = current_delegate;
2634 current_delegate = null;
2642 if (lang_version < LanguageVersion.ISO_2)
2643 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2645 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2649 namespace_or_type_expr
2651 | qualified_alias_member IDENTIFIER opt_type_argument_list
2653 var lt1 = (Tokenizer.LocatedToken) $1;
2654 var lt2 = (Tokenizer.LocatedToken) $2;
2656 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2657 lbag.AddLocation ($$, GetLocation ($2));
2663 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2665 var lt = (Tokenizer.LocatedToken) $3;
2666 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2667 lbag.AddLocation ($$, GetLocation ($2));
2672 : IDENTIFIER opt_type_argument_list
2674 var lt = (Tokenizer.LocatedToken) $1;
2675 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2680 // Generics arguments (any type, without attributes)
2682 opt_type_argument_list
2684 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2686 if (lang_version < LanguageVersion.ISO_2)
2687 FeatureIsNotAvailable (GetLocation ($1), "generics");
2691 | OP_GENERICS_LT error
2693 Error_TypeExpected (lexer.Location);
2694 $$ = new TypeArguments ();
2701 TypeArguments type_args = new TypeArguments ();
2702 type_args.Add ((FullNamedExpression) $1);
2705 | type_arguments COMMA type
2707 TypeArguments type_args = (TypeArguments) $1;
2708 type_args.Add ((FullNamedExpression) $3);
2714 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2716 type_declaration_name
2719 lexer.parsing_generic_declaration = true;
2721 opt_type_parameter_list
2723 lexer.parsing_generic_declaration = false;
2724 var lt = (Tokenizer.LocatedToken) $1;
2725 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2729 member_declaration_name
2730 : method_declaration_name
2732 MemberName mn = (MemberName)$1;
2733 if (mn.TypeParameters != null)
2734 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2735 mn.GetSignatureForError ()));
2739 method_declaration_name
2740 : type_declaration_name
2741 | explicit_interface IDENTIFIER opt_type_parameter_list
2743 lexer.parsing_generic_declaration = false;
2744 var lt = (Tokenizer.LocatedToken) $2;
2745 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2749 indexer_declaration_name
2752 lexer.parsing_generic_declaration = false;
2753 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2755 | explicit_interface THIS
2757 lexer.parsing_generic_declaration = false;
2758 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2763 : IDENTIFIER opt_type_argument_list DOT
2765 var lt = (Tokenizer.LocatedToken) $1;
2766 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2767 lbag.AddLocation ($$, GetLocation ($3));
2769 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2771 var lt1 = (Tokenizer.LocatedToken) $1;
2772 var lt2 = (Tokenizer.LocatedToken) $2;
2774 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2775 lbag.AddLocation ($$, GetLocation ($4));
2777 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2779 var lt = (Tokenizer.LocatedToken) $2;
2780 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2781 lbag.AddLocation ($$, GetLocation ($4));
2785 opt_type_parameter_list
2787 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2789 if (lang_version < LanguageVersion.ISO_2)
2790 FeatureIsNotAvailable (GetLocation ($1), "generics");
2793 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2800 var tparams = new TypeParameters ();
2801 tparams.Add ((TypeParameter)$1);
2804 | type_parameters COMMA type_parameter
2806 var tparams = (TypeParameters) $1;
2807 tparams.Add ((TypeParameter)$3);
2809 lbag.AddLocation ($3, GetLocation ($3));
2814 : opt_attributes opt_type_parameter_variance IDENTIFIER
2816 var lt = (Tokenizer.LocatedToken)$3;
2817 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2821 if (GetTokenName (yyToken) == "type")
2822 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2824 Error_SyntaxError (yyToken);
2826 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2831 // All types where void is allowed
2834 : type_expression_or_array
2837 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2844 lexer.parsing_generic_declaration = true;
2849 // A type which does not allow `void' to be used
2852 : type_expression_or_array
2855 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2856 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2864 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2865 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2870 : type_expression_or_array
2873 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2874 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2878 type_expression_or_array
2880 | type_expression rank_specifiers
2882 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2887 : namespace_or_type_expr opt_nullable
2890 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2892 var sn = $1 as SimpleName;
2893 if (sn != null && sn.Name == "var")
2894 $$ = new VarExpr (sn.Location);
2899 | namespace_or_type_expr pointer_stars
2901 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2903 | builtin_types opt_nullable
2906 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2908 | builtin_types pointer_stars
2910 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2912 | VOID pointer_stars
2914 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2921 var types = new List<FullNamedExpression> (2);
2922 types.Add ((FullNamedExpression) $1);
2925 | type_list COMMA base_type_name
2927 var types = (List<FullNamedExpression>) $1;
2928 types.Add ((FullNamedExpression) $3);
2936 if ($1 is ComposedCast) {
2937 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2944 * replaces all the productions for isolating the various
2945 * simple types, but we need this to reuse it easily in variable_type
2948 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
2949 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
2950 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
2951 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
2952 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
2953 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
2958 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
2959 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
2960 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
2961 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
2962 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
2963 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
2964 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
2965 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
2966 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
2970 // Expressions, section 7.5
2975 : primary_expression_or_type
2977 | array_creation_expression
2978 | parenthesized_expression
2979 | default_value_expression
2980 | invocation_expression
2984 | post_increment_expression
2985 | post_decrement_expression
2986 | object_or_delegate_creation_expression
2987 | anonymous_type_expression
2990 | checked_expression
2991 | unchecked_expression
2992 | pointer_member_access
2993 | anonymous_method_expression
2994 | undocumented_expressions
2997 primary_expression_or_type
2998 : IDENTIFIER opt_type_argument_list
3000 var lt = (Tokenizer.LocatedToken) $1;
3001 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3003 | IDENTIFIER GENERATE_COMPLETION {
3004 var lt = (Tokenizer.LocatedToken) $1;
3005 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3013 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3017 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3018 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3023 // Here is the trick, tokenizer may think that parens is a special but
3024 // parser is interested in open parens only, so we merge them.
3025 // Consider: if (a)foo ();
3033 // Use this production to accept closing parenthesis or
3034 // performing completion
3038 | COMPLETE_COMPLETION
3042 parenthesized_expression
3043 : OPEN_PARENS expression CLOSE_PARENS
3045 $$ = new ParenthesizedExpression ((Expression) $2);
3046 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3048 | OPEN_PARENS expression COMPLETE_COMPLETION
3050 $$ = new ParenthesizedExpression ((Expression) $2);
3055 : primary_expression DOT IDENTIFIER opt_type_argument_list
3057 var lt = (Tokenizer.LocatedToken) $3;
3058 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3059 lbag.AddLocation ($$, GetLocation ($2));
3061 | builtin_types DOT IDENTIFIER opt_type_argument_list
3063 var lt = (Tokenizer.LocatedToken) $3;
3064 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3065 lbag.AddLocation ($$, GetLocation ($2));
3067 | BASE DOT IDENTIFIER opt_type_argument_list
3069 var lt = (Tokenizer.LocatedToken) $3;
3070 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3071 lbag.AddLocation ($$, GetLocation ($2));
3073 | qualified_alias_member IDENTIFIER opt_type_argument_list
3075 var lt1 = (Tokenizer.LocatedToken) $1;
3076 var lt2 = (Tokenizer.LocatedToken) $2;
3078 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3079 lbag.AddLocation ($$, GetLocation ($2));
3081 | primary_expression DOT GENERATE_COMPLETION {
3082 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3084 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3085 var lt = (Tokenizer.LocatedToken) $3;
3086 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3088 | builtin_types DOT GENERATE_COMPLETION
3090 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3092 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3093 var lt = (Tokenizer.LocatedToken) $3;
3094 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3098 invocation_expression
3099 : primary_expression open_parens_any opt_argument_list close_parens
3101 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3102 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3104 | primary_expression open_parens_any argument_list error
3106 Error_SyntaxError (yyToken);
3108 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3109 lbag.AddLocation ($$, GetLocation ($2));
3114 opt_object_or_collection_initializer
3115 : /* empty */ { $$ = null; }
3116 | object_or_collection_initializer
3119 object_or_collection_initializer
3120 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3123 $$ = CollectionOrObjectInitializers.Empty;
3126 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3127 lbag.AddLocation ($$, GetLocation ($3));
3130 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3132 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3133 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3137 opt_member_initializer_list
3138 : /* empty */ { $$ = null; }
3139 | member_initializer_list
3145 member_initializer_list
3146 : member_initializer
3148 var a = new List<Expression> ();
3149 a.Add ((Expression) $1);
3152 | member_initializer_list COMMA member_initializer
3154 var a = (List<Expression>)$1;
3155 a.Add ((Expression) $3);
3158 | member_initializer_list error {
3159 Error_SyntaxError (yyToken);
3165 : IDENTIFIER ASSIGN initializer_value
3167 var lt = (Tokenizer.LocatedToken) $1;
3168 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3169 lbag.AddLocation ($$, GetLocation ($2));
3171 | GENERATE_COMPLETION
3173 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3175 | non_assignment_expression opt_COMPLETE_COMPLETION {
3176 CompletionSimpleName csn = $1 as CompletionSimpleName;
3178 $$ = new CollectionElementInitializer ((Expression)$1);
3180 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3182 | OPEN_BRACE expression_list CLOSE_BRACE
3187 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3189 | OPEN_BRACE CLOSE_BRACE
3191 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3198 | object_or_collection_initializer
3202 : /* empty */ { $$ = null; }
3207 : argument_or_named_argument
3209 Arguments list = new Arguments (4);
3210 list.Add ((Argument) $1);
3213 | argument_list COMMA argument
3215 Arguments list = (Arguments) $1;
3216 if (list [list.Count - 1] is NamedArgument)
3217 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3219 list.Add ((Argument) $3);
3222 | argument_list COMMA named_argument
3224 Arguments list = (Arguments) $1;
3225 NamedArgument a = (NamedArgument) $3;
3226 for (int i = 0; i < list.Count; ++i) {
3227 NamedArgument na = list [i] as NamedArgument;
3228 if (na != null && na.Name == a.Name)
3229 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3236 | argument_list COMMA error
3238 lexer.putback (')'); // TODO: Wrong but what can I do
3239 Error_SyntaxError (yyToken);
3244 report.Error (839, GetLocation ($1), "An argument is missing");
3252 $$ = new Argument ((Expression) $1);
3254 | non_simple_argument
3257 argument_or_named_argument
3263 : REF variable_reference
3265 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3266 lbag.AddLocation ($$, GetLocation ($1));
3268 | OUT variable_reference
3270 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3271 lbag.AddLocation ($$, GetLocation ($1));
3273 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3275 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3276 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3278 | ARGLIST OPEN_PARENS CLOSE_PARENS
3280 $$ = new Argument (new Arglist (GetLocation ($1)));
3281 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3290 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3292 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3293 lbag.AddLocation ($$, GetLocation ($4));
3295 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3297 Error_SyntaxError (yyToken);
3298 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3300 | primary_expression OPEN_BRACKET_EXPR error
3302 Error_SyntaxError (yyToken);
3303 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3310 var list = new List<Expression> (4);
3311 list.Add ((Expression) $1);
3314 | expression_list COMMA expression
3316 var list = (List<Expression>) $1;
3317 list.Add ((Expression) $3);
3320 | expression_list error {
3321 Error_SyntaxError (yyToken);
3326 expression_list_arguments
3327 : expression_list_argument
3329 Arguments args = new Arguments (4);
3330 args.Add ((Argument) $1);
3333 | expression_list_arguments COMMA expression_list_argument
3335 Arguments args = (Arguments) $1;
3336 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3337 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3339 args.Add ((Argument) $3);
3344 expression_list_argument
3347 $$ = new Argument ((Expression) $1);
3355 $$ = new This (GetLocation ($1));
3360 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3362 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3363 lbag.AddLocation ($$, GetLocation ($4));
3365 | BASE OPEN_BRACKET error
3367 Error_SyntaxError (yyToken);
3368 $$ = new ElementAccess (null, null, GetLocation ($2));
3372 post_increment_expression
3373 : primary_expression OP_INC
3375 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3379 post_decrement_expression
3380 : primary_expression OP_DEC
3382 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3386 object_or_delegate_creation_expression
3387 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3390 if (lang_version <= LanguageVersion.ISO_2)
3391 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3393 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3395 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3398 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3400 | NEW new_expr_type object_or_collection_initializer
3402 if (lang_version <= LanguageVersion.ISO_2)
3403 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3405 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3409 array_creation_expression
3410 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3412 opt_array_initializer
3414 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3415 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3416 Next = (ComposedTypeSpecifier) $6
3417 }, (ArrayInitializer) $7, GetLocation ($1));
3418 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3420 | NEW new_expr_type rank_specifiers opt_array_initializer
3423 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3425 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3427 | NEW rank_specifier array_initializer
3429 if (lang_version <= LanguageVersion.ISO_2)
3430 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3432 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3434 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3436 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3437 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3439 | NEW new_expr_type error
3441 Error_SyntaxError (yyToken);
3442 // It can be any of new expression, create the most common one
3443 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3449 ++lexer.parsing_type;
3453 --lexer.parsing_type;
3458 anonymous_type_expression
3459 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3461 if (lang_version <= LanguageVersion.ISO_2)
3462 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3464 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3466 // TODO: lbag comma location
3467 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3471 anonymous_type_parameters_opt_comma
3472 : anonymous_type_parameters_opt
3473 | anonymous_type_parameters COMMA
3476 anonymous_type_parameters_opt
3478 | anonymous_type_parameters
3481 anonymous_type_parameters
3482 : anonymous_type_parameter
3484 var a = new List<AnonymousTypeParameter> (4);
3485 a.Add ((AnonymousTypeParameter) $1);
3488 | anonymous_type_parameters COMMA anonymous_type_parameter
3490 var a = (List<AnonymousTypeParameter>) $1;
3491 a.Add ((AnonymousTypeParameter) $3);
3496 anonymous_type_parameter
3497 : IDENTIFIER ASSIGN variable_initializer
3499 var lt = (Tokenizer.LocatedToken)$1;
3500 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3501 lbag.AddLocation ($$, GetLocation ($2));
3505 var lt = (Tokenizer.LocatedToken)$1;
3506 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3507 lt.Value, lt.Location);
3511 MemberAccess ma = (MemberAccess) $1;
3512 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3516 report.Error (746, lexer.Location,
3517 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3529 | rank_specifier rank_specifiers
3531 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3537 : OPEN_BRACKET CLOSE_BRACKET
3539 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3540 lbag.AddLocation ($$, GetLocation ($2));
3542 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3544 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3545 lbag.AddLocation ($$, GetLocation ($3));
3554 | dim_separators COMMA
3556 $$ = ((int) $1) + 1;
3560 opt_array_initializer
3572 : OPEN_BRACE CLOSE_BRACE
3574 var ai = new ArrayInitializer (0, GetLocation ($1));
3575 ai.VariableDeclaration = current_variable;
3576 lbag.AddLocation (ai, GetLocation ($2));
3579 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3581 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3582 ai.VariableDeclaration = current_variable;
3584 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3586 lbag.AddLocation (ai, GetLocation ($4));
3592 variable_initializer_list
3593 : variable_initializer
3595 var list = new List<Expression> (4);
3596 list.Add ((Expression) $1);
3599 | variable_initializer_list COMMA variable_initializer
3601 var list = (List<Expression>) $1;
3602 list.Add ((Expression) $3);
3610 lexer.TypeOfParsing = true;
3612 open_parens_any typeof_type_expression CLOSE_PARENS
3614 lexer.TypeOfParsing = false;
3615 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3616 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3620 typeof_type_expression
3625 Error_TypeExpected (lexer.Location);
3631 : identifier_inside_body generic_dimension
3633 var lt = (Tokenizer.LocatedToken) $1;
3635 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3637 | qualified_alias_member identifier_inside_body generic_dimension
3639 var lt1 = (Tokenizer.LocatedToken) $1;
3640 var lt2 = (Tokenizer.LocatedToken) $2;
3642 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3643 lbag.AddLocation ($$, GetLocation ($2));
3645 | unbound_type_name DOT identifier_inside_body
3647 var lt = (Tokenizer.LocatedToken) $3;
3649 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3651 | unbound_type_name DOT identifier_inside_body generic_dimension
3653 var lt = (Tokenizer.LocatedToken) $3;
3655 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3657 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3659 var tne = (ATypeNameExpression) $1;
3660 if (tne.HasTypeArguments)
3661 Error_TypeExpected (GetLocation ($4));
3663 var lt = (Tokenizer.LocatedToken) $3;
3664 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3671 if (lang_version < LanguageVersion.ISO_2)
3672 FeatureIsNotAvailable (GetLocation ($1), "generics");
3678 qualified_alias_member
3679 : IDENTIFIER DOUBLE_COLON
3681 var lt = (Tokenizer.LocatedToken) $1;
3682 if (lang_version == LanguageVersion.ISO_1)
3683 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3690 : SIZEOF open_parens_any type CLOSE_PARENS
3692 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3693 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3698 : CHECKED open_parens_any expression CLOSE_PARENS
3700 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3701 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3705 unchecked_expression
3706 : UNCHECKED open_parens_any expression CLOSE_PARENS
3708 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3709 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3713 pointer_member_access
3714 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3716 var lt = (Tokenizer.LocatedToken) $3;
3717 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3721 anonymous_method_expression
3722 : DELEGATE opt_anonymous_method_signature
3724 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3728 $$ = end_anonymous ((ParametersBlock) $4);
3730 | ASYNC DELEGATE opt_anonymous_method_signature
3732 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3736 $$ = end_anonymous ((ParametersBlock) $5);
3740 opt_anonymous_method_signature
3743 $$ = ParametersCompiled.Undefined;
3745 | anonymous_method_signature
3748 anonymous_method_signature
3751 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3753 opt_formal_parameter_list CLOSE_PARENS
3755 valid_param_mod = 0;
3760 default_value_expression
3761 : DEFAULT open_parens_any type CLOSE_PARENS
3763 if (lang_version < LanguageVersion.ISO_2)
3764 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3766 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3767 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3772 : primary_expression
3773 | BANG prefixed_unary_expression
3775 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3777 | TILDE prefixed_unary_expression
3779 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3781 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3783 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3784 lbag.AddLocation ($$, GetLocation ($3));
3786 | AWAIT prefixed_unary_expression
3789 if (current_anonymous_method is LambdaExpression) {
3790 report.Error (4034, GetLocation ($1),
3791 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3792 } else if (current_anonymous_method is AnonymousMethodExpression) {
3793 report.Error (4035, GetLocation ($1),
3794 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3796 report.Error (4033, GetLocation ($1),
3797 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3800 current_block.Explicit.RegisterAsyncAwait ();
3803 $$ = new Await ((Expression) $2, GetLocation ($1));
3808 // The idea to split this out is from Rhys' grammar
3809 // to solve the problem with casts.
3811 prefixed_unary_expression
3813 | PLUS prefixed_unary_expression
3815 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3817 | MINUS prefixed_unary_expression
3819 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3821 | OP_INC prefixed_unary_expression
3823 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3825 | OP_DEC prefixed_unary_expression
3827 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3829 | STAR prefixed_unary_expression
3831 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3833 | BITWISE_AND prefixed_unary_expression
3835 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3839 multiplicative_expression
3840 : prefixed_unary_expression
3841 | multiplicative_expression STAR prefixed_unary_expression
3843 $$ = new Binary (Binary.Operator.Multiply,
3844 (Expression) $1, (Expression) $3, GetLocation ($2));
3846 | multiplicative_expression DIV prefixed_unary_expression
3848 $$ = new Binary (Binary.Operator.Division,
3849 (Expression) $1, (Expression) $3, GetLocation ($2));
3851 | multiplicative_expression PERCENT prefixed_unary_expression
3853 $$ = new Binary (Binary.Operator.Modulus,
3854 (Expression) $1, (Expression) $3, GetLocation ($2));
3859 : multiplicative_expression
3860 | additive_expression PLUS multiplicative_expression
3862 $$ = new Binary (Binary.Operator.Addition,
3863 (Expression) $1, (Expression) $3, GetLocation ($2));
3865 | additive_expression MINUS multiplicative_expression
3867 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3869 | parenthesized_expression MINUS multiplicative_expression
3871 // Shift/Reduce conflict
3872 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3874 | additive_expression AS type
3876 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3878 | additive_expression IS type
3880 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3885 : additive_expression
3886 | shift_expression OP_SHIFT_LEFT additive_expression
3888 $$ = new Binary (Binary.Operator.LeftShift,
3889 (Expression) $1, (Expression) $3, GetLocation ($2));
3891 | shift_expression OP_SHIFT_RIGHT additive_expression
3893 $$ = new Binary (Binary.Operator.RightShift,
3894 (Expression) $1, (Expression) $3, GetLocation ($2));
3898 relational_expression
3900 | relational_expression OP_LT shift_expression
3902 $$ = new Binary (Binary.Operator.LessThan,
3903 (Expression) $1, (Expression) $3, GetLocation ($2));
3905 | relational_expression OP_GT shift_expression
3907 $$ = new Binary (Binary.Operator.GreaterThan,
3908 (Expression) $1, (Expression) $3, GetLocation ($2));
3910 | relational_expression OP_LE shift_expression
3912 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3913 (Expression) $1, (Expression) $3, GetLocation ($2));
3915 | relational_expression OP_GE shift_expression
3917 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3918 (Expression) $1, (Expression) $3, GetLocation ($2));
3923 : relational_expression
3924 | equality_expression OP_EQ relational_expression
3926 $$ = new Binary (Binary.Operator.Equality,
3927 (Expression) $1, (Expression) $3, GetLocation ($2));
3929 | equality_expression OP_NE relational_expression
3931 $$ = new Binary (Binary.Operator.Inequality,
3932 (Expression) $1, (Expression) $3, GetLocation ($2));
3937 : equality_expression
3938 | and_expression BITWISE_AND equality_expression
3940 $$ = new Binary (Binary.Operator.BitwiseAnd,
3941 (Expression) $1, (Expression) $3, GetLocation ($2));
3945 exclusive_or_expression
3947 | exclusive_or_expression CARRET and_expression
3949 $$ = new Binary (Binary.Operator.ExclusiveOr,
3950 (Expression) $1, (Expression) $3, GetLocation ($2));
3954 inclusive_or_expression
3955 : exclusive_or_expression
3956 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3958 $$ = new Binary (Binary.Operator.BitwiseOr,
3959 (Expression) $1, (Expression) $3, GetLocation ($2));
3963 conditional_and_expression
3964 : inclusive_or_expression
3965 | conditional_and_expression OP_AND inclusive_or_expression
3967 $$ = new Binary (Binary.Operator.LogicalAnd,
3968 (Expression) $1, (Expression) $3, GetLocation ($2));
3972 conditional_or_expression
3973 : conditional_and_expression
3974 | conditional_or_expression OP_OR conditional_and_expression
3976 $$ = new Binary (Binary.Operator.LogicalOr,
3977 (Expression) $1, (Expression) $3, GetLocation ($2));
3981 null_coalescing_expression
3982 : conditional_or_expression
3983 | conditional_or_expression OP_COALESCING null_coalescing_expression
3985 if (lang_version < LanguageVersion.ISO_2)
3986 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3988 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3992 conditional_expression
3993 : null_coalescing_expression
3994 | null_coalescing_expression INTERR expression COLON expression_or_error
3996 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3997 lbag.AddLocation ($$, GetLocation ($4));
3999 | null_coalescing_expression INTERR expression error
4001 Error_SyntaxError (yyToken);
4002 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4006 assignment_expression
4007 : prefixed_unary_expression ASSIGN expression
4009 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4010 lbag.AddLocation ($$, GetLocation ($2));
4012 | prefixed_unary_expression OP_MULT_ASSIGN expression
4014 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4015 lbag.AddLocation ($$, GetLocation ($2));
4017 | prefixed_unary_expression OP_DIV_ASSIGN expression
4019 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4020 lbag.AddLocation ($$, GetLocation ($2));
4022 | prefixed_unary_expression OP_MOD_ASSIGN expression
4024 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4025 lbag.AddLocation ($$, GetLocation ($2));
4027 | prefixed_unary_expression OP_ADD_ASSIGN expression
4029 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4030 lbag.AddLocation ($$, GetLocation ($2));
4032 | prefixed_unary_expression OP_SUB_ASSIGN expression
4034 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4035 lbag.AddLocation ($$, GetLocation ($2));
4037 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4039 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4040 lbag.AddLocation ($$, GetLocation ($2));
4042 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4044 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4045 lbag.AddLocation ($$, GetLocation ($2));
4047 | prefixed_unary_expression OP_AND_ASSIGN expression
4049 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4050 lbag.AddLocation ($$, GetLocation ($2));
4052 | prefixed_unary_expression OP_OR_ASSIGN expression
4054 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4055 lbag.AddLocation ($$, GetLocation ($2));
4057 | prefixed_unary_expression OP_XOR_ASSIGN expression
4059 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4060 lbag.AddLocation ($$, GetLocation ($2));
4064 lambda_parameter_list
4067 var pars = new List<Parameter> (4);
4068 pars.Add ((Parameter) $1);
4072 | lambda_parameter_list COMMA lambda_parameter
4074 var pars = (List<Parameter>) $1;
4075 Parameter p = (Parameter)$3;
4076 if (pars[0].GetType () != p.GetType ()) {
4077 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4086 : parameter_modifier parameter_type identifier_inside_body
4088 var lt = (Tokenizer.LocatedToken) $3;
4090 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4092 | parameter_type identifier_inside_body
4094 var lt = (Tokenizer.LocatedToken) $2;
4096 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4100 var lt = (Tokenizer.LocatedToken) $1;
4101 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4105 opt_lambda_parameter_list
4106 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4107 | lambda_parameter_list {
4108 var pars_list = (List<Parameter>) $1;
4109 $$ = new ParametersCompiled (pars_list.ToArray ());
4113 lambda_expression_body
4114 : lambda_expression_body_simple
4118 lambda_expression_body_simple
4120 start_block (Location.Null);
4122 expression_or_error // Have to close block when error occurs
4124 Block b = end_block (Location.Null);
4125 b.IsCompilerGenerated = true;
4126 b.AddStatement (new ContextualReturn ((Expression) $2));
4135 Error_SyntaxError (yyToken);
4136 $$ = EmptyExpression.Null;
4143 var lt = (Tokenizer.LocatedToken) $1;
4144 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4145 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4147 lambda_expression_body
4149 $$ = end_anonymous ((ParametersBlock) $4);
4150 lbag.AddLocation ($$, GetLocation ($2));
4152 | ASYNC identifier_inside_body ARROW
4154 var lt = (Tokenizer.LocatedToken) $2;
4155 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4156 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4158 lambda_expression_body
4160 $$ = end_anonymous ((ParametersBlock) $5);
4161 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4163 | OPEN_PARENS_LAMBDA
4165 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4167 opt_lambda_parameter_list CLOSE_PARENS ARROW
4169 valid_param_mod = 0;
4170 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4172 lambda_expression_body
4174 $$ = end_anonymous ((ParametersBlock) $7);
4175 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4177 | ASYNC OPEN_PARENS_LAMBDA
4179 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4181 opt_lambda_parameter_list CLOSE_PARENS ARROW
4183 valid_param_mod = 0;
4184 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4186 lambda_expression_body
4188 $$ = end_anonymous ((ParametersBlock) $8);
4189 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4194 : assignment_expression
4195 | non_assignment_expression
4198 non_assignment_expression
4199 : conditional_expression
4204 $$ = new ArglistAccess (GetLocation ($1));
4208 undocumented_expressions
4209 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4211 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4212 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4214 | REFTYPE open_parens_any expression CLOSE_PARENS
4216 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4217 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4219 | MAKEREF open_parens_any expression CLOSE_PARENS
4221 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4222 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4233 $$ = new BooleanExpression ((Expression) $1);
4246 lexer.ConstraintsParsing = true;
4248 type_declaration_name
4250 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4251 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4252 FeatureIsNotAvailable (c.Location, "static classes");
4255 push_current_container (c, $3);
4258 opt_type_parameter_constraints_clauses
4260 lexer.ConstraintsParsing = false;
4263 current_container.SetConstraints ((List<Constraints>) $9);
4264 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4267 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4268 Lexer.doc_state = XmlCommentState.Allowed;
4271 lexer.parsing_modifiers = true;
4273 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4275 --lexer.parsing_declaration;
4277 Lexer.doc_state = XmlCommentState.Allowed;
4281 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4282 $$ = pop_current_class ();
4290 { $$ = $1; } // location
4296 mod_locations = null;
4298 lexer.parsing_modifiers = false;
4302 lexer.parsing_modifiers = false;
4308 | modifiers modifier
4310 var m1 = (Modifiers) $1;
4311 var m2 = (Modifiers) $2;
4313 if ((m1 & m2) != 0) {
4314 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4315 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4316 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4317 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4318 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4319 "More than one protection modifier specified");
4330 StoreModifierLocation ($$, GetLocation ($1));
4332 if (current_container.Kind == MemberKind.Namespace)
4333 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4337 $$ = Modifiers.PUBLIC;
4338 StoreModifierLocation ($$, GetLocation ($1));
4342 $$ = Modifiers.PROTECTED;
4343 StoreModifierLocation ($$, GetLocation ($1));
4347 $$ = Modifiers.INTERNAL;
4348 StoreModifierLocation ($$, GetLocation ($1));
4352 $$ = Modifiers.PRIVATE;
4353 StoreModifierLocation ($$, GetLocation ($1));
4357 $$ = Modifiers.ABSTRACT;
4358 StoreModifierLocation ($$, GetLocation ($1));
4362 $$ = Modifiers.SEALED;
4363 StoreModifierLocation ($$, GetLocation ($1));
4367 $$ = Modifiers.STATIC;
4368 StoreModifierLocation ($$, GetLocation ($1));
4372 $$ = Modifiers.READONLY;
4373 StoreModifierLocation ($$, GetLocation ($1));
4377 $$ = Modifiers.VIRTUAL;
4378 StoreModifierLocation ($$, GetLocation ($1));
4382 $$ = Modifiers.OVERRIDE;
4383 StoreModifierLocation ($$, GetLocation ($1));
4387 $$ = Modifiers.EXTERN;
4388 StoreModifierLocation ($$, GetLocation ($1));
4392 $$ = Modifiers.VOLATILE;
4393 StoreModifierLocation ($$, GetLocation ($1));
4397 $$ = Modifiers.UNSAFE;
4398 StoreModifierLocation ($$, GetLocation ($1));
4399 if (!settings.Unsafe)
4400 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4404 $$ = Modifiers.ASYNC;
4405 StoreModifierLocation ($$, GetLocation ($1));
4413 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4415 | COLON type_list error
4417 Error_SyntaxError (yyToken);
4419 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4423 opt_type_parameter_constraints_clauses
4425 | type_parameter_constraints_clauses
4431 type_parameter_constraints_clauses
4432 : type_parameter_constraints_clause
4434 var constraints = new List<Constraints> (1);
4435 constraints.Add ((Constraints) $1);
4438 | type_parameter_constraints_clauses type_parameter_constraints_clause
4440 var constraints = (List<Constraints>) $1;
4441 Constraints new_constraint = (Constraints)$2;
4443 foreach (Constraints c in constraints) {
4444 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4445 report.Error (409, new_constraint.Location,
4446 "A constraint clause has already been specified for type parameter `{0}'",
4447 new_constraint.TypeParameter.Value);
4451 constraints.Add (new_constraint);
4456 type_parameter_constraints_clause
4457 : WHERE IDENTIFIER COLON type_parameter_constraints
4459 var lt = (Tokenizer.LocatedToken) $2;
4460 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4461 lbag.AddLocation ($$, GetLocation ($3));
4463 | WHERE IDENTIFIER error
4465 Error_SyntaxError (yyToken);
4467 var lt = (Tokenizer.LocatedToken) $2;
4468 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4472 type_parameter_constraints
4473 : type_parameter_constraint
4475 var constraints = new List<FullNamedExpression> (1);
4476 constraints.Add ((FullNamedExpression) $1);
4479 | type_parameter_constraints COMMA type_parameter_constraint
4481 var constraints = (List<FullNamedExpression>) $1;
4482 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4483 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4484 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4487 prev = $3 as SpecialContraintExpr;
4489 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4490 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4492 prev = constraints [0] as SpecialContraintExpr;
4493 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4494 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4499 constraints.Add ((FullNamedExpression) $3);
4504 type_parameter_constraint
4507 if ($1 is ComposedCast)
4508 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4512 | NEW OPEN_PARENS CLOSE_PARENS
4514 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4515 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4519 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4523 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4527 opt_type_parameter_variance
4532 | type_parameter_variance
4534 if (lang_version <= LanguageVersion.V_3)
4535 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4541 type_parameter_variance
4544 $$ = Variance.Covariant;
4548 $$ = Variance.Contravariant;
4557 // A block is "contained" on the following places:
4559 // property_declaration as part of the accessor body (get/set)
4560 // operator_declaration
4561 // constructor_declaration
4562 // destructor_declaration
4563 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4568 ++lexer.parsing_block;
4569 start_block (GetLocation ($1));
4571 opt_statement_list block_end
4580 --lexer.parsing_block;
4581 $$ = end_block (GetLocation ($1));
4583 | COMPLETE_COMPLETION
4585 --lexer.parsing_block;
4586 $$ = end_block (lexer.Location);
4594 ++lexer.parsing_block;
4595 current_block.StartLocation = GetLocation ($1);
4597 opt_statement_list CLOSE_BRACE
4599 --lexer.parsing_block;
4600 $$ = end_block (GetLocation ($4));
4611 | statement_list statement
4615 : block_variable_declaration
4617 current_block.AddStatement ((Statement) $1);
4619 | valid_declaration_statement
4621 current_block.AddStatement ((Statement) $1);
4626 Error_SyntaxError (yyToken);
4632 // The interactive_statement and its derivatives are only
4633 // used to provide a special version of `expression_statement'
4634 // that has a side effect of assigning the expression to
4637 interactive_statement_list
4638 : interactive_statement
4639 | interactive_statement_list interactive_statement
4642 interactive_statement
4643 : block_variable_declaration
4645 current_block.AddStatement ((Statement) $1);
4647 | interactive_valid_declaration_statement
4649 current_block.AddStatement ((Statement) $1);
4654 valid_declaration_statement
4657 | expression_statement
4658 | selection_statement
4659 | iteration_statement
4663 | unchecked_statement
4670 interactive_valid_declaration_statement
4673 | interactive_expression_statement
4674 | selection_statement
4675 | iteration_statement
4679 | unchecked_statement
4687 : valid_declaration_statement
4688 | block_variable_declaration
4690 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4695 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4700 Error_SyntaxError (yyToken);
4701 $$ = new EmptyStatement (GetLocation ($1));
4708 // Uses lexer.Location because semicolon location is not kept in quick mode
4709 $$ = new EmptyStatement (lexer.Location);
4714 : identifier_inside_body COLON
4716 var lt = (Tokenizer.LocatedToken) $1;
4717 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4718 lbag.AddLocation (labeled, GetLocation ($2));
4719 current_block.AddLabel (labeled);
4720 current_block.AddStatement (labeled);
4726 : variable_type_simple
4727 | variable_type_simple rank_specifiers
4730 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4732 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4737 * The following is from Rhys' grammar:
4738 * > Types in local variable declarations must be recognized as
4739 * > expressions to prevent reduce/reduce errors in the grammar.
4740 * > The expressions are converted into types during semantic analysis.
4742 variable_type_simple
4743 : primary_expression_or_type opt_nullable
4745 // Ok, the above "primary_expression" is there to get rid of
4746 // both reduce/reduce and shift/reduces in the grammar, it should
4747 // really just be "type_name". If you use type_name, a reduce/reduce
4748 // creeps up. If you use namespace_or_type_name (which is all we need
4749 // really) two shift/reduces appear.
4752 // So the super-trick is that primary_expression
4753 // can only be either a SimpleName or a MemberAccess.
4754 // The MemberAccess case arises when you have a fully qualified type-name like :
4756 // SimpleName is when you have
4759 Expression expr = (Expression) $1;
4761 SimpleName sn = expr as SimpleName;
4762 if (sn != null && sn.Name == "var")
4763 $$ = new VarExpr (sn.Location);
4766 } else if (expr is ATypeNameExpression) {
4767 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4769 Error_ExpectingTypeName (expr);
4773 | primary_expression_or_type pointer_stars
4775 ATypeNameExpression expr = $1 as ATypeNameExpression;
4778 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4780 Error_ExpectingTypeName ((Expression)$1);
4784 | builtin_types opt_nullable
4789 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4791 | builtin_types pointer_stars
4793 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4795 | VOID pointer_stars
4797 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4801 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
4802 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
4808 | pointer_star pointer_stars
4810 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4818 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4822 identifier_inside_body
4827 report.Error (4003, GetLocation ($1), "`await' cannot be used as an identifier within an async method or lambda expression");
4828 $$ = Tokenizer.LocatedToken.Create ("await", GetLocation ($1));
4833 block_variable_declaration
4834 : variable_type identifier_inside_body
4836 var lt = (Tokenizer.LocatedToken) $2;
4837 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4838 current_block.AddLocalName (li);
4839 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4841 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4843 $$ = current_variable;
4844 current_variable = null;
4845 lbag.AddLocation ($$, GetLocation ($6));
4847 | CONST variable_type identifier_inside_body
4849 var lt = (Tokenizer.LocatedToken) $3;
4850 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4851 current_block.AddLocalName (li);
4852 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4854 const_variable_initializer opt_const_declarators SEMICOLON
4856 $$ = current_variable;
4857 current_variable = null;
4858 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4862 opt_local_variable_initializer
4864 | ASSIGN block_variable_initializer
4866 current_variable.Initializer = (Expression) $2;
4871 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4872 report.Error (650, lexer.Location,
4873 "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");
4875 Error_SyntaxError (yyToken);
4880 opt_variable_declarators
4882 | variable_declarators
4885 opt_using_or_fixed_variable_declarators
4887 | variable_declarators
4889 foreach (var d in current_variable.Declarators) {
4890 if (d.Initializer == null)
4891 Error_MissingInitializer (d.Variable.Location);
4896 variable_declarators
4897 : variable_declarator
4898 | variable_declarators variable_declarator
4902 : COMMA identifier_inside_body
4904 var lt = (Tokenizer.LocatedToken) $2;
4905 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4906 var d = new BlockVariableDeclaration.Declarator (li, null);
4907 current_variable.AddDeclarator (d);
4908 current_block.AddLocalName (li);
4909 lbag.AddLocation (d, GetLocation ($1));
4911 | COMMA identifier_inside_body ASSIGN block_variable_initializer
4913 var lt = (Tokenizer.LocatedToken) $2;
4914 var li = new LocalVariable (current_variable.Variable, lt.Value, 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 const_variable_initializer
4925 report.Error (145, lexer.Location, "A const field requires a value to be provided");
4927 | ASSIGN constant_initializer_expr
4929 current_variable.Initializer = (Expression) $2;
4933 opt_const_declarators
4940 | const_declarators const_declarator
4944 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
4946 var lt = (Tokenizer.LocatedToken) $2;
4947 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4948 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4949 current_variable.AddDeclarator (d);
4950 current_block.AddLocalName (li);
4951 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4955 block_variable_initializer
4956 : variable_initializer
4957 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4959 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4960 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4962 | STACKALLOC simple_type
4964 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4965 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4969 expression_statement
4970 : statement_expression SEMICOLON
4973 lbag.AddStatement ($$, GetLocation ($2));
4975 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4976 | statement_expression CLOSE_BRACE
4979 report.Error (1002, GetLocation ($2), "; expected");
4980 lexer.putback ('}');
4984 interactive_expression_statement
4985 : interactive_statement_expression SEMICOLON { $$ = $1; }
4986 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4990 // We have to do the wrapping here and not in the case above,
4991 // because statement_expression is used for example in for_statement
4993 statement_expression
4996 ExpressionStatement s = $1 as ExpressionStatement;
4998 Expression.Error_InvalidExpressionStatement (report, GetLocation ($1));
4999 $$ = new StatementErrorExpression ($1 as Expression);
5001 $$ = new StatementExpression (s);
5006 interactive_statement_expression
5009 Expression expr = (Expression) $1;
5010 ExpressionStatement s;
5012 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5013 $$ = new StatementExpression (s);
5017 Error_SyntaxError (yyToken);
5018 $$ = new EmptyStatement (GetLocation ($1));
5028 : IF open_parens_any boolean_expression CLOSE_PARENS
5031 if ($5 is EmptyStatement)
5032 Warning_EmptyStatement (GetLocation ($5));
5034 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5035 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5037 | IF open_parens_any boolean_expression CLOSE_PARENS
5038 embedded_statement ELSE embedded_statement
5040 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5041 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5043 if ($5 is EmptyStatement)
5044 Warning_EmptyStatement (GetLocation ($5));
5045 if ($7 is EmptyStatement)
5046 Warning_EmptyStatement (GetLocation ($7));
5048 | IF open_parens_any boolean_expression error
5050 Error_SyntaxError (yyToken);
5052 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5053 lbag.AddStatement ($$, GetLocation ($2));
5058 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5060 start_block (GetLocation ($5));
5062 opt_switch_sections CLOSE_BRACE
5064 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
5065 end_block (GetLocation ($8));
5066 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5068 | SWITCH open_parens_any expression error
5070 Error_SyntaxError (yyToken);
5072 $$ = new Switch ((Expression) $3, null, null, GetLocation ($1));
5073 lbag.AddStatement ($$, GetLocation ($2));
5080 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5081 $$ = new List<SwitchSection> ();
5089 var sections = new List<SwitchSection> (4);
5091 sections.Add ((SwitchSection) $1);
5094 | switch_sections switch_section
5096 var sections = (List<SwitchSection>) $1;
5098 sections.Add ((SwitchSection) $2);
5103 Error_SyntaxError (yyToken);
5104 $$ = new List<SwitchSection> ();
5111 current_block = current_block.CreateSwitchBlock (lexer.Location);
5115 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
5122 var labels = new List<SwitchLabel> (2);
5124 labels.Add ((SwitchLabel) $1);
5127 | switch_labels switch_label
5129 var labels = (List<SwitchLabel>) ($1);
5130 labels.Add ((SwitchLabel) $2);
5137 : CASE constant_expression COLON
5139 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5140 lbag.AddLocation ($$, GetLocation ($3));
5142 | CASE constant_expression error
5144 Error_SyntaxError (yyToken);
5145 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5149 $$ = new SwitchLabel (null, GetLocation ($1));
5161 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5163 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5164 Warning_EmptyStatement (GetLocation ($5));
5166 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5167 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5169 | WHILE open_parens_any boolean_expression error
5171 Error_SyntaxError (yyToken);
5173 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5174 lbag.AddStatement ($$, GetLocation ($2));
5179 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5181 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5182 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5184 | DO embedded_statement error
5186 Error_SyntaxError (yyToken);
5187 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5189 | DO embedded_statement WHILE open_parens_any boolean_expression error
5191 Error_SyntaxError (yyToken);
5193 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5194 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5199 : FOR open_parens_any
5201 start_block (GetLocation ($2));
5202 current_block.IsCompilerGenerated = true;
5203 For f = new For (GetLocation ($1));
5204 current_block.AddStatement (f);
5213 // Has to use be extra rule to recover started block
5215 : opt_for_initializer SEMICOLON
5217 ((For) $0).Initializer = (Statement) $1;
5219 // Pass the "For" object to the iterator_part4
5220 oob_stack.Push ($0);
5222 for_condition_and_iterator_part
5225 var locations = (Tuple<Location,Location>) $4;
5227 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5228 Warning_EmptyStatement (GetLocation ($5));
5231 f.Statement = (Statement) $5;
5232 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5234 $$ = end_block (GetLocation ($2));
5238 Error_SyntaxError (yyToken);
5239 $$ = end_block (current_block.StartLocation);
5243 for_condition_and_iterator_part
5244 : opt_for_condition SEMICOLON
5246 For f = (For) oob_stack.Peek ();
5247 f.Condition = (BooleanExpression) $1;
5250 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5253 // Handle errors in the case of opt_for_condition being followed by
5254 // a close parenthesis
5255 | opt_for_condition close_parens_close_brace {
5256 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5257 For f = (For) oob_stack.Peek ();
5258 f.Condition = (BooleanExpression) $1;
5259 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5264 : opt_for_iterator CLOSE_PARENS {
5265 For f = (For) oob_stack.Peek ();
5266 f.Iterator = (Statement) $1;
5267 $$ = GetLocation ($2);
5269 | opt_for_iterator CLOSE_BRACE {
5270 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5271 For f = (For) oob_stack.Peek ();
5272 f.Iterator = (Statement) $1;
5273 $$ = GetLocation ($2);
5277 close_parens_close_brace
5279 | CLOSE_BRACE { lexer.putback ('}'); }
5283 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5288 : variable_type identifier_inside_body
5290 var lt = (Tokenizer.LocatedToken) $2;
5291 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5292 current_block.AddLocalName (li);
5293 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5295 opt_local_variable_initializer opt_variable_declarators
5297 $$ = current_variable;
5298 current_variable = null;
5300 | statement_expression_list
5304 : /* empty */ { $$ = null; }
5305 | boolean_expression
5309 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5314 : statement_expression_list
5317 statement_expression_list
5318 : statement_expression
5319 | statement_expression_list COMMA statement_expression
5321 var sl = $1 as StatementList;
5323 sl = new StatementList ((Statement) $1, (Statement) $3);
5324 lbag.AddStatement (sl, GetLocation ($2));
5326 sl.Add ((Statement) $3);
5327 lbag.AppendTo (sl, GetLocation ($2));
5335 : FOREACH open_parens_any type error
5337 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5339 start_block (GetLocation ($2));
5340 current_block.IsCompilerGenerated = true;
5342 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5343 current_block.AddStatement (f);
5345 lbag.AddStatement (f, GetLocation ($2));
5346 $$ = end_block (GetLocation ($4));
5348 | FOREACH open_parens_any type identifier_inside_body error
5350 Error_SyntaxError (yyToken);
5352 start_block (GetLocation ($2));
5353 current_block.IsCompilerGenerated = true;
5355 var lt = (Tokenizer.LocatedToken) $4;
5356 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5357 current_block.AddLocalName (li);
5359 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5360 current_block.AddStatement (f);
5362 lbag.AddStatement (f, GetLocation ($2));
5363 $$ = end_block (GetLocation ($5));
5365 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5367 start_block (GetLocation ($2));
5368 current_block.IsCompilerGenerated = true;
5370 var lt = (Tokenizer.LocatedToken) $4;
5371 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5372 current_block.AddLocalName (li);
5377 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5378 Warning_EmptyStatement (GetLocation ($9));
5380 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5381 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5382 end_block (GetLocation ($7));
5390 | continue_statement
5400 $$ = new Break (GetLocation ($1));
5401 lbag.AddStatement ($$, GetLocation ($2));
5406 : CONTINUE SEMICOLON
5408 $$ = new Continue (GetLocation ($1));
5409 lbag.AddStatement ($$, GetLocation ($2));
5413 Error_SyntaxError (yyToken);
5414 $$ = new Continue (GetLocation ($1));
5419 : GOTO identifier_inside_body SEMICOLON
5421 var lt = (Tokenizer.LocatedToken) $2;
5422 $$ = new Goto (lt.Value, GetLocation ($1));
5423 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5425 | GOTO CASE constant_expression SEMICOLON
5427 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5428 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5430 | GOTO DEFAULT SEMICOLON
5432 $$ = new GotoDefault (GetLocation ($1));
5433 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5438 : RETURN opt_expression SEMICOLON
5440 $$ = new Return ((Expression) $2, GetLocation ($1));
5441 lbag.AddStatement ($$, GetLocation ($3));
5443 | RETURN expression error
5445 Error_SyntaxError (yyToken);
5446 $$ = new Return ((Expression) $2, GetLocation ($1));
5450 Error_SyntaxError (yyToken);
5451 $$ = new Return (null, GetLocation ($1));
5456 : THROW opt_expression SEMICOLON
5458 $$ = new Throw ((Expression) $2, GetLocation ($1));
5459 lbag.AddStatement ($$, GetLocation ($3));
5463 Error_SyntaxError (yyToken);
5464 $$ = new Throw (null, GetLocation ($1));
5469 : identifier_inside_body RETURN opt_expression SEMICOLON
5471 var lt = (Tokenizer.LocatedToken) $1;
5472 string s = lt.Value;
5474 report.Error (1003, lt.Location, "; expected");
5475 } else if ($3 == null) {
5476 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5477 } else if (lang_version == LanguageVersion.ISO_1){
5478 FeatureIsNotAvailable (lt.Location, "iterators");
5481 current_block.Explicit.RegisterIteratorYield ();
5482 $$ = new Yield ((Expression) $3, lt.Location);
5483 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5485 | identifier_inside_body RETURN expression error
5487 Error_SyntaxError (yyToken);
5489 var lt = (Tokenizer.LocatedToken) $1;
5490 string s = lt.Value;
5492 report.Error (1003, lt.Location, "; expected");
5493 } else if ($3 == null) {
5494 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5495 } else if (lang_version == LanguageVersion.ISO_1){
5496 FeatureIsNotAvailable (lt.Location, "iterators");
5499 current_block.Explicit.RegisterIteratorYield ();
5500 $$ = new Yield ((Expression) $3, lt.Location);
5501 lbag.AddStatement ($$, GetLocation ($2));
5503 | identifier_inside_body BREAK SEMICOLON
5505 var lt = (Tokenizer.LocatedToken) $1;
5506 string s = lt.Value;
5508 report.Error (1003, lt.Location, "; expected");
5509 } else if (lang_version == LanguageVersion.ISO_1){
5510 FeatureIsNotAvailable (lt.Location, "iterators");
5513 current_block.Explicit.RegisterIteratorYield ();
5514 $$ = new YieldBreak (lt.Location);
5515 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5525 : TRY block catch_clauses
5527 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5529 | TRY block FINALLY block
5531 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5532 lbag.AddStatement ($$, GetLocation ($3));
5534 | TRY block catch_clauses FINALLY block
5536 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5537 lbag.AddStatement ($$, GetLocation ($4));
5541 Error_SyntaxError (1524, yyToken);
5542 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5549 var l = new List<Catch> (2);
5554 | catch_clauses catch_clause
5556 var l = (List<Catch>) $1;
5558 Catch c = (Catch) $2;
5559 if (l [l.Count - 1].IsGeneral) {
5560 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5570 | identifier_inside_body
5576 $$ = new Catch ((Block) $2, GetLocation ($1));
5578 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5580 start_block (GetLocation ($2));
5581 var c = new Catch (current_block, GetLocation ($1));
5582 c.TypeExpression = (FullNamedExpression) $3;
5585 var lt = (Tokenizer.LocatedToken) $4;
5586 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5587 current_block.AddLocalName (c.Variable);
5590 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5597 | CATCH open_parens_any error
5599 if (yyToken == Token.CLOSE_PARENS) {
5600 report.Error (1015, lexer.Location,
5601 "A type that derives from `System.Exception', `object', or `string' expected");
5603 Error_SyntaxError (yyToken);
5606 $$ = new Catch (null, GetLocation ($1));
5613 $$ = new Checked ((Block) $2, GetLocation ($1));
5620 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5627 if (!settings.Unsafe)
5628 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5630 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5635 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5637 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5638 Warning_EmptyStatement (GetLocation ($5));
5640 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5641 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5643 | LOCK open_parens_any expression error
5645 Error_SyntaxError (yyToken);
5647 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5648 lbag.AddStatement ($$, GetLocation ($2));
5653 : FIXED open_parens_any variable_type identifier_inside_body
5655 start_block (GetLocation ($2));
5657 current_block.IsCompilerGenerated = true;
5658 var lt = (Tokenizer.LocatedToken) $4;
5659 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5660 current_block.AddLocalName (li);
5661 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5663 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5665 $$ = current_variable;
5666 current_variable = null;
5670 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5671 Warning_EmptyStatement (GetLocation ($10));
5673 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5674 current_block.AddStatement (f);
5675 $$ = end_block (GetLocation ($8));
5680 : USING open_parens_any variable_type identifier_inside_body
5682 start_block (GetLocation ($2));
5684 current_block.IsCompilerGenerated = true;
5685 var lt = (Tokenizer.LocatedToken) $4;
5686 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5687 current_block.AddLocalName (li);
5688 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5690 using_initialization CLOSE_PARENS
5692 $$ = current_variable;
5693 current_variable = null;
5697 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5698 Warning_EmptyStatement (GetLocation ($9));
5700 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
5701 current_block.AddStatement (u);
5702 $$ = end_block (GetLocation ($7));
5704 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5706 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5707 Warning_EmptyStatement (GetLocation ($5));
5709 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5710 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5712 | USING open_parens_any expression error
5714 Error_SyntaxError (yyToken);
5716 $$ = new Using ((Expression) $3, null, GetLocation ($1));
5717 lbag.AddStatement ($$, GetLocation ($2));
5721 using_initialization
5722 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
5725 // It has to be here for the parent to safely restore artificial block
5726 Error_SyntaxError (yyToken);
5730 using_or_fixed_variable_initializer
5733 Error_MissingInitializer (lexer.Location);
5735 | ASSIGN variable_initializer
5737 current_variable.Initializer = (Expression) $2;
5738 $$ = current_variable;
5746 : first_from_clause query_body
5748 lexer.query_parsing = false;
5750 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5752 from.Tail.Next = (Linq.AQueryClause)$2;
5755 current_block.SetEndLocation (lexer.Location);
5756 current_block = current_block.Parent;
5758 | nested_from_clause query_body
5760 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5762 from.Tail.Next = (Linq.AQueryClause)$2;
5765 current_block.SetEndLocation (lexer.Location);
5766 current_block = current_block.Parent;
5769 // Bubble up COMPLETE_COMPLETION productions
5770 | first_from_clause COMPLETE_COMPLETION {
5771 lexer.query_parsing = false;
5774 current_block.SetEndLocation (lexer.Location);
5775 current_block = current_block.Parent;
5777 | nested_from_clause COMPLETE_COMPLETION {
5779 current_block.SetEndLocation (lexer.Location);
5780 current_block = current_block.Parent;
5785 : FROM_FIRST identifier_inside_body IN expression
5787 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5789 var lt = (Tokenizer.LocatedToken) $2;
5790 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5791 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5793 | FROM_FIRST type identifier_inside_body IN expression
5795 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5797 var lt = (Tokenizer.LocatedToken) $3;
5798 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5799 $$ = new Linq.QueryExpression (
5800 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5801 IdentifierType = (FullNamedExpression)$2
5808 : FROM identifier_inside_body IN expression
5810 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5812 var lt = (Tokenizer.LocatedToken) $2;
5813 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5814 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5816 | FROM type identifier_inside_body IN expression
5818 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5820 var lt = (Tokenizer.LocatedToken) $3;
5821 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5822 $$ = new Linq.QueryExpression (
5823 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5824 IdentifierType = (FullNamedExpression)$2
5831 : FROM identifier_inside_body IN
5833 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5837 var lt = (Tokenizer.LocatedToken) $2;
5838 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5839 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5841 current_block.SetEndLocation (lexer.Location);
5842 current_block = current_block.Parent;
5844 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5846 | FROM type identifier_inside_body IN
5848 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5852 var lt = (Tokenizer.LocatedToken) $3;
5853 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5855 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5856 IdentifierType = (FullNamedExpression)$2
5859 current_block.SetEndLocation (lexer.Location);
5860 current_block = current_block.Parent;
5862 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5867 : query_body_clauses select_or_group_clause opt_query_continuation
5869 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5872 head.Next = (Linq.AQueryClause)$3;
5875 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5876 clause.Tail.Next = head;
5882 | select_or_group_clause opt_query_continuation
5884 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5887 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5888 clause.Tail.Next = head;
5894 | query_body_clauses COMPLETE_COMPLETION
5895 | query_body_clauses error
5897 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
5902 Error_SyntaxError (yyToken);
5907 select_or_group_clause
5910 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5914 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5916 current_block.SetEndLocation (lexer.Location);
5917 current_block = current_block.Parent;
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);
5929 current_block.SetEndLocation (lexer.Location);
5930 current_block = current_block.Parent;
5932 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5934 BY expression_or_error
5936 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5937 lbag.AddLocation ($$, GetLocation ($5));
5939 current_block.SetEndLocation (lexer.Location);
5940 current_block = current_block.Parent;
5946 | query_body_clauses query_body_clause
5948 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5962 : LET identifier_inside_body ASSIGN
5964 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5968 var lt = (Tokenizer.LocatedToken) $2;
5969 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5970 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5971 lbag.AddLocation ($$, GetLocation ($3));
5973 current_block.SetEndLocation (lexer.Location);
5974 current_block = current_block.Parent;
5976 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5983 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5987 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5989 current_block.SetEndLocation (lexer.Location);
5990 current_block = current_block.Parent;
5995 : JOIN identifier_inside_body IN
5997 if (linq_clause_blocks == null)
5998 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6000 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6001 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6003 expression_or_error ON
6005 current_block.SetEndLocation (lexer.Location);
6006 current_block = current_block.Parent;
6008 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6009 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6011 expression_or_error EQUALS
6013 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6014 current_block.SetEndLocation (lexer.Location);
6015 current_block = current_block.Parent;
6017 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6019 expression_or_error opt_join_into
6021 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6022 current_block.SetEndLocation (lexer.Location);
6024 var outer_selector = linq_clause_blocks.Pop ();
6025 var block = linq_clause_blocks.Pop ();
6027 var lt = (Tokenizer.LocatedToken) $2;
6028 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6029 Linq.RangeVariable into;
6033 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6034 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6037 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6039 var parent = block.Parent;
6040 while (parent is Linq.QueryBlock) {
6041 parent = parent.Parent;
6043 current_block.Parent = parent;
6045 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6047 lt = (Tokenizer.LocatedToken) $12;
6048 into = new Linq.RangeVariable (lt.Value, lt.Location);
6050 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6051 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6054 current_block = block.Parent;
6055 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6057 | JOIN type identifier_inside_body IN
6059 if (linq_clause_blocks == null)
6060 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6062 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6063 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6065 expression_or_error ON
6067 current_block.SetEndLocation (lexer.Location);
6068 current_block = current_block.Parent;
6070 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6071 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6073 expression_or_error EQUALS
6075 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6076 current_block.SetEndLocation (lexer.Location);
6077 current_block = current_block.Parent;
6079 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6081 expression_or_error opt_join_into
6083 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6084 current_block.SetEndLocation (lexer.Location);
6086 var outer_selector = linq_clause_blocks.Pop ();
6087 var block = linq_clause_blocks.Pop ();
6089 var lt = (Tokenizer.LocatedToken) $3;
6090 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6091 Linq.RangeVariable into;
6095 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6096 IdentifierType = (FullNamedExpression)$2
6100 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6102 var parent = block.Parent;
6103 while (parent is Linq.QueryBlock) {
6104 parent = parent.Parent;
6106 current_block.Parent = parent;
6108 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6110 lt = (Tokenizer.LocatedToken) $13;
6111 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6113 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6114 IdentifierType = (FullNamedExpression)$2
6118 current_block = block.Parent;
6119 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6125 | INTO identifier_inside_body
6134 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6138 current_block.SetEndLocation (lexer.Location);
6139 current_block = current_block.Parent;
6149 current_block.SetEndLocation (lexer.Location);
6150 current_block = current_block.Parent;
6152 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6156 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6163 | orderings_then_by COMMA
6165 current_block.SetEndLocation (lexer.Location);
6166 current_block = current_block.Parent;
6168 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6172 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6180 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6182 | expression ASCENDING
6184 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6185 lbag.AddLocation ($$, GetLocation ($2));
6187 | expression DESCENDING
6189 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6190 lbag.AddLocation ($$, GetLocation ($2));
6197 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6199 | expression ASCENDING
6201 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6202 lbag.AddLocation ($$, GetLocation ($2));
6204 | expression DESCENDING
6206 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6207 lbag.AddLocation ($$, GetLocation ($2));
6212 opt_query_continuation
6214 | INTO identifier_inside_body
6216 // query continuation block is not linked with query block but with block
6217 // before. This means each query can use same range variable names for
6218 // different identifiers.
6220 current_block.SetEndLocation (GetLocation ($1));
6221 current_block = current_block.Parent;
6223 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6225 if (linq_clause_blocks == null)
6226 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6228 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6232 var current_block = linq_clause_blocks.Pop ();
6233 var lt = (Tokenizer.LocatedToken) $2;
6234 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6235 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6236 next = (Linq.AQueryClause)$4
6242 // Support for using the compiler as an interactive parser
6244 // The INTERACTIVE_PARSER token is first sent to parse our
6245 // productions; If the result is a Statement, the parsing
6246 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6247 // to setup the blocks in advance.
6249 // This setup is here so that in the future we can add
6250 // support for other constructs (type parsing, namespaces, etc)
6251 // that do not require a block to be setup in advance
6255 : EVAL_STATEMENT_PARSER EOF
6256 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6257 | EVAL_STATEMENT_PARSER
6259 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6261 // (ref object retval)
6262 Parameter [] mpar = new Parameter [1];
6263 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6265 ParametersCompiled pars = new ParametersCompiled (mpar);
6266 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6267 if (settings.Unsafe)
6268 mods |= Modifiers.UNSAFE;
6270 current_local_parameters = pars;
6271 Method method = new Method (
6273 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6275 new MemberName ("Host"),
6277 null /* attributes */);
6279 current_type.AddMember (method);
6281 oob_stack.Push (method);
6282 ++lexer.parsing_block;
6283 start_block (lexer.Location);
6285 interactive_statement_list opt_COMPLETE_COMPLETION
6287 --lexer.parsing_block;
6288 Method method = (Method) oob_stack.Pop ();
6290 method.Block = (ToplevelBlock) end_block(lexer.Location);
6292 InteractiveResult = (Class) pop_current_class ();
6293 current_local_parameters = null;
6295 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6298 interactive_compilation_unit
6299 : opt_extern_alias_directives opt_using_directives
6300 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6303 opt_COMPLETE_COMPLETION
6305 | COMPLETE_COMPLETION
6308 close_brace_or_complete_completion
6310 | COMPLETE_COMPLETION
6314 // XML documentation code references micro parser
6316 documentation_parsing
6319 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6324 : doc_type_declaration_name opt_doc_method_sig
6326 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6328 | builtin_types opt_doc_method_sig
6330 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6331 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6334 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6336 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6337 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6338 var lt = (Tokenizer.LocatedToken) $3;
6339 $$ = new MemberName (lt.Value);
6341 | doc_type_declaration_name DOT THIS
6343 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6345 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6347 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6349 opt_doc_parameters CLOSE_BRACKET
6351 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6352 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6354 | EXPLICIT OPERATOR type opt_doc_method_sig
6356 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6357 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6358 module.DocumentationBuilder.ParsedParameters = p;
6359 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6362 | IMPLICIT OPERATOR type opt_doc_method_sig
6364 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6365 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6366 module.DocumentationBuilder.ParsedParameters = p;
6367 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6370 | OPERATOR overloadable_operator opt_doc_method_sig
6372 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6373 module.DocumentationBuilder.ParsedParameters = p;
6374 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6379 doc_type_declaration_name
6380 : type_declaration_name
6381 | doc_type_declaration_name DOT type_declaration_name
6383 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6391 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6393 opt_doc_parameters CLOSE_PARENS
6402 $$ = new List<DocumentationParameter> (0);
6410 var parameters = new List<DocumentationParameter> ();
6411 parameters.Add ((DocumentationParameter) $1);
6414 | doc_parameters COMMA doc_parameter
6416 var parameters = $1 as List<DocumentationParameter>;
6417 parameters.Add ((DocumentationParameter) $3);
6423 : opt_parameter_modifier parameter_type
6426 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6428 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6435 // A class used to hold info about an operator declarator
6437 class OperatorDeclaration {
6438 public readonly Operator.OpType optype;
6439 public readonly FullNamedExpression ret_type;
6440 public readonly Location location;
6442 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6445 this.ret_type = ret_type;
6446 this.location = location;
6450 void Error_ExpectingTypeName (Expression expr)
6452 if (expr is Invocation){
6453 report.Error (1002, expr.Location, "Expecting `;'");
6455 Expression.Error_InvalidExpressionStatement (report, expr.Location);
6459 void Error_ParameterModifierNotValid (string modifier, Location loc)
6461 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6465 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6467 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6468 Parameter.GetModifierSignature (mod));
6471 void Error_TypeExpected (Location loc)
6473 report.Error (1031, loc, "Type expected");
6476 void Error_UnsafeCodeNotAllowed (Location loc)
6478 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6481 void Warning_EmptyStatement (Location loc)
6483 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6486 void Error_NamedArgumentExpected (NamedArgument a)
6488 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6491 void Error_MissingInitializer (Location loc)
6493 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6496 void push_current_container (TypeDefinition tc, object partial_token)
6498 if (module.Evaluator != null){
6499 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6503 undo.AddTypeContainer (current_container, tc);
6506 if (partial_token != null)
6507 current_container.AddPartial (tc);
6509 current_container.AddTypeContainer (tc);
6511 ++lexer.parsing_declaration;
6512 current_container = tc;
6516 TypeContainer pop_current_class ()
6518 var retval = current_container;
6520 current_container = current_container.Parent;
6521 current_type = current_type.Parent as TypeDefinition;
6526 [System.Diagnostics.Conditional ("FULL_AST")]
6527 void StoreModifierLocation (object token, Location loc)
6532 if (mod_locations == null)
6533 mod_locations = new List<Tuple<Modifiers, Location>> ();
6535 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6538 string CheckAttributeTarget (string a, Location l)
6541 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6545 report.Warning (658, 1, l,
6546 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6547 return string.Empty;
6550 static bool IsUnaryOperator (Operator.OpType op)
6554 case Operator.OpType.LogicalNot:
6555 case Operator.OpType.OnesComplement:
6556 case Operator.OpType.Increment:
6557 case Operator.OpType.Decrement:
6558 case Operator.OpType.True:
6559 case Operator.OpType.False:
6560 case Operator.OpType.UnaryPlus:
6561 case Operator.OpType.UnaryNegation:
6567 void syntax_error (Location l, string msg)
6569 report.Error (1003, l, "Syntax error, " + msg);
6574 public Tokenizer Lexer {
6580 static CSharpParser ()
6582 oob_stack = new Stack<object> ();
6585 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
6586 : this (reader, file, file.Compiler.Report)
6590 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
6593 current_container = current_namespace = file;
6595 this.module = file.Module;
6596 this.compiler = file.Compiler;
6597 this.settings = compiler.Settings;
6598 this.report = report;
6600 lang_version = settings.Version;
6601 yacc_verbose_flag = settings.VerboseParserFlag;
6602 doc_support = settings.DocumentationFile != null;
6604 lexer = new Tokenizer (reader, file);
6607 lbag = new LocationsBag ();
6612 use_global_stacks = true;
6615 public void parse ()
6617 eof_token = Token.EOF;
6618 Tokenizer.LocatedToken.Initialize ();
6621 if (yacc_verbose_flag > 1)
6622 yyparse (lexer, new yydebug.yyDebugSimple ());
6626 Tokenizer tokenizer = lexer as Tokenizer;
6627 tokenizer.cleanup ();
6628 } catch (Exception e){
6629 if (e is yyParser.yyUnexpectedEof) {
6630 Error_SyntaxError (yyToken);
6631 UnexpectedEOF = true;
6635 if (e is yyParser.yyException) {
6636 report.Error (-25, lexer.Location, "Parsing error");
6638 // Used by compiler-tester to test internal errors
6639 if (yacc_verbose_flag > 0 || e is FatalException)
6642 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6647 void CheckToken (int error, int yyToken, string msg, Location loc)
6649 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6650 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6652 report.Error (error, loc, msg);
6655 string ConsumeStoredComment ()
6657 string s = tmpComment;
6659 Lexer.doc_state = XmlCommentState.Allowed;
6663 void FeatureIsNotAvailable (Location loc, string feature)
6665 report.FeatureIsNotAvailable (compiler, loc, feature);
6668 Location GetLocation (object obj)
6670 var lt = obj as Tokenizer.LocatedToken;
6674 var mn = obj as MemberName;
6678 var expr = obj as Expression;
6680 return expr.Location;
6682 return lexer.Location;
6685 public LocationsBag LocationsBag {
6691 void start_block (Location loc)
6693 if (current_block == null) {
6694 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6695 parsing_anonymous_method = false;
6696 } else if (parsing_anonymous_method) {
6697 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6698 parsing_anonymous_method = false;
6700 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6705 end_block (Location loc)
6707 Block retval = current_block.Explicit;
6708 retval.SetEndLocation (loc);
6709 current_block = retval.Parent;
6713 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
6715 oob_stack.Push (current_anonymous_method);
6716 oob_stack.Push (current_local_parameters);
6717 oob_stack.Push (current_variable);
6718 oob_stack.Push (async_block);
6720 current_local_parameters = parameters;
6722 if (lang_version <= LanguageVersion.ISO_2)
6723 FeatureIsNotAvailable (loc, "lambda expressions");
6725 current_anonymous_method = new LambdaExpression (loc);
6727 if (lang_version == LanguageVersion.ISO_1)
6728 FeatureIsNotAvailable (loc, "anonymous methods");
6730 current_anonymous_method = new AnonymousMethodExpression (loc);
6733 async_block = isAsync;
6734 // Force the next block to be created as a ToplevelBlock
6735 parsing_anonymous_method = true;
6739 * Completes the anonymous method processing, if lambda_expr is null, this
6740 * means that we have a Statement instead of an Expression embedded
6742 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6744 AnonymousMethodExpression retval;
6747 anon_block.IsAsync = true;
6749 current_anonymous_method.Block = anon_block;
6750 retval = current_anonymous_method;
6752 async_block = (bool) oob_stack.Pop ();
6753 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6754 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6755 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6760 void Error_SyntaxError (int token)
6762 Error_SyntaxError (0, token);
6765 void Error_SyntaxError (int error_code, int token)
6767 Error_SyntaxError (error_code, token, "Unexpected symbol");
6770 void Error_SyntaxError (int error_code, int token, string msg)
6772 Lexer.CompleteOnEOF = false;
6774 // An error message has been reported by tokenizer
6775 if (token == Token.ERROR)
6778 string symbol = GetSymbolName (token);
6779 string expecting = GetExpecting ();
6780 var loc = lexer.Location - symbol.Length;
6782 if (error_code == 0) {
6783 if (expecting == "`identifier'") {
6784 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6785 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6790 expecting = "identifier";
6791 } else if (expecting == "`)'") {
6798 if (string.IsNullOrEmpty (expecting))
6799 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6801 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6804 string GetExpecting ()
6806 int [] tokens = yyExpectingTokens (yyExpectingState);
6807 var names = new List<string> (tokens.Length);
6808 bool has_type = false;
6809 bool has_identifier = false;
6810 for (int i = 0; i < tokens.Length; i++){
6811 int token = tokens [i];
6812 has_identifier |= token == Token.IDENTIFIER;
6814 string name = GetTokenName (token);
6815 if (name == "<internal>")
6818 has_type |= name == "type";
6819 if (names.Contains (name))
6826 // Too many tokens to enumerate
6828 if (names.Count > 8)
6831 if (has_type && has_identifier)
6832 names.Remove ("identifier");
6834 if (names.Count == 1)
6835 return "`" + GetTokenName (tokens [0]) + "'";
6837 StringBuilder sb = new StringBuilder ();
6839 int count = names.Count;
6840 for (int i = 0; i < count; i++){
6841 bool last = i + 1 == count;
6845 sb.Append (names [i]);
6846 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6848 return sb.ToString ();
6852 string GetSymbolName (int token)
6856 return ((Constant)lexer.Value).GetValue ().ToString ();
6857 case Token.IDENTIFIER:
6858 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6900 case Token.BITWISE_AND:
6902 case Token.BITWISE_OR:
6916 case Token.OP_SHIFT_LEFT:
6918 case Token.OP_SHIFT_RIGHT:
6938 case Token.OP_COALESCING:
6940 case Token.OP_MULT_ASSIGN:
6942 case Token.OP_DIV_ASSIGN:
6944 case Token.OP_MOD_ASSIGN:
6946 case Token.OP_ADD_ASSIGN:
6948 case Token.OP_SUB_ASSIGN:
6950 case Token.OP_SHIFT_LEFT_ASSIGN:
6952 case Token.OP_SHIFT_RIGHT_ASSIGN:
6954 case Token.OP_AND_ASSIGN:
6956 case Token.OP_XOR_ASSIGN:
6958 case Token.OP_OR_ASSIGN:
6962 return GetTokenName (token);
6965 static string GetTokenName (int token)
6968 case Token.ABSTRACT:
6990 case Token.CONTINUE:
6994 case Token.DELEGATE:
7004 case Token.EXPLICIT:
7007 case Token.EXTERN_ALIAS:
7023 case Token.IMPLICIT:
7027 case Token.INTERFACE:
7029 case Token.INTERNAL:
7035 case Token.NAMESPACE:
7041 case Token.OPERATOR:
7045 case Token.OVERRIDE:
7051 case Token.PROTECTED:
7055 case Token.READONLY:
7067 case Token.STACKALLOC:
7068 return "stackalloc";
7085 case Token.UNCHECKED:
7093 case Token.VOLATILE:
7101 case Token.REFVALUE:
7102 return "__refvalue";
7112 case Token.FROM_FIRST:
7130 case Token.ASCENDING:
7132 case Token.DESCENDING:
7133 return "descending";
7140 case Token.OPEN_BRACE:
7142 case Token.CLOSE_BRACE:
7144 case Token.OPEN_BRACKET:
7145 case Token.OPEN_BRACKET_EXPR:
7147 case Token.CLOSE_BRACKET:
7149 case Token.OPEN_PARENS_CAST:
7150 case Token.OPEN_PARENS_LAMBDA:
7151 case Token.OPEN_PARENS:
7153 case Token.CLOSE_PARENS:
7159 case Token.DEFAULT_COLON:
7163 case Token.SEMICOLON:
7174 case Token.BITWISE_AND:
7175 case Token.BITWISE_OR:
7182 case Token.OP_SHIFT_LEFT:
7183 case Token.OP_SHIFT_RIGHT:
7191 case Token.OP_COALESCING:
7192 case Token.OP_MULT_ASSIGN:
7193 case Token.OP_DIV_ASSIGN:
7194 case Token.OP_MOD_ASSIGN:
7195 case Token.OP_ADD_ASSIGN:
7196 case Token.OP_SUB_ASSIGN:
7197 case Token.OP_SHIFT_LEFT_ASSIGN:
7198 case Token.OP_SHIFT_RIGHT_ASSIGN:
7199 case Token.OP_AND_ASSIGN:
7200 case Token.OP_XOR_ASSIGN:
7201 case Token.OP_OR_ASSIGN:
7202 return "<operator>";
7224 case Token.OP_GENERICS_LT:
7225 case Token.GENERIC_DIMENSION:
7227 case Token.OP_GENERICS_GT:
7230 case Token.INTERR_NULLABLE:
7232 case Token.DOUBLE_COLON:
7236 case Token.IDENTIFIER:
7238 return "identifier";
7241 return "end-of-file";
7243 // All of these are internal.
7246 case Token.FIRST_KEYWORD:
7247 case Token.EVAL_COMPILATION_UNIT_PARSER:
7248 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7249 case Token.EVAL_STATEMENT_PARSER:
7250 case Token.LAST_KEYWORD:
7251 case Token.GENERATE_COMPLETION:
7252 case Token.COMPLETE_COMPLETION:
7253 return "<internal>";
7255 // A bit more robust.
7257 return yyNames [token];