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 BlockVariable current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 Stack<Linq.QueryBlock> linq_clause_blocks;
122 ModuleContainer module;
124 readonly CompilerContext compiler;
125 readonly LanguageVersion lang_version;
126 readonly bool doc_support;
127 readonly CompilerSettings settings;
128 readonly Report report;
131 // Instead of allocating carrier array everytime we
132 // share the bucket for very common constructs which can never
135 List<Parameter> parameters_bucket;
138 // Full AST support members
141 List<Tuple<Modifiers, Location>> mod_locations;
142 Stack<Location> location_stack;
146 %token NONE /* This token is never returned by our lexer */
147 %token ERROR // This is used not by the parser, but by the tokenizer.
151 *These are the C# keywords
250 %token INTERR_NULLABLE
258 /* C# keywords which are not really keywords */
264 /* C# single character operators/punctuation. */
292 /* C# multi-character operators. */
297 %token OP_SHIFT_RIGHT
304 %token OP_MULT_ASSIGN
309 %token OP_SHIFT_LEFT_ASSIGN
310 %token OP_SHIFT_RIGHT_ASSIGN
317 /* Generics <,> tokens */
318 %token OP_GENERICS_LT
319 %token OP_GENERICS_LT_DECL
320 %token OP_GENERICS_GT
325 %token OPEN_PARENS_LAMBDA
326 %token OPEN_PARENS_CAST
327 %token GENERIC_DIMENSION
329 %token OPEN_BRACKET_EXPR
331 // Make the parser go into eval mode parsing (statements and compilation units).
332 %token EVAL_STATEMENT_PARSER
333 %token EVAL_COMPILATION_UNIT_PARSER
334 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
339 // This token is generated to trigger the completion engine at this point
341 %token GENERATE_COMPLETION
344 // This token is return repeatedly after the first GENERATE_COMPLETION
345 // token is produced and before the final EOF
347 %token COMPLETE_COMPLETION
349 /* Add precedence rules to solve dangling else s/r conflict */
353 /* Define the operator tokens and their precedences */
361 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
363 %left STAR DIV PERCENT
364 %right BANG CARRET UMINUS
365 %nonassoc OP_INC OP_DEC
367 %left OPEN_BRACKET OPEN_BRACE
370 %start compilation_unit
374 : outer_declaration opt_EOF
376 Lexer.check_incorrect_doc_comment ();
378 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
379 | documentation_parsing
383 : opt_extern_alias_directives opt_using_directives
384 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
387 Attributes attrs = (Attributes) $4;
388 report.Error (1730, attrs.Attrs [0].Location,
389 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
391 current_namespace.UnattachedAttributes = attrs;
394 | opt_extern_alias_directives opt_using_directives attribute_sections
396 module.AddAttributes ((Attributes) $3, current_namespace);
400 if (yyToken == Token.EXTERN_ALIAS)
401 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
403 Error_SyntaxError (yyToken);
412 extern_alias_directives
413 : extern_alias_directive
414 | extern_alias_directives extern_alias_directive
417 extern_alias_directive
418 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
420 var lt = (LocatedToken) $2;
423 syntax_error (lt.Location, "`alias' expected");
425 if (lang_version == LanguageVersion.ISO_1)
426 FeatureIsNotAvailable (lt.Location, "external alias");
428 lt = (LocatedToken) $3;
429 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
430 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
433 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
434 current_namespace.AddUsing (na);
436 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
441 Error_SyntaxError (yyToken);
447 | using_directives using_directive
454 Lexer.doc_state = XmlCommentState.Allowed;
459 : USING namespace_or_type_expr SEMICOLON
461 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
462 current_namespace.AddUsing (un);
464 lbag.AddLocation (un, GetLocation ($3));
466 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
468 var lt = (LocatedToken) $2;
469 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
470 report.Warning (440, 2, lt.Location,
471 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
474 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
475 current_namespace.AddUsing (un);
477 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
481 Error_SyntaxError (yyToken);
487 // Strictly speaking, namespaces don't have attributes but
488 // we parse global attributes along with namespace declarations and then
491 namespace_declaration
492 : opt_attributes NAMESPACE namespace_name
494 Attributes attrs = (Attributes) $1;
495 var name = (MemberName) $3;
497 bool valid_global_attrs = true;
498 if ((current_namespace.DeclarationFound || current_namespace != file)) {
499 valid_global_attrs = false;
501 foreach (var a in attrs.Attrs) {
502 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
505 valid_global_attrs = false;
510 if (!valid_global_attrs)
511 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
514 module.AddAttributes (attrs, current_namespace);
516 var ns = new NamespaceContainer (name, current_namespace);
517 current_namespace.AddTypeContainer (ns);
518 current_container = current_namespace = ns;
523 Lexer.doc_state = XmlCommentState.Allowed;
525 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
528 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
530 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
532 current_container = current_namespace = current_namespace.Parent;
534 | opt_attributes NAMESPACE namespace_name
536 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
538 var name = (MemberName) $3;
539 var ns = new NamespaceContainer (name, current_namespace);
540 lbag.AddLocation (ns, GetLocation ($2));
541 current_namespace.AddTypeContainer (ns);
550 Error_SyntaxError (yyToken);
558 var lt = (LocatedToken) $1;
559 $$ = new MemberName (lt.Value, lt.Location);
561 | namespace_name DOT IDENTIFIER
563 var lt = (LocatedToken) $3;
564 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
568 Error_SyntaxError (yyToken);
569 $$ = new MemberName ("<invalid>", lexer.Location);
588 opt_extern_alias_directives
590 | extern_alias_directives
593 opt_namespace_or_type_declarations
595 | namespace_or_type_declarations
598 namespace_or_type_declarations
599 : namespace_or_type_declaration
600 | namespace_or_type_declarations namespace_or_type_declaration
603 namespace_or_type_declaration
607 TypeContainer ds = (TypeContainer)$1;
609 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
610 report.Error (1527, ds.Location,
611 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
614 // Here is a trick, for explicit attributes we don't know where they belong to until
615 // we parse succeeding declaration hence we parse them as normal and re-attach them
616 // when we know whether they are global (assembly:, module:) or local (type:).
617 if (ds.OptAttributes != null) {
618 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
621 current_namespace.DeclarationFound = true;
623 | namespace_declaration
625 current_namespace.DeclarationFound = true;
627 | attribute_sections CLOSE_BRACE {
628 current_namespace.UnattachedAttributes = (Attributes) $1;
629 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
637 | interface_declaration
639 | delegate_declaration
641 // Enable this when we have handled all errors, because this acts as a generic fallback
644 // Console.WriteLine ("Token=" + yyToken);
645 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
661 var sect = (List<Attribute>) $1;
662 $$ = new Attributes (sect);
664 | attribute_sections attribute_section
666 Attributes attrs = $1 as Attributes;
667 var sect = (List<Attribute>) $2;
669 attrs = new Attributes (sect);
671 attrs.AddAttributes (sect);
679 PushLocation (GetLocation ($1));
680 lexer.parsing_attribute_section = true;
682 attribute_section_cont
684 lexer.parsing_attribute_section = false;
689 attribute_section_cont
690 : attribute_target COLON
692 current_attr_target = (string) $1;
693 if (current_attr_target == "assembly" || current_attr_target == "module") {
694 Lexer.check_incorrect_doc_comment ();
697 attribute_list opt_comma CLOSE_BRACKET
699 // when attribute target is invalid
700 if (current_attr_target == string.Empty)
701 $$ = new List<Attribute> (0);
705 lbag.InsertLocation ($$, 0, PopLocation ());
707 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($5), GetLocation ($6));
709 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($6));
712 current_attr_target = null;
713 lexer.parsing_attribute_section = false;
715 | attribute_list opt_comma CLOSE_BRACKET
719 lbag.InsertLocation ($$, 0, PopLocation ());
721 lbag.AddLocation ($$, GetLocation($2), GetLocation ($3));
723 lbag.AddLocation ($$, GetLocation($3));
728 Error_SyntaxError (yyToken);
730 var lt = (LocatedToken) $1;
731 var tne = new SimpleName (lt.Value, null, lt.Location);
733 $$ = new List<Attribute> () {
734 new Attribute (null, tne, null, GetLocation ($1), false)
739 $$ = CheckAttributeTarget (GetTokenName (yyToken), GetLocation ($1));
747 var lt = (LocatedToken) $1;
748 $$ = CheckAttributeTarget (lt.Value, lt.Location);
750 | EVENT { $$ = "event"; }
751 | RETURN { $$ = "return"; }
757 $$ = new List<Attribute> (4) { (Attribute) $1 };
759 | attribute_list COMMA attribute
761 var attrs = (List<Attribute>) $1;
763 attrs.Add ((Attribute) $3);
764 lbag.AppendTo (attrs, GetLocation ($2));
774 ++lexer.parsing_block;
776 opt_attribute_arguments
778 --lexer.parsing_block;
780 var tne = (ATypeNameExpression) $1;
781 if (tne.HasTypeArguments) {
782 report.Error (404, tne.Location, "Attributes cannot be generic");
785 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
790 : namespace_or_type_expr
793 opt_attribute_arguments
794 : /* empty */ { $$ = null; }
795 | OPEN_PARENS attribute_arguments CLOSE_PARENS
803 : /* empty */ { $$ = null; }
804 | positional_or_named_argument
806 Arguments a = new Arguments (4);
807 a.Add ((Argument) $1);
808 $$ = new Arguments [] { a, null };
810 | named_attribute_argument
812 Arguments a = new Arguments (4);
813 a.Add ((Argument) $1);
814 $$ = new Arguments [] { null, a };
816 | attribute_arguments COMMA positional_or_named_argument
818 Arguments[] o = (Arguments[]) $1;
820 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
821 o [0] = new Arguments (4);
824 Arguments args = ((Arguments) o [0]);
825 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
826 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
828 args.Add ((Argument) $3);
830 | attribute_arguments COMMA named_attribute_argument
832 Arguments[] o = (Arguments[]) $1;
834 o [1] = new Arguments (4);
837 ((Arguments) o [1]).Add ((Argument) $3);
841 positional_or_named_argument
844 $$ = new Argument ((Expression) $1);
849 Error_SyntaxError (yyToken);
854 named_attribute_argument
857 ++lexer.parsing_block;
861 --lexer.parsing_block;
862 var lt = (LocatedToken) $1;
863 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
864 lbag.AddLocation ($$, GetLocation($2));
869 : identifier_inside_body COLON opt_named_modifier expression_or_error
871 if (lang_version <= LanguageVersion.V_3)
872 FeatureIsNotAvailable (GetLocation ($1), "named argument");
874 // Avoid boxing in common case (no modifier)
875 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
877 var lt = (LocatedToken) $1;
878 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
879 lbag.AddLocation ($$, GetLocation($2));
884 : /* empty */ { $$ = null; }
887 $$ = Argument.AType.Ref;
891 $$ = Argument.AType.Out;
895 opt_class_member_declarations
897 | class_member_declarations
900 class_member_declarations
901 : class_member_declaration
903 lexer.parsing_modifiers = true;
905 | class_member_declarations class_member_declaration
907 lexer.parsing_modifiers = true;
911 class_member_declaration
912 : constant_declaration
915 | property_declaration
917 | indexer_declaration
918 | operator_declaration
919 | constructor_declaration
920 | destructor_declaration
922 | attributes_without_members
926 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
927 GetSymbolName (yyToken));
929 lexer.parsing_generic_declaration = false;
940 type_declaration_name
942 lexer.ConstraintsParsing = true;
943 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
946 opt_type_parameter_constraints_clauses
948 lexer.ConstraintsParsing = false;
951 current_container.SetConstraints ((List<Constraints>) $9);
954 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
956 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
958 lexer.parsing_modifiers = true;
963 Lexer.doc_state = XmlCommentState.Allowed;
965 opt_class_member_declarations CLOSE_BRACE
967 --lexer.parsing_declaration;
969 Lexer.doc_state = XmlCommentState.Allowed;
973 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
974 $$ = pop_current_class ();
976 | opt_attributes opt_modifiers opt_partial STRUCT error
978 Error_SyntaxError (yyToken);
985 CONST type IDENTIFIER
987 var lt = (LocatedToken) $5;
988 var mod = (Modifiers) $2;
989 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
990 current_type.AddMember (current_field);
992 if ((mod & Modifiers.STATIC) != 0) {
993 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
998 constant_initializer opt_constant_declarators SEMICOLON
1001 current_field.DocComment = Lexer.consume_doc_comment ();
1002 Lexer.doc_state = XmlCommentState.Allowed;
1005 current_field.Initializer = (ConstInitializer) $7;
1006 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1007 current_field = null;
1013 Error_SyntaxError (yyToken);
1015 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
1019 opt_constant_declarators
1021 | constant_declarators
1024 constant_declarators
1025 : constant_declarator
1027 current_field.AddDeclarator ((FieldDeclarator) $1);
1029 | constant_declarators constant_declarator
1031 current_field.AddDeclarator ((FieldDeclarator) $2);
1036 : COMMA IDENTIFIER constant_initializer
1038 var lt = (LocatedToken) $2;
1039 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1040 lbag.AddLocation ($$, GetLocation ($1));
1044 constant_initializer
1047 ++lexer.parsing_block;
1049 constant_initializer_expr
1051 --lexer.parsing_block;
1052 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1056 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1061 constant_initializer_expr
1062 : constant_expression
1069 member_type IDENTIFIER
1071 lexer.parsing_generic_declaration = false;
1073 FullNamedExpression type = (FullNamedExpression) $3;
1074 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1075 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1077 var lt = (LocatedToken) $4;
1078 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1079 current_type.AddField (current_field);
1082 opt_field_initializer
1083 opt_field_declarators
1087 current_field.DocComment = Lexer.consume_doc_comment ();
1088 Lexer.doc_state = XmlCommentState.Allowed;
1091 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1093 current_field = null;
1097 FIXED simple_type IDENTIFIER
1099 if (lang_version < LanguageVersion.ISO_2)
1100 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1102 var lt = (LocatedToken) $5;
1103 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1104 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1106 current_type.AddField (current_field);
1108 fixed_field_size opt_fixed_field_declarators SEMICOLON
1111 current_field.DocComment = Lexer.consume_doc_comment ();
1112 Lexer.doc_state = XmlCommentState.Allowed;
1115 current_field.Initializer = (ConstInitializer) $7;
1116 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1118 current_field = null;
1122 FIXED simple_type error
1125 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1129 opt_field_initializer
1133 ++lexer.parsing_block;
1134 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1135 start_block (GetLocation ($1));
1137 variable_initializer
1139 --lexer.parsing_block;
1140 current_field.Initializer = (Expression) $3;
1141 end_block (lexer.Location);
1142 current_local_parameters = null;
1146 opt_field_declarators
1154 current_field.AddDeclarator ((FieldDeclarator) $1);
1156 | field_declarators field_declarator
1158 current_field.AddDeclarator ((FieldDeclarator) $2);
1165 var lt = (LocatedToken) $2;
1166 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1167 lbag.AddLocation ($$, GetLocation ($1));
1169 | COMMA IDENTIFIER ASSIGN
1171 ++lexer.parsing_block;
1173 variable_initializer
1175 --lexer.parsing_block;
1176 var lt = (LocatedToken) $2;
1177 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1178 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1182 opt_fixed_field_declarators
1184 | fixed_field_declarators
1187 fixed_field_declarators
1188 : fixed_field_declarator
1190 current_field.AddDeclarator ((FieldDeclarator) $1);
1192 | fixed_field_declarators fixed_field_declarator
1194 current_field.AddDeclarator ((FieldDeclarator) $2);
1198 fixed_field_declarator
1199 : COMMA IDENTIFIER fixed_field_size
1201 var lt = (LocatedToken) $2;
1202 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1203 lbag.AddLocation ($$, GetLocation ($1));
1210 ++lexer.parsing_block;
1212 expression CLOSE_BRACKET
1214 --lexer.parsing_block;
1215 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1216 lbag.AddLocation ($$, GetLocation ($4));
1218 | OPEN_BRACKET error
1220 report.Error (443, lexer.Location, "Value or constant expected");
1225 variable_initializer
1230 // It has to be here for the parent to safely restore artificial block
1231 Error_SyntaxError (yyToken);
1240 Lexer.doc_state = XmlCommentState.NotAllowed;
1242 // Was added earlier in the case of body being eof for full ast
1246 Method method = (Method) $1;
1247 method.Block = (ToplevelBlock) $3;
1248 async_block = false;
1250 if (method.Block == null) {
1251 method.ParameterInfo.CheckParameters (method);
1253 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1254 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1255 method.GetSignatureForError ());
1258 if (current_container.Kind == MemberKind.Interface) {
1259 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1260 method.GetSignatureForError ());
1264 current_local_parameters = null;
1267 Lexer.doc_state = XmlCommentState.Allowed;
1275 method_declaration_name OPEN_PARENS
1277 valid_param_mod = ParameterModifierType.All;
1279 opt_formal_parameter_list CLOSE_PARENS
1281 valid_param_mod = 0;
1282 MemberName name = (MemberName) $4;
1283 current_local_parameters = (ParametersCompiled) $7;
1285 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1286 name, current_local_parameters, (Attributes) $1);
1288 current_type.AddMember (method);
1290 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1293 method.DocComment = Lexer.consume_doc_comment ();
1295 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1299 lexer.ConstraintsParsing = true;
1301 opt_type_parameter_constraints_clauses
1303 lexer.ConstraintsParsing = false;
1306 var method = (Method) $9;
1307 method.SetConstraints ((List<Constraints>) $10);
1317 lexer.parsing_generic_declaration = true;
1319 method_declaration_name
1322 lexer.parsing_generic_declaration = false;
1323 valid_param_mod = ParameterModifierType.All;
1325 opt_formal_parameter_list CLOSE_PARENS
1327 lexer.ConstraintsParsing = true;
1329 opt_type_parameter_constraints_clauses
1331 lexer.ConstraintsParsing = false;
1332 valid_param_mod = 0;
1334 MemberName name = (MemberName) $6;
1335 current_local_parameters = (ParametersCompiled) $9;
1337 var modifiers = (Modifiers) $2;
1338 modifiers |= Modifiers.PARTIAL;
1340 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1341 modifiers, name, current_local_parameters, (Attributes) $1);
1343 current_type.AddMember (method);
1345 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1348 method.SetConstraints ((List<Constraints>) $12);
1351 method.DocComment = Lexer.consume_doc_comment ();
1353 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1354 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1360 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1362 MemberName name = (MemberName) $5;
1363 report.Error (1585, name.Location,
1364 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1366 var method = Method.Create (current_type, (FullNamedExpression) $3,
1367 0, name, (ParametersCompiled) $7, (Attributes) $1);
1369 current_type.AddMember (method);
1371 current_local_parameters = (ParametersCompiled) $7;
1374 method.DocComment = Lexer.consume_doc_comment ();
1381 method_declaration_name error
1383 Error_SyntaxError (yyToken);
1384 current_local_parameters = ParametersCompiled.Undefined;
1386 MemberName name = (MemberName) $4;
1387 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1388 name, current_local_parameters, (Attributes) $1);
1390 current_type.AddMember (method);
1393 method.DocComment = Lexer.consume_doc_comment ();
1401 | SEMICOLON { $$ = null; }
1404 opt_formal_parameter_list
1405 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1406 | formal_parameter_list
1409 formal_parameter_list
1412 var pars_list = (List<Parameter>) $1;
1413 $$ = new ParametersCompiled (pars_list.ToArray ());
1415 | fixed_parameters COMMA parameter_array
1417 var pars_list = (List<Parameter>) $1;
1418 pars_list.Add ((Parameter) $3);
1420 $$ = new ParametersCompiled (pars_list.ToArray ());
1422 | fixed_parameters COMMA arglist_modifier
1424 var pars_list = (List<Parameter>) $1;
1425 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1426 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1428 | parameter_array COMMA error
1431 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1433 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1435 | fixed_parameters COMMA parameter_array COMMA error
1438 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1440 var pars_list = (List<Parameter>) $1;
1441 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1443 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1445 | arglist_modifier COMMA error
1447 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1449 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1451 | fixed_parameters COMMA ARGLIST COMMA error
1453 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1455 var pars_list = (List<Parameter>) $1;
1456 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1458 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1462 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1466 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1470 Error_SyntaxError (yyToken);
1471 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1478 parameters_bucket.Clear ();
1479 Parameter p = (Parameter) $1;
1480 parameters_bucket.Add (p);
1482 default_parameter_used = p.HasDefaultValue;
1483 $$ = parameters_bucket;
1485 | fixed_parameters COMMA fixed_parameter
1487 var pars = (List<Parameter>) $1;
1488 Parameter p = (Parameter) $3;
1490 if (p.HasExtensionMethodModifier)
1491 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1492 else if (!p.HasDefaultValue && default_parameter_used)
1493 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1495 default_parameter_used |= p.HasDefaultValue;
1498 lbag.AddLocation (p, GetLocation ($2));
1507 opt_parameter_modifier
1509 identifier_inside_body
1511 var lt = (LocatedToken) $4;
1512 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1515 opt_parameter_modifier
1517 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1519 var lt = (LocatedToken) $4;
1520 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1521 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1523 | attribute_sections error
1525 Error_SyntaxError (yyToken);
1526 Location l = GetLocation ($2);
1527 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1530 opt_parameter_modifier
1534 Error_SyntaxError (yyToken);
1535 Location l = GetLocation ($4);
1536 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1539 opt_parameter_modifier
1541 identifier_inside_body
1544 ++lexer.parsing_block;
1548 --lexer.parsing_block;
1549 if (lang_version <= LanguageVersion.V_3) {
1550 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1553 Parameter.Modifier mod = (Parameter.Modifier) $2;
1554 if (mod != Parameter.Modifier.NONE) {
1556 case Parameter.Modifier.REF:
1557 case Parameter.Modifier.OUT:
1558 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1559 Parameter.GetModifierSignature (mod));
1562 case Parameter.Modifier.This:
1563 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1564 Parameter.GetModifierSignature (mod));
1567 throw new NotImplementedException (mod.ToString ());
1570 mod = Parameter.Modifier.NONE;
1573 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1574 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1576 var lt = (LocatedToken) $4;
1577 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1578 lbag.AddLocation ($$, GetLocation ($5));
1581 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1585 opt_parameter_modifier
1586 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1587 | parameter_modifiers
1591 : parameter_modifier
1595 | parameter_modifiers parameter_modifier
1597 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1598 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1599 if (((Parameter.Modifier)$1 & p2) == p2) {
1600 Error_DuplicateParameterModifier (lexer.Location, p2);
1602 switch (mod & ~Parameter.Modifier.This) {
1603 case Parameter.Modifier.REF:
1604 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1606 case Parameter.Modifier.OUT:
1607 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1610 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1621 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1622 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1624 $$ = Parameter.Modifier.REF;
1628 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1629 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1631 $$ = Parameter.Modifier.OUT;
1635 if ((valid_param_mod & ParameterModifierType.This) == 0)
1636 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1638 if (lang_version <= LanguageVersion.ISO_2)
1639 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1641 $$ = Parameter.Modifier.This;
1646 : opt_attributes params_modifier type IDENTIFIER
1648 var lt = (LocatedToken) $4;
1649 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1651 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1653 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1655 var lt = (LocatedToken) $4;
1656 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1658 | opt_attributes params_modifier type error
1660 Error_SyntaxError (yyToken);
1662 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1669 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1670 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1672 | PARAMS parameter_modifier
1674 Parameter.Modifier mod = (Parameter.Modifier)$2;
1675 if ((mod & Parameter.Modifier.This) != 0) {
1676 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1678 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1681 | PARAMS params_modifier
1683 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1690 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1691 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1695 property_declaration
1699 member_declaration_name
1702 tmpComment = Lexer.consume_doc_comment ();
1706 var type = (FullNamedExpression) $3;
1707 current_property = new Property (current_type, type, (Modifiers) $2,
1708 (MemberName) $4, (Attributes) $1);
1710 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1711 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1713 current_type.AddMember (current_property);
1714 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1716 lexer.PropertyParsing = true;
1718 accessor_declarations
1720 lexer.PropertyParsing = false;
1723 current_property.DocComment = ConsumeStoredComment ();
1727 lbag.AppendToMember (current_property, GetLocation ($10));
1728 current_property = null;
1734 : opt_attributes opt_modifiers
1735 member_type indexer_declaration_name OPEN_BRACKET
1737 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1739 opt_formal_parameter_list CLOSE_BRACKET
1741 valid_param_mod = 0;
1742 var type = (FullNamedExpression) $3;
1743 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1745 current_property = indexer;
1747 current_type.AddIndexer (indexer);
1748 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1750 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1751 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1753 if (indexer.ParameterInfo.IsEmpty) {
1754 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1758 tmpComment = Lexer.consume_doc_comment ();
1759 Lexer.doc_state = XmlCommentState.Allowed;
1762 lexer.PropertyParsing = true;
1764 OPEN_BRACE accessor_declarations
1766 lexer.PropertyParsing = false;
1770 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1771 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1774 current_property.DocComment = ConsumeStoredComment ();
1776 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1777 current_property = null;
1782 accessor_declarations
1783 : get_accessor_declaration
1784 | get_accessor_declaration accessor_declarations
1785 | set_accessor_declaration
1786 | set_accessor_declaration accessor_declarations
1789 if (yyToken == Token.CLOSE_BRACE) {
1790 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1792 if (yyToken == Token.SEMICOLON)
1793 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1795 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1800 get_accessor_declaration
1801 : opt_attributes opt_modifiers GET
1803 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1804 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1807 if (current_property.Get != null) {
1808 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1811 if (current_property is Indexer) {
1812 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1813 (Attributes) $1, GetLocation ($3));
1815 current_property.Get = new Property.GetMethod (current_property,
1816 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1819 current_local_parameters = current_property.Get.ParameterInfo;
1820 lbag.AddMember (current_property.Get, mod_locations);
1821 lexer.PropertyParsing = false;
1826 current_property.Get.Block = (ToplevelBlock) $5;
1828 if (current_container.Kind == MemberKind.Interface) {
1829 report.Error (531, current_property.Get.Block.StartLocation,
1830 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1834 current_local_parameters = null;
1835 lexer.PropertyParsing = true;
1838 if (Lexer.doc_state == XmlCommentState.Error)
1839 Lexer.doc_state = XmlCommentState.NotAllowed;
1843 set_accessor_declaration
1844 : opt_attributes opt_modifiers SET
1846 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1847 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1850 if (current_property.Set != null) {
1851 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1854 if (current_property is Indexer) {
1855 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1856 ParametersCompiled.MergeGenerated (compiler,
1857 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1858 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1860 (Attributes) $1, GetLocation ($3));
1862 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1863 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1864 (Attributes) $1, GetLocation ($3));
1867 current_local_parameters = current_property.Set.ParameterInfo;
1868 lbag.AddMember (current_property.Set, mod_locations);
1869 lexer.PropertyParsing = false;
1874 current_property.Set.Block = (ToplevelBlock) $5;
1876 if (current_container.Kind == MemberKind.Interface) {
1877 report.Error (531, current_property.Set.Block.StartLocation,
1878 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1882 current_local_parameters = null;
1883 lexer.PropertyParsing = true;
1886 && Lexer.doc_state == XmlCommentState.Error)
1887 Lexer.doc_state = XmlCommentState.NotAllowed;
1900 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1905 interface_declaration
1912 type_declaration_name
1914 lexer.ConstraintsParsing = true;
1915 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1916 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1919 opt_type_parameter_constraints_clauses
1921 lexer.ConstraintsParsing = false;
1924 current_container.SetConstraints ((List<Constraints>) $9);
1927 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1928 Lexer.doc_state = XmlCommentState.Allowed;
1931 lexer.parsing_modifiers = true;
1933 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1935 --lexer.parsing_declaration;
1937 Lexer.doc_state = XmlCommentState.Allowed;
1941 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1942 $$ = pop_current_class ();
1944 | opt_attributes opt_modifiers opt_partial INTERFACE error
1946 Error_SyntaxError (yyToken);
1950 opt_interface_member_declarations
1952 | interface_member_declarations
1955 interface_member_declarations
1956 : interface_member_declaration
1958 lexer.parsing_modifiers = true;
1960 | interface_member_declarations interface_member_declaration
1962 lexer.parsing_modifiers = true;
1966 interface_member_declaration
1967 : constant_declaration
1969 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1973 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1975 | method_declaration
1976 | property_declaration
1978 | indexer_declaration
1979 | operator_declaration
1981 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1983 | constructor_declaration
1985 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1989 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1993 operator_declaration
1994 : opt_attributes opt_modifiers operator_declarator
1999 OperatorDeclaration decl = (OperatorDeclaration) $3;
2001 Operator op = new Operator (
2002 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
2003 current_local_parameters,
2004 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2006 if (op.Block == null)
2007 op.ParameterInfo.CheckParameters (op);
2010 op.DocComment = tmpComment;
2011 Lexer.doc_state = XmlCommentState.Allowed;
2014 // Note again, checking is done in semantic analysis
2015 current_type.AddOperator (op);
2017 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
2020 current_local_parameters = null;
2026 | SEMICOLON { $$ = null; }
2030 : type_expression_or_array
2033 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2034 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2039 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2041 valid_param_mod = ParameterModifierType.DefaultValue;
2043 opt_formal_parameter_list CLOSE_PARENS
2045 valid_param_mod = 0;
2047 Location loc = GetLocation ($2);
2048 Operator.OpType op = (Operator.OpType) $3;
2049 current_local_parameters = (ParametersCompiled)$6;
2051 int p_count = current_local_parameters.Count;
2053 if (op == Operator.OpType.Addition)
2054 op = Operator.OpType.UnaryPlus;
2055 else if (op == Operator.OpType.Subtraction)
2056 op = Operator.OpType.UnaryNegation;
2059 if (IsUnaryOperator (op)) {
2061 report.Error (1020, loc, "Overloadable binary operator expected");
2062 } else if (p_count != 1) {
2063 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2064 Operator.GetName (op));
2068 report.Error (1019, loc, "Overloadable unary operator expected");
2069 } else if (p_count != 2) {
2070 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2071 Operator.GetName (op));
2076 tmpComment = Lexer.consume_doc_comment ();
2077 Lexer.doc_state = XmlCommentState.NotAllowed;
2080 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2081 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2083 | conversion_operator_declarator
2086 overloadable_operator
2088 : BANG { $$ = Operator.OpType.LogicalNot; }
2089 | TILDE { $$ = Operator.OpType.OnesComplement; }
2090 | OP_INC { $$ = Operator.OpType.Increment; }
2091 | OP_DEC { $$ = Operator.OpType.Decrement; }
2092 | TRUE { $$ = Operator.OpType.True; }
2093 | FALSE { $$ = Operator.OpType.False; }
2094 // Unary and binary:
2095 | PLUS { $$ = Operator.OpType.Addition; }
2096 | MINUS { $$ = Operator.OpType.Subtraction; }
2098 | STAR { $$ = Operator.OpType.Multiply; }
2099 | DIV { $$ = Operator.OpType.Division; }
2100 | PERCENT { $$ = Operator.OpType.Modulus; }
2101 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2102 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2103 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2104 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2105 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2106 | OP_EQ { $$ = Operator.OpType.Equality; }
2107 | OP_NE { $$ = Operator.OpType.Inequality; }
2108 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2109 | OP_LT { $$ = Operator.OpType.LessThan; }
2110 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2111 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2114 conversion_operator_declarator
2115 : IMPLICIT OPERATOR type OPEN_PARENS
2117 valid_param_mod = ParameterModifierType.DefaultValue;
2119 opt_formal_parameter_list CLOSE_PARENS
2121 valid_param_mod = 0;
2123 Location loc = GetLocation ($2);
2124 current_local_parameters = (ParametersCompiled)$6;
2126 if (current_local_parameters.Count != 1) {
2127 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2131 tmpComment = Lexer.consume_doc_comment ();
2132 Lexer.doc_state = XmlCommentState.NotAllowed;
2135 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2136 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2138 | EXPLICIT OPERATOR type OPEN_PARENS
2140 valid_param_mod = ParameterModifierType.DefaultValue;
2142 opt_formal_parameter_list CLOSE_PARENS
2144 valid_param_mod = 0;
2146 Location loc = GetLocation ($2);
2147 current_local_parameters = (ParametersCompiled)$6;
2149 if (current_local_parameters.Count != 1) {
2150 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2154 tmpComment = Lexer.consume_doc_comment ();
2155 Lexer.doc_state = XmlCommentState.NotAllowed;
2158 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2159 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2163 Error_SyntaxError (yyToken);
2164 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2165 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2169 Error_SyntaxError (yyToken);
2170 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2171 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2175 constructor_declaration
2176 : constructor_declarator
2179 Constructor c = (Constructor) $1;
2180 c.Block = (ToplevelBlock) $2;
2183 c.DocComment = ConsumeStoredComment ();
2185 current_local_parameters = null;
2187 Lexer.doc_state = XmlCommentState.Allowed;
2191 constructor_declarator
2197 tmpComment = Lexer.consume_doc_comment ();
2198 Lexer.doc_state = XmlCommentState.Allowed;
2201 valid_param_mod = ParameterModifierType.All;
2203 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2205 valid_param_mod = 0;
2206 current_local_parameters = (ParametersCompiled) $6;
2208 var lt = (LocatedToken) $3;
2209 var mods = (Modifiers) $2;
2210 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2212 if (lt.Value != current_container.MemberName.Name) {
2213 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2214 } else if ((mods & Modifiers.STATIC) != 0) {
2215 if ((mods & Modifiers.AccessibilityMask) != 0){
2216 report.Error (515, c.Location,
2217 "`{0}': static constructor cannot have an access modifier",
2218 c.GetSignatureForError ());
2222 current_type.AddConstructor (c);
2223 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2227 // start block here, so possible anonymous methods inside
2228 // constructor initializer can get correct parent block
2230 start_block (lexer.Location);
2232 opt_constructor_initializer
2235 var c = (Constructor) $8;
2236 c.Initializer = (ConstructorInitializer) $9;
2239 report.Error (514, c.Location,
2240 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2241 c.GetSignatureForError ());
2251 | SEMICOLON { current_block = null; $$ = null; }
2254 opt_constructor_initializer
2256 | constructor_initializer
2259 constructor_initializer
2260 : COLON BASE OPEN_PARENS
2262 ++lexer.parsing_block;
2264 opt_argument_list CLOSE_PARENS
2266 --lexer.parsing_block;
2267 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2268 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2270 | COLON THIS OPEN_PARENS
2272 ++lexer.parsing_block;
2274 opt_argument_list CLOSE_PARENS
2276 --lexer.parsing_block;
2277 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2278 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2282 Error_SyntaxError (yyToken);
2283 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2284 lbag.AddLocation ($$, GetLocation ($1));
2288 Error_SyntaxError (yyToken);
2293 destructor_declaration
2294 : opt_attributes opt_modifiers TILDE
2297 tmpComment = Lexer.consume_doc_comment ();
2298 Lexer.doc_state = XmlCommentState.NotAllowed;
2301 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2303 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2305 var lt = (LocatedToken) $5;
2306 if (lt.Value != current_container.MemberName.Name){
2307 report.Error (574, lt.Location, "Name of destructor must match name of class");
2308 } else if (current_container.Kind != MemberKind.Class){
2309 report.Error (575, lt.Location, "Only class types can contain destructor");
2312 Destructor d = new Destructor (current_type, (Modifiers) $2,
2313 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2315 d.DocComment = ConsumeStoredComment ();
2317 d.Block = (ToplevelBlock) $8;
2318 current_type.AddMember (d);
2319 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2321 current_local_parameters = null;
2328 EVENT type member_declaration_name
2330 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2331 current_type.AddMember (current_event_field);
2333 if (current_event_field.MemberName.ExplicitInterface != null) {
2334 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2335 current_event_field.GetSignatureForError ());
2338 $$ = current_event_field;
2340 opt_event_initializer
2341 opt_event_declarators
2345 current_event_field.DocComment = Lexer.consume_doc_comment ();
2346 Lexer.doc_state = XmlCommentState.Allowed;
2349 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2350 current_event_field = null;
2354 EVENT type member_declaration_name
2357 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2358 current_type.AddMember (current_event);
2359 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2361 lexer.EventParsing = true;
2363 event_accessor_declarations
2365 if (current_container.Kind == MemberKind.Interface)
2366 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2368 lexer.EventParsing = false;
2373 current_event.DocComment = Lexer.consume_doc_comment ();
2374 Lexer.doc_state = XmlCommentState.Allowed;
2377 lbag.AppendToMember (current_event, GetLocation ($9));
2378 current_event = null;
2379 current_local_parameters = null;
2385 Error_SyntaxError (yyToken);
2387 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2391 opt_event_initializer
2395 ++lexer.parsing_block;
2397 event_variable_initializer
2399 --lexer.parsing_block;
2400 current_event_field.Initializer = (Expression) $3;
2404 opt_event_declarators
2412 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2414 | event_declarators event_declarator
2416 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2423 var lt = (LocatedToken) $2;
2424 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2425 lbag.AddLocation ($$, GetLocation ($1));
2427 | COMMA IDENTIFIER ASSIGN
2429 ++lexer.parsing_block;
2431 event_variable_initializer
2433 --lexer.parsing_block;
2434 var lt = (LocatedToken) $2;
2435 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2436 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2440 event_variable_initializer
2442 if (current_container.Kind == MemberKind.Interface) {
2443 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2444 current_event_field.GetSignatureForError ());
2447 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2448 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2449 current_event_field.GetSignatureForError ());
2452 variable_initializer
2458 event_accessor_declarations
2459 : add_accessor_declaration remove_accessor_declaration
2460 | remove_accessor_declaration add_accessor_declaration
2461 | add_accessor_declaration
2463 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2464 current_event.GetSignatureForError ());
2466 | remove_accessor_declaration
2468 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2469 current_event.GetSignatureForError ());
2473 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2478 add_accessor_declaration
2479 : opt_attributes opt_modifiers ADD
2481 if ($2 != ModifierNone) {
2482 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2485 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2486 current_local_parameters = current_event.Add.ParameterInfo;
2488 lbag.AddMember (current_event.Add, mod_locations);
2489 lexer.EventParsing = false;
2491 event_accessor_block
2493 lexer.EventParsing = true;
2495 current_event.Add.Block = (ToplevelBlock) $5;
2497 if (current_container.Kind == MemberKind.Interface) {
2498 report.Error (531, current_event.Add.Block.StartLocation,
2499 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2502 current_local_parameters = null;
2506 remove_accessor_declaration
2507 : opt_attributes opt_modifiers REMOVE
2509 if ($2 != ModifierNone) {
2510 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2513 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2514 current_local_parameters = current_event.Remove.ParameterInfo;
2516 lbag.AddMember (current_event.Remove, mod_locations);
2517 lexer.EventParsing = false;
2519 event_accessor_block
2521 lexer.EventParsing = true;
2523 current_event.Remove.Block = (ToplevelBlock) $5;
2525 if (current_container.Kind == MemberKind.Interface) {
2526 report.Error (531, current_event.Remove.Block.StartLocation,
2527 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2530 current_local_parameters = null;
2534 event_accessor_block
2537 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2543 attributes_without_members
2544 : attribute_sections CLOSE_BRACE
2546 current_type.UnattachedAttributes = (Attributes) $1;
2547 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2548 lexer.putback ('}');
2552 // For full ast try to recover incomplete ambiguous member
2553 // declaration in form on class X { public int }
2555 : opt_attributes opt_modifiers member_type CLOSE_BRACE
2557 report.Error (1519, lexer.Location, "Unexpected symbol `}' in class, struct, or interface member declaration");
2559 lexer.putback ('}');
2561 lexer.parsing_generic_declaration = false;
2562 FullNamedExpression type = (FullNamedExpression) $3;
2563 current_field = new Field (current_type, type, (Modifiers) $2, MemberName.Null, (Attributes) $1);
2564 current_type.AddField (current_field);
2572 ENUM type_declaration_name
2576 enumTypeComment = Lexer.consume_doc_comment ();
2581 Lexer.doc_state = XmlCommentState.Allowed;
2583 MemberName name = (MemberName) $4;
2584 if (name.IsGeneric) {
2585 report.Error (1675, name.Location, "Enums cannot have type parameters");
2588 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2590 opt_enum_member_declarations
2592 // here will be evaluated after CLOSE_BLACE is consumed.
2594 Lexer.doc_state = XmlCommentState.Allowed;
2596 CLOSE_BRACE opt_semicolon
2599 current_container.DocComment = enumTypeComment;
2601 --lexer.parsing_declaration;
2604 // em.DocComment = ev.DocComment;
2606 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2607 $$ = pop_current_class ();
2615 var te = $2 as TypeExpression;
2616 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2617 Enum.Error_1008 (GetLocation ($2), report);
2623 Error_TypeExpected (GetLocation ($1));
2628 opt_enum_member_declarations
2630 | enum_member_declarations
2631 | enum_member_declarations COMMA
2633 lbag.AddLocation ($1, GetLocation ($2));
2637 enum_member_declarations
2638 : enum_member_declaration
2639 | enum_member_declarations COMMA enum_member_declaration
2641 lbag.AddLocation ($1, GetLocation ($2));
2646 enum_member_declaration
2647 : opt_attributes IDENTIFIER
2649 var lt = (LocatedToken) $2;
2650 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2651 ((Enum) current_type).AddEnumMember (em);
2654 em.DocComment = Lexer.consume_doc_comment ();
2655 Lexer.doc_state = XmlCommentState.Allowed;
2660 | opt_attributes IDENTIFIER
2662 ++lexer.parsing_block;
2664 tmpComment = Lexer.consume_doc_comment ();
2665 Lexer.doc_state = XmlCommentState.NotAllowed;
2668 ASSIGN constant_expression
2670 --lexer.parsing_block;
2672 var lt = (LocatedToken) $2;
2673 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2674 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2675 ((Enum) current_type).AddEnumMember (em);
2678 em.DocComment = ConsumeStoredComment ();
2682 | opt_attributes IDENTIFIER error
2684 Error_SyntaxError (yyToken);
2686 var lt = (LocatedToken) $2;
2687 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2688 ((Enum) current_type).AddEnumMember (em);
2691 em.DocComment = Lexer.consume_doc_comment ();
2692 Lexer.doc_state = XmlCommentState.Allowed;
2697 | attributes_without_members
2700 delegate_declaration
2704 member_type type_declaration_name
2707 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2709 opt_formal_parameter_list CLOSE_PARENS
2711 valid_param_mod = 0;
2713 ParametersCompiled p = (ParametersCompiled) $8;
2715 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2717 p.CheckParameters (del);
2719 current_container.AddTypeContainer (del);
2721 current_delegate = del;
2722 lexer.ConstraintsParsing = true;
2724 opt_type_parameter_constraints_clauses
2726 lexer.ConstraintsParsing = false;
2731 current_delegate.DocComment = Lexer.consume_doc_comment ();
2732 Lexer.doc_state = XmlCommentState.Allowed;
2736 current_delegate.SetConstraints ((List<Constraints>) $11);
2737 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2739 $$ = current_delegate;
2741 current_delegate = null;
2749 if (lang_version < LanguageVersion.ISO_2)
2750 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2752 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2756 namespace_or_type_expr
2758 | qualified_alias_member IDENTIFIER opt_type_argument_list
2760 var lt1 = (LocatedToken) $1;
2761 var lt2 = (LocatedToken) $2;
2763 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2764 lbag.AddLocation ($$, GetLocation ($2));
2770 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2772 var lt = (LocatedToken) $3;
2773 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2774 lbag.AddLocation ($$, GetLocation ($2));
2779 : IDENTIFIER opt_type_argument_list
2781 var lt = (LocatedToken) $1;
2782 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2787 // Generics arguments (any type, without attributes)
2789 opt_type_argument_list
2791 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2793 if (lang_version < LanguageVersion.ISO_2)
2794 FeatureIsNotAvailable (GetLocation ($1), "generics");
2798 | OP_GENERICS_LT error
2800 Error_TypeExpected (lexer.Location);
2801 $$ = new TypeArguments ();
2808 TypeArguments type_args = new TypeArguments ();
2809 type_args.Add ((FullNamedExpression) $1);
2812 | type_arguments COMMA type
2814 TypeArguments type_args = (TypeArguments) $1;
2815 type_args.Add ((FullNamedExpression) $3);
2821 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2823 type_declaration_name
2826 lexer.parsing_generic_declaration = true;
2828 opt_type_parameter_list
2830 lexer.parsing_generic_declaration = false;
2831 var lt = (LocatedToken) $1;
2832 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2836 member_declaration_name
2837 : method_declaration_name
2839 MemberName mn = (MemberName)$1;
2840 if (mn.TypeParameters != null)
2841 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2842 mn.GetSignatureForError ()));
2846 method_declaration_name
2847 : type_declaration_name
2848 | explicit_interface IDENTIFIER opt_type_parameter_list
2850 lexer.parsing_generic_declaration = false;
2851 var lt = (LocatedToken) $2;
2852 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2856 indexer_declaration_name
2859 lexer.parsing_generic_declaration = false;
2860 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2862 | explicit_interface THIS
2864 lexer.parsing_generic_declaration = false;
2865 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2870 : IDENTIFIER opt_type_argument_list DOT
2872 var lt = (LocatedToken) $1;
2873 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2874 lbag.AddLocation ($$, GetLocation ($3));
2876 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2878 var lt1 = (LocatedToken) $1;
2879 var lt2 = (LocatedToken) $2;
2881 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2882 lbag.AddLocation ($$, GetLocation ($4));
2884 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2886 var lt = (LocatedToken) $2;
2887 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2888 lbag.AddLocation ($$, GetLocation ($4));
2892 opt_type_parameter_list
2894 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2896 if (lang_version < LanguageVersion.ISO_2)
2897 FeatureIsNotAvailable (GetLocation ($1), "generics");
2900 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2907 var tparams = new TypeParameters ();
2908 tparams.Add ((TypeParameter)$1);
2911 | type_parameters COMMA type_parameter
2913 var tparams = (TypeParameters) $1;
2914 tparams.Add ((TypeParameter)$3);
2916 lbag.AddLocation ($3, GetLocation ($3));
2921 : opt_attributes opt_type_parameter_variance IDENTIFIER
2923 var lt = (LocatedToken)$3;
2924 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2928 if (GetTokenName (yyToken) == "type")
2929 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2931 Error_SyntaxError (yyToken);
2933 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2938 // All types where void is allowed
2941 : type_expression_or_array
2944 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2951 lexer.parsing_generic_declaration = true;
2956 // A type which does not allow `void' to be used
2959 : type_expression_or_array
2962 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2963 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2971 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2972 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2977 : type_expression_or_array
2980 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2981 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2985 type_expression_or_array
2987 | type_expression rank_specifiers
2989 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2994 : namespace_or_type_expr opt_nullable
2997 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2999 var sn = $1 as SimpleName;
3000 if (sn != null && sn.Name == "var")
3001 $$ = new VarExpr (sn.Location);
3006 | namespace_or_type_expr pointer_stars
3008 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
3010 | builtin_types opt_nullable
3013 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3015 | builtin_types pointer_stars
3017 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
3019 | VOID pointer_stars
3021 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
3028 var types = new List<FullNamedExpression> (2);
3029 types.Add ((FullNamedExpression) $1);
3032 | type_list COMMA base_type_name
3034 var types = (List<FullNamedExpression>) $1;
3035 types.Add ((FullNamedExpression) $3);
3043 if ($1 is ComposedCast) {
3044 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3051 * replaces all the productions for isolating the various
3052 * simple types, but we need this to reuse it easily in variable_type
3055 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3056 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3057 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3058 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3059 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3060 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3065 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3066 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3067 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3068 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3069 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3070 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3071 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3072 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3073 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3077 // Expressions, section 7.5
3082 : primary_expression_or_type
3084 | array_creation_expression
3085 | parenthesized_expression
3086 | default_value_expression
3087 | invocation_expression
3091 | post_increment_expression
3092 | post_decrement_expression
3093 | object_or_delegate_creation_expression
3094 | anonymous_type_expression
3097 | checked_expression
3098 | unchecked_expression
3099 | pointer_member_access
3100 | anonymous_method_expression
3101 | undocumented_expressions
3104 primary_expression_or_type
3105 : IDENTIFIER opt_type_argument_list
3107 var lt = (LocatedToken) $1;
3108 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3110 | IDENTIFIER GENERATE_COMPLETION {
3111 var lt = (LocatedToken) $1;
3112 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3120 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3124 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3125 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3130 // Here is the trick, tokenizer may think that parens is a special but
3131 // parser is interested in open parens only, so we merge them.
3132 // Consider: if (a)foo ();
3140 // Use this production to accept closing parenthesis or
3141 // performing completion
3145 | COMPLETE_COMPLETION
3149 parenthesized_expression
3150 : OPEN_PARENS expression CLOSE_PARENS
3152 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3153 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3155 | OPEN_PARENS expression COMPLETE_COMPLETION
3157 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3162 : primary_expression DOT identifier_inside_body opt_type_argument_list
3164 var lt = (LocatedToken) $3;
3165 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3166 lbag.AddLocation ($$, GetLocation ($2));
3168 | builtin_types DOT identifier_inside_body opt_type_argument_list
3170 var lt = (LocatedToken) $3;
3171 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3172 lbag.AddLocation ($$, GetLocation ($2));
3174 | BASE DOT identifier_inside_body opt_type_argument_list
3176 var lt = (LocatedToken) $3;
3177 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3178 lbag.AddLocation ($$, GetLocation ($2));
3180 | qualified_alias_member identifier_inside_body opt_type_argument_list
3182 var lt1 = (LocatedToken) $1;
3183 var lt2 = (LocatedToken) $2;
3185 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3186 lbag.AddLocation ($$, GetLocation ($2));
3188 | primary_expression DOT GENERATE_COMPLETION {
3189 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3191 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3192 var lt = (LocatedToken) $3;
3193 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3195 | builtin_types DOT GENERATE_COMPLETION
3197 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3199 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3200 var lt = (LocatedToken) $3;
3201 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3205 invocation_expression
3206 : primary_expression open_parens_any opt_argument_list close_parens
3208 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3209 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3211 | primary_expression open_parens_any argument_list error
3213 Error_SyntaxError (yyToken);
3215 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3216 lbag.AddLocation ($$, GetLocation ($2));
3218 | primary_expression open_parens_any error
3220 Error_SyntaxError (yyToken);
3222 $$ = new Invocation ((Expression) $1, null);
3223 lbag.AddLocation ($$, GetLocation ($2));
3227 opt_object_or_collection_initializer
3228 : /* empty */ { $$ = null; }
3229 | object_or_collection_initializer
3232 object_or_collection_initializer
3233 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3236 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3238 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3240 lbag.AddLocation ($$, GetLocation ($3));
3242 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3244 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3245 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3249 opt_member_initializer_list
3250 : /* empty */ { $$ = null; }
3251 | member_initializer_list
3257 member_initializer_list
3258 : member_initializer
3260 var a = new List<Expression> ();
3261 a.Add ((Expression) $1);
3264 | member_initializer_list COMMA member_initializer
3266 var a = (List<Expression>)$1;
3267 a.Add ((Expression) $3);
3270 | member_initializer_list error {
3271 Error_SyntaxError (yyToken);
3277 : IDENTIFIER ASSIGN initializer_value
3279 var lt = (LocatedToken) $1;
3280 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3281 lbag.AddLocation ($$, GetLocation ($2));
3283 | AWAIT ASSIGN initializer_value
3285 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
3286 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3287 lbag.AddLocation ($$, GetLocation ($2));
3289 | GENERATE_COMPLETION
3291 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3293 | non_assignment_expression opt_COMPLETE_COMPLETION {
3294 CompletionSimpleName csn = $1 as CompletionSimpleName;
3296 $$ = new CollectionElementInitializer ((Expression)$1);
3298 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3300 | OPEN_BRACE expression_list CLOSE_BRACE
3305 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3307 | OPEN_BRACE CLOSE_BRACE
3309 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3316 | object_or_collection_initializer
3320 : /* empty */ { $$ = null; }
3325 : argument_or_named_argument
3327 Arguments list = new Arguments (4);
3328 list.Add ((Argument) $1);
3331 | argument_list COMMA argument
3333 Arguments list = (Arguments) $1;
3334 if (list [list.Count - 1] is NamedArgument)
3335 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3337 list.Add ((Argument) $3);
3340 | argument_list COMMA named_argument
3342 Arguments list = (Arguments) $1;
3343 NamedArgument a = (NamedArgument) $3;
3344 for (int i = 0; i < list.Count; ++i) {
3345 NamedArgument na = list [i] as NamedArgument;
3346 if (na != null && na.Name == a.Name)
3347 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3354 | argument_list COMMA error
3356 if (lexer.putback_char == -1)
3357 lexer.putback (')'); // TODO: Wrong but what can I do
3358 Error_SyntaxError (yyToken);
3363 report.Error (839, GetLocation ($1), "An argument is missing");
3371 $$ = new Argument ((Expression) $1);
3373 | non_simple_argument
3376 argument_or_named_argument
3382 : REF variable_reference
3384 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3385 lbag.AddLocation ($$, GetLocation ($1));
3387 | OUT variable_reference
3389 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3390 lbag.AddLocation ($$, GetLocation ($1));
3392 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3394 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3395 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3397 | ARGLIST OPEN_PARENS CLOSE_PARENS
3399 $$ = new Argument (new Arglist (GetLocation ($1)));
3400 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3409 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3411 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3412 lbag.AddLocation ($$, GetLocation ($4));
3414 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3416 Error_SyntaxError (yyToken);
3417 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3419 | primary_expression OPEN_BRACKET_EXPR error
3421 Error_SyntaxError (yyToken);
3422 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3427 : expression_or_error
3429 var list = new List<Expression> (4);
3430 list.Add ((Expression) $1);
3433 | expression_list COMMA expression_or_error
3435 var list = (List<Expression>) $1;
3436 list.Add ((Expression) $3);
3441 expression_list_arguments
3442 : expression_list_argument
3444 Arguments args = new Arguments (4);
3445 args.Add ((Argument) $1);
3448 | expression_list_arguments COMMA expression_list_argument
3450 Arguments args = (Arguments) $1;
3451 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3452 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3454 args.Add ((Argument) $3);
3459 expression_list_argument
3462 $$ = new Argument ((Expression) $1);
3470 $$ = new This (GetLocation ($1));
3475 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3477 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3478 lbag.AddLocation ($$, GetLocation ($4));
3480 | BASE OPEN_BRACKET error
3482 Error_SyntaxError (yyToken);
3483 $$ = new ElementAccess (null, null, GetLocation ($2));
3487 post_increment_expression
3488 : primary_expression OP_INC
3490 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3494 post_decrement_expression
3495 : primary_expression OP_DEC
3497 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3501 object_or_delegate_creation_expression
3502 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3505 if (lang_version <= LanguageVersion.ISO_2)
3506 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3508 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3510 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3513 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3515 | NEW new_expr_type object_or_collection_initializer
3517 if (lang_version <= LanguageVersion.ISO_2)
3518 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3520 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3524 array_creation_expression
3525 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3527 opt_array_initializer
3529 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3530 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3531 Next = (ComposedTypeSpecifier) $6
3532 }, (ArrayInitializer) $7, GetLocation ($1));
3533 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3535 | NEW new_expr_type rank_specifiers opt_array_initializer
3538 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3540 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3542 | NEW rank_specifier array_initializer
3544 if (lang_version <= LanguageVersion.ISO_2)
3545 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3547 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3549 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3551 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3552 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3554 | NEW new_expr_type error
3556 Error_SyntaxError (yyToken);
3557 // It can be any of new expression, create the most common one
3558 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3564 ++lexer.parsing_type;
3568 --lexer.parsing_type;
3573 anonymous_type_expression
3574 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3576 if (lang_version <= LanguageVersion.ISO_2)
3577 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3579 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3581 // TODO: lbag comma location
3582 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3586 anonymous_type_parameters_opt_comma
3587 : anonymous_type_parameters_opt
3588 | anonymous_type_parameters COMMA
3591 anonymous_type_parameters_opt
3593 | anonymous_type_parameters
3596 anonymous_type_parameters
3597 : anonymous_type_parameter
3599 var a = new List<AnonymousTypeParameter> (4);
3600 a.Add ((AnonymousTypeParameter) $1);
3603 | anonymous_type_parameters COMMA anonymous_type_parameter
3605 var a = (List<AnonymousTypeParameter>) $1;
3606 a.Add ((AnonymousTypeParameter) $3);
3611 anonymous_type_parameter
3612 : identifier_inside_body ASSIGN variable_initializer
3614 var lt = (LocatedToken)$1;
3615 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3616 lbag.AddLocation ($$, GetLocation ($2));
3618 | identifier_inside_body
3620 var lt = (LocatedToken)$1;
3621 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3622 lt.Value, lt.Location);
3626 MemberAccess ma = (MemberAccess) $1;
3627 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3631 report.Error (746, lexer.Location,
3632 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3644 | rank_specifier rank_specifiers
3646 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3652 : OPEN_BRACKET CLOSE_BRACKET
3654 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3655 lbag.AddLocation ($$, GetLocation ($2));
3657 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3659 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3660 lbag.AddLocation ($$, GetLocation ($3));
3669 | dim_separators COMMA
3671 $$ = ((int) $1) + 1;
3675 opt_array_initializer
3687 : OPEN_BRACE CLOSE_BRACE
3689 var ai = new ArrayInitializer (0, GetLocation ($1));
3690 ai.VariableDeclaration = current_variable;
3691 lbag.AddLocation (ai, GetLocation ($2));
3694 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3696 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3697 ai.VariableDeclaration = current_variable;
3699 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3701 lbag.AddLocation (ai, GetLocation ($4));
3707 variable_initializer_list
3708 : variable_initializer
3710 var list = new List<Expression> (4);
3711 list.Add ((Expression) $1);
3714 | variable_initializer_list COMMA variable_initializer
3716 var list = (List<Expression>) $1;
3717 list.Add ((Expression) $3);
3725 lexer.TypeOfParsing = true;
3727 open_parens_any typeof_type_expression CLOSE_PARENS
3729 lexer.TypeOfParsing = false;
3730 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3731 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3735 typeof_type_expression
3740 Error_TypeExpected (lexer.Location);
3746 : identifier_inside_body generic_dimension
3748 var lt = (LocatedToken) $1;
3750 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3752 | qualified_alias_member identifier_inside_body generic_dimension
3754 var lt1 = (LocatedToken) $1;
3755 var lt2 = (LocatedToken) $2;
3757 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3758 lbag.AddLocation ($$, GetLocation ($2));
3760 | unbound_type_name DOT identifier_inside_body
3762 var lt = (LocatedToken) $3;
3764 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3766 | unbound_type_name DOT identifier_inside_body generic_dimension
3768 var lt = (LocatedToken) $3;
3770 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3772 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3774 var tne = (ATypeNameExpression) $1;
3775 if (tne.HasTypeArguments)
3776 Error_TypeExpected (GetLocation ($4));
3778 var lt = (LocatedToken) $3;
3779 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3786 if (lang_version < LanguageVersion.ISO_2)
3787 FeatureIsNotAvailable (GetLocation ($1), "generics");
3793 qualified_alias_member
3794 : IDENTIFIER DOUBLE_COLON
3796 var lt = (LocatedToken) $1;
3797 if (lang_version == LanguageVersion.ISO_1)
3798 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3805 : SIZEOF open_parens_any type CLOSE_PARENS
3807 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3808 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3810 | SIZEOF open_parens_any type error
3812 Error_SyntaxError (yyToken);
3814 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3815 lbag.AddLocation ($$, GetLocation ($2));
3820 : CHECKED open_parens_any expression CLOSE_PARENS
3822 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3823 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3827 Error_SyntaxError (yyToken);
3829 $$ = new CheckedExpr (null, GetLocation ($1));
3833 unchecked_expression
3834 : UNCHECKED open_parens_any expression CLOSE_PARENS
3836 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3837 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3841 Error_SyntaxError (yyToken);
3843 $$ = new UnCheckedExpr (null, GetLocation ($1));
3847 pointer_member_access
3848 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3850 var lt = (LocatedToken) $3;
3851 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3855 anonymous_method_expression
3856 : DELEGATE opt_anonymous_method_signature
3858 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3862 $$ = end_anonymous ((ParametersBlock) $4);
3864 | ASYNC DELEGATE opt_anonymous_method_signature
3866 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3870 $$ = end_anonymous ((ParametersBlock) $5);
3874 opt_anonymous_method_signature
3877 $$ = ParametersCompiled.Undefined;
3879 | anonymous_method_signature
3882 anonymous_method_signature
3885 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3887 opt_formal_parameter_list CLOSE_PARENS
3889 valid_param_mod = 0;
3894 default_value_expression
3895 : DEFAULT open_parens_any type CLOSE_PARENS
3897 if (lang_version < LanguageVersion.ISO_2)
3898 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3900 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3901 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3906 : primary_expression
3907 | BANG prefixed_unary_expression
3909 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3911 | TILDE prefixed_unary_expression
3913 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3915 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3917 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3918 lbag.AddLocation ($$, GetLocation ($3));
3920 | AWAIT prefixed_unary_expression
3923 if (current_anonymous_method is LambdaExpression) {
3924 report.Error (4034, GetLocation ($1),
3925 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3926 } else if (current_anonymous_method is AnonymousMethodExpression) {
3927 report.Error (4035, GetLocation ($1),
3928 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3930 report.Error (4033, GetLocation ($1),
3931 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3934 current_block.Explicit.RegisterAsyncAwait ();
3937 $$ = new Await ((Expression) $2, GetLocation ($1));
3941 Error_SyntaxError (yyToken);
3943 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3947 Error_SyntaxError (yyToken);
3949 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3951 | OPEN_PARENS_CAST type CLOSE_PARENS error
3953 Error_SyntaxError (yyToken);
3955 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3956 lbag.AddLocation ($$, GetLocation ($3));
3960 Error_SyntaxError (yyToken);
3962 $$ = new Await (null, GetLocation ($1));
3967 // The idea to split this out is from Rhys' grammar
3968 // to solve the problem with casts.
3970 prefixed_unary_expression
3972 | PLUS prefixed_unary_expression
3974 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3976 | MINUS prefixed_unary_expression
3978 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3980 | OP_INC prefixed_unary_expression
3982 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3984 | OP_DEC prefixed_unary_expression
3986 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3988 | STAR prefixed_unary_expression
3990 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3992 | BITWISE_AND prefixed_unary_expression
3994 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3998 Error_SyntaxError (yyToken);
4000 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
4004 Error_SyntaxError (yyToken);
4006 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
4010 Error_SyntaxError (yyToken);
4012 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
4016 Error_SyntaxError (yyToken);
4018 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
4022 Error_SyntaxError (yyToken);
4024 $$ = new Indirection (null, GetLocation ($1));
4028 Error_SyntaxError (yyToken);
4030 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
4034 multiplicative_expression
4035 : prefixed_unary_expression
4036 | multiplicative_expression STAR prefixed_unary_expression
4038 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4039 lbag.AddLocation ($$, GetLocation ($2));
4041 | multiplicative_expression DIV prefixed_unary_expression
4043 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4044 lbag.AddLocation ($$, GetLocation ($2));
4046 | multiplicative_expression PERCENT prefixed_unary_expression
4048 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4049 lbag.AddLocation ($$, GetLocation ($2));
4051 | multiplicative_expression STAR error
4053 Error_SyntaxError (yyToken);
4055 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4056 lbag.AddLocation ($$, GetLocation ($2));
4058 | multiplicative_expression DIV error
4060 Error_SyntaxError (yyToken);
4062 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4063 lbag.AddLocation ($$, GetLocation ($2));
4065 | multiplicative_expression PERCENT error
4067 Error_SyntaxError (yyToken);
4069 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4070 lbag.AddLocation ($$, GetLocation ($2));
4075 : multiplicative_expression
4076 | additive_expression PLUS multiplicative_expression
4078 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4079 lbag.AddLocation ($$, GetLocation ($2));
4081 | additive_expression MINUS multiplicative_expression
4083 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4084 lbag.AddLocation ($$, GetLocation ($2));
4086 | additive_expression AS type
4088 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4090 | additive_expression IS type
4092 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4094 | additive_expression PLUS error
4096 Error_SyntaxError (yyToken);
4098 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4099 lbag.AddLocation ($$, GetLocation ($2));
4101 | additive_expression MINUS error
4103 Error_SyntaxError (yyToken);
4105 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4106 lbag.AddLocation ($$, GetLocation ($2));
4108 | additive_expression AS error
4110 Error_SyntaxError (yyToken);
4112 $$ = new As ((Expression) $1, null, GetLocation ($2));
4114 | additive_expression IS error
4116 Error_SyntaxError (yyToken);
4118 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4123 : additive_expression
4124 | shift_expression OP_SHIFT_LEFT additive_expression
4126 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4127 lbag.AddLocation ($$, GetLocation ($2));
4129 | shift_expression OP_SHIFT_RIGHT additive_expression
4131 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4132 lbag.AddLocation ($$, GetLocation ($2));
4134 | shift_expression OP_SHIFT_LEFT error
4136 Error_SyntaxError (yyToken);
4138 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4139 lbag.AddLocation ($$, GetLocation ($2));
4141 | shift_expression OP_SHIFT_RIGHT error
4143 Error_SyntaxError (yyToken);
4145 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4146 lbag.AddLocation ($$, GetLocation ($2));
4150 relational_expression
4152 | relational_expression OP_LT shift_expression
4154 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4155 lbag.AddLocation ($$, GetLocation ($2));
4157 | relational_expression OP_GT shift_expression
4159 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4160 lbag.AddLocation ($$, GetLocation ($2));
4162 | relational_expression OP_LE shift_expression
4164 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4165 lbag.AddLocation ($$, GetLocation ($2));
4167 | relational_expression OP_GE shift_expression
4169 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4170 lbag.AddLocation ($$, GetLocation ($2));
4172 | relational_expression OP_LT error
4174 Error_SyntaxError (yyToken);
4176 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4177 lbag.AddLocation ($$, GetLocation ($2));
4179 | relational_expression OP_GT error
4181 Error_SyntaxError (yyToken);
4183 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4184 lbag.AddLocation ($$, GetLocation ($2));
4186 | relational_expression OP_LE error
4188 Error_SyntaxError (yyToken);
4190 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4191 lbag.AddLocation ($$, GetLocation ($2));
4193 | relational_expression OP_GE error
4195 Error_SyntaxError (yyToken);
4197 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4198 lbag.AddLocation ($$, GetLocation ($2));
4203 : relational_expression
4204 | equality_expression OP_EQ relational_expression
4206 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4207 lbag.AddLocation ($$, GetLocation ($2));
4209 | equality_expression OP_NE relational_expression
4211 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4212 lbag.AddLocation ($$, GetLocation ($2));
4214 | equality_expression OP_EQ error
4216 Error_SyntaxError (yyToken);
4218 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4219 lbag.AddLocation ($$, GetLocation ($2));
4221 | equality_expression OP_NE error
4223 Error_SyntaxError (yyToken);
4225 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4226 lbag.AddLocation ($$, GetLocation ($2));
4231 : equality_expression
4232 | and_expression BITWISE_AND equality_expression
4234 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4235 lbag.AddLocation ($$, GetLocation ($2));
4237 | and_expression BITWISE_AND error
4239 Error_SyntaxError (yyToken);
4241 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4242 lbag.AddLocation ($$, GetLocation ($2));
4246 exclusive_or_expression
4248 | exclusive_or_expression CARRET and_expression
4250 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4251 lbag.AddLocation ($$, GetLocation ($2));
4253 | exclusive_or_expression CARRET error
4255 Error_SyntaxError (yyToken);
4257 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4258 lbag.AddLocation ($$, GetLocation ($2));
4262 inclusive_or_expression
4263 : exclusive_or_expression
4264 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4266 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4267 lbag.AddLocation ($$, GetLocation ($2));
4269 | inclusive_or_expression BITWISE_OR error
4271 Error_SyntaxError (yyToken);
4273 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4274 lbag.AddLocation ($$, GetLocation ($2));
4278 conditional_and_expression
4279 : inclusive_or_expression
4280 | conditional_and_expression OP_AND inclusive_or_expression
4282 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4283 lbag.AddLocation ($$, GetLocation ($2));
4285 | conditional_and_expression OP_AND error
4287 Error_SyntaxError (yyToken);
4289 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4290 lbag.AddLocation ($$, GetLocation ($2));
4294 conditional_or_expression
4295 : conditional_and_expression
4296 | conditional_or_expression OP_OR conditional_and_expression
4298 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4299 lbag.AddLocation ($$, GetLocation ($2));
4301 | conditional_or_expression OP_OR error
4303 Error_SyntaxError (yyToken);
4305 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4306 lbag.AddLocation ($$, GetLocation ($2));
4310 null_coalescing_expression
4311 : conditional_or_expression
4312 | conditional_or_expression OP_COALESCING null_coalescing_expression
4314 if (lang_version < LanguageVersion.ISO_2)
4315 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4317 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4318 lbag.AddLocation ($$, GetLocation ($2));
4322 conditional_expression
4323 : null_coalescing_expression
4324 | null_coalescing_expression INTERR expression COLON expression
4326 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4327 lbag.AddLocation ($$, GetLocation ($4));
4329 | null_coalescing_expression INTERR expression error
4331 Error_SyntaxError (yyToken);
4333 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4335 | null_coalescing_expression INTERR expression COLON error
4337 Error_SyntaxError (yyToken);
4339 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4340 lbag.AddLocation ($$, GetLocation ($4));
4342 | null_coalescing_expression INTERR expression COLON CLOSE_BRACE
4344 Error_SyntaxError (Token.CLOSE_BRACE);
4346 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4347 lbag.AddLocation ($$, GetLocation ($4));
4348 lexer.putback ('}');
4352 assignment_expression
4353 : prefixed_unary_expression ASSIGN expression
4355 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4356 lbag.AddLocation ($$, GetLocation ($2));
4358 | prefixed_unary_expression OP_MULT_ASSIGN expression
4360 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4361 lbag.AddLocation ($$, GetLocation ($2));
4363 | prefixed_unary_expression OP_DIV_ASSIGN expression
4365 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4366 lbag.AddLocation ($$, GetLocation ($2));
4368 | prefixed_unary_expression OP_MOD_ASSIGN expression
4370 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4371 lbag.AddLocation ($$, GetLocation ($2));
4373 | prefixed_unary_expression OP_ADD_ASSIGN expression
4375 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4376 lbag.AddLocation ($$, GetLocation ($2));
4378 | prefixed_unary_expression OP_SUB_ASSIGN expression
4380 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4381 lbag.AddLocation ($$, GetLocation ($2));
4383 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4385 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4386 lbag.AddLocation ($$, GetLocation ($2));
4388 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4390 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4391 lbag.AddLocation ($$, GetLocation ($2));
4393 | prefixed_unary_expression OP_AND_ASSIGN expression
4395 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4396 lbag.AddLocation ($$, GetLocation ($2));
4398 | prefixed_unary_expression OP_OR_ASSIGN expression
4400 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4401 lbag.AddLocation ($$, GetLocation ($2));
4403 | prefixed_unary_expression OP_XOR_ASSIGN expression
4405 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4406 lbag.AddLocation ($$, GetLocation ($2));
4410 lambda_parameter_list
4413 var pars = new List<Parameter> (4);
4414 pars.Add ((Parameter) $1);
4418 | lambda_parameter_list COMMA lambda_parameter
4420 var pars = (List<Parameter>) $1;
4421 Parameter p = (Parameter)$3;
4422 if (pars[0].GetType () != p.GetType ()) {
4423 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4432 : parameter_modifier parameter_type identifier_inside_body
4434 var lt = (LocatedToken) $3;
4436 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4438 | parameter_type identifier_inside_body
4440 var lt = (LocatedToken) $2;
4442 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4446 var lt = (LocatedToken) $1;
4447 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4451 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4452 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4456 opt_lambda_parameter_list
4457 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4458 | lambda_parameter_list {
4459 var pars_list = (List<Parameter>) $1;
4460 $$ = new ParametersCompiled (pars_list.ToArray ());
4464 lambda_expression_body
4466 start_block (Location.Null);
4468 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4470 Block b = end_block (Location.Null);
4471 b.IsCompilerGenerated = true;
4472 b.AddStatement (new ContextualReturn ((Expression) $2));
4478 // Handles only cases like foo = x.FirstOrDefault (l => );
4479 // where we must restore current_variable
4480 Block b = end_block (Location.Null);
4481 b.IsCompilerGenerated = true;
4483 Error_SyntaxError (yyToken);
4492 Error_SyntaxError (yyToken);
4500 var lt = (LocatedToken) $1;
4501 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4502 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4504 lambda_expression_body
4506 $$ = end_anonymous ((ParametersBlock) $4);
4507 lbag.AddLocation ($$, GetLocation ($2));
4511 var lt = (LocatedToken) Error_AwaitAsIdentifier ($1);
4512 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4513 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4515 lambda_expression_body
4517 $$ = end_anonymous ((ParametersBlock) $4);
4518 lbag.AddLocation ($$, GetLocation ($2));
4520 | ASYNC identifier_inside_body ARROW
4522 var lt = (LocatedToken) $2;
4523 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4524 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4526 lambda_expression_body
4528 $$ = end_anonymous ((ParametersBlock) $5);
4529 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4531 | OPEN_PARENS_LAMBDA
4533 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4535 opt_lambda_parameter_list CLOSE_PARENS ARROW
4537 valid_param_mod = 0;
4538 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4540 lambda_expression_body
4542 $$ = end_anonymous ((ParametersBlock) $7);
4543 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4545 | ASYNC OPEN_PARENS_LAMBDA
4547 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4549 opt_lambda_parameter_list CLOSE_PARENS ARROW
4551 valid_param_mod = 0;
4552 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4554 lambda_expression_body
4556 $$ = end_anonymous ((ParametersBlock) $8);
4557 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4562 : assignment_expression
4563 | non_assignment_expression
4566 non_assignment_expression
4567 : conditional_expression
4572 $$ = new ArglistAccess (GetLocation ($1));
4576 undocumented_expressions
4577 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4579 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4580 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4582 | REFTYPE open_parens_any expression CLOSE_PARENS
4584 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4585 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4587 | MAKEREF open_parens_any expression CLOSE_PARENS
4589 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4590 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4601 $$ = new BooleanExpression ((Expression) $1);
4615 type_declaration_name
4617 lexer.ConstraintsParsing = true;
4619 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4620 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4621 FeatureIsNotAvailable (c.Location, "static classes");
4624 push_current_container (c, $3);
4627 opt_type_parameter_constraints_clauses
4629 lexer.ConstraintsParsing = false;
4632 current_container.SetConstraints ((List<Constraints>) $9);
4633 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4636 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4637 Lexer.doc_state = XmlCommentState.Allowed;
4640 lexer.parsing_modifiers = true;
4642 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4644 --lexer.parsing_declaration;
4646 Lexer.doc_state = XmlCommentState.Allowed;
4650 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4651 $$ = pop_current_class ();
4659 { $$ = $1; } // location
4665 mod_locations = null;
4667 lexer.parsing_modifiers = false;
4671 lexer.parsing_modifiers = false;
4677 | modifiers modifier
4679 var m1 = (Modifiers) $1;
4680 var m2 = (Modifiers) $2;
4682 if ((m1 & m2) != 0) {
4683 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4684 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4685 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4686 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4687 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4688 "More than one protection modifier specified");
4699 StoreModifierLocation ($$, GetLocation ($1));
4701 if (current_container.Kind == MemberKind.Namespace)
4702 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4706 $$ = Modifiers.PUBLIC;
4707 StoreModifierLocation ($$, GetLocation ($1));
4711 $$ = Modifiers.PROTECTED;
4712 StoreModifierLocation ($$, GetLocation ($1));
4716 $$ = Modifiers.INTERNAL;
4717 StoreModifierLocation ($$, GetLocation ($1));
4721 $$ = Modifiers.PRIVATE;
4722 StoreModifierLocation ($$, GetLocation ($1));
4726 $$ = Modifiers.ABSTRACT;
4727 StoreModifierLocation ($$, GetLocation ($1));
4731 $$ = Modifiers.SEALED;
4732 StoreModifierLocation ($$, GetLocation ($1));
4736 $$ = Modifiers.STATIC;
4737 StoreModifierLocation ($$, GetLocation ($1));
4741 $$ = Modifiers.READONLY;
4742 StoreModifierLocation ($$, GetLocation ($1));
4746 $$ = Modifiers.VIRTUAL;
4747 StoreModifierLocation ($$, GetLocation ($1));
4751 $$ = Modifiers.OVERRIDE;
4752 StoreModifierLocation ($$, GetLocation ($1));
4756 $$ = Modifiers.EXTERN;
4757 StoreModifierLocation ($$, GetLocation ($1));
4761 $$ = Modifiers.VOLATILE;
4762 StoreModifierLocation ($$, GetLocation ($1));
4766 $$ = Modifiers.UNSAFE;
4767 StoreModifierLocation ($$, GetLocation ($1));
4768 if (!settings.Unsafe)
4769 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4773 $$ = Modifiers.ASYNC;
4774 StoreModifierLocation ($$, GetLocation ($1));
4782 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4784 | COLON type_list error
4786 Error_SyntaxError (yyToken);
4788 current_type.SetBaseTypes ((List<FullNamedExpression>) $2);
4792 opt_type_parameter_constraints_clauses
4794 | type_parameter_constraints_clauses
4800 type_parameter_constraints_clauses
4801 : type_parameter_constraints_clause
4803 var constraints = new List<Constraints> (1);
4804 constraints.Add ((Constraints) $1);
4807 | type_parameter_constraints_clauses type_parameter_constraints_clause
4809 var constraints = (List<Constraints>) $1;
4810 Constraints new_constraint = (Constraints)$2;
4812 foreach (Constraints c in constraints) {
4813 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4814 report.Error (409, new_constraint.Location,
4815 "A constraint clause has already been specified for type parameter `{0}'",
4816 new_constraint.TypeParameter.Value);
4820 constraints.Add (new_constraint);
4825 type_parameter_constraints_clause
4826 : WHERE IDENTIFIER COLON type_parameter_constraints
4828 var lt = (LocatedToken) $2;
4829 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4830 lbag.AddLocation ($$, GetLocation ($3));
4832 | WHERE IDENTIFIER error
4834 Error_SyntaxError (yyToken);
4836 var lt = (LocatedToken) $2;
4837 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4841 type_parameter_constraints
4842 : type_parameter_constraint
4844 var constraints = new List<FullNamedExpression> (1);
4845 constraints.Add ((FullNamedExpression) $1);
4848 | type_parameter_constraints COMMA type_parameter_constraint
4850 var constraints = (List<FullNamedExpression>) $1;
4851 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4852 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4853 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4856 prev = $3 as SpecialContraintExpr;
4858 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4859 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4861 prev = constraints [0] as SpecialContraintExpr;
4862 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4863 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4868 constraints.Add ((FullNamedExpression) $3);
4873 type_parameter_constraint
4876 if ($1 is ComposedCast)
4877 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4881 | NEW OPEN_PARENS CLOSE_PARENS
4883 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4884 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4888 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4892 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4896 opt_type_parameter_variance
4901 | type_parameter_variance
4903 if (lang_version <= LanguageVersion.V_3)
4904 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4910 type_parameter_variance
4913 $$ = Variance.Covariant;
4917 $$ = Variance.Contravariant;
4926 // A block is "contained" on the following places:
4928 // property_declaration as part of the accessor body (get/set)
4929 // operator_declaration
4930 // constructor_declaration
4931 // destructor_declaration
4932 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4937 ++lexer.parsing_block;
4938 start_block (GetLocation ($1));
4940 opt_statement_list block_end
4949 --lexer.parsing_block;
4950 $$ = end_block (GetLocation ($1));
4952 | COMPLETE_COMPLETION
4954 --lexer.parsing_block;
4955 $$ = end_block (lexer.Location);
4963 ++lexer.parsing_block;
4964 current_block.StartLocation = GetLocation ($1);
4966 opt_statement_list CLOSE_BRACE
4968 --lexer.parsing_block;
4969 $$ = end_block (GetLocation ($4));
4980 | statement_list statement
4984 : block_variable_declaration
4986 current_block.AddStatement ((Statement) $1);
4988 | valid_declaration_statement
4990 current_block.AddStatement ((Statement) $1);
4995 Error_SyntaxError (yyToken);
5001 // The interactive_statement and its derivatives are only
5002 // used to provide a special version of `expression_statement'
5003 // that has a side effect of assigning the expression to
5006 interactive_statement_list
5007 : interactive_statement
5008 | interactive_statement_list interactive_statement
5011 interactive_statement
5012 : block_variable_declaration
5014 current_block.AddStatement ((Statement) $1);
5016 | interactive_valid_declaration_statement
5018 current_block.AddStatement ((Statement) $1);
5023 valid_declaration_statement
5026 | expression_statement
5027 | selection_statement
5028 | iteration_statement
5032 | unchecked_statement
5039 interactive_valid_declaration_statement
5042 | interactive_expression_statement
5043 | selection_statement
5044 | iteration_statement
5048 | unchecked_statement
5056 : valid_declaration_statement
5057 | block_variable_declaration
5059 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5064 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5069 Error_SyntaxError (yyToken);
5070 $$ = new EmptyStatement (GetLocation ($1));
5077 // Uses lexer.Location because semicolon location is not kept in quick mode
5078 $$ = new EmptyStatement (lexer.Location);
5083 : identifier_inside_body COLON
5085 var lt = (LocatedToken) $1;
5086 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5087 lbag.AddLocation (labeled, GetLocation ($2));
5088 current_block.AddLabel (labeled);
5089 current_block.AddStatement (labeled);
5095 : variable_type_simple
5096 | variable_type_simple rank_specifiers
5099 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5101 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5106 * The following is from Rhys' grammar:
5107 * > Types in local variable declarations must be recognized as
5108 * > expressions to prevent reduce/reduce errors in the grammar.
5109 * > The expressions are converted into types during semantic analysis.
5111 variable_type_simple
5112 : primary_expression_or_type opt_nullable
5114 // Ok, the above "primary_expression" is there to get rid of
5115 // both reduce/reduce and shift/reduces in the grammar, it should
5116 // really just be "type_name". If you use type_name, a reduce/reduce
5117 // creeps up. If you use namespace_or_type_name (which is all we need
5118 // really) two shift/reduces appear.
5121 // So the super-trick is that primary_expression
5122 // can only be either a SimpleName or a MemberAccess.
5123 // The MemberAccess case arises when you have a fully qualified type-name like :
5125 // SimpleName is when you have
5128 Expression expr = (Expression) $1;
5130 SimpleName sn = expr as SimpleName;
5131 if (sn != null && sn.Name == "var")
5132 $$ = new VarExpr (sn.Location);
5135 } else if (expr is ATypeNameExpression) {
5136 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5138 Error_ExpectingTypeName (expr);
5142 | primary_expression_or_type pointer_stars
5144 ATypeNameExpression expr = $1 as ATypeNameExpression;
5147 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5149 Error_ExpectingTypeName ((Expression)$1);
5153 | builtin_types opt_nullable
5158 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5160 | builtin_types pointer_stars
5162 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5164 | VOID pointer_stars
5166 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5170 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5171 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5177 | pointer_star pointer_stars
5179 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5187 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5191 identifier_inside_body
5195 $$ = Error_AwaitAsIdentifier ($1);
5199 block_variable_declaration
5200 : variable_type identifier_inside_body
5202 var lt = (LocatedToken) $2;
5203 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5204 current_block.AddLocalName (li);
5205 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5207 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5209 $$ = current_variable;
5210 current_variable = null;
5212 lbag.AddLocation ($$, PopLocation (), GetLocation ($6));
5214 lbag.AddLocation ($$, GetLocation ($6));
5216 | CONST variable_type identifier_inside_body
5218 var lt = (LocatedToken) $3;
5219 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5220 current_block.AddLocalName (li);
5221 current_variable = new BlockConstant ((FullNamedExpression) $2, li);
5223 const_variable_initializer opt_const_declarators SEMICOLON
5225 $$ = current_variable;
5226 current_variable = null;
5227 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5231 opt_local_variable_initializer
5233 | ASSIGN block_variable_initializer
5235 current_variable.Initializer = (Expression) $2;
5236 PushLocation (GetLocation ($1));
5237 $$ = current_variable;
5241 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5242 report.Error (650, lexer.Location,
5243 "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");
5245 Error_SyntaxError (yyToken);
5250 opt_variable_declarators
5252 | variable_declarators
5255 opt_using_or_fixed_variable_declarators
5257 | variable_declarators
5259 foreach (var d in current_variable.Declarators) {
5260 if (d.Initializer == null)
5261 Error_MissingInitializer (d.Variable.Location);
5266 variable_declarators
5267 : variable_declarator
5268 | variable_declarators variable_declarator
5272 : COMMA identifier_inside_body
5274 var lt = (LocatedToken) $2;
5275 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5276 var d = new BlockVariableDeclarator (li, null);
5277 current_variable.AddDeclarator (d);
5278 current_block.AddLocalName (li);
5279 lbag.AddLocation (d, GetLocation ($1));
5281 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5283 var lt = (LocatedToken) $2;
5284 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5285 var d = new BlockVariableDeclarator (li, (Expression) $4);
5286 current_variable.AddDeclarator (d);
5287 current_block.AddLocalName (li);
5288 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5292 const_variable_initializer
5295 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5297 | ASSIGN constant_initializer_expr
5299 current_variable.Initializer = (Expression) $2;
5303 opt_const_declarators
5310 | const_declarators const_declarator
5314 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5316 var lt = (LocatedToken) $2;
5317 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5318 var d = new BlockVariableDeclarator (li, (Expression) $4);
5319 current_variable.AddDeclarator (d);
5320 current_block.AddLocalName (li);
5321 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5325 block_variable_initializer
5326 : variable_initializer
5327 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5329 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5330 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5332 | STACKALLOC simple_type
5334 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5335 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5339 expression_statement
5340 : statement_expression SEMICOLON
5343 lbag.AddStatement ($$, GetLocation ($2));
5345 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5346 | statement_expression CLOSE_BRACE
5349 report.Error (1002, GetLocation ($2), "; expected");
5350 lexer.putback ('}');
5354 interactive_expression_statement
5355 : interactive_statement_expression SEMICOLON { $$ = $1; }
5356 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5360 // We have to do the wrapping here and not in the case above,
5361 // because statement_expression is used for example in for_statement
5363 statement_expression
5366 ExpressionStatement s = $1 as ExpressionStatement;
5368 var expr = $1 as Expression;
5369 $$ = new StatementErrorExpression (expr);
5371 $$ = new StatementExpression (s);
5376 interactive_statement_expression
5379 Expression expr = (Expression) $1;
5380 ExpressionStatement s;
5382 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5383 $$ = new StatementExpression (s);
5387 Error_SyntaxError (yyToken);
5388 $$ = new EmptyStatement (GetLocation ($1));
5398 : IF open_parens_any boolean_expression CLOSE_PARENS
5401 if ($5 is EmptyStatement)
5402 Warning_EmptyStatement (GetLocation ($5));
5404 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5405 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5407 | IF open_parens_any boolean_expression CLOSE_PARENS
5408 embedded_statement ELSE embedded_statement
5410 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5411 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5413 if ($5 is EmptyStatement)
5414 Warning_EmptyStatement (GetLocation ($5));
5415 if ($7 is EmptyStatement)
5416 Warning_EmptyStatement (GetLocation ($7));
5418 | IF open_parens_any boolean_expression error
5420 Error_SyntaxError (yyToken);
5422 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5423 lbag.AddStatement ($$, GetLocation ($2));
5428 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5430 start_block (GetLocation ($5));
5432 opt_switch_sections CLOSE_BRACE
5434 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5435 end_block (GetLocation ($8));
5436 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5438 | SWITCH open_parens_any expression error
5440 Error_SyntaxError (yyToken);
5442 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5443 lbag.AddStatement ($$, GetLocation ($2));
5450 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5457 | switch_sections switch_section
5460 Error_SyntaxError (yyToken);
5465 : switch_labels statement_list
5471 var label = (SwitchLabel) $1;
5472 label.SectionStart = true;
5473 current_block.AddStatement (label);
5475 | switch_labels switch_label
5477 current_block.AddStatement ((Statement) $2);
5482 : CASE constant_expression COLON
5484 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5485 lbag.AddLocation ($$, GetLocation ($3));
5487 | CASE constant_expression error
5489 Error_SyntaxError (yyToken);
5490 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5494 $$ = new SwitchLabel (null, GetLocation ($1));
5506 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5508 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5509 Warning_EmptyStatement (GetLocation ($5));
5511 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5512 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5514 | WHILE open_parens_any boolean_expression error
5516 Error_SyntaxError (yyToken);
5518 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5519 lbag.AddStatement ($$, GetLocation ($2));
5524 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5526 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5527 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5529 | DO embedded_statement error
5531 Error_SyntaxError (yyToken);
5532 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5534 | DO embedded_statement WHILE open_parens_any boolean_expression error
5536 Error_SyntaxError (yyToken);
5538 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5539 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5544 : FOR open_parens_any
5546 start_block (GetLocation ($2));
5547 current_block.IsCompilerGenerated = true;
5548 For f = new For (GetLocation ($1));
5549 current_block.AddStatement (f);
5558 // Has to use be extra rule to recover started block
5560 : opt_for_initializer SEMICOLON
5562 ((For) $0).Initializer = (Statement) $1;
5564 // Pass the "For" object to the iterator_part4
5565 oob_stack.Push ($0);
5567 for_condition_and_iterator_part
5570 var locations = (Tuple<Location,Location>) $4;
5572 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5573 Warning_EmptyStatement (GetLocation ($5));
5576 f.Statement = (Statement) $5;
5577 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5579 $$ = end_block (GetLocation ($2));
5583 Error_SyntaxError (yyToken);
5584 $$ = end_block (current_block.StartLocation);
5588 for_condition_and_iterator_part
5589 : opt_for_condition SEMICOLON
5591 For f = (For) oob_stack.Peek ();
5592 f.Condition = (BooleanExpression) $1;
5595 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5598 // Handle errors in the case of opt_for_condition being followed by
5599 // a close parenthesis
5600 | opt_for_condition close_parens_close_brace {
5601 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5602 For f = (For) oob_stack.Peek ();
5603 f.Condition = (BooleanExpression) $1;
5604 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5609 : opt_for_iterator CLOSE_PARENS {
5610 For f = (For) oob_stack.Peek ();
5611 f.Iterator = (Statement) $1;
5612 $$ = GetLocation ($2);
5614 | opt_for_iterator CLOSE_BRACE {
5615 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5616 For f = (For) oob_stack.Peek ();
5617 f.Iterator = (Statement) $1;
5618 $$ = GetLocation ($2);
5622 close_parens_close_brace
5624 | CLOSE_BRACE { lexer.putback ('}'); }
5628 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5633 : variable_type identifier_inside_body
5635 var lt = (LocatedToken) $2;
5636 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5637 current_block.AddLocalName (li);
5638 current_variable = new BlockVariable ((FullNamedExpression) $1, li);
5640 opt_local_variable_initializer opt_variable_declarators
5642 $$ = current_variable;
5644 lbag.AddLocation (current_variable, PopLocation ());
5646 current_variable = null;
5648 | statement_expression_list
5652 : /* empty */ { $$ = null; }
5653 | boolean_expression
5657 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5662 : statement_expression_list
5665 statement_expression_list
5666 : statement_expression
5667 | statement_expression_list COMMA statement_expression
5669 var sl = $1 as StatementList;
5671 sl = new StatementList ((Statement) $1, (Statement) $3);
5672 lbag.AddStatement (sl, GetLocation ($2));
5674 sl.Add ((Statement) $3);
5675 lbag.AppendTo (sl, GetLocation ($2));
5683 : FOREACH open_parens_any type error
5685 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5687 start_block (GetLocation ($2));
5688 current_block.IsCompilerGenerated = true;
5690 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5691 current_block.AddStatement (f);
5693 lbag.AddStatement (f, GetLocation ($2));
5694 $$ = end_block (GetLocation ($4));
5696 | FOREACH open_parens_any type identifier_inside_body error
5698 Error_SyntaxError (yyToken);
5700 start_block (GetLocation ($2));
5701 current_block.IsCompilerGenerated = true;
5703 var lt = (LocatedToken) $4;
5704 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5705 current_block.AddLocalName (li);
5707 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5708 current_block.AddStatement (f);
5710 lbag.AddStatement (f, GetLocation ($2));
5711 $$ = end_block (GetLocation ($5));
5713 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5715 start_block (GetLocation ($2));
5716 current_block.IsCompilerGenerated = true;
5718 var lt = (LocatedToken) $4;
5719 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5720 current_block.AddLocalName (li);
5725 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5726 Warning_EmptyStatement (GetLocation ($9));
5728 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5729 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5730 end_block (GetLocation ($7));
5738 | continue_statement
5748 $$ = new Break (GetLocation ($1));
5749 lbag.AddStatement ($$, GetLocation ($2));
5754 : CONTINUE SEMICOLON
5756 $$ = new Continue (GetLocation ($1));
5757 lbag.AddStatement ($$, GetLocation ($2));
5761 Error_SyntaxError (yyToken);
5762 $$ = new Continue (GetLocation ($1));
5767 : GOTO identifier_inside_body SEMICOLON
5769 var lt = (LocatedToken) $2;
5770 $$ = new Goto (lt.Value, GetLocation ($1));
5771 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5773 | GOTO CASE constant_expression SEMICOLON
5775 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5776 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5778 | GOTO DEFAULT SEMICOLON
5780 $$ = new GotoDefault (GetLocation ($1));
5781 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5786 : RETURN opt_expression SEMICOLON
5788 $$ = new Return ((Expression) $2, GetLocation ($1));
5789 lbag.AddStatement ($$, GetLocation ($3));
5791 | RETURN expression error
5793 Error_SyntaxError (yyToken);
5794 $$ = new Return ((Expression) $2, GetLocation ($1));
5798 Error_SyntaxError (yyToken);
5799 $$ = new Return (null, GetLocation ($1));
5804 : THROW opt_expression SEMICOLON
5806 $$ = new Throw ((Expression) $2, GetLocation ($1));
5807 lbag.AddStatement ($$, GetLocation ($3));
5811 Error_SyntaxError (yyToken);
5812 $$ = new Throw (null, GetLocation ($1));
5817 : identifier_inside_body RETURN opt_expression SEMICOLON
5819 var lt = (LocatedToken) $1;
5820 string s = lt.Value;
5822 report.Error (1003, lt.Location, "; expected");
5823 } else if ($3 == null) {
5824 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5825 } else if (lang_version == LanguageVersion.ISO_1){
5826 FeatureIsNotAvailable (lt.Location, "iterators");
5829 current_block.Explicit.RegisterIteratorYield ();
5830 $$ = new Yield ((Expression) $3, lt.Location);
5831 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5833 | identifier_inside_body RETURN expression error
5835 Error_SyntaxError (yyToken);
5837 var lt = (LocatedToken) $1;
5838 string s = lt.Value;
5840 report.Error (1003, lt.Location, "; expected");
5841 } else if ($3 == null) {
5842 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5843 } else if (lang_version == LanguageVersion.ISO_1){
5844 FeatureIsNotAvailable (lt.Location, "iterators");
5847 current_block.Explicit.RegisterIteratorYield ();
5848 $$ = new Yield ((Expression) $3, lt.Location);
5849 lbag.AddStatement ($$, GetLocation ($2));
5851 | identifier_inside_body BREAK SEMICOLON
5853 var lt = (LocatedToken) $1;
5854 string s = lt.Value;
5856 report.Error (1003, lt.Location, "; expected");
5857 } else if (lang_version == LanguageVersion.ISO_1){
5858 FeatureIsNotAvailable (lt.Location, "iterators");
5861 current_block.ParametersBlock.TopBlock.IsIterator = true;
5862 $$ = new YieldBreak (lt.Location);
5863 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5873 : TRY block catch_clauses
5875 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5877 | TRY block FINALLY block
5879 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5880 lbag.AddStatement ($$, GetLocation ($3));
5882 | TRY block catch_clauses FINALLY block
5884 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5885 lbag.AddStatement ($$, GetLocation ($4));
5889 Error_SyntaxError (1524, yyToken);
5890 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5897 var l = new List<Catch> (2);
5902 | catch_clauses catch_clause
5904 var l = (List<Catch>) $1;
5906 Catch c = (Catch) $2;
5907 if (l [l.Count - 1].IsGeneral) {
5908 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5918 | identifier_inside_body
5924 $$ = new Catch ((Block) $2, GetLocation ($1));
5926 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5928 start_block (GetLocation ($2));
5929 var c = new Catch (current_block, GetLocation ($1));
5930 c.TypeExpression = (FullNamedExpression) $3;
5933 var lt = (LocatedToken) $4;
5934 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5935 current_block.AddLocalName (c.Variable);
5938 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5945 | CATCH open_parens_any error
5947 if (yyToken == Token.CLOSE_PARENS) {
5948 report.Error (1015, lexer.Location,
5949 "A type that derives from `System.Exception', `object', or `string' expected");
5951 Error_SyntaxError (yyToken);
5954 $$ = new Catch (null, GetLocation ($1));
5956 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5958 Error_SyntaxError (yyToken);
5960 // Required otherwise missing block could not be detected because
5961 // start_block is run early
5962 var c = new Catch (null, GetLocation ($1));
5963 c.TypeExpression = (FullNamedExpression) $3;
5966 var lt = (LocatedToken) $4;
5967 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5970 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5979 $$ = new Checked ((Block) $2, GetLocation ($1));
5986 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5993 if (!settings.Unsafe)
5994 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5996 $$ = new Unsafe ((Block) $3, GetLocation ($1));
6001 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
6003 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6004 Warning_EmptyStatement (GetLocation ($5));
6006 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
6007 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6009 | LOCK open_parens_any expression error
6011 Error_SyntaxError (yyToken);
6013 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
6014 lbag.AddStatement ($$, GetLocation ($2));
6019 : FIXED open_parens_any variable_type identifier_inside_body
6021 start_block (GetLocation ($2));
6023 current_block.IsCompilerGenerated = true;
6024 var lt = (LocatedToken) $4;
6025 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
6026 current_block.AddLocalName (li);
6027 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
6029 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
6031 $$ = current_variable;
6032 current_variable = null;
6036 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6037 Warning_EmptyStatement (GetLocation ($10));
6039 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
6040 current_block.AddStatement (f);
6041 $$ = end_block (GetLocation ($8));
6046 : USING open_parens_any variable_type identifier_inside_body
6048 start_block (GetLocation ($2));
6050 current_block.IsCompilerGenerated = true;
6051 var lt = (LocatedToken) $4;
6052 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
6053 current_block.AddLocalName (li);
6054 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
6056 using_initialization CLOSE_PARENS
6058 $$ = current_variable;
6059 current_variable = null;
6063 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6064 Warning_EmptyStatement (GetLocation ($9));
6066 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6067 current_block.AddStatement (u);
6068 $$ = end_block (GetLocation ($7));
6070 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6072 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6073 Warning_EmptyStatement (GetLocation ($5));
6075 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6076 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6078 | USING open_parens_any expression error
6080 Error_SyntaxError (yyToken);
6082 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6083 lbag.AddStatement ($$, GetLocation ($2));
6087 using_initialization
6088 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6091 // It has to be here for the parent to safely restore artificial block
6092 Error_SyntaxError (yyToken);
6096 using_or_fixed_variable_initializer
6099 Error_MissingInitializer (lexer.Location);
6101 | ASSIGN variable_initializer
6103 current_variable.Initializer = (Expression) $2;
6104 $$ = current_variable;
6112 : first_from_clause query_body
6114 lexer.query_parsing = false;
6116 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6118 from.Tail.Next = (Linq.AQueryClause)$2;
6121 current_block.SetEndLocation (lexer.Location);
6122 current_block = current_block.Parent;
6124 | nested_from_clause query_body
6126 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6128 from.Tail.Next = (Linq.AQueryClause)$2;
6131 current_block.SetEndLocation (lexer.Location);
6132 current_block = current_block.Parent;
6135 // Bubble up COMPLETE_COMPLETION productions
6136 | first_from_clause COMPLETE_COMPLETION {
6137 lexer.query_parsing = false;
6140 current_block.SetEndLocation (lexer.Location);
6141 current_block = current_block.Parent;
6143 | nested_from_clause COMPLETE_COMPLETION {
6145 current_block.SetEndLocation (lexer.Location);
6146 current_block = current_block.Parent;
6151 : FROM_FIRST identifier_inside_body IN expression
6153 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6155 var lt = (LocatedToken) $2;
6156 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6157 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6159 | FROM_FIRST type identifier_inside_body IN expression
6161 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6163 var lt = (LocatedToken) $3;
6164 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6165 $$ = new Linq.QueryExpression (
6166 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6167 IdentifierType = (FullNamedExpression)$2
6174 : FROM identifier_inside_body IN expression
6176 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6178 var lt = (LocatedToken) $2;
6179 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6180 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6182 | FROM type identifier_inside_body IN expression
6184 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6186 var lt = (LocatedToken) $3;
6187 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6188 $$ = new Linq.QueryExpression (
6189 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6190 IdentifierType = (FullNamedExpression)$2
6197 : FROM identifier_inside_body IN
6199 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6203 var lt = (LocatedToken) $2;
6204 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6205 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6207 current_block.SetEndLocation (lexer.Location);
6208 current_block = current_block.Parent;
6210 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6212 | FROM type identifier_inside_body IN
6214 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6218 var lt = (LocatedToken) $3;
6219 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6221 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6222 IdentifierType = (FullNamedExpression)$2
6225 current_block.SetEndLocation (lexer.Location);
6226 current_block = current_block.Parent;
6228 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6233 : query_body_clauses select_or_group_clause opt_query_continuation
6235 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6238 head.Next = (Linq.AQueryClause)$3;
6241 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6242 clause.Tail.Next = head;
6248 | select_or_group_clause opt_query_continuation
6250 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6253 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6254 clause.Tail.Next = head;
6260 | query_body_clauses COMPLETE_COMPLETION
6261 | query_body_clauses error
6263 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6268 Error_SyntaxError (yyToken);
6273 select_or_group_clause
6276 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6280 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6282 current_block.SetEndLocation (lexer.Location);
6283 current_block = current_block.Parent;
6287 if (linq_clause_blocks == null)
6288 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6290 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6291 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6295 current_block.SetEndLocation (lexer.Location);
6296 current_block = current_block.Parent;
6298 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6302 var obj = (object[]) $5;
6304 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)obj[0], GetLocation ($1));
6305 lbag.AddLocation ($$, (Location) obj[1]);
6307 current_block.SetEndLocation (lexer.Location);
6308 current_block = current_block.Parent;
6313 : BY expression_or_error
6315 $$ = new object[] { $2, GetLocation ($1) };
6319 Error_SyntaxError (yyToken);
6320 $$ = new object[2] { null, Location.Null };
6326 | query_body_clauses query_body_clause
6328 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6342 : LET identifier_inside_body ASSIGN
6344 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6348 var lt = (LocatedToken) $2;
6349 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6350 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6351 lbag.AddLocation ($$, GetLocation ($3));
6353 current_block.SetEndLocation (lexer.Location);
6354 current_block = current_block.Parent;
6356 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6363 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6367 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6369 current_block.SetEndLocation (lexer.Location);
6370 current_block = current_block.Parent;
6375 : JOIN identifier_inside_body IN
6377 if (linq_clause_blocks == null)
6378 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6380 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6381 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6383 expression_or_error ON
6385 current_block.SetEndLocation (lexer.Location);
6386 current_block = current_block.Parent;
6388 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6389 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6391 expression_or_error EQUALS
6393 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6394 current_block.SetEndLocation (lexer.Location);
6395 current_block = current_block.Parent;
6397 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6399 expression_or_error opt_join_into
6401 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6402 current_block.SetEndLocation (lexer.Location);
6404 var outer_selector = linq_clause_blocks.Pop ();
6405 var block = linq_clause_blocks.Pop ();
6407 var lt = (LocatedToken) $2;
6408 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6409 Linq.RangeVariable into;
6413 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6414 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6417 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6419 var parent = block.Parent;
6420 while (parent is Linq.QueryBlock) {
6421 parent = parent.Parent;
6423 current_block.Parent = parent;
6425 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6427 lt = (LocatedToken) $12;
6428 into = new Linq.RangeVariable (lt.Value, lt.Location);
6430 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6431 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6434 current_block = block.Parent;
6435 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6437 | JOIN type identifier_inside_body IN
6439 if (linq_clause_blocks == null)
6440 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6442 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6443 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6445 expression_or_error ON
6447 current_block.SetEndLocation (lexer.Location);
6448 current_block = current_block.Parent;
6450 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6451 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6453 expression_or_error EQUALS
6455 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6456 current_block.SetEndLocation (lexer.Location);
6457 current_block = current_block.Parent;
6459 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6461 expression_or_error opt_join_into
6463 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6464 current_block.SetEndLocation (lexer.Location);
6466 var outer_selector = linq_clause_blocks.Pop ();
6467 var block = linq_clause_blocks.Pop ();
6469 var lt = (LocatedToken) $3;
6470 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6471 Linq.RangeVariable into;
6475 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6476 IdentifierType = (FullNamedExpression)$2
6480 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6482 var parent = block.Parent;
6483 while (parent is Linq.QueryBlock) {
6484 parent = parent.Parent;
6486 current_block.Parent = parent;
6488 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6490 lt = (LocatedToken) $13;
6491 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6493 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6494 IdentifierType = (FullNamedExpression)$2
6498 current_block = block.Parent;
6499 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6505 | INTO identifier_inside_body
6514 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6518 current_block.SetEndLocation (lexer.Location);
6519 current_block = current_block.Parent;
6529 current_block.SetEndLocation (lexer.Location);
6530 current_block = current_block.Parent;
6532 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6536 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6543 | orderings_then_by COMMA
6545 current_block.SetEndLocation (lexer.Location);
6546 current_block = current_block.Parent;
6548 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6552 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6560 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6562 | expression ASCENDING
6564 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6565 lbag.AddLocation ($$, GetLocation ($2));
6567 | expression DESCENDING
6569 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6570 lbag.AddLocation ($$, GetLocation ($2));
6577 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6579 | expression ASCENDING
6581 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6582 lbag.AddLocation ($$, GetLocation ($2));
6584 | expression DESCENDING
6586 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6587 lbag.AddLocation ($$, GetLocation ($2));
6592 opt_query_continuation
6594 | INTO identifier_inside_body
6596 // query continuation block is not linked with query block but with block
6597 // before. This means each query can use same range variable names for
6598 // different identifiers.
6600 current_block.SetEndLocation (GetLocation ($1));
6601 current_block = current_block.Parent;
6603 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6605 if (linq_clause_blocks == null)
6606 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6608 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6612 var current_block = linq_clause_blocks.Pop ();
6613 var lt = (LocatedToken) $2;
6614 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6615 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6616 next = (Linq.AQueryClause)$4
6622 // Support for using the compiler as an interactive parser
6624 // The INTERACTIVE_PARSER token is first sent to parse our
6625 // productions; If the result is a Statement, the parsing
6626 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6627 // to setup the blocks in advance.
6629 // This setup is here so that in the future we can add
6630 // support for other constructs (type parsing, namespaces, etc)
6631 // that do not require a block to be setup in advance
6635 : EVAL_STATEMENT_PARSER EOF
6636 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6637 | EVAL_STATEMENT_PARSER
6639 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6641 // (ref object retval)
6642 Parameter [] mpar = new Parameter [1];
6643 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6645 ParametersCompiled pars = new ParametersCompiled (mpar);
6646 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6647 if (settings.Unsafe)
6648 mods |= Modifiers.UNSAFE;
6650 current_local_parameters = pars;
6651 Method method = new Method (
6653 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6655 new MemberName ("Host"),
6657 null /* attributes */);
6659 current_type.AddMember (method);
6661 oob_stack.Push (method);
6662 ++lexer.parsing_block;
6663 start_block (lexer.Location);
6665 interactive_statement_list opt_COMPLETE_COMPLETION
6667 --lexer.parsing_block;
6668 Method method = (Method) oob_stack.Pop ();
6670 method.Block = (ToplevelBlock) end_block(lexer.Location);
6672 InteractiveResult = (Class) pop_current_class ();
6673 current_local_parameters = null;
6675 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6678 interactive_compilation_unit
6679 : opt_extern_alias_directives opt_using_directives
6680 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6683 opt_COMPLETE_COMPLETION
6685 | COMPLETE_COMPLETION
6688 close_brace_or_complete_completion
6690 | COMPLETE_COMPLETION
6694 // XML documentation code references micro parser
6696 documentation_parsing
6699 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6704 : doc_type_declaration_name opt_doc_method_sig
6706 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6708 | builtin_types opt_doc_method_sig
6710 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6711 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6714 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6716 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6717 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6718 var lt = (LocatedToken) $3;
6719 $$ = new MemberName (lt.Value);
6721 | doc_type_declaration_name DOT THIS
6723 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6725 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6727 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6729 opt_doc_parameters CLOSE_BRACKET
6731 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6732 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6734 | EXPLICIT OPERATOR type opt_doc_method_sig
6736 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6737 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6738 module.DocumentationBuilder.ParsedParameters = p;
6739 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6742 | IMPLICIT OPERATOR type opt_doc_method_sig
6744 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6745 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6746 module.DocumentationBuilder.ParsedParameters = p;
6747 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6750 | OPERATOR overloadable_operator opt_doc_method_sig
6752 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6753 module.DocumentationBuilder.ParsedParameters = p;
6754 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6759 doc_type_declaration_name
6760 : type_declaration_name
6761 | doc_type_declaration_name DOT type_declaration_name
6763 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6771 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6773 opt_doc_parameters CLOSE_PARENS
6782 $$ = new List<DocumentationParameter> (0);
6790 var parameters = new List<DocumentationParameter> ();
6791 parameters.Add ((DocumentationParameter) $1);
6794 | doc_parameters COMMA doc_parameter
6796 var parameters = $1 as List<DocumentationParameter>;
6797 parameters.Add ((DocumentationParameter) $3);
6803 : opt_parameter_modifier parameter_type
6806 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6808 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6815 // A class used to hold info about an operator declarator
6817 class OperatorDeclaration {
6818 public readonly Operator.OpType optype;
6819 public readonly FullNamedExpression ret_type;
6820 public readonly Location location;
6822 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6825 this.ret_type = ret_type;
6826 this.location = location;
6830 void Error_ExpectingTypeName (Expression expr)
6832 if (expr is Invocation){
6833 report.Error (1002, expr.Location, "Expecting `;'");
6835 expr.Error_InvalidExpressionStatement (report);
6839 void Error_ParameterModifierNotValid (string modifier, Location loc)
6841 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6845 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6847 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6848 Parameter.GetModifierSignature (mod));
6851 void Error_TypeExpected (Location loc)
6853 report.Error (1031, loc, "Type expected");
6856 void Error_UnsafeCodeNotAllowed (Location loc)
6858 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6861 void Warning_EmptyStatement (Location loc)
6863 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6866 void Error_NamedArgumentExpected (NamedArgument a)
6868 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6871 void Error_MissingInitializer (Location loc)
6873 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6876 object Error_AwaitAsIdentifier (object token)
6879 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6880 return new LocatedToken ("await", GetLocation (token));
6886 void push_current_container (TypeDefinition tc, object partial_token)
6888 if (module.Evaluator != null){
6889 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6893 undo.AddTypeContainer (current_container, tc);
6896 if (partial_token != null)
6897 current_container.AddPartial (tc);
6899 current_container.AddTypeContainer (tc);
6901 ++lexer.parsing_declaration;
6902 current_container = tc;
6906 TypeContainer pop_current_class ()
6908 var retval = current_container;
6910 current_container = current_container.Parent;
6911 current_type = current_type.Parent as TypeDefinition;
6916 [System.Diagnostics.Conditional ("FULL_AST")]
6917 void StoreModifierLocation (object token, Location loc)
6922 if (mod_locations == null)
6923 mod_locations = new List<Tuple<Modifiers, Location>> ();
6925 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6928 [System.Diagnostics.Conditional ("FULL_AST")]
6929 void PushLocation (Location loc)
6931 if (location_stack == null)
6932 location_stack = new Stack<Location> ();
6934 location_stack.Push (loc);
6937 Location PopLocation ()
6939 if (location_stack == null)
6940 return Location.Null;
6942 return location_stack.Pop ();
6945 string CheckAttributeTarget (string a, Location l)
6948 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6952 report.Warning (658, 1, l,
6953 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6954 return string.Empty;
6957 static bool IsUnaryOperator (Operator.OpType op)
6961 case Operator.OpType.LogicalNot:
6962 case Operator.OpType.OnesComplement:
6963 case Operator.OpType.Increment:
6964 case Operator.OpType.Decrement:
6965 case Operator.OpType.True:
6966 case Operator.OpType.False:
6967 case Operator.OpType.UnaryPlus:
6968 case Operator.OpType.UnaryNegation:
6974 void syntax_error (Location l, string msg)
6976 report.Error (1003, l, "Syntax error, " + msg);
6981 public Tokenizer Lexer {
6987 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6988 : this (reader, file, file.Compiler.Report, session)
6992 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6995 current_container = current_namespace = file;
6997 this.module = file.Module;
6998 this.compiler = file.Compiler;
6999 this.settings = compiler.Settings;
7000 this.report = report;
7002 lang_version = settings.Version;
7003 yacc_verbose_flag = settings.VerboseParserFlag;
7004 doc_support = settings.DocumentationFile != null;
7005 lexer = new Tokenizer (reader, file, session);
7006 oob_stack = new Stack<object> ();
7007 lbag = session.LocationsBag;
7008 use_global_stacks = session.UseJayGlobalArrays;
7009 parameters_bucket = session.ParametersStack;
7012 public void parse ()
7014 eof_token = Token.EOF;
7017 if (yacc_verbose_flag > 1)
7018 yyparse (lexer, new yydebug.yyDebugSimple ());
7022 Tokenizer tokenizer = lexer as Tokenizer;
7023 tokenizer.cleanup ();
7024 } catch (Exception e){
7025 if (e is yyParser.yyUnexpectedEof) {
7026 Error_SyntaxError (yyToken);
7027 UnexpectedEOF = true;
7031 if (e is yyParser.yyException) {
7032 if (report.Errors == 0)
7033 report.Error (-25, lexer.Location, "Parsing error");
7035 // Used by compiler-tester to test internal errors
7036 if (yacc_verbose_flag > 0 || e is FatalException)
7039 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
7044 void CheckToken (int error, int yyToken, string msg, Location loc)
7046 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
7047 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
7049 report.Error (error, loc, msg);
7052 string ConsumeStoredComment ()
7054 string s = tmpComment;
7056 Lexer.doc_state = XmlCommentState.Allowed;
7060 void FeatureIsNotAvailable (Location loc, string feature)
7062 report.FeatureIsNotAvailable (compiler, loc, feature);
7065 Location GetLocation (object obj)
7067 var lt = obj as LocatedToken;
7071 var mn = obj as MemberName;
7075 var expr = obj as Expression;
7077 return expr.Location;
7079 return lexer.Location;
7082 void start_block (Location loc)
7084 if (current_block == null) {
7085 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
7086 parsing_anonymous_method = false;
7087 } else if (parsing_anonymous_method) {
7088 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
7089 parsing_anonymous_method = false;
7091 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7096 end_block (Location loc)
7098 Block retval = current_block.Explicit;
7099 retval.SetEndLocation (loc);
7100 current_block = retval.Parent;
7104 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7106 oob_stack.Push (current_anonymous_method);
7107 oob_stack.Push (current_local_parameters);
7108 oob_stack.Push (current_variable);
7109 oob_stack.Push (async_block);
7111 current_local_parameters = parameters;
7113 if (lang_version <= LanguageVersion.ISO_2)
7114 FeatureIsNotAvailable (loc, "lambda expressions");
7116 current_anonymous_method = new LambdaExpression (loc);
7118 if (lang_version == LanguageVersion.ISO_1)
7119 FeatureIsNotAvailable (loc, "anonymous methods");
7121 current_anonymous_method = new AnonymousMethodExpression (loc);
7124 async_block = isAsync;
7125 // Force the next block to be created as a ToplevelBlock
7126 parsing_anonymous_method = true;
7130 * Completes the anonymous method processing, if lambda_expr is null, this
7131 * means that we have a Statement instead of an Expression embedded
7133 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7135 AnonymousMethodExpression retval;
7138 anon_block.IsAsync = true;
7140 current_anonymous_method.Block = anon_block;
7141 retval = current_anonymous_method;
7143 async_block = (bool) oob_stack.Pop ();
7144 current_variable = (BlockVariable) oob_stack.Pop ();
7145 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7146 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7151 void Error_SyntaxError (int token)
7153 Error_SyntaxError (0, token);
7156 void Error_SyntaxError (int error_code, int token)
7158 Error_SyntaxError (error_code, token, "Unexpected symbol");
7161 void Error_SyntaxError (int error_code, int token, string msg)
7163 Lexer.CompleteOnEOF = false;
7165 // An error message has been reported by tokenizer
7166 if (token == Token.ERROR)
7169 // Avoid duplicit error message after unterminated string literals
7170 if (token == Token.LITERAL && lexer.Location.Column == 0)
7173 string symbol = GetSymbolName (token);
7174 string expecting = GetExpecting ();
7175 var loc = lexer.Location - symbol.Length;
7177 if (error_code == 0) {
7178 if (expecting == "`identifier'") {
7179 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7180 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7185 expecting = "identifier";
7186 } else if (expecting == "`)'") {
7193 if (string.IsNullOrEmpty (expecting))
7194 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7196 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7199 string GetExpecting ()
7201 int [] tokens = yyExpectingTokens (yyExpectingState);
7202 var names = new List<string> (tokens.Length);
7203 bool has_type = false;
7204 bool has_identifier = false;
7205 for (int i = 0; i < tokens.Length; i++){
7206 int token = tokens [i];
7207 has_identifier |= token == Token.IDENTIFIER;
7209 string name = GetTokenName (token);
7210 if (name == "<internal>")
7213 has_type |= name == "type";
7214 if (names.Contains (name))
7221 // Too many tokens to enumerate
7223 if (names.Count > 8)
7226 if (has_type && has_identifier)
7227 names.Remove ("identifier");
7229 if (names.Count == 1)
7230 return "`" + GetTokenName (tokens [0]) + "'";
7232 StringBuilder sb = new StringBuilder ();
7234 int count = names.Count;
7235 for (int i = 0; i < count; i++){
7236 bool last = i + 1 == count;
7240 sb.Append (names [i]);
7241 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7243 return sb.ToString ();
7247 string GetSymbolName (int token)
7251 return ((Constant)lexer.Value).GetValue ().ToString ();
7252 case Token.IDENTIFIER:
7253 return ((LocatedToken)lexer.Value).Value;
7295 case Token.BITWISE_AND:
7297 case Token.BITWISE_OR:
7311 case Token.OP_SHIFT_LEFT:
7313 case Token.OP_SHIFT_RIGHT:
7333 case Token.OP_COALESCING:
7335 case Token.OP_MULT_ASSIGN:
7337 case Token.OP_DIV_ASSIGN:
7339 case Token.OP_MOD_ASSIGN:
7341 case Token.OP_ADD_ASSIGN:
7343 case Token.OP_SUB_ASSIGN:
7345 case Token.OP_SHIFT_LEFT_ASSIGN:
7347 case Token.OP_SHIFT_RIGHT_ASSIGN:
7349 case Token.OP_AND_ASSIGN:
7351 case Token.OP_XOR_ASSIGN:
7353 case Token.OP_OR_ASSIGN:
7357 return GetTokenName (token);
7360 static string GetTokenName (int token)
7363 case Token.ABSTRACT:
7385 case Token.CONTINUE:
7389 case Token.DELEGATE:
7399 case Token.EXPLICIT:
7402 case Token.EXTERN_ALIAS:
7418 case Token.IMPLICIT:
7422 case Token.INTERFACE:
7424 case Token.INTERNAL:
7430 case Token.NAMESPACE:
7436 case Token.OPERATOR:
7440 case Token.OVERRIDE:
7446 case Token.PROTECTED:
7450 case Token.READONLY:
7462 case Token.STACKALLOC:
7463 return "stackalloc";
7480 case Token.UNCHECKED:
7488 case Token.VOLATILE:
7496 case Token.REFVALUE:
7497 return "__refvalue";
7507 case Token.FROM_FIRST:
7525 case Token.ASCENDING:
7527 case Token.DESCENDING:
7528 return "descending";
7535 case Token.OPEN_BRACE:
7537 case Token.CLOSE_BRACE:
7539 case Token.OPEN_BRACKET:
7540 case Token.OPEN_BRACKET_EXPR:
7542 case Token.CLOSE_BRACKET:
7544 case Token.OPEN_PARENS_CAST:
7545 case Token.OPEN_PARENS_LAMBDA:
7546 case Token.OPEN_PARENS:
7548 case Token.CLOSE_PARENS:
7554 case Token.DEFAULT_COLON:
7558 case Token.SEMICOLON:
7569 case Token.BITWISE_AND:
7570 case Token.BITWISE_OR:
7577 case Token.OP_SHIFT_LEFT:
7578 case Token.OP_SHIFT_RIGHT:
7586 case Token.OP_COALESCING:
7587 case Token.OP_MULT_ASSIGN:
7588 case Token.OP_DIV_ASSIGN:
7589 case Token.OP_MOD_ASSIGN:
7590 case Token.OP_ADD_ASSIGN:
7591 case Token.OP_SUB_ASSIGN:
7592 case Token.OP_SHIFT_LEFT_ASSIGN:
7593 case Token.OP_SHIFT_RIGHT_ASSIGN:
7594 case Token.OP_AND_ASSIGN:
7595 case Token.OP_XOR_ASSIGN:
7596 case Token.OP_OR_ASSIGN:
7597 return "<operator>";
7619 case Token.OP_GENERICS_LT:
7620 case Token.GENERIC_DIMENSION:
7622 case Token.OP_GENERICS_GT:
7625 case Token.INTERR_NULLABLE:
7627 case Token.DOUBLE_COLON:
7631 case Token.IDENTIFIER:
7633 return "identifier";
7636 return "end-of-file";
7638 // All of these are internal.
7641 case Token.FIRST_KEYWORD:
7642 case Token.EVAL_COMPILATION_UNIT_PARSER:
7643 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7644 case Token.EVAL_STATEMENT_PARSER:
7645 case Token.LAST_KEYWORD:
7646 case Token.GENERATE_COMPLETION:
7647 case Token.COMPLETE_COMPLETION:
7648 return "<internal>";
7650 // A bit more robust.
7652 return yyNames [token];