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;
54 /// Current block is used to add statements as we find
59 Delegate current_delegate;
61 AnonymousMethodExpression current_anonymous_method;
64 /// This is used by the unary_expression code to resolve
65 /// a name against a parameter.
68 // FIXME: This is very ugly and it's very hard to reset it correctly
69 // on all places, especially when some parameters are autogenerated.
70 ParametersCompiled current_local_parameters;
72 bool parsing_anonymous_method;
75 /// An out-of-band stack.
77 static Stack<object> oob_stack;
82 Stack<Block> switch_stack;
85 /// Controls the verbosity of the errors produced by the parser
87 static public int yacc_verbose_flag;
90 /// Used by the interactive shell, flags whether EOF was reached
91 /// and an error was produced
93 public bool UnexpectedEOF;
101 /// Temporary Xml documentation cache.
102 /// For enum types, we need one more temporary store.
105 string enumTypeComment;
107 /// Current attribute target
108 string current_attr_target;
110 /// assembly and module attribute definitions are enabled
111 bool global_attrs_enabled = true;
113 ParameterModifierType valid_param_mod;
115 bool default_parameter_used;
117 /// When using the interactive parser, this holds the
118 /// resulting expression
119 public object InteractiveResult;
122 // Keeps track of global data changes to undo on parser error
126 Stack<Linq.QueryBlock> linq_clause_blocks;
128 // A counter to create new class names in interactive mode
129 static int class_count;
131 CompilerContext compiler;
134 // Instead of allocating carrier array everytime we
135 // share the bucket for very common constructs which can never
138 static List<Parameter> parameters_bucket = new List<Parameter> (6);
139 static List<object> variables_bucket = new List<object> (6);
143 %token NONE /* This token is never returned by our lexer */
144 %token ERROR // This is used not by the parser, but by the tokenizer.
148 *These are the C# keywords
247 %token INTERR_NULLABLE
250 /* Generics <,> tokens */
251 %token OP_GENERICS_LT
252 %token OP_GENERICS_LT_DECL
253 %token OP_GENERICS_GT
255 /* C# keywords which are not really keywords */
261 /* C# single character operators/punctuation. */
289 /* C# multi-character operators. */
294 %token OP_SHIFT_RIGHT
301 %token OP_MULT_ASSIGN
306 %token OP_SHIFT_LEFT_ASSIGN
307 %token OP_SHIFT_RIGHT_ASSIGN
317 %token OPEN_PARENS_LAMBDA
318 %token OPEN_PARENS_CAST
319 %token GENERIC_DIMENSION
321 %token OPEN_BRACKET_EXPR
323 // Make the parser go into eval mode parsing (statements and compilation units).
324 %token EVAL_STATEMENT_PARSER
325 %token EVAL_COMPILATION_UNIT_PARSER
326 %token EVAL_USING_DECLARATIONS_UNIT_PARSER
329 // This token is generated to trigger the completion engine at this point
331 %token GENERATE_COMPLETION
334 // This token is return repeatedly after the first GENERATE_COMPLETION
335 // token is produced and before the final EOF
337 %token COMPLETE_COMPLETION
339 /* Add precedence rules to solve dangling else s/r conflict */
343 /* Define the operator tokens and their precedences */
351 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
353 %left STAR DIV PERCENT
354 %right BANG CARRET UMINUS
355 %nonassoc OP_INC OP_DEC
357 %left OPEN_BRACKET OPEN_BRACE
360 %start compilation_unit
364 : outer_declarations opt_EOF
365 | outer_declarations global_attributes opt_EOF
366 | global_attributes opt_EOF
367 | opt_EOF /* allow empty files */
368 | interactive_parsing { Lexer.CompleteOnEOF = false; } opt_EOF
374 Lexer.check_incorrect_doc_comment ();
378 Lexer.check_incorrect_doc_comment ();
384 | outer_declarations outer_declaration
388 : extern_alias_directive
390 | namespace_member_declaration
393 extern_alias_directives
394 : extern_alias_directive
395 | extern_alias_directives extern_alias_directive
398 extern_alias_directive
399 : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON
401 var lt = (Tokenizer.LocatedToken) $2;
404 syntax_error (lt.Location, "`alias' expected");
405 } else if (RootContext.Version == LanguageVersion.ISO_1) {
406 Report.FeatureIsNotAvailable (lt.Location, "external alias");
408 lt = (Tokenizer.LocatedToken) $3;
409 current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report);
414 syntax_error (GetLocation ($1), "`alias' expected"); // TODO: better
420 | using_directives using_directive
424 : using_alias_directive
426 if (RootContext.Documentation != null)
427 Lexer.doc_state = XmlCommentState.Allowed;
429 | using_namespace_directive
431 if (RootContext.Documentation != null)
432 Lexer.doc_state = XmlCommentState.Allowed;
436 using_alias_directive
437 : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON
439 var lt = (Tokenizer.LocatedToken) $2;
440 current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1));
443 CheckIdentifierToken (yyToken, GetLocation ($2));
448 using_namespace_directive
449 : USING namespace_name SEMICOLON
451 current_namespace.AddUsing ((MemberName) $2, GetLocation ($1));
456 // Strictly speaking, namespaces don't have attributes but
457 // we parse global attributes along with namespace declarations and then
460 namespace_declaration
461 : opt_attributes NAMESPACE qualified_identifier
463 MemberName name = (MemberName) $3;
466 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
469 current_namespace = new NamespaceEntry (
470 current_namespace, file, name.GetName ());
471 current_class = current_namespace.SlaveDeclSpace;
472 current_container = current_class.PartialContainer;
474 namespace_body opt_semicolon
476 current_namespace = current_namespace.Parent;
477 current_class = current_namespace.SlaveDeclSpace;
478 current_container = current_class.PartialContainer;
485 var lt = (Tokenizer.LocatedToken) $1;
486 $$ = new MemberName (lt.Value, lt.Location);
488 | qualified_identifier DOT IDENTIFIER
490 var lt = (Tokenizer.LocatedToken) $3;
491 $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location);
495 syntax_error (lexer.Location, "`.' expected");
496 $$ = new MemberName ("<invalid>", lexer.Location);
511 : namespace_or_type_name
513 MemberName name = (MemberName) $1;
515 if (name.TypeArguments != null)
516 syntax_error (lexer.Location, "namespace name expected");
525 if (RootContext.Documentation != null)
526 Lexer.doc_state = XmlCommentState.Allowed;
532 : opt_extern_alias_directives
534 opt_namespace_member_declarations
538 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
541 | opt_extern_alias_directives
543 opt_namespace_member_declarations
546 Report.Error (1513, lexer.Location, "Expected `}'");
555 opt_extern_alias_directives
557 | extern_alias_directives
560 opt_namespace_member_declarations
562 | namespace_member_declarations
565 namespace_member_declarations
566 : namespace_member_declaration
567 | namespace_member_declarations namespace_member_declaration
570 namespace_member_declaration
574 DeclSpace ds = (DeclSpace)$1;
576 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
577 Report.Error (1527, ds.Location,
578 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
581 current_namespace.DeclarationFound = true;
583 | namespace_declaration {
584 current_namespace.DeclarationFound = true;
587 | field_declaration {
588 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
590 | method_declaration {
591 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
598 | interface_declaration
600 | delegate_declaration
602 // Enable this when we have handled all errors, because this acts as a generic fallback
605 // Console.WriteLine ("Token=" + yyToken);
606 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
618 Attributes attrs = (Attributes)$1;
619 if (global_attrs_enabled) {
620 CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace);
622 foreach (Attribute a in attrs.Attrs) {
623 Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations");
634 global_attrs_enabled = false;
639 global_attrs_enabled = false;
648 if (current_attr_target != String.Empty) {
649 var sect = (List<Attribute>) $1;
651 if (global_attrs_enabled) {
652 if (current_attr_target == "module") {
653 current_container.Module.Compiled.AddAttributes (sect);
655 } else if (current_attr_target != null && current_attr_target.Length > 0) {
656 CodeGen.Assembly.AddAttributes (sect, current_namespace);
659 $$ = new Attributes (sect);
662 if (RootContext.Documentation != null) {
663 Lexer.check_incorrect_doc_comment ();
665 XmlCommentState.Allowed;
669 $$ = new Attributes (sect);
674 current_attr_target = null;
676 | attribute_sections attribute_section
678 if (current_attr_target != String.Empty) {
679 Attributes attrs = $1 as Attributes;
680 var sect = (List<Attribute>) $2;
682 if (global_attrs_enabled) {
683 if (current_attr_target == "module") {
684 current_container.Module.Compiled.AddAttributes (sect);
686 } else if (current_attr_target == "assembly") {
687 CodeGen.Assembly.AddAttributes (sect, current_namespace);
691 attrs = new Attributes (sect);
693 attrs.AddAttributes (sect);
697 attrs = new Attributes (sect);
699 attrs.AddAttributes (sect);
705 current_attr_target = null;
710 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
714 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
720 attribute_target_specifier
721 : attribute_target COLON
723 current_attr_target = (string)$1;
731 var lt = (Tokenizer.LocatedToken) $1;
732 $$ = CheckAttributeTarget (lt.Value, lt.Location);
734 | EVENT { $$ = "event"; }
735 | RETURN { $$ = "return"; }
738 string name = GetTokenName (yyToken);
739 $$ = CheckAttributeTarget (name, GetLocation ($1));
746 $$ = new List<Attribute> (4) { (Attribute) $1 };
748 | attribute_list COMMA attribute
750 var attrs = (List<Attribute>) $1;
751 attrs.Add ((Attribute) $3);
760 ++lexer.parsing_block;
762 opt_attribute_arguments
764 --lexer.parsing_block;
765 MemberName mname = (MemberName) $1;
766 if (mname.IsGeneric) {
767 Report.Error (404, lexer.Location,
768 "'<' unexpected: attributes cannot be generic");
771 Arguments [] arguments = (Arguments []) $3;
772 ATypeNameExpression expr = mname.GetTypeExpression ();
774 if (current_attr_target == String.Empty)
776 else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module"))
777 // FIXME: supply "nameEscaped" parameter here.
778 $$ = new GlobalAttribute (current_namespace, current_attr_target,
779 expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
781 $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
786 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
789 opt_attribute_arguments
790 : /* empty */ { $$ = null; }
791 | OPEN_PARENS attribute_arguments CLOSE_PARENS
799 : /* empty */ { $$ = null; }
800 | positional_or_named_argument
802 Arguments a = new Arguments (4);
803 a.Add ((Argument) $1);
804 $$ = new Arguments [] { a, null };
806 | named_attribute_argument
808 Arguments a = new Arguments (4);
809 a.Add ((Argument) $1);
810 $$ = new Arguments [] { null, a };
812 | attribute_arguments COMMA positional_or_named_argument
814 Arguments[] o = (Arguments[]) $1;
816 Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments");
817 o [0] = new Arguments (4);
820 Arguments args = ((Arguments) o [0]);
821 if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument)
822 Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]);
824 args.Add ((Argument) $3);
826 | attribute_arguments COMMA named_attribute_argument
828 Arguments[] o = (Arguments[]) $1;
830 o [1] = new Arguments (4);
833 ((Arguments) o [1]).Add ((Argument) $3);
837 positional_or_named_argument
840 $$ = new Argument ((Expression) $1);
845 named_attribute_argument
848 ++lexer.parsing_block;
852 --lexer.parsing_block;
853 var lt = (Tokenizer.LocatedToken) $1;
854 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4);
859 : IDENTIFIER COLON opt_named_modifier expression
861 if (RootContext.Version <= LanguageVersion.V_3)
862 Report.FeatureIsNotAvailable (GetLocation ($1), "named argument");
864 // Avoid boxing in common case (no modifier)
865 var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3;
867 var lt = (Tokenizer.LocatedToken) $1;
868 $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod);
873 : /* empty */ { $$ = null; }
876 $$ = Argument.AType.Ref;
880 $$ = Argument.AType.Out;
884 opt_class_member_declarations
886 | class_member_declarations
889 class_member_declarations
890 : class_member_declaration
891 | class_member_declarations
892 class_member_declaration
895 class_member_declaration
896 : constant_declaration // done
897 | field_declaration // done
898 | method_declaration // done
899 | property_declaration // done
900 | event_declaration // done
901 | indexer_declaration // done
902 | operator_declaration // done
903 | constructor_declaration // done
904 | destructor_declaration // done
908 Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
909 GetSymbolName (yyToken));
911 lexer.parsing_generic_declaration = false;
921 lexer.ConstraintsParsing = true;
923 type_declaration_name
925 MemberName name = MakeName ((MemberName) $6);
926 push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
929 opt_type_parameter_constraints_clauses
931 lexer.ConstraintsParsing = false;
933 current_class.SetParameterInfo ((List<Constraints>) $9);
935 if (RootContext.Documentation != null)
936 current_container.DocComment = Lexer.consume_doc_comment ();
940 --lexer.parsing_declaration;
941 if (RootContext.Documentation != null)
942 Lexer.doc_state = XmlCommentState.Allowed;
946 $$ = pop_current_class ();
948 | opt_attributes opt_modifiers opt_partial STRUCT error {
949 CheckIdentifierToken (yyToken, GetLocation ($5));
956 if (RootContext.Documentation != null)
957 Lexer.doc_state = XmlCommentState.Allowed;
959 opt_struct_member_declarations CLOSE_BRACE
962 opt_struct_member_declarations
964 | struct_member_declarations
967 struct_member_declarations
968 : struct_member_declaration
969 | struct_member_declarations struct_member_declaration
972 struct_member_declaration
973 : constant_declaration
976 | property_declaration
978 | indexer_declaration
979 | operator_declaration
980 | constructor_declaration
984 * This is only included so we can flag error 575:
985 * destructors only allowed on class types
987 | destructor_declaration
998 var modflags = (Modifiers) $2;
999 foreach (VariableDeclaration constant in (List<object>) $5){
1000 Location l = constant.Location;
1001 if ((modflags & Modifiers.STATIC) != 0) {
1002 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + "." + (string) constant.identifier);
1006 Const c = new Const (
1007 current_class, (FullNamedExpression) $4, (string) constant.identifier,
1008 constant.GetInitializer ((FullNamedExpression) $4), modflags,
1009 (Attributes) $1, l);
1011 if (RootContext.Documentation != null) {
1012 c.DocComment = Lexer.consume_doc_comment ();
1013 Lexer.doc_state = XmlCommentState.Allowed;
1015 current_container.AddConstant (c);
1020 constant_declarators
1021 : constant_declarator
1023 variables_bucket.Clear ();
1025 variables_bucket.Add ($1);
1026 $$ = variables_bucket;
1028 | constant_declarators COMMA constant_declarator
1031 var constants = (List<object>) $1;
1040 ++lexer.parsing_block;
1042 constant_initializer
1044 --lexer.parsing_block;
1045 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $4);
1049 // A const field requires a value to be provided
1050 Report.Error (145, GetLocation ($1), "A const field requires a value to be provided");
1055 constant_initializer
1056 : constant_expression
1064 variable_declarators
1067 FullNamedExpression type = (FullNamedExpression) $3;
1068 if (type.Type == TypeManager.void_type)
1069 Report.Error (670, GetLocation ($3), "Fields cannot have void type");
1071 var mod = (Modifiers) $2;
1073 foreach (VariableMemberDeclaration var in (List<object>) $4){
1074 Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
1076 field.Initializer = var.GetInitializer (type);
1078 if (RootContext.Documentation != null) {
1079 field.DocComment = Lexer.consume_doc_comment ();
1080 Lexer.doc_state = XmlCommentState.Allowed;
1082 current_container.AddField (field);
1083 $$ = field; // FIXME: might be better if it points to the top item
1089 fixed_variable_declarators
1092 FullNamedExpression type = (FullNamedExpression) $4;
1093 var mod = (Modifiers) $2;
1095 if (RootContext.Version < LanguageVersion.ISO_2)
1096 Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers");
1098 foreach (VariableDeclaration var in (List<VariableDeclaration>) $5) {
1099 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1100 var.GetInitializer (type), (Attributes) $1, var.Location);
1102 if (RootContext.Documentation != null) {
1103 field.DocComment = Lexer.consume_doc_comment ();
1104 Lexer.doc_state = XmlCommentState.Allowed;
1106 current_container.AddField (field);
1107 $$ = field; // FIXME: might be better if it points to the top item
1116 Report.Error (1641, GetLocation ($5), "A fixed size buffer field must have the array size specifier after the field name");
1120 fixed_variable_declarators
1121 : fixed_variable_declarator
1123 var decl = new List<VariableDeclaration> (2);
1124 decl.Add ((VariableDeclaration)$1);
1127 | fixed_variable_declarators COMMA fixed_variable_declarator
1129 var decls = (List<VariableDeclaration>) $1;
1130 decls.Add ((VariableDeclaration)$3);
1135 fixed_variable_declarator
1136 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1138 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
1140 | IDENTIFIER OPEN_BRACKET error
1142 Report.Error (443, lexer.Location, "Value or constant expected");
1143 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null);
1148 local_variable_declarators
1149 : local_variable_declarator
1151 variables_bucket.Clear ();
1153 variables_bucket.Add ($1);
1154 $$ = variables_bucket;
1156 | local_variable_declarators COMMA local_variable_declarator
1158 var decls = (List<object>) $1;
1164 local_variable_declarator
1165 : IDENTIFIER ASSIGN local_variable_initializer
1167 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
1171 $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null);
1173 | IDENTIFIER variable_bad_array
1179 local_variable_initializer
1182 | STACKALLOC simple_type OPEN_BRACKET_EXPR expression CLOSE_BRACKET
1184 $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1));
1188 $$ = new ArglistAccess (GetLocation ($1));
1190 | STACKALLOC simple_type
1192 Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
1193 $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
1197 variable_declarators
1198 : variable_declarator
1200 variables_bucket.Clear ();
1202 variables_bucket.Add ($1);
1203 $$ = variables_bucket;
1205 | variable_declarators COMMA variable_declarator
1207 var decls = (List<object>) $1;
1214 : member_declaration_name ASSIGN
1216 ++lexer.parsing_block;
1217 lexer.parsing_generic_declaration = false;
1219 variable_initializer
1221 --lexer.parsing_block;
1222 $$ = new VariableMemberDeclaration ((MemberName) $1, (Expression) $4);
1224 | member_declaration_name
1226 lexer.parsing_generic_declaration = false;
1227 $$ = new VariableMemberDeclaration ((MemberName) $1, null);
1229 | member_declaration_name variable_bad_array
1231 lexer.parsing_generic_declaration = false;
1237 : OPEN_BRACKET_EXPR opt_expression CLOSE_BRACKET
1239 Report.Error (650, GetLocation ($1), "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1240 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1244 variable_initializer
1251 if (RootContext.Documentation != null)
1252 Lexer.doc_state = XmlCommentState.NotAllowed;
1256 Method method = (Method) $1;
1257 method.Block = (ToplevelBlock) $3;
1258 current_container.AddMethod (method);
1260 if (current_container.Kind == MemberKind.Interface && method.Block != null) {
1261 Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ());
1264 current_local_parameters = null;
1266 if (RootContext.Documentation != null)
1267 Lexer.doc_state = XmlCommentState.Allowed;
1275 method_declaration_name OPEN_PARENS
1277 valid_param_mod = ParameterModifierType.All;
1279 opt_formal_parameter_list CLOSE_PARENS
1281 lexer.ConstraintsParsing = true;
1283 opt_type_parameter_constraints_clauses
1285 lexer.ConstraintsParsing = false;
1286 valid_param_mod = 0;
1287 MemberName name = (MemberName) $4;
1288 current_local_parameters = (ParametersCompiled) $7;
1290 GenericMethod generic = null;
1291 if (name.TypeArguments != null) {
1292 generic = new GenericMethod (current_namespace, current_class, name,
1293 (FullNamedExpression) $3, current_local_parameters);
1295 generic.SetParameterInfo ((List<Constraints>) $10);
1296 } else if ($10 != null) {
1297 Report.Error (80, GetLocation ($10),
1298 "Constraints are not allowed on non-generic declarations");
1301 Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2,
1302 name, current_local_parameters, (Attributes) $1);
1304 if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
1305 Report.Error (460, method.Location,
1306 "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
1307 method.GetSignatureForError ());
1310 if (RootContext.Documentation != null)
1311 method.DocComment = Lexer.consume_doc_comment ();
1318 VOID method_declaration_name
1321 valid_param_mod = ParameterModifierType.All;
1323 opt_formal_parameter_list CLOSE_PARENS
1325 lexer.ConstraintsParsing = true;
1327 opt_type_parameter_constraints_clauses
1329 lexer.ConstraintsParsing = false;
1330 valid_param_mod = 0;
1332 MemberName name = (MemberName) $5;
1333 current_local_parameters = (ParametersCompiled) $8;
1335 if ($10 != null && name.TypeArguments == null)
1336 Report.Error (80, lexer.Location,
1337 "Constraints are not allowed on non-generic declarations");
1340 GenericMethod generic = null;
1341 if (name.TypeArguments != null) {
1342 generic = new GenericMethod (current_namespace, current_class, name,
1343 new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1344 current_local_parameters);
1346 generic.SetParameterInfo ((List<Constraints>) $11);
1349 var modifiers = (Modifiers) $2;
1352 const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
1353 Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
1355 if ((modifiers & invalid_partial_mod) != 0) {
1356 Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
1357 "any of abstract, extern, new, override, sealed, or virtual modifiers");
1358 modifiers &= ~invalid_partial_mod;
1361 if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
1362 Report.Error (751, name.Location, "A partial method must be declared within a " +
1363 "partial class or partial struct");
1366 modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
1368 method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation ($4)),
1369 modifiers, name, current_local_parameters, (Attributes) $1);
1371 if (RootContext.Documentation != null)
1372 method.DocComment = Lexer.consume_doc_comment ();
1379 modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1381 MemberName name = (MemberName) $5;
1382 Report.Error (1585, name.Location,
1383 "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4));
1385 Method method = new Method (current_class, null, (FullNamedExpression) $3,
1386 0, name, (ParametersCompiled) $7, (Attributes) $1);
1388 current_local_parameters = (ParametersCompiled) $7;
1390 if (RootContext.Documentation != null)
1391 method.DocComment = Lexer.consume_doc_comment ();
1399 | SEMICOLON { $$ = null; }
1402 opt_formal_parameter_list
1403 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
1404 | formal_parameter_list
1407 formal_parameter_list
1410 var pars_list = (List<Parameter>) $1;
1411 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
1413 | fixed_parameters COMMA parameter_array
1415 var pars_list = (List<Parameter>) $1;
1416 pars_list.Add ((Parameter) $3);
1418 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
1420 | fixed_parameters COMMA arglist_modifier
1422 var pars_list = (List<Parameter>) $1;
1423 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1424 $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
1426 | parameter_array COMMA error
1429 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1431 $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
1433 | fixed_parameters COMMA parameter_array COMMA error
1436 Report.Error (231, ((Parameter) $3).Location, "A params 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 (compiler, pars_list.ToArray (), true);
1443 | arglist_modifier COMMA error
1445 Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list");
1447 $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1449 | fixed_parameters COMMA ARGLIST COMMA error
1451 Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
1453 var pars_list = (List<Parameter>) $1;
1454 pars_list.Add (new ArglistParameter (GetLocation ($3)));
1456 $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
1460 $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } );
1464 $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true);
1471 parameters_bucket.Clear ();
1472 Parameter p = (Parameter) $1;
1473 parameters_bucket.Add (p);
1475 default_parameter_used = p.HasDefaultValue;
1476 $$ = parameters_bucket;
1478 | fixed_parameters COMMA fixed_parameter
1480 var pars = (List<Parameter>) $1;
1481 Parameter p = (Parameter) $3;
1483 if (p.HasExtensionMethodModifier)
1484 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1485 else if (!p.HasDefaultValue && default_parameter_used)
1486 Report.Error (1737, p.Location, "Optional parameter cannot precede required parameters");
1488 default_parameter_used |= p.HasDefaultValue;
1497 opt_parameter_modifier
1501 var lt = (Tokenizer.LocatedToken) $4;
1502 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1505 opt_parameter_modifier
1507 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1509 var lt = (Tokenizer.LocatedToken) $4;
1510 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1511 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1514 opt_parameter_modifier
1518 Location l = GetLocation ($4);
1519 CheckIdentifierToken (yyToken, l);
1520 $$ = new Parameter ((FullNamedExpression) $3, "NeedSomeGeneratorHere", (Parameter.Modifier) $2, (Attributes) $1, l);
1523 opt_parameter_modifier
1528 ++lexer.parsing_block;
1532 --lexer.parsing_block;
1533 if (RootContext.Version <= LanguageVersion.V_3) {
1534 Report.FeatureIsNotAvailable (GetLocation ($5), "optional parameter");
1537 Parameter.Modifier mod = (Parameter.Modifier) $2;
1538 if (mod != Parameter.Modifier.NONE) {
1540 case Parameter.Modifier.REF:
1541 case Parameter.Modifier.OUT:
1542 Report.Error (1741, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1543 Parameter.GetModifierSignature (mod));
1546 case Parameter.Modifier.This:
1547 Report.Error (1743, GetLocation ($2), "Cannot specify a default value for the `{0}' parameter",
1548 Parameter.GetModifierSignature (mod));
1551 throw new NotImplementedException (mod.ToString ());
1554 mod = Parameter.Modifier.NONE;
1557 if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0)
1558 Report.Error (1065, GetLocation ($5), "Optional parameter is not valid in this context");
1560 var lt = (Tokenizer.LocatedToken) $4;
1561 $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location);
1563 ((Parameter) $$).DefaultValue = (Expression) $7;
1567 opt_parameter_modifier
1568 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1569 | parameter_modifiers
1573 : parameter_modifier
1577 | parameter_modifiers parameter_modifier
1579 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1580 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1581 if (((Parameter.Modifier)$1 & p2) == p2) {
1582 Error_DuplicateParameterModifier (lexer.Location, p2);
1584 switch (mod & ~Parameter.Modifier.This) {
1585 case Parameter.Modifier.REF:
1586 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1588 case Parameter.Modifier.OUT:
1589 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1592 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1603 if ((valid_param_mod & ParameterModifierType.Ref) == 0)
1604 Error_ParameterModifierNotValid ("ref", GetLocation ($1));
1606 $$ = Parameter.Modifier.REF;
1610 if ((valid_param_mod & ParameterModifierType.Out) == 0)
1611 Error_ParameterModifierNotValid ("out", GetLocation ($1));
1613 $$ = Parameter.Modifier.OUT;
1617 if ((valid_param_mod & ParameterModifierType.This) == 0)
1618 Error_ParameterModifierNotValid ("this", GetLocation ($1));
1620 if (RootContext.Version <= LanguageVersion.ISO_2)
1621 Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods");
1623 $$ = Parameter.Modifier.This;
1628 : opt_attributes params_modifier type IDENTIFIER
1630 var lt = (Tokenizer.LocatedToken) $4;
1631 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1633 | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression
1635 Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array");
1637 var lt = (Tokenizer.LocatedToken) $4;
1638 $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location);
1640 | opt_attributes params_modifier type error {
1641 CheckIdentifierToken (yyToken, GetLocation ($4));
1649 if ((valid_param_mod & ParameterModifierType.Params) == 0)
1650 Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context");
1652 | PARAMS parameter_modifier
1654 Parameter.Modifier mod = (Parameter.Modifier)$2;
1655 if ((mod & Parameter.Modifier.This) != 0) {
1656 Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether");
1658 Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out");
1661 | PARAMS params_modifier
1663 Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS);
1670 if ((valid_param_mod & ParameterModifierType.Arglist) == 0)
1671 Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context");
1675 property_declaration
1679 member_declaration_name
1681 if (RootContext.Documentation != null)
1682 tmpComment = Lexer.consume_doc_comment ();
1686 current_property = new Property (current_class, (FullNamedExpression) $3, (Modifiers) $2,
1687 (MemberName) $4, (Attributes) $1);
1689 if (current_property.TypeExpression.Type == TypeManager.void_type)
1690 Report.Error (547, GetLocation ($3), "`{0}': property or indexer cannot have void type", current_property.GetSignatureForError ());
1692 current_container.AddProperty ((Property)current_property);
1694 lexer.PropertyParsing = true;
1696 accessor_declarations
1698 lexer.PropertyParsing = false;
1700 if (RootContext.Documentation != null)
1701 current_property.DocComment = ConsumeStoredComment ();
1703 current_property = null;
1710 : opt_attributes opt_modifiers
1711 member_type indexer_declaration_name OPEN_BRACKET
1713 valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
1715 opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE
1717 valid_param_mod = 0;
1719 Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3,
1720 (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1);
1722 current_property = indexer;
1724 current_container.AddIndexer (indexer);
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 current_property = null;
1754 accessor_declarations
1755 : get_accessor_declaration
1756 | get_accessor_declaration accessor_declarations
1757 | set_accessor_declaration
1758 | set_accessor_declaration accessor_declarations
1761 if (yyToken == Token.CLOSE_BRACE) {
1762 Report.Error (548, lexer.Location, "`{0}': property or indexer must have at least one accessor", current_property.GetSignatureForError ());
1764 if (yyToken == Token.SEMICOLON)
1765 Report.Error (1597, lexer.Location, "Semicolon after method or accessor block is not valid");
1767 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1772 get_accessor_declaration
1773 : opt_attributes opt_modifiers GET
1775 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1776 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1779 if (current_property.Get != null) {
1780 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1783 if (current_property is Indexer) {
1784 current_property.Get = new Indexer.GetIndexerMethod (current_property, (Modifiers) $2, ((Indexer)current_property).ParameterInfo.Clone (),
1785 (Attributes) $1, GetLocation ($3));
1787 current_property.Get = new Property.GetMethod (current_property,
1788 (Modifiers) $2, (Attributes) $1, GetLocation ($3));
1791 current_local_parameters = current_property.Get.ParameterInfo;
1792 lexer.PropertyParsing = false;
1797 current_property.Get.Block = (ToplevelBlock) $5;
1799 if (current_container.Kind == MemberKind.Interface) {
1800 Report.Error (531, current_property.Get.Block.StartLocation,
1801 "`{0}': interface members cannot have a definition", current_property.Get.GetSignatureForError ());
1805 current_local_parameters = null;
1806 lexer.PropertyParsing = true;
1808 if (RootContext.Documentation != null)
1809 if (Lexer.doc_state == XmlCommentState.Error)
1810 Lexer.doc_state = XmlCommentState.NotAllowed;
1814 set_accessor_declaration
1815 : opt_attributes opt_modifiers SET
1817 if ($2 != ModifierNone && RootContext.Version == LanguageVersion.ISO_1) {
1818 Report.FeatureIsNotAvailable (GetLocation ($2), "access modifiers on properties");
1821 if (current_property.Set != null) {
1822 Report.Error (1007, GetLocation ($3), "Property accessor already defined");
1825 if (current_property is Indexer) {
1826 current_property.Set = new Indexer.SetIndexerMethod (current_property, (Modifiers) $2,
1827 ParametersCompiled.MergeGenerated (compiler,
1828 ((Indexer)current_property).ParameterInfo, true, new Parameter (
1829 current_property.TypeExpression, "value", Parameter.Modifier.NONE, null, GetLocation ($3)),
1831 (Attributes) $1, GetLocation ($3));
1833 current_property.Set = new Property.SetMethod (current_property, (Modifiers) $2,
1834 ParametersCompiled.CreateImplicitParameter (current_property.TypeExpression, GetLocation ($3)),
1835 (Attributes) $1, GetLocation ($3));
1838 current_local_parameters = current_property.Set.ParameterInfo;
1839 lexer.PropertyParsing = false;
1844 current_property.Set.Block = (ToplevelBlock) $5;
1846 if (current_container.Kind == MemberKind.Interface) {
1847 Report.Error (531, current_property.Set.Block.StartLocation,
1848 "`{0}': interface members cannot have a definition", current_property.Set.GetSignatureForError ());
1852 current_local_parameters = null;
1853 lexer.PropertyParsing = true;
1855 if (RootContext.Documentation != null
1856 && Lexer.doc_state == XmlCommentState.Error)
1857 Lexer.doc_state = XmlCommentState.NotAllowed;
1869 Error_SyntaxError (1043, yyToken, "Invalid accessor body");
1874 interface_declaration
1880 lexer.ConstraintsParsing = true;
1882 type_declaration_name
1884 MemberName name = MakeName ((MemberName) $6);
1885 push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
1888 opt_type_parameter_constraints_clauses
1890 lexer.ConstraintsParsing = false;
1892 current_class.SetParameterInfo ((List<Constraints>) $9);
1894 if (RootContext.Documentation != null) {
1895 current_container.DocComment = Lexer.consume_doc_comment ();
1896 Lexer.doc_state = XmlCommentState.Allowed;
1901 --lexer.parsing_declaration;
1902 if (RootContext.Documentation != null)
1903 Lexer.doc_state = XmlCommentState.Allowed;
1907 $$ = pop_current_class ();
1909 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1910 CheckIdentifierToken (yyToken, GetLocation ($5));
1916 opt_interface_member_declarations
1920 opt_interface_member_declarations
1922 | interface_member_declarations
1925 interface_member_declarations
1926 : interface_member_declaration
1927 | interface_member_declarations interface_member_declaration
1930 interface_member_declaration
1931 : constant_declaration
1933 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1937 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1939 | method_declaration
1940 | property_declaration
1942 | indexer_declaration
1943 | operator_declaration
1945 Report.Error (567, GetLocation ($1), "Interfaces cannot contain operators");
1947 | constructor_declaration
1949 Report.Error (526, GetLocation ($1), "Interfaces cannot contain contructors");
1953 Report.Error (524, GetLocation ($1), "Interfaces cannot declare classes, structs, interfaces, delegates, or enumerations");
1957 operator_declaration
1958 : opt_attributes opt_modifiers operator_declarator
1966 OperatorDeclaration decl = (OperatorDeclaration) $3;
1967 Operator op = new Operator (
1968 current_class, decl.optype, decl.ret_type, (Modifiers) $2,
1969 current_local_parameters,
1970 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1972 if (RootContext.Documentation != null) {
1973 op.DocComment = tmpComment;
1974 Lexer.doc_state = XmlCommentState.Allowed;
1977 // Note again, checking is done in semantic analysis
1978 current_container.AddOperator (op);
1980 current_local_parameters = null;
1986 | SEMICOLON { $$ = null; }
1990 : type_expression_or_array
1993 Report.Error (590, GetLocation ($1), "User-defined operators cannot return void");
1994 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
1999 : operator_type OPERATOR overloadable_operator OPEN_PARENS
2001 valid_param_mod = ParameterModifierType.DefaultValue;
2003 opt_formal_parameter_list CLOSE_PARENS
2005 valid_param_mod = 0;
2007 Location loc = GetLocation ($2);
2008 Operator.OpType op = (Operator.OpType) $3;
2009 current_local_parameters = (ParametersCompiled)$6;
2011 int p_count = current_local_parameters.Count;
2013 if (op == Operator.OpType.Addition)
2014 op = Operator.OpType.UnaryPlus;
2015 else if (op == Operator.OpType.Subtraction)
2016 op = Operator.OpType.UnaryNegation;
2019 if (IsUnaryOperator (op)) {
2021 Report.Error (1020, loc, "Overloadable binary operator expected");
2022 } else if (p_count != 1) {
2023 Report.Error (1535, loc, "Overloaded unary operator `{0}' takes one parameter",
2024 Operator.GetName (op));
2028 Report.Error (1534, loc, "Overloaded binary operator `{0}' takes two parameters",
2029 Operator.GetName (op));
2030 } else if (p_count != 2) {
2031 Report.Error (1019, loc, "Overloadable unary operator expected");
2035 if (RootContext.Documentation != null) {
2036 tmpComment = Lexer.consume_doc_comment ();
2037 Lexer.doc_state = XmlCommentState.NotAllowed;
2040 $$ = new OperatorDeclaration (op, (FullNamedExpression) $1, loc);
2042 | conversion_operator_declarator
2045 overloadable_operator
2047 : BANG { $$ = Operator.OpType.LogicalNot; }
2048 | TILDE { $$ = Operator.OpType.OnesComplement; }
2049 | OP_INC { $$ = Operator.OpType.Increment; }
2050 | OP_DEC { $$ = Operator.OpType.Decrement; }
2051 | TRUE { $$ = Operator.OpType.True; }
2052 | FALSE { $$ = Operator.OpType.False; }
2053 // Unary and binary:
2054 | PLUS { $$ = Operator.OpType.Addition; }
2055 | MINUS { $$ = Operator.OpType.Subtraction; }
2057 | STAR { $$ = Operator.OpType.Multiply; }
2058 | DIV { $$ = Operator.OpType.Division; }
2059 | PERCENT { $$ = Operator.OpType.Modulus; }
2060 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2061 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2062 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2063 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2064 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2065 | OP_EQ { $$ = Operator.OpType.Equality; }
2066 | OP_NE { $$ = Operator.OpType.Inequality; }
2067 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2068 | OP_LT { $$ = Operator.OpType.LessThan; }
2069 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2070 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2073 conversion_operator_declarator
2074 : IMPLICIT OPERATOR type OPEN_PARENS
2076 valid_param_mod = ParameterModifierType.DefaultValue;
2078 opt_formal_parameter_list CLOSE_PARENS
2080 valid_param_mod = 0;
2082 Location loc = GetLocation ($2);
2083 current_local_parameters = (ParametersCompiled)$6;
2085 if (RootContext.Documentation != null) {
2086 tmpComment = Lexer.consume_doc_comment ();
2087 Lexer.doc_state = XmlCommentState.NotAllowed;
2090 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (FullNamedExpression) $3, loc);
2092 | EXPLICIT OPERATOR type OPEN_PARENS
2094 valid_param_mod = ParameterModifierType.DefaultValue;
2096 opt_formal_parameter_list CLOSE_PARENS
2098 valid_param_mod = 0;
2100 Location loc = GetLocation ($2);
2101 current_local_parameters = (ParametersCompiled)$6;
2103 if (RootContext.Documentation != null) {
2104 tmpComment = Lexer.consume_doc_comment ();
2105 Lexer.doc_state = XmlCommentState.NotAllowed;
2108 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (FullNamedExpression) $3, loc);
2112 Error_SyntaxError (yyToken);
2113 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2114 $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1));
2118 Error_SyntaxError (yyToken);
2119 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2120 $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1));
2124 constructor_declaration
2125 : constructor_declarator
2128 Constructor c = (Constructor) $1;
2129 c.Block = (ToplevelBlock) $2;
2131 if (RootContext.Documentation != null)
2132 c.DocComment = ConsumeStoredComment ();
2134 current_container.AddConstructor (c);
2136 current_local_parameters = null;
2137 if (RootContext.Documentation != null)
2138 Lexer.doc_state = XmlCommentState.Allowed;
2142 constructor_declarator
2147 if (RootContext.Documentation != null) {
2148 tmpComment = Lexer.consume_doc_comment ();
2149 Lexer.doc_state = XmlCommentState.Allowed;
2152 valid_param_mod = ParameterModifierType.All;
2154 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2156 valid_param_mod = 0;
2157 current_local_parameters = (ParametersCompiled) $6;
2160 // start block here, so possible anonymous methods inside
2161 // constructor initializer can get correct parent block
2163 start_block (lexer.Location);
2165 opt_constructor_initializer
2167 var lt = (Tokenizer.LocatedToken) $3;
2168 var mods = (Modifiers) $2;
2169 ConstructorInitializer ci = (ConstructorInitializer) $9;
2171 Constructor c = new Constructor (current_class, lt.Value, mods,
2172 (Attributes) $1, current_local_parameters, ci, lt.Location);
2174 if (lt.Value != current_container.MemberName.Name) {
2175 Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
2176 } else if ((mods & Modifiers.STATIC) != 0) {
2177 if ((mods & Modifiers.AccessibilityMask) != 0){
2178 Report.Error (515, c.Location,
2179 "`{0}': static constructor cannot have an access modifier",
2180 c.GetSignatureForError ());
2183 Report.Error (514, c.Location,
2184 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2185 c.GetSignatureForError ());
2196 | SEMICOLON { current_block = null; $$ = null; }
2199 opt_constructor_initializer
2201 | constructor_initializer
2204 constructor_initializer
2205 : COLON BASE OPEN_PARENS
2207 ++lexer.parsing_block;
2209 opt_argument_list CLOSE_PARENS
2211 --lexer.parsing_block;
2212 $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2));
2214 | COLON THIS OPEN_PARENS
2216 ++lexer.parsing_block;
2218 opt_argument_list CLOSE_PARENS
2220 --lexer.parsing_block;
2221 $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2));
2224 Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected");
2229 destructor_declaration
2230 : opt_attributes opt_modifiers TILDE
2232 if (RootContext.Documentation != null) {
2233 tmpComment = Lexer.consume_doc_comment ();
2234 Lexer.doc_state = XmlCommentState.NotAllowed;
2237 current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
2239 IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body
2241 var lt = (Tokenizer.LocatedToken) $5;
2242 if (lt.Value != current_container.MemberName.Name){
2243 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2244 } else if (current_container.Kind != MemberKind.Class){
2245 Report.Error (575, lt.Location, "Only class types can contain destructor");
2247 Destructor d = new Destructor (current_class, (Modifiers) $2,
2248 ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location);
2249 if (RootContext.Documentation != null)
2250 d.DocComment = ConsumeStoredComment ();
2252 d.Block = (ToplevelBlock) $8;
2253 current_container.AddMethod (d);
2256 current_local_parameters = null;
2263 EVENT type variable_declarators SEMICOLON
2265 foreach (VariableMemberDeclaration var in (List<object>) $5) {
2267 EventField e = new EventField (
2268 current_class, (FullNamedExpression) $4, (Modifiers) $2, var.MemberName, (Attributes) $1);
2270 e.Initializer = var.GetInitializer ((FullNamedExpression) $4);
2271 if (current_container.Kind == MemberKind.Interface && e.Initializer != null) {
2272 Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
2275 if (var.MemberName.Left != null) {
2276 Report.Error (71, e.Location,
2277 "`{0}': An explicit interface implementation of an event must use property syntax",
2278 e.GetSignatureForError ());
2281 current_container.AddEvent (e);
2283 if (RootContext.Documentation != null) {
2284 e.DocComment = Lexer.consume_doc_comment ();
2285 Lexer.doc_state = XmlCommentState.Allowed;
2291 EVENT type member_declaration_name
2294 current_event = new EventProperty (current_class, (FullNamedExpression) $4, (Modifiers) $2, (MemberName) $5, (Attributes) $1);
2295 current_container.AddEvent (current_event);
2297 lexer.EventParsing = true;
2299 event_accessor_declarations
2301 if (current_container.Kind == MemberKind.Interface)
2302 Report.Error (69, GetLocation ($6), "Event in interface cannot have add or remove accessors");
2304 lexer.EventParsing = false;
2308 if (RootContext.Documentation != null) {
2309 current_event.DocComment = Lexer.consume_doc_comment ();
2310 Lexer.doc_state = XmlCommentState.Allowed;
2313 current_event = null;
2314 current_local_parameters = null;
2316 | opt_attributes opt_modifiers EVENT type member_declaration_name error
2318 MemberName mn = (MemberName) $5;
2319 if (mn.Left != null)
2320 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2322 if (RootContext.Documentation != null)
2323 Lexer.doc_state = XmlCommentState.Allowed;
2325 Error_SyntaxError (yyToken);
2330 event_accessor_declarations
2331 : add_accessor_declaration remove_accessor_declaration
2332 | remove_accessor_declaration add_accessor_declaration
2333 | add_accessor_declaration
2335 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2336 current_event.GetSignatureForError ());
2338 | remove_accessor_declaration
2340 Report.Error (65, lexer.Location, "`{0}': event property must have both add and remove accessors",
2341 current_event.GetSignatureForError ());
2345 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2350 add_accessor_declaration
2351 : opt_attributes opt_modifiers ADD
2353 if ($2 != ModifierNone) {
2354 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2357 current_event.Add = new EventProperty.AddDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2358 current_local_parameters = current_event.Add.ParameterInfo;
2360 lexer.EventParsing = false;
2362 event_accessor_block
2364 lexer.EventParsing = true;
2366 current_event.Add.Block = (ToplevelBlock) $5;
2368 if (current_container.Kind == MemberKind.Interface) {
2369 Report.Error (531, current_event.Add.Block.StartLocation,
2370 "`{0}': interface members cannot have a definition", current_event.Add.GetSignatureForError ());
2373 current_local_parameters = null;
2377 remove_accessor_declaration
2378 : opt_attributes opt_modifiers REMOVE
2380 if ($2 != ModifierNone) {
2381 Report.Error (1609, GetLocation ($2), "Modifiers cannot be placed on event accessor declarations");
2384 current_event.Remove = new EventProperty.RemoveDelegateMethod (current_event, (Attributes) $1, GetLocation ($3));
2385 current_local_parameters = current_event.Remove.ParameterInfo;
2387 lexer.EventParsing = false;
2389 event_accessor_block
2391 lexer.EventParsing = true;
2393 current_event.Remove.Block = (ToplevelBlock) $5;
2395 if (current_container.Kind == MemberKind.Interface) {
2396 Report.Error (531, current_event.Remove.Block.StartLocation,
2397 "`{0}': interface members cannot have a definition", current_event.Remove.GetSignatureForError ());
2400 current_local_parameters = null;
2404 event_accessor_block
2407 Report.Error (73, lexer.Location, "An add or remove accessor must have a body");
2415 ENUM type_declaration_name
2417 if (RootContext.Documentation != null)
2418 enumTypeComment = Lexer.consume_doc_comment ();
2423 MemberName name = (MemberName) $4;
2424 if (name.IsGeneric) {
2425 Report.Error (1675, name.Location, "Enums cannot have type parameters");
2428 name = MakeName (name);
2429 Enum e = new Enum (current_namespace, current_class, (TypeExpression) $5, (Modifiers) $2,
2430 name, (Attributes) $1);
2432 if (RootContext.Documentation != null)
2433 e.DocComment = enumTypeComment;
2436 EnumMember em = null;
2437 foreach (VariableDeclaration ev in (IList<VariableDeclaration>) $7) {
2438 em = new EnumMember (
2439 e, em, ev.identifier, ev.GetInitializer (null),
2440 ev.OptAttributes, ev.Location);
2442 // if (RootContext.Documentation != null)
2443 em.DocComment = ev.DocComment;
2445 e.AddEnumMember (em);
2447 if (RootContext.EvalMode)
2448 undo.AddTypeContainer (current_container, e);
2450 current_container.AddTypeContainer (e);
2461 var te = $2 as TypeExpression;
2463 (te.Type != TypeManager.int32_type && te.Type != TypeManager.uint32_type &&
2464 te.Type != TypeManager.int64_type && te.Type != TypeManager.uint64_type &&
2465 te.Type != TypeManager.short_type && te.Type != TypeManager.ushort_type &&
2466 te.Type != TypeManager.byte_type && te.Type != TypeManager.sbyte_type)) {
2467 Enum.Error_1008 (GetLocation ($2), Report);
2475 Error_TypeExpected (GetLocation ($1));
2483 if (RootContext.Documentation != null)
2484 Lexer.doc_state = XmlCommentState.Allowed;
2486 opt_enum_member_declarations
2488 // here will be evaluated after CLOSE_BLACE is consumed.
2489 if (RootContext.Documentation != null)
2490 Lexer.doc_state = XmlCommentState.Allowed;
2498 opt_enum_member_declarations
2499 : /* empty */ { $$ = new VariableDeclaration [0]; }
2500 | enum_member_declarations opt_comma { $$ = $1; }
2503 enum_member_declarations
2504 : enum_member_declaration
2506 var l = new List<VariableDeclaration> (4);
2507 l.Add ((VariableDeclaration) $1);
2510 | enum_member_declarations COMMA enum_member_declaration
2512 var l = (List<VariableDeclaration>) $1;
2513 l.Add ((VariableDeclaration) $3);
2518 enum_member_declaration
2519 : opt_attributes IDENTIFIER
2521 VariableDeclaration vd = new VariableDeclaration (
2522 (Tokenizer.LocatedToken) $2, null, (Attributes) $1);
2524 if (RootContext.Documentation != null) {
2525 vd.DocComment = Lexer.consume_doc_comment ();
2526 Lexer.doc_state = XmlCommentState.Allowed;
2531 | opt_attributes IDENTIFIER
2533 ++lexer.parsing_block;
2534 if (RootContext.Documentation != null) {
2535 tmpComment = Lexer.consume_doc_comment ();
2536 Lexer.doc_state = XmlCommentState.NotAllowed;
2539 ASSIGN constant_expression
2541 --lexer.parsing_block;
2542 VariableDeclaration vd = new VariableDeclaration (
2543 (Tokenizer.LocatedToken) $2, (Expression) $5, (Attributes) $1);
2545 if (RootContext.Documentation != null)
2546 vd.DocComment = ConsumeStoredComment ();
2552 delegate_declaration
2556 member_type type_declaration_name
2559 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
2561 opt_formal_parameter_list CLOSE_PARENS
2563 valid_param_mod = 0;
2565 MemberName name = MakeName ((MemberName) $5);
2566 ParametersCompiled p = (ParametersCompiled) $8;
2568 Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4,
2569 (Modifiers) $2, name, p, (Attributes) $1);
2571 if (RootContext.Documentation != null) {
2572 del.DocComment = Lexer.consume_doc_comment ();
2573 Lexer.doc_state = XmlCommentState.Allowed;
2576 current_container.AddDelegate (del);
2577 current_delegate = del;
2578 lexer.ConstraintsParsing = true;
2580 opt_type_parameter_constraints_clauses
2582 lexer.ConstraintsParsing = false;
2586 current_delegate.SetParameterInfo ((List<Constraints>) $11);
2587 $$ = current_delegate;
2589 current_delegate = null;
2600 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2601 Report.FeatureIsNotSupported (GetLocation ($1), "nullable types");
2602 else if (RootContext.Version < LanguageVersion.ISO_2)
2603 Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types");
2605 $$ = ComposedTypeSpecifier.CreateNullable (GetLocation ($1));
2609 namespace_or_type_name
2611 | qualified_alias_member IDENTIFIER opt_type_argument_list
2613 var lt1 = (Tokenizer.LocatedToken) $1;
2614 var lt2 = (Tokenizer.LocatedToken) $2;
2616 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2622 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list
2624 var lt = (Tokenizer.LocatedToken) $3;
2625 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2630 : IDENTIFIER opt_type_argument_list
2632 var lt = (Tokenizer.LocatedToken) $1;
2633 $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location);
2638 // Generics arguments (any type, without attributes)
2640 opt_type_argument_list
2641 : /* empty */ { $$ = null; }
2642 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2644 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2645 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2646 else if (RootContext.Version < LanguageVersion.ISO_2)
2647 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2651 | OP_GENERICS_LT error
2653 Error_TypeExpected (lexer.Location);
2654 $$ = new TypeArguments ();
2661 TypeArguments type_args = new TypeArguments ();
2662 type_args.Add ((FullNamedExpression) $1);
2665 | type_arguments COMMA type
2667 TypeArguments type_args = (TypeArguments) $1;
2668 type_args.Add ((FullNamedExpression) $3);
2674 // Generics parameters (identifiers only, with attributes), used in type or method declarations
2676 type_declaration_name
2679 lexer.parsing_generic_declaration = true;
2681 opt_type_parameter_list
2683 lexer.parsing_generic_declaration = false;
2684 var lt = (Tokenizer.LocatedToken) $1;
2685 $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location);
2689 member_declaration_name
2690 : method_declaration_name
2692 MemberName mn = (MemberName)$1;
2693 if (mn.TypeArguments != null)
2694 syntax_error (mn.Location, string.Format ("Member `{0}' cannot declare type arguments",
2695 mn.GetSignatureForError ()));
2699 method_declaration_name
2700 : type_declaration_name
2701 | explicit_interface IDENTIFIER opt_type_parameter_list
2703 lexer.parsing_generic_declaration = false;
2704 var lt = (Tokenizer.LocatedToken) $2;
2705 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2709 indexer_declaration_name
2712 lexer.parsing_generic_declaration = false;
2713 $$ = new MemberName (TypeContainer.DefaultIndexerName, GetLocation ($1));
2715 | explicit_interface THIS
2717 lexer.parsing_generic_declaration = false;
2718 $$ = new MemberName ((MemberName) $1, TypeContainer.DefaultIndexerName, null, GetLocation ($1));
2723 : IDENTIFIER opt_type_argument_list DOT
2725 var lt = (Tokenizer.LocatedToken) $1;
2726 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2728 | qualified_alias_member IDENTIFIER opt_type_argument_list DOT
2730 var lt1 = (Tokenizer.LocatedToken) $1;
2731 var lt2 = (Tokenizer.LocatedToken) $2;
2733 $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
2735 | explicit_interface IDENTIFIER opt_type_argument_list DOT
2737 var lt = (Tokenizer.LocatedToken) $2;
2738 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location);
2742 opt_type_parameter_list
2743 : /* empty */ { $$ = null; }
2744 | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT
2746 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
2747 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
2748 else if (RootContext.Version < LanguageVersion.ISO_2)
2749 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
2758 TypeArguments type_args = new TypeArguments ();
2759 type_args.Add ((FullNamedExpression)$1);
2762 | type_parameters COMMA type_parameter
2764 TypeArguments type_args = (TypeArguments) $1;
2765 type_args.Add ((FullNamedExpression)$3);
2771 : opt_attributes opt_type_parameter_variance IDENTIFIER
2773 var lt = (Tokenizer.LocatedToken)$3;
2774 $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location);
2778 if (GetTokenName (yyToken) == "type")
2779 Report.Error (81, GetLocation ($1), "Type parameter declaration must be an identifier not a type");
2781 Error_SyntaxError (yyToken);
2783 $$ = new TypeParameterName ("", null, lexer.Location);
2788 // All types where void is allowed
2791 : type_expression_or_array
2794 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2801 lexer.parsing_generic_declaration = true;
2806 // A type which does not allow `void' to be used
2809 : type_expression_or_array
2812 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2813 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2821 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
2822 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2827 : type_expression_or_array
2830 Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'");
2831 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
2835 type_expression_or_array
2837 | type_expression rank_specifiers
2839 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2844 : namespace_or_type_name opt_nullable
2846 MemberName name = (MemberName) $1;
2849 $$ = new ComposedCast (name.GetTypeExpression (), (ComposedTypeSpecifier) $2);
2851 if (name.Left == null && name.Name == "var")
2852 $$ = new VarExpr (name.Location);
2854 $$ = name.GetTypeExpression ();
2857 | builtin_types opt_nullable
2860 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
2862 | type_expression STAR
2865 // Note that here only unmanaged types are allowed but we
2866 // can't perform checks during this phase - we do it during
2867 // semantic analysis.
2869 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
2873 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
2880 var types = new List<FullNamedExpression> (2);
2881 types.Add ((FullNamedExpression) $1);
2884 | type_list COMMA base_type_name
2886 var types = (List<FullNamedExpression>) $1;
2887 types.Add ((FullNamedExpression) $3);
2895 if ($1 is ComposedCast) {
2896 Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
2902 Error_TypeExpected (lexer.Location);
2908 * replaces all the productions for isolating the various
2909 * simple types, but we need this to reuse it easily in variable_type
2912 : OBJECT { $$ = new TypeExpression (TypeManager.object_type, GetLocation ($1)); }
2913 | STRING { $$ = new TypeExpression (TypeManager.string_type, GetLocation ($1)); }
2914 | BOOL { $$ = new TypeExpression (TypeManager.bool_type, GetLocation ($1)); }
2915 | DECIMAL { $$ = new TypeExpression (TypeManager.decimal_type, GetLocation ($1)); }
2916 | FLOAT { $$ = new TypeExpression (TypeManager.float_type, GetLocation ($1)); }
2917 | DOUBLE { $$ = new TypeExpression (TypeManager.double_type, GetLocation ($1)); }
2922 : SBYTE { $$ = new TypeExpression (TypeManager.sbyte_type, GetLocation ($1)); }
2923 | BYTE { $$ = new TypeExpression (TypeManager.byte_type, GetLocation ($1)); }
2924 | SHORT { $$ = new TypeExpression (TypeManager.short_type, GetLocation ($1)); }
2925 | USHORT { $$ = new TypeExpression (TypeManager.ushort_type, GetLocation ($1)); }
2926 | INT { $$ = new TypeExpression (TypeManager.int32_type, GetLocation ($1)); }
2927 | UINT { $$ = new TypeExpression (TypeManager.uint32_type, GetLocation ($1)); }
2928 | LONG { $$ = new TypeExpression (TypeManager.int64_type, GetLocation ($1)); }
2929 | ULONG { $$ = new TypeExpression (TypeManager.uint64_type, GetLocation ($1)); }
2930 | CHAR { $$ = new TypeExpression (TypeManager.char_type, GetLocation ($1)); }
2934 // Expressions, section 7.5
2939 : primary_expression_no_array_creation
2940 | array_creation_expression
2943 primary_expression_no_array_creation
2945 | IDENTIFIER opt_type_argument_list
2947 var lt = (Tokenizer.LocatedToken) $1;
2948 $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location);
2950 | IDENTIFIER GENERATE_COMPLETION {
2951 var lt = (Tokenizer.LocatedToken) $1;
2952 $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location);
2954 | parenthesized_expression
2955 | default_value_expression
2957 | invocation_expression
2961 | post_increment_expression
2962 | post_decrement_expression
2963 | object_or_delegate_creation_expression
2964 | anonymous_type_expression
2967 | checked_expression
2968 | unchecked_expression
2969 | pointer_member_access
2970 | anonymous_method_expression
2976 | NULL { $$ = new NullLiteral (GetLocation ($1)); }
2980 : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); }
2981 | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); }
2986 // Here is the trick, tokenizer may think that parens is a special but
2987 // parser is interested in open parens only, so we merge them.
2988 // Consider: if (a)foo ();
2996 // Use this production to accept closing parenthesis or
2997 // performing completion
3001 | COMPLETE_COMPLETION
3005 parenthesized_expression
3006 : OPEN_PARENS expression CLOSE_PARENS
3008 $$ = new ParenthesizedExpression ((Expression) $2);
3010 | OPEN_PARENS expression COMPLETE_COMPLETION
3012 $$ = new ParenthesizedExpression ((Expression) $2);
3017 : primary_expression DOT IDENTIFIER opt_type_argument_list
3019 var lt = (Tokenizer.LocatedToken) $3;
3020 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3022 | builtin_types DOT IDENTIFIER opt_type_argument_list
3024 var lt = (Tokenizer.LocatedToken) $3;
3025 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3027 | qualified_alias_member IDENTIFIER opt_type_argument_list
3029 var lt1 = (Tokenizer.LocatedToken) $1;
3030 var lt2 = (Tokenizer.LocatedToken) $2;
3032 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location);
3034 | primary_expression DOT GENERATE_COMPLETION {
3035 $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3));
3037 | primary_expression DOT IDENTIFIER GENERATE_COMPLETION {
3038 var lt = (Tokenizer.LocatedToken) $3;
3039 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3041 | builtin_types DOT GENERATE_COMPLETION
3043 $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location);
3045 | builtin_types DOT IDENTIFIER GENERATE_COMPLETION {
3046 var lt = (Tokenizer.LocatedToken) $3;
3047 $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location);
3051 invocation_expression
3052 : primary_expression open_parens_any opt_argument_list close_parens
3054 $$ = new Invocation ((Expression) $1, (Arguments) $3);
3058 opt_object_or_collection_initializer
3059 : /* empty */ { $$ = null; }
3060 | object_or_collection_initializer
3063 object_or_collection_initializer
3064 : OPEN_BRACE opt_member_initializer_list close_brace_or_complete_completion
3067 $$ = CollectionOrObjectInitializers.Empty;
3069 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3071 | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE
3073 $$ = new CollectionOrObjectInitializers ((List<Expression>) $2, GetLocation ($1));
3077 opt_member_initializer_list
3078 : /* empty */ { $$ = null; }
3079 | member_initializer_list
3085 member_initializer_list
3086 : member_initializer
3088 var a = new List<Expression> ();
3089 a.Add ((Expression) $1);
3092 | member_initializer_list COMMA member_initializer
3094 var a = (List<Expression>)$1;
3095 a.Add ((Expression) $3);
3098 | member_initializer_list error {
3099 Error_SyntaxError (yyToken);
3105 : IDENTIFIER ASSIGN initializer_value
3107 var lt = (Tokenizer.LocatedToken) $1;
3108 $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location);
3110 | GENERATE_COMPLETION
3112 $$ = new CompletionElementInitializer (null, GetLocation ($1));
3114 | non_assignment_expression opt_COMPLETE_COMPLETION {
3115 CompletionSimpleName csn = $1 as CompletionSimpleName;
3117 $$ = new CollectionElementInitializer ((Expression)$1);
3119 $$ = new CompletionElementInitializer (csn.Prefix, csn.Location);
3121 | OPEN_BRACE expression_list CLOSE_BRACE
3126 $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
3128 | OPEN_BRACE CLOSE_BRACE
3130 Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty");
3137 | object_or_collection_initializer
3141 : /* empty */ { $$ = null; }
3146 : argument_or_named_argument
3148 Arguments list = new Arguments (4);
3149 list.Add ((Argument) $1);
3152 | argument_list COMMA argument
3154 Arguments list = (Arguments) $1;
3155 if (list [list.Count - 1] is NamedArgument)
3156 Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]);
3158 list.Add ((Argument) $3);
3161 | argument_list COMMA named_argument
3163 Arguments list = (Arguments) $1;
3164 NamedArgument a = (NamedArgument) $3;
3165 for (int i = 0; i < list.Count; ++i) {
3166 NamedArgument na = list [i] as NamedArgument;
3167 if (na != null && na.Name == a.Name)
3168 Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times",
3175 | argument_list COMMA
3177 Report.Error (839, GetLocation ($2), "An argument is missing");
3180 | COMMA argument_or_named_argument
3182 Report.Error (839, GetLocation ($1), "An argument is missing");
3190 $$ = new Argument ((Expression) $1);
3192 | non_simple_argument
3195 argument_or_named_argument
3201 : REF variable_reference
3203 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3205 | OUT variable_reference
3207 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3209 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3211 $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1)));
3213 | ARGLIST OPEN_PARENS CLOSE_PARENS
3215 $$ = new Argument (new Arglist (GetLocation ($1)));
3219 $$ = new Argument (new ArglistAccess (GetLocation ($1)));
3228 : primary_expression OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3230 $$ = new ElementAccess ((Expression) $1, (Arguments) $3, GetLocation ($2));
3237 var list = new List<Expression> (4);
3238 list.Add ((Expression) $1);
3241 | expression_list COMMA expression
3243 var list = (List<Expression>) $1;
3244 list.Add ((Expression) $3);
3247 | expression_list error {
3248 Error_SyntaxError (yyToken);
3253 expression_list_arguments
3254 : expression_list_argument
3256 Arguments args = new Arguments (4);
3257 args.Add ((Argument) $1);
3260 | expression_list_arguments COMMA expression_list_argument
3262 Arguments args = (Arguments) $1;
3263 args.Add ((Argument) $3);
3268 expression_list_argument
3271 $$ = new Argument ((Expression) $1);
3279 $$ = new This (GetLocation ($1));
3284 : BASE DOT IDENTIFIER opt_type_argument_list
3286 var lt = (Tokenizer.LocatedToken) $3;
3287 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3289 | BASE OPEN_BRACKET_EXPR expression_list_arguments CLOSE_BRACKET
3291 $$ = new BaseIndexerAccess ((Arguments) $3, GetLocation ($1));
3293 | BASE OPEN_BRACKET error
3295 Error_SyntaxError (yyToken);
3296 $$ = new BaseAccess (null, GetLocation ($1));
3300 post_increment_expression
3301 : primary_expression OP_INC
3303 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2));
3307 post_decrement_expression
3308 : primary_expression OP_DEC
3310 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2));
3314 object_or_delegate_creation_expression
3315 : NEW new_expr_type open_parens_any opt_argument_list CLOSE_PARENS opt_object_or_collection_initializer
3318 if (RootContext.Version <= LanguageVersion.ISO_2)
3319 Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers");
3321 $$ = new NewInitialize ((FullNamedExpression) $2, (Arguments) $4, (CollectionOrObjectInitializers) $6, GetLocation ($1));
3324 $$ = new New ((FullNamedExpression) $2, (Arguments) $4, GetLocation ($1));
3326 | NEW new_expr_type object_or_collection_initializer
3328 if (RootContext.Version <= LanguageVersion.ISO_2)
3329 Report.FeatureIsNotAvailable (GetLocation ($1), "collection initializers");
3331 $$ = new NewInitialize ((FullNamedExpression) $2, null, (CollectionOrObjectInitializers) $3, GetLocation ($1));
3335 array_creation_expression
3336 : NEW new_expr_type OPEN_BRACKET_EXPR expression_list CLOSE_BRACKET
3338 opt_array_initializer
3340 $$ = new ArrayCreation ((FullNamedExpression) $2, (List<Expression>) $4,
3341 new ComposedTypeSpecifier (((List<Expression>) $4).Count, GetLocation ($3)) {
3342 Next = (ComposedTypeSpecifier) $6
3343 }, (ArrayInitializer) $7, GetLocation ($1));
3345 | NEW new_expr_type rank_specifiers opt_array_initializer
3348 Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
3350 $$ = new ArrayCreation ((FullNamedExpression) $2, (ComposedTypeSpecifier) $3, (ArrayInitializer) $4, GetLocation ($1));
3352 | NEW rank_specifiers array_initializer
3354 if (RootContext.Version <= LanguageVersion.ISO_2)
3355 Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
3357 $$ = new ImplicitlyTypedArrayCreation ((ComposedTypeSpecifier) $2, (ArrayInitializer) $3, GetLocation ($1));
3359 | NEW new_expr_type OPEN_BRACKET CLOSE_BRACKET OPEN_BRACKET_EXPR error CLOSE_BRACKET
3361 Report.Error (178, GetLocation ($6), "Invalid rank specifier, expecting `,' or `]'");
3362 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3364 | NEW new_expr_type error
3366 Error_SyntaxError (1526, yyToken, "Unexpected symbol");
3367 $$ = new ArrayCreation ((FullNamedExpression) $2, null, GetLocation ($1));
3373 ++lexer.parsing_type;
3377 --lexer.parsing_type;
3382 anonymous_type_expression
3383 : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
3385 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3386 Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types");
3387 else if (RootContext.Version <= LanguageVersion.ISO_2)
3388 Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
3390 $$ = new NewAnonymousType ((List<AnonymousTypeParameter>) $3, current_container, GetLocation ($1));
3394 anonymous_type_parameters_opt_comma
3395 : anonymous_type_parameters_opt
3396 | anonymous_type_parameters COMMA
3399 anonymous_type_parameters_opt
3401 | anonymous_type_parameters
3404 anonymous_type_parameters
3405 : anonymous_type_parameter
3407 var a = new List<AnonymousTypeParameter> (4);
3408 a.Add ((AnonymousTypeParameter) $1);
3411 | anonymous_type_parameters COMMA anonymous_type_parameter
3413 var a = (List<AnonymousTypeParameter>) $1;
3414 a.Add ((AnonymousTypeParameter) $3);
3419 anonymous_type_parameter
3420 : IDENTIFIER ASSIGN variable_initializer
3422 var lt = (Tokenizer.LocatedToken)$1;
3423 $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location);
3427 var lt = (Tokenizer.LocatedToken)$1;
3428 $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location),
3429 lt.Value, lt.Location);
3431 | BASE DOT IDENTIFIER opt_type_argument_list
3433 var lt = (Tokenizer.LocatedToken) $3;
3434 BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3435 $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location);
3439 MemberAccess ma = (MemberAccess) $1;
3440 $$ = new AnonymousTypeParameter (ma, ma.Name, ma.Location);
3444 Report.Error (746, lexer.Location,
3445 "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression");
3458 opt_rank_specifier_or_nullable
3460 | opt_nullable rank_specifiers
3463 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3473 | rank_specifier rank_specifiers
3475 ((ComposedTypeSpecifier) $1).Next = (ComposedTypeSpecifier) $2;
3481 : OPEN_BRACKET CLOSE_BRACKET
3483 $$ = ComposedTypeSpecifier.CreateArrayDimension (1, GetLocation ($1));
3485 | OPEN_BRACKET dim_separators CLOSE_BRACKET
3487 $$ = ComposedTypeSpecifier.CreateArrayDimension ((int)$2, GetLocation ($1));
3496 | dim_separators COMMA
3498 $$ = ((int) $1) + 1;
3502 opt_array_initializer
3514 : OPEN_BRACE CLOSE_BRACE
3516 $$ = new ArrayInitializer (0, GetLocation ($1));
3518 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3520 $$ = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
3524 variable_initializer_list
3525 : variable_initializer
3527 var list = new List<Expression> (4);
3528 list.Add ((Expression) $1);
3531 | variable_initializer_list COMMA variable_initializer
3533 var list = (List<Expression>) $1;
3534 list.Add ((Expression) $3);
3539 Error_SyntaxError (yyToken);
3540 $$ = new List<Expression> ();
3547 lexer.TypeOfParsing = true;
3549 open_parens_any typeof_type_expression CLOSE_PARENS
3551 lexer.TypeOfParsing = false;
3552 $$ = new TypeOf ((FullNamedExpression) $4, GetLocation ($1));
3556 typeof_type_expression
3561 Error_TypeExpected (lexer.Location);
3567 : IDENTIFIER generic_dimension
3569 var lt = (Tokenizer.LocatedToken) $1;
3571 $$ = new SimpleName (lt.Value, (int) $2, lt.Location);
3573 | qualified_alias_member IDENTIFIER generic_dimension
3575 var lt1 = (Tokenizer.LocatedToken) $1;
3576 var lt2 = (Tokenizer.LocatedToken) $2;
3578 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location);
3580 | unbound_type_name DOT IDENTIFIER
3582 var lt = (Tokenizer.LocatedToken) $3;
3584 $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
3586 | unbound_type_name DOT IDENTIFIER generic_dimension
3588 var lt = (Tokenizer.LocatedToken) $3;
3590 $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location);
3592 | namespace_or_type_name DOT IDENTIFIER generic_dimension
3594 var lt = (Tokenizer.LocatedToken) $3;
3595 MemberName name = (MemberName) $1;
3597 $$ = new MemberAccess (name.GetTypeExpression (), lt.Value, (int) $4, lt.Location);
3604 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
3605 Report.FeatureIsNotSupported (GetLocation ($1), "generics");
3606 else if (RootContext.Version < LanguageVersion.ISO_2)
3607 Report.FeatureIsNotAvailable (GetLocation ($1), "generics");
3613 qualified_alias_member
3614 : IDENTIFIER DOUBLE_COLON
3616 var lt = (Tokenizer.LocatedToken) $1;
3617 if (RootContext.Version == LanguageVersion.ISO_1)
3618 Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier");
3625 : SIZEOF open_parens_any type CLOSE_PARENS {
3626 $$ = new SizeOf ((Expression) $3, GetLocation ($1));
3631 : CHECKED open_parens_any expression CLOSE_PARENS
3633 $$ = new CheckedExpr ((Expression) $3, GetLocation ($1));
3637 unchecked_expression
3638 : UNCHECKED open_parens_any expression CLOSE_PARENS
3640 $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1));
3644 pointer_member_access
3645 : primary_expression OP_PTR IDENTIFIER
3647 var lt = (Tokenizer.LocatedToken) $3;
3648 $$ = new MemberAccess (new Indirection ((Expression) $1, GetLocation ($2)), lt.Value, lt.Location);
3652 anonymous_method_expression
3653 : DELEGATE opt_anonymous_method_signature
3655 start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1));
3659 $$ = end_anonymous ((ToplevelBlock) $4);
3663 opt_anonymous_method_signature
3666 $$ = ParametersCompiled.Undefined;
3668 | anonymous_method_signature
3671 anonymous_method_signature
3674 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
3676 opt_formal_parameter_list CLOSE_PARENS
3678 valid_param_mod = 0;
3683 default_value_expression
3684 : DEFAULT open_parens_any type CLOSE_PARENS
3686 if (RootContext.Version < LanguageVersion.ISO_2)
3687 Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression");
3689 $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1));
3694 : primary_expression
3695 | BANG prefixed_unary_expression
3697 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1));
3699 | TILDE prefixed_unary_expression
3701 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1));
3707 : OPEN_PARENS_CAST type CLOSE_PARENS prefixed_unary_expression
3709 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3711 | OPEN_PARENS builtin_types CLOSE_PARENS prefixed_unary_expression
3713 $$ = new Cast ((FullNamedExpression) $2, (Expression) $4, GetLocation ($1));
3718 // The idea to split this out is from Rhys' grammar
3719 // to solve the problem with casts.
3721 prefixed_unary_expression
3723 | PLUS prefixed_unary_expression
3725 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1));
3727 | MINUS prefixed_unary_expression
3729 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1));
3731 | OP_INC prefixed_unary_expression
3733 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1));
3735 | OP_DEC prefixed_unary_expression
3737 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1));
3739 | STAR prefixed_unary_expression
3741 $$ = new Indirection ((Expression) $2, GetLocation ($1));
3743 | BITWISE_AND prefixed_unary_expression
3745 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1));
3749 multiplicative_expression
3750 : prefixed_unary_expression
3751 | multiplicative_expression STAR prefixed_unary_expression
3753 $$ = new Binary (Binary.Operator.Multiply,
3754 (Expression) $1, (Expression) $3, GetLocation ($2));
3756 | multiplicative_expression DIV prefixed_unary_expression
3758 $$ = new Binary (Binary.Operator.Division,
3759 (Expression) $1, (Expression) $3, GetLocation ($2));
3761 | multiplicative_expression PERCENT prefixed_unary_expression
3763 $$ = new Binary (Binary.Operator.Modulus,
3764 (Expression) $1, (Expression) $3, GetLocation ($2));
3769 : multiplicative_expression
3770 | additive_expression PLUS multiplicative_expression
3772 $$ = new Binary (Binary.Operator.Addition,
3773 (Expression) $1, (Expression) $3, GetLocation ($2));
3775 | additive_expression MINUS multiplicative_expression
3777 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3779 | parenthesized_expression MINUS multiplicative_expression
3781 // Shift/Reduce conflict
3782 $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3784 | additive_expression AS type
3786 $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2));
3788 | additive_expression IS type
3790 $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2));
3795 : additive_expression
3796 | shift_expression OP_SHIFT_LEFT additive_expression
3798 $$ = new Binary (Binary.Operator.LeftShift,
3799 (Expression) $1, (Expression) $3, GetLocation ($2));
3801 | shift_expression OP_SHIFT_RIGHT additive_expression
3803 $$ = new Binary (Binary.Operator.RightShift,
3804 (Expression) $1, (Expression) $3, GetLocation ($2));
3808 relational_expression
3810 | relational_expression OP_LT shift_expression
3812 $$ = new Binary (Binary.Operator.LessThan,
3813 (Expression) $1, (Expression) $3, GetLocation ($2));
3815 | relational_expression OP_GT shift_expression
3817 $$ = new Binary (Binary.Operator.GreaterThan,
3818 (Expression) $1, (Expression) $3, GetLocation ($2));
3820 | relational_expression OP_LE shift_expression
3822 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3823 (Expression) $1, (Expression) $3, GetLocation ($2));
3825 | relational_expression OP_GE shift_expression
3827 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3828 (Expression) $1, (Expression) $3, GetLocation ($2));
3833 : relational_expression
3834 | equality_expression OP_EQ relational_expression
3836 $$ = new Binary (Binary.Operator.Equality,
3837 (Expression) $1, (Expression) $3, GetLocation ($2));
3839 | equality_expression OP_NE relational_expression
3841 $$ = new Binary (Binary.Operator.Inequality,
3842 (Expression) $1, (Expression) $3, GetLocation ($2));
3847 : equality_expression
3848 | and_expression BITWISE_AND equality_expression
3850 $$ = new Binary (Binary.Operator.BitwiseAnd,
3851 (Expression) $1, (Expression) $3, GetLocation ($2));
3855 exclusive_or_expression
3857 | exclusive_or_expression CARRET and_expression
3859 $$ = new Binary (Binary.Operator.ExclusiveOr,
3860 (Expression) $1, (Expression) $3, GetLocation ($2));
3864 inclusive_or_expression
3865 : exclusive_or_expression
3866 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3868 $$ = new Binary (Binary.Operator.BitwiseOr,
3869 (Expression) $1, (Expression) $3, GetLocation ($2));
3873 conditional_and_expression
3874 : inclusive_or_expression
3875 | conditional_and_expression OP_AND inclusive_or_expression
3877 $$ = new Binary (Binary.Operator.LogicalAnd,
3878 (Expression) $1, (Expression) $3, GetLocation ($2));
3882 conditional_or_expression
3883 : conditional_and_expression
3884 | conditional_or_expression OP_OR conditional_and_expression
3886 $$ = new Binary (Binary.Operator.LogicalOr,
3887 (Expression) $1, (Expression) $3, GetLocation ($2));
3891 null_coalescing_expression
3892 : conditional_or_expression
3893 | conditional_or_expression OP_COALESCING null_coalescing_expression
3895 if (RootContext.Version < LanguageVersion.ISO_2)
3896 Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator");
3898 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2));
3902 conditional_expression
3903 : null_coalescing_expression
3904 | null_coalescing_expression INTERR expression COLON expression
3906 $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5);
3910 assignment_expression
3911 : prefixed_unary_expression ASSIGN expression
3913 $$ = new SimpleAssign ((Expression) $1, (Expression) $3, GetLocation ($2));
3915 | prefixed_unary_expression OP_MULT_ASSIGN expression
3917 $$ = new CompoundAssign (
3918 Binary.Operator.Multiply, (Expression) $1, (Expression) $3, GetLocation ($2));
3920 | prefixed_unary_expression OP_DIV_ASSIGN expression
3922 $$ = new CompoundAssign (
3923 Binary.Operator.Division, (Expression) $1, (Expression) $3, GetLocation ($2));
3925 | prefixed_unary_expression OP_MOD_ASSIGN expression
3927 $$ = new CompoundAssign (
3928 Binary.Operator.Modulus, (Expression) $1, (Expression) $3, GetLocation ($2));
3930 | prefixed_unary_expression OP_ADD_ASSIGN expression
3932 $$ = new CompoundAssign (
3933 Binary.Operator.Addition, (Expression) $1, (Expression) $3, GetLocation ($2));
3935 | prefixed_unary_expression OP_SUB_ASSIGN expression
3937 $$ = new CompoundAssign (
3938 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2));
3940 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3942 $$ = new CompoundAssign (
3943 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3, GetLocation ($2));
3945 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3947 $$ = new CompoundAssign (
3948 Binary.Operator.RightShift, (Expression) $1, (Expression) $3, GetLocation ($2));
3950 | prefixed_unary_expression OP_AND_ASSIGN expression
3952 $$ = new CompoundAssign (
3953 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3, GetLocation ($2));
3955 | prefixed_unary_expression OP_OR_ASSIGN expression
3957 $$ = new CompoundAssign (
3958 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3, GetLocation ($2));
3960 | prefixed_unary_expression OP_XOR_ASSIGN expression
3962 $$ = new CompoundAssign (
3963 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3, GetLocation ($2));
3967 lambda_parameter_list
3970 var pars = new List<Parameter> (4);
3971 pars.Add ((Parameter) $1);
3975 | lambda_parameter_list COMMA lambda_parameter
3977 var pars = (List<Parameter>) $1;
3978 Parameter p = (Parameter)$3;
3979 if (pars[0].GetType () != p.GetType ()) {
3980 Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
3989 : parameter_modifier parameter_type IDENTIFIER
3991 var lt = (Tokenizer.LocatedToken) $3;
3993 $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3995 | parameter_type IDENTIFIER
3997 var lt = (Tokenizer.LocatedToken) $2;
3999 $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4003 var lt = (Tokenizer.LocatedToken) $1;
4004 $$ = new ImplicitLambdaParameter (lt.Value, lt.Location);
4008 opt_lambda_parameter_list
4009 : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
4010 | lambda_parameter_list {
4011 var pars_list = (List<Parameter>) $1;
4012 $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
4016 lambda_expression_body
4018 start_block (lexer.Location);
4022 Block b = end_block (lexer.Location);
4023 b.AddStatement (new ContextualReturn ((Expression) $2));
4034 var lt = (Tokenizer.LocatedToken) $1;
4035 Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location);
4036 start_anonymous (true, new ParametersCompiled (compiler, p), GetLocation ($1));
4038 lambda_expression_body
4040 $$ = end_anonymous ((ToplevelBlock) $4);
4042 | OPEN_PARENS_LAMBDA
4044 if (RootContext.Version <= LanguageVersion.ISO_2)
4045 Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions");
4047 valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out;
4049 opt_lambda_parameter_list CLOSE_PARENS ARROW
4051 valid_param_mod = 0;
4052 start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1));
4054 lambda_expression_body
4056 $$ = end_anonymous ((ToplevelBlock) $7);
4061 : assignment_expression
4062 | non_assignment_expression
4065 non_assignment_expression
4066 : conditional_expression
4078 $$ = new BooleanExpression ((Expression) $1);
4091 lexer.ConstraintsParsing = true;
4093 type_declaration_name
4095 MemberName name = MakeName ((MemberName) $6);
4096 push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3);
4099 opt_type_parameter_constraints_clauses
4101 lexer.ConstraintsParsing = false;
4103 current_class.SetParameterInfo ((List<Constraints>) $9);
4105 if (RootContext.Documentation != null) {
4106 current_container.DocComment = Lexer.consume_doc_comment ();
4107 Lexer.doc_state = XmlCommentState.Allowed;
4110 OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
4112 --lexer.parsing_declaration;
4113 if (RootContext.Documentation != null)
4114 Lexer.doc_state = XmlCommentState.Allowed;
4118 $$ = pop_current_class ();
4126 { $$ = $1; } // location
4130 : /* empty */ { $$ = ModifierNone; }
4136 | modifiers modifier
4138 var m1 = (Modifiers) $1;
4139 var m2 = (Modifiers) $2;
4141 if ((m1 & m2) != 0) {
4142 Report.Error (1004, lexer.Location - ModifiersExtensions.Name (m2).Length,
4143 "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2));
4144 } else if ((m2 & Modifiers.AccessibilityMask) != 0 && (m1 & Modifiers.AccessibilityMask) != 0 &&
4145 ((m2 | m1 & Modifiers.AccessibilityMask) != (Modifiers.PROTECTED | Modifiers.INTERNAL))) {
4146 Report.Error (107, lexer.Location - ModifiersExtensions.Name (m2).Length,
4147 "More than one protection modifier specified");
4158 if (current_container == RootContext.ToplevelTypes)
4159 Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements");
4161 | PUBLIC { $$ = Modifiers.PUBLIC; }
4162 | PROTECTED { $$ = Modifiers.PROTECTED; }
4163 | INTERNAL { $$ = Modifiers.INTERNAL; }
4164 | PRIVATE { $$ = Modifiers.PRIVATE; }
4165 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4166 | SEALED { $$ = Modifiers.SEALED; }
4167 | STATIC { $$ = Modifiers.STATIC; }
4168 | READONLY { $$ = Modifiers.READONLY; }
4169 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4170 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4171 | EXTERN { $$ = Modifiers.EXTERN; }
4172 | VOLATILE { $$ = Modifiers.VOLATILE; }
4175 $$ = Modifiers.UNSAFE;
4176 if (!RootContext.Unsafe)
4177 Error_UnsafeCodeNotAllowed (GetLocation ($1));
4189 current_container.AddBasesForPart (current_class, (List<FullNamedExpression>) $2);
4193 opt_type_parameter_constraints_clauses
4194 : /* empty */ { $$ = null; }
4195 | type_parameter_constraints_clauses
4201 type_parameter_constraints_clauses
4202 : type_parameter_constraints_clause
4204 var constraints = new List<Constraints> (1);
4205 constraints.Add ((Constraints) $1);
4208 | type_parameter_constraints_clauses type_parameter_constraints_clause
4210 var constraints = (List<Constraints>) $1;
4211 Constraints new_constraint = (Constraints)$2;
4213 foreach (Constraints c in constraints) {
4214 if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) {
4215 Report.Error (409, new_constraint.Location,
4216 "A constraint clause has already been specified for type parameter `{0}'",
4217 new_constraint.TypeParameter.Value);
4221 constraints.Add (new_constraint);
4226 type_parameter_constraints_clause
4227 : WHERE IDENTIFIER COLON type_parameter_constraints
4229 var lt = (Tokenizer.LocatedToken) $2;
4230 $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List<FullNamedExpression>) $4, GetLocation ($1));
4234 type_parameter_constraints
4235 : type_parameter_constraint
4237 var constraints = new List<FullNamedExpression> (1);
4238 constraints.Add ((FullNamedExpression) $1);
4241 | type_parameter_constraints COMMA type_parameter_constraint
4243 var constraints = (List<FullNamedExpression>) $1;
4244 var prev = constraints [constraints.Count - 1] as SpecialContraintExpr;
4245 if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) {
4246 Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified");
4249 prev = $3 as SpecialContraintExpr;
4251 if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) {
4252 Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified");
4254 prev = constraints [0] as SpecialContraintExpr;
4255 if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) {
4256 Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint");
4261 constraints.Add ((FullNamedExpression) $3);
4266 type_parameter_constraint
4269 if ($1 is ComposedCast)
4270 Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ());
4274 | NEW OPEN_PARENS CLOSE_PARENS
4276 $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1));
4280 $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1));
4284 $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1));
4288 opt_type_parameter_variance
4293 | type_parameter_variance
4295 if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2)
4296 Report.FeatureIsNotSupported (lexer.Location, "generic type variance");
4297 else if (RootContext.Version <= LanguageVersion.V_3)
4298 Report.FeatureIsNotAvailable (lexer.Location, "generic type variance");
4304 type_parameter_variance
4307 $$ = Variance.Covariant;
4311 $$ = Variance.Contravariant;
4320 // A block is "contained" on the following places:
4322 // property_declaration as part of the accessor body (get/set)
4323 // operator_declaration
4324 // constructor_declaration
4325 // destructor_declaration
4326 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4331 ++lexer.parsing_block;
4332 start_block (GetLocation ($1));
4334 opt_statement_list block_end
4343 --lexer.parsing_block;
4344 $$ = end_block (GetLocation ($1));
4346 | COMPLETE_COMPLETION
4348 --lexer.parsing_block;
4349 $$ = end_block (lexer.Location);
4357 ++lexer.parsing_block;
4358 current_block.StartLocation = GetLocation ($1);
4360 opt_statement_list CLOSE_BRACE
4362 --lexer.parsing_block;
4363 $$ = end_block (GetLocation ($4));
4374 | statement_list statement
4378 : declaration_statement
4380 if ($1 != null && (Block) $1 != current_block){
4381 current_block.AddStatement ((Statement) $1);
4382 current_block = (Block) $1;
4385 | valid_declaration_statement
4387 current_block.AddStatement ((Statement) $1);
4393 // The interactive_statement and its derivatives are only
4394 // used to provide a special version of `expression_statement'
4395 // that has a side effect of assigning the expression to
4398 interactive_statement_list
4399 : interactive_statement
4400 | interactive_statement_list interactive_statement
4403 interactive_statement
4404 : declaration_statement
4406 if ($1 != null && (Block) $1 != current_block){
4407 current_block.AddStatement ((Statement) $1);
4408 current_block = (Block) $1;
4411 | interactive_valid_declaration_statement
4413 current_block.AddStatement ((Statement) $1);
4418 valid_declaration_statement
4421 | expression_statement
4422 | selection_statement
4423 | iteration_statement
4427 | unchecked_statement
4434 interactive_valid_declaration_statement
4437 | interactive_expression_statement
4438 | selection_statement
4439 | iteration_statement
4443 | unchecked_statement
4451 : valid_declaration_statement
4452 | declaration_statement
4454 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4459 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4467 $$ = new EmptyStatement (GetLocation ($1));
4474 var lt = (Tokenizer.LocatedToken) $1;
4475 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4477 if (current_block.AddLabel (labeled))
4478 current_block.AddStatement (labeled);
4483 declaration_statement
4484 : local_variable_declaration SEMICOLON
4487 var de = (Tuple<FullNamedExpression, List<object>>) $1;
4488 $$ = declare_local_variables (de.Item1, de.Item2, de.Item1.Location);
4492 | local_constant_declaration SEMICOLON
4495 var de = (Tuple<FullNamedExpression, List<object>>) $1;
4497 $$ = declare_local_constants (de.Item1, de.Item2);
4503 * The following is from Rhys' grammar:
4504 * > Types in local variable declarations must be recognized as
4505 * > expressions to prevent reduce/reduce errors in the grammar.
4506 * > The expressions are converted into types during semantic analysis.
4509 : primary_expression_no_array_creation opt_rank_specifier_or_nullable
4511 // Ok, the above "primary_expression" is there to get rid of
4512 // both reduce/reduce and shift/reduces in the grammar, it should
4513 // really just be "type_name". If you use type_name, a reduce/reduce
4514 // creeps up. If you use namespace_or_type_name (which is all we need
4515 // really) two shift/reduces appear.
4518 // So the super-trick is that primary_expression
4519 // can only be either a SimpleName or a MemberAccess.
4520 // The MemberAccess case arises when you have a fully qualified type-name like :
4522 // SimpleName is when you have
4525 Expression expr = (Expression) $1;
4527 SimpleName sn = expr as SimpleName;
4528 if (sn != null && sn.Name == "var")
4529 $$ = new VarExpr (sn.Location);
4532 } else if (expr is ATypeNameExpression) {
4533 $$ = new ComposedCast ((ATypeNameExpression)expr, (ComposedTypeSpecifier) $2);
4535 Error_ExpectingTypeName (expr);
4539 | builtin_types opt_rank_specifier_or_nullable
4544 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4546 | VOID opt_rank_specifier
4548 Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report);
4549 $$ = new TypeExpression (TypeManager.void_type, GetLocation ($1));
4553 local_variable_pointer_type
4554 : primary_expression_no_array_creation STAR
4556 ATypeNameExpression expr = $1 as ATypeNameExpression;
4559 $$ = new ComposedCast (expr, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4561 Error_ExpectingTypeName ((Expression)$1);
4565 | builtin_types STAR
4567 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4571 $$ = new ComposedCast (new TypeExpression (TypeManager.void_type, GetLocation ($1)), ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4573 | local_variable_pointer_type STAR
4575 $$ = new ComposedCast ((FullNamedExpression) $1, ComposedTypeSpecifier.CreatePointer (GetLocation ($2)));
4581 | local_variable_pointer_type opt_rank_specifier
4587 $$ = new ComposedCast ((FullNamedExpression) $1, (ComposedTypeSpecifier) $2);
4594 local_variable_declaration
4595 : local_variable_type local_variable_declarators
4598 VarExpr ve = $1 as VarExpr;
4600 if (!((VariableDeclaration) ((List<object>)$2) [0]).HasInitializer)
4601 ve.VariableInitializersCount = 0;
4603 ve.VariableInitializersCount = ((List<object>)$2).Count;
4606 $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $1, (List<object>) $2);
4612 local_constant_declaration
4613 : CONST variable_type constant_declarators
4616 $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $2, (List<object>) $3);
4622 expression_statement
4623 : statement_expression SEMICOLON { $$ = $1; }
4624 | statement_expression COMPLETE_COMPLETION { $$ = $1; }
4627 interactive_expression_statement
4628 : interactive_statement_expression SEMICOLON { $$ = $1; }
4629 | interactive_statement_expression COMPLETE_COMPLETION { $$ = $1; }
4633 // We have to do the wrapping here and not in the case above,
4634 // because statement_expression is used for example in for_statement
4636 statement_expression
4639 ExpressionStatement s = $1 as ExpressionStatement;
4641 Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1));
4642 s = EmptyExpressionStatement.Instance;
4645 $$ = new StatementExpression (s);
4649 Error_SyntaxError (yyToken);
4654 interactive_statement_expression
4657 Expression expr = (Expression) $1;
4658 ExpressionStatement s;
4660 s = new OptionalAssign (new SimpleName ("$retval", lexer.Location), expr, lexer.Location);
4661 $$ = new StatementExpression (s);
4665 Error_SyntaxError (yyToken);
4666 $$ = new EmptyStatement (GetLocation ($1));
4676 : IF open_parens_any boolean_expression CLOSE_PARENS
4679 if ($5 is EmptyStatement)
4680 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4682 $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4684 | IF open_parens_any boolean_expression CLOSE_PARENS
4685 embedded_statement ELSE embedded_statement
4687 $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1));
4689 if ($5 is EmptyStatement)
4690 Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement");
4691 if ($7 is EmptyStatement)
4692 Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement");
4697 : SWITCH open_parens_any
4699 if (switch_stack == null)
4700 switch_stack = new Stack<Block> (2);
4701 switch_stack.Push (current_block);
4703 expression CLOSE_PARENS
4706 $$ = new Switch ((Expression) $4, (List<SwitchSection>) $6, GetLocation ($1));
4707 current_block = (Block) switch_stack.Pop ();
4723 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4724 $$ = new List<SwitchSection> ();
4732 var sections = new List<SwitchSection> (4);
4734 sections.Add ((SwitchSection) $1);
4737 | switch_sections switch_section
4739 var sections = (List<SwitchSection>) $1;
4741 sections.Add ((SwitchSection) $2);
4749 current_block = current_block.CreateSwitchBlock (lexer.Location);
4753 $$ = new SwitchSection ((List<SwitchLabel>) $1, current_block.Explicit);
4760 var labels = new List<SwitchLabel> (4);
4762 labels.Add ((SwitchLabel) $1);
4765 | switch_labels switch_label
4767 var labels = (List<SwitchLabel>) ($1);
4768 labels.Add ((SwitchLabel) $2);
4775 : CASE constant_expression COLON
4777 $$ = new SwitchLabel ((Expression) $2, GetLocation ($1));
4781 $$ = new SwitchLabel (null, GetLocation ($1));
4793 : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement
4795 $$ = new While ((BooleanExpression) $3, (Statement) $5, GetLocation ($1));
4800 : DO embedded_statement
4801 WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON
4803 $$ = new Do ((Statement) $2, (BooleanExpression) $5, GetLocation ($1));
4808 : FOR open_parens_any opt_for_initializer SEMICOLON
4810 Location l = lexer.Location;
4812 Block assign_block = current_block;
4814 if ($3 is Tuple<FullNamedExpression, List<object>>){
4815 var de = (Tuple<FullNamedExpression, List<object>>) $3;
4817 var type = de.Item1;
4819 foreach (VariableDeclaration decl in de.Item2){
4823 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4827 Expression expr = decl.GetInitializer (type);
4829 LocalVariableReference var;
4830 var = new LocalVariableReference (assign_block, decl.identifier, l);
4833 Assign a = new SimpleAssign (var, expr, decl.Location);
4835 assign_block.AddStatement (new StatementExpression (a));
4839 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4840 // This can be referred to as $5 below.
4846 opt_for_condition SEMICOLON
4847 opt_for_iterator CLOSE_PARENS
4850 Location l = GetLocation ($1);
4852 For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, l);
4854 current_block.AddStatement (f);
4856 $$ = end_block (lexer.Location);
4861 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
4866 : local_variable_declaration
4867 | statement_expression_list
4871 : /* empty */ { $$ = null; }
4872 | boolean_expression
4876 : /* empty */ { $$ = new EmptyStatement (lexer.Location); }
4881 : statement_expression_list
4884 statement_expression_list
4885 : statement_expression
4887 Statement s = (Statement) $1;
4888 Block b = new Block (current_block, s.loc, lexer.Location);
4893 | statement_expression_list COMMA statement_expression
4895 Block b = (Block) $1;
4897 b.AddStatement ((Statement) $3);
4903 : FOREACH open_parens_any type IN expression CLOSE_PARENS
4905 Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement");
4908 | FOREACH open_parens_any type IDENTIFIER IN
4909 expression CLOSE_PARENS
4911 start_block (lexer.Location);
4912 Block foreach_block = current_block;
4914 var lt = (Tokenizer.LocatedToken) $4;
4915 Location l = lt.Location;
4916 LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4918 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4920 // Get a writable reference to this read-only variable.
4922 // Note that the $$ here refers to the value of _this_ code block,
4923 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4924 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4931 LocalVariableReference v = (LocalVariableReference) $8;
4932 Location l = GetLocation ($1);
4935 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4936 current_block.AddStatement (f);
4939 $$ = end_block (lexer.Location);
4945 | continue_statement
4955 $$ = new Break (GetLocation ($1));
4960 : CONTINUE SEMICOLON
4962 $$ = new Continue (GetLocation ($1));
4967 : GOTO IDENTIFIER SEMICOLON
4969 var lt = (Tokenizer.LocatedToken) $2;
4970 $$ = new Goto (lt.Value, lt.Location);
4972 | GOTO CASE constant_expression SEMICOLON
4974 $$ = new GotoCase ((Expression) $3, GetLocation ($1));
4976 | GOTO DEFAULT SEMICOLON
4978 $$ = new GotoDefault (GetLocation ($1));
4983 : RETURN opt_expression SEMICOLON
4985 $$ = new Return ((Expression) $2, GetLocation ($1));
4990 : THROW opt_expression SEMICOLON
4992 $$ = new Throw ((Expression) $2, GetLocation ($1));
4997 : IDENTIFIER RETURN expression SEMICOLON
4999 var lt = (Tokenizer.LocatedToken) $1;
5000 string s = lt.Value;
5002 Report.Error (1003, lt.Location, "; expected");
5005 if (RootContext.Version == LanguageVersion.ISO_1){
5006 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5009 current_block.Toplevel.IsIterator = true;
5010 $$ = new Yield ((Expression) $3, lt.Location);
5012 | IDENTIFIER RETURN SEMICOLON
5014 Report.Error (1627, GetLocation ($2), "Expression expected after yield return");
5017 | IDENTIFIER BREAK SEMICOLON
5019 var lt = (Tokenizer.LocatedToken) $1;
5020 string s = lt.Value;
5022 Report.Error (1003, lt.Location, "; expected");
5025 if (RootContext.Version == LanguageVersion.ISO_1){
5026 Report.FeatureIsNotAvailable (lt.Location, "yield statement");
5030 current_block.Toplevel.IsIterator = true;
5031 $$ = new YieldBreak (lt.Location);
5041 : TRY block catch_clauses
5043 $$ = new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), false);
5045 | TRY block FINALLY block
5047 $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1));
5049 | TRY block catch_clauses FINALLY block
5051 $$ = new TryFinally (new TryCatch ((Block) $2, (List<Catch>) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1));
5055 Report.Error (1524, GetLocation ($1), "Expected catch or finally");
5063 var l = new List<Catch> (2);
5068 | catch_clauses catch_clause
5070 var l = (List<Catch>) $1;
5072 Catch c = (Catch) $2;
5073 if (l [0].IsGeneral) {
5074 Report.Error (1017, c.loc, "Try statement already has an empty catch block");
5087 : /* empty */ { $$ = null; }
5092 : CATCH opt_catch_args
5095 var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
5099 List<object> one = new List<object> (1);
5101 one.Add (new VariableDeclaration (lt, null));
5103 start_block (lexer.Location);
5104 current_block = declare_local_variables (cc.Item1, one, lt.Location);
5108 Expression type = null;
5110 Block var_block = null;
5113 var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
5119 var_block = end_block (lexer.Location);
5123 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
5128 : /* empty */ { $$ = null; }
5133 : open_parens_any type opt_identifier CLOSE_PARENS
5135 $$ = new Tuple<FullNamedExpression, Tokenizer.LocatedToken> ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3);
5137 | open_parens_any CLOSE_PARENS
5139 Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
5147 $$ = new Checked ((Block) $2, GetLocation ($1));
5154 $$ = new Unchecked ((Block) $2, GetLocation ($1));
5161 if (!RootContext.Unsafe)
5162 Error_UnsafeCodeNotAllowed (GetLocation ($1));
5164 $$ = new Unsafe ((Block) $3, GetLocation ($1));
5169 : FIXED open_parens_any
5170 type_and_void fixed_pointer_declarators
5173 start_block (lexer.Location);
5177 Expression type = (Expression) $3;
5178 var list = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $4;
5179 Fixed f = new Fixed (type,
5180 list.ConvertAll (i => {
5181 var v = new KeyValuePair<LocalInfo, Expression> (current_block.AddVariable (type, i.Key.Value, i.Key.Location), i.Value);
5182 if (v.Key != null) {
5183 v.Key.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5184 v.Key.Pinned = true;
5187 }), (Statement) $7, GetLocation ($1));
5189 current_block.AddStatement (f);
5191 $$ = end_block (lexer.Location);
5195 fixed_pointer_declarators
5196 : fixed_pointer_declarator {
5197 var declarators = new List<KeyValuePair<Tokenizer.LocatedToken, Expression>> (2);
5199 declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$1);
5202 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5204 var declarators = (List<KeyValuePair<Tokenizer.LocatedToken, Expression>>) $1;
5206 declarators.Add ((KeyValuePair<Tokenizer.LocatedToken, Expression>)$3);
5211 fixed_pointer_declarator
5212 : IDENTIFIER ASSIGN expression
5214 var lt = (Tokenizer.LocatedToken) $1;
5215 $$ = new KeyValuePair<Tokenizer.LocatedToken, Expression> (lt, (Expression) $3);
5219 Report.Error (210, ((Tokenizer.LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5225 : LOCK open_parens_any expression CLOSE_PARENS embedded_statement
5227 $$ = new Lock ((Expression) $3, (Statement) $5, GetLocation ($1));
5232 : USING open_parens_any local_variable_declaration CLOSE_PARENS
5234 start_block (lexer.Location);
5235 Block assign_block = current_block;
5237 var de = (Tuple<FullNamedExpression, List<object>>) $3;
5238 Location l = GetLocation ($1);
5240 var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
5242 foreach (VariableDeclaration decl in de.Item2) {
5243 LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location);
5246 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5248 Expression expr = decl.GetInitializer (de.Item1);
5250 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5253 LocalVariableReference var;
5255 // Get a writable reference to this read-only variable.
5256 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5258 // This is so that it is not a warning on using variables
5261 vars.Push (new Tuple<LocalVariableReference, Expression> (var, expr));
5263 // Assign a = new SimpleAssign (var, expr, decl.Location);
5264 // assign_block.AddStatement (new StatementExpression (a));
5267 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5268 // It can be referred to as $5 below.
5273 Statement stmt = (Statement) $6;
5274 var vars = (Stack<Tuple<LocalVariableReference, Expression>>) $5;
5275 Location l = GetLocation ($1);
5277 while (vars.Count > 0) {
5278 var de = vars.Pop ();
5279 stmt = new Using (de.Item1, de.Item2, stmt, l);
5281 current_block.AddStatement (stmt);
5282 $$ = end_block (lexer.Location);
5284 | USING open_parens_any expression CLOSE_PARENS
5286 start_block (lexer.Location);
5290 current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1)));
5291 $$ = end_block (lexer.Location);
5299 : first_from_clause query_body
5301 lexer.query_parsing = false;
5303 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5305 from.Tail.Next = (Linq.AQueryClause)$2;
5308 current_block.SetEndLocation (lexer.Location);
5309 current_block = current_block.Parent;
5311 | nested_from_clause query_body
5313 Linq.AQueryClause from = $1 as Linq.AQueryClause;
5315 from.Tail.Next = (Linq.AQueryClause)$2;
5318 current_block.SetEndLocation (lexer.Location);
5319 current_block = current_block.Parent;
5322 // Bubble up COMPLETE_COMPLETION productions
5323 | first_from_clause COMPLETE_COMPLETION {
5324 lexer.query_parsing = false;
5327 current_block.SetEndLocation (lexer.Location);
5328 current_block = current_block.Parent;
5330 | nested_from_clause COMPLETE_COMPLETION {
5332 current_block.SetEndLocation (lexer.Location);
5333 current_block = current_block.Parent;
5338 : FROM_FIRST IDENTIFIER IN expression
5340 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5342 var lt = (Tokenizer.LocatedToken) $2;
5343 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
5345 | FROM_FIRST type IDENTIFIER IN expression
5347 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5349 var lt = (Tokenizer.LocatedToken) $3;
5350 $$ = new Linq.QueryExpression (
5351 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5352 IdentifierType = (FullNamedExpression)$2
5359 : FROM IDENTIFIER IN expression
5361 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5363 var lt = (Tokenizer.LocatedToken) $2;
5364 $$ = new Linq.QueryExpression (new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$4, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)));
5366 | FROM type IDENTIFIER IN expression
5368 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5370 var lt = (Tokenizer.LocatedToken) $3;
5371 $$ = new Linq.QueryExpression (
5372 new Linq.QueryStartClause ((Linq.QueryBlock)current_block, (Expression)$5, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5373 IdentifierType = (FullNamedExpression)$2
5380 : FROM IDENTIFIER IN
5382 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5386 var lt = (Tokenizer.LocatedToken) $2;
5387 var sn = new SimpleMemberName (lt.Value, lt.Location);
5388 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$5, GetLocation ($1));
5390 current_block.SetEndLocation (lexer.Location);
5391 current_block = current_block.Parent;
5393 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5395 | FROM type IDENTIFIER IN
5397 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5401 var lt = (Tokenizer.LocatedToken) $3;
5402 var sn = new SimpleMemberName (lt.Value, lt.Location);
5404 $$ = new Linq.SelectMany ((Linq.QueryBlock)current_block, sn, (Expression)$6, GetLocation ($1)) {
5405 IdentifierType = (FullNamedExpression)$2
5408 current_block.SetEndLocation (lexer.Location);
5409 current_block = current_block.Parent;
5411 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5416 : opt_query_body_clauses select_or_group_clause opt_query_continuation
5418 Linq.AQueryClause head = (Linq.AQueryClause)$2;
5421 head.Next = (Linq.AQueryClause)$3;
5424 Linq.AQueryClause clause = (Linq.AQueryClause)$1;
5425 clause.Tail.Next = head;
5431 | opt_query_body_clauses COMPLETE_COMPLETION
5434 select_or_group_clause
5437 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5441 $$ = new Linq.Select ((Linq.QueryBlock)current_block, (Expression)$3, GetLocation ($1));
5443 current_block.SetEndLocation (lexer.Location);
5444 current_block = current_block.Parent;
5448 if (linq_clause_blocks == null)
5449 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5451 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5452 linq_clause_blocks.Push ((Linq.QueryBlock)current_block);
5456 current_block.SetEndLocation (lexer.Location);
5457 current_block = current_block.Parent;
5459 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5463 $$ = new Linq.GroupBy ((Linq.QueryBlock)current_block, (Expression)$3, linq_clause_blocks.Pop (), (Expression)$6, GetLocation ($1));
5465 current_block.SetEndLocation (lexer.Location);
5466 current_block = current_block.Parent;
5470 opt_query_body_clauses
5472 | query_body_clauses
5477 | query_body_clauses query_body_clause
5479 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$2;
5493 : LET IDENTIFIER ASSIGN
5495 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5499 var lt = (Tokenizer.LocatedToken) $2;
5500 var sn = new SimpleMemberName (lt.Value, lt.Location);
5501 $$ = new Linq.Let ((Linq.QueryBlock) current_block, sn, (Expression)$5, GetLocation ($1));
5503 current_block.SetEndLocation (lexer.Location);
5504 current_block = current_block.Parent;
5506 ((Linq.QueryBlock)current_block).AddRangeVariable (sn);
5513 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5517 $$ = new Linq.Where ((Linq.QueryBlock)current_block, (BooleanExpression)$3, GetLocation ($1));
5519 current_block.SetEndLocation (lexer.Location);
5520 current_block = current_block.Parent;
5525 : JOIN IDENTIFIER IN
5527 if (linq_clause_blocks == null)
5528 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5530 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5531 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5535 current_block.SetEndLocation (lexer.Location);
5536 current_block = current_block.Parent;
5538 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5539 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5543 current_block.AddStatement (new ContextualReturn ((Expression) $8));
5544 current_block.SetEndLocation (lexer.Location);
5545 current_block = current_block.Parent;
5547 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5549 expression opt_join_into
5551 var lt = (Tokenizer.LocatedToken) $2;
5552 var sn = new SimpleMemberName (lt.Value, lt.Location);
5553 SimpleMemberName sn2 = null;
5555 var outer_selector = linq_clause_blocks.Pop ();
5556 var block = linq_clause_blocks.Pop ();
5559 $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1));
5561 var lt2 = (Tokenizer.LocatedToken) $12;
5562 sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
5563 $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, (Linq.QueryBlock) current_block,
5564 sn2, GetLocation ($1));
5567 current_block.AddStatement (new ContextualReturn ((Expression) $11));
5568 current_block.SetEndLocation (lexer.Location);
5569 current_block = current_block.Parent;
5571 ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
5573 | JOIN type IDENTIFIER IN
5575 if (linq_clause_blocks == null)
5576 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5578 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5579 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5583 current_block.SetEndLocation (lexer.Location);
5584 current_block = current_block.Parent;
5586 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5587 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5591 current_block.AddStatement (new ContextualReturn ((Expression) $9));
5592 current_block.SetEndLocation (lexer.Location);
5593 current_block = current_block.Parent;
5595 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5597 expression opt_join_into
5599 var lt = (Tokenizer.LocatedToken) $3;
5600 var sn = new SimpleMemberName (lt.Value, lt.Location);
5601 SimpleMemberName sn2 = null;
5602 var outer_selector = linq_clause_blocks.Pop ();
5603 var block = linq_clause_blocks.Pop ();
5606 $$ = new Linq.Join (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, GetLocation ($1)) {
5607 IdentifierType = (FullNamedExpression)$2
5610 var lt2 = (Tokenizer.LocatedToken) $13;
5611 sn2 = new SimpleMemberName (lt2.Value, lt2.Location);
5612 $$ = new Linq.GroupJoin (block, sn, (Expression)$6, outer_selector, (Linq.QueryBlock) current_block, sn2, GetLocation ($1)) {
5613 IdentifierType = (FullNamedExpression)$2
5617 current_block.AddStatement (new ContextualReturn ((Expression) $12));
5618 current_block.SetEndLocation (lexer.Location);
5619 current_block = current_block.Parent;
5621 ((Linq.QueryBlock)current_block).AddRangeVariable (sn2 ?? sn);
5636 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5640 current_block.SetEndLocation (lexer.Location);
5641 current_block = current_block.Parent;
5651 current_block.SetEndLocation (lexer.Location);
5652 current_block = current_block.Parent;
5654 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5658 ((Linq.AQueryClause)$1).Next = (Linq.AQueryClause)$4;
5665 | orderings_then_by COMMA
5667 current_block.SetEndLocation (lexer.Location);
5668 current_block = current_block.Parent;
5670 current_block = new Linq.QueryBlock (compiler, (Linq.QueryBlock) current_block, lexer.Location);
5674 ((Linq.AQueryClause)$1).Tail.Next = (Linq.AQueryClause)$4;
5682 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5684 | expression ASCENDING
5686 $$ = new Linq.OrderByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5688 | expression DESCENDING
5690 $$ = new Linq.OrderByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5697 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5699 | expression ASCENDING
5701 $$ = new Linq.ThenByAscending ((Linq.QueryBlock) current_block, (Expression)$1);
5703 | expression DESCENDING
5705 $$ = new Linq.ThenByDescending ((Linq.QueryBlock) current_block, (Expression)$1);
5710 opt_query_continuation
5714 // query continuation block is not linked with query block but with block
5715 // before. This means each query can use same range variable names for
5716 // different identifiers.
5718 current_block.SetEndLocation (GetLocation ($1));
5719 current_block = current_block.Parent;
5721 current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
5723 if (linq_clause_blocks == null)
5724 linq_clause_blocks = new Stack<Linq.QueryBlock> ();
5726 linq_clause_blocks.Push ((Linq.QueryBlock) current_block);
5730 var current_block = linq_clause_blocks.Pop ();
5731 var lt = (Tokenizer.LocatedToken) $2;
5732 $$ = new Linq.QueryStartClause ((Linq.QueryBlock)current_block, null, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)) {
5733 next = (Linq.AQueryClause)$4
5739 // Support for using the compiler as an interactive parser
5741 // The INTERACTIVE_PARSER token is first sent to parse our
5742 // productions; If the result is a Statement, the parsing
5743 // is repeated, this time with INTERACTIVE_PARSE_WITH_BLOCK
5744 // to setup the blocks in advance.
5746 // This setup is here so that in the future we can add
5747 // support for other constructs (type parsing, namespaces, etc)
5748 // that do not require a block to be setup in advance
5752 : EVAL_STATEMENT_PARSER EOF
5753 | EVAL_USING_DECLARATIONS_UNIT_PARSER using_directives
5754 | EVAL_STATEMENT_PARSER {
5755 Evaluator.LoadAliases (current_namespace);
5757 push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
5758 Modifiers.PUBLIC, null), null);
5760 var baseclass_list = new List<FullNamedExpression> ();
5761 baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
5762 current_container.AddBasesForPart (current_class, baseclass_list);
5764 // (ref object retval)
5765 Parameter [] mpar = new Parameter [1];
5766 mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
5768 ParametersCompiled pars = new ParametersCompiled (compiler, mpar);
5769 current_local_parameters = pars;
5770 Method method = new Method (
5773 new TypeExpression (TypeManager.void_type, Location.Null),
5774 Modifiers.PUBLIC | Modifiers.STATIC,
5775 new MemberName ("Host"),
5777 null /* attributes */);
5779 oob_stack.Push (method);
5780 ++lexer.parsing_block;
5781 start_block (lexer.Location);
5783 interactive_statement_list opt_COMPLETE_COMPLETION
5785 --lexer.parsing_block;
5786 Method method = (Method) oob_stack.Pop ();
5788 method.Block = (ToplevelBlock) end_block(lexer.Location);
5789 current_container.AddMethod (method);
5791 --lexer.parsing_declaration;
5792 InteractiveResult = pop_current_class ();
5793 current_local_parameters = null;
5795 | EVAL_COMPILATION_UNIT_PARSER {
5796 Evaluator.LoadAliases (current_namespace);
5798 interactive_compilation_unit
5801 interactive_compilation_unit
5802 : outer_declarations
5803 | outer_declarations global_attributes
5808 opt_COMPLETE_COMPLETION
5810 | COMPLETE_COMPLETION
5813 close_brace_or_complete_completion
5815 | COMPLETE_COMPLETION
5820 // A class used to pass around variable declarations and constants
5822 class VariableDeclaration {
5823 public string identifier;
5824 Expression initializer;
5825 public Location Location;
5826 public Attributes OptAttributes;
5827 public string DocComment;
5829 public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer, Attributes opt_attrs)
5831 this.identifier = lt.Value;
5832 this.initializer = initializer;
5833 this.Location = lt.Location;
5834 this.OptAttributes = opt_attrs;
5837 public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
5838 : this (lt, initializer, null)
5842 public Expression GetInitializer (FullNamedExpression type)
5844 if (initializer is ArrayInitializer)
5845 return new ArrayCreation (type, (ArrayInitializer)initializer);
5850 public bool HasInitializer {
5851 get { return initializer != null; }
5855 class VariableMemberDeclaration
5857 public readonly MemberName MemberName;
5858 Expression initializer;
5860 public VariableMemberDeclaration (MemberName mn, Expression initializer)
5863 this.initializer = initializer;
5866 public Expression GetInitializer (FullNamedExpression type)
5868 if (initializer is ArrayInitializer)
5869 return new ArrayCreation (type, (ArrayInitializer)initializer);
5877 // A class used to hold info about an operator declarator
5879 struct OperatorDeclaration {
5880 public readonly Operator.OpType optype;
5881 public readonly FullNamedExpression ret_type;
5882 public readonly Location location;
5884 public OperatorDeclaration (Operator.OpType op, FullNamedExpression ret_type, Location location)
5887 this.ret_type = ret_type;
5888 this.location = location;
5892 void Error_ExpectingTypeName (Expression expr)
5894 if (expr is Invocation){
5895 Report.Error (1002, expr.Location, "Expecting `;'");
5897 Expression.Error_InvalidExpressionStatement (Report, expr.Location);
5901 void Error_ParameterModifierNotValid (string modifier, Location loc)
5903 Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
5907 void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5909 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5910 Parameter.GetModifierSignature (mod));
5913 void Error_TypeExpected (Location loc)
5915 Report.Error (1031, loc, "Type expected");
5918 void Error_UnsafeCodeNotAllowed (Location loc)
5920 Report.Error (227, loc, "Unsafe code requires the `unsafe' command line option to be specified");
5923 void Error_NamedArgumentExpected (NamedArgument a)
5925 Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments");
5928 void push_current_class (TypeContainer tc, object partial_token)
5930 if (RootContext.EvalMode){
5931 tc.ModFlags = (tc.ModFlags & ~(Modifiers.PRIVATE|Modifiers.INTERNAL)) | Modifiers.PUBLIC;
5932 undo.AddTypeContainer (current_container, tc);
5935 if (partial_token != null)
5936 current_container = current_container.AddPartial (tc);
5938 current_container = current_container.AddTypeContainer (tc);
5940 ++lexer.parsing_declaration;
5944 DeclSpace pop_current_class ()
5946 DeclSpace retval = current_class;
5948 current_class = current_class.Parent;
5949 current_container = current_class.PartialContainer;
5955 // Given the @class_name name, it creates a fully qualified name
5956 // based on the containing declaration space
5959 MakeName (MemberName class_name)
5961 Namespace ns = current_namespace.NS;
5963 if (current_container == RootContext.ToplevelTypes) {
5964 if (ns.Name.Length != 0)
5965 return new MemberName (ns.MemberName, class_name);
5969 return new MemberName (current_container.MemberName, class_name);
5973 Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
5975 Block implicit_block;
5978 // If we are doing interactive editing, we want variable declarations
5979 // that are in the top block to be added instead to the class as
5982 if (RootContext.StatementMode){
5985 for (Block b = current_block; b != null; b = b.Parent){
5986 if (b is ExplicitBlock && !(b is ToplevelBlock)){
5987 // There has been an explicit block, we cant add to the class
5994 // We can use "current_block" since we know there are no explicit blocks
5996 foreach (VariableDeclaration decl in variable_declarators){
5997 // We can not use the super-handy f.Initializer, because
5998 // multiple lines would force code to be executed out of sync
5999 var init = decl.GetInitializer (type);
6001 string id = "$" + decl.identifier;
6002 LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
6004 // Avoid warning about this variable not being used.
6007 LocalVariableReference var;
6008 var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
6009 Assign assign = new SimpleAssign (var, init, decl.Location);
6010 current_block.AddStatement (new StatementExpression (assign));
6011 assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
6012 current_block.AddStatement (new StatementExpression (assign));
6014 Field f = new Field (current_container, (FullNamedExpression) type, Modifiers.PUBLIC | Modifiers.STATIC,
6015 new MemberName (decl.identifier, loc), null);
6016 current_container.AddField (f);
6018 // Register the field to be visible later as a global variable
6019 Evaluator.QueueField (f);
6023 return current_block;
6028 // We use the `Used' property to check whether statements
6029 // have been added to the current block. If so, we need
6030 // to create another block to contain the new declaration
6031 // otherwise, as an optimization, we use the same block to
6032 // add the declaration.
6034 // FIXME: A further optimization is to check if the statements
6035 // that were added were added as part of the initialization
6036 // below. In which case, no other statements have been executed
6037 // and we might be able to reduce the number of blocks for
6038 // situations like this:
6040 // int j = 1; int k = j + 1;
6042 if (current_block.Used)
6043 implicit_block = new Block (current_block, loc, lexer.Location);
6045 implicit_block = current_block;
6047 foreach (VariableDeclaration decl in variable_declarators){
6049 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
6050 if (decl.HasInitializer){
6053 var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
6055 assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
6057 implicit_block.AddStatement (new StatementExpression (assign));
6062 return implicit_block;
6065 Block declare_local_constants (FullNamedExpression type, List<object> declarators)
6067 Block implicit_block;
6069 if (current_block.Used)
6070 implicit_block = new Block (current_block);
6072 implicit_block = current_block;
6074 foreach (VariableDeclaration decl in declarators){
6075 implicit_block.AddConstant (type, decl.identifier, decl.GetInitializer (type), decl.Location);
6078 return implicit_block;
6081 string CheckAttributeTarget (string a, Location l)
6084 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
6088 Report.Warning (658, 1, l,
6089 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
6090 return string.Empty;
6093 static bool IsUnaryOperator (Operator.OpType op)
6097 case Operator.OpType.LogicalNot:
6098 case Operator.OpType.OnesComplement:
6099 case Operator.OpType.Increment:
6100 case Operator.OpType.Decrement:
6101 case Operator.OpType.True:
6102 case Operator.OpType.False:
6103 case Operator.OpType.UnaryPlus:
6104 case Operator.OpType.UnaryNegation:
6110 void syntax_error (Location l, string msg)
6112 Report.Error (1003, l, "Syntax error, " + msg);
6117 public Tokenizer Lexer {
6123 static CSharpParser ()
6125 oob_stack = new Stack<object> ();
6128 public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
6130 if (RootContext.EvalMode)
6134 this.compiler = ctx;
6135 current_namespace = new NamespaceEntry (null, file, null);
6136 current_class = current_namespace.SlaveDeclSpace;
6137 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
6139 lexer = new Tokenizer (reader, file, ctx);
6141 use_global_stacks = true;
6144 public void parse ()
6146 eof_token = Token.EOF;
6147 Tokenizer.LocatedToken.Initialize ();
6150 if (yacc_verbose_flag > 1)
6151 yyparse (lexer, new yydebug.yyDebugSimple ());
6155 Tokenizer tokenizer = lexer as Tokenizer;
6156 tokenizer.cleanup ();
6157 } catch (Exception e){
6158 if (e is yyParser.yyUnexpectedEof)
6159 UnexpectedEOF = true;
6161 if (e is yyParser.yyException)
6162 Report.Error (-25, lexer.Location, "Parsing error");
6163 else if (yacc_verbose_flag > 0)
6164 throw; // Used by compiler-tester to test internal errors
6166 Report.Error (589, lexer.Location, "Internal compiler error during parsing");
6169 if (RootContext.ToplevelTypes.NamespaceEntry != null)
6170 throw new InternalErrorException ("who set it?");
6173 void CheckToken (int error, int yyToken, string msg, Location loc)
6175 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
6176 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken));
6178 Report.Error (error, loc, msg);
6181 void CheckIdentifierToken (int yyToken, Location loc)
6183 CheckToken (1041, yyToken, "Identifier expected", loc);
6186 string ConsumeStoredComment ()
6188 string s = tmpComment;
6190 Lexer.doc_state = XmlCommentState.Allowed;
6194 Location GetLocation (object obj)
6196 if (obj is Tokenizer.LocatedToken)
6197 return ((Tokenizer.LocatedToken) obj).Location;
6198 if (obj is MemberName)
6199 return ((MemberName) obj).Location;
6201 if (obj is Expression)
6202 return ((Expression) obj).Location;
6204 return lexer.Location;
6208 get { return compiler.Report; }
6211 void start_block (Location loc)
6213 if (current_block == null || parsing_anonymous_method) {
6214 current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, loc);
6215 parsing_anonymous_method = false;
6217 current_block = new ExplicitBlock (current_block, loc, Location.Null);
6222 end_block (Location loc)
6224 Block retval = current_block.Explicit;
6225 retval.SetEndLocation (loc);
6226 current_block = retval.Parent;
6231 start_anonymous (bool lambda, ParametersCompiled parameters, Location loc)
6233 if (RootContext.Version == LanguageVersion.ISO_1){
6234 Report.FeatureIsNotAvailable (loc, "anonymous methods");
6237 oob_stack.Push (current_anonymous_method);
6238 oob_stack.Push (current_local_parameters);
6240 current_local_parameters = parameters;
6242 current_anonymous_method = lambda
6243 ? new LambdaExpression (loc)
6244 : new AnonymousMethodExpression (loc);
6246 // Force the next block to be created as a ToplevelBlock
6247 parsing_anonymous_method = true;
6251 * Completes the anonymous method processing, if lambda_expr is null, this
6252 * means that we have a Statement instead of an Expression embedded
6254 AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block)
6256 AnonymousMethodExpression retval;
6258 current_anonymous_method.Block = anon_block;
6259 retval = current_anonymous_method;
6261 current_local_parameters = (ParametersCompiled) oob_stack.Pop ();
6262 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
6267 public NamespaceEntry CurrentNamespace {
6269 return current_namespace;
6274 void Error_SyntaxError (int token)
6276 Error_SyntaxError (0, token, "Unexpected symbol");
6279 void Error_SyntaxError (int error_code, int token, string msg)
6281 string symbol = GetSymbolName (token);
6282 string expecting = GetExpecting ();
6284 if (error_code == 0) {
6285 if (expecting == "`)'")
6291 if (string.IsNullOrEmpty (expecting))
6292 Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg);
6294 Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", symbol, expecting, msg);
6297 string GetExpecting ()
6299 int [] tokens = yyExpectingTokens (yyExpectingState);
6300 var names = new List<string> (tokens.Length);
6301 bool has_type = false;
6302 bool has_identifier = false;
6303 for (int i = 0; i < tokens.Length; i++){
6304 int token = tokens [i];
6305 has_identifier |= token == Token.IDENTIFIER;
6307 string name = GetTokenName (token);
6308 if (name == "<internal>")
6311 has_type |= name == "type";
6312 if (names.Contains (name))
6319 // Too many tokens to enumerate
6321 if (names.Count > 8)
6324 if (has_type && has_identifier)
6325 names.Remove ("identifier");
6327 if (names.Count == 1)
6328 return "`" + GetTokenName (tokens [0]) + "'";
6330 StringBuilder sb = new StringBuilder ();
6332 int count = names.Count;
6333 for (int i = 0; i < count; i++){
6334 bool last = i + 1 == count;
6338 sb.Append (names [i]);
6339 sb.Append (last ? "'" : count < 3 ? "' " : "', ");
6341 return sb.ToString ();
6345 string GetSymbolName (int token)
6349 return ((Constant)lexer.Value).GetValue ().ToString ();
6350 case Token.IDENTIFIER:
6351 return ((Tokenizer.LocatedToken)lexer.Value).Value;
6393 case Token.BITWISE_AND:
6395 case Token.BITWISE_OR:
6409 case Token.OP_SHIFT_LEFT:
6411 case Token.OP_SHIFT_RIGHT:
6431 case Token.OP_COALESCING:
6433 case Token.OP_MULT_ASSIGN:
6435 case Token.OP_DIV_ASSIGN:
6437 case Token.OP_MOD_ASSIGN:
6439 case Token.OP_ADD_ASSIGN:
6441 case Token.OP_SUB_ASSIGN:
6443 case Token.OP_SHIFT_LEFT_ASSIGN:
6445 case Token.OP_SHIFT_RIGHT_ASSIGN:
6447 case Token.OP_AND_ASSIGN:
6449 case Token.OP_XOR_ASSIGN:
6451 case Token.OP_OR_ASSIGN:
6455 return GetTokenName (token);
6458 static string GetTokenName (int token)
6461 case Token.ABSTRACT:
6481 case Token.CONTINUE:
6485 case Token.DELEGATE:
6495 case Token.EXPLICIT:
6513 case Token.IMPLICIT:
6517 case Token.INTERFACE:
6519 case Token.INTERNAL:
6525 case Token.NAMESPACE:
6531 case Token.OPERATOR:
6535 case Token.OVERRIDE:
6541 case Token.PROTECTED:
6545 case Token.READONLY:
6557 case Token.STACKALLOC:
6558 return "stackalloc";
6575 case Token.UNCHECKED:
6583 case Token.VOLATILE:
6596 case Token.FROM_FIRST:
6614 case Token.ASCENDING:
6616 case Token.DESCENDING:
6617 return "descending";
6624 case Token.OPEN_BRACE:
6626 case Token.CLOSE_BRACE:
6628 case Token.OPEN_BRACKET:
6629 case Token.OPEN_BRACKET_EXPR:
6631 case Token.CLOSE_BRACKET:
6633 case Token.OPEN_PARENS_CAST:
6634 case Token.OPEN_PARENS_LAMBDA:
6635 case Token.OPEN_PARENS:
6637 case Token.CLOSE_PARENS:
6643 case Token.DEFAULT_COLON:
6647 case Token.SEMICOLON:
6658 case Token.BITWISE_AND:
6659 case Token.BITWISE_OR:
6666 case Token.OP_SHIFT_LEFT:
6667 case Token.OP_SHIFT_RIGHT:
6675 case Token.OP_COALESCING:
6676 case Token.OP_MULT_ASSIGN:
6677 case Token.OP_DIV_ASSIGN:
6678 case Token.OP_MOD_ASSIGN:
6679 case Token.OP_ADD_ASSIGN:
6680 case Token.OP_SUB_ASSIGN:
6681 case Token.OP_SHIFT_LEFT_ASSIGN:
6682 case Token.OP_SHIFT_RIGHT_ASSIGN:
6683 case Token.OP_AND_ASSIGN:
6684 case Token.OP_XOR_ASSIGN:
6685 case Token.OP_OR_ASSIGN:
6686 return "<operator>";
6708 case Token.OP_GENERICS_LT:
6709 case Token.GENERIC_DIMENSION:
6711 case Token.OP_GENERICS_GT:
6714 case Token.INTERR_NULLABLE:
6716 case Token.DOUBLE_COLON:
6720 case Token.IDENTIFIER:
6721 return "identifier";
6723 // All of these are internal.
6726 case Token.FIRST_KEYWORD:
6728 case Token.EVAL_COMPILATION_UNIT_PARSER:
6729 case Token.EVAL_USING_DECLARATIONS_UNIT_PARSER:
6730 case Token.EVAL_STATEMENT_PARSER:
6731 case Token.LAST_KEYWORD:
6732 case Token.GENERATE_COMPLETION:
6733 case Token.COMPLETE_COMPLETION:
6734 return "<internal>";
6736 // A bit more robust.
6738 return yyNames [token];