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 // Licensed under the terms of the GNU GPL
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:
19 // Possible optimization:
20 // Run memory profiler with parsing only, and consider dropping
21 // arraylists where not needed. Some pieces can use linked lists.
29 using System.Collections;
34 public class CSharpParser {
35 NamespaceEntry current_namespace;
36 TypeContainer current_container;
37 DeclSpace current_class;
39 IAnonymousHost anonymous_host;
42 /// Current block is used to add statements as we find
45 Block current_block, top_current_block;
47 Delegate current_delegate;
49 GenericMethod current_generic_method;
50 AnonymousMethodExpression current_anonymous_method;
53 /// This is used by the unary_expression code to resolve
54 /// a name against a parameter.
56 Parameters current_local_parameters;
59 /// Using during property parsing to describe the implicit
60 /// value parameter that is passed to the "set" and "get"accesor
61 /// methods (properties and indexers).
63 Expression implicit_value_parameter_type;
64 Parameters indexer_parameters;
67 /// Hack to help create non-typed array initializer
69 public static Expression current_array_type;
70 Expression pushed_current_array_type;
73 /// Used to determine if we are parsing the get/set pair
74 /// of an indexer or a property
78 bool parsing_anonymous_method;
81 /// An out-of-band stack.
83 static Stack oob_stack;
90 static public int yacc_verbose_flag;
92 // Name of the file we are parsing
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;
112 bool has_get, has_set;
117 %token NONE /* This token is never returned by our lexer */
118 %token ERROR // This is used not by the parser, but by the tokenizer.
122 *These are the C# keywords
209 %token QUERY_FIRST_TOKEN
222 %token QUERY_LAST_TOKEN
224 /* C# keywords which are not really keywords */
230 /* C# single character operators/punctuation. */
231 %token OPEN_BRACE "{"
232 %token CLOSE_BRACE "}"
233 %token OPEN_BRACKET "["
234 %token CLOSE_BRACKET "]"
235 %token OPEN_PARENS "("
236 %token CLOSE_PARENS ")"
248 %token OP_GENERICS_LT "<"
250 %token OP_GENERICS_GT ">"
251 %token BITWISE_AND "&"
252 %token BITWISE_OR "|"
259 /* C# multi-character operators. */
260 %token DOUBLE_COLON "::"
263 %token OP_SHIFT_LEFT "<<"
264 %token OP_SHIFT_RIGHT ">>"
271 %token OP_MULT_ASSIGN "*="
272 %token OP_DIV_ASSIGN "/="
273 %token OP_MOD_ASSIGN "%="
274 %token OP_ADD_ASSIGN "+="
275 %token OP_SUB_ASSIGN "-="
276 %token OP_SHIFT_LEFT_ASSIGN "<<="
277 %token OP_SHIFT_RIGHT_ASSIGN ">>="
278 %token OP_AND_ASSIGN "&="
279 %token OP_XOR_ASSIGN "^="
280 %token OP_OR_ASSIGN "|="
284 %token LITERAL_INTEGER "int literal"
285 %token LITERAL_FLOAT "float literal"
286 %token LITERAL_DOUBLE "double literal"
287 %token LITERAL_DECIMAL "decimal literal"
288 %token LITERAL_CHARACTER "character literal"
289 %token LITERAL_STRING "string literal"
292 %token OPEN_PARENS_LAMBDA
293 %token CLOSE_PARENS_CAST
294 %token CLOSE_PARENS_NO_CAST
295 %token CLOSE_PARENS_OPEN_PARENS
296 %token CLOSE_PARENS_MINUS
297 %token DEFAULT_OPEN_PARENS
298 %token GENERIC_DIMENSION
301 /* Add precedence rules to solve dangling else s/r conflict */
310 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
312 %left STAR DIV PERCENT
313 %right BANG CARRET UMINUS
314 %nonassoc OP_INC OP_DEC
316 %left OPEN_BRACKET OPEN_BRACE
320 %start compilation_unit
324 : outer_declarations opt_EOF
325 | outer_declarations global_attributes opt_EOF
326 | global_attributes opt_EOF
327 | opt_EOF /* allow empty files */
333 Lexer.check_incorrect_doc_comment ();
337 Lexer.check_incorrect_doc_comment ();
343 | outer_declarations outer_declaration
347 : extern_alias_directive
349 | namespace_member_declaration
352 extern_alias_directives
353 : extern_alias_directive
354 | extern_alias_directives extern_alias_directive;
356 extern_alias_directive
357 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
359 LocatedToken lt = (LocatedToken) $2;
362 Report.Error (1003, lt.Location, "'alias' expected");
363 } else if (RootContext.Version == LanguageVersion.ISO_1) {
364 Report.FeatureIsNotISO1 (lt.Location, "external alias");
366 lt = (LocatedToken) $3;
367 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
374 | using_directives using_directive
378 : using_alias_directive
380 if (RootContext.Documentation != null)
381 Lexer.doc_state = XmlCommentState.Allowed;
383 | using_namespace_directive
385 if (RootContext.Documentation != null)
386 Lexer.doc_state = XmlCommentState.Allowed;
390 using_alias_directive
391 : USING IDENTIFIER ASSIGN
392 namespace_or_type_name SEMICOLON
394 LocatedToken lt = (LocatedToken) $2;
395 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
398 CheckIdentifierToken (yyToken, GetLocation ($2));
402 using_namespace_directive
403 : USING namespace_name SEMICOLON
405 current_namespace.Using ((MemberName) $2, (Location) $1);
410 // Strictly speaking, namespaces don't have attributes but
411 // we parse global attributes along with namespace declarations and then
414 namespace_declaration
415 : opt_attributes NAMESPACE namespace_or_type_name
417 MemberName name = (MemberName) $3;
420 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
423 if (name.TypeArguments != null)
424 syntax_error (lexer.Location, "namespace name expected");
426 current_namespace = new NamespaceEntry (
427 current_namespace, file, name.GetName ());
428 current_class = current_namespace.SlaveDeclSpace;
429 current_container = current_class.PartialContainer;
431 namespace_body opt_semicolon
433 current_namespace = current_namespace.Parent;
434 current_class = current_namespace.SlaveDeclSpace;
435 current_container = current_class.PartialContainer;
450 : namespace_or_type_name {
451 MemberName name = (MemberName) $1;
453 if (name.TypeArguments != null)
454 syntax_error (lexer.Location, "namespace name expected");
463 if (RootContext.Documentation != null)
464 Lexer.doc_state = XmlCommentState.Allowed;
470 : opt_extern_alias_directives
472 opt_namespace_member_declarations
476 Report.Error (1518, lexer.Location, "Expected `class', `delegate', `enum', `interface', or `struct'");
479 | opt_extern_alias_directives
481 opt_namespace_member_declarations
484 Report.Error (1513, lexer.Location, "} expected");
493 opt_extern_alias_directives
495 | extern_alias_directives
498 opt_namespace_member_declarations
500 | namespace_member_declarations
503 namespace_member_declarations
504 : namespace_member_declaration
505 | namespace_member_declarations namespace_member_declaration
508 namespace_member_declaration
512 DeclSpace ds = (DeclSpace)$1;
514 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
515 Report.Error (1527, ds.Location,
516 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
519 current_namespace.DeclarationFound = true;
521 | namespace_declaration {
522 current_namespace.DeclarationFound = true;
525 | field_declaration {
526 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
528 | method_declaration {
529 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
536 | interface_declaration
538 | delegate_declaration
540 // Enable this when we have handled all errors, because this acts as a generic fallback
543 // Console.WriteLine ("Token=" + yyToken);
544 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
556 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
564 global_attrs_enabled = false;
569 global_attrs_enabled = false;
578 if (current_attr_target != String.Empty) {
579 ArrayList sect = (ArrayList) $1;
581 if (global_attrs_enabled) {
582 if (current_attr_target == "module") {
583 CodeGen.Module.AddAttributes (sect);
585 } else if (current_attr_target != null && current_attr_target.Length > 0) {
586 CodeGen.Assembly.AddAttributes (sect);
589 $$ = new Attributes (sect);
592 if (RootContext.Documentation != null) {
593 Lexer.check_incorrect_doc_comment ();
595 XmlCommentState.Allowed;
599 $$ = new Attributes (sect);
604 current_attr_target = null;
606 | attribute_sections attribute_section
608 if (current_attr_target != String.Empty) {
609 Attributes attrs = $1 as Attributes;
610 ArrayList sect = (ArrayList) $2;
612 if (global_attrs_enabled) {
613 if (current_attr_target == "module") {
614 CodeGen.Module.AddAttributes (sect);
616 } else if (current_attr_target == "assembly") {
617 CodeGen.Assembly.AddAttributes (sect);
621 attrs = new Attributes (sect);
623 attrs.AddAttributes (sect);
627 attrs = new Attributes (sect);
629 attrs.AddAttributes (sect);
635 current_attr_target = null;
640 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
644 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
650 attribute_target_specifier
651 : attribute_target COLON
653 current_attr_target = (string)$1;
661 LocatedToken lt = (LocatedToken) $1;
662 $$ = CheckAttributeTarget (lt.Value, lt.Location);
664 | EVENT { $$ = "event"; }
665 | RETURN { $$ = "return"; }
668 string name = yyNames [yyToken].ToLower ();
669 $$ = CheckAttributeTarget (name, GetLocation ($1));
676 ArrayList attrs = new ArrayList (4);
682 | attribute_list COMMA attribute
684 ArrayList attrs = (ArrayList) $1;
692 : attribute_name opt_attribute_arguments
694 MemberName mname = (MemberName) $1;
695 if (mname.IsGeneric) {
696 Report.Error (404, lexer.Location,
697 "'<' unexpected: attributes cannot be generic");
700 object [] arguments = (object []) $2;
701 MemberName left = mname.Left;
702 string identifier = mname.Name;
704 Expression left_expr = left == null ? null : left.GetTypeExpression ();
706 if (current_attr_target == String.Empty)
708 else if (current_attr_target == "assembly" || current_attr_target == "module")
709 // FIXME: supply "nameEscaped" parameter here.
710 $$ = new GlobalAttribute (current_namespace, current_attr_target,
711 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
713 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
718 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
721 opt_attribute_arguments
722 : /* empty */ { $$ = null; }
723 | OPEN_PARENS attribute_arguments CLOSE_PARENS
731 : opt_positional_argument_list
736 $$ = new object [] { $1, null };
739 | positional_argument_list COMMA named_argument_list
741 $$ = new object[] { $1, $3 };
743 | named_argument_list
745 $$ = new object [] { null, $1 };
750 opt_positional_argument_list
751 : /* empty */ { $$ = null; }
752 | positional_argument_list
755 positional_argument_list
758 ArrayList args = new ArrayList (4);
759 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
763 | positional_argument_list COMMA expression
765 ArrayList args = (ArrayList) $1;
766 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
775 ArrayList args = new ArrayList (4);
780 | named_argument_list COMMA named_argument
782 ArrayList args = (ArrayList) $1;
787 | named_argument_list COMMA expression
789 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
795 : IDENTIFIER ASSIGN expression
797 // FIXME: keep location
798 $$ = new DictionaryEntry (
799 ((LocatedToken) $1).Value,
800 new Argument ((Expression) $3, Argument.AType.Expression));
806 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
809 opt_class_member_declarations
811 | class_member_declarations
814 class_member_declarations
815 : class_member_declaration
816 | class_member_declarations
817 class_member_declaration
820 class_member_declaration
821 : constant_declaration // done
822 | field_declaration // done
823 | method_declaration // done
824 | property_declaration // done
825 | event_declaration // done
826 | indexer_declaration // done
827 | operator_declaration // done
828 | constructor_declaration // done
829 | destructor_declaration // done
839 lexer.ConstraintsParsing = true;
843 MemberName name = MakeName ((MemberName) $6);
844 push_current_class (new Struct (
845 current_namespace, current_class, name, (int) $2,
846 (Attributes) $1), false, $3);
849 opt_type_parameter_constraints_clauses
851 lexer.ConstraintsParsing = false;
854 current_container.AddBasesForPart (current_class, (ArrayList) $8);
856 current_class.SetParameterInfo ((ArrayList) $9);
858 if (RootContext.Documentation != null)
859 current_container.DocComment = Lexer.consume_doc_comment ();
863 if (RootContext.Documentation != null)
864 Lexer.doc_state = XmlCommentState.Allowed;
868 $$ = pop_current_class ();
870 | opt_attributes opt_modifiers opt_partial STRUCT error {
871 CheckIdentifierToken (yyToken, GetLocation ($5));
878 if (RootContext.Documentation != null)
879 Lexer.doc_state = XmlCommentState.Allowed;
881 opt_struct_member_declarations CLOSE_BRACE
884 opt_struct_member_declarations
886 | struct_member_declarations
889 struct_member_declarations
890 : struct_member_declaration
891 | struct_member_declarations struct_member_declaration
894 struct_member_declaration
895 : constant_declaration
898 | property_declaration
900 | indexer_declaration
901 | operator_declaration
902 | constructor_declaration
906 * This is only included so we can flag error 575:
907 * destructors only allowed on class types
909 | destructor_declaration
920 int modflags = (int) $2;
921 foreach (VariableDeclaration constant in (ArrayList) $5){
922 Location l = constant.Location;
923 if ((modflags & Modifiers.STATIC) != 0) {
924 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
928 Const c = new Const (
929 current_class, (Expression) $4, (string) constant.identifier,
930 (Expression) constant.expression_or_array_initializer, modflags,
933 if (RootContext.Documentation != null) {
934 c.DocComment = Lexer.consume_doc_comment ();
935 Lexer.doc_state = XmlCommentState.Allowed;
937 current_container.AddConstant (c);
943 : constant_declarator
945 ArrayList constants = new ArrayList (4);
950 | constant_declarators COMMA constant_declarator
953 ArrayList constants = (ArrayList) $1;
960 : IDENTIFIER ASSIGN constant_expression
962 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
966 // A const field requires a value to be provided
967 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
979 Expression type = (Expression) $3;
982 current_array_type = null;
984 foreach (VariableDeclaration var in (ArrayList) $4){
985 Field field = new Field (current_class, type, mod, var.identifier,
986 (Attributes) $1, var.Location);
988 field.Initializer = var.expression_or_array_initializer;
990 if (RootContext.Documentation != null) {
991 field.DocComment = Lexer.consume_doc_comment ();
992 Lexer.doc_state = XmlCommentState.Allowed;
994 current_container.AddField (field);
995 $$ = field; // FIXME: might be better if it points to the top item
1002 fixed_variable_declarators
1005 Expression type = (Expression) $4;
1008 current_array_type = null;
1010 foreach (VariableDeclaration var in (ArrayList) $5) {
1011 FixedField field = new FixedField (current_class, type, mod, var.identifier,
1012 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
1014 if (RootContext.Documentation != null) {
1015 field.DocComment = Lexer.consume_doc_comment ();
1016 Lexer.doc_state = XmlCommentState.Allowed;
1018 current_container.AddField (field);
1019 $$ = field; // FIXME: might be better if it points to the top item
1028 Report.Error (1641, GetLocation ($4), "A fixed size buffer field must have the array size specifier after the field name");
1033 variable_declarators
1035 current_array_type = null;
1036 Report.Error (670, (Location) $3, "Fields cannot have void type");
1040 fixed_variable_declarators
1041 : fixed_variable_declarator
1043 ArrayList decl = new ArrayList (2);
1047 | fixed_variable_declarators COMMA fixed_variable_declarator
1049 ArrayList decls = (ArrayList) $1;
1055 fixed_variable_declarator
1056 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1058 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1060 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1062 Report.Error (443, lexer.Location, "Value or constant expected");
1063 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1067 variable_declarators
1068 : variable_declarator
1070 ArrayList decl = new ArrayList (4);
1075 | variable_declarators COMMA variable_declarator
1077 ArrayList decls = (ArrayList) $1;
1084 : IDENTIFIER ASSIGN variable_initializer
1086 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1090 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1092 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1094 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1095 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1100 variable_initializer
1109 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1111 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1115 $$ = new ArglistAccess ((Location) $1);
1119 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1126 anonymous_host = (IAnonymousHost) $1;
1127 if (RootContext.Documentation != null)
1128 Lexer.doc_state = XmlCommentState.NotAllowed;
1132 Method method = (Method) $1;
1133 method.Block = (ToplevelBlock) $3;
1134 current_container.AddMethod (method);
1136 anonymous_host = null;
1137 current_generic_method = null;
1138 current_local_parameters = null;
1140 if (RootContext.Documentation != null)
1141 Lexer.doc_state = XmlCommentState.Allowed;
1154 Report.Error (1585, lexer.Location,
1155 "Member modifier `{0}' must precede the member type and name",
1156 Modifiers.Name (i));
1165 // This rule is used to handle the cases where OPEN_PARENS_LAMBDA
1166 // is returned (type followed by an identifier), these are the
1167 // declarations (methods, overloads, constructors, etc) and a handful
1168 // of expressions ("using", "fixed") or "catch".
1172 | OPEN_PARENS_LAMBDA
1178 type namespace_or_type_name
1179 open_parens opt_formal_parameter_list CLOSE_PARENS
1181 lexer.ConstraintsParsing = true;
1183 opt_type_parameter_constraints_clauses
1185 lexer.ConstraintsParsing = false;
1187 MemberName name = (MemberName) $4;
1189 if ($9 != null && name.TypeArguments == null)
1190 Report.Error (80, lexer.Location,
1191 "Constraints are not allowed on non-generic declarations");
1195 GenericMethod generic = null;
1196 if (name.TypeArguments != null) {
1197 generic = new GenericMethod (current_namespace, current_class, name,
1198 (Expression) $3, (Parameters) $6);
1200 generic.SetParameterInfo ((ArrayList) $9);
1203 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1204 name, (Parameters) $6, (Attributes) $1);
1206 anonymous_host = method;
1207 current_local_parameters = (Parameters) $6;
1208 current_generic_method = generic;
1210 if (RootContext.Documentation != null)
1211 method.DocComment = Lexer.consume_doc_comment ();
1217 VOID namespace_or_type_name
1218 open_parens opt_formal_parameter_list CLOSE_PARENS
1220 lexer.ConstraintsParsing = true;
1222 opt_type_parameter_constraints_clauses
1224 lexer.ConstraintsParsing = false;
1226 MemberName name = (MemberName) $4;
1228 if ($9 != null && name.TypeArguments == null)
1229 Report.Error (80, lexer.Location,
1230 "Constraints are not allowed on non-generic declarations");
1233 GenericMethod generic = null;
1234 if (name.TypeArguments != null) {
1235 generic = new GenericMethod (current_namespace, current_class, name,
1236 TypeManager.system_void_expr, (Parameters) $6);
1238 generic.SetParameterInfo ((ArrayList) $9);
1241 method = new Method (current_class, generic, TypeManager.system_void_expr,
1242 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1244 anonymous_host = method;
1245 current_local_parameters = (Parameters) $6;
1246 current_generic_method = generic;
1248 if (RootContext.Documentation != null)
1249 method.DocComment = Lexer.consume_doc_comment ();
1256 modifiers namespace_or_type_name open_parens opt_formal_parameter_list CLOSE_PARENS
1258 MemberName name = (MemberName) $5;
1259 Report.Error (1585, name.Location,
1260 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1262 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1263 0, false, name, (Parameters) $6, (Attributes) $1);
1265 current_local_parameters = (Parameters) $6;
1267 if (RootContext.Documentation != null)
1268 method.DocComment = Lexer.consume_doc_comment ();
1276 | SEMICOLON { $$ = null; }
1279 opt_formal_parameter_list
1280 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1281 | formal_parameter_list
1284 formal_parameter_list
1287 ArrayList pars_list = (ArrayList) $1;
1289 Parameter [] pars = new Parameter [pars_list.Count];
1290 pars_list.CopyTo (pars);
1292 $$ = new Parameters (pars);
1294 | fixed_parameters COMMA parameter_array
1296 ArrayList pars_list = (ArrayList) $1;
1299 Parameter [] pars = new Parameter [pars_list.Count];
1300 pars_list.CopyTo (pars);
1302 $$ = new Parameters (pars);
1304 | fixed_parameters COMMA ARGLIST
1306 ArrayList pars_list = (ArrayList) $1;
1307 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1309 Parameter [] pars = new Parameter [pars_list.Count];
1310 pars_list.CopyTo (pars);
1312 $$ = new Parameters (pars, true);
1314 | parameter_array COMMA error
1317 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1320 | fixed_parameters COMMA parameter_array COMMA error
1323 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1326 | ARGLIST COMMA error
1328 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1331 | fixed_parameters COMMA ARGLIST COMMA error
1333 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1338 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1342 $$ = new Parameters (new Parameter[0], true);
1349 ArrayList pars = new ArrayList (4);
1354 | fixed_parameters COMMA fixed_parameter
1356 ArrayList pars = (ArrayList) $1;
1357 Parameter p = (Parameter)$3;
1359 if ((p.modFlags & Parameter.Modifier.This) != 0)
1360 Report.Error (1100, p.Location, "The parameter modifier `this' can only be used on the first parameter");
1369 opt_parameter_modifier
1373 LocatedToken lt = (LocatedToken) $4;
1374 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1377 opt_parameter_modifier
1379 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1381 LocatedToken lt = (LocatedToken) $4;
1382 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1386 opt_parameter_modifier
1389 Report.Error (1001, GetLocation ($3), "Identifier expected");
1393 opt_parameter_modifier
1396 CheckIdentifierToken (yyToken, GetLocation ($4));
1400 opt_parameter_modifier
1406 LocatedToken lt = (LocatedToken) $4;
1407 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1412 opt_parameter_modifier
1413 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1414 | parameter_modifiers
1418 : parameter_modifier
1422 | parameter_modifiers parameter_modifier
1424 Parameter.Modifier p2 = (Parameter.Modifier)$2;
1425 Parameter.Modifier mod = (Parameter.Modifier)$1 | p2;
1426 if (((Parameter.Modifier)$1 & p2) == p2) {
1427 Error_DuplicateParameterModifier (lexer.Location, p2);
1429 switch (mod & ~Parameter.Modifier.This) {
1430 case Parameter.Modifier.REF:
1431 Report.Error (1101, lexer.Location, "The parameter modifiers `this' and `ref' cannot be used altogether");
1433 case Parameter.Modifier.OUT:
1434 Report.Error (1102, lexer.Location, "The parameter modifiers `this' and `out' cannot be used altogether");
1437 Report.Error (1108, lexer.Location, "A parameter cannot have specified more than one modifier");
1446 : REF { $$ = Parameter.Modifier.REF; }
1447 | OUT { $$ = Parameter.Modifier.OUT; }
1448 | THIS { $$ = Parameter.Modifier.This; }
1452 : opt_attributes PARAMS type IDENTIFIER
1454 LocatedToken lt = (LocatedToken) $4;
1455 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1457 | opt_attributes PARAMS PARAMS type IDENTIFIER
1459 Error_DuplicateParameterModifier (lexer.Location, Parameter.Modifier.PARAMS);
1462 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1464 Parameter.Modifier mod = (Parameter.Modifier)$3;
1465 if ((mod & Parameter.Modifier.This) != 0) {
1466 Report.Error (1104, lexer.Location, "The parameter modifiers `this' and `params' cannot be used altogether");
1468 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1472 | opt_attributes PARAMS type error {
1473 CheckIdentifierToken (yyToken, GetLocation ($4));
1478 property_declaration
1482 namespace_or_type_name
1484 if (RootContext.Documentation != null)
1485 tmpComment = Lexer.consume_doc_comment ();
1489 implicit_value_parameter_type = (Expression) $3;
1491 lexer.PropertyParsing = true;
1493 accessor_declarations
1495 lexer.PropertyParsing = false;
1496 has_get = has_set = false;
1504 Accessors accessors = (Accessors) $8;
1505 Accessor get_block = accessors.get_or_add;
1506 Accessor set_block = accessors.set_or_remove;
1508 MemberName name = (MemberName) $4;
1510 if (name.TypeArguments != null)
1511 syntax_error (lexer.Location, "a property can't have type arguments");
1513 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1514 name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse);
1516 current_container.AddProperty (prop);
1517 implicit_value_parameter_type = null;
1519 if (RootContext.Documentation != null)
1520 prop.DocComment = ConsumeStoredComment ();
1525 accessor_declarations
1526 : get_accessor_declaration
1528 $$ = new Accessors ((Accessor) $1, null);
1530 | get_accessor_declaration accessor_declarations
1532 Accessors accessors = (Accessors) $2;
1533 accessors.get_or_add = (Accessor) $1;
1536 | set_accessor_declaration
1538 $$ = new Accessors (null, (Accessor) $1);
1540 | set_accessor_declaration accessor_declarations
1542 Accessors accessors = (Accessors) $2;
1543 accessors.set_or_remove = (Accessor) $1;
1544 accessors.declared_in_reverse = true;
1549 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1554 get_accessor_declaration
1555 : opt_attributes opt_modifiers GET
1557 // If this is not the case, then current_local_parameters has already
1558 // been set in indexer_declaration
1559 if (parsing_indexer == false)
1560 current_local_parameters = null;
1562 current_local_parameters = indexer_parameters;
1563 lexer.PropertyParsing = false;
1565 anonymous_host = SimpleAnonymousHost.GetSimple ();
1570 Report.Error (1007, (Location) $3, "Property accessor already defined");
1573 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1575 current_local_parameters = null;
1576 lexer.PropertyParsing = true;
1578 SimpleAnonymousHost.Simple.Propagate (accessor);
1579 anonymous_host = null;
1581 if (RootContext.Documentation != null)
1582 if (Lexer.doc_state == XmlCommentState.Error)
1583 Lexer.doc_state = XmlCommentState.NotAllowed;
1589 set_accessor_declaration
1590 : opt_attributes opt_modifiers SET
1593 Parameter implicit_value_parameter = new Parameter (
1594 implicit_value_parameter_type, "value",
1595 Parameter.Modifier.NONE, null, (Location) $3);
1597 if (parsing_indexer == false) {
1598 args = new Parameter [1];
1599 args [0] = implicit_value_parameter;
1600 current_local_parameters = new Parameters (args);
1602 Parameter [] fpars = indexer_parameters.FixedParameters;
1605 int count = fpars.Length;
1607 args = new Parameter [count + 1];
1608 fpars.CopyTo (args, 0);
1609 args [count] = implicit_value_parameter;
1612 current_local_parameters = new Parameters (
1616 lexer.PropertyParsing = false;
1618 anonymous_host = SimpleAnonymousHost.GetSimple ();
1623 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1626 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1628 current_local_parameters = null;
1629 lexer.PropertyParsing = true;
1631 SimpleAnonymousHost.Simple.Propagate (accessor);
1632 anonymous_host = null;
1634 if (RootContext.Documentation != null
1635 && Lexer.doc_state == XmlCommentState.Error)
1636 Lexer.doc_state = XmlCommentState.NotAllowed;
1644 | SEMICOLON { $$ = null; }
1647 interface_declaration
1653 lexer.ConstraintsParsing = true;
1657 MemberName name = MakeName ((MemberName) $6);
1659 push_current_class (new Interface (
1660 current_namespace, current_class, name, (int) $2,
1661 (Attributes) $1), true, $3);
1664 opt_type_parameter_constraints_clauses
1666 lexer.ConstraintsParsing = false;
1669 current_container.AddBasesForPart (current_class, (ArrayList) $8);
1671 current_class.SetParameterInfo ((ArrayList) $9);
1673 if (RootContext.Documentation != null) {
1674 current_container.DocComment = Lexer.consume_doc_comment ();
1675 Lexer.doc_state = XmlCommentState.Allowed;
1680 if (RootContext.Documentation != null)
1681 Lexer.doc_state = XmlCommentState.Allowed;
1685 $$ = pop_current_class ();
1687 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1688 CheckIdentifierToken (yyToken, GetLocation ($5));
1694 opt_interface_member_declarations
1698 opt_interface_member_declarations
1700 | interface_member_declarations
1703 interface_member_declarations
1704 : interface_member_declaration
1705 | interface_member_declarations interface_member_declaration
1708 interface_member_declaration
1709 : interface_method_declaration
1714 Method m = (Method) $1;
1716 if (m.IsExplicitImpl)
1717 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1718 m.GetSignatureForError ());
1720 current_container.AddMethod (m);
1722 if (RootContext.Documentation != null)
1723 Lexer.doc_state = XmlCommentState.Allowed;
1725 | interface_property_declaration
1730 Property p = (Property) $1;
1732 if (p.IsExplicitImpl)
1733 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1734 p.GetSignatureForError ());
1736 current_container.AddProperty (p);
1738 if (RootContext.Documentation != null)
1739 Lexer.doc_state = XmlCommentState.Allowed;
1741 | interface_event_declaration
1744 Event e = (Event) $1;
1746 if (e.IsExplicitImpl)
1747 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1748 e.GetSignatureForError ());
1750 current_container.AddEvent (e);
1753 if (RootContext.Documentation != null)
1754 Lexer.doc_state = XmlCommentState.Allowed;
1756 | interface_indexer_declaration
1761 Indexer i = (Indexer) $1;
1763 if (i.IsExplicitImpl)
1764 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1765 i.GetSignatureForError ());
1767 current_container.AddIndexer (i);
1769 if (RootContext.Documentation != null)
1770 Lexer.doc_state = XmlCommentState.Allowed;
1772 | delegate_declaration
1775 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1776 ((MemberCore)$1).GetSignatureForError ());
1782 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1783 ((MemberCore)$1).GetSignatureForError ());
1786 | struct_declaration
1789 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1790 ((MemberCore)$1).GetSignatureForError ());
1796 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1797 ((MemberCore)$1).GetSignatureForError ());
1800 | interface_declaration
1803 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1804 ((MemberCore)$1).GetSignatureForError ());
1807 | constant_declaration
1809 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1817 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1822 interface_method_declaration_body
1825 lexer.ConstraintsParsing = false;
1827 opt_statement_list CLOSE_BRACE
1829 Report.Error (531, lexer.Location,
1830 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1836 interface_method_declaration
1837 : opt_attributes opt_new type namespace_or_type_name
1838 open_parens opt_formal_parameter_list CLOSE_PARENS
1840 lexer.ConstraintsParsing = true;
1842 opt_type_parameter_constraints_clauses
1844 // Refer to the name as $-1 in interface_method_declaration_body
1847 interface_method_declaration_body
1849 lexer.ConstraintsParsing = false;
1851 MemberName name = (MemberName) $4;
1853 if ($9 != null && name.TypeArguments == null)
1854 Report.Error (80, lexer.Location,
1855 "Constraints are not allowed on non-generic declarations");
1857 GenericMethod generic = null;
1858 if (name.TypeArguments != null) {
1859 generic = new GenericMethod (current_namespace, current_class, name,
1860 (Expression) $3, (Parameters) $6);
1862 generic.SetParameterInfo ((ArrayList) $9);
1865 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1866 (Parameters) $6, (Attributes) $1);
1867 if (RootContext.Documentation != null)
1868 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1870 | opt_attributes opt_new VOID namespace_or_type_name
1871 open_parens opt_formal_parameter_list CLOSE_PARENS
1873 lexer.ConstraintsParsing = true;
1875 opt_type_parameter_constraints_clauses
1879 interface_method_declaration_body
1881 lexer.ConstraintsParsing = false;
1883 MemberName name = (MemberName) $4;
1885 if ($9 != null && name.TypeArguments == null)
1886 Report.Error (80, lexer.Location,
1887 "Constraints are not allowed on non-generic declarations");
1889 GenericMethod generic = null;
1890 if (name.TypeArguments != null) {
1891 generic = new GenericMethod (current_namespace, current_class, name,
1892 TypeManager.system_void_expr, (Parameters) $6);
1894 generic.SetParameterInfo ((ArrayList) $9);
1897 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1898 true, name, (Parameters) $6, (Attributes) $1);
1899 if (RootContext.Documentation != null)
1900 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1904 interface_property_declaration
1909 { lexer.PropertyParsing = true; }
1910 accessor_declarations
1912 has_get = has_set = false;
1913 lexer.PropertyParsing = false;
1917 LocatedToken lt = (LocatedToken) $4;
1918 MemberName name = new MemberName (lt.Value, lt.Location);
1920 if ($3 == TypeManager.system_void_expr) {
1921 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1927 p = new Property (current_class, (Expression) $3, (int) $2, true,
1928 name, (Attributes) $1,
1931 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1935 Accessors accessor = (Accessors) $7;
1936 p = new Property (current_class, (Expression) $3, (int) $2, true,
1937 name, (Attributes) $1,
1938 accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
1940 if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
1941 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1946 if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
1947 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1952 if (RootContext.Documentation != null)
1953 p.DocComment = Lexer.consume_doc_comment ();
1960 CheckIdentifierToken (yyToken, GetLocation ($4));
1966 interface_event_declaration
1967 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1969 LocatedToken lt = (LocatedToken) $5;
1970 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1971 new MemberName (lt.Value, lt.Location),
1973 if (RootContext.Documentation != null)
1974 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1976 | opt_attributes opt_new EVENT type error {
1977 CheckIdentifierToken (yyToken, GetLocation ($5));
1980 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1981 LocatedToken lt = (LocatedToken) $5;
1982 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1985 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1987 lexer.EventParsing = true;
1989 event_accessor_declarations
1991 lexer.EventParsing = false;
1994 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
1999 interface_indexer_declaration
2000 : opt_attributes opt_new type THIS
2001 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
2003 { lexer.PropertyParsing = true; }
2004 accessor_declarations
2006 has_get = has_set = false;
2007 lexer.PropertyParsing = false;
2013 i = new Indexer (current_class, (Expression) $3,
2014 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2015 (int) $2, true, (Parameters) $6, (Attributes) $1,
2018 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
2022 Accessors accessors = (Accessors) $10;
2023 i = new Indexer (current_class, (Expression) $3,
2024 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
2025 (int) $2, true, (Parameters) $6, (Attributes) $1,
2026 accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
2028 if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
2029 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
2034 if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
2035 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
2040 if (RootContext.Documentation != null)
2041 i.DocComment = ConsumeStoredComment ();
2047 operator_declaration
2048 : opt_attributes opt_modifiers operator_declarator
2050 anonymous_host = SimpleAnonymousHost.GetSimple ();
2057 OperatorDeclaration decl = (OperatorDeclaration) $3;
2059 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
2061 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
2062 if (decl.arg2type != null)
2063 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
2065 Operator op = new Operator (
2066 current_class, decl.optype, decl.ret_type, (int) $2,
2067 new Parameters (param_list),
2068 (ToplevelBlock) $5, (Attributes) $1, decl.location);
2070 if (RootContext.Documentation != null) {
2071 op.DocComment = tmpComment;
2072 Lexer.doc_state = XmlCommentState.Allowed;
2075 SimpleAnonymousHost.Simple.Propagate (op);
2076 anonymous_host = null;
2078 // Note again, checking is done in semantic analysis
2079 current_container.AddOperator (op);
2081 current_local_parameters = null;
2087 | SEMICOLON { $$ = null; }
2090 : type OPERATOR overloadable_operator
2091 open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2093 // TODO: wrong location
2094 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2095 Error_ParameterModifierNotValid ((Location) $2);
2097 LocatedToken lt = (LocatedToken) $7;
2098 Operator.OpType op = (Operator.OpType) $3;
2099 CheckUnaryOperator (op, lt.Location);
2101 if (op == Operator.OpType.Addition)
2102 op = Operator.OpType.UnaryPlus;
2104 if (op == Operator.OpType.Subtraction)
2105 op = Operator.OpType.UnaryNegation;
2107 Parameter [] pars = new Parameter [1];
2108 Expression type = (Expression) $6;
2110 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2112 current_local_parameters = new Parameters (pars);
2114 if (RootContext.Documentation != null) {
2115 tmpComment = Lexer.consume_doc_comment ();
2116 Lexer.doc_state = XmlCommentState.NotAllowed;
2119 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2120 null, null, (Location) $2);
2122 | type OPERATOR overloadable_operator
2124 opt_parameter_modifier type IDENTIFIER COMMA
2125 opt_parameter_modifier type IDENTIFIER
2128 // TODO: wrong location
2129 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE || (Parameter.Modifier)$9 != Parameter.Modifier.NONE)
2130 Error_ParameterModifierNotValid ((Location) $2);
2132 LocatedToken ltParam1 = (LocatedToken) $7;
2133 LocatedToken ltParam2 = (LocatedToken) $11;
2134 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2136 Parameter [] pars = new Parameter [2];
2138 Expression typeL = (Expression) $6;
2139 Expression typeR = (Expression) $10;
2141 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
2142 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
2144 current_local_parameters = new Parameters (pars);
2146 if (RootContext.Documentation != null) {
2147 tmpComment = Lexer.consume_doc_comment ();
2148 Lexer.doc_state = XmlCommentState.NotAllowed;
2151 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2152 typeL, ltParam1.Value,
2153 typeR, ltParam2.Value, (Location) $2);
2155 | conversion_operator_declarator
2156 | type OPERATOR overloadable_operator
2158 opt_parameter_modifier type IDENTIFIER COMMA
2159 opt_parameter_modifier type IDENTIFIER COMMA
2160 opt_parameter_modifier type IDENTIFIER
2163 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2164 Operator.GetName ((Operator.OpType) $3));
2167 | type OPERATOR overloadable_operator
2168 open_parens CLOSE_PARENS
2170 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2171 Operator.GetName ((Operator.OpType) $3));
2176 overloadable_operator
2178 : BANG { $$ = Operator.OpType.LogicalNot; }
2179 | TILDE { $$ = Operator.OpType.OnesComplement; }
2180 | OP_INC { $$ = Operator.OpType.Increment; }
2181 | OP_DEC { $$ = Operator.OpType.Decrement; }
2182 | TRUE { $$ = Operator.OpType.True; }
2183 | FALSE { $$ = Operator.OpType.False; }
2184 // Unary and binary:
2185 | PLUS { $$ = Operator.OpType.Addition; }
2186 | MINUS { $$ = Operator.OpType.Subtraction; }
2188 | STAR { $$ = Operator.OpType.Multiply; }
2189 | DIV { $$ = Operator.OpType.Division; }
2190 | PERCENT { $$ = Operator.OpType.Modulus; }
2191 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2192 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2193 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2194 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2195 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2196 | OP_EQ { $$ = Operator.OpType.Equality; }
2197 | OP_NE { $$ = Operator.OpType.Inequality; }
2198 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2199 | OP_LT { $$ = Operator.OpType.LessThan; }
2200 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2201 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2204 conversion_operator_declarator
2205 : IMPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2207 // TODO: wrong location
2208 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2209 Error_ParameterModifierNotValid (GetLocation ($4));
2211 LocatedToken lt = (LocatedToken) $7;
2212 Parameter [] pars = new Parameter [1];
2214 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2216 current_local_parameters = new Parameters (pars);
2218 if (RootContext.Documentation != null) {
2219 tmpComment = Lexer.consume_doc_comment ();
2220 Lexer.doc_state = XmlCommentState.NotAllowed;
2223 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $6, lt.Value,
2224 null, null, (Location) $2);
2226 | EXPLICIT OPERATOR type open_parens opt_parameter_modifier type IDENTIFIER CLOSE_PARENS
2228 // TODO: wrong location
2229 if ((Parameter.Modifier)$5 != Parameter.Modifier.NONE)
2230 Error_ParameterModifierNotValid (GetLocation ($4));
2232 LocatedToken lt = (LocatedToken) $7;
2233 Parameter [] pars = new Parameter [1];
2235 pars [0] = new Parameter ((Expression) $6, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2237 current_local_parameters = new Parameters (pars);
2239 if (RootContext.Documentation != null) {
2240 tmpComment = Lexer.consume_doc_comment ();
2241 Lexer.doc_state = XmlCommentState.NotAllowed;
2244 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $6, lt.Value,
2245 null, null, (Location) $2);
2249 syntax_error ((Location) $1, "'operator' expected");
2253 syntax_error ((Location) $1, "'operator' expected");
2257 constructor_declaration
2260 constructor_declarator
2263 Constructor c = (Constructor) $3;
2264 c.Block = (ToplevelBlock) $4;
2265 c.OptAttributes = (Attributes) $1;
2266 c.ModFlags = (int) $2;
2268 if (RootContext.Documentation != null)
2269 c.DocComment = ConsumeStoredComment ();
2271 if (c.Name == current_container.Basename){
2272 if ((c.ModFlags & Modifiers.STATIC) != 0){
2273 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2274 Report.Error (515, c.Location,
2275 "`{0}': access modifiers are not allowed on static constructors",
2276 c.GetSignatureForError ());
2279 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2281 if (c.Initializer != null){
2282 Report.Error (514, c.Location,
2283 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2284 c.GetSignatureForError ());
2287 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2290 // We let another layer check the validity of the constructor.
2291 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2294 current_container.AddConstructor (c);
2296 current_local_parameters = null;
2297 if (RootContext.Documentation != null)
2298 Lexer.doc_state = XmlCommentState.Allowed;
2302 constructor_declarator
2303 : constructor_header
2307 | constructor_header constructor_initializer
2309 ((Constructor)$1).Initializer = (ConstructorInitializer) $2;
2317 if (RootContext.Documentation != null) {
2318 tmpComment = Lexer.consume_doc_comment ();
2319 Lexer.doc_state = XmlCommentState.Allowed;
2322 open_parens opt_formal_parameter_list CLOSE_PARENS
2324 current_local_parameters = (Parameters) $4;
2325 current_block = top_current_block = new ToplevelBlock (null,
2326 current_local_parameters, null, Location.Null);
2328 LocatedToken lt = (LocatedToken) $1;
2329 $$ = new Constructor (current_class, lt.Value, 0, current_local_parameters,
2332 anonymous_host = (IAnonymousHost) $$;
2338 | SEMICOLON { current_block = top_current_block = null; $$ = null; }
2341 constructor_initializer
2342 : COLON BASE open_parens opt_argument_list CLOSE_PARENS
2344 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2346 | COLON THIS open_parens opt_argument_list CLOSE_PARENS
2348 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2351 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2357 : /* EMPTY */ { $$ = 0; }
2358 | UNSAFE { $$ = Modifiers.UNSAFE; }
2359 | EXTERN { $$ = Modifiers.EXTERN; }
2362 destructor_declaration
2363 : opt_attributes opt_finalizer TILDE
2365 if (RootContext.Documentation != null) {
2366 tmpComment = Lexer.consume_doc_comment ();
2367 Lexer.doc_state = XmlCommentState.NotAllowed;
2370 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2372 LocatedToken lt = (LocatedToken) $5;
2373 if (lt.Value != current_container.MemberName.Name){
2374 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2375 } else if (current_container.Kind != Kind.Class){
2376 Report.Error (575, lt.Location, "Only class types can contain destructor");
2378 Location l = lt.Location;
2381 if (!RootContext.StdLib && current_container.Name == "System.Object")
2382 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2384 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2386 Method d = new Destructor (
2387 current_class, TypeManager.system_void_expr, m, "Finalize",
2388 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2389 if (RootContext.Documentation != null)
2390 d.DocComment = ConsumeStoredComment ();
2392 d.Block = (ToplevelBlock) $8;
2393 current_container.AddMethod (d);
2401 EVENT type variable_declarators SEMICOLON
2403 current_array_type = null;
2404 foreach (VariableDeclaration var in (ArrayList) $5) {
2406 MemberName name = new MemberName (var.identifier,
2409 EventField e = new EventField (
2410 current_class, (Expression) $4, (int) $2, false, name,
2413 e.Initializer = var.expression_or_array_initializer;
2415 current_container.AddEvent (e);
2417 if (RootContext.Documentation != null) {
2418 e.DocComment = Lexer.consume_doc_comment ();
2419 Lexer.doc_state = XmlCommentState.Allowed;
2425 EVENT type namespace_or_type_name
2428 implicit_value_parameter_type = (Expression) $4;
2429 lexer.EventParsing = true;
2431 event_accessor_declarations
2433 lexer.EventParsing = false;
2437 MemberName name = (MemberName) $5;
2440 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2441 current_container.Name, name.ToString ());
2444 Accessors accessors = (Accessors) $8;
2446 if (name.TypeArguments != null)
2447 syntax_error (lexer.Location, "an event can't have type arguments");
2449 if (accessors.get_or_add == null || accessors.set_or_remove == null)
2450 // CS0073 is already reported, so no CS0065 here.
2453 Event e = new EventProperty (
2454 current_class, (Expression) $4, (int) $2, false, name,
2455 (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
2456 if (RootContext.Documentation != null) {
2457 e.DocComment = Lexer.consume_doc_comment ();
2458 Lexer.doc_state = XmlCommentState.Allowed;
2461 current_container.AddEvent (e);
2462 implicit_value_parameter_type = null;
2466 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2467 MemberName mn = (MemberName) $5;
2469 if (mn.Left != null)
2470 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2472 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2474 if (RootContext.Documentation != null)
2475 Lexer.doc_state = XmlCommentState.Allowed;
2479 event_accessor_declarations
2480 : add_accessor_declaration remove_accessor_declaration
2482 $$ = new Accessors ((Accessor) $1, (Accessor) $2);
2484 | remove_accessor_declaration add_accessor_declaration
2486 Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
2487 accessors.declared_in_reverse = true;
2490 | add_accessor_declaration { $$ = null; }
2491 | remove_accessor_declaration { $$ = null; }
2494 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2500 add_accessor_declaration
2501 : opt_attributes ADD
2503 Parameter [] args = new Parameter [1];
2504 Parameter implicit_value_parameter = new Parameter (
2505 implicit_value_parameter_type, "value",
2506 Parameter.Modifier.NONE, null, (Location) $2);
2508 args [0] = implicit_value_parameter;
2510 current_local_parameters = new Parameters (args);
2511 lexer.EventParsing = false;
2513 anonymous_host = SimpleAnonymousHost.GetSimple ();
2517 Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2518 lexer.EventParsing = true;
2520 current_local_parameters = null;
2521 SimpleAnonymousHost.Simple.Propagate (accessor);
2522 anonymous_host = null;
2526 | opt_attributes ADD error {
2527 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2530 | opt_attributes modifiers ADD {
2531 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2536 remove_accessor_declaration
2537 : opt_attributes REMOVE
2539 Parameter [] args = new Parameter [1];
2540 Parameter implicit_value_parameter = new Parameter (
2541 implicit_value_parameter_type, "value",
2542 Parameter.Modifier.NONE, null, (Location) $2);
2544 args [0] = implicit_value_parameter;
2546 current_local_parameters = new Parameters (args);
2547 lexer.EventParsing = false;
2551 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2552 lexer.EventParsing = true;
2554 | opt_attributes REMOVE error {
2555 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2558 | opt_attributes modifiers REMOVE {
2559 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2565 : opt_attributes opt_modifiers indexer_declarator
2568 IndexerDeclaration decl = (IndexerDeclaration) $3;
2570 implicit_value_parameter_type = decl.type;
2572 lexer.PropertyParsing = true;
2573 parsing_indexer = true;
2575 indexer_parameters = decl.param_list;
2576 anonymous_host = SimpleAnonymousHost.GetSimple ();
2578 accessor_declarations
2580 lexer.PropertyParsing = false;
2581 has_get = has_set = false;
2582 parsing_indexer = false;
2589 // The signature is computed from the signature of the indexer. Look
2590 // at section 3.6 on the spec
2592 IndexerDeclaration decl = (IndexerDeclaration) $3;
2593 Accessors accessors = (Accessors) $6;
2594 Accessor get_block = accessors.get_or_add;
2595 Accessor set_block = accessors.set_or_remove;
2598 if (decl.interface_type != null)
2599 name = new MemberName (
2600 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2602 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2604 indexer = new Indexer (current_class, decl.type, name,
2605 (int) $2, false, decl.param_list, (Attributes) $1,
2606 get_block, set_block, accessors.declared_in_reverse);
2608 if (RootContext.Documentation != null)
2609 indexer.DocComment = ConsumeStoredComment ();
2611 current_container.AddIndexer (indexer);
2613 current_local_parameters = null;
2614 implicit_value_parameter_type = null;
2615 indexer_parameters = null;
2620 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2622 Parameters pars = (Parameters) $4;
2623 if (pars.HasArglist) {
2624 // "__arglist is not valid in this context"
2625 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2626 } else if (pars.Empty){
2627 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2629 if (RootContext.Documentation != null) {
2630 tmpComment = Lexer.consume_doc_comment ();
2631 Lexer.doc_state = XmlCommentState.Allowed;
2634 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2636 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2638 Parameters pars = (Parameters) $6;
2640 if (pars.HasArglist) {
2641 // "__arglist is not valid in this context"
2642 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2643 } else if (pars.Empty){
2644 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2647 MemberName name = (MemberName) $2;
2648 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2650 if (RootContext.Documentation != null) {
2651 tmpComment = Lexer.consume_doc_comment ();
2652 Lexer.doc_state = XmlCommentState.Allowed;
2662 if (RootContext.Documentation != null)
2663 enumTypeComment = Lexer.consume_doc_comment ();
2668 LocatedToken lt = (LocatedToken) $4;
2669 Location enum_location = lt.Location;
2671 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2672 Enum e = new Enum (current_namespace, current_class, (Expression) $5, (int) $2,
2673 name, (Attributes) $1);
2675 if (RootContext.Documentation != null)
2676 e.DocComment = enumTypeComment;
2679 EnumMember em = null;
2680 foreach (VariableDeclaration ev in (ArrayList) $7) {
2681 em = new EnumMember (
2682 e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
2683 ev.OptAttributes, ev.Location);
2685 // if (RootContext.Documentation != null)
2686 em.DocComment = ev.DocComment;
2688 e.AddEnumMember (em);
2691 current_container.AddEnum (e);
2698 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2699 | COLON type { $$ = $2; }
2705 if (RootContext.Documentation != null)
2706 Lexer.doc_state = XmlCommentState.Allowed;
2708 opt_enum_member_declarations
2710 // here will be evaluated after CLOSE_BLACE is consumed.
2711 if (RootContext.Documentation != null)
2712 Lexer.doc_state = XmlCommentState.Allowed;
2720 opt_enum_member_declarations
2721 : /* empty */ { $$ = new ArrayList (4); }
2722 | enum_member_declarations opt_comma { $$ = $1; }
2725 enum_member_declarations
2726 : enum_member_declaration
2728 ArrayList l = new ArrayList (4);
2733 | enum_member_declarations COMMA enum_member_declaration
2735 ArrayList l = (ArrayList) $1;
2743 enum_member_declaration
2744 : opt_attributes IDENTIFIER
2746 VariableDeclaration vd = new VariableDeclaration (
2747 (LocatedToken) $2, null, (Attributes) $1);
2749 if (RootContext.Documentation != null) {
2750 vd.DocComment = Lexer.consume_doc_comment ();
2751 Lexer.doc_state = XmlCommentState.Allowed;
2756 | opt_attributes IDENTIFIER
2758 if (RootContext.Documentation != null) {
2759 tmpComment = Lexer.consume_doc_comment ();
2760 Lexer.doc_state = XmlCommentState.NotAllowed;
2765 VariableDeclaration vd = new VariableDeclaration (
2766 (LocatedToken) $2, $5, (Attributes) $1);
2768 if (RootContext.Documentation != null)
2769 vd.DocComment = ConsumeStoredComment ();
2775 delegate_declaration
2780 lexer.ConstraintsParsing = true;
2783 open_parens opt_formal_parameter_list CLOSE_PARENS
2785 MemberName name = MakeName ((MemberName) $6);
2786 Parameters p = (Parameters) $8;
2788 // TODO: wrong location
2789 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2792 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2793 (int) $2, name, p, (Attributes) $1);
2795 if (RootContext.Documentation != null) {
2796 del.DocComment = Lexer.consume_doc_comment ();
2797 Lexer.doc_state = XmlCommentState.Allowed;
2800 current_container.AddDelegate (del);
2801 current_delegate = del;
2803 opt_type_parameter_constraints_clauses
2805 lexer.ConstraintsParsing = false;
2809 current_delegate.SetParameterInfo ((ArrayList) $11);
2810 $$ = current_delegate;
2812 current_delegate = null;
2819 lexer.CheckNullable (false);
2824 lexer.CheckNullable (true);
2829 namespace_or_type_name
2831 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2832 LocatedToken lt1 = (LocatedToken) $1;
2833 LocatedToken lt2 = (LocatedToken) $3;
2834 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2836 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2837 LocatedToken lt = (LocatedToken) $3;
2838 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2843 : IDENTIFIER opt_type_argument_list {
2844 LocatedToken lt = (LocatedToken) $1;
2845 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2849 opt_type_argument_list
2850 : /* empty */ { $$ = null; }
2851 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2854 if (RootContext.Version == LanguageVersion.ISO_1)
2855 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2859 $$ = new TypeArguments ((int) $1, lexer.Location);
2860 if (RootContext.Version == LanguageVersion.ISO_1)
2861 Report.FeatureIsNotISO1 (lexer.Location, "generics");
2866 : opt_attributes type {
2867 TypeArguments type_args = new TypeArguments (lexer.Location);
2869 SimpleName sn = $2 as SimpleName;
2871 Report.Error (1031, lexer.Location, "Type expected");
2873 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2875 type_args.Add ((Expression) $2);
2878 | type_arguments COMMA opt_attributes type {
2879 TypeArguments type_args = (TypeArguments) $1;
2881 SimpleName sn = $4 as SimpleName;
2883 Report.Error (1031, lexer.Location, "Type expected");
2885 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2887 type_args.Add ((Expression) $4);
2894 * Before you think of adding a return_type, notice that we have been
2895 * using two rules in the places where it matters (one rule using type
2896 * and another identical one that uses VOID as the return type). This
2897 * gets rid of a shift/reduce couple
2900 : namespace_or_type_name opt_nullable
2902 MemberName name = (MemberName) $1;
2903 $$ = name.GetTypeExpression ();
2906 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2908 | builtin_types opt_nullable
2911 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2921 // Note that here only unmanaged types are allowed but we
2922 // can't perform checks during this phase - we do it during
2923 // semantic analysis.
2925 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2929 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2934 : builtin_types opt_nullable
2937 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2939 | non_expression_type rank_specifier
2941 Location loc = GetLocation ($1);
2943 loc = lexer.Location;
2944 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2946 | non_expression_type STAR
2948 Location loc = GetLocation ($1);
2950 loc = lexer.Location;
2951 $$ = new ComposedCast ((Expression) $1, "*", loc);
2953 | expression rank_specifiers
2955 $$ = new ComposedCast ((Expression) $1, (string) $2);
2959 $$ = new ComposedCast ((Expression) $1, "*");
2963 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2964 // through this different path
2966 | multiplicative_expression STAR
2968 $$ = new ComposedCast ((Expression) $1, "*");
2975 ArrayList types = new ArrayList (4);
2980 | type_list COMMA type
2982 ArrayList types = (ArrayList) $1;
2990 * replaces all the productions for isolating the various
2991 * simple types, but we need this to reuse it easily in local_variable_type
2994 : OBJECT { $$ = TypeManager.system_object_expr; }
2995 | STRING { $$ = TypeManager.system_string_expr; }
2996 | BOOL { $$ = TypeManager.system_boolean_expr; }
2997 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2998 | FLOAT { $$ = TypeManager.system_single_expr; }
2999 | DOUBLE { $$ = TypeManager.system_double_expr; }
3004 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
3005 | BYTE { $$ = TypeManager.system_byte_expr; }
3006 | SHORT { $$ = TypeManager.system_int16_expr; }
3007 | USHORT { $$ = TypeManager.system_uint16_expr; }
3008 | INT { $$ = TypeManager.system_int32_expr; }
3009 | UINT { $$ = TypeManager.system_uint32_expr; }
3010 | LONG { $$ = TypeManager.system_int64_expr; }
3011 | ULONG { $$ = TypeManager.system_uint64_expr; }
3012 | CHAR { $$ = TypeManager.system_char_expr; }
3013 | VOID { $$ = TypeManager.system_void_expr; }
3017 : type rank_specifiers opt_nullable
3019 string rank_specifiers = (string) $2;
3021 rank_specifiers += "?";
3023 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
3028 // Expressions, section 7.5
3037 MemberName mn = (MemberName) $1;
3038 $$ = mn.GetTypeExpression ();
3040 | IDENTIFIER DOUBLE_COLON IDENTIFIER
3042 LocatedToken lt1 = (LocatedToken) $1;
3043 LocatedToken lt2 = (LocatedToken) $3;
3044 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
3046 | parenthesized_expression
3047 | default_value_expression
3049 | invocation_expression
3053 | post_increment_expression
3054 | post_decrement_expression
3058 | checked_expression
3059 | unchecked_expression
3060 | pointer_member_access
3061 | anonymous_method_expression
3068 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
3069 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
3070 | NULL { $$ = new NullLiteral (lexer.Location); }
3074 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
3075 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
3076 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
3081 object v = lexer.Value;
3084 $$ = new IntLiteral ((int) v, lexer.Location);
3085 } else if (v is uint)
3086 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
3088 $$ = new LongLiteral ((Int64) v, lexer.Location);
3089 else if (v is ulong)
3090 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
3092 Console.WriteLine ("OOPS. Unexpected result from scanner");
3097 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
3098 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
3101 parenthesized_expression_0
3102 : OPEN_PARENS expression CLOSE_PARENS
3105 lexer.Deambiguate_CloseParens ($$);
3106 // After this, the next token returned is one of
3107 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
3108 // or CLOSE_PARENS_MINUS.
3110 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
3113 parenthesized_expression
3114 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
3118 | parenthesized_expression_0 CLOSE_PARENS
3122 | parenthesized_expression_0 CLOSE_PARENS_MINUS
3124 // If a parenthesized expression is followed by a minus, we need to wrap
3125 // the expression inside a ParenthesizedExpression for the CS0075 check
3126 // in Binary.DoResolve().
3127 $$ = new ParenthesizedExpression ((Expression) $1);
3132 : primary_expression DOT IDENTIFIER opt_type_argument_list
3134 LocatedToken lt = (LocatedToken) $3;
3135 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3137 | predefined_type DOT IDENTIFIER opt_type_argument_list
3139 LocatedToken lt = (LocatedToken) $3;
3140 // TODO: Location is wrong as some predefined types doesn't hold a location
3141 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3149 invocation_expression
3150 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3153 Report.Error (1, (Location) $2, "Parse error");
3155 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3157 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3159 $$ = new Invocation ((Expression) $1, new ArrayList ());
3161 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3163 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3165 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3167 ArrayList args = new ArrayList (1);
3169 $$ = new Invocation ((Expression) $1, args);
3171 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3173 ArrayList args = ((ArrayList) $4);
3175 $$ = new Invocation ((Expression) $1, args);
3180 : /* empty */ { $$ = null; }
3187 ArrayList list = new ArrayList (4);
3191 | argument_list COMMA argument
3193 ArrayList list = (ArrayList) $1;
3197 | argument_list error {
3198 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3206 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3208 | non_simple_argument
3215 : REF variable_reference
3217 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3219 | OUT variable_reference
3221 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3223 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3225 ArrayList list = (ArrayList) $3;
3226 Argument[] args = new Argument [list.Count];
3227 list.CopyTo (args, 0);
3229 Expression expr = new Arglist (args, (Location) $1);
3230 $$ = new Argument (expr, Argument.AType.Expression);
3232 | ARGLIST OPEN_PARENS CLOSE_PARENS
3234 $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression);
3238 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3243 : expression { note ("section 5.4"); $$ = $1; }
3247 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3249 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3251 | primary_expression rank_specifiers
3253 // So the super-trick is that primary_expression
3254 // can only be either a SimpleName or a MemberAccess.
3255 // The MemberAccess case arises when you have a fully qualified type-name like :
3257 // SimpleName is when you have
3260 Expression expr = (Expression) $1;
3261 if (expr is ComposedCast){
3262 $$ = new ComposedCast (expr, (string) $2);
3263 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3264 Error_ExpectingTypeName (expr);
3265 $$ = TypeManager.system_object_expr;
3268 // So we extract the string corresponding to the SimpleName
3271 $$ = new ComposedCast (expr, (string) $2);
3273 current_array_type = (Expression)$$;
3280 ArrayList list = new ArrayList (4);
3284 | expression_list COMMA expression
3286 ArrayList list = (ArrayList) $1;
3295 $$ = new This (current_block, (Location) $1);
3300 : BASE DOT IDENTIFIER opt_type_argument_list
3302 LocatedToken lt = (LocatedToken) $3;
3303 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3305 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3307 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3310 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3315 post_increment_expression
3316 : primary_expression OP_INC
3318 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3319 (Expression) $1, (Location) $2);
3323 post_decrement_expression
3324 : primary_expression OP_DEC
3326 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3327 (Expression) $1, (Location) $2);
3332 : object_or_delegate_creation_expression
3333 | array_creation_expression
3336 object_or_delegate_creation_expression
3337 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3339 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3343 array_creation_expression
3344 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3346 opt_array_initializer
3348 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3350 | NEW type rank_specifiers array_initializer
3352 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3356 Report.Error (1031, (Location) $1, "Type expected");
3361 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3377 opt_rank_specifier_or_nullable
3386 | opt_nullable rank_specifiers
3393 | opt_nullable rank_specifiers INTERR
3396 $$ = "?" + $2 + "?";
3403 : rank_specifier opt_rank_specifier
3405 $$ = (string) $2 + (string) $1;
3410 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3412 $$ = "[" + (string) $2 + "]";
3432 | dim_separators COMMA
3434 $$ = (string) $1 + ",";
3438 opt_array_initializer
3450 : OPEN_BRACE CLOSE_BRACE
3452 ArrayList list = new ArrayList (4);
3455 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3457 $$ = (ArrayList) $2;
3461 variable_initializer_list
3462 : variable_initializer
3464 ArrayList list = new ArrayList (4);
3468 | variable_initializer_list COMMA variable_initializer
3470 ArrayList list = (ArrayList) $1;
3479 pushed_current_array_type = current_array_type;
3480 lexer.TypeOfParsing = true;
3482 OPEN_PARENS type CLOSE_PARENS
3484 lexer.TypeOfParsing = false;
3485 Expression type = (Expression)$4;
3486 if (type == TypeManager.system_void_expr)
3487 $$ = new TypeOfVoid ((Location) $1);
3489 $$ = new TypeOf (type, (Location) $1);
3490 current_array_type = pushed_current_array_type;
3495 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3496 $$ = new SizeOf ((Expression) $3, (Location) $1);
3501 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3503 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3507 unchecked_expression
3508 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3510 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3514 pointer_member_access
3515 : primary_expression OP_PTR IDENTIFIER
3518 LocatedToken lt = (LocatedToken) $3;
3520 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3521 $$ = new MemberAccess (deref, lt.Value);
3525 anonymous_method_expression
3526 : DELEGATE opt_anonymous_method_signature
3528 start_anonymous (false, (Parameters) $2, (Location) $1);
3532 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $1);
3536 opt_anonymous_method_signature
3537 : /* empty */ { $$ = null; }
3538 | anonymous_method_signature
3541 anonymous_method_signature
3542 : open_parens opt_anonymous_method_parameter_list CLOSE_PARENS
3545 $$ = Parameters.EmptyReadOnlyParameters;
3547 ArrayList par_list = (ArrayList) $2;
3548 Parameter [] pars = new Parameter [par_list.Count];
3549 par_list.CopyTo (pars);
3550 $$ = new Parameters (pars);
3555 opt_anonymous_method_parameter_list
3556 : /* empty */ { $$ = null; }
3557 | anonymous_method_parameter_list { $$ = $1; }
3560 anonymous_method_parameter_list
3561 : anonymous_method_parameter
3563 ArrayList a = new ArrayList (4);
3567 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3569 ArrayList a = (ArrayList) $1;
3575 anonymous_method_parameter
3576 : opt_parameter_modifier type IDENTIFIER {
3577 LocatedToken lt = (LocatedToken) $3;
3578 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3580 | PARAMS type IDENTIFIER {
3581 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3586 default_value_expression
3587 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3589 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3594 : primary_expression
3595 | BANG prefixed_unary_expression
3597 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3599 | TILDE prefixed_unary_expression
3601 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3607 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3609 $$ = new Cast ((Expression) $1, (Expression) $3);
3611 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3613 $$ = new Cast ((Expression) $1, (Expression) $3);
3615 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3617 $$ = new Cast ((Expression) $1, (Expression) $3);
3623 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3625 // TODO: wrong location
3626 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3631 // The idea to split this out is from Rhys' grammar
3632 // to solve the problem with casts.
3634 prefixed_unary_expression
3636 | PLUS prefixed_unary_expression
3638 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3640 | MINUS prefixed_unary_expression
3642 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3644 | OP_INC prefixed_unary_expression
3646 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3647 (Expression) $2, (Location) $1);
3649 | OP_DEC prefixed_unary_expression
3651 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3652 (Expression) $2, (Location) $1);
3654 | STAR prefixed_unary_expression
3656 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3658 | BITWISE_AND prefixed_unary_expression
3660 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3664 pre_increment_expression
3665 : OP_INC prefixed_unary_expression
3667 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3668 (Expression) $2, (Location) $1);
3672 pre_decrement_expression
3673 : OP_DEC prefixed_unary_expression
3675 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3676 (Expression) $2, (Location) $1);
3680 multiplicative_expression
3681 : prefixed_unary_expression
3682 | multiplicative_expression STAR prefixed_unary_expression
3684 $$ = new Binary (Binary.Operator.Multiply,
3685 (Expression) $1, (Expression) $3);
3687 | multiplicative_expression DIV prefixed_unary_expression
3689 $$ = new Binary (Binary.Operator.Division,
3690 (Expression) $1, (Expression) $3);
3692 | multiplicative_expression PERCENT prefixed_unary_expression
3694 $$ = new Binary (Binary.Operator.Modulus,
3695 (Expression) $1, (Expression) $3);
3700 : multiplicative_expression
3701 | additive_expression PLUS multiplicative_expression
3703 $$ = new Binary (Binary.Operator.Addition,
3704 (Expression) $1, (Expression) $3);
3706 | additive_expression MINUS multiplicative_expression
3708 $$ = new Binary (Binary.Operator.Subtraction,
3709 (Expression) $1, (Expression) $3);
3714 : additive_expression
3715 | shift_expression OP_SHIFT_LEFT additive_expression
3717 $$ = new Binary (Binary.Operator.LeftShift,
3718 (Expression) $1, (Expression) $3);
3720 | shift_expression OP_SHIFT_RIGHT additive_expression
3722 $$ = new Binary (Binary.Operator.RightShift,
3723 (Expression) $1, (Expression) $3);
3734 lexer.PutbackNullable ();
3739 nullable_type_or_conditional
3742 if (((bool) $2) && ($1 is ComposedCast))
3743 $$ = ((ComposedCast) $1).RemoveNullable ();
3749 relational_expression
3751 | relational_expression OP_LT shift_expression
3753 $$ = new Binary (Binary.Operator.LessThan,
3754 (Expression) $1, (Expression) $3);
3756 | relational_expression OP_GT shift_expression
3758 $$ = new Binary (Binary.Operator.GreaterThan,
3759 (Expression) $1, (Expression) $3);
3761 | relational_expression OP_LE shift_expression
3763 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3764 (Expression) $1, (Expression) $3);
3766 | relational_expression OP_GE shift_expression
3768 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3769 (Expression) $1, (Expression) $3);
3771 | relational_expression IS
3774 } nullable_type_or_conditional
3776 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3778 | relational_expression AS
3781 } nullable_type_or_conditional
3783 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3788 : relational_expression
3789 | equality_expression OP_EQ relational_expression
3791 $$ = new Binary (Binary.Operator.Equality,
3792 (Expression) $1, (Expression) $3);
3794 | equality_expression OP_NE relational_expression
3796 $$ = new Binary (Binary.Operator.Inequality,
3797 (Expression) $1, (Expression) $3);
3802 : equality_expression
3803 | and_expression BITWISE_AND equality_expression
3805 $$ = new Binary (Binary.Operator.BitwiseAnd,
3806 (Expression) $1, (Expression) $3);
3810 exclusive_or_expression
3812 | exclusive_or_expression CARRET and_expression
3814 $$ = new Binary (Binary.Operator.ExclusiveOr,
3815 (Expression) $1, (Expression) $3);
3819 inclusive_or_expression
3820 : exclusive_or_expression
3821 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3823 $$ = new Binary (Binary.Operator.BitwiseOr,
3824 (Expression) $1, (Expression) $3);
3828 conditional_and_expression
3829 : inclusive_or_expression
3830 | conditional_and_expression OP_AND inclusive_or_expression
3832 $$ = new Binary (Binary.Operator.LogicalAnd,
3833 (Expression) $1, (Expression) $3);
3837 conditional_or_expression
3838 : conditional_and_expression
3839 | conditional_or_expression OP_OR conditional_and_expression
3841 $$ = new Binary (Binary.Operator.LogicalOr,
3842 (Expression) $1, (Expression) $3);
3846 conditional_expression
3847 : conditional_or_expression
3848 | conditional_or_expression INTERR expression COLON expression
3850 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3852 | conditional_or_expression INTERR INTERR expression
3854 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3856 // We'll be resolved into a `parenthesized_expression_0' later on.
3857 | conditional_or_expression INTERR CLOSE_PARENS
3859 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3860 lexer.PutbackCloseParens ();
3864 assignment_expression
3865 : prefixed_unary_expression ASSIGN expression
3867 $$ = new Assign ((Expression) $1, (Expression) $3);
3869 | prefixed_unary_expression OP_MULT_ASSIGN expression
3871 $$ = new CompoundAssign (
3872 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3874 | prefixed_unary_expression OP_DIV_ASSIGN expression
3876 $$ = new CompoundAssign (
3877 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3879 | prefixed_unary_expression OP_MOD_ASSIGN expression
3881 $$ = new CompoundAssign (
3882 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3884 | prefixed_unary_expression OP_ADD_ASSIGN expression
3886 $$ = new CompoundAssign (
3887 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3889 | prefixed_unary_expression OP_SUB_ASSIGN expression
3891 $$ = new CompoundAssign (
3892 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3894 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3896 $$ = new CompoundAssign (
3897 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3899 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3901 $$ = new CompoundAssign (
3902 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3904 | prefixed_unary_expression OP_AND_ASSIGN expression
3906 $$ = new CompoundAssign (
3907 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3909 | prefixed_unary_expression OP_OR_ASSIGN expression
3911 $$ = new CompoundAssign (
3912 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3914 | prefixed_unary_expression OP_XOR_ASSIGN expression
3916 $$ = new CompoundAssign (
3917 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3921 implicitly_typed_lambda_parameter_list
3923 LocatedToken lt = (LocatedToken) $1;
3924 ArrayList a = new ArrayList (4);
3926 a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
3929 | implicitly_typed_lambda_parameter_list COMMA IDENTIFIER {
3930 LocatedToken lt = (LocatedToken) $3;
3931 ArrayList a = (ArrayList) $1;
3932 a.Add (new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location));
3937 explicitly_typed_lambda_parameter_list
3938 : explicitly_typed_lambda_parameter
3940 ArrayList pars = new ArrayList (4);
3945 | explicitly_typed_lambda_parameter_list COMMA explicitly_typed_lambda_parameter
3947 ArrayList pars = (ArrayList) $1;
3954 explicitly_typed_lambda_parameter
3955 : parameter_modifier type IDENTIFIER
3957 LocatedToken lt = (LocatedToken) $3;
3959 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3963 LocatedToken lt = (LocatedToken) $2;
3965 $$ = new Parameter ((Expression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
3969 lambda_parameter_list
3970 : implicitly_typed_lambda_parameter_list { $$ = $1; }
3971 | explicitly_typed_lambda_parameter_list { $$ = $1; }
3974 opt_lambda_parameter_list
3975 : /* empty */ { $$ = null; }
3976 | lambda_parameter_list {
3977 ArrayList pars_list = (ArrayList) $1;
3979 Parameter [] pars = new Parameter [pars_list.Count];
3980 pars_list.CopyTo (pars);
3981 $$ = new Parameters (pars);
3985 lambda_expression_body
3987 start_block (lexer.Location);
3991 Block b = end_block (lexer.Location);
3992 b.AddStatement (new ContextualReturn ((Expression) $2));
4003 Parameter [] pars = new Parameter [1];
4004 LocatedToken lt = (LocatedToken) $1;
4005 pars [0] = new Parameter ((Expression)null, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
4007 Parameters parameters = new Parameters (pars);
4009 start_anonymous (true, parameters, (Location) $2);
4011 lambda_expression_body
4013 $$ = end_anonymous ((ToplevelBlock) $4, (Location) $2);
4015 | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW
4017 start_anonymous (true, (Parameters) $2, (Location) $4);
4019 lambda_expression_body
4021 $$ = end_anonymous ((ToplevelBlock) $6, (Location) $4);
4026 : assignment_expression
4027 | non_assignment_expression
4030 non_assignment_expression
4031 : conditional_expression
4053 lexer.ConstraintsParsing = true;
4057 MemberName name = MakeName ((MemberName) $6);
4058 int mod_flags = (int) $2;
4060 push_current_class (new Class (
4061 current_namespace, current_class, name,
4062 mod_flags, (Attributes) $1), false, $3);
4065 opt_type_parameter_constraints_clauses
4067 lexer.ConstraintsParsing = false;
4070 if (current_class.Name == "System.Object") {
4071 Report.Error (537, current_class.Location,
4072 "The class System.Object cannot have a base " +
4073 "class or implement an interface.");
4075 current_container.AddBasesForPart (current_class, (ArrayList) $8);
4078 current_class.SetParameterInfo ((ArrayList) $9);
4080 if (RootContext.Documentation != null) {
4081 current_container.DocComment = Lexer.consume_doc_comment ();
4082 Lexer.doc_state = XmlCommentState.Allowed;
4087 if (RootContext.Documentation != null)
4088 Lexer.doc_state = XmlCommentState.Allowed;
4092 $$ = pop_current_class ();
4100 { $$ = $1; } // location
4104 : /* empty */ { $$ = (int) 0; }
4110 | modifiers modifier
4115 if ((m1 & m2) != 0) {
4116 Location l = lexer.Location;
4117 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
4119 $$ = (int) (m1 | m2);
4124 : NEW { $$ = Modifiers.NEW; }
4125 | PUBLIC { $$ = Modifiers.PUBLIC; }
4126 | PROTECTED { $$ = Modifiers.PROTECTED; }
4127 | INTERNAL { $$ = Modifiers.INTERNAL; }
4128 | PRIVATE { $$ = Modifiers.PRIVATE; }
4129 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
4130 | SEALED { $$ = Modifiers.SEALED; }
4131 | STATIC { $$ = Modifiers.STATIC; }
4132 | READONLY { $$ = Modifiers.READONLY; }
4133 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
4134 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
4135 | EXTERN { $$ = Modifiers.EXTERN; }
4136 | VOLATILE { $$ = Modifiers.VOLATILE; }
4137 | UNSAFE { $$ = Modifiers.UNSAFE; }
4141 : /* empty */ { $$ = null; }
4142 | class_base { $$ = $1; }
4146 : COLON type_list { $$ = $2; }
4149 opt_type_parameter_constraints_clauses
4150 : /* empty */ { $$ = null; }
4151 | type_parameter_constraints_clauses
4155 type_parameter_constraints_clauses
4156 : type_parameter_constraints_clause {
4157 ArrayList constraints = new ArrayList (1);
4158 constraints.Add ($1);
4161 | type_parameter_constraints_clauses type_parameter_constraints_clause {
4162 ArrayList constraints = (ArrayList) $1;
4163 Constraints new_constraint = (Constraints)$2;
4165 foreach (Constraints c in constraints) {
4166 if (new_constraint.TypeParameter == c.TypeParameter) {
4167 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
4168 new_constraint.TypeParameter);
4172 constraints.Add (new_constraint);
4177 type_parameter_constraints_clause
4178 : WHERE IDENTIFIER COLON type_parameter_constraints {
4179 LocatedToken lt = (LocatedToken) $2;
4180 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
4184 type_parameter_constraints
4185 : type_parameter_constraint {
4186 ArrayList constraints = new ArrayList (1);
4187 constraints.Add ($1);
4190 | type_parameter_constraints COMMA type_parameter_constraint {
4191 ArrayList constraints = (ArrayList) $1;
4193 constraints.Add ($3);
4198 type_parameter_constraint
4200 | NEW OPEN_PARENS CLOSE_PARENS {
4201 $$ = SpecialConstraint.Constructor;
4204 $$ = SpecialConstraint.ReferenceType;
4207 $$ = SpecialConstraint.ValueType;
4216 // A block is "contained" on the following places:
4218 // property_declaration as part of the accessor body (get/set)
4219 // operator_declaration
4220 // constructor_declaration
4221 // destructor_declaration
4222 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4227 start_block ((Location) $1);
4229 opt_statement_list CLOSE_BRACE
4231 $$ = end_block ((Location) $4);
4237 opt_statement_list CLOSE_BRACE
4239 $$ = end_block ((Location) $3);
4250 | statement_list statement
4254 : declaration_statement
4256 if ($1 != null && (Block) $1 != current_block){
4257 current_block.AddStatement ((Statement) $1);
4258 current_block = (Block) $1;
4261 | valid_declaration_statement
4263 current_block.AddStatement ((Statement) $1);
4268 valid_declaration_statement
4271 | expression_statement
4272 | selection_statement
4273 | iteration_statement
4277 | unchecked_statement
4285 : valid_declaration_statement
4286 | declaration_statement
4288 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4293 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4301 $$ = EmptyStatement.Value;
4308 LocatedToken lt = (LocatedToken) $1;
4309 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4311 if (current_block.AddLabel (labeled))
4312 current_block.AddStatement (labeled);
4317 declaration_statement
4318 : local_variable_declaration SEMICOLON
4320 current_array_type = null;
4322 DictionaryEntry de = (DictionaryEntry) $1;
4323 Expression e = (Expression) de.Key;
4325 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4329 | local_constant_declaration SEMICOLON
4331 current_array_type = null;
4333 DictionaryEntry de = (DictionaryEntry) $1;
4335 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4341 * The following is from Rhys' grammar:
4342 * > Types in local variable declarations must be recognized as
4343 * > expressions to prevent reduce/reduce errors in the grammar.
4344 * > The expressions are converted into types during semantic analysis.
4347 : primary_expression opt_rank_specifier_or_nullable
4349 // FIXME: Do something smart here regarding the composition of the type.
4351 // Ok, the above "primary_expression" is there to get rid of
4352 // both reduce/reduce and shift/reduces in the grammar, it should
4353 // really just be "type_name". If you use type_name, a reduce/reduce
4354 // creeps up. If you use namespace_or_type_name (which is all we need
4355 // really) two shift/reduces appear.
4358 // So the super-trick is that primary_expression
4359 // can only be either a SimpleName or a MemberAccess.
4360 // The MemberAccess case arises when you have a fully qualified type-name like :
4362 // SimpleName is when you have
4365 Expression expr = (Expression) $1;
4366 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4367 Error_ExpectingTypeName (expr);
4371 // So we extract the string corresponding to the SimpleName
4375 if ((string) $2 == "")
4378 $$ = new ComposedCast ((Expression) $1, (string) $2);
4381 | builtin_types opt_rank_specifier_or_nullable
4383 if ((string) $2 == "")
4386 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4390 local_variable_pointer_type
4391 : primary_expression STAR
4393 Expression expr = (Expression) $1;
4395 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4396 Error_ExpectingTypeName (expr);
4400 $$ = new ComposedCast ((Expression) $1, "*");
4402 | builtin_types STAR
4404 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4408 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4410 | local_variable_pointer_type STAR
4412 $$ = new ComposedCast ((Expression) $1, "*");
4416 local_variable_declaration
4417 : local_variable_type variable_declarators
4420 $$ = new DictionaryEntry ($1, $2);
4424 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4429 if ((string) $2 == "")
4430 t = (Expression) $1;
4432 t = new ComposedCast ((Expression) $1, (string) $2);
4433 $$ = new DictionaryEntry (t, $3);
4439 local_constant_declaration
4440 : CONST local_variable_type constant_declarators
4443 $$ = new DictionaryEntry ($2, $3);
4449 expression_statement
4450 : statement_expression SEMICOLON { $$ = $1; }
4454 // We have to do the wrapping here and not in the case above,
4455 // because statement_expression is used for example in for_statement
4457 statement_expression
4460 Expression expr = (Expression) $1;
4461 ExpressionStatement s = expr as ExpressionStatement;
4463 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4466 $$ = new StatementExpression (s);
4470 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4475 object_creation_expression
4476 : object_or_delegate_creation_expression
4477 { note ("complain if this is a delegate maybe?"); }
4486 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4489 Location l = (Location) $1;
4491 $$ = new If ((Expression) $3, (Statement) $5, l);
4493 // FIXME: location for warning should be loc property of $5.
4494 if ($5 == EmptyStatement.Value)
4495 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4498 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4499 embedded_statement ELSE embedded_statement
4501 Location l = (Location) $1;
4503 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4505 // FIXME: location for warning should be loc property of $5 and $7.
4506 if ($5 == EmptyStatement.Value)
4507 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4508 if ($7 == EmptyStatement.Value)
4509 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4514 : SWITCH OPEN_PARENS
4516 if (switch_stack == null)
4517 switch_stack = new Stack (2);
4518 switch_stack.Push (current_block);
4520 expression CLOSE_PARENS
4523 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4524 current_block = (Block) switch_stack.Pop ();
4540 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4541 $$ = new ArrayList ();
4549 ArrayList sections = new ArrayList (4);
4554 | switch_sections switch_section
4556 ArrayList sections = (ArrayList) $1;
4566 current_block = current_block.CreateSwitchBlock (lexer.Location);
4570 Block topmost = current_block;
4572 while (topmost.Implicit)
4573 topmost = topmost.Parent;
4574 $$ = new SwitchSection ((ArrayList) $1, topmost);
4581 ArrayList labels = new ArrayList (4);
4586 | switch_labels switch_label
4588 ArrayList labels = (ArrayList) ($1);
4596 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4597 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4600 1523, GetLocation ($1),
4601 "The keyword case or default must precede code in switch block");
4613 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4615 Location l = (Location) $1;
4616 $$ = new While ((Expression) $3, (Statement) $5, l);
4621 : DO embedded_statement
4622 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4624 Location l = (Location) $1;
4626 $$ = new Do ((Statement) $2, (Expression) $5, l);
4632 opt_for_initializer SEMICOLON
4634 Block assign_block = new Block (current_block);
4635 current_block = assign_block;
4637 if ($3 is DictionaryEntry){
4638 DictionaryEntry de = (DictionaryEntry) $3;
4640 Expression type = (Expression) de.Key;
4641 ArrayList var_declarators = (ArrayList) de.Value;
4643 foreach (VariableDeclaration decl in var_declarators){
4647 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4651 Location l = lexer.Location;
4652 Expression expr = decl.expression_or_array_initializer;
4654 LocalVariableReference var;
4655 var = new LocalVariableReference (assign_block, decl.identifier, l);
4658 Assign a = new Assign (var, expr, decl.Location);
4660 assign_block.AddStatement (new StatementExpression (a));
4664 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4665 // This can be referred to as $5 below.
4671 opt_for_condition SEMICOLON
4672 opt_for_iterator CLOSE_PARENS
4675 Location l = (Location) $1;
4677 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4679 current_block.AddStatement (f);
4680 while (current_block.Implicit)
4681 current_block = current_block.Parent;
4683 current_block = current_block.Parent;
4688 : /* empty */ { $$ = EmptyStatement.Value; }
4693 : local_variable_declaration
4694 | statement_expression_list
4698 : /* empty */ { $$ = null; }
4699 | boolean_expression
4703 : /* empty */ { $$ = EmptyStatement.Value; }
4708 : statement_expression_list
4711 statement_expression_list
4712 : statement_expression
4714 // CHANGE: was `null'
4715 Statement s = (Statement) $1;
4716 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4721 | statement_expression_list COMMA statement_expression
4723 Block b = (Block) $1;
4725 b.AddStatement ((Statement) $3);
4731 : FOREACH open_parens type IN expression CLOSE_PARENS
4733 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4736 | FOREACH open_parens type IDENTIFIER IN
4737 expression CLOSE_PARENS
4739 Block foreach_block = new Block (current_block);
4740 current_block = foreach_block;
4742 LocatedToken lt = (LocatedToken) $4;
4743 Location l = lt.Location;
4746 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4748 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4750 // Get a writable reference to this read-only variable.
4752 // Note that the $$ here refers to the value of _this_ code block,
4753 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4754 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4761 LocalVariableReference v = (LocalVariableReference) $8;
4762 Location l = (Location) $1;
4765 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4766 current_block.AddStatement (f);
4769 while (current_block.Implicit)
4770 current_block = current_block.Parent;
4772 current_block = current_block.Parent;
4778 | continue_statement
4788 $$ = new Break ((Location) $1);
4793 : CONTINUE SEMICOLON
4795 $$ = new Continue ((Location) $1);
4800 : GOTO IDENTIFIER SEMICOLON
4802 LocatedToken lt = (LocatedToken) $2;
4803 $$ = new Goto (lt.Value, lt.Location);
4805 | GOTO CASE constant_expression SEMICOLON
4807 $$ = new GotoCase ((Expression) $3, (Location) $1);
4809 | GOTO DEFAULT SEMICOLON
4811 $$ = new GotoDefault ((Location) $1);
4816 : RETURN opt_expression SEMICOLON
4818 $$ = new Return ((Expression) $2, (Location) $1);
4823 : THROW opt_expression SEMICOLON
4825 $$ = new Throw ((Expression) $2, (Location) $1);
4830 : IDENTIFIER RETURN expression SEMICOLON
4832 LocatedToken lt = (LocatedToken) $1;
4833 string s = lt.Value;
4835 Report.Error (1003, lt.Location, "; expected");
4838 if (RootContext.Version == LanguageVersion.ISO_1){
4839 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
4842 if (anonymous_host == null){
4843 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4846 anonymous_host.SetYields ();
4847 $$ = new Yield ((Expression) $3, lt.Location);
4850 | IDENTIFIER RETURN SEMICOLON
4852 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4855 | IDENTIFIER BREAK SEMICOLON
4857 LocatedToken lt = (LocatedToken) $1;
4858 string s = lt.Value;
4860 Report.Error (1003, lt.Location, "; expected");
4863 if (RootContext.Version == LanguageVersion.ISO_1){
4864 Report.FeatureIsNotISO1 (lt.Location, "yield statement");
4867 if (anonymous_host == null){
4868 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4871 anonymous_host.SetYields ();
4872 $$ = new YieldBreak (lt.Location);
4883 : TRY block catch_clauses
4887 ArrayList c = (ArrayList)$3;
4888 for (int i = 0; i < c.Count; ++i) {
4889 Catch cc = (Catch) c [i];
4891 if (i != c.Count - 1)
4892 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4899 // Now s contains the list of specific catch clauses
4900 // and g contains the general one.
4902 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4904 | TRY block opt_catch_clauses FINALLY block
4907 ArrayList s = new ArrayList (4);
4908 ArrayList catch_list = (ArrayList) $3;
4910 if (catch_list != null){
4911 foreach (Catch cc in catch_list) {
4919 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4923 Report.Error (1524, (Location) $1, "Expected catch or finally");
4929 : /* empty */ { $$ = null; }
4936 ArrayList l = new ArrayList (4);
4941 | catch_clauses catch_clause
4943 ArrayList l = (ArrayList) $1;
4951 : /* empty */ { $$ = null; }
4956 : CATCH opt_catch_args
4958 Expression type = null;
4961 DictionaryEntry cc = (DictionaryEntry) $2;
4962 type = (Expression) cc.Key;
4963 LocatedToken lt = (LocatedToken) cc.Value;
4966 ArrayList one = new ArrayList (4);
4968 one.Add (new VariableDeclaration (lt, null));
4970 current_block = new Block (current_block);
4971 Block b = declare_local_variables (type, one, lt.Location);
4976 Expression type = null;
4978 Block var_block = null;
4981 DictionaryEntry cc = (DictionaryEntry) $2;
4982 type = (Expression) cc.Key;
4983 LocatedToken lt = (LocatedToken) cc.Value;
4987 while (current_block.Implicit)
4988 current_block = current_block.Parent;
4989 var_block = current_block;
4990 current_block = current_block.Parent;
4994 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
4999 : /* empty */ { $$ = null; }
5004 : open_parens type opt_identifier CLOSE_PARENS
5006 $$ = new DictionaryEntry ($2, $3);
5014 $$ = new Checked ((Block) $2);
5021 $$ = new Unchecked ((Block) $2);
5028 RootContext.CheckUnsafeOption ((Location) $1);
5030 $$ = new Unsafe ((Block) $3);
5036 type fixed_pointer_declarators
5039 ArrayList list = (ArrayList) $4;
5040 Expression type = (Expression) $3;
5041 Location l = (Location) $1;
5042 int top = list.Count;
5044 Block assign_block = new Block (current_block);
5045 current_block = assign_block;
5047 for (int i = 0; i < top; i++){
5048 Pair p = (Pair) list [i];
5051 v = current_block.AddVariable (type, (string) p.First, l);
5055 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
5063 Location l = (Location) $1;
5065 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
5067 current_block.AddStatement (f);
5068 while (current_block.Implicit)
5069 current_block = current_block.Parent;
5071 current_block = current_block.Parent;
5075 fixed_pointer_declarators
5076 : fixed_pointer_declarator {
5077 ArrayList declarators = new ArrayList (4);
5079 declarators.Add ($1);
5082 | fixed_pointer_declarators COMMA fixed_pointer_declarator
5084 ArrayList declarators = (ArrayList) $1;
5086 declarators.Add ($3);
5091 fixed_pointer_declarator
5092 : IDENTIFIER ASSIGN expression
5094 LocatedToken lt = (LocatedToken) $1;
5095 // FIXME: keep location
5096 $$ = new Pair (lt.Value, $3);
5100 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
5106 : LOCK OPEN_PARENS expression CLOSE_PARENS
5112 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
5117 : USING open_parens resource_acquisition CLOSE_PARENS
5119 Block assign_block = new Block (current_block);
5120 current_block = assign_block;
5122 if ($3 is DictionaryEntry){
5123 DictionaryEntry de = (DictionaryEntry) $3;
5124 Location l = (Location) $1;
5126 Expression type = (Expression) de.Key;
5127 ArrayList var_declarators = (ArrayList) de.Value;
5129 ArrayList vars = new ArrayList (4);
5131 foreach (VariableDeclaration decl in var_declarators){
5133 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
5136 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
5138 Expression expr = decl.expression_or_array_initializer;
5140 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
5143 LocalVariableReference var;
5145 // Get a writable reference to this read-only variable.
5146 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
5148 // This is so that it is not a warning on using variables
5151 vars.Add (new DictionaryEntry (var, expr));
5153 // Assign a = new Assign (var, expr, decl.Location);
5154 // assign_block.AddStatement (new StatementExpression (a));
5157 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
5158 // It can be referred to as $5 below.
5159 $$ = new DictionaryEntry (type, vars);
5166 Using u = new Using ($5, (Statement) $6, (Location) $1);
5167 current_block.AddStatement (u);
5168 while (current_block.Implicit)
5169 current_block = current_block.Parent;
5171 current_block = current_block.Parent;
5175 resource_acquisition
5176 : local_variable_declaration
5184 : from_clause query_body
5186 lexer.QueryParsing = false;
5187 $$ = new QueryExpression ();
5192 : FROM IDENTIFIER IN expression opt_join_clauses
5193 | FROM type IDENTIFIER IN expression opt_join_clauses
5203 | join_clauses join_clause
5207 : JOIN join_clause_body
5208 | JOIN join_clause_body INTO IDENTIFIER
5209 | JOIN type join_clause_body
5210 | JOIN type join_clause_body INTO IDENTIFIER
5214 : IDENTIFIER IN expression ON expression EQUALS expression
5218 : opt_from_let_where_clauses opt_orderby_clause select_clause opt_query_continuation
5219 | opt_from_let_where_clauses opt_orderby_clause group_clause opt_query_continuation
5222 opt_from_let_where_clauses
5224 | from_let_where_clauses
5227 from_let_where_clauses
5228 : from_let_where_clause
5229 | from_let_where_clauses from_let_where_clause
5232 from_let_where_clause
5239 : LET IDENTIFIER ASSIGN expression
5243 : WHERE boolean_expression
5257 | orderings COMMA ordering
5262 | expression ASCENDING
5263 | expression DESCENDING
5271 : GROUP expression BY expression
5274 opt_query_continuation
5276 | query_continuation
5280 : INTO IDENTIFIER opt_join_clauses query_body
5286 // A class used to pass around variable declarations and constants
5288 public class VariableDeclaration {
5289 public string identifier;
5290 public Expression expression_or_array_initializer;
5291 public Location Location;
5292 public Attributes OptAttributes;
5293 public string DocComment;
5295 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
5297 this.identifier = lt.Value;
5298 if (eoai is ArrayList) {
5299 if (CSharpParser.current_array_type == null)
5300 Report.Error (622, lt.Location,
5301 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
5302 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
5304 this.expression_or_array_initializer = (Expression)eoai;
5306 this.Location = lt.Location;
5307 this.OptAttributes = opt_attrs;
5310 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5316 // A class used to hold info about an indexer declarator
5318 public class IndexerDeclaration {
5319 public Expression type;
5320 public MemberName interface_type;
5321 public Parameters param_list;
5322 public Location location;
5324 public IndexerDeclaration (Expression type, MemberName interface_type,
5325 Parameters param_list, Location loc)
5328 this.interface_type = interface_type;
5329 this.param_list = param_list;
5330 this.location = loc;
5335 // We use this when we do not have an object in advance that is an IAnonymousHost
5337 public class SimpleAnonymousHost : IAnonymousHost {
5338 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5341 ArrayList anonymous_methods;
5343 public static SimpleAnonymousHost GetSimple () {
5344 Simple.yields = false;
5345 Simple.anonymous_methods = null;
5349 public void SetYields ()
5354 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5356 if (anonymous_methods == null)
5357 anonymous_methods = new ArrayList ();
5358 anonymous_methods.Add (anonymous);
5361 public void Propagate (IAnonymousHost real_host)
5364 real_host.SetYields ();
5365 if (anonymous_methods != null) {
5366 foreach (AnonymousMethodExpression ame in anonymous_methods)
5367 real_host.AddAnonymousMethod (ame);
5373 // A class used to hold info about an operator declarator
5375 public class OperatorDeclaration {
5376 public Operator.OpType optype;
5377 public Expression ret_type, arg1type, arg2type;
5378 public string arg1name, arg2name;
5379 public Location location;
5381 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5382 Expression arg1type, string arg1name,
5383 Expression arg2type, string arg2name, Location location)
5386 this.ret_type = ret_type;
5387 this.arg1type = arg1type;
5388 this.arg1name = arg1name;
5389 this.arg2type = arg2type;
5390 this.arg2name = arg2name;
5391 this.location = location;
5396 void Error_ExpectingTypeName (Expression expr)
5398 if (expr is Invocation){
5399 Report.Error (1002, expr.Location, "Expecting `;'");
5401 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5405 public static void Error_ParameterModifierNotValid (Location loc)
5407 Report.Error (631, loc, "The modifiers `ref' and `out' are not valid in this context");
5410 static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod)
5412 Report.Error (1107, loc, "Duplicate parameter modifier `{0}'",
5413 Parameter.GetModifierSignature (mod));
5416 void push_current_class (TypeContainer tc, bool is_interface, object partial_token)
5418 if (partial_token != null)
5419 current_container = current_container.AddPartial (tc, is_interface);
5421 current_container = current_container.AddTypeContainer (tc, is_interface);
5425 DeclSpace pop_current_class ()
5427 DeclSpace retval = current_class;
5429 current_class = current_class.Parent;
5430 current_container = current_class.PartialContainer;
5436 // Given the @class_name name, it creates a fully qualified name
5437 // based on the containing declaration space
5440 MakeName (MemberName class_name)
5442 Namespace ns = current_namespace.NS;
5444 if (current_container.Name.Length == 0){
5445 if (ns.Name.Length != 0)
5446 return new MemberName (ns.MemberName, class_name);
5450 return new MemberName (current_container.MemberName, class_name);
5454 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5456 Block implicit_block;
5457 ArrayList inits = null;
5460 // We use the `Used' property to check whether statements
5461 // have been added to the current block. If so, we need
5462 // to create another block to contain the new declaration
5463 // otherwise, as an optimization, we use the same block to
5464 // add the declaration.
5466 // FIXME: A further optimization is to check if the statements
5467 // that were added were added as part of the initialization
5468 // below. In which case, no other statements have been executed
5469 // and we might be able to reduce the number of blocks for
5470 // situations like this:
5472 // int j = 1; int k = j + 1;
5474 if (current_block.Used)
5475 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5477 implicit_block = current_block;
5479 foreach (VariableDeclaration decl in variable_declarators){
5481 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5482 if (decl.expression_or_array_initializer != null){
5484 inits = new ArrayList (4);
5491 return implicit_block;
5493 foreach (VariableDeclaration decl in inits){
5495 Expression expr = decl.expression_or_array_initializer;
5497 LocalVariableReference var;
5498 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5500 assign = new Assign (var, expr, decl.Location);
5502 implicit_block.AddStatement (new StatementExpression (assign));
5505 return implicit_block;
5508 Block declare_local_constants (Expression type, ArrayList declarators)
5510 Block implicit_block;
5512 if (current_block.Used)
5513 implicit_block = new Block (current_block, Block.Flags.Implicit);
5515 implicit_block = current_block;
5517 foreach (VariableDeclaration decl in declarators){
5518 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5521 return implicit_block;
5524 string CheckAttributeTarget (string a, Location l)
5527 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5531 Report.Warning (658, 1, l,
5532 "`{0}' is invalid attribute target. All attributes in this attribute section will be ignored", a);
5533 return string.Empty;
5536 void CheckUnaryOperator (Operator.OpType op, Location l)
5540 case Operator.OpType.LogicalNot:
5541 case Operator.OpType.OnesComplement:
5542 case Operator.OpType.Increment:
5543 case Operator.OpType.Decrement:
5544 case Operator.OpType.True:
5545 case Operator.OpType.False:
5546 case Operator.OpType.Addition:
5547 case Operator.OpType.Subtraction:
5552 Report.Error (1019, l, "Overloadable unary operator expected");
5558 void CheckBinaryOperator (Operator.OpType op, Location l)
5562 case Operator.OpType.Addition:
5563 case Operator.OpType.Subtraction:
5564 case Operator.OpType.Multiply:
5565 case Operator.OpType.Division:
5566 case Operator.OpType.Modulus:
5567 case Operator.OpType.BitwiseAnd:
5568 case Operator.OpType.BitwiseOr:
5569 case Operator.OpType.ExclusiveOr:
5570 case Operator.OpType.LeftShift:
5571 case Operator.OpType.RightShift:
5572 case Operator.OpType.Equality:
5573 case Operator.OpType.Inequality:
5574 case Operator.OpType.GreaterThan:
5575 case Operator.OpType.LessThan:
5576 case Operator.OpType.GreaterThanOrEqual:
5577 case Operator.OpType.LessThanOrEqual:
5581 Report.Error (1020, l, "Overloadable binary operator expected");
5587 void syntax_error (Location l, string msg)
5589 Report.Error (1003, l, "Syntax error, " + msg);
5592 void note (string s)
5594 // Used to put annotations
5599 public Tokenizer Lexer {
5605 static CSharpParser ()
5607 oob_stack = new Stack ();
5610 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5612 this.name = file.Name;
5614 current_namespace = new NamespaceEntry (null, file, null);
5615 current_class = current_namespace.SlaveDeclSpace;
5616 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5618 lexer = new Tokenizer (reader, file, defines);
5621 public void parse ()
5623 int errors = Report.Errors;
5625 if (yacc_verbose_flag > 1)
5626 yyparse (lexer, new yydebug.yyDebugSimple ());
5629 Tokenizer tokenizer = lexer as Tokenizer;
5630 tokenizer.cleanup ();
5631 } catch (Exception e){
5633 // Removed for production use, use parser verbose to get the output.
5635 // Console.WriteLine (e);
5636 if (Report.Errors == errors)
5637 Report.Error (-25, lexer.Location, "Parsing error");
5638 if (yacc_verbose_flag > 0)
5639 Console.WriteLine (e);
5642 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5643 throw new InternalErrorException ("who set it?");
5646 static void CheckToken (int error, int yyToken, string msg, Location loc)
5648 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5649 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5651 Report.Error (error, loc, msg);
5654 void CheckIdentifierToken (int yyToken, Location loc)
5656 CheckToken (1041, yyToken, "Identifier expected", loc);
5659 string ConsumeStoredComment ()
5661 string s = tmpComment;
5663 Lexer.doc_state = XmlCommentState.Allowed;
5667 Location GetLocation (object obj)
5669 if (obj is MemberCore)
5670 return ((MemberCore) obj).Location;
5671 if (obj is MemberName)
5672 return ((MemberName) obj).Location;
5673 if (obj is LocatedToken)
5674 return ((LocatedToken) obj).Location;
5675 if (obj is Location)
5676 return (Location) obj;
5677 return lexer.Location;
5681 start_block (Location loc)
5683 if (parsing_anonymous_method) {
5684 top_current_block = new ToplevelBlock (
5685 current_block, current_local_parameters, current_generic_method, loc);
5686 if (current_block != null)
5687 current_block.AddAnonymousChild ((ToplevelBlock) top_current_block);
5688 current_block = top_current_block;
5689 parsing_anonymous_method = false;
5690 } else if (current_block == null) {
5691 current_block = new ToplevelBlock (
5692 (ToplevelBlock) top_current_block, current_local_parameters,
5693 current_generic_method, loc);
5694 top_current_block = current_block;
5696 current_block = new Block (current_block, loc, Location.Null);
5701 end_block (Location loc)
5705 while (current_block.Implicit)
5706 current_block = current_block.Parent;
5707 retval = current_block;
5708 current_block.SetEndLocation (loc);
5709 current_block = current_block.Parent;
5710 if (current_block == null)
5711 top_current_block = null;
5716 start_anonymous (bool lambda, Parameters parameters, Location loc)
5718 oob_stack.Push (current_anonymous_method);
5719 oob_stack.Push (current_local_parameters);
5721 current_local_parameters = parameters;
5723 // Force the next block to be created as a ToplevelBlock
5724 oob_stack.Push (current_block);
5725 oob_stack.Push (top_current_block);
5727 current_anonymous_method = lambda
5728 ? new LambdaExpression (
5729 current_anonymous_method, current_generic_method, current_container,
5730 parameters, (ToplevelBlock) top_current_block, loc)
5731 : new AnonymousMethodExpression (
5732 current_anonymous_method, current_generic_method, current_container,
5733 parameters, (ToplevelBlock) top_current_block, loc);
5735 parsing_anonymous_method = true;
5739 * Completes the anonymous method processing, if lambda_expr is null, this
5740 * means that we have a Statement instead of an Expression embedded
5742 AnonymousMethodExpression
5743 end_anonymous (ToplevelBlock anon_block, Location loc)
5745 AnonymousMethodExpression retval;
5747 top_current_block = (Block) oob_stack.Pop ();
5748 current_block = (Block) oob_stack.Pop ();
5750 if (RootContext.Version == LanguageVersion.ISO_1){
5751 Report.FeatureIsNotISO1 (loc, "anonymous methods");
5754 anon_block.Parent = current_block;
5756 current_anonymous_method.Block = anon_block;
5757 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
5758 anonymous_host.AddAnonymousMethod (current_anonymous_method);
5760 retval = current_anonymous_method;
5763 current_local_parameters = (Parameters) oob_stack.Pop ();
5764 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();