3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnome.org)
6 // Ravi Pratap (ravi@ximian.com)
7 // Marek Safar (marek.safar@gmail.com)
9 // Dual Licensed under the terms of the GNU GPL and the MIT X11 license
11 // (C) 2001 Ximian, Inc (http://www.ximian.com)
12 // (C) 2004-2011 Novell, Inc
13 // Copyright 2011-2012 Xamarin Inc.
19 using System.Collections.Generic;
26 public class CSharpParser
29 enum ParameterModifierType
36 DefaultValue = 1 << 6,
38 All = Ref | Out | This | Params | Arglist | DefaultValue
41 static readonly object ModifierNone = 0;
43 NamespaceContainer current_namespace;
44 TypeContainer current_container;
45 TypeDefinition current_type;
46 PropertyBase current_property;
47 EventProperty current_event;
48 EventField current_event_field;
49 FieldBase current_field;
52 /// Current block is used to add statements as we find
57 BlockVariableDeclaration current_variable;
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
77 /// An out-of-band stack.
79 Stack<object> oob_stack;
82 /// Controls the verbosity of the errors produced by the parser
84 int yacc_verbose_flag;
87 /// Used by the interactive shell, flags whether EOF was reached
88 /// and an error was produced
90 public bool UnexpectedEOF;
95 readonly CompilationSourceFile file;
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 ParameterModifierType valid_param_mod;
109 bool default_parameter_used;
111 /// When using the interactive parser, this holds the
112 /// resulting expression
113 public Class InteractiveResult;
116 // Keeps track of global data changes to undo on parser error
120 Stack<Linq.QueryBlock> linq_clause_blocks;
122 ModuleContainer module;
124 readonly CompilerContext compiler;
125 readonly LanguageVersion lang_version;
126 readonly bool doc_support;
127 readonly CompilerSettings settings;
128 readonly Report report;
131 // Instead of allocating carrier array everytime we
132 // share the bucket for very common constructs which can never
135 List<Parameter> parameters_bucket;
138 // Full AST support members
141 List<Tuple<Modifiers, Location>> mod_locations;
145 %token NONE /* This token is never returned by our lexer */
146 %token ERROR // This is used not by the parser, but by the tokenizer.
150 *These are the C# keywords
249 %token INTERR_NULLABLE
257 /* C# keywords which are not really keywords */
263 /* C# single character operators/punctuation. */
291 /* C# multi-character operators. */
296 %token OP_SHIFT_RIGHT
303 %token OP_MULT_ASSIGN
308 %token OP_SHIFT_LEFT_ASSIGN
309 %token OP_SHIFT_RIGHT_ASSIGN
316 /* Generics <,> tokens */
317 %token OP_GENERICS_LT
318 %token OP_GENERICS_LT_DECL
319 %token OP_GENERICS_GT
324 %token OPEN_PARENS_LAMBDA
325 %token OPEN_PARENS_CAST
326 %token GENERIC_DIMENSION
328 %token OPEN_BRACKET_EXPR
330 // Make the parser go into eval mode parsing (statements and compilation units).
331 %token EVAL_STATEMENT_PARSER
332 %token EVAL_COMPILATION_UNIT_PARSER
333 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
338 // This token is generated to trigger the completion engine at this point
340 %token GENERATE_COMPLETION
343 // This token is return repeatedly after the first GENERATE_COMPLETION
344 // token is produced and before the final EOF
346 %token COMPLETE_COMPLETION
348 /* Add precedence rules to solve dangling else s/r conflict */
352 /* Define the operator tokens and their precedences */
360 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
362 %left STAR DIV PERCENT
363 %right BANG CARRET UMINUS
364 %nonassoc OP_INC OP_DEC
366 %left OPEN_BRACKET OPEN_BRACE
369 %start compilation_unit
373 : outer_declaration opt_EOF
375 Lexer.check_incorrect_doc_comment ();
377 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
378 | documentation_parsing
382 : opt_extern_alias_directives opt_using_directives
383 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations opt_attributes
386 Attributes attrs = (Attributes) $4;
387 report.Error (1730, attrs.Attrs [0].Location,
388 "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
390 current_namespace.UnattachedAttributes = attrs;
393 | opt_extern_alias_directives opt_using_directives attribute_sections
395 module.AddAttributes ((Attributes) $3, current_namespace);
399 if (yyToken == Token.EXTERN_ALIAS)
400 report.Error (439, lexer.Location, "An extern alias declaration must precede all other elements");
402 Error_SyntaxError (yyToken);
411 extern_alias_directives
412 : extern_alias_directive
413 | extern_alias_directives extern_alias_directive
416 extern_alias_directive
417 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
419 var lt = (Tokenizer.LocatedToken) $2;
422 syntax_error (lt.Location, "`alias' expected");
424 if (lang_version == LanguageVersion.ISO_1)
425 FeatureIsNotAvailable (lt.Location, "external alias");
427 lt = (Tokenizer.LocatedToken) $3;
428 if (lt.Value == QualifiedAliasMember.GlobalAlias) {
429 RootNamespace.Error_GlobalNamespaceRedefined (report, lt.Location);
432 var na = new UsingExternAlias (new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1));
433 current_namespace.AddUsing (na);
435 lbag.AddLocation (na, GetLocation ($2), GetLocation ($4));
440 Error_SyntaxError (yyToken);
446 | using_directives using_directive
453 Lexer.doc_state = XmlCommentState.Allowed;
458 : USING namespace_or_type_expr SEMICOLON
460 var un = new UsingNamespace ((ATypeNameExpression) $2, GetLocation ($1));
461 current_namespace.AddUsing (un);
463 lbag.AddLocation (un, GetLocation ($3));
465 | USING IDENTIFIER ASSIGN namespace_or_type_expr SEMICOLON
467 var lt = (Tokenizer.LocatedToken) $2;
468 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
469 report.Warning (440, 2, lt.Location,
470 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
473 var un = new UsingAliasNamespace (new SimpleMemberName (lt.Value, lt.Location), (ATypeNameExpression) $4, GetLocation ($1));
474 current_namespace.AddUsing (un);
476 lbag.AddLocation (un, GetLocation ($3), GetLocation ($5));
480 Error_SyntaxError (yyToken);
486 // Strictly speaking, namespaces don't have attributes but
487 // we parse global attributes along with namespace declarations and then
490 namespace_declaration
491 : opt_attributes NAMESPACE namespace_name
493 Attributes attrs = (Attributes) $1;
494 var name = (MemberName) $3;
496 bool valid_global_attrs = true;
497 if ((current_namespace.DeclarationFound || current_namespace != file)) {
498 valid_global_attrs = false;
500 foreach (var a in attrs.Attrs) {
501 if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module")
504 valid_global_attrs = false;
509 if (!valid_global_attrs)
510 report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
513 module.AddAttributes (attrs, current_namespace);
515 var ns = new NamespaceContainer (name, current_namespace);
516 current_namespace.AddTypeContainer (ns);
517 current_container = current_namespace = ns;
522 Lexer.doc_state = XmlCommentState.Allowed;
524 opt_extern_alias_directives opt_using_directives opt_namespace_or_type_declarations CLOSE_BRACE opt_semicolon_error
527 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10), GetLocation ($11));
529 lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($5), GetLocation ($10));
531 current_container = current_namespace = current_namespace.Parent;
533 | opt_attributes NAMESPACE namespace_name
535 report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken));
537 var name = (MemberName) $3;
538 var ns = new NamespaceContainer (name, current_namespace);
539 lbag.AddLocation (ns, GetLocation ($2));
540 current_namespace.AddTypeContainer (ns);
549 Error_SyntaxError (yyToken);
557 var lt = (Tokenizer.LocatedToken) $1;
558 $$ = new MemberName (lt.Value, lt.Location);
560 | namespace_name DOT IDENTIFIER
562 var lt = (Tokenizer.LocatedToken) $3;
563 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
567 Error_SyntaxError (yyToken);
568 $$ = new MemberName ("<invalid>", lexer.Location);
587 opt_extern_alias_directives
589 | extern_alias_directives
592 opt_namespace_or_type_declarations
594 | namespace_or_type_declarations
597 namespace_or_type_declarations
598 : namespace_or_type_declaration
599 | namespace_or_type_declarations namespace_or_type_declaration
602 namespace_or_type_declaration
606 TypeContainer ds = (TypeContainer)$1;
608 if ((ds.ModFlags & (Modifiers.PRIVATE | Modifiers.PROTECTED)) != 0){
609 report.Error (1527, ds.Location,
610 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
613 // Here is a trick, for explicit attributes we don't know where they belong to until
614 // we parse succeeding declaration hence we parse them as normal and re-attach them
615 // when we know whether they are global (assembly:, module:) or local (type:).
616 if (ds.OptAttributes != null) {
617 ds.OptAttributes.ConvertGlobalAttributes (ds, current_namespace, !current_namespace.DeclarationFound && current_namespace == file);
620 current_namespace.DeclarationFound = true;
622 | namespace_declaration
624 current_namespace.DeclarationFound = true;
626 | attribute_sections CLOSE_BRACE {
627 current_namespace.UnattachedAttributes = (Attributes) $1;
628 report.Error (1518, lexer.Location, "Attributes must be attached to class, delegate, enum, interface or struct");
636 | interface_declaration
638 | delegate_declaration
640 // Enable this when we have handled all errors, because this acts as a generic fallback
643 // Console.WriteLine ("Token=" + yyToken);
644 // report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
660 var sect = (List<Attribute>) $1;
661 $$ = new Attributes (sect);
663 | attribute_sections attribute_section
665 Attributes attrs = $1 as Attributes;
666 var sect = (List<Attribute>) $2;
668 attrs = new Attributes (sect);
670 attrs.AddAttributes (sect);
678 lexer.parsing_attribute_section = true;
680 attribute_section_cont
682 lexer.parsing_attribute_section = false;
687 attribute_section_cont
688 : attribute_target COLON
690 current_attr_target = (string) $1;
691 if (current_attr_target == "assembly" || current_attr_target == "module") {
692 Lexer.check_incorrect_doc_comment ();
695 attribute_list opt_comma CLOSE_BRACKET
697 // when attribute target is invalid
698 if (current_attr_target == string.Empty)
699 $$ = new List<Attribute> (0);
703 current_attr_target = null;
704 lexer.parsing_attribute_section = false;
706 | attribute_list opt_comma CLOSE_BRACKET
715 var lt = (Tokenizer.LocatedToken) $1;
716 $$ = CheckAttributeTarget (lt.Value, lt.Location);
718 | EVENT { $$ = "event"; }
719 | RETURN { $$ = "return"; }
722 if (yyToken == Token.IDENTIFIER) {
723 Error_SyntaxError (yyToken);
726 string name = GetTokenName (yyToken);
727 $$ = CheckAttributeTarget (name, GetLocation ($1));
735 $$ = new List<Attribute> (4) { (Attribute) $1 };
737 | attribute_list COMMA attribute
739 var attrs = (List<Attribute>) $1;
740 attrs.Add ((Attribute) $3);
749 ++lexer.parsing_block;
751 opt_attribute_arguments
753 --lexer.parsing_block;
755 var tne = (ATypeNameExpression) $1;
756 if (tne.HasTypeArguments) {
757 report.Error (404, tne.Location, "Attributes cannot be generic");
760 $$ = new Attribute (current_attr_target, tne, (Arguments[]) $3, GetLocation ($1), lexer.IsEscapedIdentifier (tne));
765 : namespace_or_type_expr
768 opt_attribute_arguments
769 : /* empty */ { $$ = null; }
770 | OPEN_PARENS attribute_arguments CLOSE_PARENS
778 : /* empty */ { $$ = null; }
779 | positional_or_named_argument
781 Arguments a = new Arguments (4);
782 a.Add ((Argument) $1);
783 $$ = new Arguments [] { a, null };
785 | named_attribute_argument
787 Arguments a = new Arguments (4);
788 a.Add ((Argument) $1);
789 $$ = new Arguments [] { null, a };
791 | attribute_arguments COMMA positional_or_named_argument
793 Arguments[] o = (Arguments[]) $1;
795 report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
796 o [0] = new Arguments (4);
799 Arguments args = ((Arguments) o [0]);
800 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
801 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
803 args.Add ((Argument) $3);
805 | attribute_arguments COMMA named_attribute_argument
807 Arguments[] o = (Arguments[]) $1;
809 o [1] = new Arguments (4);
812 ((Arguments) o [1]).Add ((Argument) $3);
816 positional_or_named_argument
819 $$ = new Argument ((Expression) $1);
824 named_attribute_argument
827 ++lexer.parsing_block;
831 --lexer.parsing_block;
832 var lt = (Tokenizer.LocatedToken) $1;
833 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
834 lbag.AddLocation ($$, GetLocation($2));
839 : identifier_inside_body COLON opt_named_modifier expression
841 if (lang_version <= LanguageVersion.V_3)
842 FeatureIsNotAvailable (GetLocation ($1), "named argument");
844 // Avoid boxing in common case (no modifier)
845 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
847 var lt = (Tokenizer.LocatedToken) $1;
848 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
849 lbag.AddLocation ($$, GetLocation($2));
854 : /* empty */ { $$ = null; }
857 $$ = Argument.AType.Ref;
861 $$ = Argument.AType.Out;
865 opt_class_member_declarations
867 | class_member_declarations
870 class_member_declarations
871 : class_member_declaration
873 lexer.parsing_modifiers = true;
875 | class_member_declarations class_member_declaration
877 lexer.parsing_modifiers = true;
881 class_member_declaration
882 : constant_declaration
885 | property_declaration
887 | indexer_declaration
888 | operator_declaration
889 | constructor_declaration
890 | destructor_declaration
892 | attributes_without_members
895 report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
896 GetSymbolName (yyToken));
898 lexer.parsing_generic_declaration = false;
909 type_declaration_name
911 lexer.ConstraintsParsing = true;
912 push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
915 opt_type_parameter_constraints_clauses
917 lexer.ConstraintsParsing = false;
920 current_container.SetConstraints ((List<Constraints>) $9);
923 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
925 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
927 lexer.parsing_modifiers = true;
932 Lexer.doc_state = XmlCommentState.Allowed;
934 opt_class_member_declarations CLOSE_BRACE
936 --lexer.parsing_declaration;
938 Lexer.doc_state = XmlCommentState.Allowed;
942 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
943 $$ = pop_current_class ();
945 | opt_attributes opt_modifiers opt_partial STRUCT error
947 Error_SyntaxError (yyToken);
954 CONST type IDENTIFIER
956 var lt = (Tokenizer.LocatedToken) $5;
957 var mod = (Modifiers) $2;
958 current_field = new Const (current_type, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
959 current_type.AddMember (current_field);
961 if ((mod & Modifiers.STATIC) != 0) {
962 report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
967 constant_initializer opt_constant_declarators SEMICOLON
970 current_field.DocComment = Lexer.consume_doc_comment ();
971 Lexer.doc_state = XmlCommentState.Allowed;
974 current_field.Initializer = (ConstInitializer) $7;
975 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
976 current_field = null;
982 Error_SyntaxError (yyToken);
984 current_type.AddMember (new Const (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
988 opt_constant_declarators
990 | constant_declarators
994 : constant_declarator
996 current_field.AddDeclarator ((FieldDeclarator) $1);
998 | constant_declarators constant_declarator
1000 current_field.AddDeclarator ((FieldDeclarator) $2);
1005 : COMMA IDENTIFIER constant_initializer
1007 var lt = (Tokenizer.LocatedToken) $2;
1008 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1009 lbag.AddLocation ($$, GetLocation ($1));
1013 constant_initializer
1016 ++lexer.parsing_block;
1018 constant_initializer_expr
1020 --lexer.parsing_block;
1021 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1025 report.Error (145, lexer.Location, "A const field requires a value to be provided");
1030 constant_initializer_expr
1031 : constant_expression
1038 member_type IDENTIFIER
1040 lexer.parsing_generic_declaration = false;
1042 FullNamedExpression type = (FullNamedExpression) $3;
1043 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1044 report.Error (670, GetLocation ($3), "Fields cannot have void type");
1046 var lt = (Tokenizer.LocatedToken) $4;
1047 current_field = new Field (current_type, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1048 current_type.AddField (current_field);
1051 opt_field_initializer
1052 opt_field_declarators
1056 current_field.DocComment = Lexer.consume_doc_comment ();
1057 Lexer.doc_state = XmlCommentState.Allowed;
1060 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1062 current_field = null;
1066 FIXED simple_type IDENTIFIER
1068 if (lang_version < LanguageVersion.ISO_2)
1069 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1071 var lt = (Tokenizer.LocatedToken) $5;
1072 current_field = new FixedField (current_type, (FullNamedExpression) $4, (Modifiers) $2,
1073 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1075 current_type.AddField (current_field);
1077 fixed_field_size opt_fixed_field_declarators SEMICOLON
1080 current_field.DocComment = Lexer.consume_doc_comment ();
1081 Lexer.doc_state = XmlCommentState.Allowed;
1084 current_field.Initializer = (ConstInitializer) $7;
1085 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1087 current_field = null;
1091 FIXED simple_type error
1094 report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1098 opt_field_initializer
1102 ++lexer.parsing_block;
1103 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1104 start_block (GetLocation ($1));
1106 variable_initializer
1108 --lexer.parsing_block;
1109 current_field.Initializer = (Expression) $3;
1110 end_block (lexer.Location);
1111 current_local_parameters = null;
1115 opt_field_declarators
1123 current_field.AddDeclarator ((FieldDeclarator) $1);
1125 | field_declarators field_declarator
1127 current_field.AddDeclarator ((FieldDeclarator) $2);
1134 var lt = (Tokenizer.LocatedToken) $2;
1135 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1136 lbag.AddLocation ($$, GetLocation ($1));
1138 | COMMA IDENTIFIER ASSIGN
1140 ++lexer.parsing_block;
1142 variable_initializer
1144 --lexer.parsing_block;
1145 var lt = (Tokenizer.LocatedToken) $2;
1146 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1147 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1151 opt_fixed_field_declarators
1153 | fixed_field_declarators
1156 fixed_field_declarators
1157 : fixed_field_declarator
1159 current_field.AddDeclarator ((FieldDeclarator) $1);
1161 | fixed_field_declarators fixed_field_declarator
1163 current_field.AddDeclarator ((FieldDeclarator) $2);
1167 fixed_field_declarator
1168 : COMMA IDENTIFIER fixed_field_size
1170 var lt = (Tokenizer.LocatedToken) $2;
1171 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1172 lbag.AddLocation ($$, GetLocation ($1));
1179 ++lexer.parsing_block;
1181 expression CLOSE_BRACKET
1183 --lexer.parsing_block;
1184 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1185 lbag.AddLocation ($$, GetLocation ($4));
1187 | OPEN_BRACKET error
1189 report.Error (443, lexer.Location, "Value or constant expected");
1194 variable_initializer
1199 // It has to be here for the parent to safely restore artificial block
1200 Error_SyntaxError (yyToken);
1209 Lexer.doc_state = XmlCommentState.NotAllowed;
1211 // Was added earlier in the case of body being eof for full ast
1215 Method method = (Method) $1;
1216 method.Block = (ToplevelBlock) $3;
1217 async_block = false;
1219 if (method.Block == null) {
1220 method.ParameterInfo.CheckParameters (method);
1222 if ((method.ModFlags & Modifiers.ASYNC) != 0) {
1223 report.Error (1994, method.Location, "`{0}': The async modifier can only be used with methods that have a body",
1224 method.GetSignatureForError ());
1227 if (current_container.Kind == MemberKind.Interface) {
1228 report.Error (531, method.Location, "`{0}': interface members cannot have a definition",
1229 method.GetSignatureForError ());
1233 current_local_parameters = null;
1236 Lexer.doc_state = XmlCommentState.Allowed;
1244 method_declaration_name OPEN_PARENS
1246 valid_param_mod = ParameterModifierType.All;
1248 opt_formal_parameter_list CLOSE_PARENS
1250 valid_param_mod = 0;
1251 MemberName name = (MemberName) $4;
1252 current_local_parameters = (ParametersCompiled) $7;
1254 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1255 name, current_local_parameters, (Attributes) $1);
1257 current_type.AddMember (method);
1259 async_block = (method.ModFlags & Modifiers.ASYNC) != 0;
1262 method.DocComment = Lexer.consume_doc_comment ();
1264 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1268 lexer.ConstraintsParsing = true;
1270 opt_type_parameter_constraints_clauses
1272 lexer.ConstraintsParsing = false;
1275 var method = (Method) $9;
1276 method.SetConstraints ((List<Constraints>) $10);
1286 lexer.parsing_generic_declaration = true;
1288 method_declaration_name
1291 lexer.parsing_generic_declaration = false;
1292 valid_param_mod = ParameterModifierType.All;
1294 opt_formal_parameter_list CLOSE_PARENS
1296 lexer.ConstraintsParsing = true;
1298 opt_type_parameter_constraints_clauses
1300 lexer.ConstraintsParsing = false;
1301 valid_param_mod = 0;
1303 MemberName name = (MemberName) $6;
1304 current_local_parameters = (ParametersCompiled) $9;
1306 var modifiers = (Modifiers) $2;
1307 modifiers |= Modifiers.PARTIAL;
1309 var method = Method.Create (current_type, new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($4)),
1310 modifiers, name, current_local_parameters, (Attributes) $1);
1312 current_type.AddMember (method);
1315 method.SetConstraints ((List<Constraints>) $11);
1318 method.DocComment = Lexer.consume_doc_comment ();
1320 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1321 lbag.AddMember (method, mod_locations, GetLocation ($7), GetLocation ($10));
1327 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1329 MemberName name = (MemberName) $5;
1330 report.Error (1585, name.Location,
1331 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1333 var method = Method.Create (current_type, (FullNamedExpression) $3,
1334 0, name, (ParametersCompiled) $7, (Attributes) $1);
1336 current_type.AddMember (method);
1338 current_local_parameters = (ParametersCompiled) $7;
1341 method.DocComment = Lexer.consume_doc_comment ();
1348 method_declaration_name error
1350 Error_SyntaxError (yyToken);
1351 current_local_parameters = ParametersCompiled.Undefined;
1353 MemberName name = (MemberName) $4;
1354 var method = Method.Create (current_type, (FullNamedExpression) $3, (Modifiers) $2,
1355 name, current_local_parameters, (Attributes) $1);
1357 current_type.AddMember (method);
1360 method.DocComment = Lexer.consume_doc_comment ();
1368 | SEMICOLON { $$ = null; }
1371 opt_formal_parameter_list
1372 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1373 | formal_parameter_list
1376 formal_parameter_list
1379 var pars_list = (List<Parameter>) $1;
1380 $$ = new ParametersCompiled (pars_list.ToArray ());
1382 | fixed_parameters COMMA parameter_array
1384 var pars_list = (List<Parameter>) $1;
1385 pars_list.Add ((Parameter) $3);
1387 $$ = new ParametersCompiled (pars_list.ToArray ());
1389 | fixed_parameters COMMA arglist_modifier
1391 var pars_list = (List<Parameter>) $1;
1392 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1393 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1395 | parameter_array COMMA error
1398 report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1400 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1402 | fixed_parameters COMMA parameter_array COMMA error
1405 report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1407 var pars_list = (List<Parameter>) $1;
1408 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1410 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1412 | arglist_modifier COMMA error
1414 report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1416 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1418 | fixed_parameters COMMA ARGLIST COMMA error
1420 report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1422 var pars_list = (List<Parameter>) $1;
1423 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1425 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1429 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1433 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1437 Error_SyntaxError (yyToken);
1438 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1445 parameters_bucket.Clear ();
1446 Parameter p = (Parameter) $1;
1447 parameters_bucket.Add (p);
1449 default_parameter_used = p.HasDefaultValue;
1450 $$ = parameters_bucket;
1452 | fixed_parameters COMMA fixed_parameter
1454 var pars = (List<Parameter>) $1;
1455 Parameter p = (Parameter) $3;
1457 if (p.HasExtensionMethodModifier)
1458 report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1459 else if (!p.HasDefaultValue && default_parameter_used)
1460 report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1462 default_parameter_used |= p.HasDefaultValue;
1465 lbag.AddLocation (p, GetLocation ($2));
1474 opt_parameter_modifier
1476 identifier_inside_body
1478 var lt = (Tokenizer.LocatedToken) $4;
1479 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1482 opt_parameter_modifier
1484 identifier_inside_body OPEN_BRACKET CLOSE_BRACKET
1486 var lt = (Tokenizer.LocatedToken) $4;
1487 report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1488 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1490 | attribute_sections error
1492 Error_SyntaxError (yyToken);
1493 Location l = GetLocation ($2);
1494 $$ = new Parameter (null, null, Parameter.Modifier.NONE, (Attributes) $1, l);
1497 opt_parameter_modifier
1501 Error_SyntaxError (yyToken);
1502 Location l = GetLocation ($4);
1503 $$ = new Parameter ((FullNamedExpression) $3, null, (Parameter.Modifier) $2, (Attributes) $1, l);
1506 opt_parameter_modifier
1508 identifier_inside_body
1511 ++lexer.parsing_block;
1515 --lexer.parsing_block;
1516 if (lang_version <= LanguageVersion.V_3) {
1517 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1520 Parameter.Modifier mod = (Parameter.Modifier) $2;
1521 if (mod != Parameter.Modifier.NONE) {
1523 case Parameter.Modifier.REF:
1524 case Parameter.Modifier.OUT:
1525 report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1526 Parameter.GetModifierSignature (mod));
1529 case Parameter.Modifier.This:
1530 report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1531 Parameter.GetModifierSignature (mod));
1534 throw new NotImplementedException (mod.ToString ());
1537 mod = Parameter.Modifier.NONE;
1540 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1541 report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1543 var lt = (Tokenizer.LocatedToken) $4;
1544 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1545 lbag.AddLocation ($$, GetLocation ($5));
1548 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1552 opt_parameter_modifier
1553 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1554 | parameter_modifiers
1558 : parameter_modifier
1562 | parameter_modifiers parameter_modifier
1564 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1565 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1566 if (((Parameter.Modifier)$1 & p2) == p2) {
1567 Error_DuplicateParameterModifier (lexer.Location, p2);
1569 switch (mod & ~Parameter.Modifier.This) {
1570 case Parameter.Modifier.REF:
1571 report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1573 case Parameter.Modifier.OUT:
1574 report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1577 report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1588 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1589 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1591 $$ = Parameter.Modifier.REF;
1595 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1596 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1598 $$ = Parameter.Modifier.OUT;
1602 if ((valid_param_mod & ParameterModifierType.This) == 0)
1603 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1605 if (lang_version <= LanguageVersion.ISO_2)
1606 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1608 $$ = Parameter.Modifier.This;
1613 : opt_attributes params_modifier type IDENTIFIER
1615 var lt = (Tokenizer.LocatedToken) $4;
1616 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1618 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1620 report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1622 var lt = (Tokenizer.LocatedToken) $4;
1623 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1625 | opt_attributes params_modifier type error
1627 Error_SyntaxError (yyToken);
1629 $$ = new ParamsParameter ((FullNamedExpression) $3, null, (Attributes) $1, Location.Null);
1636 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1637 report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1639 | PARAMS parameter_modifier
1641 Parameter.Modifier mod = (Parameter.Modifier)$2;
1642 if ((mod & Parameter.Modifier.This) != 0) {
1643 report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1645 report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1648 | PARAMS params_modifier
1650 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1657 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1658 report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1662 property_declaration
1666 member_declaration_name
1669 tmpComment = Lexer.consume_doc_comment ();
1673 var type = (FullNamedExpression) $3;
1674 current_property = new Property (current_type, type, (Modifiers) $2,
1675 (MemberName) $4, (Attributes) $1);
1677 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1678 report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1680 current_type.AddMember (current_property);
1681 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1683 lexer.PropertyParsing = true;
1685 accessor_declarations
1687 lexer.PropertyParsing = false;
1690 current_property.DocComment = ConsumeStoredComment ();
1694 lbag.AppendToMember (current_property, GetLocation ($10));
1695 current_property = null;
1701 : opt_attributes opt_modifiers
1702 member_type indexer_declaration_name OPEN_BRACKET
1704 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1706 opt_formal_parameter_list CLOSE_BRACKET
1708 valid_param_mod = 0;
1709 var type = (FullNamedExpression) $3;
1710 Indexer indexer = new Indexer (current_type, type, (MemberName) $4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1712 current_property = indexer;
1714 current_type.AddIndexer (indexer);
1715 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8));
1717 if (type.Type != null && type.Type.Kind == MemberKind.Void)
1718 report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1720 if (indexer.ParameterInfo.IsEmpty) {
1721 report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1725 tmpComment = Lexer.consume_doc_comment ();
1726 Lexer.doc_state = XmlCommentState.Allowed;
1729 lexer.PropertyParsing = true;
1731 OPEN_BRACE accessor_declarations
1733 lexer.PropertyParsing = false;
1737 if (current_property.AccessorFirst != null && current_property.AccessorFirst.Block == null)
1738 ((Indexer) current_property).ParameterInfo.CheckParameters (current_property);
1741 current_property.DocComment = ConsumeStoredComment ();
1743 lbag.AppendToMember (current_property, GetLocation ($10), GetLocation ($13));
1744 current_property = null;
1749 accessor_declarations
1750 : get_accessor_declaration
1751 | get_accessor_declaration accessor_declarations
1752 | set_accessor_declaration
1753 | set_accessor_declaration accessor_declarations
1756 if (yyToken == Token.CLOSE_BRACE) {
1757 report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1759 if (yyToken == Token.SEMICOLON)
1760 report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1762 report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1767 get_accessor_declaration
1768 : opt_attributes opt_modifiers GET
1770 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1771 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1774 if (current_property.Get != null) {
1775 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1778 if (current_property is Indexer) {
1779 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1780 (Attributes) $1, GetLocation ($3));
1782 current_property.Get = new Property.GetMethod (current_property,
1783 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1786 current_local_parameters = current_property.Get.ParameterInfo;
1787 lbag.AddMember (current_property.Get, mod_locations);
1788 lexer.PropertyParsing = false;
1793 current_property.Get.Block = (ToplevelBlock) $5;
1795 if (current_container.Kind == MemberKind.Interface) {
1796 report.Error (531, current_property.Get.Block.StartLocation,
1797 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1801 current_local_parameters = null;
1802 lexer.PropertyParsing = true;
1805 if (Lexer.doc_state == XmlCommentState.Error)
1806 Lexer.doc_state = XmlCommentState.NotAllowed;
1810 set_accessor_declaration
1811 : opt_attributes opt_modifiers SET
1813 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1814 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1817 if (current_property.Set != null) {
1818 report.Error (1007, GetLocation ($3), "Property accessor already defined");
1821 if (current_property is Indexer) {
1822 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1823 ParametersCompiled.MergeGenerated (compiler,
1824 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1825 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1827 (Attributes) $1, GetLocation ($3));
1829 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1830 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1831 (Attributes) $1, GetLocation ($3));
1834 current_local_parameters = current_property.Set.ParameterInfo;
1835 lbag.AddMember (current_property.Set, mod_locations);
1836 lexer.PropertyParsing = false;
1841 current_property.Set.Block = (ToplevelBlock) $5;
1843 if (current_container.Kind == MemberKind.Interface) {
1844 report.Error (531, current_property.Set.Block.StartLocation,
1845 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1849 current_local_parameters = null;
1850 lexer.PropertyParsing = true;
1853 && Lexer.doc_state == XmlCommentState.Error)
1854 Lexer.doc_state = XmlCommentState.NotAllowed;
1867 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1872 interface_declaration
1879 type_declaration_name
1881 lexer.ConstraintsParsing = true;
1882 push_current_container (new Interface (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
1883 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
1886 opt_type_parameter_constraints_clauses
1888 lexer.ConstraintsParsing = false;
1891 current_container.SetConstraints ((List<Constraints>) $9);
1894 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
1895 Lexer.doc_state = XmlCommentState.Allowed;
1898 lexer.parsing_modifiers = true;
1900 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1902 --lexer.parsing_declaration;
1904 Lexer.doc_state = XmlCommentState.Allowed;
1908 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13));
1909 $$ = pop_current_class ();
1911 | opt_attributes opt_modifiers opt_partial INTERFACE error
1913 Error_SyntaxError (yyToken);
1917 opt_interface_member_declarations
1919 | interface_member_declarations
1922 interface_member_declarations
1923 : interface_member_declaration
1925 lexer.parsing_modifiers = true;
1927 | interface_member_declarations interface_member_declaration
1929 lexer.parsing_modifiers = true;
1933 interface_member_declaration
1934 : constant_declaration
1936 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1940 report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1942 | method_declaration
1943 | property_declaration
1945 | indexer_declaration
1946 | operator_declaration
1948 report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1950 | constructor_declaration
1952 report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1956 report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1960 operator_declaration
1961 : opt_attributes opt_modifiers operator_declarator
1966 OperatorDeclaration decl = (OperatorDeclaration) $3;
1968 Operator op = new Operator (
1969 current_type, decl.optype, decl.ret_type, (Modifiers) $2,
1970 current_local_parameters,
1971 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1973 if (op.Block == null)
1974 op.ParameterInfo.CheckParameters (op);
1977 op.DocComment = tmpComment;
1978 Lexer.doc_state = XmlCommentState.Allowed;
1981 // Note again, checking is done in semantic analysis
1982 current_type.AddOperator (op);
1984 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1987 current_local_parameters = null;
1993 | SEMICOLON { $$ = null; }
1997 : type_expression_or_array
2000 report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
2001 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2006 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2008 valid_param_mod = ParameterModifierType.DefaultValue;
2010 opt_formal_parameter_list CLOSE_PARENS
2012 valid_param_mod = 0;
2014 Location loc = GetLocation ($2);
2015 Operator.OpType op = (Operator.OpType) $3;
2016 current_local_parameters = (ParametersCompiled)$6;
2018 int p_count = current_local_parameters.Count;
2020 if (op == Operator.OpType.Addition)
2021 op = Operator.OpType.UnaryPlus;
2022 else if (op == Operator.OpType.Subtraction)
2023 op = Operator.OpType.UnaryNegation;
2026 if (IsUnaryOperator (op)) {
2028 report.Error (1020, loc, "Overloadable binary operator expected");
2029 } else if (p_count != 1) {
2030 report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2031 Operator.GetName (op));
2035 report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2036 Operator.GetName (op));
2037 } else if (p_count != 2) {
2038 report.Error (1019, loc, "Overloadable unary operator expected");
2043 tmpComment = Lexer.consume_doc_comment ();
2044 Lexer.doc_state = XmlCommentState.NotAllowed;
2047 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2048 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2050 | conversion_operator_declarator
2053 overloadable_operator
2055 : BANG { $$ = Operator.OpType.LogicalNot; }
2056 | TILDE { $$ = Operator.OpType.OnesComplement; }
2057 | OP_INC { $$ = Operator.OpType.Increment; }
2058 | OP_DEC { $$ = Operator.OpType.Decrement; }
2059 | TRUE { $$ = Operator.OpType.True; }
2060 | FALSE { $$ = Operator.OpType.False; }
2061 // Unary and binary:
2062 | PLUS { $$ = Operator.OpType.Addition; }
2063 | MINUS { $$ = Operator.OpType.Subtraction; }
2065 | STAR { $$ = Operator.OpType.Multiply; }
2066 | DIV { $$ = Operator.OpType.Division; }
2067 | PERCENT { $$ = Operator.OpType.Modulus; }
2068 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2069 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2070 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2071 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2072 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2073 | OP_EQ { $$ = Operator.OpType.Equality; }
2074 | OP_NE { $$ = Operator.OpType.Inequality; }
2075 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2076 | OP_LT { $$ = Operator.OpType.LessThan; }
2077 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2078 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2081 conversion_operator_declarator
2082 : IMPLICIT OPERATOR type OPEN_PARENS
2084 valid_param_mod = ParameterModifierType.DefaultValue;
2086 opt_formal_parameter_list CLOSE_PARENS
2088 valid_param_mod = 0;
2090 Location loc = GetLocation ($2);
2091 current_local_parameters = (ParametersCompiled)$6;
2093 if (current_local_parameters.Count != 1) {
2094 report.Error (1535, loc, "Overloaded unary operator `implicit' takes one parameter");
2098 tmpComment = Lexer.consume_doc_comment ();
2099 Lexer.doc_state = XmlCommentState.NotAllowed;
2102 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2103 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2105 | EXPLICIT OPERATOR type OPEN_PARENS
2107 valid_param_mod = ParameterModifierType.DefaultValue;
2109 opt_formal_parameter_list CLOSE_PARENS
2111 valid_param_mod = 0;
2113 Location loc = GetLocation ($2);
2114 current_local_parameters = (ParametersCompiled)$6;
2116 if (current_local_parameters.Count != 1) {
2117 report.Error (1535, loc, "Overloaded unary operator `explicit' takes one parameter");
2121 tmpComment = Lexer.consume_doc_comment ();
2122 Lexer.doc_state = XmlCommentState.NotAllowed;
2125 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2126 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2130 Error_SyntaxError (yyToken);
2131 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2132 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2136 Error_SyntaxError (yyToken);
2137 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2138 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2142 constructor_declaration
2143 : constructor_declarator
2146 Constructor c = (Constructor) $1;
2147 c.Block = (ToplevelBlock) $2;
2150 c.DocComment = ConsumeStoredComment ();
2152 current_local_parameters = null;
2154 Lexer.doc_state = XmlCommentState.Allowed;
2158 constructor_declarator
2164 tmpComment = Lexer.consume_doc_comment ();
2165 Lexer.doc_state = XmlCommentState.Allowed;
2168 valid_param_mod = ParameterModifierType.All;
2170 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2172 valid_param_mod = 0;
2173 current_local_parameters = (ParametersCompiled) $6;
2175 var lt = (Tokenizer.LocatedToken) $3;
2176 var mods = (Modifiers) $2;
2177 var c = new Constructor (current_type, lt.Value, mods, (Attributes) $1, current_local_parameters, lt.Location);
2179 if (lt.Value != current_container.MemberName.Name) {
2180 report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2181 } else if ((mods & Modifiers.STATIC) != 0) {
2182 if ((mods & Modifiers.AccessibilityMask) != 0){
2183 report.Error (515, c.Location,
2184 "`{0}': static constructor cannot have an access modifier",
2185 c.GetSignatureForError ());
2189 current_type.AddConstructor (c);
2190 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2194 // start block here, so possible anonymous methods inside
2195 // constructor initializer can get correct parent block
2197 start_block (lexer.Location);
2199 opt_constructor_initializer
2202 var c = (Constructor) $8;
2203 c.Initializer = (ConstructorInitializer) $9;
2206 report.Error (514, c.Location,
2207 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2208 c.GetSignatureForError ());
2218 | SEMICOLON { current_block = null; $$ = null; }
2221 opt_constructor_initializer
2223 | constructor_initializer
2226 constructor_initializer
2227 : COLON BASE OPEN_PARENS
2229 ++lexer.parsing_block;
2231 opt_argument_list CLOSE_PARENS
2233 --lexer.parsing_block;
2234 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2235 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2237 | COLON THIS OPEN_PARENS
2239 ++lexer.parsing_block;
2241 opt_argument_list CLOSE_PARENS
2243 --lexer.parsing_block;
2244 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2245 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2249 Error_SyntaxError (yyToken);
2250 $$ = new ConstructorThisInitializer (null, GetLocation ($2));
2251 lbag.AddLocation ($$, GetLocation ($1));
2255 Error_SyntaxError (yyToken);
2260 destructor_declaration
2261 : opt_attributes opt_modifiers TILDE
2264 tmpComment = Lexer.consume_doc_comment ();
2265 Lexer.doc_state = XmlCommentState.NotAllowed;
2268 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2270 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2272 var lt = (Tokenizer.LocatedToken) $5;
2273 if (lt.Value != current_container.MemberName.Name){
2274 report.Error (574, lt.Location, "Name of destructor must match name of class");
2275 } else if (current_container.Kind != MemberKind.Class){
2276 report.Error (575, lt.Location, "Only class types can contain destructor");
2279 Destructor d = new Destructor (current_type, (Modifiers) $2,
2280 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2282 d.DocComment = ConsumeStoredComment ();
2284 d.Block = (ToplevelBlock) $8;
2285 current_type.AddMember (d);
2286 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2288 current_local_parameters = null;
2295 EVENT type member_declaration_name
2297 current_event_field = new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2298 current_type.AddMember (current_event_field);
2300 if (current_event_field.MemberName.ExplicitInterface != null) {
2301 report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2302 current_event_field.GetSignatureForError ());
2305 $$ = current_event_field;
2307 opt_event_initializer
2308 opt_event_declarators
2312 current_event_field.DocComment = Lexer.consume_doc_comment ();
2313 Lexer.doc_state = XmlCommentState.Allowed;
2316 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2317 current_event_field = null;
2321 EVENT type member_declaration_name
2324 current_event = new EventProperty (current_type, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2325 current_type.AddMember (current_event);
2326 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2328 lexer.EventParsing = true;
2330 event_accessor_declarations
2332 if (current_container.Kind == MemberKind.Interface)
2333 report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2335 lexer.EventParsing = false;
2340 current_event.DocComment = Lexer.consume_doc_comment ();
2341 Lexer.doc_state = XmlCommentState.Allowed;
2344 lbag.AppendToMember (current_event, GetLocation ($9));
2345 current_event = null;
2346 current_local_parameters = null;
2352 Error_SyntaxError (yyToken);
2354 current_type.AddMember (new EventField (current_type, (FullNamedExpression) $4, (Modifiers) $2, MemberName.Null, (Attributes) $1));
2358 opt_event_initializer
2362 ++lexer.parsing_block;
2364 event_variable_initializer
2366 --lexer.parsing_block;
2367 current_event_field.Initializer = (Expression) $3;
2371 opt_event_declarators
2379 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2381 | event_declarators event_declarator
2383 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2390 var lt = (Tokenizer.LocatedToken) $2;
2391 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2392 lbag.AddLocation ($$, GetLocation ($1));
2394 | COMMA IDENTIFIER ASSIGN
2396 ++lexer.parsing_block;
2398 event_variable_initializer
2400 --lexer.parsing_block;
2401 var lt = (Tokenizer.LocatedToken) $2;
2402 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2403 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2407 event_variable_initializer
2409 if (current_container.Kind == MemberKind.Interface) {
2410 report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2411 current_event_field.GetSignatureForError ());
2414 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2415 report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2416 current_event_field.GetSignatureForError ());
2419 variable_initializer
2425 event_accessor_declarations
2426 : add_accessor_declaration remove_accessor_declaration
2427 | remove_accessor_declaration add_accessor_declaration
2428 | add_accessor_declaration
2430 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2431 current_event.GetSignatureForError ());
2433 | remove_accessor_declaration
2435 report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2436 current_event.GetSignatureForError ());
2440 report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2445 add_accessor_declaration
2446 : opt_attributes opt_modifiers ADD
2448 if ($2 != ModifierNone) {
2449 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2452 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2453 current_local_parameters = current_event.Add.ParameterInfo;
2455 lbag.AddMember (current_event.Add, mod_locations);
2456 lexer.EventParsing = false;
2458 event_accessor_block
2460 lexer.EventParsing = true;
2462 current_event.Add.Block = (ToplevelBlock) $5;
2464 if (current_container.Kind == MemberKind.Interface) {
2465 report.Error (531, current_event.Add.Block.StartLocation,
2466 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2469 current_local_parameters = null;
2473 remove_accessor_declaration
2474 : opt_attributes opt_modifiers REMOVE
2476 if ($2 != ModifierNone) {
2477 report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2480 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2481 current_local_parameters = current_event.Remove.ParameterInfo;
2483 lbag.AddMember (current_event.Remove, mod_locations);
2484 lexer.EventParsing = false;
2486 event_accessor_block
2488 lexer.EventParsing = true;
2490 current_event.Remove.Block = (ToplevelBlock) $5;
2492 if (current_container.Kind == MemberKind.Interface) {
2493 report.Error (531, current_event.Remove.Block.StartLocation,
2494 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2497 current_local_parameters = null;
2501 event_accessor_block
2504 report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2510 attributes_without_members
2511 : attribute_sections CLOSE_BRACE
2513 current_type.UnattachedAttributes = (Attributes) $1;
2514 report.Error (1519, GetLocation ($1), "An attribute is missing member declaration");
2515 lexer.putback ('}');
2522 ENUM type_declaration_name
2526 enumTypeComment = Lexer.consume_doc_comment ();
2531 Lexer.doc_state = XmlCommentState.Allowed;
2533 MemberName name = (MemberName) $4;
2534 if (name.IsGeneric) {
2535 report.Error (1675, name.Location, "Enums cannot have type parameters");
2538 push_current_container (new Enum (current_container, (FullNamedExpression) $5, (Modifiers) $2, name, (Attributes) $1), null);
2540 opt_enum_member_declarations
2542 // here will be evaluated after CLOSE_BLACE is consumed.
2544 Lexer.doc_state = XmlCommentState.Allowed;
2546 CLOSE_BRACE opt_semicolon
2549 current_container.DocComment = enumTypeComment;
2551 --lexer.parsing_declaration;
2554 // em.DocComment = ev.DocComment;
2556 lbag.AddMember (current_container, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2557 $$ = pop_current_class ();
2565 var te = $2 as TypeExpression;
2566 if (te == null || !EnumSpec.IsValidUnderlyingType (te.Type)) {
2567 Enum.Error_1008 (GetLocation ($2), report);
2573 Error_TypeExpected (GetLocation ($1));
2578 opt_enum_member_declarations
2580 | enum_member_declarations
2581 | enum_member_declarations COMMA
2583 lbag.AddLocation ($1, GetLocation ($2));
2587 enum_member_declarations
2588 : enum_member_declaration
2589 | enum_member_declarations COMMA enum_member_declaration
2591 lbag.AddLocation ($1, GetLocation ($2));
2596 enum_member_declaration
2597 : opt_attributes IDENTIFIER
2599 var lt = (Tokenizer.LocatedToken) $2;
2600 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2601 ((Enum) current_type).AddEnumMember (em);
2604 em.DocComment = Lexer.consume_doc_comment ();
2605 Lexer.doc_state = XmlCommentState.Allowed;
2610 | opt_attributes IDENTIFIER
2612 ++lexer.parsing_block;
2614 tmpComment = Lexer.consume_doc_comment ();
2615 Lexer.doc_state = XmlCommentState.NotAllowed;
2618 ASSIGN constant_expression
2620 --lexer.parsing_block;
2622 var lt = (Tokenizer.LocatedToken) $2;
2623 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2624 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2625 ((Enum) current_type).AddEnumMember (em);
2628 em.DocComment = ConsumeStoredComment ();
2632 | opt_attributes IDENTIFIER error
2634 Error_SyntaxError (yyToken);
2636 var lt = (Tokenizer.LocatedToken) $2;
2637 var em = new EnumMember ((Enum) current_type, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2638 ((Enum) current_type).AddEnumMember (em);
2641 em.DocComment = Lexer.consume_doc_comment ();
2642 Lexer.doc_state = XmlCommentState.Allowed;
2647 | attributes_without_members
2650 delegate_declaration
2654 member_type type_declaration_name
2657 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2659 opt_formal_parameter_list CLOSE_PARENS
2661 valid_param_mod = 0;
2663 ParametersCompiled p = (ParametersCompiled) $8;
2665 Delegate del = new Delegate (current_container, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, p, (Attributes) $1);
2667 p.CheckParameters (del);
2669 current_container.AddTypeContainer (del);
2671 current_delegate = del;
2672 lexer.ConstraintsParsing = true;
2674 opt_type_parameter_constraints_clauses
2676 lexer.ConstraintsParsing = false;
2681 current_delegate.DocComment = Lexer.consume_doc_comment ();
2682 Lexer.doc_state = XmlCommentState.Allowed;
2686 current_delegate.SetConstraints ((List<Constraints>) $11);
2687 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2689 $$ = current_delegate;
2691 current_delegate = null;
2699 if (lang_version < LanguageVersion.ISO_2)
2700 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2702 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2706 namespace_or_type_expr
2708 | qualified_alias_member IDENTIFIER opt_type_argument_list
2710 var lt1 = (Tokenizer.LocatedToken) $1;
2711 var lt2 = (Tokenizer.LocatedToken) $2;
2713 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2714 lbag.AddLocation ($$, GetLocation ($2));
2720 | namespace_or_type_expr DOT IDENTIFIER opt_type_argument_list
2722 var lt = (Tokenizer.LocatedToken) $3;
2723 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2724 lbag.AddLocation ($$, GetLocation ($2));
2729 : IDENTIFIER opt_type_argument_list
2731 var lt = (Tokenizer.LocatedToken) $1;
2732 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2737 // Generics arguments (any type, without attributes)
2739 opt_type_argument_list
2741 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2743 if (lang_version < LanguageVersion.ISO_2)
2744 FeatureIsNotAvailable (GetLocation ($1), "generics");
2748 | OP_GENERICS_LT error
2750 Error_TypeExpected (lexer.Location);
2751 $$ = new TypeArguments ();
2758 TypeArguments type_args = new TypeArguments ();
2759 type_args.Add ((FullNamedExpression) $1);
2762 | type_arguments COMMA type
2764 TypeArguments type_args = (TypeArguments) $1;
2765 type_args.Add ((FullNamedExpression) $3);
2771 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2773 type_declaration_name
2776 lexer.parsing_generic_declaration = true;
2778 opt_type_parameter_list
2780 lexer.parsing_generic_declaration = false;
2781 var lt = (Tokenizer.LocatedToken) $1;
2782 $$ = new MemberName (lt.Value, (TypeParameters)$3, lt.Location);
2786 member_declaration_name
2787 : method_declaration_name
2789 MemberName mn = (MemberName)$1;
2790 if (mn.TypeParameters != null)
2791 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2792 mn.GetSignatureForError ()));
2796 method_declaration_name
2797 : type_declaration_name
2798 | explicit_interface IDENTIFIER opt_type_parameter_list
2800 lexer.parsing_generic_declaration = false;
2801 var lt = (Tokenizer.LocatedToken) $2;
2802 $$ = new MemberName (lt.Value, (TypeParameters) $3, (ATypeNameExpression) $1, lt.Location);
2806 indexer_declaration_name
2809 lexer.parsing_generic_declaration = false;
2810 $$ = new MemberName (TypeDefinition.DefaultIndexerName, GetLocation ($1));
2812 | explicit_interface THIS
2814 lexer.parsing_generic_declaration = false;
2815 $$ = new MemberName (TypeDefinition.DefaultIndexerName, null, (ATypeNameExpression) $1, GetLocation ($2));
2820 : IDENTIFIER opt_type_argument_list DOT
2822 var lt = (Tokenizer.LocatedToken) $1;
2823 $$ = new SimpleName (lt.Value, (TypeArguments) $2, lt.Location);
2824 lbag.AddLocation ($$, GetLocation ($3));
2826 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2828 var lt1 = (Tokenizer.LocatedToken) $1;
2829 var lt2 = (Tokenizer.LocatedToken) $2;
2831 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2832 lbag.AddLocation ($$, GetLocation ($4));
2834 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2836 var lt = (Tokenizer.LocatedToken) $2;
2837 $$ = new MemberAccess ((ATypeNameExpression) $1, lt.Value, (TypeArguments) $3, lt.Location);
2838 lbag.AddLocation ($$, GetLocation ($4));
2842 opt_type_parameter_list
2844 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2846 if (lang_version < LanguageVersion.ISO_2)
2847 FeatureIsNotAvailable (GetLocation ($1), "generics");
2850 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2857 var tparams = new TypeParameters ();
2858 tparams.Add ((TypeParameter)$1);
2861 | type_parameters COMMA type_parameter
2863 var tparams = (TypeParameters) $1;
2864 tparams.Add ((TypeParameter)$3);
2866 lbag.AddLocation ($3, GetLocation ($3));
2871 : opt_attributes opt_type_parameter_variance IDENTIFIER
2873 var lt = (Tokenizer.LocatedToken)$3;
2874 $$ = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)$1, (Variance) $2);
2878 if (GetTokenName (yyToken) == "type")
2879 report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2881 Error_SyntaxError (yyToken);
2883 $$ = new TypeParameter (MemberName.Null, null, Variance.None);
2888 // All types where void is allowed
2891 : type_expression_or_array
2894 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2901 lexer.parsing_generic_declaration = true;
2906 // A type which does not allow `void' to be used
2909 : type_expression_or_array
2912 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2913 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2921 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
2922 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2927 : type_expression_or_array
2930 report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2931 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
2935 type_expression_or_array
2937 | type_expression rank_specifiers
2939 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2944 : namespace_or_type_expr opt_nullable
2947 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2949 var sn = $1 as SimpleName;
2950 if (sn != null && sn.Name == "var")
2951 $$ = new VarExpr (sn.Location);
2956 | namespace_or_type_expr pointer_stars
2958 $$ = new ComposedCast ((ATypeNameExpression) $1, (ComposedTypeSpecifier) $2);
2960 | builtin_types opt_nullable
2963 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2965 | builtin_types pointer_stars
2967 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2969 | VOID pointer_stars
2971 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2978 var types = new List<FullNamedExpression> (2);
2979 types.Add ((FullNamedExpression) $1);
2982 | type_list COMMA base_type_name
2984 var types = (List<FullNamedExpression>) $1;
2985 types.Add ((FullNamedExpression) $3);
2993 if ($1 is ComposedCast) {
2994 report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
3001 * replaces all the productions for isolating the various
3002 * simple types, but we need this to reuse it easily in variable_type
3005 : OBJECT { $$ = new TypeExpression (compiler.BuiltinTypes.Object, GetLocation ($1)); }
3006 | STRING { $$ = new TypeExpression (compiler.BuiltinTypes.String, GetLocation ($1)); }
3007 | BOOL { $$ = new TypeExpression (compiler.BuiltinTypes.Bool, GetLocation ($1)); }
3008 | DECIMAL { $$ = new TypeExpression (compiler.BuiltinTypes.Decimal, GetLocation ($1)); }
3009 | FLOAT { $$ = new TypeExpression (compiler.BuiltinTypes.Float, GetLocation ($1)); }
3010 | DOUBLE { $$ = new TypeExpression (compiler.BuiltinTypes.Double, GetLocation ($1)); }
3015 : SBYTE { $$ = new TypeExpression (compiler.BuiltinTypes.SByte, GetLocation ($1)); }
3016 | BYTE { $$ = new TypeExpression (compiler.BuiltinTypes.Byte, GetLocation ($1)); }
3017 | SHORT { $$ = new TypeExpression (compiler.BuiltinTypes.Short, GetLocation ($1)); }
3018 | USHORT { $$ = new TypeExpression (compiler.BuiltinTypes.UShort, GetLocation ($1)); }
3019 | INT { $$ = new TypeExpression (compiler.BuiltinTypes.Int, GetLocation ($1)); }
3020 | UINT { $$ = new TypeExpression (compiler.BuiltinTypes.UInt, GetLocation ($1)); }
3021 | LONG { $$ = new TypeExpression (compiler.BuiltinTypes.Long, GetLocation ($1)); }
3022 | ULONG { $$ = new TypeExpression (compiler.BuiltinTypes.ULong, GetLocation ($1)); }
3023 | CHAR { $$ = new TypeExpression (compiler.BuiltinTypes.Char, GetLocation ($1)); }
3027 // Expressions, section 7.5
3032 : primary_expression_or_type
3034 | array_creation_expression
3035 | parenthesized_expression
3036 | default_value_expression
3037 | invocation_expression
3041 | post_increment_expression
3042 | post_decrement_expression
3043 | object_or_delegate_creation_expression
3044 | anonymous_type_expression
3047 | checked_expression
3048 | unchecked_expression
3049 | pointer_member_access
3050 | anonymous_method_expression
3051 | undocumented_expressions
3054 primary_expression_or_type
3055 : IDENTIFIER opt_type_argument_list
3057 var lt = (Tokenizer.LocatedToken) $1;
3058 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3060 | IDENTIFIER GENERATE_COMPLETION {
3061 var lt = (Tokenizer.LocatedToken) $1;
3062 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3070 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3074 : TRUE { $$ = new BoolLiteral (compiler.BuiltinTypes, true, GetLocation ($1)); }
3075 | FALSE { $$ = new BoolLiteral (compiler.BuiltinTypes, false, GetLocation ($1)); }
3080 // Here is the trick, tokenizer may think that parens is a special but
3081 // parser is interested in open parens only, so we merge them.
3082 // Consider: if (a)foo ();
3090 // Use this production to accept closing parenthesis or
3091 // performing completion
3095 | COMPLETE_COMPLETION
3099 parenthesized_expression
3100 : OPEN_PARENS expression CLOSE_PARENS
3102 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3103 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3105 | OPEN_PARENS expression COMPLETE_COMPLETION
3107 $$ = new ParenthesizedExpression ((Expression) $2, GetLocation ($1));
3112 : primary_expression DOT identifier_inside_body opt_type_argument_list
3114 var lt = (Tokenizer.LocatedToken) $3;
3115 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3116 lbag.AddLocation ($$, GetLocation ($2));
3118 | builtin_types DOT identifier_inside_body opt_type_argument_list
3120 var lt = (Tokenizer.LocatedToken) $3;
3121 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3122 lbag.AddLocation ($$, GetLocation ($2));
3124 | BASE DOT identifier_inside_body opt_type_argument_list
3126 var lt = (Tokenizer.LocatedToken) $3;
3127 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3128 lbag.AddLocation ($$, GetLocation ($2));
3130 | qualified_alias_member identifier_inside_body opt_type_argument_list
3132 var lt1 = (Tokenizer.LocatedToken) $1;
3133 var lt2 = (Tokenizer.LocatedToken) $2;
3135 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3136 lbag.AddLocation ($$, GetLocation ($2));
3138 | primary_expression DOT GENERATE_COMPLETION {
3139 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3141 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3142 var lt = (Tokenizer.LocatedToken) $3;
3143 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3145 | builtin_types DOT GENERATE_COMPLETION
3147 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3149 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3150 var lt = (Tokenizer.LocatedToken) $3;
3151 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3155 invocation_expression
3156 : primary_expression open_parens_any opt_argument_list close_parens
3158 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3159 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3161 | primary_expression open_parens_any argument_list error
3163 Error_SyntaxError (yyToken);
3165 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3166 lbag.AddLocation ($$, GetLocation ($2));
3168 | primary_expression open_parens_any error
3170 Error_SyntaxError (yyToken);
3172 $$ = new Invocation ((Expression) $1, null);
3173 lbag.AddLocation ($$, GetLocation ($2));
3177 opt_object_or_collection_initializer
3178 : /* empty */ { $$ = null; }
3179 | object_or_collection_initializer
3182 object_or_collection_initializer
3183 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3186 $$ = new CollectionOrObjectInitializers (GetLocation ($1));
3188 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3190 lbag.AddLocation ($$, GetLocation ($3));
3192 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3194 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3195 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3199 opt_member_initializer_list
3200 : /* empty */ { $$ = null; }
3201 | member_initializer_list
3207 member_initializer_list
3208 : member_initializer
3210 var a = new List<Expression> ();
3211 a.Add ((Expression) $1);
3214 | member_initializer_list COMMA member_initializer
3216 var a = (List<Expression>)$1;
3217 a.Add ((Expression) $3);
3220 | member_initializer_list error {
3221 Error_SyntaxError (yyToken);
3227 : IDENTIFIER ASSIGN initializer_value
3229 var lt = (Tokenizer.LocatedToken) $1;
3230 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3231 lbag.AddLocation ($$, GetLocation ($2));
3233 | AWAIT ASSIGN initializer_value
3235 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
3236 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3237 lbag.AddLocation ($$, GetLocation ($2));
3239 | GENERATE_COMPLETION
3241 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3243 | non_assignment_expression opt_COMPLETE_COMPLETION {
3244 CompletionSimpleName csn = $1 as CompletionSimpleName;
3246 $$ = new CollectionElementInitializer ((Expression)$1);
3248 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3250 | OPEN_BRACE expression_list CLOSE_BRACE
3255 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3257 | OPEN_BRACE CLOSE_BRACE
3259 report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3266 | object_or_collection_initializer
3270 : /* empty */ { $$ = null; }
3275 : argument_or_named_argument
3277 Arguments list = new Arguments (4);
3278 list.Add ((Argument) $1);
3281 | argument_list COMMA argument
3283 Arguments list = (Arguments) $1;
3284 if (list [list.Count - 1] is NamedArgument)
3285 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3287 list.Add ((Argument) $3);
3290 | argument_list COMMA named_argument
3292 Arguments list = (Arguments) $1;
3293 NamedArgument a = (NamedArgument) $3;
3294 for (int i = 0; i < list.Count; ++i) {
3295 NamedArgument na = list [i] as NamedArgument;
3296 if (na != null && na.Name == a.Name)
3297 report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3304 | argument_list COMMA error
3306 if (lexer.putback_char == -1)
3307 lexer.putback (')'); // TODO: Wrong but what can I do
3308 Error_SyntaxError (yyToken);
3313 report.Error (839, GetLocation ($1), "An argument is missing");
3321 $$ = new Argument ((Expression) $1);
3323 | non_simple_argument
3326 argument_or_named_argument
3332 : REF variable_reference
3334 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3335 lbag.AddLocation ($$, GetLocation ($1));
3337 | OUT variable_reference
3339 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3340 lbag.AddLocation ($$, GetLocation ($1));
3342 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3344 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3345 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3347 | ARGLIST OPEN_PARENS CLOSE_PARENS
3349 $$ = new Argument (new Arglist (GetLocation ($1)));
3350 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3359 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3361 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3362 lbag.AddLocation ($$, GetLocation ($4));
3364 | primary_expression OPEN_BRACKET_EXPR expression_list_arguments error
3366 Error_SyntaxError (yyToken);
3367 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3369 | primary_expression OPEN_BRACKET_EXPR error
3371 Error_SyntaxError (yyToken);
3372 $$ = new ElementAccess ((Expression) $1, null, GetLocation ($2));
3379 var list = new List<Expression> (4);
3380 list.Add ((Expression) $1);
3383 | expression_list COMMA expression
3385 var list = (List<Expression>) $1;
3386 list.Add ((Expression) $3);
3389 | expression_list error {
3390 Error_SyntaxError (yyToken);
3395 expression_list_arguments
3396 : expression_list_argument
3398 Arguments args = new Arguments (4);
3399 args.Add ((Argument) $1);
3402 | expression_list_arguments COMMA expression_list_argument
3404 Arguments args = (Arguments) $1;
3405 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3406 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3408 args.Add ((Argument) $3);
3413 expression_list_argument
3416 $$ = new Argument ((Expression) $1);
3424 $$ = new This (GetLocation ($1));
3429 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3431 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3432 lbag.AddLocation ($$, GetLocation ($4));
3434 | BASE OPEN_BRACKET error
3436 Error_SyntaxError (yyToken);
3437 $$ = new ElementAccess (null, null, GetLocation ($2));
3441 post_increment_expression
3442 : primary_expression OP_INC
3444 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3448 post_decrement_expression
3449 : primary_expression OP_DEC
3451 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3455 object_or_delegate_creation_expression
3456 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3459 if (lang_version <= LanguageVersion.ISO_2)
3460 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3462 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3464 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3467 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3469 | NEW new_expr_type object_or_collection_initializer
3471 if (lang_version <= LanguageVersion.ISO_2)
3472 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3474 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3478 array_creation_expression
3479 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3481 opt_array_initializer
3483 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3484 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3485 Next = (ComposedTypeSpecifier) $6
3486 }, (ArrayInitializer) $7, GetLocation ($1));
3487 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3489 | NEW new_expr_type rank_specifiers opt_array_initializer
3492 report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3494 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3496 | NEW rank_specifier array_initializer
3498 if (lang_version <= LanguageVersion.ISO_2)
3499 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3501 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3503 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3505 report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3506 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3508 | NEW new_expr_type error
3510 Error_SyntaxError (yyToken);
3511 // It can be any of new expression, create the most common one
3512 $$ = new New ((FullNamedExpression) $2, null, GetLocation ($1));
3518 ++lexer.parsing_type;
3522 --lexer.parsing_type;
3527 anonymous_type_expression
3528 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3530 if (lang_version <= LanguageVersion.ISO_2)
3531 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3533 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3535 // TODO: lbag comma location
3536 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3540 anonymous_type_parameters_opt_comma
3541 : anonymous_type_parameters_opt
3542 | anonymous_type_parameters COMMA
3545 anonymous_type_parameters_opt
3547 | anonymous_type_parameters
3550 anonymous_type_parameters
3551 : anonymous_type_parameter
3553 var a = new List<AnonymousTypeParameter> (4);
3554 a.Add ((AnonymousTypeParameter) $1);
3557 | anonymous_type_parameters COMMA anonymous_type_parameter
3559 var a = (List<AnonymousTypeParameter>) $1;
3560 a.Add ((AnonymousTypeParameter) $3);
3565 anonymous_type_parameter
3566 : identifier_inside_body ASSIGN variable_initializer
3568 var lt = (Tokenizer.LocatedToken)$1;
3569 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3570 lbag.AddLocation ($$, GetLocation ($2));
3572 | identifier_inside_body
3574 var lt = (Tokenizer.LocatedToken)$1;
3575 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3576 lt.Value, lt.Location);
3580 MemberAccess ma = (MemberAccess) $1;
3581 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3585 report.Error (746, lexer.Location,
3586 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3598 | rank_specifier rank_specifiers
3600 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3606 : OPEN_BRACKET CLOSE_BRACKET
3608 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3609 lbag.AddLocation ($$, GetLocation ($2));
3611 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3613 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3614 lbag.AddLocation ($$, GetLocation ($3));
3623 | dim_separators COMMA
3625 $$ = ((int) $1) + 1;
3629 opt_array_initializer
3641 : OPEN_BRACE CLOSE_BRACE
3643 var ai = new ArrayInitializer (0, GetLocation ($1));
3644 ai.VariableDeclaration = current_variable;
3645 lbag.AddLocation (ai, GetLocation ($2));
3648 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3650 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3651 ai.VariableDeclaration = current_variable;
3653 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3655 lbag.AddLocation (ai, GetLocation ($4));
3661 variable_initializer_list
3662 : variable_initializer
3664 var list = new List<Expression> (4);
3665 list.Add ((Expression) $1);
3668 | variable_initializer_list COMMA variable_initializer
3670 var list = (List<Expression>) $1;
3671 list.Add ((Expression) $3);
3679 lexer.TypeOfParsing = true;
3681 open_parens_any typeof_type_expression CLOSE_PARENS
3683 lexer.TypeOfParsing = false;
3684 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3685 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3689 typeof_type_expression
3694 Error_TypeExpected (lexer.Location);
3700 : identifier_inside_body generic_dimension
3702 var lt = (Tokenizer.LocatedToken) $1;
3704 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3706 | qualified_alias_member identifier_inside_body generic_dimension
3708 var lt1 = (Tokenizer.LocatedToken) $1;
3709 var lt2 = (Tokenizer.LocatedToken) $2;
3711 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3712 lbag.AddLocation ($$, GetLocation ($2));
3714 | unbound_type_name DOT identifier_inside_body
3716 var lt = (Tokenizer.LocatedToken) $3;
3718 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3720 | unbound_type_name DOT identifier_inside_body generic_dimension
3722 var lt = (Tokenizer.LocatedToken) $3;
3724 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3726 | namespace_or_type_expr DOT identifier_inside_body generic_dimension
3728 var tne = (ATypeNameExpression) $1;
3729 if (tne.HasTypeArguments)
3730 Error_TypeExpected (GetLocation ($4));
3732 var lt = (Tokenizer.LocatedToken) $3;
3733 $$ = new MemberAccess (tne, lt.Value, (int) $4, lt.Location);
3740 if (lang_version < LanguageVersion.ISO_2)
3741 FeatureIsNotAvailable (GetLocation ($1), "generics");
3747 qualified_alias_member
3748 : IDENTIFIER DOUBLE_COLON
3750 var lt = (Tokenizer.LocatedToken) $1;
3751 if (lang_version == LanguageVersion.ISO_1)
3752 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3759 : SIZEOF open_parens_any type CLOSE_PARENS
3761 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3762 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3764 | SIZEOF open_parens_any type error
3766 Error_SyntaxError (yyToken);
3768 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3769 lbag.AddLocation ($$, GetLocation ($2));
3774 : CHECKED open_parens_any expression CLOSE_PARENS
3776 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3777 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3781 Error_SyntaxError (yyToken);
3783 $$ = new CheckedExpr (null, GetLocation ($1));
3787 unchecked_expression
3788 : UNCHECKED open_parens_any expression CLOSE_PARENS
3790 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3791 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3795 Error_SyntaxError (yyToken);
3797 $$ = new UnCheckedExpr (null, GetLocation ($1));
3801 pointer_member_access
3802 : primary_expression OP_PTR IDENTIFIER opt_type_argument_list
3804 var lt = (Tokenizer.LocatedToken) $3;
3805 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, (TypeArguments) $4, lt.Location);
3809 anonymous_method_expression
3810 : DELEGATE opt_anonymous_method_signature
3812 start_anonymous (false, (ParametersCompiled) $2, false, GetLocation ($1));
3816 $$ = end_anonymous ((ParametersBlock) $4);
3818 | ASYNC DELEGATE opt_anonymous_method_signature
3820 start_anonymous (false, (ParametersCompiled) $3, true, GetLocation ($1));
3824 $$ = end_anonymous ((ParametersBlock) $5);
3828 opt_anonymous_method_signature
3831 $$ = ParametersCompiled.Undefined;
3833 | anonymous_method_signature
3836 anonymous_method_signature
3839 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3841 opt_formal_parameter_list CLOSE_PARENS
3843 valid_param_mod = 0;
3848 default_value_expression
3849 : DEFAULT open_parens_any type CLOSE_PARENS
3851 if (lang_version < LanguageVersion.ISO_2)
3852 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3854 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3855 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3860 : primary_expression
3861 | BANG prefixed_unary_expression
3863 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3865 | TILDE prefixed_unary_expression
3867 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3869 | OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3871 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3872 lbag.AddLocation ($$, GetLocation ($3));
3874 | AWAIT prefixed_unary_expression
3877 if (current_anonymous_method is LambdaExpression) {
3878 report.Error (4034, GetLocation ($1),
3879 "The `await' operator can only be used when its containing lambda expression is marked with the `async' modifier");
3880 } else if (current_anonymous_method is AnonymousMethodExpression) {
3881 report.Error (4035, GetLocation ($1),
3882 "The `await' operator can only be used when its containing anonymous method is marked with the `async' modifier");
3884 report.Error (4033, GetLocation ($1),
3885 "The `await' operator can only be used when its containing method is marked with the `async' modifier");
3888 current_block.Explicit.RegisterAsyncAwait ();
3891 $$ = new Await ((Expression) $2, GetLocation ($1));
3895 Error_SyntaxError (yyToken);
3897 $$ = new Unary (Unary.Operator.LogicalNot, null, GetLocation ($1));
3901 Error_SyntaxError (yyToken);
3903 $$ = new Unary (Unary.Operator.OnesComplement, null, GetLocation ($1));
3905 | OPEN_PARENS_CAST type CLOSE_PARENS error
3907 Error_SyntaxError (yyToken);
3909 $$ = new Cast ((FullNamedExpression) $2, null, GetLocation ($1));
3910 lbag.AddLocation ($$, GetLocation ($3));
3914 Error_SyntaxError (yyToken);
3916 $$ = new Await (null, GetLocation ($1));
3921 // The idea to split this out is from Rhys' grammar
3922 // to solve the problem with casts.
3924 prefixed_unary_expression
3926 | PLUS prefixed_unary_expression
3928 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3930 | MINUS prefixed_unary_expression
3932 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3934 | OP_INC prefixed_unary_expression
3936 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3938 | OP_DEC prefixed_unary_expression
3940 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3942 | STAR prefixed_unary_expression
3944 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3946 | BITWISE_AND prefixed_unary_expression
3948 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3952 Error_SyntaxError (yyToken);
3954 $$ = new Unary (Unary.Operator.UnaryPlus, null, GetLocation ($1));
3958 Error_SyntaxError (yyToken);
3960 $$ = new Unary (Unary.Operator.UnaryNegation, null, GetLocation ($1));
3964 Error_SyntaxError (yyToken);
3966 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, null, GetLocation ($1));
3970 Error_SyntaxError (yyToken);
3972 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, null, GetLocation ($1));
3976 Error_SyntaxError (yyToken);
3978 $$ = new Indirection (null, GetLocation ($1));
3982 Error_SyntaxError (yyToken);
3984 $$ = new Unary (Unary.Operator.AddressOf, null, GetLocation ($1));
3988 multiplicative_expression
3989 : prefixed_unary_expression
3990 | multiplicative_expression STAR prefixed_unary_expression
3992 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3993 lbag.AddLocation ($$, GetLocation ($2));
3995 | multiplicative_expression DIV prefixed_unary_expression
3997 $$ = new Binary (Binary.Operator.Division, (Expression) $1, (Expression) $3);
3998 lbag.AddLocation ($$, GetLocation ($2));
4000 | multiplicative_expression PERCENT prefixed_unary_expression
4002 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4003 lbag.AddLocation ($$, GetLocation ($2));
4005 | multiplicative_expression STAR error
4007 Error_SyntaxError (yyToken);
4009 $$ = new Binary (Binary.Operator.Multiply, (Expression) $1, null);
4010 lbag.AddLocation ($$, GetLocation ($2));
4012 | multiplicative_expression DIV error
4014 Error_SyntaxError (yyToken);
4016 $$ = new Binary (Binary.Operator.Division, (Expression) $1, null);
4017 lbag.AddLocation ($$, GetLocation ($2));
4019 | multiplicative_expression PERCENT error
4021 Error_SyntaxError (yyToken);
4023 $$ = new Binary (Binary.Operator.Modulus, (Expression) $1, null);
4024 lbag.AddLocation ($$, GetLocation ($2));
4029 : multiplicative_expression
4030 | additive_expression PLUS multiplicative_expression
4032 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4033 lbag.AddLocation ($$, GetLocation ($2));
4035 | additive_expression MINUS multiplicative_expression
4037 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4038 lbag.AddLocation ($$, GetLocation ($2));
4040 | additive_expression AS type
4042 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
4044 | additive_expression IS type
4046 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
4048 | additive_expression PLUS error
4050 Error_SyntaxError (yyToken);
4052 $$ = new Binary (Binary.Operator.Addition, (Expression) $1, null);
4053 lbag.AddLocation ($$, GetLocation ($2));
4055 | additive_expression MINUS error
4057 Error_SyntaxError (yyToken);
4059 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, null);
4060 lbag.AddLocation ($$, GetLocation ($2));
4062 | additive_expression AS error
4064 Error_SyntaxError (yyToken);
4066 $$ = new As ((Expression) $1, null, GetLocation ($2));
4068 | additive_expression IS error
4070 Error_SyntaxError (yyToken);
4072 $$ = new Is ((Expression) $1, null, GetLocation ($2));
4077 : additive_expression
4078 | shift_expression OP_SHIFT_LEFT additive_expression
4080 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4081 lbag.AddLocation ($$, GetLocation ($2));
4083 | shift_expression OP_SHIFT_RIGHT additive_expression
4085 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4086 lbag.AddLocation ($$, GetLocation ($2));
4088 | shift_expression OP_SHIFT_LEFT error
4090 Error_SyntaxError (yyToken);
4092 $$ = new Binary (Binary.Operator.LeftShift, (Expression) $1, null);
4093 lbag.AddLocation ($$, GetLocation ($2));
4095 | shift_expression OP_SHIFT_RIGHT error
4097 Error_SyntaxError (yyToken);
4099 $$ = new Binary (Binary.Operator.RightShift, (Expression) $1, null);
4100 lbag.AddLocation ($$, GetLocation ($2));
4104 relational_expression
4106 | relational_expression OP_LT shift_expression
4108 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, (Expression) $3);
4109 lbag.AddLocation ($$, GetLocation ($2));
4111 | relational_expression OP_GT shift_expression
4113 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, (Expression) $3);
4114 lbag.AddLocation ($$, GetLocation ($2));
4116 | relational_expression OP_LE shift_expression
4118 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, (Expression) $3);
4119 lbag.AddLocation ($$, GetLocation ($2));
4121 | relational_expression OP_GE shift_expression
4123 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, (Expression) $3);
4124 lbag.AddLocation ($$, GetLocation ($2));
4126 | relational_expression OP_LT error
4128 Error_SyntaxError (yyToken);
4130 $$ = new Binary (Binary.Operator.LessThan, (Expression) $1, null);
4131 lbag.AddLocation ($$, GetLocation ($2));
4133 | relational_expression OP_GT error
4135 Error_SyntaxError (yyToken);
4137 $$ = new Binary (Binary.Operator.GreaterThan, (Expression) $1, null);
4138 lbag.AddLocation ($$, GetLocation ($2));
4140 | relational_expression OP_LE error
4142 Error_SyntaxError (yyToken);
4144 $$ = new Binary (Binary.Operator.LessThanOrEqual, (Expression) $1, null);
4145 lbag.AddLocation ($$, GetLocation ($2));
4147 | relational_expression OP_GE error
4149 Error_SyntaxError (yyToken);
4151 $$ = new Binary (Binary.Operator.GreaterThanOrEqual, (Expression) $1, null);
4152 lbag.AddLocation ($$, GetLocation ($2));
4157 : relational_expression
4158 | equality_expression OP_EQ relational_expression
4160 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, (Expression) $3);
4161 lbag.AddLocation ($$, GetLocation ($2));
4163 | equality_expression OP_NE relational_expression
4165 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, (Expression) $3);
4166 lbag.AddLocation ($$, GetLocation ($2));
4168 | equality_expression OP_EQ error
4170 Error_SyntaxError (yyToken);
4172 $$ = new Binary (Binary.Operator.Equality, (Expression) $1, null);
4173 lbag.AddLocation ($$, GetLocation ($2));
4175 | equality_expression OP_NE error
4177 Error_SyntaxError (yyToken);
4179 $$ = new Binary (Binary.Operator.Inequality, (Expression) $1, null);
4180 lbag.AddLocation ($$, GetLocation ($2));
4185 : equality_expression
4186 | and_expression BITWISE_AND equality_expression
4188 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4189 lbag.AddLocation ($$, GetLocation ($2));
4191 | and_expression BITWISE_AND error
4193 Error_SyntaxError (yyToken);
4195 $$ = new Binary (Binary.Operator.BitwiseAnd, (Expression) $1, null);
4196 lbag.AddLocation ($$, GetLocation ($2));
4200 exclusive_or_expression
4202 | exclusive_or_expression CARRET and_expression
4204 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4205 lbag.AddLocation ($$, GetLocation ($2));
4207 | exclusive_or_expression CARRET error
4209 Error_SyntaxError (yyToken);
4211 $$ = new Binary (Binary.Operator.ExclusiveOr, (Expression) $1, null);
4212 lbag.AddLocation ($$, GetLocation ($2));
4216 inclusive_or_expression
4217 : exclusive_or_expression
4218 | inclusive_or_expression BITWISE_OR exclusive_or_expression
4220 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4221 lbag.AddLocation ($$, GetLocation ($2));
4223 | inclusive_or_expression BITWISE_OR error
4225 Error_SyntaxError (yyToken);
4227 $$ = new Binary (Binary.Operator.BitwiseOr, (Expression) $1, null);
4228 lbag.AddLocation ($$, GetLocation ($2));
4232 conditional_and_expression
4233 : inclusive_or_expression
4234 | conditional_and_expression OP_AND inclusive_or_expression
4236 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, (Expression) $3);
4237 lbag.AddLocation ($$, GetLocation ($2));
4239 | conditional_and_expression OP_AND error
4241 Error_SyntaxError (yyToken);
4243 $$ = new Binary (Binary.Operator.LogicalAnd, (Expression) $1, null);
4244 lbag.AddLocation ($$, GetLocation ($2));
4248 conditional_or_expression
4249 : conditional_and_expression
4250 | conditional_or_expression OP_OR conditional_and_expression
4252 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, (Expression) $3);
4253 lbag.AddLocation ($$, GetLocation ($2));
4255 | conditional_or_expression OP_OR error
4257 Error_SyntaxError (yyToken);
4259 $$ = new Binary (Binary.Operator.LogicalOr, (Expression) $1, null);
4260 lbag.AddLocation ($$, GetLocation ($2));
4264 null_coalescing_expression
4265 : conditional_or_expression
4266 | conditional_or_expression OP_COALESCING null_coalescing_expression
4268 if (lang_version < LanguageVersion.ISO_2)
4269 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
4271 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3);
4272 lbag.AddLocation ($$, GetLocation ($2));
4276 conditional_expression
4277 : null_coalescing_expression
4278 | null_coalescing_expression INTERR expression COLON expression
4280 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
4281 lbag.AddLocation ($$, GetLocation ($4));
4283 | null_coalescing_expression INTERR expression error
4285 Error_SyntaxError (yyToken);
4287 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4289 | null_coalescing_expression INTERR expression COLON error
4291 Error_SyntaxError (yyToken);
4293 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, null, GetLocation ($2));
4294 lbag.AddLocation ($$, GetLocation ($4));
4298 assignment_expression
4299 : prefixed_unary_expression ASSIGN expression
4301 $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
4302 lbag.AddLocation ($$, GetLocation ($2));
4304 | prefixed_unary_expression OP_MULT_ASSIGN expression
4306 $$ = new CompoundAssign (Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
4307 lbag.AddLocation ($$, GetLocation ($2));
4309 | prefixed_unary_expression OP_DIV_ASSIGN expression
4311 $$ = new CompoundAssign (Binary.Operator.Division, (Expression) $1, (Expression) $3);
4312 lbag.AddLocation ($$, GetLocation ($2));
4314 | prefixed_unary_expression OP_MOD_ASSIGN expression
4316 $$ = new CompoundAssign (Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
4317 lbag.AddLocation ($$, GetLocation ($2));
4319 | prefixed_unary_expression OP_ADD_ASSIGN expression
4321 $$ = new CompoundAssign (Binary.Operator.Addition, (Expression) $1, (Expression) $3);
4322 lbag.AddLocation ($$, GetLocation ($2));
4324 | prefixed_unary_expression OP_SUB_ASSIGN expression
4326 $$ = new CompoundAssign (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
4327 lbag.AddLocation ($$, GetLocation ($2));
4329 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4331 $$ = new CompoundAssign (Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
4332 lbag.AddLocation ($$, GetLocation ($2));
4334 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4336 $$ = new CompoundAssign (Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
4337 lbag.AddLocation ($$, GetLocation ($2));
4339 | prefixed_unary_expression OP_AND_ASSIGN expression
4341 $$ = new CompoundAssign (Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
4342 lbag.AddLocation ($$, GetLocation ($2));
4344 | prefixed_unary_expression OP_OR_ASSIGN expression
4346 $$ = new CompoundAssign (Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
4347 lbag.AddLocation ($$, GetLocation ($2));
4349 | prefixed_unary_expression OP_XOR_ASSIGN expression
4351 $$ = new CompoundAssign (Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
4352 lbag.AddLocation ($$, GetLocation ($2));
4356 lambda_parameter_list
4359 var pars = new List<Parameter> (4);
4360 pars.Add ((Parameter) $1);
4364 | lambda_parameter_list COMMA lambda_parameter
4366 var pars = (List<Parameter>) $1;
4367 Parameter p = (Parameter)$3;
4368 if (pars[0].GetType () != p.GetType ()) {
4369 report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4378 : parameter_modifier parameter_type identifier_inside_body
4380 var lt = (Tokenizer.LocatedToken) $3;
4382 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4384 | parameter_type identifier_inside_body
4386 var lt = (Tokenizer.LocatedToken) $2;
4388 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4392 var lt = (Tokenizer.LocatedToken) $1;
4393 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4397 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4398 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4402 opt_lambda_parameter_list
4403 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4404 | lambda_parameter_list {
4405 var pars_list = (List<Parameter>) $1;
4406 $$ = new ParametersCompiled (pars_list.ToArray ());
4410 lambda_expression_body
4412 start_block (Location.Null);
4414 expression // All expressions must handle error or current block won't be restored and breaking ast completely
4416 Block b = end_block (Location.Null);
4417 b.IsCompilerGenerated = true;
4418 b.AddStatement (new ContextualReturn ((Expression) $2));
4424 // Handles only cases like foo = x.FirstOrDefault (l => );
4425 // where we must restore current_variable
4426 Block b = end_block (Location.Null);
4427 b.IsCompilerGenerated = true;
4429 Error_SyntaxError (yyToken);
4438 Error_SyntaxError (yyToken);
4446 var lt = (Tokenizer.LocatedToken) $1;
4447 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4448 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4450 lambda_expression_body
4452 $$ = end_anonymous ((ParametersBlock) $4);
4453 lbag.AddLocation ($$, GetLocation ($2));
4457 var lt = (Tokenizer.LocatedToken) Error_AwaitAsIdentifier ($1);
4458 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4459 start_anonymous (true, new ParametersCompiled (p), false, lt.Location);
4461 lambda_expression_body
4463 $$ = end_anonymous ((ParametersBlock) $4);
4464 lbag.AddLocation ($$, GetLocation ($2));
4466 | ASYNC identifier_inside_body ARROW
4468 var lt = (Tokenizer.LocatedToken) $2;
4469 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4470 start_anonymous (true, new ParametersCompiled (p), true, lt.Location);
4472 lambda_expression_body
4474 $$ = end_anonymous ((ParametersBlock) $5);
4475 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
4477 | OPEN_PARENS_LAMBDA
4479 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4481 opt_lambda_parameter_list CLOSE_PARENS ARROW
4483 valid_param_mod = 0;
4484 start_anonymous (true, (ParametersCompiled) $3, false, GetLocation ($1));
4486 lambda_expression_body
4488 $$ = end_anonymous ((ParametersBlock) $7);
4489 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($4), GetLocation ($5));
4491 | ASYNC OPEN_PARENS_LAMBDA
4493 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4495 opt_lambda_parameter_list CLOSE_PARENS ARROW
4497 valid_param_mod = 0;
4498 start_anonymous (true, (ParametersCompiled) $4, true, GetLocation ($1));
4500 lambda_expression_body
4502 $$ = end_anonymous ((ParametersBlock) $8);
4503 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($5), GetLocation ($6));
4508 : assignment_expression
4509 | non_assignment_expression
4512 non_assignment_expression
4513 : conditional_expression
4518 $$ = new ArglistAccess (GetLocation ($1));
4522 undocumented_expressions
4523 : REFVALUE OPEN_PARENS non_assignment_expression COMMA type CLOSE_PARENS
4525 $$ = new RefValueExpr ((Expression) $3, (FullNamedExpression) $5, GetLocation ($1));
4526 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4528 | REFTYPE open_parens_any expression CLOSE_PARENS
4530 $$ = new RefTypeExpr ((Expression) $3, GetLocation ($1));
4531 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4533 | MAKEREF open_parens_any expression CLOSE_PARENS
4535 $$ = new MakeRefExpr ((Expression) $3, GetLocation ($1));
4536 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
4547 $$ = new BooleanExpression ((Expression) $1);
4561 type_declaration_name
4563 lexer.ConstraintsParsing = true;
4565 Class c = new Class (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1);
4566 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4567 FeatureIsNotAvailable (c.Location, "static classes");
4570 push_current_container (c, $3);
4573 opt_type_parameter_constraints_clauses
4575 lexer.ConstraintsParsing = false;
4578 current_container.SetConstraints ((List<Constraints>) $9);
4579 lbag.AddMember (current_container, mod_locations, GetLocation ($4));
4582 current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
4583 Lexer.doc_state = XmlCommentState.Allowed;
4586 lexer.parsing_modifiers = true;
4588 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4590 --lexer.parsing_declaration;
4592 Lexer.doc_state = XmlCommentState.Allowed;
4596 lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4597 $$ = pop_current_class ();
4605 { $$ = $1; } // location
4611 mod_locations = null;
4613 lexer.parsing_modifiers = false;
4617 lexer.parsing_modifiers = false;
4623 | modifiers modifier
4625 var m1 = (Modifiers) $1;
4626 var m2 = (Modifiers) $2;
4628 if ((m1 & m2) != 0) {
4629 report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4630 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4631 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4632 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4633 report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4634 "More than one protection modifier specified");
4645 StoreModifierLocation ($$, GetLocation ($1));
4647 if (current_container.Kind == MemberKind.Namespace)
4648 report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4652 $$ = Modifiers.PUBLIC;
4653 StoreModifierLocation ($$, GetLocation ($1));
4657 $$ = Modifiers.PROTECTED;
4658 StoreModifierLocation ($$, GetLocation ($1));
4662 $$ = Modifiers.INTERNAL;
4663 StoreModifierLocation ($$, GetLocation ($1));
4667 $$ = Modifiers.PRIVATE;
4668 StoreModifierLocation ($$, GetLocation ($1));
4672 $$ = Modifiers.ABSTRACT;
4673 StoreModifierLocation ($$, GetLocation ($1));
4677 $$ = Modifiers.SEALED;
4678 StoreModifierLocation ($$, GetLocation ($1));
4682 $$ = Modifiers.STATIC;
4683 StoreModifierLocation ($$, GetLocation ($1));
4687 $$ = Modifiers.READONLY;
4688 StoreModifierLocation ($$, GetLocation ($1));
4692 $$ = Modifiers.VIRTUAL;
4693 StoreModifierLocation ($$, GetLocation ($1));
4697 $$ = Modifiers.OVERRIDE;
4698 StoreModifierLocation ($$, GetLocation ($1));
4702 $$ = Modifiers.EXTERN;
4703 StoreModifierLocation ($$, GetLocation ($1));
4707 $$ = Modifiers.VOLATILE;
4708 StoreModifierLocation ($$, GetLocation ($1));
4712 $$ = Modifiers.UNSAFE;
4713 StoreModifierLocation ($$, GetLocation ($1));
4714 if (!settings.Unsafe)
4715 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4719 $$ = Modifiers.ASYNC;
4720 StoreModifierLocation ($$, GetLocation ($1));
4728 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4730 | COLON type_list error
4732 Error_SyntaxError (yyToken);
4734 current_type.AddBasesForPart ((List<FullNamedExpression>) $2);
4738 opt_type_parameter_constraints_clauses
4740 | type_parameter_constraints_clauses
4746 type_parameter_constraints_clauses
4747 : type_parameter_constraints_clause
4749 var constraints = new List<Constraints> (1);
4750 constraints.Add ((Constraints) $1);
4753 | type_parameter_constraints_clauses type_parameter_constraints_clause
4755 var constraints = (List<Constraints>) $1;
4756 Constraints new_constraint = (Constraints)$2;
4758 foreach (Constraints c in constraints) {
4759 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4760 report.Error (409, new_constraint.Location,
4761 "A constraint clause has already been specified for type parameter `{0}'",
4762 new_constraint.TypeParameter.Value);
4766 constraints.Add (new_constraint);
4771 type_parameter_constraints_clause
4772 : WHERE IDENTIFIER COLON type_parameter_constraints
4774 var lt = (Tokenizer.LocatedToken) $2;
4775 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4776 lbag.AddLocation ($$, GetLocation ($3));
4778 | WHERE IDENTIFIER error
4780 Error_SyntaxError (yyToken);
4782 var lt = (Tokenizer.LocatedToken) $2;
4783 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), null, GetLocation ($1));
4787 type_parameter_constraints
4788 : type_parameter_constraint
4790 var constraints = new List<FullNamedExpression> (1);
4791 constraints.Add ((FullNamedExpression) $1);
4794 | type_parameter_constraints COMMA type_parameter_constraint
4796 var constraints = (List<FullNamedExpression>) $1;
4797 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4798 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4799 report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4802 prev = $3 as SpecialContraintExpr;
4804 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4805 report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4807 prev = constraints [0] as SpecialContraintExpr;
4808 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4809 report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4814 constraints.Add ((FullNamedExpression) $3);
4819 type_parameter_constraint
4822 if ($1 is ComposedCast)
4823 report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4827 | NEW OPEN_PARENS CLOSE_PARENS
4829 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4830 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4834 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4838 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4842 opt_type_parameter_variance
4847 | type_parameter_variance
4849 if (lang_version <= LanguageVersion.V_3)
4850 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4856 type_parameter_variance
4859 $$ = Variance.Covariant;
4863 $$ = Variance.Contravariant;
4872 // A block is "contained" on the following places:
4874 // property_declaration as part of the accessor body (get/set)
4875 // operator_declaration
4876 // constructor_declaration
4877 // destructor_declaration
4878 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4883 ++lexer.parsing_block;
4884 start_block (GetLocation ($1));
4886 opt_statement_list block_end
4895 --lexer.parsing_block;
4896 $$ = end_block (GetLocation ($1));
4898 | COMPLETE_COMPLETION
4900 --lexer.parsing_block;
4901 $$ = end_block (lexer.Location);
4909 ++lexer.parsing_block;
4910 current_block.StartLocation = GetLocation ($1);
4912 opt_statement_list CLOSE_BRACE
4914 --lexer.parsing_block;
4915 $$ = end_block (GetLocation ($4));
4926 | statement_list statement
4930 : block_variable_declaration
4932 current_block.AddStatement ((Statement) $1);
4934 | valid_declaration_statement
4936 current_block.AddStatement ((Statement) $1);
4941 Error_SyntaxError (yyToken);
4947 // The interactive_statement and its derivatives are only
4948 // used to provide a special version of `expression_statement'
4949 // that has a side effect of assigning the expression to
4952 interactive_statement_list
4953 : interactive_statement
4954 | interactive_statement_list interactive_statement
4957 interactive_statement
4958 : block_variable_declaration
4960 current_block.AddStatement ((Statement) $1);
4962 | interactive_valid_declaration_statement
4964 current_block.AddStatement ((Statement) $1);
4969 valid_declaration_statement
4972 | expression_statement
4973 | selection_statement
4974 | iteration_statement
4978 | unchecked_statement
4985 interactive_valid_declaration_statement
4988 | interactive_expression_statement
4989 | selection_statement
4990 | iteration_statement
4994 | unchecked_statement
5002 : valid_declaration_statement
5003 | block_variable_declaration
5005 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5010 report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
5015 Error_SyntaxError (yyToken);
5016 $$ = new EmptyStatement (GetLocation ($1));
5023 // Uses lexer.Location because semicolon location is not kept in quick mode
5024 $$ = new EmptyStatement (lexer.Location);
5029 : identifier_inside_body COLON
5031 var lt = (Tokenizer.LocatedToken) $1;
5032 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
5033 lbag.AddLocation (labeled, GetLocation ($2));
5034 current_block.AddLabel (labeled);
5035 current_block.AddStatement (labeled);
5041 : variable_type_simple
5042 | variable_type_simple rank_specifiers
5045 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
5047 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5052 * The following is from Rhys' grammar:
5053 * > Types in local variable declarations must be recognized as
5054 * > expressions to prevent reduce/reduce errors in the grammar.
5055 * > The expressions are converted into types during semantic analysis.
5057 variable_type_simple
5058 : primary_expression_or_type opt_nullable
5060 // Ok, the above "primary_expression" is there to get rid of
5061 // both reduce/reduce and shift/reduces in the grammar, it should
5062 // really just be "type_name". If you use type_name, a reduce/reduce
5063 // creeps up. If you use namespace_or_type_name (which is all we need
5064 // really) two shift/reduces appear.
5067 // So the super-trick is that primary_expression
5068 // can only be either a SimpleName or a MemberAccess.
5069 // The MemberAccess case arises when you have a fully qualified type-name like :
5071 // SimpleName is when you have
5074 Expression expr = (Expression) $1;
5076 SimpleName sn = expr as SimpleName;
5077 if (sn != null && sn.Name == "var")
5078 $$ = new VarExpr (sn.Location);
5081 } else if (expr is ATypeNameExpression) {
5082 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
5084 Error_ExpectingTypeName (expr);
5088 | primary_expression_or_type pointer_stars
5090 ATypeNameExpression expr = $1 as ATypeNameExpression;
5093 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
5095 Error_ExpectingTypeName ((Expression)$1);
5099 | builtin_types opt_nullable
5104 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5106 | builtin_types pointer_stars
5108 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
5110 | VOID pointer_stars
5112 $$ = new ComposedCast (new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1)), (ComposedTypeSpecifier) $2);
5116 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), report);
5117 $$ = new TypeExpression (compiler.BuiltinTypes.Void, GetLocation ($1));
5123 | pointer_star pointer_stars
5125 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
5133 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
5137 identifier_inside_body
5141 $$ = Error_AwaitAsIdentifier ($1);
5145 block_variable_declaration
5146 : variable_type identifier_inside_body
5148 var lt = (Tokenizer.LocatedToken) $2;
5149 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5150 current_block.AddLocalName (li);
5151 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5153 opt_local_variable_initializer opt_variable_declarators SEMICOLON
5155 $$ = current_variable;
5156 current_variable = null;
5157 lbag.AddLocation ($$, GetLocation ($6));
5159 | CONST variable_type identifier_inside_body
5161 var lt = (Tokenizer.LocatedToken) $3;
5162 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5163 current_block.AddLocalName (li);
5164 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
5166 const_variable_initializer opt_const_declarators SEMICOLON
5168 $$ = current_variable;
5169 current_variable = null;
5170 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
5174 opt_local_variable_initializer
5176 | ASSIGN block_variable_initializer
5178 current_variable.Initializer = (Expression) $2;
5183 if (yyToken == Token.OPEN_BRACKET_EXPR) {
5184 report.Error (650, lexer.Location,
5185 "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");
5187 Error_SyntaxError (yyToken);
5192 opt_variable_declarators
5194 | variable_declarators
5197 opt_using_or_fixed_variable_declarators
5199 | variable_declarators
5201 foreach (var d in current_variable.Declarators) {
5202 if (d.Initializer == null)
5203 Error_MissingInitializer (d.Variable.Location);
5208 variable_declarators
5209 : variable_declarator
5210 | variable_declarators variable_declarator
5214 : COMMA identifier_inside_body
5216 var lt = (Tokenizer.LocatedToken) $2;
5217 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5218 var d = new BlockVariableDeclaration.Declarator (li, null);
5219 current_variable.AddDeclarator (d);
5220 current_block.AddLocalName (li);
5221 lbag.AddLocation (d, GetLocation ($1));
5223 | COMMA identifier_inside_body ASSIGN block_variable_initializer
5225 var lt = (Tokenizer.LocatedToken) $2;
5226 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
5227 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5228 current_variable.AddDeclarator (d);
5229 current_block.AddLocalName (li);
5230 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5234 const_variable_initializer
5237 report.Error (145, lexer.Location, "A const field requires a value to be provided");
5239 | ASSIGN constant_initializer_expr
5241 current_variable.Initializer = (Expression) $2;
5245 opt_const_declarators
5252 | const_declarators const_declarator
5256 : COMMA identifier_inside_body ASSIGN constant_initializer_expr
5258 var lt = (Tokenizer.LocatedToken) $2;
5259 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
5260 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
5261 current_variable.AddDeclarator (d);
5262 current_block.AddLocalName (li);
5263 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
5267 block_variable_initializer
5268 : variable_initializer
5269 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
5271 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
5272 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
5274 | STACKALLOC simple_type
5276 report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
5277 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
5281 expression_statement
5282 : statement_expression SEMICOLON
5285 lbag.AddStatement ($$, GetLocation ($2));
5287 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
5288 | statement_expression CLOSE_BRACE
5291 report.Error (1002, GetLocation ($2), "; expected");
5292 lexer.putback ('}');
5296 interactive_expression_statement
5297 : interactive_statement_expression SEMICOLON { $$ = $1; }
5298 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
5302 // We have to do the wrapping here and not in the case above,
5303 // because statement_expression is used for example in for_statement
5305 statement_expression
5308 ExpressionStatement s = $1 as ExpressionStatement;
5310 var expr = $1 as Expression;
5311 expr.Error_InvalidExpressionStatement (report);
5312 $$ = new StatementErrorExpression (expr);
5314 $$ = new StatementExpression (s);
5319 interactive_statement_expression
5322 Expression expr = (Expression) $1;
5323 ExpressionStatement s;
5325 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
5326 $$ = new StatementExpression (s);
5330 Error_SyntaxError (yyToken);
5331 $$ = new EmptyStatement (GetLocation ($1));
5341 : IF open_parens_any boolean_expression CLOSE_PARENS
5344 if ($5 is EmptyStatement)
5345 Warning_EmptyStatement (GetLocation ($5));
5347 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5348 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5350 | IF open_parens_any boolean_expression CLOSE_PARENS
5351 embedded_statement ELSE embedded_statement
5353 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
5354 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5356 if ($5 is EmptyStatement)
5357 Warning_EmptyStatement (GetLocation ($5));
5358 if ($7 is EmptyStatement)
5359 Warning_EmptyStatement (GetLocation ($7));
5361 | IF open_parens_any boolean_expression error
5363 Error_SyntaxError (yyToken);
5365 $$ = new If ((BooleanExpression) $3, null, GetLocation ($1));
5366 lbag.AddStatement ($$, GetLocation ($2));
5371 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
5373 start_block (GetLocation ($5));
5375 opt_switch_sections CLOSE_BRACE
5377 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, GetLocation ($1));
5378 end_block (GetLocation ($8));
5379 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5381 | SWITCH open_parens_any expression error
5383 Error_SyntaxError (yyToken);
5385 $$ = new Switch ((Expression) $3, null, GetLocation ($1));
5386 lbag.AddStatement ($$, GetLocation ($2));
5393 report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
5400 | switch_sections switch_section
5403 Error_SyntaxError (yyToken);
5408 : switch_labels statement_list
5414 var label = (SwitchLabel) $1;
5415 label.SectionStart = true;
5416 current_block.AddStatement (label);
5418 | switch_labels switch_label
5420 current_block.AddStatement ((Statement) $2);
5425 : CASE constant_expression COLON
5427 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5428 lbag.AddLocation ($$, GetLocation ($3));
5430 | CASE constant_expression error
5432 Error_SyntaxError (yyToken);
5433 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5437 $$ = new SwitchLabel (null, GetLocation ($1));
5449 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5451 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5452 Warning_EmptyStatement (GetLocation ($5));
5454 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5455 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5457 | WHILE open_parens_any boolean_expression error
5459 Error_SyntaxError (yyToken);
5461 $$ = new While ((BooleanExpression) $3, null, GetLocation ($1));
5462 lbag.AddStatement ($$, GetLocation ($2));
5467 : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5469 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5470 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5472 | DO embedded_statement error
5474 Error_SyntaxError (yyToken);
5475 $$ = new Do ((Statement) $2, null, GetLocation ($1), Location.Null);
5477 | DO embedded_statement WHILE open_parens_any boolean_expression error
5479 Error_SyntaxError (yyToken);
5481 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1), GetLocation ($3));
5482 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4));
5487 : FOR open_parens_any
5489 start_block (GetLocation ($2));
5490 current_block.IsCompilerGenerated = true;
5491 For f = new For (GetLocation ($1));
5492 current_block.AddStatement (f);
5501 // Has to use be extra rule to recover started block
5503 : opt_for_initializer SEMICOLON
5505 ((For) $0).Initializer = (Statement) $1;
5507 // Pass the "For" object to the iterator_part4
5508 oob_stack.Push ($0);
5510 for_condition_and_iterator_part
5513 var locations = (Tuple<Location,Location>) $4;
5515 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5516 Warning_EmptyStatement (GetLocation ($5));
5519 f.Statement = (Statement) $5;
5520 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation (locations.Item1), GetLocation (locations.Item2));
5522 $$ = end_block (GetLocation ($2));
5526 Error_SyntaxError (yyToken);
5527 $$ = end_block (current_block.StartLocation);
5531 for_condition_and_iterator_part
5532 : opt_for_condition SEMICOLON
5534 For f = (For) oob_stack.Peek ();
5535 f.Condition = (BooleanExpression) $1;
5538 $$ = new Tuple<Location,Location> (GetLocation ($2), (Location) $4);
5541 // Handle errors in the case of opt_for_condition being followed by
5542 // a close parenthesis
5543 | opt_for_condition close_parens_close_brace {
5544 report.Error (1525, GetLocation ($2), "Unexpected symbol `}'");
5545 For f = (For) oob_stack.Peek ();
5546 f.Condition = (BooleanExpression) $1;
5547 $$ = new Tuple<Location,Location> (GetLocation ($2), GetLocation ($2));
5552 : opt_for_iterator CLOSE_PARENS {
5553 For f = (For) oob_stack.Peek ();
5554 f.Iterator = (Statement) $1;
5555 $$ = GetLocation ($2);
5557 | opt_for_iterator CLOSE_BRACE {
5558 report.Error (1525, GetLocation ($2), "Unexpected symbol expected ')'");
5559 For f = (For) oob_stack.Peek ();
5560 f.Iterator = (Statement) $1;
5561 $$ = GetLocation ($2);
5565 close_parens_close_brace
5567 | CLOSE_BRACE { lexer.putback ('}'); }
5571 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5576 : variable_type identifier_inside_body
5578 var lt = (Tokenizer.LocatedToken) $2;
5579 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5580 current_block.AddLocalName (li);
5581 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5583 opt_local_variable_initializer opt_variable_declarators
5585 $$ = current_variable;
5586 current_variable = null;
5588 | statement_expression_list
5592 : /* empty */ { $$ = null; }
5593 | boolean_expression
5597 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5602 : statement_expression_list
5605 statement_expression_list
5606 : statement_expression
5607 | statement_expression_list COMMA statement_expression
5609 var sl = $1 as StatementList;
5611 sl = new StatementList ((Statement) $1, (Statement) $3);
5612 lbag.AddStatement (sl, GetLocation ($2));
5614 sl.Add ((Statement) $3);
5615 lbag.AppendTo (sl, GetLocation ($2));
5623 : FOREACH open_parens_any type error
5625 report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5627 start_block (GetLocation ($2));
5628 current_block.IsCompilerGenerated = true;
5630 Foreach f = new Foreach ((Expression) $3, null, null, null, null, GetLocation ($1));
5631 current_block.AddStatement (f);
5633 lbag.AddStatement (f, GetLocation ($2));
5634 $$ = end_block (GetLocation ($4));
5636 | FOREACH open_parens_any type identifier_inside_body error
5638 Error_SyntaxError (yyToken);
5640 start_block (GetLocation ($2));
5641 current_block.IsCompilerGenerated = true;
5643 var lt = (Tokenizer.LocatedToken) $4;
5644 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5645 current_block.AddLocalName (li);
5647 Foreach f = new Foreach ((Expression) $3, li, null, null, null, GetLocation ($1));
5648 current_block.AddStatement (f);
5650 lbag.AddStatement (f, GetLocation ($2));
5651 $$ = end_block (GetLocation ($5));
5653 | FOREACH open_parens_any type identifier_inside_body IN expression CLOSE_PARENS
5655 start_block (GetLocation ($2));
5656 current_block.IsCompilerGenerated = true;
5658 var lt = (Tokenizer.LocatedToken) $4;
5659 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5660 current_block.AddLocalName (li);
5665 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5666 Warning_EmptyStatement (GetLocation ($9));
5668 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, current_block, GetLocation ($1));
5669 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5670 end_block (GetLocation ($7));
5678 | continue_statement
5688 $$ = new Break (GetLocation ($1));
5689 lbag.AddStatement ($$, GetLocation ($2));
5694 : CONTINUE SEMICOLON
5696 $$ = new Continue (GetLocation ($1));
5697 lbag.AddStatement ($$, GetLocation ($2));
5701 Error_SyntaxError (yyToken);
5702 $$ = new Continue (GetLocation ($1));
5707 : GOTO identifier_inside_body SEMICOLON
5709 var lt = (Tokenizer.LocatedToken) $2;
5710 $$ = new Goto (lt.Value, GetLocation ($1));
5711 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5713 | GOTO CASE constant_expression SEMICOLON
5715 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5716 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5718 | GOTO DEFAULT SEMICOLON
5720 $$ = new GotoDefault (GetLocation ($1));
5721 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5726 : RETURN opt_expression SEMICOLON
5728 $$ = new Return ((Expression) $2, GetLocation ($1));
5729 lbag.AddStatement ($$, GetLocation ($3));
5731 | RETURN expression error
5733 Error_SyntaxError (yyToken);
5734 $$ = new Return ((Expression) $2, GetLocation ($1));
5738 Error_SyntaxError (yyToken);
5739 $$ = new Return (null, GetLocation ($1));
5744 : THROW opt_expression SEMICOLON
5746 $$ = new Throw ((Expression) $2, GetLocation ($1));
5747 lbag.AddStatement ($$, GetLocation ($3));
5751 Error_SyntaxError (yyToken);
5752 $$ = new Throw (null, GetLocation ($1));
5757 : identifier_inside_body RETURN opt_expression SEMICOLON
5759 var lt = (Tokenizer.LocatedToken) $1;
5760 string s = lt.Value;
5762 report.Error (1003, lt.Location, "; expected");
5763 } else if ($3 == null) {
5764 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5765 } else if (lang_version == LanguageVersion.ISO_1){
5766 FeatureIsNotAvailable (lt.Location, "iterators");
5769 current_block.Explicit.RegisterIteratorYield ();
5770 $$ = new Yield ((Expression) $3, lt.Location);
5771 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5773 | identifier_inside_body RETURN expression error
5775 Error_SyntaxError (yyToken);
5777 var lt = (Tokenizer.LocatedToken) $1;
5778 string s = lt.Value;
5780 report.Error (1003, lt.Location, "; expected");
5781 } else if ($3 == null) {
5782 report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5783 } else if (lang_version == LanguageVersion.ISO_1){
5784 FeatureIsNotAvailable (lt.Location, "iterators");
5787 current_block.Explicit.RegisterIteratorYield ();
5788 $$ = new Yield ((Expression) $3, lt.Location);
5789 lbag.AddStatement ($$, GetLocation ($2));
5791 | identifier_inside_body BREAK SEMICOLON
5793 var lt = (Tokenizer.LocatedToken) $1;
5794 string s = lt.Value;
5796 report.Error (1003, lt.Location, "; expected");
5797 } else if (lang_version == LanguageVersion.ISO_1){
5798 FeatureIsNotAvailable (lt.Location, "iterators");
5801 current_block.Explicit.RegisterIteratorYield ();
5802 $$ = new YieldBreak (lt.Location);
5803 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5813 : TRY block catch_clauses
5815 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5817 | TRY block FINALLY block
5819 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5820 lbag.AddStatement ($$, GetLocation ($3));
5822 | TRY block catch_clauses FINALLY block
5824 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, Location.Null, true), (Block) $5, GetLocation ($1));
5825 lbag.AddStatement ($$, GetLocation ($4));
5829 Error_SyntaxError (1524, yyToken);
5830 $$ = new TryCatch ((Block) $2, null, GetLocation ($1), false);
5837 var l = new List<Catch> (2);
5842 | catch_clauses catch_clause
5844 var l = (List<Catch>) $1;
5846 Catch c = (Catch) $2;
5847 if (l [l.Count - 1].IsGeneral) {
5848 report.Error (1017, c.loc, "Try statement already has an empty catch block");
5858 | identifier_inside_body
5864 $$ = new Catch ((Block) $2, GetLocation ($1));
5866 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5868 start_block (GetLocation ($2));
5869 var c = new Catch (current_block, GetLocation ($1));
5870 c.TypeExpression = (FullNamedExpression) $3;
5873 var lt = (Tokenizer.LocatedToken) $4;
5874 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5875 current_block.AddLocalName (c.Variable);
5878 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5885 | CATCH open_parens_any error
5887 if (yyToken == Token.CLOSE_PARENS) {
5888 report.Error (1015, lexer.Location,
5889 "A type that derives from `System.Exception', `object', or `string' expected");
5891 Error_SyntaxError (yyToken);
5894 $$ = new Catch (null, GetLocation ($1));
5896 | CATCH open_parens_any type opt_identifier CLOSE_PARENS error
5898 Error_SyntaxError (yyToken);
5900 // Required otherwise missing block could not be detected because
5901 // start_block is run early
5902 var c = new Catch (null, GetLocation ($1));
5903 c.TypeExpression = (FullNamedExpression) $3;
5906 var lt = (Tokenizer.LocatedToken) $4;
5907 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5910 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5919 $$ = new Checked ((Block) $2, GetLocation ($1));
5926 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5933 if (!settings.Unsafe)
5934 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5936 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5941 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5943 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5944 Warning_EmptyStatement (GetLocation ($5));
5946 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5947 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5949 | LOCK open_parens_any expression error
5951 Error_SyntaxError (yyToken);
5953 $$ = new Lock ((Expression) $3, null, GetLocation ($1));
5954 lbag.AddStatement ($$, GetLocation ($2));
5959 : FIXED open_parens_any variable_type identifier_inside_body
5961 start_block (GetLocation ($2));
5963 current_block.IsCompilerGenerated = true;
5964 var lt = (Tokenizer.LocatedToken) $4;
5965 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5966 current_block.AddLocalName (li);
5967 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5969 using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators CLOSE_PARENS
5971 $$ = current_variable;
5972 current_variable = null;
5976 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5977 Warning_EmptyStatement (GetLocation ($10));
5979 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5980 current_block.AddStatement (f);
5981 $$ = end_block (GetLocation ($8));
5986 : USING open_parens_any variable_type identifier_inside_body
5988 start_block (GetLocation ($2));
5990 current_block.IsCompilerGenerated = true;
5991 var lt = (Tokenizer.LocatedToken) $4;
5992 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5993 current_block.AddLocalName (li);
5994 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5996 using_initialization CLOSE_PARENS
5998 $$ = current_variable;
5999 current_variable = null;
6003 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6004 Warning_EmptyStatement (GetLocation ($9));
6006 Using u = new Using ((Using.VariableDeclaration) $8, (Statement) $9, GetLocation ($1));
6007 current_block.AddStatement (u);
6008 $$ = end_block (GetLocation ($7));
6010 | USING open_parens_any expression CLOSE_PARENS embedded_statement
6012 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
6013 Warning_EmptyStatement (GetLocation ($5));
6015 $$ = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
6016 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
6018 | USING open_parens_any expression error
6020 Error_SyntaxError (yyToken);
6022 $$ = new Using ((Expression) $3, null, GetLocation ($1));
6023 lbag.AddStatement ($$, GetLocation ($2));
6027 using_initialization
6028 : using_or_fixed_variable_initializer opt_using_or_fixed_variable_declarators
6031 // It has to be here for the parent to safely restore artificial block
6032 Error_SyntaxError (yyToken);
6036 using_or_fixed_variable_initializer
6039 Error_MissingInitializer (lexer.Location);
6041 | ASSIGN variable_initializer
6043 current_variable.Initializer = (Expression) $2;
6044 $$ = current_variable;
6052 : first_from_clause query_body
6054 lexer.query_parsing = false;
6056 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6058 from.Tail.Next = (Linq.AQueryClause)$2;
6061 current_block.SetEndLocation (lexer.Location);
6062 current_block = current_block.Parent;
6064 | nested_from_clause query_body
6066 Linq.AQueryClause from = $1 as Linq.AQueryClause;
6068 from.Tail.Next = (Linq.AQueryClause)$2;
6071 current_block.SetEndLocation (lexer.Location);
6072 current_block = current_block.Parent;
6075 // Bubble up COMPLETE_COMPLETION productions
6076 | first_from_clause COMPLETE_COMPLETION {
6077 lexer.query_parsing = false;
6080 current_block.SetEndLocation (lexer.Location);
6081 current_block = current_block.Parent;
6083 | nested_from_clause COMPLETE_COMPLETION {
6085 current_block.SetEndLocation (lexer.Location);
6086 current_block = current_block.Parent;
6091 : FROM_FIRST identifier_inside_body IN expression
6093 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6095 var lt = (Tokenizer.LocatedToken) $2;
6096 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6097 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6099 | FROM_FIRST type identifier_inside_body IN expression
6101 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6103 var lt = (Tokenizer.LocatedToken) $3;
6104 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6105 $$ = new Linq.QueryExpression (
6106 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6107 IdentifierType = (FullNamedExpression)$2
6114 : FROM identifier_inside_body IN expression
6116 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6118 var lt = (Tokenizer.LocatedToken) $2;
6119 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6120 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
6122 | FROM type identifier_inside_body IN expression
6124 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6126 var lt = (Tokenizer.LocatedToken) $3;
6127 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6128 $$ = new Linq.QueryExpression (
6129 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
6130 IdentifierType = (FullNamedExpression)$2
6137 : FROM identifier_inside_body IN
6139 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6143 var lt = (Tokenizer.LocatedToken) $2;
6144 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6145 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
6147 current_block.SetEndLocation (lexer.Location);
6148 current_block = current_block.Parent;
6150 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6152 | FROM type identifier_inside_body IN
6154 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6158 var lt = (Tokenizer.LocatedToken) $3;
6159 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6161 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
6162 IdentifierType = (FullNamedExpression)$2
6165 current_block.SetEndLocation (lexer.Location);
6166 current_block = current_block.Parent;
6168 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6173 : query_body_clauses select_or_group_clause opt_query_continuation
6175 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6178 head.Next = (Linq.AQueryClause)$3;
6181 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6182 clause.Tail.Next = head;
6188 | select_or_group_clause opt_query_continuation
6190 Linq.AQueryClause head = (Linq.AQueryClause)$2;
6193 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
6194 clause.Tail.Next = head;
6200 | query_body_clauses COMPLETE_COMPLETION
6201 | query_body_clauses error
6203 report.Error (742, GetLocation ($2), "Unexpected symbol `{0}'. A query body must end with select or group clause", GetSymbolName (yyToken));
6208 Error_SyntaxError (yyToken);
6213 select_or_group_clause
6216 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6220 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6222 current_block.SetEndLocation (lexer.Location);
6223 current_block = current_block.Parent;
6227 if (linq_clause_blocks == null)
6228 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6230 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6231 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
6235 current_block.SetEndLocation (lexer.Location);
6236 current_block = current_block.Parent;
6238 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6240 BY expression_or_error
6242 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
6243 lbag.AddLocation ($$, GetLocation ($5));
6245 current_block.SetEndLocation (lexer.Location);
6246 current_block = current_block.Parent;
6252 | query_body_clauses query_body_clause
6254 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
6268 : LET identifier_inside_body ASSIGN
6270 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6274 var lt = (Tokenizer.LocatedToken) $2;
6275 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6276 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
6277 lbag.AddLocation ($$, GetLocation ($3));
6279 current_block.SetEndLocation (lexer.Location);
6280 current_block = current_block.Parent;
6282 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6289 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6293 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
6295 current_block.SetEndLocation (lexer.Location);
6296 current_block = current_block.Parent;
6301 : JOIN identifier_inside_body IN
6303 if (linq_clause_blocks == null)
6304 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6306 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6307 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6309 expression_or_error ON
6311 current_block.SetEndLocation (lexer.Location);
6312 current_block = current_block.Parent;
6314 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6315 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6317 expression_or_error EQUALS
6319 current_block.AddStatement (new ContextualReturn ((Expression) $8));
6320 current_block.SetEndLocation (lexer.Location);
6321 current_block = current_block.Parent;
6323 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6325 expression_or_error opt_join_into
6327 current_block.AddStatement (new ContextualReturn ((Expression) $11));
6328 current_block.SetEndLocation (lexer.Location);
6330 var outer_selector = linq_clause_blocks.Pop ();
6331 var block = linq_clause_blocks.Pop ();
6333 var lt = (Tokenizer.LocatedToken) $2;
6334 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6335 Linq.RangeVariable into;
6339 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
6340 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9));
6343 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6345 var parent = block.Parent;
6346 while (parent is Linq.QueryBlock) {
6347 parent = parent.Parent;
6349 current_block.Parent = parent;
6351 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6353 lt = (Tokenizer.LocatedToken) $12;
6354 into = new Linq.RangeVariable (lt.Value, lt.Location);
6356 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
6357 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($12));
6360 current_block = block.Parent;
6361 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6363 | JOIN type identifier_inside_body IN
6365 if (linq_clause_blocks == null)
6366 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6368 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6369 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6371 expression_or_error ON
6373 current_block.SetEndLocation (lexer.Location);
6374 current_block = current_block.Parent;
6376 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6377 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6379 expression_or_error EQUALS
6381 current_block.AddStatement (new ContextualReturn ((Expression) $9));
6382 current_block.SetEndLocation (lexer.Location);
6383 current_block = current_block.Parent;
6385 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6387 expression_or_error opt_join_into
6389 current_block.AddStatement (new ContextualReturn ((Expression) $12));
6390 current_block.SetEndLocation (lexer.Location);
6392 var outer_selector = linq_clause_blocks.Pop ();
6393 var block = linq_clause_blocks.Pop ();
6395 var lt = (Tokenizer.LocatedToken) $3;
6396 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
6397 Linq.RangeVariable into;
6401 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
6402 IdentifierType = (FullNamedExpression)$2
6406 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
6408 var parent = block.Parent;
6409 while (parent is Linq.QueryBlock) {
6410 parent = parent.Parent;
6412 current_block.Parent = parent;
6414 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
6416 lt = (Tokenizer.LocatedToken) $13;
6417 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
6419 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
6420 IdentifierType = (FullNamedExpression)$2
6424 current_block = block.Parent;
6425 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
6431 | INTO identifier_inside_body
6440 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6444 current_block.SetEndLocation (lexer.Location);
6445 current_block = current_block.Parent;
6455 current_block.SetEndLocation (lexer.Location);
6456 current_block = current_block.Parent;
6458 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6462 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
6469 | orderings_then_by COMMA
6471 current_block.SetEndLocation (lexer.Location);
6472 current_block = current_block.Parent;
6474 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
6478 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
6486 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6488 | expression ASCENDING
6490 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6491 lbag.AddLocation ($$, GetLocation ($2));
6493 | expression DESCENDING
6495 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6496 lbag.AddLocation ($$, GetLocation ($2));
6503 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6505 | expression ASCENDING
6507 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
6508 lbag.AddLocation ($$, GetLocation ($2));
6510 | expression DESCENDING
6512 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
6513 lbag.AddLocation ($$, GetLocation ($2));
6518 opt_query_continuation
6520 | INTO identifier_inside_body
6522 // query continuation block is not linked with query block but with block
6523 // before. This means each query can use same range variable names for
6524 // different identifiers.
6526 current_block.SetEndLocation (GetLocation ($1));
6527 current_block = current_block.Parent;
6529 current_block = new Linq.QueryBlock (current_block, lexer.Location);
6531 if (linq_clause_blocks == null)
6532 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
6534 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
6538 var current_block = linq_clause_blocks.Pop ();
6539 var lt = (Tokenizer.LocatedToken) $2;
6540 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
6541 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
6542 next = (Linq.AQueryClause)$4
6548 // Support for using the compiler as an interactive parser
6550 // The INTERACTIVE_PARSER token is first sent to parse our
6551 // productions; If the result is a Statement, the parsing
6552 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
6553 // to setup the blocks in advance.
6555 // This setup is here so that in the future we can add
6556 // support for other constructs (type parsing, namespaces, etc)
6557 // that do not require a block to be setup in advance
6561 : EVAL_STATEMENT_PARSER EOF
6562 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
6563 | EVAL_STATEMENT_PARSER
6565 current_container = current_type = new Class (current_container, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
6567 // (ref object retval)
6568 Parameter [] mpar = new Parameter [1];
6569 mpar [0] = new Parameter (new TypeExpression (compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
6571 ParametersCompiled pars = new ParametersCompiled (mpar);
6572 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
6573 if (settings.Unsafe)
6574 mods |= Modifiers.UNSAFE;
6576 current_local_parameters = pars;
6577 Method method = new Method (
6579 new TypeExpression (compiler.BuiltinTypes.Void, Location.Null),
6581 new MemberName ("Host"),
6583 null /* attributes */);
6585 current_type.AddMember (method);
6587 oob_stack.Push (method);
6588 ++lexer.parsing_block;
6589 start_block (lexer.Location);
6591 interactive_statement_list opt_COMPLETE_COMPLETION
6593 --lexer.parsing_block;
6594 Method method = (Method) oob_stack.Pop ();
6596 method.Block = (ToplevelBlock) end_block(lexer.Location);
6598 InteractiveResult = (Class) pop_current_class ();
6599 current_local_parameters = null;
6601 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
6604 interactive_compilation_unit
6605 : opt_extern_alias_directives opt_using_directives
6606 | opt_extern_alias_directives opt_using_directives namespace_or_type_declarations
6609 opt_COMPLETE_COMPLETION
6611 | COMPLETE_COMPLETION
6614 close_brace_or_complete_completion
6616 | COMPLETE_COMPLETION
6620 // XML documentation code references micro parser
6622 documentation_parsing
6625 module.DocumentationBuilder.ParsedName = (MemberName) $2;
6630 : doc_type_declaration_name opt_doc_method_sig
6632 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6634 | builtin_types opt_doc_method_sig
6636 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6637 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$2;
6640 | builtin_types DOT IDENTIFIER opt_doc_method_sig
6642 module.DocumentationBuilder.ParsedBuiltinType = (TypeExpression)$1;
6643 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$4;
6644 var lt = (Tokenizer.LocatedToken) $3;
6645 $$ = new MemberName (lt.Value);
6647 | doc_type_declaration_name DOT THIS
6649 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6651 | doc_type_declaration_name DOT THIS OPEN_BRACKET
6653 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6655 opt_doc_parameters CLOSE_BRACKET
6657 module.DocumentationBuilder.ParsedParameters = (List<DocumentationParameter>)$6;
6658 $$ = new MemberName ((MemberName) $1, MemberCache.IndexerNameAlias, Location.Null);
6660 | EXPLICIT OPERATOR type opt_doc_method_sig
6662 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6663 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6664 module.DocumentationBuilder.ParsedParameters = p;
6665 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Explicit;
6668 | IMPLICIT OPERATOR type opt_doc_method_sig
6670 var p = (List<DocumentationParameter>)$4 ?? new List<DocumentationParameter> (1);
6671 p.Add (new DocumentationParameter ((FullNamedExpression) $3));
6672 module.DocumentationBuilder.ParsedParameters = p;
6673 module.DocumentationBuilder.ParsedOperator = Operator.OpType.Implicit;
6676 | OPERATOR overloadable_operator opt_doc_method_sig
6678 var p = (List<DocumentationParameter>)$3 ?? new List<DocumentationParameter> (1);
6679 module.DocumentationBuilder.ParsedParameters = p;
6680 module.DocumentationBuilder.ParsedOperator = (Operator.OpType) $2;
6685 doc_type_declaration_name
6686 : type_declaration_name
6687 | doc_type_declaration_name DOT type_declaration_name
6689 $$ = new MemberName (((MemberName) $1), (MemberName) $3);
6697 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
6699 opt_doc_parameters CLOSE_PARENS
6708 $$ = new List<DocumentationParameter> (0);
6716 var parameters = new List<DocumentationParameter> ();
6717 parameters.Add ((DocumentationParameter) $1);
6720 | doc_parameters COMMA doc_parameter
6722 var parameters = $1 as List<DocumentationParameter>;
6723 parameters.Add ((DocumentationParameter) $3);
6729 : opt_parameter_modifier parameter_type
6732 $$ = new DocumentationParameter ((Parameter.Modifier) $1, (FullNamedExpression) $2);
6734 $$ = new DocumentationParameter ((FullNamedExpression) $2);
6741 // A class used to hold info about an operator declarator
6743 class OperatorDeclaration {
6744 public readonly Operator.OpType optype;
6745 public readonly FullNamedExpression ret_type;
6746 public readonly Location location;
6748 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6751 this.ret_type = ret_type;
6752 this.location = location;
6756 void Error_ExpectingTypeName (Expression expr)
6758 if (expr is Invocation){
6759 report.Error (1002, expr.Location, "Expecting `;'");
6761 expr.Error_InvalidExpressionStatement (report);
6765 void Error_ParameterModifierNotValid (string modifier, Location loc)
6767 report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6771 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6773 report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6774 Parameter.GetModifierSignature (mod));
6777 void Error_TypeExpected (Location loc)
6779 report.Error (1031, loc, "Type expected");
6782 void Error_UnsafeCodeNotAllowed (Location loc)
6784 report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6787 void Warning_EmptyStatement (Location loc)
6789 report.Warning (642, 3, loc, "Possible mistaken empty statement");
6792 void Error_NamedArgumentExpected (NamedArgument a)
6794 report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6797 void Error_MissingInitializer (Location loc)
6799 report.Error (210, loc, "You must provide an initializer in a fixed or using statement declaration");
6802 object Error_AwaitAsIdentifier (object token)
6805 report.Error (4003, GetLocation (token), "`await' cannot be used as an identifier within an async method or lambda expression");
6806 return new Tokenizer.LocatedToken ("await", GetLocation (token));
6812 void push_current_container (TypeDefinition tc, object partial_token)
6814 if (module.Evaluator != null){
6815 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6819 undo.AddTypeContainer (current_container, tc);
6822 if (partial_token != null)
6823 current_container.AddPartial (tc);
6825 current_container.AddTypeContainer (tc);
6827 ++lexer.parsing_declaration;
6828 current_container = tc;
6832 TypeContainer pop_current_class ()
6834 var retval = current_container;
6836 current_container = current_container.Parent;
6837 current_type = current_type.Parent as TypeDefinition;
6842 [System.Diagnostics.Conditional ("FULL_AST")]
6843 void StoreModifierLocation (object token, Location loc)
6848 if (mod_locations == null)
6849 mod_locations = new List<Tuple<Modifiers, Location>> ();
6851 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6854 string CheckAttributeTarget (string a, Location l)
6857 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6861 report.Warning (658, 1, l,
6862 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6863 return string.Empty;
6866 static bool IsUnaryOperator (Operator.OpType op)
6870 case Operator.OpType.LogicalNot:
6871 case Operator.OpType.OnesComplement:
6872 case Operator.OpType.Increment:
6873 case Operator.OpType.Decrement:
6874 case Operator.OpType.True:
6875 case Operator.OpType.False:
6876 case Operator.OpType.UnaryPlus:
6877 case Operator.OpType.UnaryNegation:
6883 void syntax_error (Location l, string msg)
6885 report.Error (1003, l, "Syntax error, " + msg);
6890 public Tokenizer Lexer {
6896 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
6897 : this (reader, file, file.Compiler.Report, session)
6901 public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
6904 current_container = current_namespace = file;
6906 this.module = file.Module;
6907 this.compiler = file.Compiler;
6908 this.settings = compiler.Settings;
6909 this.report = report;
6911 lang_version = settings.Version;
6912 yacc_verbose_flag = settings.VerboseParserFlag;
6913 doc_support = settings.DocumentationFile != null;
6914 lexer = new Tokenizer (reader, file, session);
6915 oob_stack = new Stack<object> ();
6916 lbag = session.LocationsBag;
6917 use_global_stacks = session.UseJayGlobalArrays;
6918 parameters_bucket = session.ParametersStack;
6921 public void parse ()
6923 eof_token = Token.EOF;
6926 if (yacc_verbose_flag > 1)
6927 yyparse (lexer, new yydebug.yyDebugSimple ());
6931 Tokenizer tokenizer = lexer as Tokenizer;
6932 tokenizer.cleanup ();
6933 } catch (Exception e){
6934 if (e is yyParser.yyUnexpectedEof) {
6935 Error_SyntaxError (yyToken);
6936 UnexpectedEOF = true;
6940 if (e is yyParser.yyException) {
6941 if (report.Errors == 0)
6942 report.Error (-25, lexer.Location, "Parsing error");
6944 // Used by compiler-tester to test internal errors
6945 if (yacc_verbose_flag > 0 || e is FatalException)
6948 report.Error (589, lexer.Location, "Internal compiler error during parsing" + e);
6953 void CheckToken (int error, int yyToken, string msg, Location loc)
6955 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6956 report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6958 report.Error (error, loc, msg);
6961 string ConsumeStoredComment ()
6963 string s = tmpComment;
6965 Lexer.doc_state = XmlCommentState.Allowed;
6969 void FeatureIsNotAvailable (Location loc, string feature)
6971 report.FeatureIsNotAvailable (compiler, loc, feature);
6974 Location GetLocation (object obj)
6976 var lt = obj as Tokenizer.LocatedToken;
6980 var mn = obj as MemberName;
6984 var expr = obj as Expression;
6986 return expr.Location;
6988 return lexer.Location;
6991 void start_block (Location loc)
6993 if (current_block == null) {
6994 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6995 parsing_anonymous_method = false;
6996 } else if (parsing_anonymous_method) {
6997 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6998 parsing_anonymous_method = false;
7000 current_block = new ExplicitBlock (current_block, loc, Location.Null);
7005 end_block (Location loc)
7007 Block retval = current_block.Explicit;
7008 retval.SetEndLocation (loc);
7009 current_block = retval.Parent;
7013 void start_anonymous (bool isLambda, ParametersCompiled parameters, bool isAsync, Location loc)
7015 oob_stack.Push (current_anonymous_method);
7016 oob_stack.Push (current_local_parameters);
7017 oob_stack.Push (current_variable);
7018 oob_stack.Push (async_block);
7020 current_local_parameters = parameters;
7022 if (lang_version <= LanguageVersion.ISO_2)
7023 FeatureIsNotAvailable (loc, "lambda expressions");
7025 current_anonymous_method = new LambdaExpression (loc);
7027 if (lang_version == LanguageVersion.ISO_1)
7028 FeatureIsNotAvailable (loc, "anonymous methods");
7030 current_anonymous_method = new AnonymousMethodExpression (loc);
7033 async_block = isAsync;
7034 // Force the next block to be created as a ToplevelBlock
7035 parsing_anonymous_method = true;
7039 * Completes the anonymous method processing, if lambda_expr is null, this
7040 * means that we have a Statement instead of an Expression embedded
7042 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
7044 AnonymousMethodExpression retval;
7047 anon_block.IsAsync = true;
7049 current_anonymous_method.Block = anon_block;
7050 retval = current_anonymous_method;
7052 async_block = (bool) oob_stack.Pop ();
7053 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
7054 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
7055 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
7060 void Error_SyntaxError (int token)
7062 Error_SyntaxError (0, token);
7065 void Error_SyntaxError (int error_code, int token)
7067 Error_SyntaxError (error_code, token, "Unexpected symbol");
7070 void Error_SyntaxError (int error_code, int token, string msg)
7072 Lexer.CompleteOnEOF = false;
7074 // An error message has been reported by tokenizer
7075 if (token == Token.ERROR)
7078 // Avoid duplicit error message after unterminated string literals
7079 if (token == Token.LITERAL && lexer.Location.Column == 0)
7082 string symbol = GetSymbolName (token);
7083 string expecting = GetExpecting ();
7084 var loc = lexer.Location - symbol.Length;
7086 if (error_code == 0) {
7087 if (expecting == "`identifier'") {
7088 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
7089 report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
7094 expecting = "identifier";
7095 } else if (expecting == "`)'") {
7102 if (string.IsNullOrEmpty (expecting))
7103 report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
7105 report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
7108 string GetExpecting ()
7110 int [] tokens = yyExpectingTokens (yyExpectingState);
7111 var names = new List<string> (tokens.Length);
7112 bool has_type = false;
7113 bool has_identifier = false;
7114 for (int i = 0; i < tokens.Length; i++){
7115 int token = tokens [i];
7116 has_identifier |= token == Token.IDENTIFIER;
7118 string name = GetTokenName (token);
7119 if (name == "<internal>")
7122 has_type |= name == "type";
7123 if (names.Contains (name))
7130 // Too many tokens to enumerate
7132 if (names.Count > 8)
7135 if (has_type && has_identifier)
7136 names.Remove ("identifier");
7138 if (names.Count == 1)
7139 return "`" + GetTokenName (tokens [0]) + "'";
7141 StringBuilder sb = new StringBuilder ();
7143 int count = names.Count;
7144 for (int i = 0; i < count; i++){
7145 bool last = i + 1 == count;
7149 sb.Append (names [i]);
7150 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
7152 return sb.ToString ();
7156 string GetSymbolName (int token)
7160 return ((Constant)lexer.Value).GetValue ().ToString ();
7161 case Token.IDENTIFIER:
7162 return ((Tokenizer.LocatedToken)lexer.Value).Value;
7204 case Token.BITWISE_AND:
7206 case Token.BITWISE_OR:
7220 case Token.OP_SHIFT_LEFT:
7222 case Token.OP_SHIFT_RIGHT:
7242 case Token.OP_COALESCING:
7244 case Token.OP_MULT_ASSIGN:
7246 case Token.OP_DIV_ASSIGN:
7248 case Token.OP_MOD_ASSIGN:
7250 case Token.OP_ADD_ASSIGN:
7252 case Token.OP_SUB_ASSIGN:
7254 case Token.OP_SHIFT_LEFT_ASSIGN:
7256 case Token.OP_SHIFT_RIGHT_ASSIGN:
7258 case Token.OP_AND_ASSIGN:
7260 case Token.OP_XOR_ASSIGN:
7262 case Token.OP_OR_ASSIGN:
7266 return GetTokenName (token);
7269 static string GetTokenName (int token)
7272 case Token.ABSTRACT:
7294 case Token.CONTINUE:
7298 case Token.DELEGATE:
7308 case Token.EXPLICIT:
7311 case Token.EXTERN_ALIAS:
7327 case Token.IMPLICIT:
7331 case Token.INTERFACE:
7333 case Token.INTERNAL:
7339 case Token.NAMESPACE:
7345 case Token.OPERATOR:
7349 case Token.OVERRIDE:
7355 case Token.PROTECTED:
7359 case Token.READONLY:
7371 case Token.STACKALLOC:
7372 return "stackalloc";
7389 case Token.UNCHECKED:
7397 case Token.VOLATILE:
7405 case Token.REFVALUE:
7406 return "__refvalue";
7416 case Token.FROM_FIRST:
7434 case Token.ASCENDING:
7436 case Token.DESCENDING:
7437 return "descending";
7444 case Token.OPEN_BRACE:
7446 case Token.CLOSE_BRACE:
7448 case Token.OPEN_BRACKET:
7449 case Token.OPEN_BRACKET_EXPR:
7451 case Token.CLOSE_BRACKET:
7453 case Token.OPEN_PARENS_CAST:
7454 case Token.OPEN_PARENS_LAMBDA:
7455 case Token.OPEN_PARENS:
7457 case Token.CLOSE_PARENS:
7463 case Token.DEFAULT_COLON:
7467 case Token.SEMICOLON:
7478 case Token.BITWISE_AND:
7479 case Token.BITWISE_OR:
7486 case Token.OP_SHIFT_LEFT:
7487 case Token.OP_SHIFT_RIGHT:
7495 case Token.OP_COALESCING:
7496 case Token.OP_MULT_ASSIGN:
7497 case Token.OP_DIV_ASSIGN:
7498 case Token.OP_MOD_ASSIGN:
7499 case Token.OP_ADD_ASSIGN:
7500 case Token.OP_SUB_ASSIGN:
7501 case Token.OP_SHIFT_LEFT_ASSIGN:
7502 case Token.OP_SHIFT_RIGHT_ASSIGN:
7503 case Token.OP_AND_ASSIGN:
7504 case Token.OP_XOR_ASSIGN:
7505 case Token.OP_OR_ASSIGN:
7506 return "<operator>";
7528 case Token.OP_GENERICS_LT:
7529 case Token.GENERIC_DIMENSION:
7531 case Token.OP_GENERICS_GT:
7534 case Token.INTERR_NULLABLE:
7536 case Token.DOUBLE_COLON:
7540 case Token.IDENTIFIER:
7542 return "identifier";
7545 return "end-of-file";
7547 // All of these are internal.
7550 case Token.FIRST_KEYWORD:
7551 case Token.EVAL_COMPILATION_UNIT_PARSER:
7552 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
7553 case Token.EVAL_STATEMENT_PARSER:
7554 case Token.LAST_KEYWORD:
7555 case Token.GENERATE_COMPLETION:
7556 case Token.COMPLETE_COMPLETION:
7557 return "<internal>";
7559 // A bit more robust.
7561 return yyNames [token];