3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.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 Novell, Inc
15 // (1) Figure out why error productions dont work. `type-declaration' is a
16 // great spot to put an `error' because you can reproduce it with this input:
23 using System.Collections.Generic;
30 public class CSharpParser
33 enum ParameterModifierType
40 DefaultValue = 1 << 6,
42 All = Ref | Out | This | Params | Arglist | DefaultValue
45 static readonly object ModifierNone = 0;
47 NamespaceEntry current_namespace;
48 TypeContainer current_container;
49 DeclSpace current_class;
50 PropertyBase current_property;
51 EventProperty current_event;
52 EventField current_event_field;
53 FieldBase current_field;
56 /// Current block is used to add statements as we find
61 BlockVariableDeclaration current_variable;
63 Delegate current_delegate;
65 AnonymousMethodExpression current_anonymous_method;
68 /// This is used by the unary_expression code to resolve
69 /// a name against a parameter.
72 // FIXME: This is very ugly and it's very hard to reset it correctly
73 // on all places, especially when some parameters are autogenerated.
74 ParametersCompiled current_local_parameters;
76 bool parsing_anonymous_method;
79 /// An out-of-band stack.
81 static Stack<object> oob_stack;
84 /// Controls the verbosity of the errors produced by the parser
86 static public int yacc_verbose_flag;
89 /// Used by the interactive shell, flags whether EOF was reached
90 /// and an error was produced
92 public bool UnexpectedEOF;
100 /// Temporary Xml documentation cache.
101 /// For enum types, we need one more temporary store.
104 string enumTypeComment;
106 /// Current attribute target
107 string current_attr_target;
109 /// assembly and module attribute definitions are enabled
110 bool global_attrs_enabled = true;
112 ParameterModifierType valid_param_mod;
114 bool default_parameter_used;
116 /// When using the interactive parser, this holds the
117 /// resulting expression
118 public Class InteractiveResult;
121 // Keeps track of global data changes to undo on parser error
125 Stack<Linq.QueryBlock> linq_clause_blocks;
127 ModuleContainer module;
129 readonly CompilerContext compiler;
130 readonly LanguageVersion lang_version;
131 readonly bool doc_support;
132 readonly CompilerSettings settings;
135 // Instead of allocating carrier array everytime we
136 // share the bucket for very common constructs which can never
139 static List<Parameter> parameters_bucket = new List<Parameter> (6);
142 // Full AST support members
145 List<Tuple<Modifiers, Location>> mod_locations;
149 %token NONE /* This token is never returned by our lexer */
150 %token ERROR // This is used not by the parser, but by the tokenizer.
154 *These are the C# keywords
253 %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
336 // This token is generated to trigger the completion engine at this point
338 %token GENERATE_COMPLETION
341 // This token is return repeatedly after the first GENERATE_COMPLETION
342 // token is produced and before the final EOF
344 %token COMPLETE_COMPLETION
346 /* Add precedence rules to solve dangling else s/r conflict */
350 /* Define the operator tokens and their precedences */
358 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
360 %left STAR DIV PERCENT
361 %right BANG CARRET UMINUS
362 %nonassoc OP_INC OP_DEC
364 %left OPEN_BRACKET OPEN_BRACE
367 %start compilation_unit
371 : outer_declarations opt_EOF
372 | outer_declarations global_attributes opt_EOF
373 | global_attributes opt_EOF
374 | opt_EOF /* allow empty files */
375 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
381 Lexer.check_incorrect_doc_comment ();
385 Lexer.check_incorrect_doc_comment ();
391 | outer_declarations outer_declaration
395 : extern_alias_directive
397 | namespace_member_declaration
400 extern_alias_directives
401 : extern_alias_directive
402 | extern_alias_directives extern_alias_directive
405 extern_alias_directive
406 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
408 var lt = (Tokenizer.LocatedToken) $2;
411 syntax_error (lt.Location, "`alias' expected");
412 } else if (lang_version == LanguageVersion.ISO_1) {
413 FeatureIsNotAvailable (lt.Location, "external alias");
415 lt = (Tokenizer.LocatedToken) $3;
416 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
421 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
427 | using_directives using_directive
431 : using_alias_directive
434 Lexer.doc_state = XmlCommentState.Allowed;
436 | using_namespace_directive
439 Lexer.doc_state = XmlCommentState.Allowed;
443 using_alias_directive
444 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
446 var lt = (Tokenizer.LocatedToken) $2;
447 if (lang_version != LanguageVersion.ISO_1 && lt.Value == "global") {
448 Report.Warning (440, 2, lt.Location,
449 "An alias named `global' will not be used when resolving `global::'. The global namespace will be used instead");
452 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
456 Error_SyntaxError (yyToken);
461 using_namespace_directive
462 : USING namespace_name SEMICOLON
464 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
469 // Strictly speaking, namespaces don't have attributes but
470 // we parse global attributes along with namespace declarations and then
473 namespace_declaration
474 : opt_attributes NAMESPACE qualified_identifier
476 MemberName name = (MemberName) $3;
479 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
482 current_namespace = new NamespaceEntry (module,
483 current_namespace, file, name.GetName ());
484 current_class = current_namespace.SlaveDeclSpace;
485 current_container = current_class.PartialContainer;
487 namespace_body opt_semicolon
489 current_namespace = current_namespace.Parent;
490 current_class = current_namespace.SlaveDeclSpace;
491 current_container = current_class.PartialContainer;
498 var lt = (Tokenizer.LocatedToken) $1;
499 $$ = new MemberName (lt.Value, lt.Location);
501 | qualified_identifier DOT IDENTIFIER
503 var lt = (Tokenizer.LocatedToken) $3;
504 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
508 Error_SyntaxError (yyToken);
509 $$ = new MemberName ("<invalid>", lexer.Location);
524 : namespace_or_type_name
526 MemberName name = (MemberName) $1;
528 if (name.TypeArguments != null)
529 syntax_error (lexer.Location, "namespace name expected");
539 Lexer.doc_state = XmlCommentState.Allowed;
541 opt_extern_alias_directives
543 opt_namespace_member_declarations
552 opt_extern_alias_directives
554 | extern_alias_directives
557 opt_namespace_member_declarations
559 | namespace_member_declarations
562 namespace_member_declarations
563 : namespace_member_declaration
564 | namespace_member_declarations namespace_member_declaration
567 namespace_member_declaration
571 DeclSpace ds = (DeclSpace)$1;
573 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
574 Report.Error (1527, ds.Location,
575 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
578 current_namespace.DeclarationFound = true;
580 | namespace_declaration
582 current_namespace.DeclarationFound = true;
586 Error_SyntaxError (yyToken);
593 | interface_declaration
595 | delegate_declaration
597 // Enable this when we have handled all errors, because this acts as a generic fallback
600 // Console.WriteLine ("Token=" + yyToken);
601 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
613 Attributes attrs = (Attributes)$1;
614 if (global_attrs_enabled) {
615 module.AddAttributes (attrs.Attrs, current_namespace);
617 foreach (Attribute a in attrs.Attrs) {
618 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
629 global_attrs_enabled = false;
634 global_attrs_enabled = false;
643 if (current_attr_target != String.Empty) {
644 var sect = (List<Attribute>) $1;
646 if (global_attrs_enabled) {
647 if (!string.IsNullOrEmpty (current_attr_target)) {
648 module.AddAttributes (sect, current_namespace);
651 $$ = new Attributes (sect);
655 Lexer.check_incorrect_doc_comment ();
657 XmlCommentState.Allowed;
661 $$ = new Attributes (sect);
666 current_attr_target = null;
668 | attribute_sections attribute_section
670 if (current_attr_target != String.Empty) {
671 Attributes attrs = $1 as Attributes;
672 var sect = (List<Attribute>) $2;
674 if (global_attrs_enabled) {
675 if (!string.IsNullOrEmpty (current_attr_target)) {
676 module.AddAttributes (sect);
680 attrs = new Attributes (sect);
682 attrs.AddAttributes (sect);
686 attrs = new Attributes (sect);
688 attrs.AddAttributes (sect);
694 current_attr_target = null;
699 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
703 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
709 attribute_target_specifier
710 : attribute_target COLON
712 current_attr_target = (string)$1;
720 var lt = (Tokenizer.LocatedToken) $1;
721 $$ = CheckAttributeTarget (lt.Value, lt.Location);
723 | EVENT { $$ = "event"; }
724 | RETURN { $$ = "return"; }
727 string name = GetTokenName (yyToken);
728 $$ = 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;
754 MemberName mname = (MemberName) $1;
755 if (mname.IsGeneric) {
756 Report.Error (404, lexer.Location,
757 "'<' unexpected: attributes cannot be generic");
760 Arguments [] arguments = (Arguments []) $3;
761 ATypeNameExpression expr = mname.GetTypeExpression ();
763 if (current_attr_target == String.Empty)
765 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
766 // FIXME: supply "nameEscaped" parameter here.
767 $$ = new GlobalAttribute (current_namespace, current_attr_target,
768 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
770 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
775 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
778 opt_attribute_arguments
779 : /* empty */ { $$ = null; }
780 | OPEN_PARENS attribute_arguments CLOSE_PARENS
788 : /* empty */ { $$ = null; }
789 | positional_or_named_argument
791 Arguments a = new Arguments (4);
792 a.Add ((Argument) $1);
793 $$ = new Arguments [] { a, null };
795 | named_attribute_argument
797 Arguments a = new Arguments (4);
798 a.Add ((Argument) $1);
799 $$ = new Arguments [] { null, a };
801 | attribute_arguments COMMA positional_or_named_argument
803 Arguments[] o = (Arguments[]) $1;
805 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
806 o [0] = new Arguments (4);
809 Arguments args = ((Arguments) o [0]);
810 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
811 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
813 args.Add ((Argument) $3);
815 | attribute_arguments COMMA named_attribute_argument
817 Arguments[] o = (Arguments[]) $1;
819 o [1] = new Arguments (4);
822 ((Arguments) o [1]).Add ((Argument) $3);
826 positional_or_named_argument
829 $$ = new Argument ((Expression) $1);
834 named_attribute_argument
837 ++lexer.parsing_block;
841 --lexer.parsing_block;
842 var lt = (Tokenizer.LocatedToken) $1;
843 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
848 : IDENTIFIER COLON opt_named_modifier expression
850 if (lang_version <= LanguageVersion.V_3)
851 FeatureIsNotAvailable (GetLocation ($1), "named argument");
853 // Avoid boxing in common case (no modifier)
854 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
856 var lt = (Tokenizer.LocatedToken) $1;
857 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
862 : /* empty */ { $$ = null; }
865 $$ = Argument.AType.Ref;
869 $$ = Argument.AType.Out;
873 opt_class_member_declarations
875 | class_member_declarations
878 class_member_declarations
879 : class_member_declaration
880 | class_member_declarations
881 class_member_declaration
884 class_member_declaration
885 : constant_declaration // done
886 | field_declaration // done
887 | method_declaration // done
888 | property_declaration // done
889 | event_declaration // done
890 | indexer_declaration // done
891 | operator_declaration // done
892 | constructor_declaration // done
893 | destructor_declaration // done
897 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
898 GetSymbolName (yyToken));
900 lexer.parsing_generic_declaration = false;
910 lexer.ConstraintsParsing = true;
912 type_declaration_name
914 MemberName name = MakeName ((MemberName) $6);
915 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
918 opt_type_parameter_constraints_clauses
920 lexer.ConstraintsParsing = false;
922 current_class.SetParameterInfo ((List<Constraints>) $9);
925 current_container.DocComment = Lexer.consume_doc_comment ();
927 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
931 --lexer.parsing_declaration;
933 Lexer.doc_state = XmlCommentState.Allowed;
937 lbag.AppendToMember (current_class, GetLocation ($13));
938 $$ = pop_current_class ();
940 | opt_attributes opt_modifiers opt_partial STRUCT error
942 Error_SyntaxError (yyToken);
950 Lexer.doc_state = XmlCommentState.Allowed;
952 opt_struct_member_declarations CLOSE_BRACE
954 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
958 opt_struct_member_declarations
960 | struct_member_declarations
963 struct_member_declarations
964 : struct_member_declaration
965 | struct_member_declarations struct_member_declaration
968 struct_member_declaration
969 : constant_declaration
972 | property_declaration
974 | indexer_declaration
975 | operator_declaration
976 | constructor_declaration
980 * This is only included so we can flag error 575:
981 * destructors only allowed on class types
983 | destructor_declaration
989 CONST type IDENTIFIER
991 var lt = (Tokenizer.LocatedToken) $5;
992 var mod = (Modifiers) $2;
993 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
994 current_container.AddConstant ((Const) current_field);
996 if ((mod & Modifiers.STATIC) != 0) {
997 Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
1002 constant_initializer opt_constant_declarators SEMICOLON
1005 current_field.DocComment = Lexer.consume_doc_comment ();
1006 Lexer.doc_state = XmlCommentState.Allowed;
1009 current_field.Initializer = (ConstInitializer) $7;
1010 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1011 current_field = null;
1015 opt_constant_declarators
1017 | constant_declarators
1020 constant_declarators
1021 : constant_declarator
1023 current_field.AddDeclarator ((FieldDeclarator) $1);
1025 | constant_declarators constant_declarator
1027 current_field.AddDeclarator ((FieldDeclarator) $2);
1032 : COMMA IDENTIFIER constant_initializer
1034 var lt = (Tokenizer.LocatedToken) $2;
1035 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1036 lbag.AddLocation ($$, GetLocation ($1));
1040 constant_initializer
1043 ++lexer.parsing_block;
1045 constant_initializer_expr
1047 --lexer.parsing_block;
1048 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1052 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
1057 constant_initializer_expr
1058 : constant_expression
1065 member_type IDENTIFIER
1067 lexer.parsing_generic_declaration = false;
1069 FullNamedExpression type = (FullNamedExpression) $3;
1070 if (type.Type == TypeManager.void_type)
1071 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1073 var lt = (Tokenizer.LocatedToken) $4;
1074 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1075 current_container.AddField (current_field);
1078 opt_field_initializer
1079 opt_field_declarators
1083 current_field.DocComment = Lexer.consume_doc_comment ();
1084 Lexer.doc_state = XmlCommentState.Allowed;
1087 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1089 current_field = null;
1093 FIXED simple_type IDENTIFIER
1095 if (lang_version < LanguageVersion.ISO_2)
1096 FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1098 var lt = (Tokenizer.LocatedToken) $5;
1099 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1100 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1102 current_container.AddField (current_field);
1104 fixed_field_size opt_fixed_field_declarators SEMICOLON
1107 current_field.DocComment = Lexer.consume_doc_comment ();
1108 Lexer.doc_state = XmlCommentState.Allowed;
1111 current_field.Initializer = (ConstInitializer) $7;
1112 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1114 current_field = null;
1118 FIXED simple_type error
1121 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1125 opt_field_initializer
1129 ++lexer.parsing_block;
1130 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1131 start_block (GetLocation ($1));
1133 variable_initializer
1135 --lexer.parsing_block;
1136 current_field.Initializer = (Expression) $3;
1137 end_block (lexer.Location);
1138 current_local_parameters = null;
1142 opt_field_declarators
1150 current_field.AddDeclarator ((FieldDeclarator) $1);
1152 | field_declarators field_declarator
1154 current_field.AddDeclarator ((FieldDeclarator) $2);
1161 var lt = (Tokenizer.LocatedToken) $2;
1162 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1163 lbag.AddLocation ($$, GetLocation ($1));
1165 | COMMA IDENTIFIER ASSIGN
1167 ++lexer.parsing_block;
1169 variable_initializer
1171 --lexer.parsing_block;
1172 var lt = (Tokenizer.LocatedToken) $2;
1173 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1174 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1178 opt_fixed_field_declarators
1180 | fixed_field_declarators
1183 fixed_field_declarators
1184 : fixed_field_declarator
1186 current_field.AddDeclarator ((FieldDeclarator) $1);
1188 | fixed_field_declarators fixed_field_declarator
1190 current_field.AddDeclarator ((FieldDeclarator) $2);
1194 fixed_field_declarator
1195 : COMMA IDENTIFIER fixed_field_size
1197 var lt = (Tokenizer.LocatedToken) $2;
1198 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1199 lbag.AddLocation ($$, GetLocation ($1));
1206 ++lexer.parsing_block;
1208 expression CLOSE_BRACKET
1210 --lexer.parsing_block;
1211 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1212 lbag.AddLocation ($$, GetLocation ($4));
1214 | OPEN_BRACKET error
1216 Report.Error (443, lexer.Location, "Value or constant expected");
1221 variable_initializer
1226 // It has to be here for the parent to safely restore artificial block
1227 Error_SyntaxError (yyToken);
1236 Lexer.doc_state = XmlCommentState.NotAllowed;
1238 // Add it early in the case of body being eof for full aot
1239 current_container.AddMethod ((Method) $1);
1243 Method method = (Method) $1;
1244 method.Block = (ToplevelBlock) $3;
1246 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1247 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1250 current_local_parameters = null;
1253 Lexer.doc_state = XmlCommentState.Allowed;
1261 method_declaration_name OPEN_PARENS
1263 valid_param_mod = ParameterModifierType.All;
1265 opt_formal_parameter_list CLOSE_PARENS
1267 lexer.ConstraintsParsing = true;
1269 opt_type_parameter_constraints_clauses
1271 lexer.ConstraintsParsing = false;
1272 valid_param_mod = 0;
1273 MemberName name = (MemberName) $4;
1274 current_local_parameters = (ParametersCompiled) $7;
1276 GenericMethod generic = null;
1277 if (name.TypeArguments != null) {
1278 generic = new GenericMethod (current_namespace, current_class, name,
1279 (FullNamedExpression) $3, current_local_parameters);
1281 generic.SetParameterInfo ((List<Constraints>) $10);
1282 } else if ($10 != null) {
1283 Report.Error (80, GetLocation ($10),
1284 "Constraints are not allowed on non-generic declarations");
1287 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1288 name, current_local_parameters, (Attributes) $1);
1290 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1291 Report.Error (460, method.Location,
1292 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1293 method.GetSignatureForError ());
1297 method.DocComment = Lexer.consume_doc_comment ();
1299 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1305 VOID method_declaration_name
1308 valid_param_mod = ParameterModifierType.All;
1310 opt_formal_parameter_list CLOSE_PARENS
1312 lexer.ConstraintsParsing = true;
1314 opt_type_parameter_constraints_clauses
1316 lexer.ConstraintsParsing = false;
1317 valid_param_mod = 0;
1319 MemberName name = (MemberName) $5;
1320 current_local_parameters = (ParametersCompiled) $8;
1322 if ($10 != null && name.TypeArguments == null)
1323 Report.Error (80, lexer.Location,
1324 "Constraints are not allowed on non-generic declarations");
1327 GenericMethod generic = null;
1328 if (name.TypeArguments != null) {
1329 generic = new GenericMethod (current_namespace, current_class, name,
1330 new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1331 current_local_parameters);
1333 generic.SetParameterInfo ((List<Constraints>) $11);
1336 var modifiers = (Modifiers) $2;
1339 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1340 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1342 if ((modifiers & invalid_partial_mod) != 0) {
1343 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1344 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1345 modifiers &= ~invalid_partial_mod;
1348 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1349 Report.Error (751, name.Location, "A partial method must be declared within a " +
1350 "partial class or partial struct");
1353 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1355 method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1356 modifiers, name, current_local_parameters, (Attributes) $1);
1359 method.DocComment = Lexer.consume_doc_comment ();
1361 // TODO: lbag, push void
1362 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1363 lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
1369 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1371 MemberName name = (MemberName) $5;
1372 Report.Error (1585, name.Location,
1373 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1375 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1376 0, name, (ParametersCompiled) $7, (Attributes) $1);
1378 current_local_parameters = (ParametersCompiled) $7;
1381 method.DocComment = Lexer.consume_doc_comment ();
1389 | SEMICOLON { $$ = null; }
1392 opt_formal_parameter_list
1393 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1394 | formal_parameter_list
1397 formal_parameter_list
1400 var pars_list = (List<Parameter>) $1;
1401 $$ = new ParametersCompiled (pars_list.ToArray ());
1403 | fixed_parameters COMMA parameter_array
1405 var pars_list = (List<Parameter>) $1;
1406 pars_list.Add ((Parameter) $3);
1408 $$ = new ParametersCompiled (pars_list.ToArray ());
1410 | fixed_parameters COMMA arglist_modifier
1412 var pars_list = (List<Parameter>) $1;
1413 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1414 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1416 | parameter_array COMMA error
1419 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1421 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1423 | fixed_parameters COMMA parameter_array COMMA error
1426 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1428 var pars_list = (List<Parameter>) $1;
1429 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1431 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1433 | arglist_modifier COMMA error
1435 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1437 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1439 | fixed_parameters COMMA ARGLIST COMMA error
1441 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1443 var pars_list = (List<Parameter>) $1;
1444 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1446 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1450 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1454 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1458 Error_SyntaxError (yyToken);
1459 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1466 parameters_bucket.Clear ();
1467 Parameter p = (Parameter) $1;
1468 parameters_bucket.Add (p);
1470 default_parameter_used = p.HasDefaultValue;
1471 $$ = parameters_bucket;
1473 | fixed_parameters COMMA fixed_parameter
1475 var pars = (List<Parameter>) $1;
1476 Parameter p = (Parameter) $3;
1478 if (p.HasExtensionMethodModifier)
1479 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1480 else if (!p.HasDefaultValue && default_parameter_used)
1481 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1483 default_parameter_used |= p.HasDefaultValue;
1486 lbag.AddLocation (p, GetLocation ($2));
1495 opt_parameter_modifier
1499 var lt = (Tokenizer.LocatedToken) $4;
1500 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1503 opt_parameter_modifier
1505 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1507 var lt = (Tokenizer.LocatedToken) $4;
1508 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1509 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1512 opt_parameter_modifier
1516 Error_SyntaxError (yyToken);
1517 Location l = GetLocation ($4);
1518 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1521 opt_parameter_modifier
1526 ++lexer.parsing_block;
1530 --lexer.parsing_block;
1531 if (lang_version <= LanguageVersion.V_3) {
1532 FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1535 Parameter.Modifier mod = (Parameter.Modifier) $2;
1536 if (mod != Parameter.Modifier.NONE) {
1538 case Parameter.Modifier.REF:
1539 case Parameter.Modifier.OUT:
1540 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1541 Parameter.GetModifierSignature (mod));
1544 case Parameter.Modifier.This:
1545 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1546 Parameter.GetModifierSignature (mod));
1549 throw new NotImplementedException (mod.ToString ());
1552 mod = Parameter.Modifier.NONE;
1555 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1556 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1558 var lt = (Tokenizer.LocatedToken) $4;
1559 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1560 lbag.AddLocation ($$, GetLocation ($5));
1563 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1567 opt_parameter_modifier
1568 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1569 | parameter_modifiers
1573 : parameter_modifier
1577 | parameter_modifiers parameter_modifier
1579 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1580 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1581 if (((Parameter.Modifier)$1 & p2) == p2) {
1582 Error_DuplicateParameterModifier (lexer.Location, p2);
1584 switch (mod & ~Parameter.Modifier.This) {
1585 case Parameter.Modifier.REF:
1586 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1588 case Parameter.Modifier.OUT:
1589 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1592 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1603 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1604 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1606 $$ = Parameter.Modifier.REF;
1610 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1611 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1613 $$ = Parameter.Modifier.OUT;
1617 if ((valid_param_mod & ParameterModifierType.This) == 0)
1618 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1620 if (lang_version <= LanguageVersion.ISO_2)
1621 FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1623 $$ = Parameter.Modifier.This;
1628 : opt_attributes params_modifier type IDENTIFIER
1630 var lt = (Tokenizer.LocatedToken) $4;
1631 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1633 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1635 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1637 var lt = (Tokenizer.LocatedToken) $4;
1638 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1640 | opt_attributes params_modifier type error
1642 Error_SyntaxError (yyToken);
1650 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1651 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1653 | PARAMS parameter_modifier
1655 Parameter.Modifier mod = (Parameter.Modifier)$2;
1656 if ((mod & Parameter.Modifier.This) != 0) {
1657 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1659 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1662 | PARAMS params_modifier
1664 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1671 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1672 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1676 property_declaration
1680 member_declaration_name
1683 tmpComment = Lexer.consume_doc_comment ();
1687 current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
1688 (MemberName) $4, (Attributes) $1);
1690 if (current_property.TypeExpression.Type == TypeManager.void_type)
1691 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1693 current_container.AddProperty ((Property)current_property);
1694 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1696 lexer.PropertyParsing = true;
1698 accessor_declarations
1700 lexer.PropertyParsing = false;
1703 current_property.DocComment = ConsumeStoredComment ();
1707 lbag.AppendToMember (current_property, GetLocation ($10));
1708 current_property = null;
1714 : opt_attributes opt_modifiers
1715 member_type indexer_declaration_name OPEN_BRACKET
1717 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1719 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1721 valid_param_mod = 0;
1723 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
1724 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1726 current_property = indexer;
1728 current_container.AddIndexer (indexer);
1729 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1731 if (indexer.TypeExpression.Type == TypeManager.void_type)
1732 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1734 if (indexer.Parameters.IsEmpty) {
1735 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1739 tmpComment = Lexer.consume_doc_comment ();
1740 Lexer.doc_state = XmlCommentState.Allowed;
1743 lexer.PropertyParsing = true;
1745 accessor_declarations
1747 lexer.PropertyParsing = false;
1752 current_property.DocComment = ConsumeStoredComment ();
1754 lbag.AppendToMember (current_property, GetLocation ($12));
1755 current_property = null;
1760 accessor_declarations
1761 : get_accessor_declaration
1762 | get_accessor_declaration accessor_declarations
1763 | set_accessor_declaration
1764 | set_accessor_declaration accessor_declarations
1767 if (yyToken == Token.CLOSE_BRACE) {
1768 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1770 if (yyToken == Token.SEMICOLON)
1771 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1773 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1778 get_accessor_declaration
1779 : opt_attributes opt_modifiers GET
1781 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1782 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1785 if (current_property.Get != null) {
1786 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1789 if (current_property is Indexer) {
1790 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1791 (Attributes) $1, GetLocation ($3));
1793 current_property.Get = new Property.GetMethod (current_property,
1794 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1797 current_local_parameters = current_property.Get.ParameterInfo;
1798 lbag.AddMember (current_property.Get, mod_locations);
1799 lexer.PropertyParsing = false;
1804 current_property.Get.Block = (ToplevelBlock) $5;
1806 if (current_container.Kind == MemberKind.Interface) {
1807 Report.Error (531, current_property.Get.Block.StartLocation,
1808 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1812 current_local_parameters = null;
1813 lexer.PropertyParsing = true;
1816 if (Lexer.doc_state == XmlCommentState.Error)
1817 Lexer.doc_state = XmlCommentState.NotAllowed;
1821 set_accessor_declaration
1822 : opt_attributes opt_modifiers SET
1824 if ($2 != ModifierNone && lang_version == LanguageVersion.ISO_1) {
1825 FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1828 if (current_property.Set != null) {
1829 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1832 if (current_property is Indexer) {
1833 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1834 ParametersCompiled.MergeGenerated (compiler,
1835 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1836 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1838 (Attributes) $1, GetLocation ($3));
1840 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1841 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1842 (Attributes) $1, GetLocation ($3));
1845 current_local_parameters = current_property.Set.ParameterInfo;
1846 lbag.AddMember (current_property.Set, mod_locations);
1847 lexer.PropertyParsing = false;
1852 current_property.Set.Block = (ToplevelBlock) $5;
1854 if (current_container.Kind == MemberKind.Interface) {
1855 Report.Error (531, current_property.Set.Block.StartLocation,
1856 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1860 current_local_parameters = null;
1861 lexer.PropertyParsing = true;
1864 && Lexer.doc_state == XmlCommentState.Error)
1865 Lexer.doc_state = XmlCommentState.NotAllowed;
1878 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1883 interface_declaration
1889 lexer.ConstraintsParsing = true;
1891 type_declaration_name
1893 MemberName name = MakeName ((MemberName) $6);
1894 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1895 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1898 opt_type_parameter_constraints_clauses
1900 lexer.ConstraintsParsing = false;
1902 current_class.SetParameterInfo ((List<Constraints>) $9);
1905 current_container.DocComment = Lexer.consume_doc_comment ();
1906 Lexer.doc_state = XmlCommentState.Allowed;
1909 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1911 --lexer.parsing_declaration;
1913 Lexer.doc_state = XmlCommentState.Allowed;
1917 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1918 $$ = pop_current_class ();
1920 | opt_attributes opt_modifiers opt_partial INTERFACE error
1922 Error_SyntaxError (yyToken);
1926 opt_interface_member_declarations
1928 | interface_member_declarations
1931 interface_member_declarations
1932 : interface_member_declaration
1933 | interface_member_declarations interface_member_declaration
1936 interface_member_declaration
1937 : constant_declaration
1939 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1943 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1945 | method_declaration
1946 | property_declaration
1948 | indexer_declaration
1949 | operator_declaration
1951 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1953 | constructor_declaration
1955 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1959 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1963 operator_declaration
1964 : opt_attributes opt_modifiers operator_declarator
1969 OperatorDeclaration decl = (OperatorDeclaration) $3;
1971 Operator op = new Operator (
1972 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1973 current_local_parameters,
1974 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1977 op.DocComment = tmpComment;
1978 Lexer.doc_state = XmlCommentState.Allowed;
1981 // Note again, checking is done in semantic analysis
1982 current_container.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 (TypeManager.void_type, 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;
2094 tmpComment = Lexer.consume_doc_comment ();
2095 Lexer.doc_state = XmlCommentState.NotAllowed;
2098 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2099 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2101 | EXPLICIT OPERATOR type OPEN_PARENS
2103 valid_param_mod = ParameterModifierType.DefaultValue;
2105 opt_formal_parameter_list CLOSE_PARENS
2107 valid_param_mod = 0;
2109 Location loc = GetLocation ($2);
2110 current_local_parameters = (ParametersCompiled)$6;
2113 tmpComment = Lexer.consume_doc_comment ();
2114 Lexer.doc_state = XmlCommentState.NotAllowed;
2117 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2118 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2122 Error_SyntaxError (yyToken);
2123 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2124 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2128 Error_SyntaxError (yyToken);
2129 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2130 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2134 constructor_declaration
2135 : constructor_declarator
2138 Constructor c = (Constructor) $1;
2139 c.Block = (ToplevelBlock) $2;
2142 c.DocComment = ConsumeStoredComment ();
2144 current_container.AddConstructor (c);
2146 current_local_parameters = null;
2148 Lexer.doc_state = XmlCommentState.Allowed;
2152 constructor_declarator
2158 tmpComment = Lexer.consume_doc_comment ();
2159 Lexer.doc_state = XmlCommentState.Allowed;
2162 valid_param_mod = ParameterModifierType.All;
2164 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2166 valid_param_mod = 0;
2167 current_local_parameters = (ParametersCompiled) $6;
2170 // start block here, so possible anonymous methods inside
2171 // constructor initializer can get correct parent block
2173 start_block (lexer.Location);
2175 opt_constructor_initializer
2177 var lt = (Tokenizer.LocatedToken) $3;
2178 var mods = (Modifiers) $2;
2179 ConstructorInitializer ci = (ConstructorInitializer) $9;
2181 Constructor c = new Constructor (current_class, lt.Value, mods,
2182 (Attributes) $1, current_local_parameters, ci, lt.Location);
2184 if (lt.Value != current_container.MemberName.Name) {
2185 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2186 } else if ((mods & Modifiers.STATIC) != 0) {
2187 if ((mods & Modifiers.AccessibilityMask) != 0){
2188 Report.Error (515, c.Location,
2189 "`{0}': static constructor cannot have an access modifier",
2190 c.GetSignatureForError ());
2193 Report.Error (514, c.Location,
2194 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2195 c.GetSignatureForError ());
2200 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2207 | SEMICOLON { current_block = null; $$ = null; }
2210 opt_constructor_initializer
2212 | constructor_initializer
2215 constructor_initializer
2216 : COLON BASE OPEN_PARENS
2218 ++lexer.parsing_block;
2220 opt_argument_list CLOSE_PARENS
2222 --lexer.parsing_block;
2223 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2224 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2226 | COLON THIS OPEN_PARENS
2228 ++lexer.parsing_block;
2230 opt_argument_list CLOSE_PARENS
2232 --lexer.parsing_block;
2233 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2234 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2238 Error_SyntaxError (yyToken);
2243 destructor_declaration
2244 : opt_attributes opt_modifiers TILDE
2247 tmpComment = Lexer.consume_doc_comment ();
2248 Lexer.doc_state = XmlCommentState.NotAllowed;
2251 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2253 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2255 var lt = (Tokenizer.LocatedToken) $5;
2256 if (lt.Value != current_container.MemberName.Name){
2257 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2258 } else if (current_container.Kind != MemberKind.Class){
2259 Report.Error (575, lt.Location, "Only class types can contain destructor");
2262 Destructor d = new Destructor (current_class, (Modifiers) $2,
2263 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2265 d.DocComment = ConsumeStoredComment ();
2267 d.Block = (ToplevelBlock) $8;
2268 current_container.AddMethod (d);
2269 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2271 current_local_parameters = null;
2278 EVENT type member_declaration_name
2280 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2281 current_container.AddEvent (current_event_field);
2283 if (current_event_field.MemberName.Left != null) {
2284 Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2285 current_event_field.GetSignatureForError ());
2288 $$ = current_event_field;
2290 opt_event_initializer
2291 opt_event_declarators
2295 current_event_field.DocComment = Lexer.consume_doc_comment ();
2296 Lexer.doc_state = XmlCommentState.Allowed;
2299 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2300 current_event_field = null;
2304 EVENT type member_declaration_name
2307 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2308 current_container.AddEvent (current_event);
2309 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2311 lexer.EventParsing = true;
2313 event_accessor_declarations
2315 if (current_container.Kind == MemberKind.Interface)
2316 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2318 lexer.EventParsing = false;
2323 current_event.DocComment = Lexer.consume_doc_comment ();
2324 Lexer.doc_state = XmlCommentState.Allowed;
2327 lbag.AppendToMember (current_event, GetLocation ($9));
2328 current_event = null;
2329 current_local_parameters = null;
2333 opt_event_initializer
2337 ++lexer.parsing_block;
2339 event_variable_initializer
2341 --lexer.parsing_block;
2342 current_event_field.Initializer = (Expression) $3;
2346 opt_event_declarators
2354 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2356 | event_declarators event_declarator
2358 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2365 var lt = (Tokenizer.LocatedToken) $2;
2366 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2367 lbag.AddLocation ($$, GetLocation ($1));
2369 | COMMA IDENTIFIER ASSIGN
2371 ++lexer.parsing_block;
2373 event_variable_initializer
2375 --lexer.parsing_block;
2376 var lt = (Tokenizer.LocatedToken) $2;
2377 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2378 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2382 event_variable_initializer
2384 if (current_container.Kind == MemberKind.Interface) {
2385 Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2386 current_event_field.GetSignatureForError ());
2389 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2390 Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2391 current_event_field.GetSignatureForError ());
2394 variable_initializer
2400 event_accessor_declarations
2401 : add_accessor_declaration remove_accessor_declaration
2402 | remove_accessor_declaration add_accessor_declaration
2403 | add_accessor_declaration
2405 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2406 current_event.GetSignatureForError ());
2408 | remove_accessor_declaration
2410 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2411 current_event.GetSignatureForError ());
2415 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2420 add_accessor_declaration
2421 : opt_attributes opt_modifiers ADD
2423 if ($2 != ModifierNone) {
2424 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2427 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2428 current_local_parameters = current_event.Add.ParameterInfo;
2430 lbag.AddMember (current_event.Add, mod_locations);
2431 lexer.EventParsing = false;
2433 event_accessor_block
2435 lexer.EventParsing = true;
2437 current_event.Add.Block = (ToplevelBlock) $5;
2439 if (current_container.Kind == MemberKind.Interface) {
2440 Report.Error (531, current_event.Add.Block.StartLocation,
2441 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2444 current_local_parameters = null;
2448 remove_accessor_declaration
2449 : opt_attributes opt_modifiers REMOVE
2451 if ($2 != ModifierNone) {
2452 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2455 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2456 current_local_parameters = current_event.Remove.ParameterInfo;
2458 lbag.AddMember (current_event.Remove, mod_locations);
2459 lexer.EventParsing = false;
2461 event_accessor_block
2463 lexer.EventParsing = true;
2465 current_event.Remove.Block = (ToplevelBlock) $5;
2467 if (current_container.Kind == MemberKind.Interface) {
2468 Report.Error (531, current_event.Remove.Block.StartLocation,
2469 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2472 current_local_parameters = null;
2476 event_accessor_block
2479 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2488 ENUM type_declaration_name
2492 enumTypeComment = Lexer.consume_doc_comment ();
2497 Lexer.doc_state = XmlCommentState.Allowed;
2499 MemberName name = (MemberName) $4;
2500 if (name.IsGeneric) {
2501 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2504 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2506 opt_enum_member_declarations
2508 // here will be evaluated after CLOSE_BLACE is consumed.
2510 Lexer.doc_state = XmlCommentState.Allowed;
2512 CLOSE_BRACE opt_semicolon
2515 current_class.DocComment = enumTypeComment;
2517 --lexer.parsing_declaration;
2520 // em.DocComment = ev.DocComment;
2522 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2523 $$ = pop_current_class ();
2531 var te = $2 as TypeExpression;
2533 (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
2534 te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
2535 te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
2536 te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
2537 Enum.Error_1008 (GetLocation ($2), Report);
2545 Error_TypeExpected (GetLocation ($1));
2550 opt_enum_member_declarations
2552 | enum_member_declarations
2553 | enum_member_declarations COMMA
2555 lbag.AddLocation ($1, GetLocation ($2));
2559 enum_member_declarations
2560 : enum_member_declaration
2561 | enum_member_declarations COMMA enum_member_declaration
2563 lbag.AddLocation ($1, GetLocation ($2));
2568 enum_member_declaration
2569 : opt_attributes IDENTIFIER
2571 var lt = (Tokenizer.LocatedToken) $2;
2572 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2573 ((Enum) current_class).AddEnumMember (em);
2576 em.DocComment = Lexer.consume_doc_comment ();
2577 Lexer.doc_state = XmlCommentState.Allowed;
2582 | opt_attributes IDENTIFIER
2584 ++lexer.parsing_block;
2586 tmpComment = Lexer.consume_doc_comment ();
2587 Lexer.doc_state = XmlCommentState.NotAllowed;
2590 ASSIGN constant_expression
2592 --lexer.parsing_block;
2594 var lt = (Tokenizer.LocatedToken) $2;
2595 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2596 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2597 ((Enum) current_class).AddEnumMember (em);
2600 em.DocComment = ConsumeStoredComment ();
2606 delegate_declaration
2610 member_type type_declaration_name
2613 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2615 opt_formal_parameter_list CLOSE_PARENS
2617 valid_param_mod = 0;
2619 MemberName name = MakeName ((MemberName) $5);
2620 ParametersCompiled p = (ParametersCompiled) $8;
2622 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2623 (Modifiers) $2, name, p, (Attributes) $1);
2626 del.DocComment = Lexer.consume_doc_comment ();
2627 Lexer.doc_state = XmlCommentState.Allowed;
2630 current_container.AddDelegate (del);
2631 current_delegate = del;
2632 lexer.ConstraintsParsing = true;
2634 opt_type_parameter_constraints_clauses
2636 lexer.ConstraintsParsing = false;
2640 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2641 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2643 $$ = current_delegate;
2645 current_delegate = null;
2653 if (lang_version < LanguageVersion.ISO_2)
2654 FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2656 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2660 namespace_or_type_name
2662 | qualified_alias_member IDENTIFIER opt_type_argument_list
2664 var lt1 = (Tokenizer.LocatedToken) $1;
2665 var lt2 = (Tokenizer.LocatedToken) $2;
2667 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2673 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2675 var lt = (Tokenizer.LocatedToken) $3;
2676 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2677 lbag.AddLocation ($$, GetLocation ($2));
2682 : IDENTIFIER opt_type_argument_list
2684 var lt = (Tokenizer.LocatedToken) $1;
2685 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2690 // Generics arguments (any type, without attributes)
2692 opt_type_argument_list
2694 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2696 if (lang_version < LanguageVersion.ISO_2)
2697 FeatureIsNotAvailable (GetLocation ($1), "generics");
2701 | OP_GENERICS_LT error
2703 Error_TypeExpected (lexer.Location);
2704 $$ = new TypeArguments ();
2711 TypeArguments type_args = new TypeArguments ();
2712 type_args.Add ((FullNamedExpression) $1);
2715 | type_arguments COMMA type
2717 TypeArguments type_args = (TypeArguments) $1;
2718 type_args.Add ((FullNamedExpression) $3);
2724 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2726 type_declaration_name
2729 lexer.parsing_generic_declaration = true;
2731 opt_type_parameter_list
2733 lexer.parsing_generic_declaration = false;
2734 var lt = (Tokenizer.LocatedToken) $1;
2735 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2739 member_declaration_name
2740 : method_declaration_name
2742 MemberName mn = (MemberName)$1;
2743 if (mn.TypeArguments != null)
2744 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2745 mn.GetSignatureForError ()));
2749 method_declaration_name
2750 : type_declaration_name
2751 | explicit_interface IDENTIFIER opt_type_parameter_list
2753 lexer.parsing_generic_declaration = false;
2754 var lt = (Tokenizer.LocatedToken) $2;
2755 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2759 indexer_declaration_name
2762 lexer.parsing_generic_declaration = false;
2763 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2765 | explicit_interface THIS
2767 lexer.parsing_generic_declaration = false;
2768 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2773 : IDENTIFIER opt_type_argument_list DOT
2775 var lt = (Tokenizer.LocatedToken) $1;
2776 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2777 lbag.AddLocation ($$, GetLocation ($3));
2779 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2781 var lt1 = (Tokenizer.LocatedToken) $1;
2782 var lt2 = (Tokenizer.LocatedToken) $2;
2784 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2785 lbag.AddLocation ($$, GetLocation ($4));
2787 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2789 var lt = (Tokenizer.LocatedToken) $2;
2790 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2791 lbag.AddLocation ($$, GetLocation ($4));
2795 opt_type_parameter_list
2797 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2799 if (lang_version < LanguageVersion.ISO_2)
2800 FeatureIsNotAvailable (GetLocation ($1), "generics");
2803 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2810 TypeArguments type_args = new TypeArguments ();
2811 type_args.Add ((FullNamedExpression)$1);
2814 | type_parameters COMMA type_parameter
2816 TypeArguments type_args = (TypeArguments) $1;
2817 type_args.Add ((FullNamedExpression)$3);
2819 lbag.AddLocation ($3, GetLocation ($3));
2824 : opt_attributes opt_type_parameter_variance IDENTIFIER
2826 var lt = (Tokenizer.LocatedToken)$3;
2827 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2831 if (GetTokenName (yyToken) == "type")
2832 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2834 Error_SyntaxError (yyToken);
2836 $$ = new TypeParameterName ("", null, lexer.Location);
2841 // All types where void is allowed
2844 : type_expression_or_array
2847 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2854 lexer.parsing_generic_declaration = true;
2859 // A type which does not allow `void' to be used
2862 : type_expression_or_array
2865 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2866 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2874 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2875 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2880 : type_expression_or_array
2883 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2884 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2888 type_expression_or_array
2890 | type_expression rank_specifiers
2892 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2897 : namespace_or_type_name opt_nullable
2899 MemberName name = (MemberName) $1;
2902 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2904 if (name.Left == null && name.Name == "var")
2905 $$ = new VarExpr (name.Location);
2907 $$ = name.GetTypeExpression ();
2910 | namespace_or_type_name pointer_stars
2912 $$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2);
2914 | builtin_types opt_nullable
2917 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2919 | builtin_types pointer_stars
2921 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2923 | VOID pointer_stars
2925 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2932 var types = new List<FullNamedExpression> (2);
2933 types.Add ((FullNamedExpression) $1);
2936 | type_list COMMA base_type_name
2938 var types = (List<FullNamedExpression>) $1;
2939 types.Add ((FullNamedExpression) $3);
2947 if ($1 is ComposedCast) {
2948 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2954 Error_TypeExpected (lexer.Location);
2960 * replaces all the productions for isolating the various
2961 * simple types, but we need this to reuse it easily in variable_type
2964 : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
2965 | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
2966 | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
2967 | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
2968 | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
2969 | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
2974 : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
2975 | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
2976 | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
2977 | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
2978 | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
2979 | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
2980 | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
2981 | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
2982 | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
2986 // Expressions, section 7.5
2991 : primary_expression_or_type
2993 | array_creation_expression
2994 | parenthesized_expression
2995 | default_value_expression
2996 | invocation_expression
3000 | post_increment_expression
3001 | post_decrement_expression
3002 | object_or_delegate_creation_expression
3003 | anonymous_type_expression
3006 | checked_expression
3007 | unchecked_expression
3008 | pointer_member_access
3009 | anonymous_method_expression
3012 primary_expression_or_type
3013 : IDENTIFIER opt_type_argument_list
3015 var lt = (Tokenizer.LocatedToken) $1;
3016 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3018 | IDENTIFIER GENERATE_COMPLETION {
3019 var lt = (Tokenizer.LocatedToken) $1;
3020 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3028 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3032 : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
3033 | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
3038 // Here is the trick, tokenizer may think that parens is a special but
3039 // parser is interested in open parens only, so we merge them.
3040 // Consider: if (a)foo ();
3048 // Use this production to accept closing parenthesis or
3049 // performing completion
3053 | COMPLETE_COMPLETION
3057 parenthesized_expression
3058 : OPEN_PARENS expression CLOSE_PARENS
3060 $$ = new ParenthesizedExpression ((Expression) $2);
3061 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3063 | OPEN_PARENS expression COMPLETE_COMPLETION
3065 $$ = new ParenthesizedExpression ((Expression) $2);
3070 : primary_expression DOT IDENTIFIER opt_type_argument_list
3072 var lt = (Tokenizer.LocatedToken) $3;
3073 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3074 lbag.AddLocation ($$, GetLocation ($2));
3076 | builtin_types DOT IDENTIFIER opt_type_argument_list
3078 var lt = (Tokenizer.LocatedToken) $3;
3079 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3080 lbag.AddLocation ($$, GetLocation ($2));
3082 | BASE DOT IDENTIFIER opt_type_argument_list
3084 var lt = (Tokenizer.LocatedToken) $3;
3085 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3086 lbag.AddLocation ($$, GetLocation ($2));
3088 | qualified_alias_member IDENTIFIER opt_type_argument_list
3090 var lt1 = (Tokenizer.LocatedToken) $1;
3091 var lt2 = (Tokenizer.LocatedToken) $2;
3093 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3095 | primary_expression DOT GENERATE_COMPLETION {
3096 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3098 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3099 var lt = (Tokenizer.LocatedToken) $3;
3100 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3102 | builtin_types DOT GENERATE_COMPLETION
3104 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3106 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3107 var lt = (Tokenizer.LocatedToken) $3;
3108 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3112 invocation_expression
3113 : primary_expression open_parens_any opt_argument_list close_parens
3115 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3116 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3120 opt_object_or_collection_initializer
3121 : /* empty */ { $$ = null; }
3122 | object_or_collection_initializer
3125 object_or_collection_initializer
3126 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3129 $$ = CollectionOrObjectInitializers.Empty;
3132 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3133 lbag.AddLocation ($$, GetLocation ($3));
3136 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3138 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3139 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3143 opt_member_initializer_list
3144 : /* empty */ { $$ = null; }
3145 | member_initializer_list
3151 member_initializer_list
3152 : member_initializer
3154 var a = new List<Expression> ();
3155 a.Add ((Expression) $1);
3158 | member_initializer_list COMMA member_initializer
3160 var a = (List<Expression>)$1;
3161 a.Add ((Expression) $3);
3164 | member_initializer_list error {
3165 Error_SyntaxError (yyToken);
3171 : IDENTIFIER ASSIGN initializer_value
3173 var lt = (Tokenizer.LocatedToken) $1;
3174 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3175 lbag.AddLocation ($$, GetLocation ($2));
3177 | GENERATE_COMPLETION
3179 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3181 | non_assignment_expression opt_COMPLETE_COMPLETION {
3182 CompletionSimpleName csn = $1 as CompletionSimpleName;
3184 $$ = new CollectionElementInitializer ((Expression)$1);
3186 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3188 | OPEN_BRACE expression_list CLOSE_BRACE
3193 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3195 | OPEN_BRACE CLOSE_BRACE
3197 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3204 | object_or_collection_initializer
3208 : /* empty */ { $$ = null; }
3213 : argument_or_named_argument
3215 Arguments list = new Arguments (4);
3216 list.Add ((Argument) $1);
3219 | argument_list COMMA argument
3221 Arguments list = (Arguments) $1;
3222 if (list [list.Count - 1] is NamedArgument)
3223 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3225 list.Add ((Argument) $3);
3228 | argument_list COMMA named_argument
3230 Arguments list = (Arguments) $1;
3231 NamedArgument a = (NamedArgument) $3;
3232 for (int i = 0; i < list.Count; ++i) {
3233 NamedArgument na = list [i] as NamedArgument;
3234 if (na != null && na.Name == a.Name)
3235 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3242 | argument_list COMMA
3244 Report.Error (839, GetLocation ($2), "An argument is missing");
3249 Report.Error (839, GetLocation ($1), "An argument is missing");
3257 $$ = new Argument ((Expression) $1);
3259 | non_simple_argument
3262 argument_or_named_argument
3268 : REF variable_reference
3270 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3271 lbag.AddLocation ($$, GetLocation ($1));
3273 | OUT variable_reference
3275 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3276 lbag.AddLocation ($$, GetLocation ($1));
3278 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3280 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3281 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3283 | ARGLIST OPEN_PARENS CLOSE_PARENS
3285 $$ = new Argument (new Arglist (GetLocation ($1)));
3286 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3295 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3297 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3298 lbag.AddLocation ($$, GetLocation ($4));
3305 var list = new List<Expression> (4);
3306 list.Add ((Expression) $1);
3309 | expression_list COMMA expression
3311 var list = (List<Expression>) $1;
3312 list.Add ((Expression) $3);
3315 | expression_list error {
3316 Error_SyntaxError (yyToken);
3321 expression_list_arguments
3322 : expression_list_argument
3324 Arguments args = new Arguments (4);
3325 args.Add ((Argument) $1);
3328 | expression_list_arguments COMMA expression_list_argument
3330 Arguments args = (Arguments) $1;
3331 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3332 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3334 args.Add ((Argument) $3);
3339 expression_list_argument
3342 $$ = new Argument ((Expression) $1);
3350 $$ = new This (GetLocation ($1));
3355 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3357 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3358 lbag.AddLocation ($$, GetLocation ($4));
3360 | BASE OPEN_BRACKET error
3362 Error_SyntaxError (yyToken);
3363 $$ = new ElementAccess (null, null, GetLocation ($2));
3367 post_increment_expression
3368 : primary_expression OP_INC
3370 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3374 post_decrement_expression
3375 : primary_expression OP_DEC
3377 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3381 object_or_delegate_creation_expression
3382 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3385 if (lang_version <= LanguageVersion.ISO_2)
3386 FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3388 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3390 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3393 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3395 | NEW new_expr_type object_or_collection_initializer
3397 if (lang_version <= LanguageVersion.ISO_2)
3398 FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3400 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3404 array_creation_expression
3405 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3407 opt_array_initializer
3409 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3410 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3411 Next = (ComposedTypeSpecifier) $6
3412 }, (ArrayInitializer) $7, GetLocation ($1));
3413 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3415 | NEW new_expr_type rank_specifiers opt_array_initializer
3418 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3420 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3422 | NEW rank_specifier array_initializer
3424 if (lang_version <= LanguageVersion.ISO_2)
3425 FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3427 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3429 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3431 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3432 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3434 | NEW new_expr_type error
3436 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3437 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3443 ++lexer.parsing_type;
3447 --lexer.parsing_type;
3452 anonymous_type_expression
3453 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3455 if (lang_version <= LanguageVersion.ISO_2)
3456 FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3458 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3460 // TODO: lbag comma location
3461 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3465 anonymous_type_parameters_opt_comma
3466 : anonymous_type_parameters_opt
3467 | anonymous_type_parameters COMMA
3470 anonymous_type_parameters_opt
3472 | anonymous_type_parameters
3475 anonymous_type_parameters
3476 : anonymous_type_parameter
3478 var a = new List<AnonymousTypeParameter> (4);
3479 a.Add ((AnonymousTypeParameter) $1);
3482 | anonymous_type_parameters COMMA anonymous_type_parameter
3484 var a = (List<AnonymousTypeParameter>) $1;
3485 a.Add ((AnonymousTypeParameter) $3);
3490 anonymous_type_parameter
3491 : IDENTIFIER ASSIGN variable_initializer
3493 var lt = (Tokenizer.LocatedToken)$1;
3494 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3495 lbag.AddLocation ($$, GetLocation ($2));
3499 var lt = (Tokenizer.LocatedToken)$1;
3500 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3501 lt.Value, lt.Location);
3505 MemberAccess ma = (MemberAccess) $1;
3506 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3510 Report.Error (746, lexer.Location,
3511 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3523 | rank_specifier rank_specifiers
3525 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3531 : OPEN_BRACKET CLOSE_BRACKET
3533 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3534 lbag.AddLocation ($$, GetLocation ($2));
3536 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3538 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3539 lbag.AddLocation ($$, GetLocation ($3));
3548 | dim_separators COMMA
3550 $$ = ((int) $1) + 1;
3554 opt_array_initializer
3566 : OPEN_BRACE CLOSE_BRACE
3568 var ai = new ArrayInitializer (0, GetLocation ($1));
3569 ai.VariableDeclaration = current_variable;
3570 lbag.AddLocation (ai, GetLocation ($2));
3573 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3575 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3576 ai.VariableDeclaration = current_variable;
3578 lbag.AddLocation (ai, GetLocation ($3), GetLocation ($4));
3580 lbag.AddLocation (ai, GetLocation ($4));
3586 variable_initializer_list
3587 : variable_initializer
3589 var list = new List<Expression> (4);
3590 list.Add ((Expression) $1);
3593 | variable_initializer_list COMMA variable_initializer
3595 var list = (List<Expression>) $1;
3596 list.Add ((Expression) $3);
3604 lexer.TypeOfParsing = true;
3606 open_parens_any typeof_type_expression CLOSE_PARENS
3608 lexer.TypeOfParsing = false;
3609 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3610 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3614 typeof_type_expression
3619 Error_TypeExpected (lexer.Location);
3625 : IDENTIFIER generic_dimension
3627 var lt = (Tokenizer.LocatedToken) $1;
3629 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3631 | qualified_alias_member IDENTIFIER generic_dimension
3633 var lt1 = (Tokenizer.LocatedToken) $1;
3634 var lt2 = (Tokenizer.LocatedToken) $2;
3636 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3638 | unbound_type_name DOT IDENTIFIER
3640 var lt = (Tokenizer.LocatedToken) $3;
3642 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3644 | unbound_type_name DOT IDENTIFIER generic_dimension
3646 var lt = (Tokenizer.LocatedToken) $3;
3648 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3650 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3652 var te = ((MemberName) $1).GetTypeExpression ();
3653 if (te.HasTypeArguments)
3654 Error_TypeExpected (GetLocation ($4));
3656 var lt = (Tokenizer.LocatedToken) $3;
3657 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3664 if (lang_version < LanguageVersion.ISO_2)
3665 FeatureIsNotAvailable (GetLocation ($1), "generics");
3671 qualified_alias_member
3672 : IDENTIFIER DOUBLE_COLON
3674 var lt = (Tokenizer.LocatedToken) $1;
3675 if (lang_version == LanguageVersion.ISO_1)
3676 FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3683 : SIZEOF open_parens_any type CLOSE_PARENS
3685 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3686 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3691 : CHECKED open_parens_any expression CLOSE_PARENS
3693 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3694 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3698 unchecked_expression
3699 : UNCHECKED open_parens_any expression CLOSE_PARENS
3701 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3702 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3706 pointer_member_access
3707 : primary_expression OP_PTR IDENTIFIER
3709 var lt = (Tokenizer.LocatedToken) $3;
3710 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3714 anonymous_method_expression
3715 : DELEGATE opt_anonymous_method_signature
3717 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3721 $$ = end_anonymous ((ParametersBlock) $4);
3725 opt_anonymous_method_signature
3728 $$ = ParametersCompiled.Undefined;
3730 | anonymous_method_signature
3733 anonymous_method_signature
3736 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3738 opt_formal_parameter_list CLOSE_PARENS
3740 valid_param_mod = 0;
3745 default_value_expression
3746 : DEFAULT open_parens_any type CLOSE_PARENS
3748 if (lang_version < LanguageVersion.ISO_2)
3749 FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3751 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3752 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3757 : primary_expression
3758 | BANG prefixed_unary_expression
3760 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3762 | TILDE prefixed_unary_expression
3764 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3770 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3772 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3773 lbag.AddLocation ($$, GetLocation ($3));
3778 // The idea to split this out is from Rhys' grammar
3779 // to solve the problem with casts.
3781 prefixed_unary_expression
3783 | PLUS prefixed_unary_expression
3785 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3787 | MINUS prefixed_unary_expression
3789 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3791 | OP_INC prefixed_unary_expression
3793 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3795 | OP_DEC prefixed_unary_expression
3797 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3799 | STAR prefixed_unary_expression
3801 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3803 | BITWISE_AND prefixed_unary_expression
3805 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3809 multiplicative_expression
3810 : prefixed_unary_expression
3811 | multiplicative_expression STAR prefixed_unary_expression
3813 $$ = new Binary (Binary.Operator.Multiply,
3814 (Expression) $1, (Expression) $3, GetLocation ($2));
3816 | multiplicative_expression DIV prefixed_unary_expression
3818 $$ = new Binary (Binary.Operator.Division,
3819 (Expression) $1, (Expression) $3, GetLocation ($2));
3821 | multiplicative_expression PERCENT prefixed_unary_expression
3823 $$ = new Binary (Binary.Operator.Modulus,
3824 (Expression) $1, (Expression) $3, GetLocation ($2));
3829 : multiplicative_expression
3830 | additive_expression PLUS multiplicative_expression
3832 $$ = new Binary (Binary.Operator.Addition,
3833 (Expression) $1, (Expression) $3, GetLocation ($2));
3835 | additive_expression MINUS multiplicative_expression
3837 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3839 | parenthesized_expression MINUS multiplicative_expression
3841 // Shift/Reduce conflict
3842 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3844 | additive_expression AS type
3846 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3848 | additive_expression IS type
3850 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3855 : additive_expression
3856 | shift_expression OP_SHIFT_LEFT additive_expression
3858 $$ = new Binary (Binary.Operator.LeftShift,
3859 (Expression) $1, (Expression) $3, GetLocation ($2));
3861 | shift_expression OP_SHIFT_RIGHT additive_expression
3863 $$ = new Binary (Binary.Operator.RightShift,
3864 (Expression) $1, (Expression) $3, GetLocation ($2));
3868 relational_expression
3870 | relational_expression OP_LT shift_expression
3872 $$ = new Binary (Binary.Operator.LessThan,
3873 (Expression) $1, (Expression) $3, GetLocation ($2));
3875 | relational_expression OP_GT shift_expression
3877 $$ = new Binary (Binary.Operator.GreaterThan,
3878 (Expression) $1, (Expression) $3, GetLocation ($2));
3880 | relational_expression OP_LE shift_expression
3882 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3883 (Expression) $1, (Expression) $3, GetLocation ($2));
3885 | relational_expression OP_GE shift_expression
3887 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3888 (Expression) $1, (Expression) $3, GetLocation ($2));
3893 : relational_expression
3894 | equality_expression OP_EQ relational_expression
3896 $$ = new Binary (Binary.Operator.Equality,
3897 (Expression) $1, (Expression) $3, GetLocation ($2));
3899 | equality_expression OP_NE relational_expression
3901 $$ = new Binary (Binary.Operator.Inequality,
3902 (Expression) $1, (Expression) $3, GetLocation ($2));
3907 : equality_expression
3908 | and_expression BITWISE_AND equality_expression
3910 $$ = new Binary (Binary.Operator.BitwiseAnd,
3911 (Expression) $1, (Expression) $3, GetLocation ($2));
3915 exclusive_or_expression
3917 | exclusive_or_expression CARRET and_expression
3919 $$ = new Binary (Binary.Operator.ExclusiveOr,
3920 (Expression) $1, (Expression) $3, GetLocation ($2));
3924 inclusive_or_expression
3925 : exclusive_or_expression
3926 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3928 $$ = new Binary (Binary.Operator.BitwiseOr,
3929 (Expression) $1, (Expression) $3, GetLocation ($2));
3933 conditional_and_expression
3934 : inclusive_or_expression
3935 | conditional_and_expression OP_AND inclusive_or_expression
3937 $$ = new Binary (Binary.Operator.LogicalAnd,
3938 (Expression) $1, (Expression) $3, GetLocation ($2));
3942 conditional_or_expression
3943 : conditional_and_expression
3944 | conditional_or_expression OP_OR conditional_and_expression
3946 $$ = new Binary (Binary.Operator.LogicalOr,
3947 (Expression) $1, (Expression) $3, GetLocation ($2));
3951 null_coalescing_expression
3952 : conditional_or_expression
3953 | conditional_or_expression OP_COALESCING null_coalescing_expression
3955 if (lang_version < LanguageVersion.ISO_2)
3956 FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3958 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3962 conditional_expression
3963 : null_coalescing_expression
3964 | null_coalescing_expression INTERR expression COLON expression
3966 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3967 lbag.AddLocation ($$, GetLocation ($4));
3971 assignment_expression
3972 : prefixed_unary_expression ASSIGN expression
3974 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3976 | prefixed_unary_expression OP_MULT_ASSIGN expression
3978 $$ = new CompoundAssign (
3979 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3981 | prefixed_unary_expression OP_DIV_ASSIGN expression
3983 $$ = new CompoundAssign (
3984 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3986 | prefixed_unary_expression OP_MOD_ASSIGN expression
3988 $$ = new CompoundAssign (
3989 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
3991 | prefixed_unary_expression OP_ADD_ASSIGN expression
3993 $$ = new CompoundAssign (
3994 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
3996 | prefixed_unary_expression OP_SUB_ASSIGN expression
3998 $$ = new CompoundAssign (
3999 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
4001 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
4003 $$ = new CompoundAssign (
4004 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4006 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
4008 $$ = new CompoundAssign (
4009 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4011 | prefixed_unary_expression OP_AND_ASSIGN expression
4013 $$ = new CompoundAssign (
4014 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4016 | prefixed_unary_expression OP_OR_ASSIGN expression
4018 $$ = new CompoundAssign (
4019 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4021 | prefixed_unary_expression OP_XOR_ASSIGN expression
4023 $$ = new CompoundAssign (
4024 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4028 lambda_parameter_list
4031 var pars = new List<Parameter> (4);
4032 pars.Add ((Parameter) $1);
4036 | lambda_parameter_list COMMA lambda_parameter
4038 var pars = (List<Parameter>) $1;
4039 Parameter p = (Parameter)$3;
4040 if (pars[0].GetType () != p.GetType ()) {
4041 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4050 : parameter_modifier parameter_type IDENTIFIER
4052 var lt = (Tokenizer.LocatedToken) $3;
4054 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4056 | parameter_type IDENTIFIER
4058 var lt = (Tokenizer.LocatedToken) $2;
4060 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4064 var lt = (Tokenizer.LocatedToken) $1;
4065 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4069 opt_lambda_parameter_list
4070 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4071 | lambda_parameter_list {
4072 var pars_list = (List<Parameter>) $1;
4073 $$ = new ParametersCompiled (pars_list.ToArray ());
4077 lambda_expression_body
4078 : lambda_expression_body_simple
4082 lambda_expression_body_simple
4084 start_block (lexer.Location);
4086 expression_or_error // Have to close block when error occurs
4088 Block b = end_block (lexer.Location);
4089 b.AddStatement (new ContextualReturn ((Expression) $2));
4098 Error_SyntaxError (yyToken);
4099 $$ = EmptyExpression.Null;
4106 var lt = (Tokenizer.LocatedToken) $1;
4107 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4108 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4110 lambda_expression_body
4112 $$ = end_anonymous ((ParametersBlock) $4);
4113 lbag.AddLocation ($$, GetLocation ($2));
4115 | OPEN_PARENS_LAMBDA
4117 if (lang_version <= LanguageVersion.ISO_2)
4118 FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4120 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4122 opt_lambda_parameter_list CLOSE_PARENS ARROW
4124 valid_param_mod = 0;
4125 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4127 lambda_expression_body
4129 $$ = end_anonymous ((ParametersBlock) $7);
4130 lbag.AddLocation ($$, GetLocation ($4), GetLocation ($5));
4135 : assignment_expression
4136 | non_assignment_expression
4139 non_assignment_expression
4140 : conditional_expression
4145 $$ = new ArglistAccess (GetLocation ($1));
4156 $$ = new BooleanExpression ((Expression) $1);
4169 lexer.ConstraintsParsing = true;
4171 type_declaration_name
4173 MemberName name = MakeName ((MemberName) $6);
4174 Class c = new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1);
4175 if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
4176 FeatureIsNotAvailable (c.Location, "static classes");
4179 push_current_class (c, $3);
4182 opt_type_parameter_constraints_clauses
4184 lexer.ConstraintsParsing = false;
4186 current_class.SetParameterInfo ((List<Constraints>) $9);
4187 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4190 current_container.DocComment = Lexer.consume_doc_comment ();
4191 Lexer.doc_state = XmlCommentState.Allowed;
4194 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4196 --lexer.parsing_declaration;
4198 Lexer.doc_state = XmlCommentState.Allowed;
4202 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4203 $$ = pop_current_class ();
4211 { $$ = $1; } // location
4217 mod_locations = null;
4225 | modifiers modifier
4227 var m1 = (Modifiers) $1;
4228 var m2 = (Modifiers) $2;
4230 if ((m1 & m2) != 0) {
4231 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4232 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4233 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4234 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4235 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4236 "More than one protection modifier specified");
4247 StoreModifierLocation ($$, GetLocation ($1));
4249 if (current_container == RootContext.ToplevelTypes)
4250 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4254 $$ = Modifiers.PUBLIC;
4255 StoreModifierLocation ($$, GetLocation ($1));
4259 $$ = Modifiers.PROTECTED;
4260 StoreModifierLocation ($$, GetLocation ($1));
4264 $$ = Modifiers.INTERNAL;
4265 StoreModifierLocation ($$, GetLocation ($1));
4269 $$ = Modifiers.PRIVATE;
4270 StoreModifierLocation ($$, GetLocation ($1));
4274 $$ = Modifiers.ABSTRACT;
4275 StoreModifierLocation ($$, GetLocation ($1));
4279 $$ = Modifiers.SEALED;
4280 StoreModifierLocation ($$, GetLocation ($1));
4284 $$ = Modifiers.STATIC;
4285 StoreModifierLocation ($$, GetLocation ($1));
4289 $$ = Modifiers.READONLY;
4290 StoreModifierLocation ($$, GetLocation ($1));
4294 $$ = Modifiers.VIRTUAL;
4295 StoreModifierLocation ($$, GetLocation ($1));
4299 $$ = Modifiers.OVERRIDE;
4300 StoreModifierLocation ($$, GetLocation ($1));
4304 $$ = Modifiers.EXTERN;
4305 StoreModifierLocation ($$, GetLocation ($1));
4309 $$ = Modifiers.VOLATILE;
4310 StoreModifierLocation ($$, GetLocation ($1));
4314 $$ = Modifiers.UNSAFE;
4315 StoreModifierLocation ($$, GetLocation ($1));
4316 if (!settings.Unsafe)
4317 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4321 $$ = Modifiers.ASYNC;
4322 StoreModifierLocation ($$, GetLocation ($1));
4330 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4334 opt_type_parameter_constraints_clauses
4336 | type_parameter_constraints_clauses
4342 Error_SyntaxError (yyToken);
4347 type_parameter_constraints_clauses
4348 : type_parameter_constraints_clause
4350 var constraints = new List<Constraints> (1);
4351 constraints.Add ((Constraints) $1);
4354 | type_parameter_constraints_clauses type_parameter_constraints_clause
4356 var constraints = (List<Constraints>) $1;
4357 Constraints new_constraint = (Constraints)$2;
4359 foreach (Constraints c in constraints) {
4360 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4361 Report.Error (409, new_constraint.Location,
4362 "A constraint clause has already been specified for type parameter `{0}'",
4363 new_constraint.TypeParameter.Value);
4367 constraints.Add (new_constraint);
4372 type_parameter_constraints_clause
4373 : WHERE IDENTIFIER COLON type_parameter_constraints
4375 var lt = (Tokenizer.LocatedToken) $2;
4376 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4380 type_parameter_constraints
4381 : type_parameter_constraint
4383 var constraints = new List<FullNamedExpression> (1);
4384 constraints.Add ((FullNamedExpression) $1);
4387 | type_parameter_constraints COMMA type_parameter_constraint
4389 var constraints = (List<FullNamedExpression>) $1;
4390 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4391 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4392 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4395 prev = $3 as SpecialContraintExpr;
4397 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4398 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4400 prev = constraints [0] as SpecialContraintExpr;
4401 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4402 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4407 constraints.Add ((FullNamedExpression) $3);
4412 type_parameter_constraint
4415 if ($1 is ComposedCast)
4416 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4420 | NEW OPEN_PARENS CLOSE_PARENS
4422 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4423 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4427 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4431 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4435 opt_type_parameter_variance
4440 | type_parameter_variance
4442 if (lang_version <= LanguageVersion.V_3)
4443 FeatureIsNotAvailable (lexer.Location, "generic type variance");
4449 type_parameter_variance
4452 $$ = Variance.Covariant;
4456 $$ = Variance.Contravariant;
4465 // A block is "contained" on the following places:
4467 // property_declaration as part of the accessor body (get/set)
4468 // operator_declaration
4469 // constructor_declaration
4470 // destructor_declaration
4471 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4476 ++lexer.parsing_block;
4477 start_block (GetLocation ($1));
4479 opt_statement_list block_end
4488 --lexer.parsing_block;
4489 $$ = end_block (GetLocation ($1));
4491 | COMPLETE_COMPLETION
4493 --lexer.parsing_block;
4494 $$ = end_block (lexer.Location);
4502 ++lexer.parsing_block;
4503 current_block.StartLocation = GetLocation ($1);
4505 opt_statement_list CLOSE_BRACE
4507 --lexer.parsing_block;
4508 $$ = end_block (GetLocation ($4));
4519 | statement_list statement
4523 : block_variable_declaration
4525 current_block.AddStatement ((Statement) $1);
4527 | valid_declaration_statement
4529 current_block.AddStatement ((Statement) $1);
4534 Error_SyntaxError (yyToken);
4540 // The interactive_statement and its derivatives are only
4541 // used to provide a special version of `expression_statement'
4542 // that has a side effect of assigning the expression to
4545 interactive_statement_list
4546 : interactive_statement
4547 | interactive_statement_list interactive_statement
4550 interactive_statement
4551 : block_variable_declaration
4553 current_block.AddStatement ((Statement) $1);
4555 | interactive_valid_declaration_statement
4557 current_block.AddStatement ((Statement) $1);
4562 valid_declaration_statement
4565 | expression_statement
4566 | selection_statement
4567 | iteration_statement
4571 | unchecked_statement
4578 interactive_valid_declaration_statement
4581 | interactive_expression_statement
4582 | selection_statement
4583 | iteration_statement
4587 | unchecked_statement
4595 : valid_declaration_statement
4596 | block_variable_declaration
4598 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4603 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4608 Error_SyntaxError (yyToken);
4609 $$ = new EmptyStatement (GetLocation ($1));
4616 // Uses lexer.Location because semicolon location is not kept in quick mode
4617 $$ = new EmptyStatement (lexer.Location);
4624 var lt = (Tokenizer.LocatedToken) $1;
4625 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4627 current_block.AddLabel (labeled);
4628 current_block.AddStatement (labeled);
4634 : variable_type_simple
4635 | variable_type_simple rank_specifiers
4638 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4640 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4645 * The following is from Rhys' grammar:
4646 * > Types in local variable declarations must be recognized as
4647 * > expressions to prevent reduce/reduce errors in the grammar.
4648 * > The expressions are converted into types during semantic analysis.
4650 variable_type_simple
4651 : primary_expression_or_type opt_nullable
4653 // Ok, the above "primary_expression" is there to get rid of
4654 // both reduce/reduce and shift/reduces in the grammar, it should
4655 // really just be "type_name". If you use type_name, a reduce/reduce
4656 // creeps up. If you use namespace_or_type_name (which is all we need
4657 // really) two shift/reduces appear.
4660 // So the super-trick is that primary_expression
4661 // can only be either a SimpleName or a MemberAccess.
4662 // The MemberAccess case arises when you have a fully qualified type-name like :
4664 // SimpleName is when you have
4667 Expression expr = (Expression) $1;
4669 SimpleName sn = expr as SimpleName;
4670 if (sn != null && sn.Name == "var")
4671 $$ = new VarExpr (sn.Location);
4674 } else if (expr is ATypeNameExpression) {
4675 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4677 Error_ExpectingTypeName (expr);
4681 | primary_expression_or_type pointer_stars
4683 ATypeNameExpression expr = $1 as ATypeNameExpression;
4686 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4688 Error_ExpectingTypeName ((Expression)$1);
4692 | builtin_types opt_nullable
4697 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4699 | builtin_types pointer_stars
4701 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4703 | VOID pointer_stars
4705 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4709 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4710 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4716 | pointer_star pointer_stars
4718 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4726 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4730 block_variable_declaration
4731 : variable_type IDENTIFIER
4733 var lt = (Tokenizer.LocatedToken) $2;
4734 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4735 current_block.AddLocalName (li);
4736 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4738 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4740 $$ = current_variable;
4741 current_variable = null;
4742 lbag.AddLocation ($$, GetLocation ($6));
4744 | CONST variable_type IDENTIFIER
4746 var lt = (Tokenizer.LocatedToken) $3;
4747 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4748 current_block.AddLocalName (li);
4749 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4751 const_variable_initializer opt_const_declarators SEMICOLON
4753 $$ = current_variable;
4754 current_variable = null;
4755 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4759 opt_local_variable_initializer
4761 | ASSIGN block_variable_initializer
4763 current_variable.Initializer = (Expression) $2;
4768 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4769 Report.Error (650, lexer.Location,
4770 "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");
4772 Error_SyntaxError (yyToken);
4777 opt_variable_declarators
4779 | variable_declarators
4782 variable_declarators
4783 : variable_declarator
4784 | variable_declarators variable_declarator
4790 var lt = (Tokenizer.LocatedToken) $2;
4791 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4792 var d = new BlockVariableDeclaration.Declarator (li, null);
4793 current_variable.AddDeclarator (d);
4794 current_block.AddLocalName (li);
4795 lbag.AddLocation (d, GetLocation ($1));
4797 | COMMA IDENTIFIER ASSIGN block_variable_initializer
4799 var lt = (Tokenizer.LocatedToken) $2;
4800 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4801 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4802 current_variable.AddDeclarator (d);
4803 current_block.AddLocalName (li);
4804 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4808 const_variable_initializer
4811 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
4813 | ASSIGN constant_initializer_expr
4815 current_variable.Initializer = (Expression) $2;
4819 opt_const_declarators
4826 | const_declarators const_declarator
4830 : COMMA IDENTIFIER ASSIGN constant_initializer_expr
4832 var lt = (Tokenizer.LocatedToken) $2;
4833 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4834 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4835 current_variable.AddDeclarator (d);
4836 current_block.AddLocalName (li);
4837 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4841 block_variable_initializer
4842 : variable_initializer
4843 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4845 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4846 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4848 | STACKALLOC simple_type
4850 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4851 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4855 expression_statement
4856 : statement_expression SEMICOLON
4859 lbag.AddStatement ($$, GetLocation ($2));
4861 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4864 interactive_expression_statement
4865 : interactive_statement_expression SEMICOLON { $$ = $1; }
4866 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4870 // We have to do the wrapping here and not in the case above,
4871 // because statement_expression is used for example in for_statement
4873 statement_expression
4876 ExpressionStatement s = $1 as ExpressionStatement;
4878 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4879 s = EmptyExpressionStatement.Instance;
4882 $$ = new StatementExpression (s);
4886 interactive_statement_expression
4889 Expression expr = (Expression) $1;
4890 ExpressionStatement s;
4892 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4893 $$ = new StatementExpression (s);
4897 Error_SyntaxError (yyToken);
4898 $$ = new EmptyStatement (GetLocation ($1));
4908 : IF open_parens_any boolean_expression CLOSE_PARENS
4911 if ($5 is EmptyStatement)
4912 Warning_EmptyStatement (GetLocation ($5));
4914 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4915 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4917 | IF open_parens_any boolean_expression CLOSE_PARENS
4918 embedded_statement ELSE embedded_statement
4920 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4921 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4923 if ($5 is EmptyStatement)
4924 Warning_EmptyStatement (GetLocation ($5));
4925 if ($7 is EmptyStatement)
4926 Warning_EmptyStatement (GetLocation ($7));
4931 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
4933 start_block (GetLocation ($5));
4935 opt_switch_sections CLOSE_BRACE
4937 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
4938 end_block (GetLocation ($8));
4939 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4946 Report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
4947 $$ = new List<SwitchSection> ();
4955 var sections = new List<SwitchSection> (4);
4957 sections.Add ((SwitchSection) $1);
4960 | switch_sections switch_section
4962 var sections = (List<SwitchSection>) $1;
4964 sections.Add ((SwitchSection) $2);
4969 Error_SyntaxError (yyToken);
4970 $$ = new List<SwitchSection> ();
4977 current_block = current_block.CreateSwitchBlock (lexer.Location);
4981 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
4988 var labels = new List<SwitchLabel> (4);
4990 labels.Add ((SwitchLabel) $1);
4993 | switch_labels switch_label
4995 var labels = (List<SwitchLabel>) ($1);
4996 labels.Add ((SwitchLabel) $2);
5003 : CASE constant_expression COLON
5005 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
5006 lbag.AddLocation ($$, GetLocation ($3));
5010 $$ = new SwitchLabel (null, GetLocation ($1));
5022 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5024 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5025 Warning_EmptyStatement (GetLocation ($5));
5027 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5028 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5033 : DO embedded_statement
5034 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5036 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5037 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5042 : FOR open_parens_any
5044 start_block (GetLocation ($2));
5045 current_block.IsCompilerGenerated = true;
5053 // Has to use be extra rule to recover started block
5055 : opt_for_initializer SEMICOLON
5056 opt_for_condition SEMICOLON
5057 opt_for_iterator CLOSE_PARENS
5060 if ($7 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5061 Warning_EmptyStatement (GetLocation ($7));
5063 For f = new For ((Statement) $1, (BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($-2));
5064 current_block.AddStatement (f);
5066 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5068 $$ = end_block (GetLocation ($2));
5072 Error_SyntaxError (yyToken);
5073 $$ = end_block (current_block.StartLocation);
5078 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5083 : variable_type IDENTIFIER
5085 var lt = (Tokenizer.LocatedToken) $2;
5086 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5087 current_block.AddLocalName (li);
5088 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5090 opt_local_variable_initializer opt_variable_declarators
5092 $$ = current_variable;
5093 current_variable = null;
5095 | statement_expression_list
5099 : /* empty */ { $$ = null; }
5100 | boolean_expression
5104 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5109 : statement_expression_list
5112 statement_expression_list
5113 : statement_expression
5114 | statement_expression_list COMMA statement_expression
5116 var sl = $1 as StatementList;
5118 sl = new StatementList ((Statement) $1, (Statement) $3);
5119 lbag.AddStatement (sl, GetLocation ($2));
5121 sl.Add ((Statement) $3);
5122 lbag.AppendTo (sl, GetLocation ($2));
5130 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5132 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5135 | FOREACH open_parens_any type IDENTIFIER IN expression CLOSE_PARENS
5137 start_block (GetLocation ($2));
5138 current_block.IsCompilerGenerated = true;
5140 var lt = (Tokenizer.LocatedToken) $4;
5141 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5142 current_block.AddLocalName (li);
5147 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5148 Warning_EmptyStatement (GetLocation ($9));
5150 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5151 current_block.AddStatement (f);
5153 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5154 $$ = end_block (GetLocation ($7));
5160 | continue_statement
5170 $$ = new Break (GetLocation ($1));
5171 lbag.AddStatement ($$, GetLocation ($2));
5176 : CONTINUE SEMICOLON
5178 $$ = new Continue (GetLocation ($1));
5179 lbag.AddStatement ($$, GetLocation ($2));
5184 : GOTO IDENTIFIER SEMICOLON
5186 var lt = (Tokenizer.LocatedToken) $2;
5187 $$ = new Goto (lt.Value, lt.Location);
5188 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5190 | GOTO CASE constant_expression SEMICOLON
5192 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5193 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5195 | GOTO DEFAULT SEMICOLON
5197 $$ = new GotoDefault (GetLocation ($1));
5198 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5203 : RETURN opt_expression SEMICOLON
5205 $$ = new Return ((Expression) $2, GetLocation ($1));
5206 lbag.AddStatement ($$, GetLocation ($3));
5211 : THROW opt_expression SEMICOLON
5213 $$ = new Throw ((Expression) $2, GetLocation ($1));
5214 lbag.AddStatement ($$, GetLocation ($3));
5219 : IDENTIFIER RETURN opt_expression SEMICOLON
5221 var lt = (Tokenizer.LocatedToken) $1;
5222 string s = lt.Value;
5224 Report.Error (1003, lt.Location, "; expected");
5225 } else if ($3 == null) {
5226 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5227 } else if (lang_version == LanguageVersion.ISO_1){
5228 FeatureIsNotAvailable (lt.Location, "iterators");
5231 current_block.ParametersBlock.TopBlock.IsIterator = true;
5232 $$ = new Yield ((Expression) $3, lt.Location);
5233 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5235 | IDENTIFIER BREAK SEMICOLON
5237 var lt = (Tokenizer.LocatedToken) $1;
5238 string s = lt.Value;
5240 Report.Error (1003, lt.Location, "; expected");
5241 } else if (lang_version == LanguageVersion.ISO_1){
5242 FeatureIsNotAvailable (lt.Location, "iterators");
5245 current_block.ParametersBlock.TopBlock.IsIterator = true;
5246 $$ = new YieldBreak (lt.Location);
5247 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5257 : TRY block catch_clauses
5259 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5261 | TRY block FINALLY block
5263 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5264 lbag.AddStatement ($$, GetLocation ($3));
5266 | TRY block catch_clauses FINALLY block
5268 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5269 lbag.AddStatement ($$, GetLocation ($4));
5273 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5281 var l = new List<Catch> (2);
5286 | catch_clauses catch_clause
5288 var l = (List<Catch>) $1;
5290 Catch c = (Catch) $2;
5291 if (l [0].IsGeneral) {
5292 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5312 $$ = new Catch ((Block) $2, GetLocation ($1));
5314 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5316 start_block (GetLocation ($2));
5317 var c = new Catch (current_block, GetLocation ($1));
5318 c.TypeExpression = (FullNamedExpression) $3;
5321 var lt = (Tokenizer.LocatedToken) $4;
5322 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5323 current_block.AddLocalName (c.Variable);
5326 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5333 | CATCH open_parens_any error
5335 if (yyToken == Token.CLOSE_PARENS) {
5336 Report.Error (1015, lexer.Location,
5337 "A type that derives from `System.Exception', `object', or `string' expected");
5339 Error_SyntaxError (yyToken);
5342 $$ = new Catch (null, GetLocation ($1));
5349 $$ = new Checked ((Block) $2, GetLocation ($1));
5356 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5363 if (!settings.Unsafe)
5364 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5366 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5371 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5373 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5374 Warning_EmptyStatement (GetLocation ($5));
5376 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5377 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5382 : FIXED open_parens_any variable_type IDENTIFIER
5384 start_block (GetLocation ($2));
5386 current_block.IsCompilerGenerated = true;
5387 var lt = (Tokenizer.LocatedToken) $4;
5388 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5389 current_block.AddLocalName (li);
5390 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5392 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5394 $$ = current_variable;
5395 current_variable = null;
5399 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5400 Warning_EmptyStatement (GetLocation ($10));
5402 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5403 current_block.AddStatement (f);
5404 $$ = end_block (GetLocation ($8));
5409 : USING open_parens_any variable_type IDENTIFIER
5411 start_block (GetLocation ($2));
5413 current_block.IsCompilerGenerated = true;
5414 var lt = (Tokenizer.LocatedToken) $4;
5415 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5416 current_block.AddLocalName (li);
5417 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5419 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5421 $$ = current_variable;
5422 current_variable = null;
5426 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5427 Warning_EmptyStatement (GetLocation ($10));
5429 Using u = new Using ((Using.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5430 current_block.AddStatement (u);
5431 $$ = end_block (GetLocation ($8));
5433 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5435 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5436 Warning_EmptyStatement (GetLocation ($5));
5438 Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5439 lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
5444 using_or_fixed_variable_initializer
5447 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
5449 | ASSIGN variable_initializer
5451 current_variable.Initializer = (Expression) $2;
5452 $$ = current_variable;
5460 : first_from_clause query_body
5462 lexer.query_parsing = false;
5464 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5466 from.Tail.Next = (Linq.AQueryClause)$2;
5469 current_block.SetEndLocation (lexer.Location);
5470 current_block = current_block.Parent;
5472 | nested_from_clause query_body
5474 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5476 from.Tail.Next = (Linq.AQueryClause)$2;
5479 current_block.SetEndLocation (lexer.Location);
5480 current_block = current_block.Parent;
5483 // Bubble up COMPLETE_COMPLETION productions
5484 | first_from_clause COMPLETE_COMPLETION {
5485 lexer.query_parsing = false;
5488 current_block.SetEndLocation (lexer.Location);
5489 current_block = current_block.Parent;
5491 | nested_from_clause COMPLETE_COMPLETION {
5493 current_block.SetEndLocation (lexer.Location);
5494 current_block = current_block.Parent;
5499 : FROM_FIRST IDENTIFIER IN expression
5501 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5503 var lt = (Tokenizer.LocatedToken) $2;
5504 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5505 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5507 | FROM_FIRST type IDENTIFIER IN expression
5509 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5511 var lt = (Tokenizer.LocatedToken) $3;
5512 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5513 $$ = new Linq.QueryExpression (
5514 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5515 IdentifierType = (FullNamedExpression)$2
5522 : FROM IDENTIFIER IN expression
5524 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5526 var lt = (Tokenizer.LocatedToken) $2;
5527 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5528 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5530 | FROM type IDENTIFIER IN expression
5532 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5534 var lt = (Tokenizer.LocatedToken) $3;
5535 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5536 $$ = new Linq.QueryExpression (
5537 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5538 IdentifierType = (FullNamedExpression)$2
5545 : FROM IDENTIFIER IN
5547 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5551 var lt = (Tokenizer.LocatedToken) $2;
5552 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5553 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5555 current_block.SetEndLocation (lexer.Location);
5556 current_block = current_block.Parent;
5558 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5560 | FROM type IDENTIFIER IN
5562 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5566 var lt = (Tokenizer.LocatedToken) $3;
5567 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5569 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5570 IdentifierType = (FullNamedExpression)$2
5573 current_block.SetEndLocation (lexer.Location);
5574 current_block = current_block.Parent;
5576 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5581 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5583 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5586 head.Next = (Linq.AQueryClause)$3;
5589 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5590 clause.Tail.Next = head;
5596 | opt_query_body_clauses COMPLETE_COMPLETION
5599 Error_SyntaxError (yyToken);
5604 select_or_group_clause
5607 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5611 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5613 current_block.SetEndLocation (lexer.Location);
5614 current_block = current_block.Parent;
5618 if (linq_clause_blocks == null)
5619 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5621 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5622 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5626 current_block.SetEndLocation (lexer.Location);
5627 current_block = current_block.Parent;
5629 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5633 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5635 current_block.SetEndLocation (lexer.Location);
5636 current_block = current_block.Parent;
5640 opt_query_body_clauses
5642 | query_body_clauses
5647 | query_body_clauses query_body_clause
5649 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5663 : LET IDENTIFIER ASSIGN
5665 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5669 var lt = (Tokenizer.LocatedToken) $2;
5670 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5671 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5673 current_block.SetEndLocation (lexer.Location);
5674 current_block = current_block.Parent;
5676 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5683 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5687 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5689 current_block.SetEndLocation (lexer.Location);
5690 current_block = current_block.Parent;
5695 : JOIN IDENTIFIER IN
5697 if (linq_clause_blocks == null)
5698 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5700 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5701 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5705 current_block.SetEndLocation (lexer.Location);
5706 current_block = current_block.Parent;
5708 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5709 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5713 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5714 current_block.SetEndLocation (lexer.Location);
5715 current_block = current_block.Parent;
5717 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5719 expression opt_join_into
5721 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5722 current_block.SetEndLocation (lexer.Location);
5724 var outer_selector = linq_clause_blocks.Pop ();
5725 var block = linq_clause_blocks.Pop ();
5727 var lt = (Tokenizer.LocatedToken) $2;
5728 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5729 Linq.RangeVariable into;
5733 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5736 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5738 var parent = block.Parent;
5739 while (parent is Linq.QueryBlock) {
5740 parent = parent.Parent;
5742 current_block.Parent = parent;
5744 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5746 lt = (Tokenizer.LocatedToken) $12;
5747 into = new Linq.RangeVariable (lt.Value, lt.Location);
5749 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5752 current_block = block.Parent;
5753 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5755 | JOIN type IDENTIFIER IN
5757 if (linq_clause_blocks == null)
5758 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5760 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5761 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5765 current_block.SetEndLocation (lexer.Location);
5766 current_block = current_block.Parent;
5768 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5769 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5773 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5774 current_block.SetEndLocation (lexer.Location);
5775 current_block = current_block.Parent;
5777 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5779 expression opt_join_into
5781 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5782 current_block.SetEndLocation (lexer.Location);
5784 var outer_selector = linq_clause_blocks.Pop ();
5785 var block = linq_clause_blocks.Pop ();
5787 var lt = (Tokenizer.LocatedToken) $3;
5788 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5789 Linq.RangeVariable into;
5793 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5794 IdentifierType = (FullNamedExpression)$2
5798 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5800 var parent = block.Parent;
5801 while (parent is Linq.QueryBlock) {
5802 parent = parent.Parent;
5804 current_block.Parent = parent;
5806 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5808 lt = (Tokenizer.LocatedToken) $13;
5809 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
5811 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
5812 IdentifierType = (FullNamedExpression)$2
5816 current_block = block.Parent;
5817 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5832 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5836 current_block.SetEndLocation (lexer.Location);
5837 current_block = current_block.Parent;
5847 current_block.SetEndLocation (lexer.Location);
5848 current_block = current_block.Parent;
5850 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5854 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5861 | orderings_then_by COMMA
5863 current_block.SetEndLocation (lexer.Location);
5864 current_block = current_block.Parent;
5866 current_block = new Linq.QueryBlock ((Linq.QueryBlock) current_block, lexer.Location);
5870 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5878 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5880 | expression ASCENDING
5882 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5884 | expression DESCENDING
5886 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5893 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5895 | expression ASCENDING
5897 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5899 | expression DESCENDING
5901 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5906 opt_query_continuation
5910 // query continuation block is not linked with query block but with block
5911 // before. This means each query can use same range variable names for
5912 // different identifiers.
5914 current_block.SetEndLocation (GetLocation ($1));
5915 current_block = current_block.Parent;
5917 current_block = new Linq.QueryBlock (current_block, lexer.Location);
5919 if (linq_clause_blocks == null)
5920 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5922 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5926 var current_block = linq_clause_blocks.Pop ();
5927 var lt = (Tokenizer.LocatedToken) $2;
5928 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5929 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
5930 next = (Linq.AQueryClause)$4
5936 // Support for using the compiler as an interactive parser
5938 // The INTERACTIVE_PARSER token is first sent to parse our
5939 // productions; If the result is a Statement, the parsing
5940 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5941 // to setup the blocks in advance.
5943 // This setup is here so that in the future we can add
5944 // support for other constructs (type parsing, namespaces, etc)
5945 // that do not require a block to be setup in advance
5949 : EVAL_STATEMENT_PARSER EOF
5950 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
5951 | EVAL_STATEMENT_PARSER
5953 current_container = new Class (current_namespace, current_class, new MemberName ("<InteractiveExpressionClass>"), Modifiers.PUBLIC, null);
5954 current_class = current_container;
5956 var baseclass_list = new List<FullNamedExpression> ();
5957 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5958 current_container.AddBasesForPart (current_class, baseclass_list);
5960 // (ref object retval)
5961 Parameter [] mpar = new Parameter [1];
5962 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
5964 ParametersCompiled pars = new ParametersCompiled (mpar);
5965 var mods = Modifiers.PUBLIC | Modifiers.STATIC;
5966 if (settings.Unsafe)
5967 mods |= Modifiers.UNSAFE;
5969 current_local_parameters = pars;
5970 Method method = new Method (
5973 new TypeExpression (TypeManager.void_type, Location.Null),
5975 new MemberName ("Host"),
5977 null /* attributes */);
5979 current_container.AddMethod (method);
5981 oob_stack.Push (method);
5982 ++lexer.parsing_block;
5983 start_block (lexer.Location);
5985 interactive_statement_list opt_COMPLETE_COMPLETION
5987 --lexer.parsing_block;
5988 Method method = (Method) oob_stack.Pop ();
5990 method.Block = (ToplevelBlock) end_block(lexer.Location);
5992 InteractiveResult = (Class) pop_current_class ();
5993 current_local_parameters = null;
5995 | EVAL_COMPILATION_UNIT_PARSER interactive_compilation_unit
5998 interactive_compilation_unit
5999 : outer_declarations
6000 | outer_declarations global_attributes
6005 opt_COMPLETE_COMPLETION
6007 | COMPLETE_COMPLETION
6010 close_brace_or_complete_completion
6012 | COMPLETE_COMPLETION
6017 // A class used to hold info about an operator declarator
6019 class OperatorDeclaration {
6020 public readonly Operator.OpType optype;
6021 public readonly FullNamedExpression ret_type;
6022 public readonly Location location;
6024 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6027 this.ret_type = ret_type;
6028 this.location = location;
6032 void Error_ExpectingTypeName (Expression expr)
6034 if (expr is Invocation){
6035 Report.Error (1002, expr.Location, "Expecting `;'");
6037 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
6041 void Error_ParameterModifierNotValid (string modifier, Location loc)
6043 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6047 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6049 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6050 Parameter.GetModifierSignature (mod));
6053 void Error_TypeExpected (Location loc)
6055 Report.Error (1031, loc, "Type expected");
6058 void Error_UnsafeCodeNotAllowed (Location loc)
6060 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6063 void Warning_EmptyStatement (Location loc)
6065 Report.Warning (642, 3, loc, "Possible mistaken empty statement");
6068 void Error_NamedArgumentExpected (NamedArgument a)
6070 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6073 void push_current_class (TypeContainer tc, object partial_token)
6075 if (compiler.IsEvalutor){
6076 tc.Definition.Modifiers = tc.ModFlags = (tc.ModFlags & ~Modifiers.AccessibilityMask) | Modifiers.PUBLIC;
6079 undo.AddTypeContainer (current_container, tc);
6082 if (partial_token != null)
6083 current_container = current_container.AddPartial (tc);
6085 current_container = current_container.AddTypeContainer (tc);
6087 ++lexer.parsing_declaration;
6091 DeclSpace pop_current_class ()
6093 DeclSpace retval = current_class;
6095 current_class = current_class.Parent;
6096 current_container = current_class.PartialContainer;
6102 // Given the @class_name name, it creates a fully qualified name
6103 // based on the containing declaration space
6106 MakeName (MemberName class_name)
6108 Namespace ns = current_namespace.NS;
6110 if (current_container == RootContext.ToplevelTypes) {
6111 if (ns.Name.Length != 0)
6112 return new MemberName (ns.MemberName, class_name);
6116 return new MemberName (current_container.MemberName, class_name);
6120 [System.Diagnostics.Conditional ("FULL_AST")]
6121 void StoreModifierLocation (object token, Location loc)
6126 if (mod_locations == null)
6127 mod_locations = new List<Tuple<Modifiers, Location>> ();
6129 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6132 string CheckAttributeTarget (string a, Location l)
6135 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6139 Report.Warning (658, 1, l,
6140 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6141 return string.Empty;
6144 static bool IsUnaryOperator (Operator.OpType op)
6148 case Operator.OpType.LogicalNot:
6149 case Operator.OpType.OnesComplement:
6150 case Operator.OpType.Increment:
6151 case Operator.OpType.Decrement:
6152 case Operator.OpType.True:
6153 case Operator.OpType.False:
6154 case Operator.OpType.UnaryPlus:
6155 case Operator.OpType.UnaryNegation:
6161 void syntax_error (Location l, string msg)
6163 Report.Error (1003, l, "Syntax error, " + msg);
6168 public Tokenizer Lexer {
6174 static CSharpParser ()
6176 oob_stack = new Stack<object> ();
6179 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
6180 : this (reader, file, module, new NamespaceEntry (module, null, file, null))
6184 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module, NamespaceEntry ns)
6187 this.module = module;
6188 this.compiler = module.Compiler;
6189 this.settings = compiler.Settings;
6190 lang_version = settings.Version;
6191 doc_support = settings.Documentation != null;
6192 current_namespace = ns;
6193 current_class = current_namespace.SlaveDeclSpace;
6194 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6196 lexer = new Tokenizer (reader, file, compiler);
6198 use_global_stacks = true;
6201 public void parse ()
6203 eof_token = Token.EOF;
6204 Tokenizer.LocatedToken.Initialize ();
6207 if (yacc_verbose_flag > 1)
6208 yyparse (lexer, new yydebug.yyDebugSimple ());
6212 Tokenizer tokenizer = lexer as Tokenizer;
6213 tokenizer.cleanup ();
6214 } catch (Exception e){
6215 if (e is yyParser.yyUnexpectedEof) {
6216 Error_SyntaxError (yyToken);
6217 UnexpectedEOF = true;
6221 if (e is yyParser.yyException) {
6222 Report.Error (-25, lexer.Location, "Parsing error");
6224 // Used by compiler-tester to test internal errors
6225 if (yacc_verbose_flag > 0)
6228 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6232 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6233 throw new InternalErrorException ("who set it?");
6236 void CheckToken (int error, int yyToken, string msg, Location loc)
6238 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6239 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6241 Report.Error (error, loc, msg);
6244 string ConsumeStoredComment ()
6246 string s = tmpComment;
6248 Lexer.doc_state = XmlCommentState.Allowed;
6252 void FeatureIsNotAvailable (Location loc, string feature)
6254 compiler.Report.FeatureIsNotAvailable (compiler, loc, feature);
6257 Location GetLocation (object obj)
6259 var lt = obj as Tokenizer.LocatedToken;
6263 var mn = obj as MemberName;
6267 var expr = obj as Expression;
6269 return expr.Location;
6271 return lexer.Location;
6275 get { return compiler.Report; }
6278 public LocationsBag LocationsBag {
6287 void start_block (Location loc)
6289 if (current_block == null) {
6290 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6291 parsing_anonymous_method = false;
6292 } else if (parsing_anonymous_method) {
6293 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6294 parsing_anonymous_method = false;
6296 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6301 end_block (Location loc)
6303 Block retval = current_block.Explicit;
6304 retval.SetEndLocation (loc);
6305 current_block = retval.Parent;
6309 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6311 if (lang_version == LanguageVersion.ISO_1){
6312 FeatureIsNotAvailable (loc, "anonymous methods");
6315 oob_stack.Push (current_anonymous_method);
6316 oob_stack.Push (current_local_parameters);
6317 oob_stack.Push (current_variable);
6319 current_local_parameters = parameters;
6321 current_anonymous_method = lambda
6322 ? new LambdaExpression (loc)
6323 : new AnonymousMethodExpression (loc);
6325 // Force the next block to be created as a ToplevelBlock
6326 parsing_anonymous_method = true;
6330 * Completes the anonymous method processing, if lambda_expr is null, this
6331 * means that we have a Statement instead of an Expression embedded
6333 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6335 AnonymousMethodExpression retval;
6337 current_anonymous_method.Block = anon_block;
6338 retval = current_anonymous_method;
6340 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6341 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6342 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6347 public NamespaceEntry CurrentNamespace {
6349 return current_namespace;
6353 void Error_SyntaxError (int token)
6355 Error_SyntaxError (0, token, "Unexpected symbol");
6358 void Error_SyntaxError (int error_code, int token, string msg)
6360 // An error message has been reported by tokenizer
6361 if (token == Token.ERROR)
6364 string symbol = GetSymbolName (token);
6365 string expecting = GetExpecting ();
6366 var loc = lexer.Location - symbol.Length;
6368 if (error_code == 0) {
6369 if (expecting == "`identifier'") {
6370 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6371 Report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6376 expecting = "identifier";
6377 } else if (expecting == "`)'") {
6384 if (string.IsNullOrEmpty (expecting))
6385 Report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6387 Report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6390 string GetExpecting ()
6392 int [] tokens = yyExpectingTokens (yyExpectingState);
6393 var names = new List<string> (tokens.Length);
6394 bool has_type = false;
6395 bool has_identifier = false;
6396 for (int i = 0; i < tokens.Length; i++){
6397 int token = tokens [i];
6398 has_identifier |= token == Token.IDENTIFIER;
6400 string name = GetTokenName (token);
6401 if (name == "<internal>")
6404 has_type |= name == "type";
6405 if (names.Contains (name))
6412 // Too many tokens to enumerate
6414 if (names.Count > 8)
6417 if (has_type && has_identifier)
6418 names.Remove ("identifier");
6420 if (names.Count == 1)
6421 return "`" + GetTokenName (tokens [0]) + "'";
6423 StringBuilder sb = new StringBuilder ();
6425 int count = names.Count;
6426 for (int i = 0; i < count; i++){
6427 bool last = i + 1 == count;
6431 sb.Append (names [i]);
6432 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6434 return sb.ToString ();
6438 string GetSymbolName (int token)
6442 return ((Constant)lexer.Value).GetValue ().ToString ();
6443 case Token.IDENTIFIER:
6444 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6486 case Token.BITWISE_AND:
6488 case Token.BITWISE_OR:
6502 case Token.OP_SHIFT_LEFT:
6504 case Token.OP_SHIFT_RIGHT:
6524 case Token.OP_COALESCING:
6526 case Token.OP_MULT_ASSIGN:
6528 case Token.OP_DIV_ASSIGN:
6530 case Token.OP_MOD_ASSIGN:
6532 case Token.OP_ADD_ASSIGN:
6534 case Token.OP_SUB_ASSIGN:
6536 case Token.OP_SHIFT_LEFT_ASSIGN:
6538 case Token.OP_SHIFT_RIGHT_ASSIGN:
6540 case Token.OP_AND_ASSIGN:
6542 case Token.OP_XOR_ASSIGN:
6544 case Token.OP_OR_ASSIGN:
6548 return GetTokenName (token);
6551 static string GetTokenName (int token)
6554 case Token.ABSTRACT:
6576 case Token.CONTINUE:
6580 case Token.DELEGATE:
6590 case Token.EXPLICIT:
6608 case Token.IMPLICIT:
6612 case Token.INTERFACE:
6614 case Token.INTERNAL:
6620 case Token.NAMESPACE:
6626 case Token.OPERATOR:
6630 case Token.OVERRIDE:
6636 case Token.PROTECTED:
6640 case Token.READONLY:
6652 case Token.STACKALLOC:
6653 return "stackalloc";
6670 case Token.UNCHECKED:
6678 case Token.VOLATILE:
6691 case Token.FROM_FIRST:
6709 case Token.ASCENDING:
6711 case Token.DESCENDING:
6712 return "descending";
6719 case Token.OPEN_BRACE:
6721 case Token.CLOSE_BRACE:
6723 case Token.OPEN_BRACKET:
6724 case Token.OPEN_BRACKET_EXPR:
6726 case Token.CLOSE_BRACKET:
6728 case Token.OPEN_PARENS_CAST:
6729 case Token.OPEN_PARENS_LAMBDA:
6730 case Token.OPEN_PARENS:
6732 case Token.CLOSE_PARENS:
6738 case Token.DEFAULT_COLON:
6742 case Token.SEMICOLON:
6753 case Token.BITWISE_AND:
6754 case Token.BITWISE_OR:
6761 case Token.OP_SHIFT_LEFT:
6762 case Token.OP_SHIFT_RIGHT:
6770 case Token.OP_COALESCING:
6771 case Token.OP_MULT_ASSIGN:
6772 case Token.OP_DIV_ASSIGN:
6773 case Token.OP_MOD_ASSIGN:
6774 case Token.OP_ADD_ASSIGN:
6775 case Token.OP_SUB_ASSIGN:
6776 case Token.OP_SHIFT_LEFT_ASSIGN:
6777 case Token.OP_SHIFT_RIGHT_ASSIGN:
6778 case Token.OP_AND_ASSIGN:
6779 case Token.OP_XOR_ASSIGN:
6780 case Token.OP_OR_ASSIGN:
6781 return "<operator>";
6803 case Token.OP_GENERICS_LT:
6804 case Token.GENERIC_DIMENSION:
6806 case Token.OP_GENERICS_GT:
6809 case Token.INTERR_NULLABLE:
6811 case Token.DOUBLE_COLON:
6815 case Token.IDENTIFIER:
6816 return "identifier";
6819 return "end-of-file";
6821 // All of these are internal.
6824 case Token.FIRST_KEYWORD:
6825 case Token.EVAL_COMPILATION_UNIT_PARSER:
6826 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6827 case Token.EVAL_STATEMENT_PARSER:
6828 case Token.LAST_KEYWORD:
6829 case Token.GENERATE_COMPLETION:
6830 case Token.COMPLETE_COMPLETION:
6831 return "<internal>";
6833 // A bit more robust.
6835 return yyNames [token];