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 object InteractiveResult;
121 // Keeps track of global data changes to undo on parser error
125 Stack<Linq.QueryBlock> linq_clause_blocks;
127 // A counter to create new class names in interactive mode
128 static int class_count;
130 ModuleContainer module;
132 CompilerContext compiler;
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 (RootContext.Version == LanguageVersion.ISO_1) {
413 Report.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
433 if (RootContext.Documentation != null)
434 Lexer.doc_state = XmlCommentState.Allowed;
436 | using_namespace_directive
438 if (RootContext.Documentation != null)
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 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
451 Error_SyntaxError (yyToken);
456 using_namespace_directive
457 : USING namespace_name SEMICOLON
459 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
464 // Strictly speaking, namespaces don't have attributes but
465 // we parse global attributes along with namespace declarations and then
468 namespace_declaration
469 : opt_attributes NAMESPACE qualified_identifier
471 MemberName name = (MemberName) $3;
474 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
477 current_namespace = new NamespaceEntry (module,
478 current_namespace, file, name.GetName ());
479 current_class = current_namespace.SlaveDeclSpace;
480 current_container = current_class.PartialContainer;
482 namespace_body opt_semicolon
484 current_namespace = current_namespace.Parent;
485 current_class = current_namespace.SlaveDeclSpace;
486 current_container = current_class.PartialContainer;
493 var lt = (Tokenizer.LocatedToken) $1;
494 $$ = new MemberName (lt.Value, lt.Location);
496 | qualified_identifier DOT IDENTIFIER
498 var lt = (Tokenizer.LocatedToken) $3;
499 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
503 Error_SyntaxError (yyToken);
504 $$ = new MemberName ("<invalid>", lexer.Location);
519 : namespace_or_type_name
521 MemberName name = (MemberName) $1;
523 if (name.TypeArguments != null)
524 syntax_error (lexer.Location, "namespace name expected");
533 if (RootContext.Documentation != null)
534 Lexer.doc_state = XmlCommentState.Allowed;
536 opt_extern_alias_directives
538 opt_namespace_member_declarations
547 opt_extern_alias_directives
549 | extern_alias_directives
552 opt_namespace_member_declarations
554 | namespace_member_declarations
557 namespace_member_declarations
558 : namespace_member_declaration
559 | namespace_member_declarations namespace_member_declaration
562 namespace_member_declaration
566 DeclSpace ds = (DeclSpace)$1;
568 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
569 Report.Error (1527, ds.Location,
570 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
573 current_namespace.DeclarationFound = true;
575 | namespace_declaration
577 current_namespace.DeclarationFound = true;
581 Error_SyntaxError (yyToken);
588 | interface_declaration
590 | delegate_declaration
592 // Enable this when we have handled all errors, because this acts as a generic fallback
595 // Console.WriteLine ("Token=" + yyToken);
596 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
608 Attributes attrs = (Attributes)$1;
609 if (global_attrs_enabled) {
610 module.AddAttributes (attrs.Attrs, current_namespace);
612 foreach (Attribute a in attrs.Attrs) {
613 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
624 global_attrs_enabled = false;
629 global_attrs_enabled = false;
638 if (current_attr_target != String.Empty) {
639 var sect = (List<Attribute>) $1;
641 if (global_attrs_enabled) {
642 if (!string.IsNullOrEmpty (current_attr_target)) {
643 module.AddAttributes (sect, current_namespace);
646 $$ = new Attributes (sect);
649 if (RootContext.Documentation != null) {
650 Lexer.check_incorrect_doc_comment ();
652 XmlCommentState.Allowed;
656 $$ = new Attributes (sect);
661 current_attr_target = null;
663 | attribute_sections attribute_section
665 if (current_attr_target != String.Empty) {
666 Attributes attrs = $1 as Attributes;
667 var sect = (List<Attribute>) $2;
669 if (global_attrs_enabled) {
670 if (!string.IsNullOrEmpty (current_attr_target)) {
671 module.AddAttributes (sect);
675 attrs = new Attributes (sect);
677 attrs.AddAttributes (sect);
681 attrs = new Attributes (sect);
683 attrs.AddAttributes (sect);
689 current_attr_target = null;
694 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
698 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
704 attribute_target_specifier
705 : attribute_target COLON
707 current_attr_target = (string)$1;
715 var lt = (Tokenizer.LocatedToken) $1;
716 $$ = CheckAttributeTarget (lt.Value, lt.Location);
718 | EVENT { $$ = "event"; }
719 | RETURN { $$ = "return"; }
722 string name = GetTokenName (yyToken);
723 $$ = CheckAttributeTarget (name, GetLocation ($1));
730 $$ = new List<Attribute> (4) { (Attribute) $1 };
732 | attribute_list COMMA attribute
734 var attrs = (List<Attribute>) $1;
735 attrs.Add ((Attribute) $3);
744 ++lexer.parsing_block;
746 opt_attribute_arguments
748 --lexer.parsing_block;
749 MemberName mname = (MemberName) $1;
750 if (mname.IsGeneric) {
751 Report.Error (404, lexer.Location,
752 "'<' unexpected: attributes cannot be generic");
755 Arguments [] arguments = (Arguments []) $3;
756 ATypeNameExpression expr = mname.GetTypeExpression ();
758 if (current_attr_target == String.Empty)
760 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
761 // FIXME: supply "nameEscaped" parameter here.
762 $$ = new GlobalAttribute (current_namespace, current_attr_target,
763 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
765 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname));
770 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
773 opt_attribute_arguments
774 : /* empty */ { $$ = null; }
775 | OPEN_PARENS attribute_arguments CLOSE_PARENS
783 : /* empty */ { $$ = null; }
784 | positional_or_named_argument
786 Arguments a = new Arguments (4);
787 a.Add ((Argument) $1);
788 $$ = new Arguments [] { a, null };
790 | named_attribute_argument
792 Arguments a = new Arguments (4);
793 a.Add ((Argument) $1);
794 $$ = new Arguments [] { null, a };
796 | attribute_arguments COMMA positional_or_named_argument
798 Arguments[] o = (Arguments[]) $1;
800 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
801 o [0] = new Arguments (4);
804 Arguments args = ((Arguments) o [0]);
805 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
806 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
808 args.Add ((Argument) $3);
810 | attribute_arguments COMMA named_attribute_argument
812 Arguments[] o = (Arguments[]) $1;
814 o [1] = new Arguments (4);
817 ((Arguments) o [1]).Add ((Argument) $3);
821 positional_or_named_argument
824 $$ = new Argument ((Expression) $1);
829 named_attribute_argument
832 ++lexer.parsing_block;
836 --lexer.parsing_block;
837 var lt = (Tokenizer.LocatedToken) $1;
838 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
843 : IDENTIFIER COLON opt_named_modifier expression
845 if (RootContext.Version <= LanguageVersion.V_3)
846 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
848 // Avoid boxing in common case (no modifier)
849 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
851 var lt = (Tokenizer.LocatedToken) $1;
852 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
857 : /* empty */ { $$ = null; }
860 $$ = Argument.AType.Ref;
864 $$ = Argument.AType.Out;
868 opt_class_member_declarations
870 | class_member_declarations
873 class_member_declarations
874 : class_member_declaration
875 | class_member_declarations
876 class_member_declaration
879 class_member_declaration
880 : constant_declaration // done
881 | field_declaration // done
882 | method_declaration // done
883 | property_declaration // done
884 | event_declaration // done
885 | indexer_declaration // done
886 | operator_declaration // done
887 | constructor_declaration // done
888 | destructor_declaration // done
892 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
893 GetSymbolName (yyToken));
895 lexer.parsing_generic_declaration = false;
905 lexer.ConstraintsParsing = true;
907 type_declaration_name
909 MemberName name = MakeName ((MemberName) $6);
910 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
913 opt_type_parameter_constraints_clauses
915 lexer.ConstraintsParsing = false;
917 current_class.SetParameterInfo ((List<Constraints>) $9);
919 if (RootContext.Documentation != null)
920 current_container.DocComment = Lexer.consume_doc_comment ();
922 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
926 --lexer.parsing_declaration;
927 if (RootContext.Documentation != null)
928 Lexer.doc_state = XmlCommentState.Allowed;
932 lbag.AppendToMember (current_class, GetLocation ($13));
933 $$ = pop_current_class ();
935 | opt_attributes opt_modifiers opt_partial STRUCT error
937 Error_SyntaxError (yyToken);
944 if (RootContext.Documentation != null)
945 Lexer.doc_state = XmlCommentState.Allowed;
947 opt_struct_member_declarations CLOSE_BRACE
949 lbag.AppendToMember (current_class, GetLocation ($1), GetLocation ($4));
953 opt_struct_member_declarations
955 | struct_member_declarations
958 struct_member_declarations
959 : struct_member_declaration
960 | struct_member_declarations struct_member_declaration
963 struct_member_declaration
964 : constant_declaration
967 | property_declaration
969 | indexer_declaration
970 | operator_declaration
971 | constructor_declaration
975 * This is only included so we can flag error 575:
976 * destructors only allowed on class types
978 | destructor_declaration
984 CONST type IDENTIFIER
986 var lt = (Tokenizer.LocatedToken) $5;
987 var mod = (Modifiers) $2;
988 current_field = new Const (current_class, (FullNamedExpression) $4, mod, new MemberName (lt.Value, lt.Location), (Attributes) $1);
989 current_container.AddConstant ((Const) current_field);
991 if ((mod & Modifiers.STATIC) != 0) {
992 Report.Error (504, current_field.Location, "The constant `{0}' cannot be marked static", current_field.GetSignatureForError ());
997 constant_initializer opt_constant_declarators SEMICOLON
999 if (RootContext.Documentation != null) {
1000 current_field.DocComment = Lexer.consume_doc_comment ();
1001 Lexer.doc_state = XmlCommentState.Allowed;
1004 current_field.Initializer = (ConstInitializer) $7;
1005 lbag.AddMember (current_field, mod_locations, GetLocation ($3), GetLocation ($9));
1006 current_field = null;
1010 opt_constant_declarators
1012 | constant_declarators
1015 constant_declarators
1016 : constant_declarator
1018 current_field.AddDeclarator ((FieldDeclarator) $1);
1020 | constant_declarators constant_declarator
1022 current_field.AddDeclarator ((FieldDeclarator) $2);
1027 : COMMA IDENTIFIER constant_initializer
1029 var lt = (Tokenizer.LocatedToken) $2;
1030 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1031 lbag.AddLocation ($$, GetLocation ($1));
1035 constant_initializer
1038 ++lexer.parsing_block;
1040 constant_initializer_expr
1042 --lexer.parsing_block;
1043 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1047 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
1052 constant_initializer_expr
1053 : constant_expression
1060 member_type IDENTIFIER
1062 lexer.parsing_generic_declaration = false;
1064 FullNamedExpression type = (FullNamedExpression) $3;
1065 if (type.Type == TypeManager.void_type)
1066 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1068 var lt = (Tokenizer.LocatedToken) $4;
1069 current_field = new Field (current_class, type, (Modifiers) $2, new MemberName (lt.Value, lt.Location), (Attributes) $1);
1070 current_container.AddField (current_field);
1073 opt_field_initializer
1074 opt_field_declarators
1077 if (RootContext.Documentation != null) {
1078 current_field.DocComment = Lexer.consume_doc_comment ();
1079 Lexer.doc_state = XmlCommentState.Allowed;
1082 lbag.AddMember (current_field, mod_locations, GetLocation ($8));
1084 current_field = null;
1088 FIXED simple_type IDENTIFIER
1090 if (RootContext.Version < LanguageVersion.ISO_2)
1091 Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1093 var lt = (Tokenizer.LocatedToken) $5;
1094 current_field = new FixedField (current_class, (FullNamedExpression) $4, (Modifiers) $2,
1095 new MemberName (lt.Value, lt.Location), (Attributes) $1);
1097 current_container.AddField (current_field);
1099 fixed_field_size opt_fixed_field_declarators SEMICOLON
1101 if (RootContext.Documentation != null) {
1102 current_field.DocComment = Lexer.consume_doc_comment ();
1103 Lexer.doc_state = XmlCommentState.Allowed;
1106 current_field.Initializer = (ConstInitializer) $7;
1107 lbag.AddMember (current_field, mod_locations, GetLocation ($9));
1109 current_field = null;
1113 FIXED simple_type error
1116 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1120 opt_field_initializer
1124 ++lexer.parsing_block;
1125 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
1126 start_block (GetLocation ($1));
1128 variable_initializer
1130 --lexer.parsing_block;
1131 current_field.Initializer = (Expression) $3;
1132 end_block (lexer.Location);
1133 current_local_parameters = null;
1137 opt_field_declarators
1145 current_field.AddDeclarator ((FieldDeclarator) $1);
1147 | field_declarators field_declarator
1149 current_field.AddDeclarator ((FieldDeclarator) $2);
1156 var lt = (Tokenizer.LocatedToken) $2;
1157 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
1158 lbag.AddLocation ($$, GetLocation ($1));
1160 | COMMA IDENTIFIER ASSIGN
1162 ++lexer.parsing_block;
1164 variable_initializer
1166 --lexer.parsing_block;
1167 var lt = (Tokenizer.LocatedToken) $2;
1168 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
1169 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
1173 opt_fixed_field_declarators
1175 | fixed_field_declarators
1178 fixed_field_declarators
1179 : fixed_field_declarator
1181 current_field.AddDeclarator ((FieldDeclarator) $1);
1183 | fixed_field_declarators fixed_field_declarator
1185 current_field.AddDeclarator ((FieldDeclarator) $2);
1189 fixed_field_declarator
1190 : COMMA IDENTIFIER fixed_field_size
1192 var lt = (Tokenizer.LocatedToken) $2;
1193 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (ConstInitializer) $3);
1194 lbag.AddLocation ($$, GetLocation ($1));
1201 ++lexer.parsing_block;
1203 expression CLOSE_BRACKET
1205 --lexer.parsing_block;
1206 $$ = new ConstInitializer (current_field, (Expression) $3, GetLocation ($1));
1207 lbag.AddLocation ($$, GetLocation ($4));
1209 | OPEN_BRACKET error
1211 Report.Error (443, lexer.Location, "Value or constant expected");
1216 variable_initializer
1221 // It has to be here for the parent to safely restore artificial block
1222 Error_SyntaxError (yyToken);
1230 if (RootContext.Documentation != null)
1231 Lexer.doc_state = XmlCommentState.NotAllowed;
1233 // Add it early in the case of body being eof for full aot
1234 current_container.AddMethod ((Method) $1);
1238 Method method = (Method) $1;
1239 method.Block = (ToplevelBlock) $3;
1241 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1242 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1245 current_local_parameters = null;
1247 if (RootContext.Documentation != null)
1248 Lexer.doc_state = XmlCommentState.Allowed;
1256 method_declaration_name OPEN_PARENS
1258 valid_param_mod = ParameterModifierType.All;
1260 opt_formal_parameter_list CLOSE_PARENS
1262 lexer.ConstraintsParsing = true;
1264 opt_type_parameter_constraints_clauses
1266 lexer.ConstraintsParsing = false;
1267 valid_param_mod = 0;
1268 MemberName name = (MemberName) $4;
1269 current_local_parameters = (ParametersCompiled) $7;
1271 GenericMethod generic = null;
1272 if (name.TypeArguments != null) {
1273 generic = new GenericMethod (current_namespace, current_class, name,
1274 (FullNamedExpression) $3, current_local_parameters);
1276 generic.SetParameterInfo ((List<Constraints>) $10);
1277 } else if ($10 != null) {
1278 Report.Error (80, GetLocation ($10),
1279 "Constraints are not allowed on non-generic declarations");
1282 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1283 name, current_local_parameters, (Attributes) $1);
1285 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1286 Report.Error (460, method.Location,
1287 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1288 method.GetSignatureForError ());
1291 if (RootContext.Documentation != null)
1292 method.DocComment = Lexer.consume_doc_comment ();
1294 lbag.AddMember (method, mod_locations, GetLocation ($5), GetLocation ($8));
1300 VOID method_declaration_name
1303 valid_param_mod = ParameterModifierType.All;
1305 opt_formal_parameter_list CLOSE_PARENS
1307 lexer.ConstraintsParsing = true;
1309 opt_type_parameter_constraints_clauses
1311 lexer.ConstraintsParsing = false;
1312 valid_param_mod = 0;
1314 MemberName name = (MemberName) $5;
1315 current_local_parameters = (ParametersCompiled) $8;
1317 if ($10 != null && name.TypeArguments == null)
1318 Report.Error (80, lexer.Location,
1319 "Constraints are not allowed on non-generic declarations");
1322 GenericMethod generic = null;
1323 if (name.TypeArguments != null) {
1324 generic = new GenericMethod (current_namespace, current_class, name,
1325 new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1326 current_local_parameters);
1328 generic.SetParameterInfo ((List<Constraints>) $11);
1331 var modifiers = (Modifiers) $2;
1334 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1335 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1337 if ((modifiers & invalid_partial_mod) != 0) {
1338 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1339 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1340 modifiers &= ~invalid_partial_mod;
1343 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1344 Report.Error (751, name.Location, "A partial method must be declared within a " +
1345 "partial class or partial struct");
1348 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1350 method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1351 modifiers, name, current_local_parameters, (Attributes) $1);
1353 if (RootContext.Documentation != null)
1354 method.DocComment = Lexer.consume_doc_comment ();
1356 // TODO: lbag, push void
1357 StoreModifierLocation (Modifiers.PARTIAL, GetLocation ($3));
1358 lbag.AddMember (method, mod_locations, GetLocation ($6), GetLocation ($9));
1364 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1366 MemberName name = (MemberName) $5;
1367 Report.Error (1585, name.Location,
1368 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1370 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1371 0, name, (ParametersCompiled) $7, (Attributes) $1);
1373 current_local_parameters = (ParametersCompiled) $7;
1375 if (RootContext.Documentation != null)
1376 method.DocComment = Lexer.consume_doc_comment ();
1384 | SEMICOLON { $$ = null; }
1387 opt_formal_parameter_list
1388 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1389 | formal_parameter_list
1392 formal_parameter_list
1395 var pars_list = (List<Parameter>) $1;
1396 $$ = new ParametersCompiled (pars_list.ToArray ());
1398 | fixed_parameters COMMA parameter_array
1400 var pars_list = (List<Parameter>) $1;
1401 pars_list.Add ((Parameter) $3);
1403 $$ = new ParametersCompiled (pars_list.ToArray ());
1405 | fixed_parameters COMMA arglist_modifier
1407 var pars_list = (List<Parameter>) $1;
1408 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1409 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1411 | parameter_array COMMA error
1414 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1416 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1418 | fixed_parameters COMMA parameter_array COMMA error
1421 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1423 var pars_list = (List<Parameter>) $1;
1424 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1426 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1428 | arglist_modifier COMMA error
1430 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1432 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1434 | fixed_parameters COMMA ARGLIST COMMA error
1436 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1438 var pars_list = (List<Parameter>) $1;
1439 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1441 $$ = new ParametersCompiled (pars_list.ToArray (), true);
1445 $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } );
1449 $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1453 Error_SyntaxError (yyToken);
1454 $$ = ParametersCompiled.EmptyReadOnlyParameters;
1461 parameters_bucket.Clear ();
1462 Parameter p = (Parameter) $1;
1463 parameters_bucket.Add (p);
1465 default_parameter_used = p.HasDefaultValue;
1466 $$ = parameters_bucket;
1468 | fixed_parameters COMMA fixed_parameter
1470 var pars = (List<Parameter>) $1;
1471 Parameter p = (Parameter) $3;
1473 if (p.HasExtensionMethodModifier)
1474 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1475 else if (!p.HasDefaultValue && default_parameter_used)
1476 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1478 default_parameter_used |= p.HasDefaultValue;
1481 lbag.AddLocation (p, GetLocation ($2));
1490 opt_parameter_modifier
1494 var lt = (Tokenizer.LocatedToken) $4;
1495 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1498 opt_parameter_modifier
1500 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1502 var lt = (Tokenizer.LocatedToken) $4;
1503 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1504 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1507 opt_parameter_modifier
1511 Error_SyntaxError (yyToken);
1512 Location l = GetLocation ($4);
1513 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1516 opt_parameter_modifier
1521 ++lexer.parsing_block;
1525 --lexer.parsing_block;
1526 if (RootContext.Version <= LanguageVersion.V_3) {
1527 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1530 Parameter.Modifier mod = (Parameter.Modifier) $2;
1531 if (mod != Parameter.Modifier.NONE) {
1533 case Parameter.Modifier.REF:
1534 case Parameter.Modifier.OUT:
1535 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1536 Parameter.GetModifierSignature (mod));
1539 case Parameter.Modifier.This:
1540 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1541 Parameter.GetModifierSignature (mod));
1544 throw new NotImplementedException (mod.ToString ());
1547 mod = Parameter.Modifier.NONE;
1550 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1551 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1553 var lt = (Tokenizer.LocatedToken) $4;
1554 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1555 lbag.AddLocation ($$, GetLocation ($5));
1558 ((Parameter) $$).DefaultValue = new DefaultParameterValueExpression ((Expression) $7);
1562 opt_parameter_modifier
1563 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1564 | parameter_modifiers
1568 : parameter_modifier
1572 | parameter_modifiers parameter_modifier
1574 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1575 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1576 if (((Parameter.Modifier)$1 & p2) == p2) {
1577 Error_DuplicateParameterModifier (lexer.Location, p2);
1579 switch (mod & ~Parameter.Modifier.This) {
1580 case Parameter.Modifier.REF:
1581 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1583 case Parameter.Modifier.OUT:
1584 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1587 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1598 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1599 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1601 $$ = Parameter.Modifier.REF;
1605 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1606 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1608 $$ = Parameter.Modifier.OUT;
1612 if ((valid_param_mod & ParameterModifierType.This) == 0)
1613 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1615 if (RootContext.Version <= LanguageVersion.ISO_2)
1616 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1618 $$ = Parameter.Modifier.This;
1623 : opt_attributes params_modifier type IDENTIFIER
1625 var lt = (Tokenizer.LocatedToken) $4;
1626 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1628 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1630 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1632 var lt = (Tokenizer.LocatedToken) $4;
1633 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1635 | opt_attributes params_modifier type error
1637 Error_SyntaxError (yyToken);
1645 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1646 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1648 | PARAMS parameter_modifier
1650 Parameter.Modifier mod = (Parameter.Modifier)$2;
1651 if ((mod & Parameter.Modifier.This) != 0) {
1652 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1654 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1657 | PARAMS params_modifier
1659 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1666 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1667 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1671 property_declaration
1675 member_declaration_name
1677 if (RootContext.Documentation != null)
1678 tmpComment = Lexer.consume_doc_comment ();
1682 current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
1683 (MemberName) $4, (Attributes) $1);
1685 if (current_property.TypeExpression.Type == TypeManager.void_type)
1686 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1688 current_container.AddProperty ((Property)current_property);
1689 lbag.AddMember (current_property, mod_locations, GetLocation ($6));
1691 lexer.PropertyParsing = true;
1693 accessor_declarations
1695 lexer.PropertyParsing = false;
1697 if (RootContext.Documentation != null)
1698 current_property.DocComment = ConsumeStoredComment ();
1702 lbag.AppendToMember (current_property, GetLocation ($10));
1703 current_property = null;
1709 : opt_attributes opt_modifiers
1710 member_type indexer_declaration_name OPEN_BRACKET
1712 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1714 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1716 valid_param_mod = 0;
1718 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
1719 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1721 current_property = indexer;
1723 current_container.AddIndexer (indexer);
1724 lbag.AddMember (current_property, mod_locations, GetLocation ($5), GetLocation ($8), GetLocation ($9));
1726 if (indexer.TypeExpression.Type == TypeManager.void_type)
1727 Report.Error (620, GetLocation ($3), "`{0}': indexer return type cannot be `void'", indexer.GetSignatureForError ());
1729 if (indexer.Parameters.IsEmpty) {
1730 Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter");
1733 if (RootContext.Documentation != null) {
1734 tmpComment = Lexer.consume_doc_comment ();
1735 Lexer.doc_state = XmlCommentState.Allowed;
1738 lexer.PropertyParsing = true;
1740 accessor_declarations
1742 lexer.PropertyParsing = false;
1746 if (RootContext.Documentation != null)
1747 current_property.DocComment = ConsumeStoredComment ();
1749 lbag.AppendToMember (current_property, GetLocation ($12));
1750 current_property = null;
1755 accessor_declarations
1756 : get_accessor_declaration
1757 | get_accessor_declaration accessor_declarations
1758 | set_accessor_declaration
1759 | set_accessor_declaration accessor_declarations
1762 if (yyToken == Token.CLOSE_BRACE) {
1763 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1765 if (yyToken == Token.SEMICOLON)
1766 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1768 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1773 get_accessor_declaration
1774 : opt_attributes opt_modifiers GET
1776 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1777 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1780 if (current_property.Get != null) {
1781 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1784 if (current_property is Indexer) {
1785 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1786 (Attributes) $1, GetLocation ($3));
1788 current_property.Get = new Property.GetMethod (current_property,
1789 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1792 current_local_parameters = current_property.Get.ParameterInfo;
1793 lbag.AddMember (current_property.Get, mod_locations);
1794 lexer.PropertyParsing = false;
1799 current_property.Get.Block = (ToplevelBlock) $5;
1801 if (current_container.Kind == MemberKind.Interface) {
1802 Report.Error (531, current_property.Get.Block.StartLocation,
1803 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1807 current_local_parameters = null;
1808 lexer.PropertyParsing = true;
1810 if (RootContext.Documentation != null)
1811 if (Lexer.doc_state == XmlCommentState.Error)
1812 Lexer.doc_state = XmlCommentState.NotAllowed;
1816 set_accessor_declaration
1817 : opt_attributes opt_modifiers SET
1819 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1820 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1823 if (current_property.Set != null) {
1824 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1827 if (current_property is Indexer) {
1828 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1829 ParametersCompiled.MergeGenerated (compiler,
1830 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1831 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1833 (Attributes) $1, GetLocation ($3));
1835 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1836 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1837 (Attributes) $1, GetLocation ($3));
1840 current_local_parameters = current_property.Set.ParameterInfo;
1841 lbag.AddMember (current_property.Set, mod_locations);
1842 lexer.PropertyParsing = false;
1847 current_property.Set.Block = (ToplevelBlock) $5;
1849 if (current_container.Kind == MemberKind.Interface) {
1850 Report.Error (531, current_property.Set.Block.StartLocation,
1851 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1855 current_local_parameters = null;
1856 lexer.PropertyParsing = true;
1858 if (RootContext.Documentation != null
1859 && Lexer.doc_state == XmlCommentState.Error)
1860 Lexer.doc_state = XmlCommentState.NotAllowed;
1873 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1878 interface_declaration
1884 lexer.ConstraintsParsing = true;
1886 type_declaration_name
1888 MemberName name = MakeName ((MemberName) $6);
1889 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1890 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
1893 opt_type_parameter_constraints_clauses
1895 lexer.ConstraintsParsing = false;
1897 current_class.SetParameterInfo ((List<Constraints>) $9);
1899 if (RootContext.Documentation != null) {
1900 current_container.DocComment = Lexer.consume_doc_comment ();
1901 Lexer.doc_state = XmlCommentState.Allowed;
1904 OPEN_BRACE opt_interface_member_declarations CLOSE_BRACE
1906 --lexer.parsing_declaration;
1907 if (RootContext.Documentation != null)
1908 Lexer.doc_state = XmlCommentState.Allowed;
1912 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13));
1913 $$ = pop_current_class ();
1915 | opt_attributes opt_modifiers opt_partial INTERFACE error
1917 Error_SyntaxError (yyToken);
1921 opt_interface_member_declarations
1923 | interface_member_declarations
1926 interface_member_declarations
1927 : interface_member_declaration
1928 | interface_member_declarations interface_member_declaration
1931 interface_member_declaration
1932 : constant_declaration
1934 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1938 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1940 | method_declaration
1941 | property_declaration
1943 | indexer_declaration
1944 | operator_declaration
1946 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1948 | constructor_declaration
1950 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1954 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1958 operator_declaration
1959 : opt_attributes opt_modifiers operator_declarator
1964 OperatorDeclaration decl = (OperatorDeclaration) $3;
1966 Operator op = new Operator (
1967 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1968 current_local_parameters,
1969 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1971 if (RootContext.Documentation != null) {
1972 op.DocComment = tmpComment;
1973 Lexer.doc_state = XmlCommentState.Allowed;
1976 // Note again, checking is done in semantic analysis
1977 current_container.AddOperator (op);
1979 lbag.AddMember (op, mod_locations, lbag.GetLocations (decl));
1982 current_local_parameters = null;
1988 | SEMICOLON { $$ = null; }
1992 : type_expression_or_array
1995 Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1996 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2001 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2003 valid_param_mod = ParameterModifierType.DefaultValue;
2005 opt_formal_parameter_list CLOSE_PARENS
2007 valid_param_mod = 0;
2009 Location loc = GetLocation ($2);
2010 Operator.OpType op = (Operator.OpType) $3;
2011 current_local_parameters = (ParametersCompiled)$6;
2013 int p_count = current_local_parameters.Count;
2015 if (op == Operator.OpType.Addition)
2016 op = Operator.OpType.UnaryPlus;
2017 else if (op == Operator.OpType.Subtraction)
2018 op = Operator.OpType.UnaryNegation;
2021 if (IsUnaryOperator (op)) {
2023 Report.Error (1020, loc, "Overloadable binary operator expected");
2024 } else if (p_count != 1) {
2025 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2026 Operator.GetName (op));
2030 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2031 Operator.GetName (op));
2032 } else if (p_count != 2) {
2033 Report.Error (1019, loc, "Overloadable unary operator expected");
2037 if (RootContext.Documentation != null) {
2038 tmpComment = Lexer.consume_doc_comment ();
2039 Lexer.doc_state = XmlCommentState.NotAllowed;
2042 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2043 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3), GetLocation ($4), GetLocation ($7));
2045 | conversion_operator_declarator
2048 overloadable_operator
2050 : BANG { $$ = Operator.OpType.LogicalNot; }
2051 | TILDE { $$ = Operator.OpType.OnesComplement; }
2052 | OP_INC { $$ = Operator.OpType.Increment; }
2053 | OP_DEC { $$ = Operator.OpType.Decrement; }
2054 | TRUE { $$ = Operator.OpType.True; }
2055 | FALSE { $$ = Operator.OpType.False; }
2056 // Unary and binary:
2057 | PLUS { $$ = Operator.OpType.Addition; }
2058 | MINUS { $$ = Operator.OpType.Subtraction; }
2060 | STAR { $$ = Operator.OpType.Multiply; }
2061 | DIV { $$ = Operator.OpType.Division; }
2062 | PERCENT { $$ = Operator.OpType.Modulus; }
2063 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2064 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2065 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2066 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2067 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2068 | OP_EQ { $$ = Operator.OpType.Equality; }
2069 | OP_NE { $$ = Operator.OpType.Inequality; }
2070 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2071 | OP_LT { $$ = Operator.OpType.LessThan; }
2072 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2073 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2076 conversion_operator_declarator
2077 : IMPLICIT OPERATOR type OPEN_PARENS
2079 valid_param_mod = ParameterModifierType.DefaultValue;
2081 opt_formal_parameter_list CLOSE_PARENS
2083 valid_param_mod = 0;
2085 Location loc = GetLocation ($2);
2086 current_local_parameters = (ParametersCompiled)$6;
2088 if (RootContext.Documentation != null) {
2089 tmpComment = Lexer.consume_doc_comment ();
2090 Lexer.doc_state = XmlCommentState.NotAllowed;
2093 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2094 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2096 | EXPLICIT OPERATOR type OPEN_PARENS
2098 valid_param_mod = ParameterModifierType.DefaultValue;
2100 opt_formal_parameter_list CLOSE_PARENS
2102 valid_param_mod = 0;
2104 Location loc = GetLocation ($2);
2105 current_local_parameters = (ParametersCompiled)$6;
2107 if (RootContext.Documentation != null) {
2108 tmpComment = Lexer.consume_doc_comment ();
2109 Lexer.doc_state = XmlCommentState.NotAllowed;
2112 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2113 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($2), GetLocation ($4), GetLocation ($7));
2117 Error_SyntaxError (yyToken);
2118 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2119 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2123 Error_SyntaxError (yyToken);
2124 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2125 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2129 constructor_declaration
2130 : constructor_declarator
2133 Constructor c = (Constructor) $1;
2134 c.Block = (ToplevelBlock) $2;
2136 if (RootContext.Documentation != null)
2137 c.DocComment = ConsumeStoredComment ();
2139 current_container.AddConstructor (c);
2141 current_local_parameters = null;
2142 if (RootContext.Documentation != null)
2143 Lexer.doc_state = XmlCommentState.Allowed;
2147 constructor_declarator
2152 if (RootContext.Documentation != null) {
2153 tmpComment = Lexer.consume_doc_comment ();
2154 Lexer.doc_state = XmlCommentState.Allowed;
2157 valid_param_mod = ParameterModifierType.All;
2159 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2161 valid_param_mod = 0;
2162 current_local_parameters = (ParametersCompiled) $6;
2165 // start block here, so possible anonymous methods inside
2166 // constructor initializer can get correct parent block
2168 start_block (lexer.Location);
2170 opt_constructor_initializer
2172 var lt = (Tokenizer.LocatedToken) $3;
2173 var mods = (Modifiers) $2;
2174 ConstructorInitializer ci = (ConstructorInitializer) $9;
2176 Constructor c = new Constructor (current_class, lt.Value, mods,
2177 (Attributes) $1, current_local_parameters, ci, lt.Location);
2179 if (lt.Value != current_container.MemberName.Name) {
2180 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2181 } else if ((mods & Modifiers.STATIC) != 0) {
2182 if ((mods & Modifiers.AccessibilityMask) != 0){
2183 Report.Error (515, c.Location,
2184 "`{0}': static constructor cannot have an access modifier",
2185 c.GetSignatureForError ());
2188 Report.Error (514, c.Location,
2189 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2190 c.GetSignatureForError ());
2195 lbag.AddMember (c, mod_locations, GetLocation ($5), GetLocation ($7));
2202 | SEMICOLON { current_block = null; $$ = null; }
2205 opt_constructor_initializer
2207 | constructor_initializer
2210 constructor_initializer
2211 : COLON BASE OPEN_PARENS
2213 ++lexer.parsing_block;
2215 opt_argument_list CLOSE_PARENS
2217 --lexer.parsing_block;
2218 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2219 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2221 | COLON THIS OPEN_PARENS
2223 ++lexer.parsing_block;
2225 opt_argument_list CLOSE_PARENS
2227 --lexer.parsing_block;
2228 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2229 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3), GetLocation ($6));
2233 Error_SyntaxError (yyToken);
2238 destructor_declaration
2239 : opt_attributes opt_modifiers TILDE
2241 if (RootContext.Documentation != null) {
2242 tmpComment = Lexer.consume_doc_comment ();
2243 Lexer.doc_state = XmlCommentState.NotAllowed;
2246 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2248 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2250 var lt = (Tokenizer.LocatedToken) $5;
2251 if (lt.Value != current_container.MemberName.Name){
2252 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2253 } else if (current_container.Kind != MemberKind.Class){
2254 Report.Error (575, lt.Location, "Only class types can contain destructor");
2257 Destructor d = new Destructor (current_class, (Modifiers) $2,
2258 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2259 if (RootContext.Documentation != null)
2260 d.DocComment = ConsumeStoredComment ();
2262 d.Block = (ToplevelBlock) $8;
2263 current_container.AddMethod (d);
2264 lbag.AddMember (d, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($7));
2266 current_local_parameters = null;
2273 EVENT type member_declaration_name
2275 current_event_field = new EventField (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2276 current_container.AddEvent (current_event_field);
2278 if (current_event_field.MemberName.Left != null) {
2279 Report.Error (71, current_event_field.Location, "`{0}': An explicit interface implementation of an event must use property syntax",
2280 current_event_field.GetSignatureForError ());
2283 $$ = current_event_field;
2285 opt_event_initializer
2286 opt_event_declarators
2289 if (RootContext.Documentation != null) {
2290 current_event_field.DocComment = Lexer.consume_doc_comment ();
2291 Lexer.doc_state = XmlCommentState.Allowed;
2294 lbag.AddMember (current_event_field, mod_locations, GetLocation ($3), GetLocation ($9));
2295 current_event_field = null;
2299 EVENT type member_declaration_name
2302 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2303 current_container.AddEvent (current_event);
2304 lbag.AddMember (current_event, mod_locations, GetLocation ($3), GetLocation ($6));
2306 lexer.EventParsing = true;
2308 event_accessor_declarations
2310 if (current_container.Kind == MemberKind.Interface)
2311 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2313 lexer.EventParsing = false;
2317 if (RootContext.Documentation != null) {
2318 current_event.DocComment = Lexer.consume_doc_comment ();
2319 Lexer.doc_state = XmlCommentState.Allowed;
2322 lbag.AppendToMember (current_event, GetLocation ($9));
2323 current_event = null;
2324 current_local_parameters = null;
2328 opt_event_initializer
2332 ++lexer.parsing_block;
2334 event_variable_initializer
2336 --lexer.parsing_block;
2337 current_event_field.Initializer = (Expression) $3;
2341 opt_event_declarators
2349 current_event_field.AddDeclarator ((FieldDeclarator) $1);
2351 | event_declarators event_declarator
2353 current_event_field.AddDeclarator ((FieldDeclarator) $2);
2360 var lt = (Tokenizer.LocatedToken) $2;
2361 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), null);
2362 lbag.AddLocation ($$, GetLocation ($1));
2364 | COMMA IDENTIFIER ASSIGN
2366 ++lexer.parsing_block;
2368 event_variable_initializer
2370 --lexer.parsing_block;
2371 var lt = (Tokenizer.LocatedToken) $2;
2372 $$ = new FieldDeclarator (new SimpleMemberName (lt.Value, lt.Location), (Expression) $5);
2373 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2377 event_variable_initializer
2379 if (current_container.Kind == MemberKind.Interface) {
2380 Report.Error (68, lexer.Location, "`{0}': event in interface cannot have an initializer",
2381 current_event_field.GetSignatureForError ());
2384 if ((current_event_field.ModFlags & Modifiers.ABSTRACT) != 0) {
2385 Report.Error (74, lexer.Location, "`{0}': abstract event cannot have an initializer",
2386 current_event_field.GetSignatureForError ());
2389 variable_initializer
2395 event_accessor_declarations
2396 : add_accessor_declaration remove_accessor_declaration
2397 | remove_accessor_declaration add_accessor_declaration
2398 | add_accessor_declaration
2400 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2401 current_event.GetSignatureForError ());
2403 | remove_accessor_declaration
2405 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2406 current_event.GetSignatureForError ());
2410 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2415 add_accessor_declaration
2416 : opt_attributes opt_modifiers ADD
2418 if ($2 != ModifierNone) {
2419 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2422 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2423 current_local_parameters = current_event.Add.ParameterInfo;
2425 lbag.AddMember (current_event.Add, mod_locations);
2426 lexer.EventParsing = false;
2428 event_accessor_block
2430 lexer.EventParsing = true;
2432 current_event.Add.Block = (ToplevelBlock) $5;
2434 if (current_container.Kind == MemberKind.Interface) {
2435 Report.Error (531, current_event.Add.Block.StartLocation,
2436 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2439 current_local_parameters = null;
2443 remove_accessor_declaration
2444 : opt_attributes opt_modifiers REMOVE
2446 if ($2 != ModifierNone) {
2447 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2450 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2451 current_local_parameters = current_event.Remove.ParameterInfo;
2453 lbag.AddMember (current_event.Remove, mod_locations);
2454 lexer.EventParsing = false;
2456 event_accessor_block
2458 lexer.EventParsing = true;
2460 current_event.Remove.Block = (ToplevelBlock) $5;
2462 if (current_container.Kind == MemberKind.Interface) {
2463 Report.Error (531, current_event.Remove.Block.StartLocation,
2464 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2467 current_local_parameters = null;
2471 event_accessor_block
2474 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2483 ENUM type_declaration_name
2486 if (RootContext.Documentation != null)
2487 enumTypeComment = Lexer.consume_doc_comment ();
2491 if (RootContext.Documentation != null)
2492 Lexer.doc_state = XmlCommentState.Allowed;
2494 MemberName name = (MemberName) $4;
2495 if (name.IsGeneric) {
2496 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2499 push_current_class (new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2, MakeName (name), (Attributes) $1), null);
2501 opt_enum_member_declarations
2503 // here will be evaluated after CLOSE_BLACE is consumed.
2504 if (RootContext.Documentation != null)
2505 Lexer.doc_state = XmlCommentState.Allowed;
2507 CLOSE_BRACE opt_semicolon
2509 if (RootContext.Documentation != null)
2510 current_class.DocComment = enumTypeComment;
2512 --lexer.parsing_declaration;
2514 // if (RootContext.Documentation != null)
2515 // em.DocComment = ev.DocComment;
2517 lbag.AddMember (current_class, mod_locations, GetLocation ($3), GetLocation ($7), GetLocation ($11));
2518 $$ = pop_current_class ();
2526 var te = $2 as TypeExpression;
2528 (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
2529 te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
2530 te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
2531 te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
2532 Enum.Error_1008 (GetLocation ($2), Report);
2540 Error_TypeExpected (GetLocation ($1));
2545 opt_enum_member_declarations
2547 | enum_member_declarations
2548 | enum_member_declarations COMMA
2550 lbag.AddLocation ($1, GetLocation ($2));
2554 enum_member_declarations
2555 : enum_member_declaration
2556 | enum_member_declarations COMMA enum_member_declaration
2558 lbag.AddLocation ($1, GetLocation ($2));
2563 enum_member_declaration
2564 : opt_attributes IDENTIFIER
2566 var lt = (Tokenizer.LocatedToken) $2;
2567 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2568 ((Enum) current_class).AddEnumMember (em);
2570 if (RootContext.Documentation != null) {
2571 em.DocComment = Lexer.consume_doc_comment ();
2572 Lexer.doc_state = XmlCommentState.Allowed;
2577 | opt_attributes IDENTIFIER
2579 ++lexer.parsing_block;
2580 if (RootContext.Documentation != null) {
2581 tmpComment = Lexer.consume_doc_comment ();
2582 Lexer.doc_state = XmlCommentState.NotAllowed;
2585 ASSIGN constant_expression
2587 --lexer.parsing_block;
2589 var lt = (Tokenizer.LocatedToken) $2;
2590 var em = new EnumMember ((Enum) current_class, new MemberName (lt.Value, lt.Location), (Attributes) $1);
2591 em.Initializer = new ConstInitializer (em, (Expression) $5, GetLocation ($4));
2592 ((Enum) current_class).AddEnumMember (em);
2594 if (RootContext.Documentation != null)
2595 em.DocComment = ConsumeStoredComment ();
2601 delegate_declaration
2605 member_type type_declaration_name
2608 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2610 opt_formal_parameter_list CLOSE_PARENS
2612 valid_param_mod = 0;
2614 MemberName name = MakeName ((MemberName) $5);
2615 ParametersCompiled p = (ParametersCompiled) $8;
2617 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2618 (Modifiers) $2, name, p, (Attributes) $1);
2620 if (RootContext.Documentation != null) {
2621 del.DocComment = Lexer.consume_doc_comment ();
2622 Lexer.doc_state = XmlCommentState.Allowed;
2625 current_container.AddDelegate (del);
2626 current_delegate = del;
2627 lexer.ConstraintsParsing = true;
2629 opt_type_parameter_constraints_clauses
2631 lexer.ConstraintsParsing = false;
2635 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2636 lbag.AddMember (current_delegate, mod_locations, GetLocation ($3), GetLocation ($6), GetLocation ($9), GetLocation ($13));
2638 $$ = current_delegate;
2640 current_delegate = null;
2648 if (RootContext.Version < LanguageVersion.ISO_2)
2649 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2651 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2655 namespace_or_type_name
2657 | qualified_alias_member IDENTIFIER opt_type_argument_list
2659 var lt1 = (Tokenizer.LocatedToken) $1;
2660 var lt2 = (Tokenizer.LocatedToken) $2;
2662 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2668 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2670 var lt = (Tokenizer.LocatedToken) $3;
2671 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2672 lbag.AddLocation ($$, GetLocation ($2));
2677 : IDENTIFIER opt_type_argument_list
2679 var lt = (Tokenizer.LocatedToken) $1;
2680 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2685 // Generics arguments (any type, without attributes)
2687 opt_type_argument_list
2689 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2691 if (RootContext.Version < LanguageVersion.ISO_2)
2692 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2696 | OP_GENERICS_LT error
2698 Error_TypeExpected (lexer.Location);
2699 $$ = new TypeArguments ();
2706 TypeArguments type_args = new TypeArguments ();
2707 type_args.Add ((FullNamedExpression) $1);
2710 | type_arguments COMMA type
2712 TypeArguments type_args = (TypeArguments) $1;
2713 type_args.Add ((FullNamedExpression) $3);
2719 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2721 type_declaration_name
2724 lexer.parsing_generic_declaration = true;
2726 opt_type_parameter_list
2728 lexer.parsing_generic_declaration = false;
2729 var lt = (Tokenizer.LocatedToken) $1;
2730 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2734 member_declaration_name
2735 : method_declaration_name
2737 MemberName mn = (MemberName)$1;
2738 if (mn.TypeArguments != null)
2739 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2740 mn.GetSignatureForError ()));
2744 method_declaration_name
2745 : type_declaration_name
2746 | explicit_interface IDENTIFIER opt_type_parameter_list
2748 lexer.parsing_generic_declaration = false;
2749 var lt = (Tokenizer.LocatedToken) $2;
2750 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2754 indexer_declaration_name
2757 lexer.parsing_generic_declaration = false;
2758 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2760 | explicit_interface THIS
2762 lexer.parsing_generic_declaration = false;
2763 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2768 : IDENTIFIER opt_type_argument_list DOT
2770 var lt = (Tokenizer.LocatedToken) $1;
2771 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2772 lbag.AddLocation ($$, GetLocation ($3));
2774 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2776 var lt1 = (Tokenizer.LocatedToken) $1;
2777 var lt2 = (Tokenizer.LocatedToken) $2;
2779 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2780 lbag.AddLocation ($$, GetLocation ($4));
2782 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2784 var lt = (Tokenizer.LocatedToken) $2;
2785 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2786 lbag.AddLocation ($$, GetLocation ($4));
2790 opt_type_parameter_list
2792 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2794 if (RootContext.Version < LanguageVersion.ISO_2)
2795 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2798 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
2805 TypeArguments type_args = new TypeArguments ();
2806 type_args.Add ((FullNamedExpression)$1);
2809 | type_parameters COMMA type_parameter
2811 TypeArguments type_args = (TypeArguments) $1;
2812 type_args.Add ((FullNamedExpression)$3);
2814 lbag.AddLocation ($3, GetLocation ($3));
2819 : opt_attributes opt_type_parameter_variance IDENTIFIER
2821 var lt = (Tokenizer.LocatedToken)$3;
2822 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2826 if (GetTokenName (yyToken) == "type")
2827 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2829 Error_SyntaxError (yyToken);
2831 $$ = new TypeParameterName ("", null, lexer.Location);
2836 // All types where void is allowed
2839 : type_expression_or_array
2842 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2849 lexer.parsing_generic_declaration = true;
2854 // A type which does not allow `void' to be used
2857 : type_expression_or_array
2860 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2861 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2869 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2870 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2875 : type_expression_or_array
2878 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2879 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2883 type_expression_or_array
2885 | type_expression rank_specifiers
2887 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2892 : namespace_or_type_name opt_nullable
2894 MemberName name = (MemberName) $1;
2897 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2899 if (name.Left == null && name.Name == "var")
2900 $$ = new VarExpr (name.Location);
2902 $$ = name.GetTypeExpression ();
2905 | namespace_or_type_name pointer_stars
2907 $$ = new ComposedCast (((MemberName) $1).GetTypeExpression (), (ComposedTypeSpecifier) $2);
2909 | builtin_types opt_nullable
2912 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2914 | builtin_types pointer_stars
2916 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2918 | VOID pointer_stars
2920 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
2927 var types = new List<FullNamedExpression> (2);
2928 types.Add ((FullNamedExpression) $1);
2931 | type_list COMMA base_type_name
2933 var types = (List<FullNamedExpression>) $1;
2934 types.Add ((FullNamedExpression) $3);
2942 if ($1 is ComposedCast) {
2943 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2949 Error_TypeExpected (lexer.Location);
2955 * replaces all the productions for isolating the various
2956 * simple types, but we need this to reuse it easily in variable_type
2959 : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
2960 | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
2961 | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
2962 | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
2963 | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
2964 | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
2969 : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
2970 | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
2971 | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
2972 | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
2973 | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
2974 | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
2975 | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
2976 | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
2977 | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
2981 // Expressions, section 7.5
2986 : primary_expression_or_type
2988 | array_creation_expression
2989 | parenthesized_expression
2990 | default_value_expression
2991 | invocation_expression
2995 | post_increment_expression
2996 | post_decrement_expression
2997 | object_or_delegate_creation_expression
2998 | anonymous_type_expression
3001 | checked_expression
3002 | unchecked_expression
3003 | pointer_member_access
3004 | anonymous_method_expression
3007 primary_expression_or_type
3008 : IDENTIFIER opt_type_argument_list
3010 var lt = (Tokenizer.LocatedToken) $1;
3011 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
3013 | IDENTIFIER GENERATE_COMPLETION {
3014 var lt = (Tokenizer.LocatedToken) $1;
3015 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
3023 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
3027 : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
3028 | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
3033 // Here is the trick, tokenizer may think that parens is a special but
3034 // parser is interested in open parens only, so we merge them.
3035 // Consider: if (a)foo ();
3043 // Use this production to accept closing parenthesis or
3044 // performing completion
3048 | COMPLETE_COMPLETION
3052 parenthesized_expression
3053 : OPEN_PARENS expression CLOSE_PARENS
3055 $$ = new ParenthesizedExpression ((Expression) $2);
3056 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($3));
3058 | OPEN_PARENS expression COMPLETE_COMPLETION
3060 $$ = new ParenthesizedExpression ((Expression) $2);
3065 : primary_expression DOT IDENTIFIER opt_type_argument_list
3067 var lt = (Tokenizer.LocatedToken) $3;
3068 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3069 lbag.AddLocation ($$, GetLocation ($2));
3071 | builtin_types DOT IDENTIFIER opt_type_argument_list
3073 var lt = (Tokenizer.LocatedToken) $3;
3074 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3075 lbag.AddLocation ($$, GetLocation ($2));
3077 | BASE DOT IDENTIFIER opt_type_argument_list
3079 var lt = (Tokenizer.LocatedToken) $3;
3080 $$ = new MemberAccess (new BaseThis (GetLocation ($1)), lt.Value, (TypeArguments) $4, lt.Location);
3081 lbag.AddLocation ($$, GetLocation ($2));
3083 | qualified_alias_member IDENTIFIER opt_type_argument_list
3085 var lt1 = (Tokenizer.LocatedToken) $1;
3086 var lt2 = (Tokenizer.LocatedToken) $2;
3088 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3090 | primary_expression DOT GENERATE_COMPLETION {
3091 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3093 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3094 var lt = (Tokenizer.LocatedToken) $3;
3095 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3097 | builtin_types DOT GENERATE_COMPLETION
3099 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3101 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3102 var lt = (Tokenizer.LocatedToken) $3;
3103 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3107 invocation_expression
3108 : primary_expression open_parens_any opt_argument_list close_parens
3110 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3111 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3115 opt_object_or_collection_initializer
3116 : /* empty */ { $$ = null; }
3117 | object_or_collection_initializer
3120 object_or_collection_initializer
3121 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3124 $$ = CollectionOrObjectInitializers.Empty;
3127 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3128 lbag.AddLocation ($$, GetLocation ($3));
3131 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3133 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3134 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
3138 opt_member_initializer_list
3139 : /* empty */ { $$ = null; }
3140 | member_initializer_list
3146 member_initializer_list
3147 : member_initializer
3149 var a = new List<Expression> ();
3150 a.Add ((Expression) $1);
3153 | member_initializer_list COMMA member_initializer
3155 var a = (List<Expression>)$1;
3156 a.Add ((Expression) $3);
3159 | member_initializer_list error {
3160 Error_SyntaxError (yyToken);
3166 : IDENTIFIER ASSIGN initializer_value
3168 var lt = (Tokenizer.LocatedToken) $1;
3169 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3170 lbag.AddLocation ($$, GetLocation ($2));
3172 | GENERATE_COMPLETION
3174 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3176 | non_assignment_expression opt_COMPLETE_COMPLETION {
3177 CompletionSimpleName csn = $1 as CompletionSimpleName;
3179 $$ = new CollectionElementInitializer ((Expression)$1);
3181 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3183 | OPEN_BRACE expression_list CLOSE_BRACE
3188 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3190 | OPEN_BRACE CLOSE_BRACE
3192 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3199 | object_or_collection_initializer
3203 : /* empty */ { $$ = null; }
3208 : argument_or_named_argument
3210 Arguments list = new Arguments (4);
3211 list.Add ((Argument) $1);
3214 | argument_list COMMA argument
3216 Arguments list = (Arguments) $1;
3217 if (list [list.Count - 1] is NamedArgument)
3218 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3220 list.Add ((Argument) $3);
3223 | argument_list COMMA named_argument
3225 Arguments list = (Arguments) $1;
3226 NamedArgument a = (NamedArgument) $3;
3227 for (int i = 0; i < list.Count; ++i) {
3228 NamedArgument na = list [i] as NamedArgument;
3229 if (na != null && na.Name == a.Name)
3230 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3237 | argument_list COMMA
3239 Report.Error (839, GetLocation ($2), "An argument is missing");
3244 Report.Error (839, GetLocation ($1), "An argument is missing");
3252 $$ = new Argument ((Expression) $1);
3254 | non_simple_argument
3257 argument_or_named_argument
3263 : REF variable_reference
3265 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3266 lbag.AddLocation ($$, GetLocation ($1));
3268 | OUT variable_reference
3270 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3271 lbag.AddLocation ($$, GetLocation ($1));
3273 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3275 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3276 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3278 | ARGLIST OPEN_PARENS CLOSE_PARENS
3280 $$ = new Argument (new Arglist (GetLocation ($1)));
3281 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
3290 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3292 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3293 lbag.AddLocation ($$, GetLocation ($4));
3300 var list = new List<Expression> (4);
3301 list.Add ((Expression) $1);
3304 | expression_list COMMA expression
3306 var list = (List<Expression>) $1;
3307 list.Add ((Expression) $3);
3310 | expression_list error {
3311 Error_SyntaxError (yyToken);
3316 expression_list_arguments
3317 : expression_list_argument
3319 Arguments args = new Arguments (4);
3320 args.Add ((Argument) $1);
3323 | expression_list_arguments COMMA expression_list_argument
3325 Arguments args = (Arguments) $1;
3326 if (args [args.Count - 1] is NamedArgument && !($3 is NamedArgument))
3327 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
3329 args.Add ((Argument) $3);
3334 expression_list_argument
3337 $$ = new Argument ((Expression) $1);
3345 $$ = new This (GetLocation ($1));
3350 : BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3352 $$ = new ElementAccess (new BaseThis (GetLocation ($1)), (Arguments) $3, GetLocation ($2));
3353 lbag.AddLocation ($$, GetLocation ($4));
3355 | BASE OPEN_BRACKET error
3357 Error_SyntaxError (yyToken);
3358 $$ = new ElementAccess (null, null, GetLocation ($2));
3362 post_increment_expression
3363 : primary_expression OP_INC
3365 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3369 post_decrement_expression
3370 : primary_expression OP_DEC
3372 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3376 object_or_delegate_creation_expression
3377 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3380 if (RootContext.Version <= LanguageVersion.ISO_2)
3381 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3383 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3385 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3388 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3390 | NEW new_expr_type object_or_collection_initializer
3392 if (RootContext.Version <= LanguageVersion.ISO_2)
3393 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3395 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3399 array_creation_expression
3400 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3402 opt_array_initializer
3404 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3405 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3406 Next = (ComposedTypeSpecifier) $6
3407 }, (ArrayInitializer) $7, GetLocation ($1));
3408 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3410 | NEW new_expr_type rank_specifiers opt_array_initializer
3413 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3415 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3417 | NEW rank_specifier array_initializer
3419 if (RootContext.Version <= LanguageVersion.ISO_2)
3420 Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3422 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3424 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3426 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3427 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3429 | NEW new_expr_type error
3431 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3432 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3438 ++lexer.parsing_type;
3442 --lexer.parsing_type;
3447 anonymous_type_expression
3448 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3450 if (RootContext.Version <= LanguageVersion.ISO_2)
3451 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3453 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3455 // TODO: lbag comma location
3456 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3460 anonymous_type_parameters_opt_comma
3461 : anonymous_type_parameters_opt
3462 | anonymous_type_parameters COMMA
3465 anonymous_type_parameters_opt
3467 | anonymous_type_parameters
3470 anonymous_type_parameters
3471 : anonymous_type_parameter
3473 var a = new List<AnonymousTypeParameter> (4);
3474 a.Add ((AnonymousTypeParameter) $1);
3477 | anonymous_type_parameters COMMA anonymous_type_parameter
3479 var a = (List<AnonymousTypeParameter>) $1;
3480 a.Add ((AnonymousTypeParameter) $3);
3485 anonymous_type_parameter
3486 : IDENTIFIER ASSIGN variable_initializer
3488 var lt = (Tokenizer.LocatedToken)$1;
3489 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3490 lbag.AddLocation ($$, GetLocation ($2));
3494 var lt = (Tokenizer.LocatedToken)$1;
3495 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3496 lt.Value, lt.Location);
3500 MemberAccess ma = (MemberAccess) $1;
3501 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3505 Report.Error (746, lexer.Location,
3506 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3518 | rank_specifier rank_specifiers
3520 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3526 : OPEN_BRACKET CLOSE_BRACKET
3528 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3530 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3532 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3541 | dim_separators COMMA
3543 $$ = ((int) $1) + 1;
3547 opt_array_initializer
3559 : OPEN_BRACE CLOSE_BRACE
3561 var ai = new ArrayInitializer (0, GetLocation ($1));
3562 ai.VariableDeclaration = current_variable;
3563 lbag.AddLocation (ai, GetLocation ($2));
3566 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3568 var ai = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3569 ai.VariableDeclaration = current_variable;
3570 lbag.AddLocation (ai, GetLocation ($3));
3575 variable_initializer_list
3576 : variable_initializer
3578 var list = new List<Expression> (4);
3579 list.Add ((Expression) $1);
3582 | variable_initializer_list COMMA variable_initializer
3584 var list = (List<Expression>) $1;
3585 list.Add ((Expression) $3);
3593 lexer.TypeOfParsing = true;
3595 open_parens_any typeof_type_expression CLOSE_PARENS
3597 lexer.TypeOfParsing = false;
3598 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3599 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
3603 typeof_type_expression
3608 Error_TypeExpected (lexer.Location);
3614 : IDENTIFIER generic_dimension
3616 var lt = (Tokenizer.LocatedToken) $1;
3618 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3620 | qualified_alias_member IDENTIFIER generic_dimension
3622 var lt1 = (Tokenizer.LocatedToken) $1;
3623 var lt2 = (Tokenizer.LocatedToken) $2;
3625 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3627 | unbound_type_name DOT IDENTIFIER
3629 var lt = (Tokenizer.LocatedToken) $3;
3631 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3633 | unbound_type_name DOT IDENTIFIER generic_dimension
3635 var lt = (Tokenizer.LocatedToken) $3;
3637 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3639 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3641 var te = ((MemberName) $1).GetTypeExpression ();
3642 if (te.HasTypeArguments)
3643 Error_TypeExpected (GetLocation ($4));
3645 var lt = (Tokenizer.LocatedToken) $3;
3646 $$ = new MemberAccess (te, lt.Value, (int) $4, lt.Location);
3653 if (RootContext.Version < LanguageVersion.ISO_2)
3654 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
3660 qualified_alias_member
3661 : IDENTIFIER DOUBLE_COLON
3663 var lt = (Tokenizer.LocatedToken) $1;
3664 if (RootContext.Version == LanguageVersion.ISO_1)
3665 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3672 : SIZEOF open_parens_any type CLOSE_PARENS
3674 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3675 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3680 : CHECKED open_parens_any expression CLOSE_PARENS
3682 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3683 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3687 unchecked_expression
3688 : UNCHECKED open_parens_any expression CLOSE_PARENS
3690 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3691 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3695 pointer_member_access
3696 : primary_expression OP_PTR IDENTIFIER
3698 var lt = (Tokenizer.LocatedToken) $3;
3699 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3703 anonymous_method_expression
3704 : DELEGATE opt_anonymous_method_signature
3706 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3710 $$ = end_anonymous ((ParametersBlock) $4);
3714 opt_anonymous_method_signature
3717 $$ = ParametersCompiled.Undefined;
3719 | anonymous_method_signature
3722 anonymous_method_signature
3725 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3727 opt_formal_parameter_list CLOSE_PARENS
3729 valid_param_mod = 0;
3734 default_value_expression
3735 : DEFAULT open_parens_any type CLOSE_PARENS
3737 if (RootContext.Version < LanguageVersion.ISO_2)
3738 Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3740 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3741 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($4));
3746 : primary_expression
3747 | BANG prefixed_unary_expression
3749 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3751 | TILDE prefixed_unary_expression
3753 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3759 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3761 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3762 lbag.AddLocation ($$, GetLocation ($3));
3767 // The idea to split this out is from Rhys' grammar
3768 // to solve the problem with casts.
3770 prefixed_unary_expression
3772 | PLUS prefixed_unary_expression
3774 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3776 | MINUS prefixed_unary_expression
3778 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3780 | OP_INC prefixed_unary_expression
3782 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3784 | OP_DEC prefixed_unary_expression
3786 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3788 | STAR prefixed_unary_expression
3790 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3792 | BITWISE_AND prefixed_unary_expression
3794 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3798 multiplicative_expression
3799 : prefixed_unary_expression
3800 | multiplicative_expression STAR prefixed_unary_expression
3802 $$ = new Binary (Binary.Operator.Multiply,
3803 (Expression) $1, (Expression) $3, GetLocation ($2));
3805 | multiplicative_expression DIV prefixed_unary_expression
3807 $$ = new Binary (Binary.Operator.Division,
3808 (Expression) $1, (Expression) $3, GetLocation ($2));
3810 | multiplicative_expression PERCENT prefixed_unary_expression
3812 $$ = new Binary (Binary.Operator.Modulus,
3813 (Expression) $1, (Expression) $3, GetLocation ($2));
3818 : multiplicative_expression
3819 | additive_expression PLUS multiplicative_expression
3821 $$ = new Binary (Binary.Operator.Addition,
3822 (Expression) $1, (Expression) $3, GetLocation ($2));
3824 | additive_expression MINUS multiplicative_expression
3826 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3828 | parenthesized_expression MINUS multiplicative_expression
3830 // Shift/Reduce conflict
3831 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3833 | additive_expression AS type
3835 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3837 | additive_expression IS type
3839 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3844 : additive_expression
3845 | shift_expression OP_SHIFT_LEFT additive_expression
3847 $$ = new Binary (Binary.Operator.LeftShift,
3848 (Expression) $1, (Expression) $3, GetLocation ($2));
3850 | shift_expression OP_SHIFT_RIGHT additive_expression
3852 $$ = new Binary (Binary.Operator.RightShift,
3853 (Expression) $1, (Expression) $3, GetLocation ($2));
3857 relational_expression
3859 | relational_expression OP_LT shift_expression
3861 $$ = new Binary (Binary.Operator.LessThan,
3862 (Expression) $1, (Expression) $3, GetLocation ($2));
3864 | relational_expression OP_GT shift_expression
3866 $$ = new Binary (Binary.Operator.GreaterThan,
3867 (Expression) $1, (Expression) $3, GetLocation ($2));
3869 | relational_expression OP_LE shift_expression
3871 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3872 (Expression) $1, (Expression) $3, GetLocation ($2));
3874 | relational_expression OP_GE shift_expression
3876 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3877 (Expression) $1, (Expression) $3, GetLocation ($2));
3882 : relational_expression
3883 | equality_expression OP_EQ relational_expression
3885 $$ = new Binary (Binary.Operator.Equality,
3886 (Expression) $1, (Expression) $3, GetLocation ($2));
3888 | equality_expression OP_NE relational_expression
3890 $$ = new Binary (Binary.Operator.Inequality,
3891 (Expression) $1, (Expression) $3, GetLocation ($2));
3896 : equality_expression
3897 | and_expression BITWISE_AND equality_expression
3899 $$ = new Binary (Binary.Operator.BitwiseAnd,
3900 (Expression) $1, (Expression) $3, GetLocation ($2));
3904 exclusive_or_expression
3906 | exclusive_or_expression CARRET and_expression
3908 $$ = new Binary (Binary.Operator.ExclusiveOr,
3909 (Expression) $1, (Expression) $3, GetLocation ($2));
3913 inclusive_or_expression
3914 : exclusive_or_expression
3915 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3917 $$ = new Binary (Binary.Operator.BitwiseOr,
3918 (Expression) $1, (Expression) $3, GetLocation ($2));
3922 conditional_and_expression
3923 : inclusive_or_expression
3924 | conditional_and_expression OP_AND inclusive_or_expression
3926 $$ = new Binary (Binary.Operator.LogicalAnd,
3927 (Expression) $1, (Expression) $3, GetLocation ($2));
3931 conditional_or_expression
3932 : conditional_and_expression
3933 | conditional_or_expression OP_OR conditional_and_expression
3935 $$ = new Binary (Binary.Operator.LogicalOr,
3936 (Expression) $1, (Expression) $3, GetLocation ($2));
3940 null_coalescing_expression
3941 : conditional_or_expression
3942 | conditional_or_expression OP_COALESCING null_coalescing_expression
3944 if (RootContext.Version < LanguageVersion.ISO_2)
3945 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3947 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3951 conditional_expression
3952 : null_coalescing_expression
3953 | null_coalescing_expression INTERR expression COLON expression
3955 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5, GetLocation ($2));
3956 lbag.AddLocation ($$, GetLocation ($4));
3960 assignment_expression
3961 : prefixed_unary_expression ASSIGN expression
3963 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3965 | prefixed_unary_expression OP_MULT_ASSIGN expression
3967 $$ = new CompoundAssign (
3968 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3970 | prefixed_unary_expression OP_DIV_ASSIGN expression
3972 $$ = new CompoundAssign (
3973 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3975 | prefixed_unary_expression OP_MOD_ASSIGN expression
3977 $$ = new CompoundAssign (
3978 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
3980 | prefixed_unary_expression OP_ADD_ASSIGN expression
3982 $$ = new CompoundAssign (
3983 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
3985 | prefixed_unary_expression OP_SUB_ASSIGN expression
3987 $$ = new CompoundAssign (
3988 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3990 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3992 $$ = new CompoundAssign (
3993 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
3995 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3997 $$ = new CompoundAssign (
3998 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
4000 | prefixed_unary_expression OP_AND_ASSIGN expression
4002 $$ = new CompoundAssign (
4003 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
4005 | prefixed_unary_expression OP_OR_ASSIGN expression
4007 $$ = new CompoundAssign (
4008 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4010 | prefixed_unary_expression OP_XOR_ASSIGN expression
4012 $$ = new CompoundAssign (
4013 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
4017 lambda_parameter_list
4020 var pars = new List<Parameter> (4);
4021 pars.Add ((Parameter) $1);
4025 | lambda_parameter_list COMMA lambda_parameter
4027 var pars = (List<Parameter>) $1;
4028 Parameter p = (Parameter)$3;
4029 if (pars[0].GetType () != p.GetType ()) {
4030 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
4039 : parameter_modifier parameter_type IDENTIFIER
4041 var lt = (Tokenizer.LocatedToken) $3;
4043 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
4045 | parameter_type IDENTIFIER
4047 var lt = (Tokenizer.LocatedToken) $2;
4049 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4053 var lt = (Tokenizer.LocatedToken) $1;
4054 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4058 opt_lambda_parameter_list
4059 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4060 | lambda_parameter_list {
4061 var pars_list = (List<Parameter>) $1;
4062 $$ = new ParametersCompiled (pars_list.ToArray ());
4066 lambda_expression_body
4067 : lambda_expression_body_simple
4071 lambda_expression_body_simple
4073 start_block (lexer.Location);
4075 expression_or_error // Have to close block when error occurs
4077 Block b = end_block (lexer.Location);
4078 b.AddStatement (new ContextualReturn ((Expression) $2));
4087 Error_SyntaxError (yyToken);
4088 $$ = EmptyExpression.Null;
4095 var lt = (Tokenizer.LocatedToken) $1;
4096 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4097 start_anonymous (true, new ParametersCompiled (p), GetLocation ($1));
4099 lambda_expression_body
4101 $$ = end_anonymous ((ParametersBlock) $4);
4102 lbag.AddLocation ($$, GetLocation ($2));
4104 | OPEN_PARENS_LAMBDA
4106 if (RootContext.Version <= LanguageVersion.ISO_2)
4107 Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4109 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4111 opt_lambda_parameter_list CLOSE_PARENS ARROW
4113 valid_param_mod = 0;
4114 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4116 lambda_expression_body
4118 $$ = end_anonymous ((ParametersBlock) $7);
4119 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($4));
4124 : assignment_expression
4125 | non_assignment_expression
4128 non_assignment_expression
4129 : conditional_expression
4134 $$ = new ArglistAccess (GetLocation ($1));
4145 $$ = new BooleanExpression ((Expression) $1);
4158 lexer.ConstraintsParsing = true;
4160 type_declaration_name
4162 MemberName name = MakeName ((MemberName) $6);
4163 push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
4166 opt_type_parameter_constraints_clauses
4168 lexer.ConstraintsParsing = false;
4170 current_class.SetParameterInfo ((List<Constraints>) $9);
4171 lbag.AddMember (current_class, mod_locations, GetLocation ($4));
4173 if (RootContext.Documentation != null) {
4174 current_container.DocComment = Lexer.consume_doc_comment ();
4175 Lexer.doc_state = XmlCommentState.Allowed;
4178 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4180 --lexer.parsing_declaration;
4181 if (RootContext.Documentation != null)
4182 Lexer.doc_state = XmlCommentState.Allowed;
4186 lbag.AppendToMember (current_class, GetLocation ($11), GetLocation ($13), GetLocation ($15));
4187 $$ = pop_current_class ();
4195 { $$ = $1; } // location
4201 mod_locations = null;
4209 | modifiers modifier
4211 var m1 = (Modifiers) $1;
4212 var m2 = (Modifiers) $2;
4214 if ((m1 & m2) != 0) {
4215 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4216 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4217 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4218 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4219 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4220 "More than one protection modifier specified");
4231 StoreModifierLocation ($$, GetLocation ($1));
4233 if (current_container == RootContext.ToplevelTypes)
4234 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4238 $$ = Modifiers.PUBLIC;
4239 StoreModifierLocation ($$, GetLocation ($1));
4243 $$ = Modifiers.PROTECTED;
4244 StoreModifierLocation ($$, GetLocation ($1));
4248 $$ = Modifiers.INTERNAL;
4249 StoreModifierLocation ($$, GetLocation ($1));
4253 $$ = Modifiers.PRIVATE;
4254 StoreModifierLocation ($$, GetLocation ($1));
4258 $$ = Modifiers.ABSTRACT;
4259 StoreModifierLocation ($$, GetLocation ($1));
4263 $$ = Modifiers.SEALED;
4264 StoreModifierLocation ($$, GetLocation ($1));
4268 $$ = Modifiers.STATIC;
4269 StoreModifierLocation ($$, GetLocation ($1));
4273 $$ = Modifiers.READONLY;
4274 StoreModifierLocation ($$, GetLocation ($1));
4278 $$ = Modifiers.VIRTUAL;
4279 StoreModifierLocation ($$, GetLocation ($1));
4283 $$ = Modifiers.OVERRIDE;
4284 StoreModifierLocation ($$, GetLocation ($1));
4288 $$ = Modifiers.EXTERN;
4289 StoreModifierLocation ($$, GetLocation ($1));
4293 $$ = Modifiers.VOLATILE;
4294 StoreModifierLocation ($$, GetLocation ($1));
4298 $$ = Modifiers.UNSAFE;
4299 StoreModifierLocation ($$, GetLocation ($1));
4300 if (!RootContext.Unsafe)
4301 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4305 $$ = Modifiers.ASYNC;
4306 StoreModifierLocation ($$, GetLocation ($1));
4314 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4318 opt_type_parameter_constraints_clauses
4320 | type_parameter_constraints_clauses
4326 Error_SyntaxError (yyToken);
4331 type_parameter_constraints_clauses
4332 : type_parameter_constraints_clause
4334 var constraints = new List<Constraints> (1);
4335 constraints.Add ((Constraints) $1);
4338 | type_parameter_constraints_clauses type_parameter_constraints_clause
4340 var constraints = (List<Constraints>) $1;
4341 Constraints new_constraint = (Constraints)$2;
4343 foreach (Constraints c in constraints) {
4344 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4345 Report.Error (409, new_constraint.Location,
4346 "A constraint clause has already been specified for type parameter `{0}'",
4347 new_constraint.TypeParameter.Value);
4351 constraints.Add (new_constraint);
4356 type_parameter_constraints_clause
4357 : WHERE IDENTIFIER COLON type_parameter_constraints
4359 var lt = (Tokenizer.LocatedToken) $2;
4360 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4364 type_parameter_constraints
4365 : type_parameter_constraint
4367 var constraints = new List<FullNamedExpression> (1);
4368 constraints.Add ((FullNamedExpression) $1);
4371 | type_parameter_constraints COMMA type_parameter_constraint
4373 var constraints = (List<FullNamedExpression>) $1;
4374 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4375 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4376 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4379 prev = $3 as SpecialContraintExpr;
4381 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4382 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4384 prev = constraints [0] as SpecialContraintExpr;
4385 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4386 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4391 constraints.Add ((FullNamedExpression) $3);
4396 type_parameter_constraint
4399 if ($1 is ComposedCast)
4400 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4404 | NEW OPEN_PARENS CLOSE_PARENS
4406 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4407 lbag.AddLocation ($$, GetLocation ($2), GetLocation ($3));
4411 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4415 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4419 opt_type_parameter_variance
4424 | type_parameter_variance
4426 if (RootContext.Version <= LanguageVersion.V_3)
4427 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4433 type_parameter_variance
4436 $$ = Variance.Covariant;
4440 $$ = Variance.Contravariant;
4449 // A block is "contained" on the following places:
4451 // property_declaration as part of the accessor body (get/set)
4452 // operator_declaration
4453 // constructor_declaration
4454 // destructor_declaration
4455 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4460 ++lexer.parsing_block;
4461 start_block (GetLocation ($1));
4463 opt_statement_list block_end
4472 --lexer.parsing_block;
4473 $$ = end_block (GetLocation ($1));
4475 | COMPLETE_COMPLETION
4477 --lexer.parsing_block;
4478 $$ = end_block (lexer.Location);
4486 ++lexer.parsing_block;
4487 current_block.StartLocation = GetLocation ($1);
4489 opt_statement_list CLOSE_BRACE
4491 --lexer.parsing_block;
4492 $$ = end_block (GetLocation ($4));
4503 | statement_list statement
4507 : block_variable_declaration
4509 current_block.AddStatement ((Statement) $1);
4511 | valid_declaration_statement
4513 current_block.AddStatement ((Statement) $1);
4518 Error_SyntaxError (yyToken);
4524 // The interactive_statement and its derivatives are only
4525 // used to provide a special version of `expression_statement'
4526 // that has a side effect of assigning the expression to
4529 interactive_statement_list
4530 : interactive_statement
4531 | interactive_statement_list interactive_statement
4534 interactive_statement
4535 : block_variable_declaration
4537 current_block.AddStatement ((Statement) $1);
4539 | interactive_valid_declaration_statement
4541 current_block.AddStatement ((Statement) $1);
4546 valid_declaration_statement
4549 | expression_statement
4550 | selection_statement
4551 | iteration_statement
4555 | unchecked_statement
4562 interactive_valid_declaration_statement
4565 | interactive_expression_statement
4566 | selection_statement
4567 | iteration_statement
4571 | unchecked_statement
4579 : valid_declaration_statement
4580 | block_variable_declaration
4582 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4587 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4592 Error_SyntaxError (yyToken);
4593 $$ = new EmptyStatement (GetLocation ($1));
4600 // Uses lexer.Location because semicolon location is not kept in quick mode
4601 $$ = new EmptyStatement (lexer.Location);
4608 var lt = (Tokenizer.LocatedToken) $1;
4609 LabeledStatement labeled = new LabeledStatement (lt.Value, current_block, lt.Location);
4611 current_block.AddLabel (labeled);
4612 current_block.AddStatement (labeled);
4618 : variable_type_simple
4619 | variable_type_simple rank_specifiers
4622 $1 = new SimpleName ("var", ((VarExpr) $1).Location);
4624 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4629 * The following is from Rhys' grammar:
4630 * > Types in local variable declarations must be recognized as
4631 * > expressions to prevent reduce/reduce errors in the grammar.
4632 * > The expressions are converted into types during semantic analysis.
4634 variable_type_simple
4635 : primary_expression_or_type opt_nullable
4637 // Ok, the above "primary_expression" is there to get rid of
4638 // both reduce/reduce and shift/reduces in the grammar, it should
4639 // really just be "type_name". If you use type_name, a reduce/reduce
4640 // creeps up. If you use namespace_or_type_name (which is all we need
4641 // really) two shift/reduces appear.
4644 // So the super-trick is that primary_expression
4645 // can only be either a SimpleName or a MemberAccess.
4646 // The MemberAccess case arises when you have a fully qualified type-name like :
4648 // SimpleName is when you have
4651 Expression expr = (Expression) $1;
4653 SimpleName sn = expr as SimpleName;
4654 if (sn != null && sn.Name == "var")
4655 $$ = new VarExpr (sn.Location);
4658 } else if (expr is ATypeNameExpression) {
4659 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4661 Error_ExpectingTypeName (expr);
4665 | primary_expression_or_type pointer_stars
4667 ATypeNameExpression expr = $1 as ATypeNameExpression;
4670 $$ = new ComposedCast (expr, (ComposedTypeSpecifier) $2);
4672 Error_ExpectingTypeName ((Expression)$1);
4676 | builtin_types opt_nullable
4681 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4683 | builtin_types pointer_stars
4685 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4687 | VOID pointer_stars
4689 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), (ComposedTypeSpecifier) $2);
4693 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4694 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4700 | pointer_star pointer_stars
4702 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
4710 $$ = ComposedTypeSpecifier.CreatePointer (GetLocation ($1));
4714 block_variable_declaration
4715 : variable_type IDENTIFIER
4717 var lt = (Tokenizer.LocatedToken) $2;
4718 var li = new LocalVariable (current_block, lt.Value, lt.Location);
4719 current_block.AddLocalName (li);
4720 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
4722 opt_local_variable_initializer opt_variable_declarators SEMICOLON
4724 $$ = current_variable;
4725 current_variable = null;
4726 lbag.AddLocation ($$, GetLocation ($6));
4728 | CONST variable_type IDENTIFIER
4730 var lt = (Tokenizer.LocatedToken) $3;
4731 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4732 current_block.AddLocalName (li);
4733 current_variable = new BlockConstantDeclaration ((FullNamedExpression) $2, li);
4735 const_variable_initializer opt_const_declarators SEMICOLON
4737 $$ = current_variable;
4738 current_variable = null;
4739 lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
4743 opt_local_variable_initializer
4745 | ASSIGN block_variable_initializer
4747 current_variable.Initializer = (Expression) $2;
4752 if (yyToken == Token.OPEN_BRACKET_EXPR) {
4753 Report.Error (650, lexer.Location,
4754 "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");
4756 Error_SyntaxError (yyToken);
4761 opt_variable_declarators
4763 | variable_declarators
4766 variable_declarators
4767 : variable_declarator
4768 | variable_declarators variable_declarator
4774 var lt = (Tokenizer.LocatedToken) $2;
4775 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4776 var d = new BlockVariableDeclaration.Declarator (li, null);
4777 current_variable.AddDeclarator (d);
4778 current_block.AddLocalName (li);
4779 lbag.AddLocation (d, GetLocation ($1));
4781 | COMMA IDENTIFIER ASSIGN block_variable_initializer
4783 var lt = (Tokenizer.LocatedToken) $2;
4784 var li = new LocalVariable (current_variable.Variable, lt.Value, lt.Location);
4785 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4786 current_variable.AddDeclarator (d);
4787 current_block.AddLocalName (li);
4788 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4792 const_variable_initializer
4795 Report.Error (145, lexer.Location, "A const field requires a value to be provided");
4797 | ASSIGN constant_initializer_expr
4799 current_variable.Initializer = (Expression) $2;
4803 opt_const_declarators
4810 | const_declarators const_declarator
4814 : COMMA IDENTIFIER ASSIGN constant_initializer_expr
4816 var lt = (Tokenizer.LocatedToken) $2;
4817 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.Constant, lt.Location);
4818 var d = new BlockVariableDeclaration.Declarator (li, (Expression) $4);
4819 current_variable.AddDeclarator (d);
4820 current_block.AddLocalName (li);
4821 lbag.AddLocation (d, GetLocation ($1), GetLocation ($3));
4825 block_variable_initializer
4826 : variable_initializer
4827 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
4829 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
4830 lbag.AddLocation ($$, GetLocation ($3), GetLocation ($5));
4832 | STACKALLOC simple_type
4834 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
4835 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
4839 expression_statement
4840 : statement_expression SEMICOLON
4843 lbag.AddStatement ($$, GetLocation ($2));
4845 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4848 interactive_expression_statement
4849 : interactive_statement_expression SEMICOLON { $$ = $1; }
4850 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4854 // We have to do the wrapping here and not in the case above,
4855 // because statement_expression is used for example in for_statement
4857 statement_expression
4860 ExpressionStatement s = $1 as ExpressionStatement;
4862 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4863 s = EmptyExpressionStatement.Instance;
4866 $$ = new StatementExpression (s);
4870 interactive_statement_expression
4873 Expression expr = (Expression) $1;
4874 ExpressionStatement s;
4876 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4877 $$ = new StatementExpression (s);
4881 Error_SyntaxError (yyToken);
4882 $$ = new EmptyStatement (GetLocation ($1));
4892 : IF open_parens_any boolean_expression CLOSE_PARENS
4895 if ($5 is EmptyStatement)
4896 Warning_EmptyStatement (GetLocation ($5));
4898 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4899 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4901 | IF open_parens_any boolean_expression CLOSE_PARENS
4902 embedded_statement ELSE embedded_statement
4904 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4905 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4), GetLocation ($6));
4907 if ($5 is EmptyStatement)
4908 Warning_EmptyStatement (GetLocation ($5));
4909 if ($7 is EmptyStatement)
4910 Warning_EmptyStatement (GetLocation ($7));
4915 : SWITCH open_parens_any expression CLOSE_PARENS OPEN_BRACE
4917 start_block (GetLocation ($5));
4919 opt_switch_sections CLOSE_BRACE
4921 $$ = new Switch ((Expression) $3, (ExplicitBlock) current_block.Explicit, (List<SwitchSection>) $7, GetLocation ($1));
4922 end_block (GetLocation ($8));
4923 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
4930 Report.Warning (1522, 1, current_block.StartLocation, "Empty switch block");
4931 $$ = new List<SwitchSection> ();
4939 var sections = new List<SwitchSection> (4);
4941 sections.Add ((SwitchSection) $1);
4944 | switch_sections switch_section
4946 var sections = (List<SwitchSection>) $1;
4948 sections.Add ((SwitchSection) $2);
4953 Error_SyntaxError (yyToken);
4954 $$ = new List<SwitchSection> ();
4961 current_block = current_block.CreateSwitchBlock (lexer.Location);
4965 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block);
4972 var labels = new List<SwitchLabel> (4);
4974 labels.Add ((SwitchLabel) $1);
4977 | switch_labels switch_label
4979 var labels = (List<SwitchLabel>) ($1);
4980 labels.Add ((SwitchLabel) $2);
4987 : CASE constant_expression COLON
4989 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
4990 lbag.AddLocation ($$, GetLocation ($3));
4994 $$ = new SwitchLabel (null, GetLocation ($1));
5006 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
5008 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5009 Warning_EmptyStatement (GetLocation ($5));
5011 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
5012 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5017 : DO embedded_statement
5018 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
5020 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
5021 lbag.AddStatement ($$, GetLocation ($3), GetLocation ($4), GetLocation ($6), GetLocation ($7));
5026 : FOR open_parens_any
5028 start_block (GetLocation ($2));
5029 current_block.IsCompilerGenerated = true;
5037 // Has to use be extra rule to recover started block
5039 : opt_for_initializer SEMICOLON
5040 opt_for_condition SEMICOLON
5041 opt_for_iterator CLOSE_PARENS
5044 if ($7 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5045 Warning_EmptyStatement (GetLocation ($7));
5047 For f = new For ((Statement) $1, (BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($-2));
5048 current_block.AddStatement (f);
5050 lbag.AddStatement (f, current_block.StartLocation, GetLocation ($2), GetLocation ($4), GetLocation ($6));
5052 $$ = end_block (GetLocation ($2));
5056 Error_SyntaxError (yyToken);
5057 $$ = end_block (current_block.StartLocation);
5062 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5067 : variable_type IDENTIFIER
5069 var lt = (Tokenizer.LocatedToken) $2;
5070 var li = new LocalVariable (current_block, lt.Value, lt.Location);
5071 current_block.AddLocalName (li);
5072 current_variable = new BlockVariableDeclaration ((FullNamedExpression) $1, li);
5074 opt_local_variable_initializer opt_variable_declarators
5076 $$ = current_variable;
5077 current_variable = null;
5079 | statement_expression_list
5083 : /* empty */ { $$ = null; }
5084 | boolean_expression
5088 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
5093 : statement_expression_list
5096 statement_expression_list
5097 : statement_expression
5098 | statement_expression_list COMMA statement_expression
5100 var sl = $1 as StatementList;
5102 sl = new StatementList ((Statement) $1, (Statement) $3);
5103 lbag.AddStatement (sl, GetLocation ($2));
5105 sl.Add ((Statement) $3);
5106 lbag.AppendTo (sl, GetLocation ($2));
5114 : FOREACH open_parens_any type IN expression CLOSE_PARENS
5116 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
5119 | FOREACH open_parens_any type IDENTIFIER IN expression CLOSE_PARENS
5121 start_block (GetLocation ($2));
5122 current_block.IsCompilerGenerated = true;
5124 var lt = (Tokenizer.LocatedToken) $4;
5125 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ForeachVariable | LocalVariable.Flags.Used, lt.Location);
5126 current_block.AddLocalName (li);
5131 if ($9 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5132 Warning_EmptyStatement (GetLocation ($9));
5134 Foreach f = new Foreach ((Expression) $3, (LocalVariable) $8, (Expression) $6, (Statement) $9, GetLocation ($1));
5135 current_block.AddStatement (f);
5137 lbag.AddStatement (f, GetLocation ($2), GetLocation ($5), GetLocation ($7));
5138 $$ = end_block (GetLocation ($7));
5144 | continue_statement
5154 $$ = new Break (GetLocation ($1));
5155 lbag.AddStatement ($$, GetLocation ($2));
5160 : CONTINUE SEMICOLON
5162 $$ = new Continue (GetLocation ($1));
5163 lbag.AddStatement ($$, GetLocation ($2));
5168 : GOTO IDENTIFIER SEMICOLON
5170 var lt = (Tokenizer.LocatedToken) $2;
5171 $$ = new Goto (lt.Value, lt.Location);
5172 lbag.AddStatement ($$, GetLocation ($1), GetLocation ($3));
5174 | GOTO CASE constant_expression SEMICOLON
5176 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
5177 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5179 | GOTO DEFAULT SEMICOLON
5181 $$ = new GotoDefault (GetLocation ($1));
5182 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5187 : RETURN opt_expression SEMICOLON
5189 $$ = new Return ((Expression) $2, GetLocation ($1));
5190 lbag.AddStatement ($$, GetLocation ($3));
5195 : THROW opt_expression SEMICOLON
5197 $$ = new Throw ((Expression) $2, GetLocation ($1));
5198 lbag.AddStatement ($$, GetLocation ($3));
5203 : IDENTIFIER RETURN opt_expression SEMICOLON
5205 var lt = (Tokenizer.LocatedToken) $1;
5206 string s = lt.Value;
5208 Report.Error (1003, lt.Location, "; expected");
5209 } else if ($3 == null) {
5210 Report.Error (1627, GetLocation ($4), "Expression expected after yield return");
5211 } else if (RootContext.Version == LanguageVersion.ISO_1){
5212 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5215 current_block.ParametersBlock.TopBlock.IsIterator = true;
5216 $$ = new Yield ((Expression) $3, lt.Location);
5217 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5219 | IDENTIFIER BREAK SEMICOLON
5221 var lt = (Tokenizer.LocatedToken) $1;
5222 string s = lt.Value;
5224 Report.Error (1003, lt.Location, "; expected");
5225 } else if (RootContext.Version == LanguageVersion.ISO_1){
5226 Report.FeatureIsNotAvailable (lt.Location, "iterators");
5229 current_block.ParametersBlock.TopBlock.IsIterator = true;
5230 $$ = new YieldBreak (lt.Location);
5231 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($3));
5241 : TRY block catch_clauses
5243 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5245 | TRY block FINALLY block
5247 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5248 lbag.AddStatement ($$, GetLocation ($3));
5250 | TRY block catch_clauses FINALLY block
5252 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5253 lbag.AddStatement ($$, GetLocation ($4));
5257 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5265 var l = new List<Catch> (2);
5270 | catch_clauses catch_clause
5272 var l = (List<Catch>) $1;
5274 Catch c = (Catch) $2;
5275 if (l [0].IsGeneral) {
5276 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5296 $$ = new Catch ((Block) $2, GetLocation ($1));
5298 | CATCH open_parens_any type opt_identifier CLOSE_PARENS
5300 start_block (GetLocation ($2));
5301 var c = new Catch (current_block, GetLocation ($1));
5302 c.TypeExpression = (FullNamedExpression) $3;
5305 var lt = (Tokenizer.LocatedToken) $4;
5306 c.Variable = new LocalVariable (current_block, lt.Value, lt.Location);
5307 current_block.AddLocalName (c.Variable);
5310 lbag.AddLocation (c, GetLocation ($2), GetLocation ($5));
5317 | CATCH open_parens_any error
5319 if (yyToken == Token.CLOSE_PARENS) {
5320 Report.Error (1015, lexer.Location,
5321 "A type that derives from `System.Exception', `object', or `string' expected");
5323 Error_SyntaxError (yyToken);
5326 $$ = new Catch (null, GetLocation ($1));
5333 $$ = new Checked ((Block) $2, GetLocation ($1));
5340 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5347 if (!RootContext.Unsafe)
5348 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5350 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5355 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5357 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5358 Warning_EmptyStatement (GetLocation ($5));
5360 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5361 lbag.AddStatement ($$, GetLocation ($2), GetLocation ($4));
5366 : FIXED open_parens_any variable_type IDENTIFIER
5368 start_block (GetLocation ($2));
5370 var lt = (Tokenizer.LocatedToken) $4;
5371 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.FixedVariable | LocalVariable.Flags.Used, lt.Location);
5372 current_block.AddLocalName (li);
5373 current_variable = new Fixed.VariableDeclaration ((FullNamedExpression) $3, li);
5375 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5377 $$ = current_variable;
5378 current_variable = null;
5382 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5383 Warning_EmptyStatement (GetLocation ($10));
5385 Fixed f = new Fixed ((Fixed.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5386 current_block.AddStatement (f);
5387 $$ = end_block (GetLocation ($8));
5392 : USING open_parens_any variable_type IDENTIFIER
5394 start_block (GetLocation ($2));
5396 var lt = (Tokenizer.LocatedToken) $4;
5397 var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.UsingVariable | LocalVariable.Flags.Used, lt.Location);
5398 current_block.AddLocalName (li);
5399 current_variable = new Using.VariableDeclaration ((FullNamedExpression) $3, li);
5401 using_or_fixed_variable_initializer opt_variable_declarators CLOSE_PARENS
5403 $$ = current_variable;
5404 current_variable = null;
5408 if ($10 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5409 Warning_EmptyStatement (GetLocation ($10));
5411 Using u = new Using ((Using.VariableDeclaration) $9, (Statement) $10, GetLocation ($1));
5412 current_block.AddStatement (u);
5413 $$ = end_block (GetLocation ($8));
5415 | USING open_parens_any expression CLOSE_PARENS embedded_statement
5417 if ($5 is EmptyStatement && lexer.peek_token () == Token.OPEN_BRACE)
5418 Warning_EmptyStatement (GetLocation ($5));
5420 Using u = new Using ((Expression) $3, (Statement) $5, GetLocation ($1));
5421 lbag.AddStatement (u, GetLocation ($2), GetLocation ($4));
5426 using_or_fixed_variable_initializer
5429 Report.Error (210, lexer.Location, "You must provide an initializer in a fixed or using statement declaration");
5431 | ASSIGN variable_initializer
5433 current_variable.Initializer = (Expression) $2;
5434 $$ = current_variable;
5442 : first_from_clause query_body
5444 lexer.query_parsing = false;
5446 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5448 from.Tail.Next = (Linq.AQueryClause)$2;
5451 current_block.SetEndLocation (lexer.Location);
5452 current_block = current_block.Parent;
5454 | nested_from_clause query_body
5456 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5458 from.Tail.Next = (Linq.AQueryClause)$2;
5461 current_block.SetEndLocation (lexer.Location);
5462 current_block = current_block.Parent;
5465 // Bubble up COMPLETE_COMPLETION productions
5466 | first_from_clause COMPLETE_COMPLETION {
5467 lexer.query_parsing = false;
5470 current_block.SetEndLocation (lexer.Location);
5471 current_block = current_block.Parent;
5473 | nested_from_clause COMPLETE_COMPLETION {
5475 current_block.SetEndLocation (lexer.Location);
5476 current_block = current_block.Parent;
5481 : FROM_FIRST IDENTIFIER IN expression
5483 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5485 var lt = (Tokenizer.LocatedToken) $2;
5486 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5487 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5489 | FROM_FIRST type IDENTIFIER IN expression
5491 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5493 var lt = (Tokenizer.LocatedToken) $3;
5494 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5495 $$ = new Linq.QueryExpression (
5496 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5497 IdentifierType = (FullNamedExpression)$2
5504 : FROM IDENTIFIER IN expression
5506 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5508 var lt = (Tokenizer.LocatedToken) $2;
5509 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5510 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, rv, GetLocation ($1)));
5512 | FROM type IDENTIFIER IN expression
5514 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5516 var lt = (Tokenizer.LocatedToken) $3;
5517 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5518 $$ = new Linq.QueryExpression (
5519 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, rv, GetLocation ($1)) {
5520 IdentifierType = (FullNamedExpression)$2
5527 : FROM IDENTIFIER IN
5529 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5533 var lt = (Tokenizer.LocatedToken) $2;
5534 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5535 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5537 current_block.SetEndLocation (lexer.Location);
5538 current_block = current_block.Parent;
5540 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5542 | FROM type IDENTIFIER IN
5544 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5548 var lt = (Tokenizer.LocatedToken) $3;
5549 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5551 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5552 IdentifierType = (FullNamedExpression)$2
5555 current_block.SetEndLocation (lexer.Location);
5556 current_block = current_block.Parent;
5558 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5563 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5565 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5568 head.Next = (Linq.AQueryClause)$3;
5571 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5572 clause.Tail.Next = head;
5578 | opt_query_body_clauses COMPLETE_COMPLETION
5581 Error_SyntaxError (yyToken);
5586 select_or_group_clause
5589 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5593 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5595 current_block.SetEndLocation (lexer.Location);
5596 current_block = current_block.Parent;
5600 if (linq_clause_blocks == null)
5601 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5603 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5604 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5608 current_block.SetEndLocation (lexer.Location);
5609 current_block = current_block.Parent;
5611 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5615 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5617 current_block.SetEndLocation (lexer.Location);
5618 current_block = current_block.Parent;
5622 opt_query_body_clauses
5624 | query_body_clauses
5629 | query_body_clauses query_body_clause
5631 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5645 : LET IDENTIFIER ASSIGN
5647 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5651 var lt = (Tokenizer.LocatedToken) $2;
5652 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5653 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5655 current_block.SetEndLocation (lexer.Location);
5656 current_block = current_block.Parent;
5658 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5665 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5669 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5671 current_block.SetEndLocation (lexer.Location);
5672 current_block = current_block.Parent;
5677 : JOIN IDENTIFIER IN
5679 if (linq_clause_blocks == null)
5680 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5682 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5683 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5687 current_block.SetEndLocation (lexer.Location);
5688 current_block = current_block.Parent;
5690 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5691 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5695 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5696 current_block.SetEndLocation (lexer.Location);
5697 current_block = current_block.Parent;
5699 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5701 expression opt_join_into
5703 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5704 current_block.SetEndLocation (lexer.Location);
5706 var outer_selector = linq_clause_blocks.Pop ();
5707 var block = linq_clause_blocks.Pop ();
5709 var lt = (Tokenizer.LocatedToken) $2;
5710 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5711 Linq.RangeVariable into;
5715 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5718 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5720 var parent = block.Parent;
5721 while (parent is Linq.QueryBlock) {
5722 parent = parent.Parent;
5724 current_block.Parent = parent;
5726 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5728 lt = (Tokenizer.LocatedToken) $12;
5729 into = new Linq.RangeVariable (lt.Value, lt.Location);
5731 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1));
5734 current_block = block.Parent;
5735 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5737 | JOIN type IDENTIFIER IN
5739 if (linq_clause_blocks == null)
5740 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5742 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5743 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5747 current_block.SetEndLocation (lexer.Location);
5748 current_block = current_block.Parent;
5750 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5751 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5755 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5756 current_block.SetEndLocation (lexer.Location);
5757 current_block = current_block.Parent;
5759 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5761 expression opt_join_into
5763 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5764 current_block.SetEndLocation (lexer.Location);
5766 var outer_selector = linq_clause_blocks.Pop ();
5767 var block = linq_clause_blocks.Pop ();
5769 var lt = (Tokenizer.LocatedToken) $3;
5770 var sn = new Linq.RangeVariable (lt.Value, lt.Location);
5771 Linq.RangeVariable into;
5775 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5776 IdentifierType = (FullNamedExpression)$2
5780 // Set equals right side parent to beginning of linq query, it is not accessible therefore cannot cause name collisions
5782 var parent = block.Parent;
5783 while (parent is Linq.QueryBlock) {
5784 parent = parent.Parent;
5786 current_block.Parent = parent;
5788 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5790 lt = (Tokenizer.LocatedToken) $13;
5791 into = new Linq.RangeVariable (lt.Value, lt.Location); // TODO:
5793 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, into, GetLocation ($1)) {
5794 IdentifierType = (FullNamedExpression)$2
5798 current_block = block.Parent;
5799 ((Linq.QueryBlock)current_block).AddRangeVariable (into);
5814 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5818 current_block.SetEndLocation (lexer.Location);
5819 current_block = current_block.Parent;
5829 current_block.SetEndLocation (lexer.Location);
5830 current_block = current_block.Parent;
5832 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5836 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5843 | orderings_then_by COMMA
5845 current_block.SetEndLocation (lexer.Location);
5846 current_block = current_block.Parent;
5848 current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
5852 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5860 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5862 | expression ASCENDING
5864 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5866 | expression DESCENDING
5868 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5875 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5877 | expression ASCENDING
5879 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5881 | expression DESCENDING
5883 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5888 opt_query_continuation
5892 // query continuation block is not linked with query block but with block
5893 // before. This means each query can use same range variable names for
5894 // different identifiers.
5896 current_block.SetEndLocation (GetLocation ($1));
5897 current_block = current_block.Parent;
5899 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5901 if (linq_clause_blocks == null)
5902 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5904 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5908 var current_block = linq_clause_blocks.Pop ();
5909 var lt = (Tokenizer.LocatedToken) $2;
5910 var rv = new Linq.RangeVariable (lt.Value, lt.Location);
5911 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, rv, GetLocation ($1)) {
5912 next = (Linq.AQueryClause)$4
5918 // Support for using the compiler as an interactive parser
5920 // The INTERACTIVE_PARSER token is first sent to parse our
5921 // productions; If the result is a Statement, the parsing
5922 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5923 // to setup the blocks in advance.
5925 // This setup is here so that in the future we can add
5926 // support for other constructs (type parsing, namespaces, etc)
5927 // that do not require a block to be setup in advance
5931 : EVAL_STATEMENT_PARSER EOF
5932 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives opt_COMPLETE_COMPLETION
5933 | EVAL_STATEMENT_PARSER {
5934 Evaluator.LoadAliases (current_namespace);
5936 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5937 Modifiers.PUBLIC, null), null);
5939 var baseclass_list = new List<FullNamedExpression> ();
5940 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5941 current_container.AddBasesForPart (current_class, baseclass_list);
5943 // (ref object retval)
5944 Parameter [] mpar = new Parameter [1];
5945 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
5947 ParametersCompiled pars = new ParametersCompiled (mpar);
5948 current_local_parameters = pars;
5949 Method method = new Method (
5952 new TypeExpression (TypeManager.void_type, Location.Null),
5953 Modifiers.PUBLIC | Modifiers.STATIC,
5954 new MemberName ("Host"),
5956 null /* attributes */);
5958 oob_stack.Push (method);
5959 ++lexer.parsing_block;
5960 start_block (lexer.Location);
5962 interactive_statement_list opt_COMPLETE_COMPLETION
5964 --lexer.parsing_block;
5965 Method method = (Method) oob_stack.Pop ();
5967 method.Block = (ToplevelBlock) end_block(lexer.Location);
5968 current_container.AddMethod (method);
5970 --lexer.parsing_declaration;
5971 InteractiveResult = pop_current_class ();
5972 current_local_parameters = null;
5974 | EVAL_COMPILATION_UNIT_PARSER {
5975 Evaluator.LoadAliases (current_namespace);
5977 interactive_compilation_unit
5980 interactive_compilation_unit
5981 : outer_declarations
5982 | outer_declarations global_attributes
5987 opt_COMPLETE_COMPLETION
5989 | COMPLETE_COMPLETION
5992 close_brace_or_complete_completion
5994 | COMPLETE_COMPLETION
5999 // A class used to hold info about an operator declarator
6001 class OperatorDeclaration {
6002 public readonly Operator.OpType optype;
6003 public readonly FullNamedExpression ret_type;
6004 public readonly Location location;
6006 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
6009 this.ret_type = ret_type;
6010 this.location = location;
6014 void Error_ExpectingTypeName (Expression expr)
6016 if (expr is Invocation){
6017 Report.Error (1002, expr.Location, "Expecting `;'");
6019 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
6023 void Error_ParameterModifierNotValid (string modifier, Location loc)
6025 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
6029 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
6031 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
6032 Parameter.GetModifierSignature (mod));
6035 void Error_TypeExpected (Location loc)
6037 Report.Error (1031, loc, "Type expected");
6040 void Error_UnsafeCodeNotAllowed (Location loc)
6042 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
6045 void Warning_EmptyStatement (Location loc)
6047 Report.Warning (642, 3, loc, "Possible mistaken empty statement");
6050 void Error_NamedArgumentExpected (NamedArgument a)
6052 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
6055 void push_current_class (TypeContainer tc, object partial_token)
6057 if (RootContext.EvalMode){
6058 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
6059 undo.AddTypeContainer (current_container, tc);
6062 if (partial_token != null)
6063 current_container = current_container.AddPartial (tc);
6065 current_container = current_container.AddTypeContainer (tc);
6067 ++lexer.parsing_declaration;
6071 DeclSpace pop_current_class ()
6073 DeclSpace retval = current_class;
6075 current_class = current_class.Parent;
6076 current_container = current_class.PartialContainer;
6082 // Given the @class_name name, it creates a fully qualified name
6083 // based on the containing declaration space
6086 MakeName (MemberName class_name)
6088 Namespace ns = current_namespace.NS;
6090 if (current_container == RootContext.ToplevelTypes) {
6091 if (ns.Name.Length != 0)
6092 return new MemberName (ns.MemberName, class_name);
6096 return new MemberName (current_container.MemberName, class_name);
6100 [System.Diagnostics.Conditional ("FULL_AST")]
6101 void StoreModifierLocation (object token, Location loc)
6106 if (mod_locations == null)
6107 mod_locations = new List<Tuple<Modifiers, Location>> ();
6109 mod_locations.Add (Tuple.Create ((Modifiers) token, loc));
6112 string CheckAttributeTarget (string a, Location l)
6115 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6119 Report.Warning (658, 1, l,
6120 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6121 return string.Empty;
6124 static bool IsUnaryOperator (Operator.OpType op)
6128 case Operator.OpType.LogicalNot:
6129 case Operator.OpType.OnesComplement:
6130 case Operator.OpType.Increment:
6131 case Operator.OpType.Decrement:
6132 case Operator.OpType.True:
6133 case Operator.OpType.False:
6134 case Operator.OpType.UnaryPlus:
6135 case Operator.OpType.UnaryNegation:
6141 void syntax_error (Location l, string msg)
6143 Report.Error (1003, l, "Syntax error, " + msg);
6148 public Tokenizer Lexer {
6154 static CSharpParser ()
6156 oob_stack = new Stack<object> ();
6159 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ModuleContainer module)
6161 if (RootContext.EvalMode)
6165 this.module = module;
6166 this.compiler = module.Compiler;
6167 current_namespace = new NamespaceEntry (module, null, file, null);
6168 current_class = current_namespace.SlaveDeclSpace;
6169 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6171 lexer = new Tokenizer (reader, file, compiler);
6173 use_global_stacks = true;
6176 public void parse ()
6178 eof_token = Token.EOF;
6179 Tokenizer.LocatedToken.Initialize ();
6182 if (yacc_verbose_flag > 1)
6183 yyparse (lexer, new yydebug.yyDebugSimple ());
6187 Tokenizer tokenizer = lexer as Tokenizer;
6188 tokenizer.cleanup ();
6189 } catch (Exception e){
6190 if (e is yyParser.yyUnexpectedEof) {
6191 Error_SyntaxError (yyToken);
6192 UnexpectedEOF = true;
6196 if (e is yyParser.yyException) {
6197 Report.Error (-25, lexer.Location, "Parsing error");
6199 // Used by compiler-tester to test internal errors
6200 if (yacc_verbose_flag > 0)
6203 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6207 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6208 throw new InternalErrorException ("who set it?");
6211 void CheckToken (int error, int yyToken, string msg, Location loc)
6213 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6214 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6216 Report.Error (error, loc, msg);
6219 string ConsumeStoredComment ()
6221 string s = tmpComment;
6223 Lexer.doc_state = XmlCommentState.Allowed;
6227 Location GetLocation (object obj)
6229 var lt = obj as Tokenizer.LocatedToken;
6233 var mn = obj as MemberName;
6237 var expr = obj as Expression;
6239 return expr.Location;
6241 return lexer.Location;
6245 get { return compiler.Report; }
6248 public LocationsBag LocationsBag {
6257 void start_block (Location loc)
6259 if (current_block == null) {
6260 current_block = new ToplevelBlock (compiler, current_local_parameters, loc);
6261 parsing_anonymous_method = false;
6262 } else if (parsing_anonymous_method) {
6263 current_block = new ParametersBlock (current_block, current_local_parameters, loc);
6264 parsing_anonymous_method = false;
6266 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6271 end_block (Location loc)
6273 Block retval = current_block.Explicit;
6274 retval.SetEndLocation (loc);
6275 current_block = retval.Parent;
6279 void start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6281 if (RootContext.Version == LanguageVersion.ISO_1){
6282 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6285 oob_stack.Push (current_anonymous_method);
6286 oob_stack.Push (current_local_parameters);
6287 oob_stack.Push (current_variable);
6289 current_local_parameters = parameters;
6291 current_anonymous_method = lambda
6292 ? new LambdaExpression (loc)
6293 : new AnonymousMethodExpression (loc);
6295 // Force the next block to be created as a ToplevelBlock
6296 parsing_anonymous_method = true;
6300 * Completes the anonymous method processing, if lambda_expr is null, this
6301 * means that we have a Statement instead of an Expression embedded
6303 AnonymousMethodExpression end_anonymous (ParametersBlock anon_block)
6305 AnonymousMethodExpression retval;
6307 current_anonymous_method.Block = anon_block;
6308 retval = current_anonymous_method;
6310 current_variable = (BlockVariableDeclaration) oob_stack.Pop ();
6311 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6312 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6317 public NamespaceEntry CurrentNamespace {
6319 return current_namespace;
6323 void Error_SyntaxError (int token)
6325 Error_SyntaxError (0, token, "Unexpected symbol");
6328 void Error_SyntaxError (int error_code, int token, string msg)
6330 // An error message has been reported by tokenizer
6331 if (token == Token.ERROR)
6334 string symbol = GetSymbolName (token);
6335 string expecting = GetExpecting ();
6336 var loc = lexer.Location - symbol.Length;
6338 if (error_code == 0) {
6339 if (expecting == "`identifier'") {
6340 if (token > Token.FIRST_KEYWORD && token < Token.LAST_KEYWORD) {
6341 Report.Error (1041, loc, "Identifier expected, `{0}' is a keyword", symbol);
6346 expecting = "identifier";
6347 } else if (expecting == "`)'") {
6354 if (string.IsNullOrEmpty (expecting))
6355 Report.Error (error_code, loc, "{1} `{0}'", symbol, msg);
6357 Report.Error (error_code, loc, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6360 string GetExpecting ()
6362 int [] tokens = yyExpectingTokens (yyExpectingState);
6363 var names = new List<string> (tokens.Length);
6364 bool has_type = false;
6365 bool has_identifier = false;
6366 for (int i = 0; i < tokens.Length; i++){
6367 int token = tokens [i];
6368 has_identifier |= token == Token.IDENTIFIER;
6370 string name = GetTokenName (token);
6371 if (name == "<internal>")
6374 has_type |= name == "type";
6375 if (names.Contains (name))
6382 // Too many tokens to enumerate
6384 if (names.Count > 8)
6387 if (has_type && has_identifier)
6388 names.Remove ("identifier");
6390 if (names.Count == 1)
6391 return "`" + GetTokenName (tokens [0]) + "'";
6393 StringBuilder sb = new StringBuilder ();
6395 int count = names.Count;
6396 for (int i = 0; i < count; i++){
6397 bool last = i + 1 == count;
6401 sb.Append (names [i]);
6402 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6404 return sb.ToString ();
6408 string GetSymbolName (int token)
6412 return ((Constant)lexer.Value).GetValue ().ToString ();
6413 case Token.IDENTIFIER:
6414 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6456 case Token.BITWISE_AND:
6458 case Token.BITWISE_OR:
6472 case Token.OP_SHIFT_LEFT:
6474 case Token.OP_SHIFT_RIGHT:
6494 case Token.OP_COALESCING:
6496 case Token.OP_MULT_ASSIGN:
6498 case Token.OP_DIV_ASSIGN:
6500 case Token.OP_MOD_ASSIGN:
6502 case Token.OP_ADD_ASSIGN:
6504 case Token.OP_SUB_ASSIGN:
6506 case Token.OP_SHIFT_LEFT_ASSIGN:
6508 case Token.OP_SHIFT_RIGHT_ASSIGN:
6510 case Token.OP_AND_ASSIGN:
6512 case Token.OP_XOR_ASSIGN:
6514 case Token.OP_OR_ASSIGN:
6518 return GetTokenName (token);
6521 static string GetTokenName (int token)
6524 case Token.ABSTRACT:
6546 case Token.CONTINUE:
6550 case Token.DELEGATE:
6560 case Token.EXPLICIT:
6578 case Token.IMPLICIT:
6582 case Token.INTERFACE:
6584 case Token.INTERNAL:
6590 case Token.NAMESPACE:
6596 case Token.OPERATOR:
6600 case Token.OVERRIDE:
6606 case Token.PROTECTED:
6610 case Token.READONLY:
6622 case Token.STACKALLOC:
6623 return "stackalloc";
6640 case Token.UNCHECKED:
6648 case Token.VOLATILE:
6661 case Token.FROM_FIRST:
6679 case Token.ASCENDING:
6681 case Token.DESCENDING:
6682 return "descending";
6689 case Token.OPEN_BRACE:
6691 case Token.CLOSE_BRACE:
6693 case Token.OPEN_BRACKET:
6694 case Token.OPEN_BRACKET_EXPR:
6696 case Token.CLOSE_BRACKET:
6698 case Token.OPEN_PARENS_CAST:
6699 case Token.OPEN_PARENS_LAMBDA:
6700 case Token.OPEN_PARENS:
6702 case Token.CLOSE_PARENS:
6708 case Token.DEFAULT_COLON:
6712 case Token.SEMICOLON:
6723 case Token.BITWISE_AND:
6724 case Token.BITWISE_OR:
6731 case Token.OP_SHIFT_LEFT:
6732 case Token.OP_SHIFT_RIGHT:
6740 case Token.OP_COALESCING:
6741 case Token.OP_MULT_ASSIGN:
6742 case Token.OP_DIV_ASSIGN:
6743 case Token.OP_MOD_ASSIGN:
6744 case Token.OP_ADD_ASSIGN:
6745 case Token.OP_SUB_ASSIGN:
6746 case Token.OP_SHIFT_LEFT_ASSIGN:
6747 case Token.OP_SHIFT_RIGHT_ASSIGN:
6748 case Token.OP_AND_ASSIGN:
6749 case Token.OP_XOR_ASSIGN:
6750 case Token.OP_OR_ASSIGN:
6751 return "<operator>";
6773 case Token.OP_GENERICS_LT:
6774 case Token.GENERIC_DIMENSION:
6776 case Token.OP_GENERICS_GT:
6779 case Token.INTERR_NULLABLE:
6781 case Token.DOUBLE_COLON:
6785 case Token.IDENTIFIER:
6786 return "identifier";
6789 return "end-of-file";
6791 // All of these are internal.
6794 case Token.FIRST_KEYWORD:
6795 case Token.EVAL_COMPILATION_UNIT_PARSER:
6796 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6797 case Token.EVAL_STATEMENT_PARSER:
6798 case Token.LAST_KEYWORD:
6799 case Token.GENERATE_COMPLETION:
6800 case Token.COMPLETE_COMPLETION:
6801 return "<internal>";
6803 // A bit more robust.
6805 return yyNames [token];