3 // cs-parser.jay: The Parser for the C# compiler
5 // Authors: Miguel de Icaza (miguel@gnu.org)
6 // Ravi Pratap (ravi@ximian.com)
8 // Licensed under the terms of the GNU GPL
10 // (C) 2001 Ximian, Inc (http://www.ximian.com)
11 // (C) 2004 Novell, Inc
14 // (1) Figure out why error productions dont work. `type-declaration' is a
15 // great spot to put an `error' because you can reproduce it with this input:
18 // Possible optimization:
19 // Run memory profiler with parsing only, and consider dropping
20 // arraylists where not needed. Some pieces can use linked lists.
28 using System.Collections;
33 public class CSharpParser {
34 NamespaceEntry current_namespace;
35 TypeContainer current_container;
36 DeclSpace current_class;
38 IAnonymousHost anonymous_host;
41 /// Current block is used to add statements as we find
44 Block current_block, top_current_block;
46 Delegate current_delegate;
48 GenericMethod current_generic_method;
49 AnonymousMethodExpression current_anonymous_method;
52 /// This is used by the unary_expression code to resolve
53 /// a name against a parameter.
55 Parameters current_local_parameters;
58 /// Using during property parsing to describe the implicit
59 /// value parameter that is passed to the "set" and "get"accesor
60 /// methods (properties and indexers).
62 Expression implicit_value_parameter_type;
63 Parameters indexer_parameters;
66 /// Hack to help create non-typed array initializer
68 public static Expression current_array_type;
69 Expression pushed_current_array_type;
72 /// Used to determine if we are parsing the get/set pair
73 /// of an indexer or a property
77 bool parsing_anonymous_method;
80 /// An out-of-band stack.
89 static public int yacc_verbose_flag;
91 // Name of the file we are parsing
100 /// Temporary Xml documentation cache.
101 /// For enum types, we need one more temporary store.
104 string enumTypeComment;
106 /// Current attribute target
107 string current_attr_target;
109 /// assembly and module attribute definitions are enabled
110 bool global_attrs_enabled = true;
111 bool has_get, has_set;
116 %token NONE /* This token is never returned by our lexer */
117 %token ERROR // This is used not by the parser, but by the tokenizer.
121 *These are the C# keywords
208 /* C# keywords which are not really keywords */
214 /* C# single character operators/punctuation. */
215 %token OPEN_BRACE "{"
216 %token CLOSE_BRACE "}"
217 %token OPEN_BRACKET "["
218 %token CLOSE_BRACKET "]"
219 %token OPEN_PARENS "("
220 %token CLOSE_PARENS ")"
232 %token OP_GENERICS_LT "<"
234 %token OP_GENERICS_GT ">"
235 %token BITWISE_AND "&"
236 %token BITWISE_OR "|"
243 /* C# multi-character operators. */
244 %token DOUBLE_COLON "::"
247 %token OP_SHIFT_LEFT "<<"
248 %token OP_SHIFT_RIGHT ">>"
255 %token OP_MULT_ASSIGN "*="
256 %token OP_DIV_ASSIGN "/="
257 %token OP_MOD_ASSIGN "%="
258 %token OP_ADD_ASSIGN "+="
259 %token OP_SUB_ASSIGN "-="
260 %token OP_SHIFT_LEFT_ASSIGN "<<="
261 %token OP_SHIFT_RIGHT_ASSIGN ">>="
262 %token OP_AND_ASSIGN "&="
263 %token OP_XOR_ASSIGN "^="
264 %token OP_OR_ASSIGN "|="
268 %token LITERAL_INTEGER "int literal"
269 %token LITERAL_FLOAT "float literal"
270 %token LITERAL_DOUBLE "double literal"
271 %token LITERAL_DECIMAL "decimal literal"
272 %token LITERAL_CHARACTER "character literal"
273 %token LITERAL_STRING "string literal"
276 %token CLOSE_PARENS_CAST
277 %token CLOSE_PARENS_NO_CAST
278 %token CLOSE_PARENS_OPEN_PARENS
279 %token CLOSE_PARENS_MINUS
280 %token DEFAULT_OPEN_PARENS
281 %token GENERIC_DIMENSION
283 /* Add precedence rules to solve dangling else s/r conflict */
292 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
294 %left STAR DIV PERCENT
295 %right BANG CARRET UMINUS
296 %nonassoc OP_INC OP_DEC
298 %left OPEN_BRACKET OPEN_BRACE
302 %start compilation_unit
306 : outer_declarations opt_EOF
307 | outer_declarations global_attributes opt_EOF
308 | global_attributes opt_EOF
309 | opt_EOF /* allow empty files */
315 Lexer.check_incorrect_doc_comment ();
319 Lexer.check_incorrect_doc_comment ();
325 | outer_declarations outer_declaration
329 : extern_alias_directive
331 | namespace_member_declaration
334 extern_alias_directives
335 : extern_alias_directive
336 | extern_alias_directives extern_alias_directive;
338 extern_alias_directive
339 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
341 LocatedToken lt = (LocatedToken) $2;
344 Report.Error (1003, lt.Location, "'alias' expected");
345 } else if (RootContext.Version == LanguageVersion.ISO_1) {
346 Report.FeatureIsNotStandardized (lt.Location, "external alias");
348 lt = (LocatedToken) $3;
349 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
356 | using_directives using_directive
360 : using_alias_directive
362 if (RootContext.Documentation != null)
363 Lexer.doc_state = XmlCommentState.Allowed;
365 | using_namespace_directive
367 if (RootContext.Documentation != null)
368 Lexer.doc_state = XmlCommentState.Allowed;
372 using_alias_directive
373 : USING IDENTIFIER ASSIGN
374 namespace_or_type_name SEMICOLON
376 LocatedToken lt = (LocatedToken) $2;
377 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
380 CheckIdentifierToken (yyToken, GetLocation ($2));
384 using_namespace_directive
385 : USING namespace_name SEMICOLON
387 current_namespace.Using ((MemberName) $2, (Location) $1);
392 // Strictly speaking, namespaces don't have attributes but
393 // we parse global attributes along with namespace declarations and then
396 namespace_declaration
397 : opt_attributes NAMESPACE namespace_or_type_name
399 MemberName name = (MemberName) $3;
402 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
405 if (name.TypeArguments != null)
406 syntax_error (lexer.Location, "namespace name expected");
408 current_namespace = new NamespaceEntry (
409 current_namespace, file, name.GetName ());
410 current_class = current_namespace.SlaveDeclSpace;
411 current_container = current_class.PartialContainer;
413 namespace_body opt_semicolon
415 current_namespace = current_namespace.Parent;
416 current_class = current_namespace.SlaveDeclSpace;
417 current_container = current_class.PartialContainer;
432 : namespace_or_type_name {
433 MemberName name = (MemberName) $1;
435 if (name.TypeArguments != null)
436 syntax_error (lexer.Location, "namespace name expected");
445 if (RootContext.Documentation != null)
446 Lexer.doc_state = XmlCommentState.Allowed;
448 opt_extern_alias_directives
450 opt_namespace_member_declarations
459 opt_extern_alias_directives
461 | extern_alias_directives
464 opt_namespace_member_declarations
466 | namespace_member_declarations
469 namespace_member_declarations
470 : namespace_member_declaration
471 | namespace_member_declarations namespace_member_declaration
474 namespace_member_declaration
478 DeclSpace ds = (DeclSpace)$1;
480 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
481 Report.Error (1527, ds.Location,
482 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
485 current_namespace.DeclarationFound = true;
487 | namespace_declaration {
488 current_namespace.DeclarationFound = true;
491 | field_declaration {
492 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
494 | method_declaration {
495 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
502 | interface_declaration
504 | delegate_declaration
506 // Enable this when we have handled all errors, because this acts as a generic fallback
509 // Console.WriteLine ("Token=" + yyToken);
510 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
522 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
530 global_attrs_enabled = false;
535 global_attrs_enabled = false;
544 ArrayList sect = (ArrayList) $1;
546 if (global_attrs_enabled) {
547 if (current_attr_target == "module") {
548 CodeGen.Module.AddAttributes (sect);
550 } else if (current_attr_target != null && current_attr_target.Length > 0) {
551 CodeGen.Assembly.AddAttributes (sect);
554 $$ = new Attributes (sect);
557 if (RootContext.Documentation != null) {
558 Lexer.check_incorrect_doc_comment ();
560 XmlCommentState.Allowed;
564 $$ = new Attributes (sect);
566 current_attr_target = null;
568 | attribute_sections attribute_section
570 Attributes attrs = $1 as Attributes;
571 ArrayList sect = (ArrayList) $2;
573 if (global_attrs_enabled) {
574 if (current_attr_target == "module") {
575 CodeGen.Module.AddAttributes (sect);
577 } else if (current_attr_target == "assembly") {
578 CodeGen.Assembly.AddAttributes (sect);
582 attrs = new Attributes (sect);
584 attrs.AddAttributes (sect);
588 attrs = new Attributes (sect);
590 attrs.AddAttributes (sect);
593 current_attr_target = null;
598 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
602 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
608 attribute_target_specifier
609 : attribute_target COLON
611 current_attr_target = (string)$1;
619 LocatedToken lt = (LocatedToken) $1;
620 CheckAttributeTarget (lt.Value, lt.Location);
621 $$ = lt.Value; // Location won't be required anymore.
623 | EVENT { $$ = "event"; }
624 | RETURN { $$ = "return"; }
630 ArrayList attrs = new ArrayList (4);
636 | attribute_list COMMA attribute
638 ArrayList attrs = (ArrayList) $1;
646 : attribute_name opt_attribute_arguments
648 MemberName mname = (MemberName) $1;
649 if (mname.IsGeneric) {
650 Report.Error (404, lexer.Location,
651 "'<' unexpected: attributes cannot be generic");
654 object [] arguments = (object []) $2;
655 MemberName left = mname.Left;
656 string identifier = mname.Name;
658 Expression left_expr = left == null ? null : left.GetTypeExpression ();
660 if (current_attr_target == "assembly" || current_attr_target == "module")
661 // FIXME: supply "nameEscaped" parameter here.
662 $$ = new GlobalAttribute (current_namespace, current_attr_target,
663 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
665 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
670 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
673 opt_attribute_arguments
674 : /* empty */ { $$ = null; }
675 | OPEN_PARENS attribute_arguments CLOSE_PARENS
683 : opt_positional_argument_list
688 $$ = new object [] { $1, null };
691 | positional_argument_list COMMA named_argument_list
693 $$ = new object[] { $1, $3 };
695 | named_argument_list
697 $$ = new object [] { null, $1 };
702 opt_positional_argument_list
703 : /* empty */ { $$ = null; }
704 | positional_argument_list
707 positional_argument_list
710 ArrayList args = new ArrayList (4);
711 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
715 | positional_argument_list COMMA expression
717 ArrayList args = (ArrayList) $1;
718 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
727 ArrayList args = new ArrayList (4);
732 | named_argument_list COMMA named_argument
734 ArrayList args = (ArrayList) $1;
739 | named_argument_list COMMA expression
741 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
747 : IDENTIFIER ASSIGN expression
749 // FIXME: keep location
750 $$ = new DictionaryEntry (
751 ((LocatedToken) $1).Value,
752 new Argument ((Expression) $3, Argument.AType.Expression));
758 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
761 opt_class_member_declarations
763 | class_member_declarations
766 class_member_declarations
767 : class_member_declaration
768 | class_member_declarations
769 class_member_declaration
772 class_member_declaration
773 : constant_declaration // done
774 | field_declaration // done
775 | method_declaration // done
776 | property_declaration // done
777 | event_declaration // done
778 | indexer_declaration // done
779 | operator_declaration // done
780 | constructor_declaration // done
781 | destructor_declaration // done
791 lexer.ConstraintsParsing = true;
795 MemberName name = MakeName ((MemberName) $6);
796 push_current_class (new Struct (
797 current_namespace, current_class, name, (int) $2,
798 (Attributes) $1), false, $3);
801 opt_type_parameter_constraints_clauses
803 lexer.ConstraintsParsing = false;
806 current_container.AddBasesForPart (current_class, (ArrayList) $8);
808 current_class.SetParameterInfo ((ArrayList) $9);
810 if (RootContext.Documentation != null)
811 current_container.DocComment = Lexer.consume_doc_comment ();
815 if (RootContext.Documentation != null)
816 Lexer.doc_state = XmlCommentState.Allowed;
820 $$ = pop_current_class ();
822 | opt_attributes opt_modifiers opt_partial STRUCT error {
823 CheckIdentifierToken (yyToken, GetLocation ($5));
830 if (RootContext.Documentation != null)
831 Lexer.doc_state = XmlCommentState.Allowed;
833 opt_struct_member_declarations CLOSE_BRACE
836 opt_struct_member_declarations
838 | struct_member_declarations
841 struct_member_declarations
842 : struct_member_declaration
843 | struct_member_declarations struct_member_declaration
846 struct_member_declaration
847 : constant_declaration
850 | property_declaration
852 | indexer_declaration
853 | operator_declaration
854 | constructor_declaration
858 * This is only included so we can flag error 575:
859 * destructors only allowed on class types
861 | destructor_declaration
872 int modflags = (int) $2;
873 foreach (VariableDeclaration constant in (ArrayList) $5){
874 Location l = constant.Location;
875 if ((modflags & Modifiers.STATIC) != 0) {
876 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
880 Const c = new Const (
881 current_class, (Expression) $4, (string) constant.identifier,
882 (Expression) constant.expression_or_array_initializer, modflags,
885 if (RootContext.Documentation != null) {
886 c.DocComment = Lexer.consume_doc_comment ();
887 Lexer.doc_state = XmlCommentState.Allowed;
889 current_container.AddConstant (c);
895 : constant_declarator
897 ArrayList constants = new ArrayList (4);
902 | constant_declarators COMMA constant_declarator
905 ArrayList constants = (ArrayList) $1;
912 : IDENTIFIER ASSIGN constant_expression
914 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
918 // A const field requires a value to be provided
919 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
931 Expression type = (Expression) $3;
934 current_array_type = null;
936 foreach (VariableDeclaration var in (ArrayList) $4){
937 Field field = new Field (current_class, type, mod, var.identifier,
938 (Attributes) $1, var.Location);
940 field.Initializer = var.expression_or_array_initializer;
942 if (RootContext.Documentation != null) {
943 field.DocComment = Lexer.consume_doc_comment ();
944 Lexer.doc_state = XmlCommentState.Allowed;
946 current_container.AddField (field);
947 $$ = field; // FIXME: might be better if it points to the top item
954 fixed_variable_declarators
957 Expression type = (Expression) $4;
960 current_array_type = null;
962 foreach (VariableDeclaration var in (ArrayList) $5) {
963 FixedField field = new FixedField (current_class, type, mod, var.identifier,
964 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
966 if (RootContext.Documentation != null) {
967 field.DocComment = Lexer.consume_doc_comment ();
968 Lexer.doc_state = XmlCommentState.Allowed;
970 current_container.AddField (field);
971 $$ = field; // FIXME: might be better if it points to the top item
979 current_array_type = null;
980 Report.Error (670, (Location) $3, "Fields cannot have void type");
984 fixed_variable_declarators
985 : fixed_variable_declarator
987 ArrayList decl = new ArrayList (2);
991 | fixed_variable_declarators COMMA fixed_variable_declarator
993 ArrayList decls = (ArrayList) $1;
999 fixed_variable_declarator
1000 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1002 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1004 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1006 Report.Error (443, lexer.Location, "Value or constant expected");
1007 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1011 variable_declarators
1012 : variable_declarator
1014 ArrayList decl = new ArrayList (4);
1019 | variable_declarators COMMA variable_declarator
1021 ArrayList decls = (ArrayList) $1;
1028 : IDENTIFIER ASSIGN variable_initializer
1030 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1034 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1036 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1038 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1039 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1044 variable_initializer
1053 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1055 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1059 $$ = new ArglistAccess ((Location) $1);
1063 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1070 anonymous_host = (IAnonymousHost) $1;
1071 if (RootContext.Documentation != null)
1072 Lexer.doc_state = XmlCommentState.NotAllowed;
1076 Method method = (Method) $1;
1077 method.Block = (ToplevelBlock) $3;
1078 current_container.AddMethod (method);
1080 anonymous_host = null;
1081 current_generic_method = null;
1082 current_local_parameters = null;
1084 if (RootContext.Documentation != null)
1085 Lexer.doc_state = XmlCommentState.Allowed;
1098 Report.Error (1585, lexer.Location,
1099 "Member modifier `{0}' must precede the member type and name",
1100 Modifiers.Name (i));
1111 type namespace_or_type_name
1112 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1114 lexer.ConstraintsParsing = true;
1116 opt_type_parameter_constraints_clauses
1118 lexer.ConstraintsParsing = false;
1120 MemberName name = (MemberName) $4;
1122 if ($9 != null && name.TypeArguments == null)
1123 Report.Error (80, lexer.Location,
1124 "Constraints are not allowed on non-generic declarations");
1128 GenericMethod generic = null;
1129 if (name.TypeArguments != null) {
1130 generic = new GenericMethod (current_namespace, current_class, name,
1131 (Expression) $3, (Parameters) $6);
1133 generic.SetParameterInfo ((ArrayList) $9);
1136 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1137 name, (Parameters) $6, (Attributes) $1);
1139 anonymous_host = method;
1140 current_local_parameters = (Parameters) $6;
1141 current_generic_method = generic;
1143 if (RootContext.Documentation != null)
1144 method.DocComment = Lexer.consume_doc_comment ();
1150 VOID namespace_or_type_name
1151 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1153 lexer.ConstraintsParsing = true;
1155 opt_type_parameter_constraints_clauses
1157 lexer.ConstraintsParsing = false;
1159 MemberName name = (MemberName) $4;
1161 if ($9 != null && name.TypeArguments == null)
1162 Report.Error (80, lexer.Location,
1163 "Constraints are not allowed on non-generic declarations");
1166 GenericMethod generic = null;
1167 if (name.TypeArguments != null) {
1168 generic = new GenericMethod (current_namespace, current_class, name,
1169 TypeManager.system_void_expr, (Parameters) $6);
1171 generic.SetParameterInfo ((ArrayList) $9);
1174 method = new Method (current_class, generic, TypeManager.system_void_expr,
1175 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1177 anonymous_host = method;
1178 current_local_parameters = (Parameters) $6;
1179 current_generic_method = generic;
1181 if (RootContext.Documentation != null)
1182 method.DocComment = Lexer.consume_doc_comment ();
1189 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1191 MemberName name = (MemberName) $5;
1192 Report.Error (1585, name.Location,
1193 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1195 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1196 0, false, name, (Parameters) $6, (Attributes) $1);
1198 current_local_parameters = (Parameters) $6;
1200 if (RootContext.Documentation != null)
1201 method.DocComment = Lexer.consume_doc_comment ();
1209 | SEMICOLON { $$ = null; }
1212 opt_formal_parameter_list
1213 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1214 | formal_parameter_list
1217 formal_parameter_list
1220 ArrayList pars_list = (ArrayList) $1;
1222 Parameter [] pars = new Parameter [pars_list.Count];
1223 pars_list.CopyTo (pars);
1225 $$ = new Parameters (pars);
1227 | fixed_parameters COMMA parameter_array
1229 ArrayList pars_list = (ArrayList) $1;
1232 Parameter [] pars = new Parameter [pars_list.Count];
1233 pars_list.CopyTo (pars);
1235 $$ = new Parameters (pars);
1237 | fixed_parameters COMMA ARGLIST
1239 ArrayList pars_list = (ArrayList) $1;
1240 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1242 Parameter [] pars = new Parameter [pars_list.Count];
1243 pars_list.CopyTo (pars);
1245 $$ = new Parameters (pars, true);
1247 | parameter_array COMMA error
1250 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1253 | fixed_parameters COMMA parameter_array COMMA error
1256 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1259 | ARGLIST COMMA error
1261 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1264 | fixed_parameters COMMA ARGLIST COMMA error
1266 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1271 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1275 $$ = new Parameters (new Parameter[0], true);
1282 ArrayList pars = new ArrayList (4);
1287 | fixed_parameters COMMA fixed_parameter
1289 ArrayList pars = (ArrayList) $1;
1298 opt_parameter_modifier
1302 LocatedToken lt = (LocatedToken) $4;
1303 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1306 opt_parameter_modifier
1308 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1310 LocatedToken lt = (LocatedToken) $4;
1311 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1315 opt_parameter_modifier
1318 Report.Error (1001, GetLocation ($3), "Identifier expected");
1322 opt_parameter_modifier
1325 CheckIdentifierToken (yyToken, GetLocation ($4));
1329 opt_parameter_modifier
1335 LocatedToken lt = (LocatedToken) $4;
1336 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1341 opt_parameter_modifier
1342 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1343 | parameter_modifier
1347 : REF { $$ = Parameter.Modifier.REF; }
1348 | OUT { $$ = Parameter.Modifier.OUT; }
1352 : opt_attributes PARAMS type IDENTIFIER
1354 LocatedToken lt = (LocatedToken) $4;
1355 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1356 note ("type must be a single-dimension array type");
1358 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1360 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1363 | opt_attributes PARAMS type error {
1364 CheckIdentifierToken (yyToken, GetLocation ($4));
1369 property_declaration
1373 namespace_or_type_name
1375 if (RootContext.Documentation != null)
1376 tmpComment = Lexer.consume_doc_comment ();
1380 implicit_value_parameter_type = (Expression) $3;
1382 lexer.PropertyParsing = true;
1384 accessor_declarations
1386 lexer.PropertyParsing = false;
1387 has_get = has_set = false;
1395 Pair pair = (Pair) $8;
1396 Accessor get_block = (Accessor) pair.First;
1397 Accessor set_block = (Accessor) pair.Second;
1399 MemberName name = (MemberName) $4;
1401 if (name.TypeArguments != null)
1402 syntax_error (lexer.Location, "a property can't have type arguments");
1404 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1405 name, (Attributes) $1, get_block, set_block);
1407 current_container.AddProperty (prop);
1408 implicit_value_parameter_type = null;
1410 if (RootContext.Documentation != null)
1411 prop.DocComment = ConsumeStoredComment ();
1416 accessor_declarations
1417 : get_accessor_declaration
1419 $$ = new Pair ($1, null);
1421 | get_accessor_declaration accessor_declarations
1423 Pair pair = (Pair) $2;
1427 | set_accessor_declaration
1429 $$ = new Pair (null, $1);
1431 | set_accessor_declaration accessor_declarations
1433 Pair pair = (Pair) $2;
1439 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1444 get_accessor_declaration
1445 : opt_attributes opt_modifiers GET
1447 // If this is not the case, then current_local_parameters has already
1448 // been set in indexer_declaration
1449 if (parsing_indexer == false)
1450 current_local_parameters = null;
1452 current_local_parameters = indexer_parameters;
1453 lexer.PropertyParsing = false;
1455 anonymous_host = SimpleAnonymousHost.GetSimple ();
1460 Report.Error (1007, (Location) $3, "Property accessor already defined");
1463 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1465 current_local_parameters = null;
1466 lexer.PropertyParsing = true;
1468 SimpleAnonymousHost.Simple.Propagate (accessor);
1469 anonymous_host = null;
1471 if (RootContext.Documentation != null)
1472 if (Lexer.doc_state == XmlCommentState.Error)
1473 Lexer.doc_state = XmlCommentState.NotAllowed;
1479 set_accessor_declaration
1480 : opt_attributes opt_modifiers SET
1483 Parameter implicit_value_parameter = new Parameter (
1484 implicit_value_parameter_type, "value",
1485 Parameter.Modifier.NONE, null, (Location) $3);
1487 if (parsing_indexer == false) {
1488 args = new Parameter [1];
1489 args [0] = implicit_value_parameter;
1490 current_local_parameters = new Parameters (args);
1492 Parameter [] fpars = indexer_parameters.FixedParameters;
1495 int count = fpars.Length;
1497 args = new Parameter [count + 1];
1498 fpars.CopyTo (args, 0);
1499 args [count] = implicit_value_parameter;
1502 current_local_parameters = new Parameters (
1506 lexer.PropertyParsing = false;
1508 anonymous_host = SimpleAnonymousHost.GetSimple ();
1513 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1516 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1518 current_local_parameters = null;
1519 lexer.PropertyParsing = true;
1521 SimpleAnonymousHost.Simple.Propagate (accessor);
1522 anonymous_host = null;
1524 if (RootContext.Documentation != null
1525 && Lexer.doc_state == XmlCommentState.Error)
1526 Lexer.doc_state = XmlCommentState.NotAllowed;
1534 | SEMICOLON { $$ = null; }
1537 interface_declaration
1543 lexer.ConstraintsParsing = true;
1547 MemberName name = MakeName ((MemberName) $6);
1549 push_current_class (new Interface (
1550 current_namespace, current_class, name, (int) $2,
1551 (Attributes) $1), true, $3);
1554 opt_type_parameter_constraints_clauses
1556 lexer.ConstraintsParsing = false;
1559 current_container.AddBasesForPart (current_class, (ArrayList) $8);
1561 current_class.SetParameterInfo ((ArrayList) $9);
1563 if (RootContext.Documentation != null) {
1564 current_container.DocComment = Lexer.consume_doc_comment ();
1565 Lexer.doc_state = XmlCommentState.Allowed;
1570 if (RootContext.Documentation != null)
1571 Lexer.doc_state = XmlCommentState.Allowed;
1575 $$ = pop_current_class ();
1577 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1578 CheckIdentifierToken (yyToken, GetLocation ($5));
1584 opt_interface_member_declarations
1588 opt_interface_member_declarations
1590 | interface_member_declarations
1593 interface_member_declarations
1594 : interface_member_declaration
1595 | interface_member_declarations interface_member_declaration
1598 interface_member_declaration
1599 : interface_method_declaration
1604 Method m = (Method) $1;
1606 if (m.IsExplicitImpl)
1607 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1608 m.GetSignatureForError ());
1610 current_container.AddMethod (m);
1612 if (RootContext.Documentation != null)
1613 Lexer.doc_state = XmlCommentState.Allowed;
1615 | interface_property_declaration
1620 Property p = (Property) $1;
1622 if (p.IsExplicitImpl)
1623 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1624 p.GetSignatureForError ());
1626 current_container.AddProperty (p);
1628 if (RootContext.Documentation != null)
1629 Lexer.doc_state = XmlCommentState.Allowed;
1631 | interface_event_declaration
1634 Event e = (Event) $1;
1636 if (e.IsExplicitImpl)
1637 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1638 e.GetSignatureForError ());
1640 current_container.AddEvent (e);
1643 if (RootContext.Documentation != null)
1644 Lexer.doc_state = XmlCommentState.Allowed;
1646 | interface_indexer_declaration
1651 Indexer i = (Indexer) $1;
1653 if (i.IsExplicitImpl)
1654 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1655 i.GetSignatureForError ());
1657 current_container.AddIndexer (i);
1659 if (RootContext.Documentation != null)
1660 Lexer.doc_state = XmlCommentState.Allowed;
1662 | delegate_declaration
1665 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1666 ((MemberCore)$1).GetSignatureForError ());
1672 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1673 ((MemberCore)$1).GetSignatureForError ());
1676 | struct_declaration
1679 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1680 ((MemberCore)$1).GetSignatureForError ());
1686 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1687 ((MemberCore)$1).GetSignatureForError ());
1690 | interface_declaration
1693 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1694 ((MemberCore)$1).GetSignatureForError ());
1697 | constant_declaration
1699 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1707 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1712 interface_method_declaration_body
1715 lexer.ConstraintsParsing = false;
1717 opt_statement_list CLOSE_BRACE
1719 Report.Error (531, lexer.Location,
1720 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1726 interface_method_declaration
1727 : opt_attributes opt_new type namespace_or_type_name
1728 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1730 lexer.ConstraintsParsing = true;
1732 opt_type_parameter_constraints_clauses
1734 // Refer to the name as $-1 in interface_method_declaration_body
1737 interface_method_declaration_body
1739 lexer.ConstraintsParsing = false;
1741 MemberName name = (MemberName) $4;
1743 if ($9 != null && name.TypeArguments == null)
1744 Report.Error (80, lexer.Location,
1745 "Constraints are not allowed on non-generic declarations");
1747 GenericMethod generic = null;
1748 if (name.TypeArguments != null) {
1749 generic = new GenericMethod (current_namespace, current_class, name,
1750 (Expression) $3, (Parameters) $6);
1752 generic.SetParameterInfo ((ArrayList) $9);
1755 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1756 (Parameters) $6, (Attributes) $1);
1757 if (RootContext.Documentation != null)
1758 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1760 | opt_attributes opt_new VOID namespace_or_type_name
1761 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1763 lexer.ConstraintsParsing = true;
1765 opt_type_parameter_constraints_clauses
1769 interface_method_declaration_body
1771 lexer.ConstraintsParsing = false;
1773 MemberName name = (MemberName) $4;
1775 if ($9 != null && name.TypeArguments == null)
1776 Report.Error (80, lexer.Location,
1777 "Constraints are not allowed on non-generic declarations");
1779 GenericMethod generic = null;
1780 if (name.TypeArguments != null) {
1781 generic = new GenericMethod (current_namespace, current_class, name,
1782 TypeManager.system_void_expr, (Parameters) $6);
1784 generic.SetParameterInfo ((ArrayList) $9);
1787 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1788 true, name, (Parameters) $6, (Attributes) $1);
1789 if (RootContext.Documentation != null)
1790 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1794 interface_property_declaration
1799 { lexer.PropertyParsing = true; }
1800 accessor_declarations
1802 has_get = has_set = false;
1803 lexer.PropertyParsing = false;
1807 LocatedToken lt = (LocatedToken) $4;
1808 MemberName name = new MemberName (lt.Value, lt.Location);
1810 if ($3 == TypeManager.system_void_expr) {
1811 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1817 p = new Property (current_class, (Expression) $3, (int) $2, true,
1818 name, (Attributes) $1,
1821 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1825 Pair pair = (Pair) $7;
1826 p = new Property (current_class, (Expression) $3, (int) $2, true,
1827 name, (Attributes) $1,
1828 (Accessor)pair.First, (Accessor)pair.Second);
1830 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1831 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1836 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1837 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1842 if (RootContext.Documentation != null)
1843 p.DocComment = Lexer.consume_doc_comment ();
1850 CheckIdentifierToken (yyToken, GetLocation ($4));
1856 interface_event_declaration
1857 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1859 LocatedToken lt = (LocatedToken) $5;
1860 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1861 new MemberName (lt.Value, lt.Location),
1863 if (RootContext.Documentation != null)
1864 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1866 | opt_attributes opt_new EVENT type error {
1867 CheckIdentifierToken (yyToken, GetLocation ($5));
1870 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1871 LocatedToken lt = (LocatedToken) $5;
1872 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1875 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1877 lexer.EventParsing = true;
1879 event_accessor_declarations
1881 lexer.EventParsing = false;
1884 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
1889 interface_indexer_declaration
1890 : opt_attributes opt_new type THIS
1891 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1893 { lexer.PropertyParsing = true; }
1894 accessor_declarations
1896 has_get = has_set = false;
1897 lexer.PropertyParsing = false;
1903 i = new Indexer (current_class, (Expression) $3,
1904 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1905 (int) $2, true, (Parameters) $6, (Attributes) $1,
1908 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
1912 Pair pair = (Pair) $10;
1913 i = new Indexer (current_class, (Expression) $3,
1914 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1915 (int) $2, true, (Parameters) $6, (Attributes) $1,
1916 (Accessor)pair.First, (Accessor)pair.Second);
1918 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1919 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
1924 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1925 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
1930 if (RootContext.Documentation != null)
1931 i.DocComment = ConsumeStoredComment ();
1937 operator_declaration
1938 : opt_attributes opt_modifiers operator_declarator
1940 anonymous_host = SimpleAnonymousHost.GetSimple ();
1947 OperatorDeclaration decl = (OperatorDeclaration) $3;
1949 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1951 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
1952 if (decl.arg2type != null)
1953 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
1955 Operator op = new Operator (
1956 current_class, decl.optype, decl.ret_type, (int) $2,
1957 new Parameters (param_list),
1958 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1960 if (RootContext.Documentation != null) {
1961 op.DocComment = tmpComment;
1962 Lexer.doc_state = XmlCommentState.Allowed;
1965 SimpleAnonymousHost.Simple.Propagate (op);
1966 anonymous_host = null;
1968 // Note again, checking is done in semantic analysis
1969 current_container.AddOperator (op);
1971 current_local_parameters = null;
1977 | SEMICOLON { $$ = null; }
1980 : type OPERATOR overloadable_operator
1981 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1983 LocatedToken lt = (LocatedToken) $6;
1984 Operator.OpType op = (Operator.OpType) $3;
1985 CheckUnaryOperator (op, lt.Location);
1987 if (op == Operator.OpType.Addition)
1988 op = Operator.OpType.UnaryPlus;
1990 if (op == Operator.OpType.Subtraction)
1991 op = Operator.OpType.UnaryNegation;
1993 Parameter [] pars = new Parameter [1];
1994 Expression type = (Expression) $5;
1996 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
1998 current_local_parameters = new Parameters (pars);
2000 if (RootContext.Documentation != null) {
2001 tmpComment = Lexer.consume_doc_comment ();
2002 Lexer.doc_state = XmlCommentState.NotAllowed;
2005 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2006 null, null, (Location) $2);
2008 | type OPERATOR overloadable_operator
2010 type IDENTIFIER COMMA
2014 LocatedToken ltParam1 = (LocatedToken) $6;
2015 LocatedToken ltParam2 = (LocatedToken) $9;
2016 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2018 Parameter [] pars = new Parameter [2];
2020 Expression typeL = (Expression) $5;
2021 Expression typeR = (Expression) $8;
2023 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
2024 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
2026 current_local_parameters = new Parameters (pars);
2028 if (RootContext.Documentation != null) {
2029 tmpComment = Lexer.consume_doc_comment ();
2030 Lexer.doc_state = XmlCommentState.NotAllowed;
2033 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2034 typeL, ltParam1.Value,
2035 typeR, ltParam2.Value, (Location) $2);
2037 | conversion_operator_declarator
2038 | type OPERATOR overloadable_operator
2040 type IDENTIFIER COMMA
2041 type IDENTIFIER COMMA
2045 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2046 Operator.GetName ((Operator.OpType) $3));
2049 | type OPERATOR overloadable_operator
2050 OPEN_PARENS CLOSE_PARENS
2052 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2053 Operator.GetName ((Operator.OpType) $3));
2058 overloadable_operator
2060 : BANG { $$ = Operator.OpType.LogicalNot; }
2061 | TILDE { $$ = Operator.OpType.OnesComplement; }
2062 | OP_INC { $$ = Operator.OpType.Increment; }
2063 | OP_DEC { $$ = Operator.OpType.Decrement; }
2064 | TRUE { $$ = Operator.OpType.True; }
2065 | FALSE { $$ = Operator.OpType.False; }
2066 // Unary and binary:
2067 | PLUS { $$ = Operator.OpType.Addition; }
2068 | MINUS { $$ = Operator.OpType.Subtraction; }
2070 | STAR { $$ = Operator.OpType.Multiply; }
2071 | DIV { $$ = Operator.OpType.Division; }
2072 | PERCENT { $$ = Operator.OpType.Modulus; }
2073 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2074 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2075 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2076 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2077 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2078 | OP_EQ { $$ = Operator.OpType.Equality; }
2079 | OP_NE { $$ = Operator.OpType.Inequality; }
2080 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2081 | OP_LT { $$ = Operator.OpType.LessThan; }
2082 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2083 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2086 conversion_operator_declarator
2087 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2089 LocatedToken lt = (LocatedToken) $6;
2090 Parameter [] pars = new Parameter [1];
2092 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2094 current_local_parameters = new Parameters (pars);
2096 if (RootContext.Documentation != null) {
2097 tmpComment = Lexer.consume_doc_comment ();
2098 Lexer.doc_state = XmlCommentState.NotAllowed;
2101 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
2102 null, null, (Location) $2);
2104 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2106 LocatedToken lt = (LocatedToken) $6;
2107 Parameter [] pars = new Parameter [1];
2109 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2111 current_local_parameters = new Parameters (pars);
2113 if (RootContext.Documentation != null) {
2114 tmpComment = Lexer.consume_doc_comment ();
2115 Lexer.doc_state = XmlCommentState.NotAllowed;
2118 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
2119 null, null, (Location) $2);
2123 syntax_error ((Location) $1, "'operator' expected");
2127 syntax_error ((Location) $1, "'operator' expected");
2131 constructor_declaration
2134 constructor_declarator
2137 Constructor c = (Constructor) $3;
2138 c.Block = (ToplevelBlock) $4;
2139 c.OptAttributes = (Attributes) $1;
2140 c.ModFlags = (int) $2;
2142 if (RootContext.Documentation != null)
2143 c.DocComment = ConsumeStoredComment ();
2145 if (c.Name == current_container.Basename){
2146 if ((c.ModFlags & Modifiers.STATIC) != 0){
2147 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2148 Report.Error (515, c.Location,
2149 "`{0}': access modifiers are not allowed on static constructors",
2150 c.GetSignatureForError ());
2153 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2155 if (c.Initializer != null){
2156 Report.Error (514, c.Location,
2157 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2158 c.GetSignatureForError ());
2161 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2164 // We let another layer check the validity of the constructor.
2165 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2168 current_container.AddConstructor (c);
2170 current_local_parameters = null;
2171 if (RootContext.Documentation != null)
2172 Lexer.doc_state = XmlCommentState.Allowed;
2176 constructor_declarator
2179 if (RootContext.Documentation != null) {
2180 tmpComment = Lexer.consume_doc_comment ();
2181 Lexer.doc_state = XmlCommentState.Allowed;
2184 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2186 current_local_parameters = (Parameters) $4;
2188 opt_constructor_initializer
2190 LocatedToken lt = (LocatedToken) $1;
2191 $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
2192 (ConstructorInitializer) $7, lt.Location);
2194 anonymous_host = (IAnonymousHost) $$;
2200 | SEMICOLON { $$ = null; }
2203 opt_constructor_initializer
2204 : /* empty */ { $$ = null; }
2205 | constructor_initializer
2208 constructor_initializer
2209 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2211 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2213 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2215 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2218 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2224 : /* EMPTY */ { $$ = 0; }
2225 | UNSAFE { $$ = Modifiers.UNSAFE; }
2226 | EXTERN { $$ = Modifiers.EXTERN; }
2229 destructor_declaration
2230 : opt_attributes opt_finalizer TILDE
2232 if (RootContext.Documentation != null) {
2233 tmpComment = Lexer.consume_doc_comment ();
2234 Lexer.doc_state = XmlCommentState.NotAllowed;
2237 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2239 LocatedToken lt = (LocatedToken) $5;
2240 if (lt.Value != current_container.MemberName.Name){
2241 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2242 } else if (current_container.Kind != Kind.Class){
2243 Report.Error (575, lt.Location, "Only class types can contain destructor");
2245 Location l = lt.Location;
2248 if (!RootContext.StdLib && current_container.Name == "System.Object")
2249 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2251 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2253 Method d = new Destructor (
2254 current_class, TypeManager.system_void_expr, m, "Finalize",
2255 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2256 if (RootContext.Documentation != null)
2257 d.DocComment = ConsumeStoredComment ();
2259 d.Block = (ToplevelBlock) $8;
2260 current_container.AddMethod (d);
2268 EVENT type variable_declarators SEMICOLON
2270 current_array_type = null;
2271 foreach (VariableDeclaration var in (ArrayList) $5) {
2273 MemberName name = new MemberName (var.identifier,
2276 EventField e = new EventField (
2277 current_class, (Expression) $4, (int) $2, false, name,
2280 e.Initializer = var.expression_or_array_initializer;
2282 current_container.AddEvent (e);
2284 if (RootContext.Documentation != null) {
2285 e.DocComment = Lexer.consume_doc_comment ();
2286 Lexer.doc_state = XmlCommentState.Allowed;
2292 EVENT type namespace_or_type_name
2295 implicit_value_parameter_type = (Expression) $4;
2296 lexer.EventParsing = true;
2298 event_accessor_declarations
2300 lexer.EventParsing = false;
2304 MemberName name = (MemberName) $5;
2307 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2308 current_container.Name, name.ToString ());
2311 Pair pair = (Pair) $8;
2313 if (name.TypeArguments != null)
2314 syntax_error (lexer.Location, "an event can't have type arguments");
2316 if (pair.First == null || pair.Second == null)
2317 // CS0073 is already reported, so no CS0065 here.
2320 Event e = new EventProperty (
2321 current_class, (Expression) $4, (int) $2, false, name,
2322 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
2323 if (RootContext.Documentation != null) {
2324 e.DocComment = Lexer.consume_doc_comment ();
2325 Lexer.doc_state = XmlCommentState.Allowed;
2328 current_container.AddEvent (e);
2329 implicit_value_parameter_type = null;
2333 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2334 MemberName mn = (MemberName) $5;
2336 if (mn.Left != null)
2337 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2339 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2341 if (RootContext.Documentation != null)
2342 Lexer.doc_state = XmlCommentState.Allowed;
2346 event_accessor_declarations
2347 : add_accessor_declaration remove_accessor_declaration
2349 $$ = new Pair ($1, $2);
2351 | remove_accessor_declaration add_accessor_declaration
2353 $$ = new Pair ($2, $1);
2355 | add_accessor_declaration { $$ = null; }
2356 | remove_accessor_declaration { $$ = null; }
2359 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2365 add_accessor_declaration
2366 : opt_attributes ADD
2368 Parameter [] args = new Parameter [1];
2369 Parameter implicit_value_parameter = new Parameter (
2370 implicit_value_parameter_type, "value",
2371 Parameter.Modifier.NONE, null, (Location) $2);
2373 args [0] = implicit_value_parameter;
2375 current_local_parameters = new Parameters (args);
2376 lexer.EventParsing = false;
2380 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2381 lexer.EventParsing = true;
2383 | opt_attributes ADD error {
2384 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2387 | opt_attributes modifiers ADD {
2388 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2393 remove_accessor_declaration
2394 : opt_attributes REMOVE
2396 Parameter [] args = new Parameter [1];
2397 Parameter implicit_value_parameter = new Parameter (
2398 implicit_value_parameter_type, "value",
2399 Parameter.Modifier.NONE, null, (Location) $2);
2401 args [0] = implicit_value_parameter;
2403 current_local_parameters = new Parameters (args);
2404 lexer.EventParsing = false;
2408 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2409 lexer.EventParsing = true;
2411 | opt_attributes REMOVE error {
2412 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2415 | opt_attributes modifiers REMOVE {
2416 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2422 : opt_attributes opt_modifiers indexer_declarator
2425 IndexerDeclaration decl = (IndexerDeclaration) $3;
2427 implicit_value_parameter_type = decl.type;
2429 lexer.PropertyParsing = true;
2430 parsing_indexer = true;
2432 indexer_parameters = decl.param_list;
2433 anonymous_host = SimpleAnonymousHost.GetSimple ();
2435 accessor_declarations
2437 lexer.PropertyParsing = false;
2438 has_get = has_set = false;
2439 parsing_indexer = false;
2446 // The signature is computed from the signature of the indexer. Look
2447 // at section 3.6 on the spec
2449 IndexerDeclaration decl = (IndexerDeclaration) $3;
2450 Pair pair = (Pair) $6;
2451 Accessor get_block = (Accessor) pair.First;
2452 Accessor set_block = (Accessor) pair.Second;
2455 if (decl.interface_type != null)
2456 name = new MemberName (
2457 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2459 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2461 indexer = new Indexer (current_class, decl.type, name,
2462 (int) $2, false, decl.param_list, (Attributes) $1,
2463 get_block, set_block);
2465 if (RootContext.Documentation != null)
2466 indexer.DocComment = ConsumeStoredComment ();
2468 current_container.AddIndexer (indexer);
2470 current_local_parameters = null;
2471 implicit_value_parameter_type = null;
2472 indexer_parameters = null;
2477 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2479 Parameters pars = (Parameters) $4;
2480 if (pars.HasArglist) {
2481 // "__arglist is not valid in this context"
2482 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2483 } else if (pars.Empty){
2484 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2486 if (RootContext.Documentation != null) {
2487 tmpComment = Lexer.consume_doc_comment ();
2488 Lexer.doc_state = XmlCommentState.Allowed;
2491 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2493 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2495 Parameters pars = (Parameters) $6;
2497 if (pars.HasArglist) {
2498 // "__arglist is not valid in this context"
2499 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2500 } else if (pars.Empty){
2501 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2504 MemberName name = (MemberName) $2;
2505 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2507 if (RootContext.Documentation != null) {
2508 tmpComment = Lexer.consume_doc_comment ();
2509 Lexer.doc_state = XmlCommentState.Allowed;
2520 if (RootContext.Documentation != null)
2521 enumTypeComment = Lexer.consume_doc_comment ();
2526 LocatedToken lt = (LocatedToken) $5;
2527 Location enum_location = lt.Location;
2530 Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
2531 break; // assumes that the parser put us in a switch
2534 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2535 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2536 name, (Attributes) $1);
2538 if (RootContext.Documentation != null)
2539 e.DocComment = enumTypeComment;
2542 EnumMember em = null;
2543 foreach (VariableDeclaration ev in (ArrayList) $8) {
2544 em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
2545 new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
2547 // if (RootContext.Documentation != null)
2548 em.DocComment = ev.DocComment;
2550 e.AddEnumMember (em);
2553 current_container.AddEnum (e);
2560 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2561 | COLON type { $$ = $2; }
2567 if (RootContext.Documentation != null)
2568 Lexer.doc_state = XmlCommentState.Allowed;
2570 opt_enum_member_declarations
2572 // here will be evaluated after CLOSE_BLACE is consumed.
2573 if (RootContext.Documentation != null)
2574 Lexer.doc_state = XmlCommentState.Allowed;
2582 opt_enum_member_declarations
2583 : /* empty */ { $$ = new ArrayList (4); }
2584 | enum_member_declarations opt_comma { $$ = $1; }
2587 enum_member_declarations
2588 : enum_member_declaration
2590 ArrayList l = new ArrayList (4);
2595 | enum_member_declarations COMMA enum_member_declaration
2597 ArrayList l = (ArrayList) $1;
2605 enum_member_declaration
2606 : opt_attributes IDENTIFIER
2608 VariableDeclaration vd = new VariableDeclaration (
2609 (LocatedToken) $2, null, (Attributes) $1);
2611 if (RootContext.Documentation != null) {
2612 vd.DocComment = Lexer.consume_doc_comment ();
2613 Lexer.doc_state = XmlCommentState.Allowed;
2618 | opt_attributes IDENTIFIER
2620 if (RootContext.Documentation != null) {
2621 tmpComment = Lexer.consume_doc_comment ();
2622 Lexer.doc_state = XmlCommentState.NotAllowed;
2627 VariableDeclaration vd = new VariableDeclaration (
2628 (LocatedToken) $2, $5, (Attributes) $1);
2630 if (RootContext.Documentation != null)
2631 vd.DocComment = ConsumeStoredComment ();
2637 delegate_declaration
2642 lexer.ConstraintsParsing = true;
2645 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2647 MemberName name = MakeName ((MemberName) $6);
2648 Parameters p = (Parameters) $8;
2650 // TODO: wrong location
2651 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2654 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2655 (int) $2, name, p, (Attributes) $1);
2657 if (RootContext.Documentation != null) {
2658 del.DocComment = Lexer.consume_doc_comment ();
2659 Lexer.doc_state = XmlCommentState.Allowed;
2662 current_container.AddDelegate (del);
2663 current_delegate = del;
2665 opt_type_parameter_constraints_clauses
2667 lexer.ConstraintsParsing = false;
2671 current_delegate.SetParameterInfo ((ArrayList) $11);
2672 $$ = current_delegate;
2674 current_delegate = null;
2681 lexer.CheckNullable (false);
2686 lexer.CheckNullable (true);
2691 namespace_or_type_name
2693 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2694 LocatedToken lt1 = (LocatedToken) $1;
2695 LocatedToken lt2 = (LocatedToken) $3;
2696 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2698 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2699 LocatedToken lt = (LocatedToken) $3;
2700 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2705 : IDENTIFIER opt_type_argument_list {
2706 LocatedToken lt = (LocatedToken) $1;
2707 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2711 opt_type_argument_list
2712 : /* empty */ { $$ = null; }
2713 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2716 if (RootContext.Version == LanguageVersion.ISO_1)
2717 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2721 $$ = new TypeArguments ((int) $1, lexer.Location);
2722 if (RootContext.Version == LanguageVersion.ISO_1)
2723 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2728 : opt_attributes type {
2729 TypeArguments type_args = new TypeArguments (lexer.Location);
2731 SimpleName sn = $2 as SimpleName;
2733 Report.Error (1031, lexer.Location, "Type expected");
2735 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2737 type_args.Add ((Expression) $2);
2740 | type_arguments COMMA opt_attributes type {
2741 TypeArguments type_args = (TypeArguments) $1;
2743 SimpleName sn = $4 as SimpleName;
2745 Report.Error (1031, lexer.Location, "Type expected");
2747 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2749 type_args.Add ((Expression) $4);
2756 * Before you think of adding a return_type, notice that we have been
2757 * using two rules in the places where it matters (one rule using type
2758 * and another identical one that uses VOID as the return type). This
2759 * gets rid of a shift/reduce couple
2762 : namespace_or_type_name opt_nullable
2764 MemberName name = (MemberName) $1;
2765 $$ = name.GetTypeExpression ();
2768 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2770 | builtin_types opt_nullable
2773 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2783 // Note that here only unmanaged types are allowed but we
2784 // can't perform checks during this phase - we do it during
2785 // semantic analysis.
2787 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2791 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2796 : builtin_types opt_nullable
2799 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2801 | non_expression_type rank_specifier
2803 Location loc = GetLocation ($1);
2805 loc = lexer.Location;
2806 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2808 | non_expression_type STAR
2810 Location loc = GetLocation ($1);
2812 loc = lexer.Location;
2813 $$ = new ComposedCast ((Expression) $1, "*", loc);
2815 | expression rank_specifiers
2817 $$ = new ComposedCast ((Expression) $1, (string) $2);
2821 $$ = new ComposedCast ((Expression) $1, "*");
2825 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2826 // through this different path
2828 | multiplicative_expression STAR
2830 $$ = new ComposedCast ((Expression) $1, "*");
2837 ArrayList types = new ArrayList (4);
2842 | type_list COMMA type
2844 ArrayList types = (ArrayList) $1;
2852 * replaces all the productions for isolating the various
2853 * simple types, but we need this to reuse it easily in local_variable_type
2856 : OBJECT { $$ = TypeManager.system_object_expr; }
2857 | STRING { $$ = TypeManager.system_string_expr; }
2858 | BOOL { $$ = TypeManager.system_boolean_expr; }
2859 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2860 | FLOAT { $$ = TypeManager.system_single_expr; }
2861 | DOUBLE { $$ = TypeManager.system_double_expr; }
2866 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2867 | BYTE { $$ = TypeManager.system_byte_expr; }
2868 | SHORT { $$ = TypeManager.system_int16_expr; }
2869 | USHORT { $$ = TypeManager.system_uint16_expr; }
2870 | INT { $$ = TypeManager.system_int32_expr; }
2871 | UINT { $$ = TypeManager.system_uint32_expr; }
2872 | LONG { $$ = TypeManager.system_int64_expr; }
2873 | ULONG { $$ = TypeManager.system_uint64_expr; }
2874 | CHAR { $$ = TypeManager.system_char_expr; }
2875 | VOID { $$ = TypeManager.system_void_expr; }
2879 : type rank_specifiers opt_nullable
2881 string rank_specifiers = (string) $2;
2883 rank_specifiers += "?";
2885 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
2890 // Expressions, section 7.5
2899 MemberName mn = (MemberName) $1;
2900 $$ = mn.GetTypeExpression ();
2902 | IDENTIFIER DOUBLE_COLON IDENTIFIER
2904 LocatedToken lt1 = (LocatedToken) $1;
2905 LocatedToken lt2 = (LocatedToken) $3;
2906 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
2908 | parenthesized_expression
2909 | default_value_expression
2911 | invocation_expression
2915 | post_increment_expression
2916 | post_decrement_expression
2920 | checked_expression
2921 | unchecked_expression
2922 | pointer_member_access
2923 | anonymous_method_expression
2930 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2931 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2932 | NULL { $$ = new NullLiteral (lexer.Location); }
2936 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2937 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2938 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2943 object v = lexer.Value;
2946 $$ = new IntLiteral ((int) v, lexer.Location);
2947 } else if (v is uint)
2948 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2950 $$ = new LongLiteral ((Int64) v, lexer.Location);
2951 else if (v is ulong)
2952 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2954 Console.WriteLine ("OOPS. Unexpected result from scanner");
2959 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2960 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2963 parenthesized_expression_0
2964 : OPEN_PARENS expression CLOSE_PARENS
2967 lexer.Deambiguate_CloseParens ();
2968 // After this, the next token returned is one of
2969 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2970 // or CLOSE_PARENS_MINUS.
2972 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
2975 parenthesized_expression
2976 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2980 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2982 // If a parenthesized expression is followed by a minus, we need to wrap
2983 // the expression inside a ParenthesizedExpression for the CS0075 check
2984 // in Binary.DoResolve().
2985 $$ = new ParenthesizedExpression ((Expression) $1);
2990 : primary_expression DOT IDENTIFIER opt_type_argument_list
2992 LocatedToken lt = (LocatedToken) $3;
2993 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
2995 | predefined_type DOT IDENTIFIER opt_type_argument_list
2997 LocatedToken lt = (LocatedToken) $3;
2998 // TODO: Location is wrong as some predefined types doesn't hold a location
2999 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3007 invocation_expression
3008 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3011 Report.Error (1, (Location) $2, "Parse error");
3013 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3015 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3017 $$ = new Invocation ((Expression) $1, new ArrayList ());
3019 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3021 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3023 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3025 ArrayList args = new ArrayList (1);
3027 $$ = new Invocation ((Expression) $1, args);
3029 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3031 ArrayList args = ((ArrayList) $4);
3033 $$ = new Invocation ((Expression) $1, args);
3038 : /* empty */ { $$ = null; }
3045 ArrayList list = new ArrayList (4);
3049 | argument_list COMMA argument
3051 ArrayList list = (ArrayList) $1;
3055 | argument_list error {
3056 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3064 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3066 | non_simple_argument
3073 : REF variable_reference
3075 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3077 | OUT variable_reference
3079 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3081 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3083 ArrayList list = (ArrayList) $3;
3084 Argument[] args = new Argument [list.Count];
3085 list.CopyTo (args, 0);
3087 Expression expr = new Arglist (args, (Location) $1);
3088 $$ = new Argument (expr, Argument.AType.Expression);
3092 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3097 : expression { note ("section 5.4"); $$ = $1; }
3101 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3103 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3105 | primary_expression rank_specifiers
3107 // So the super-trick is that primary_expression
3108 // can only be either a SimpleName or a MemberAccess.
3109 // The MemberAccess case arises when you have a fully qualified type-name like :
3111 // SimpleName is when you have
3114 Expression expr = (Expression) $1;
3115 if (expr is ComposedCast){
3116 $$ = new ComposedCast (expr, (string) $2);
3117 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3118 Error_ExpectingTypeName (expr);
3119 $$ = TypeManager.system_object_expr;
3122 // So we extract the string corresponding to the SimpleName
3125 $$ = new ComposedCast (expr, (string) $2);
3127 current_array_type = (Expression)$$;
3134 ArrayList list = new ArrayList (4);
3138 | expression_list COMMA expression
3140 ArrayList list = (ArrayList) $1;
3149 $$ = new This (current_block, (Location) $1);
3154 : BASE DOT IDENTIFIER opt_type_argument_list
3156 LocatedToken lt = (LocatedToken) $3;
3157 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3159 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3161 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3164 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3169 post_increment_expression
3170 : primary_expression OP_INC
3172 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3173 (Expression) $1, (Location) $2);
3177 post_decrement_expression
3178 : primary_expression OP_DEC
3180 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3181 (Expression) $1, (Location) $2);
3186 : object_or_delegate_creation_expression
3187 | array_creation_expression
3190 object_or_delegate_creation_expression
3191 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3193 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3197 array_creation_expression
3198 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3200 opt_array_initializer
3202 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3204 | NEW type rank_specifiers array_initializer
3206 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3210 Report.Error (1031, (Location) $1, "Type expected");
3215 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3231 opt_rank_specifier_or_nullable
3240 | opt_nullable rank_specifiers
3247 | opt_nullable rank_specifiers INTERR
3250 $$ = "?" + $2 + "?";
3257 : rank_specifier opt_rank_specifier
3259 $$ = (string) $2 + (string) $1;
3264 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3266 $$ = "[" + (string) $2 + "]";
3286 | dim_separators COMMA
3288 $$ = (string) $1 + ",";
3292 opt_array_initializer
3304 : OPEN_BRACE CLOSE_BRACE
3306 ArrayList list = new ArrayList (4);
3309 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3311 $$ = (ArrayList) $2;
3315 variable_initializer_list
3316 : variable_initializer
3318 ArrayList list = new ArrayList (4);
3322 | variable_initializer_list COMMA variable_initializer
3324 ArrayList list = (ArrayList) $1;
3333 pushed_current_array_type = current_array_type;
3334 lexer.TypeOfParsing = true;
3336 OPEN_PARENS type CLOSE_PARENS
3338 lexer.TypeOfParsing = false;
3339 Expression type = (Expression)$4;
3340 if (type == TypeManager.system_void_expr)
3341 $$ = new TypeOfVoid ((Location) $1);
3343 $$ = new TypeOf (type, (Location) $1);
3344 current_array_type = pushed_current_array_type;
3349 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3350 $$ = new SizeOf ((Expression) $3, (Location) $1);
3355 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3357 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3361 unchecked_expression
3362 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3364 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3368 pointer_member_access
3369 : primary_expression OP_PTR IDENTIFIER
3372 LocatedToken lt = (LocatedToken) $3;
3374 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3375 $$ = new MemberAccess (deref, lt.Value);
3379 anonymous_method_expression
3380 : DELEGATE opt_anonymous_method_signature
3382 if (oob_stack == null)
3383 oob_stack = new Stack (6);
3385 oob_stack.Push (current_anonymous_method);
3386 oob_stack.Push (current_local_parameters);
3387 current_local_parameters = (Parameters)$2;
3389 // Force the next block to be created as a ToplevelBlock
3390 oob_stack.Push (current_block);
3391 oob_stack.Push (top_current_block);
3393 Location loc = (Location) $1;
3394 current_anonymous_method = new AnonymousMethodExpression (
3395 current_anonymous_method, current_generic_method, current_container,
3396 (Parameters) $2, (ToplevelBlock) top_current_block, loc);
3398 parsing_anonymous_method = true;
3402 Location loc = (Location) $1;
3403 top_current_block = (Block) oob_stack.Pop ();
3404 current_block = (Block) oob_stack.Pop ();
3406 if (RootContext.Version == LanguageVersion.ISO_1){
3407 Report.FeatureIsNotStandardized (loc, "anonymous methods");
3410 ToplevelBlock anon_block = (ToplevelBlock) $4;
3412 anon_block.Parent = current_block;
3414 current_anonymous_method.Block = anon_block;
3415 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
3416 anonymous_host.AddAnonymousMethod (current_anonymous_method);
3418 $$ = current_anonymous_method;
3421 current_local_parameters = (Parameters) oob_stack.Pop ();
3422 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
3426 opt_anonymous_method_signature
3427 : /* empty */ { $$ = null; }
3428 | anonymous_method_signature
3431 anonymous_method_signature
3432 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
3435 $$ = Parameters.EmptyReadOnlyParameters;
3437 ArrayList par_list = (ArrayList) $2;
3438 Parameter [] pars = new Parameter [par_list.Count];
3439 par_list.CopyTo (pars);
3440 $$ = new Parameters (pars);
3445 opt_anonymous_method_parameter_list
3446 : /* empty */ { $$ = null; }
3447 | anonymous_method_parameter_list { $$ = $1; }
3450 anonymous_method_parameter_list
3451 : anonymous_method_parameter
3453 ArrayList a = new ArrayList (4);
3457 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3459 ArrayList a = (ArrayList) $1;
3465 anonymous_method_parameter
3466 : opt_parameter_modifier type IDENTIFIER {
3467 LocatedToken lt = (LocatedToken) $3;
3468 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3470 | PARAMS type IDENTIFIER {
3471 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3476 default_value_expression
3477 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3479 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3484 : primary_expression
3485 | BANG prefixed_unary_expression
3487 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3489 | TILDE prefixed_unary_expression
3491 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3497 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3499 $$ = new Cast ((Expression) $1, (Expression) $3);
3501 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3503 $$ = new Cast ((Expression) $1, (Expression) $3);
3505 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3507 $$ = new Cast ((Expression) $1, (Expression) $3);
3513 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3515 // TODO: wrong location
3516 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3521 // The idea to split this out is from Rhys' grammar
3522 // to solve the problem with casts.
3524 prefixed_unary_expression
3526 | PLUS prefixed_unary_expression
3528 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3530 | MINUS prefixed_unary_expression
3532 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3534 | OP_INC prefixed_unary_expression
3536 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3537 (Expression) $2, (Location) $1);
3539 | OP_DEC prefixed_unary_expression
3541 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3542 (Expression) $2, (Location) $1);
3544 | STAR prefixed_unary_expression
3546 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3548 | BITWISE_AND prefixed_unary_expression
3550 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3554 pre_increment_expression
3555 : OP_INC prefixed_unary_expression
3557 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3558 (Expression) $2, (Location) $1);
3562 pre_decrement_expression
3563 : OP_DEC prefixed_unary_expression
3565 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3566 (Expression) $2, (Location) $1);
3570 multiplicative_expression
3571 : prefixed_unary_expression
3572 | multiplicative_expression STAR prefixed_unary_expression
3574 $$ = new Binary (Binary.Operator.Multiply,
3575 (Expression) $1, (Expression) $3);
3577 | multiplicative_expression DIV prefixed_unary_expression
3579 $$ = new Binary (Binary.Operator.Division,
3580 (Expression) $1, (Expression) $3);
3582 | multiplicative_expression PERCENT prefixed_unary_expression
3584 $$ = new Binary (Binary.Operator.Modulus,
3585 (Expression) $1, (Expression) $3);
3590 : multiplicative_expression
3591 | additive_expression PLUS multiplicative_expression
3593 $$ = new Binary (Binary.Operator.Addition,
3594 (Expression) $1, (Expression) $3);
3596 | additive_expression MINUS multiplicative_expression
3598 $$ = new Binary (Binary.Operator.Subtraction,
3599 (Expression) $1, (Expression) $3);
3604 : additive_expression
3605 | shift_expression OP_SHIFT_LEFT additive_expression
3607 $$ = new Binary (Binary.Operator.LeftShift,
3608 (Expression) $1, (Expression) $3);
3610 | shift_expression OP_SHIFT_RIGHT additive_expression
3612 $$ = new Binary (Binary.Operator.RightShift,
3613 (Expression) $1, (Expression) $3);
3624 lexer.PutbackNullable ();
3629 nullable_type_or_conditional
3632 if (((bool) $2) && ($1 is ComposedCast))
3633 $$ = ((ComposedCast) $1).RemoveNullable ();
3639 relational_expression
3641 | relational_expression OP_LT shift_expression
3643 $$ = new Binary (Binary.Operator.LessThan,
3644 (Expression) $1, (Expression) $3);
3646 | relational_expression OP_GT shift_expression
3648 $$ = new Binary (Binary.Operator.GreaterThan,
3649 (Expression) $1, (Expression) $3);
3651 | relational_expression OP_LE shift_expression
3653 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3654 (Expression) $1, (Expression) $3);
3656 | relational_expression OP_GE shift_expression
3658 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3659 (Expression) $1, (Expression) $3);
3661 | relational_expression IS
3664 } nullable_type_or_conditional
3666 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3668 | relational_expression AS
3671 } nullable_type_or_conditional
3673 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3678 : relational_expression
3679 | equality_expression OP_EQ relational_expression
3681 $$ = new Binary (Binary.Operator.Equality,
3682 (Expression) $1, (Expression) $3);
3684 | equality_expression OP_NE relational_expression
3686 $$ = new Binary (Binary.Operator.Inequality,
3687 (Expression) $1, (Expression) $3);
3692 : equality_expression
3693 | and_expression BITWISE_AND equality_expression
3695 $$ = new Binary (Binary.Operator.BitwiseAnd,
3696 (Expression) $1, (Expression) $3);
3700 exclusive_or_expression
3702 | exclusive_or_expression CARRET and_expression
3704 $$ = new Binary (Binary.Operator.ExclusiveOr,
3705 (Expression) $1, (Expression) $3);
3709 inclusive_or_expression
3710 : exclusive_or_expression
3711 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3713 $$ = new Binary (Binary.Operator.BitwiseOr,
3714 (Expression) $1, (Expression) $3);
3718 conditional_and_expression
3719 : inclusive_or_expression
3720 | conditional_and_expression OP_AND inclusive_or_expression
3722 $$ = new Binary (Binary.Operator.LogicalAnd,
3723 (Expression) $1, (Expression) $3);
3727 conditional_or_expression
3728 : conditional_and_expression
3729 | conditional_or_expression OP_OR conditional_and_expression
3731 $$ = new Binary (Binary.Operator.LogicalOr,
3732 (Expression) $1, (Expression) $3);
3736 conditional_expression
3737 : conditional_or_expression
3738 | conditional_or_expression INTERR expression COLON expression
3740 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3742 | conditional_or_expression INTERR INTERR expression
3744 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3746 // We'll be resolved into a `parenthesized_expression_0' later on.
3747 | conditional_or_expression INTERR CLOSE_PARENS
3749 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3750 lexer.PutbackCloseParens ();
3754 assignment_expression
3755 : prefixed_unary_expression ASSIGN expression
3757 $$ = new Assign ((Expression) $1, (Expression) $3);
3759 | prefixed_unary_expression OP_MULT_ASSIGN expression
3761 $$ = new CompoundAssign (
3762 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3764 | prefixed_unary_expression OP_DIV_ASSIGN expression
3766 $$ = new CompoundAssign (
3767 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3769 | prefixed_unary_expression OP_MOD_ASSIGN expression
3771 $$ = new CompoundAssign (
3772 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3774 | prefixed_unary_expression OP_ADD_ASSIGN expression
3776 $$ = new CompoundAssign (
3777 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3779 | prefixed_unary_expression OP_SUB_ASSIGN expression
3781 $$ = new CompoundAssign (
3782 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3784 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3786 $$ = new CompoundAssign (
3787 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3789 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3791 $$ = new CompoundAssign (
3792 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3794 | prefixed_unary_expression OP_AND_ASSIGN expression
3796 $$ = new CompoundAssign (
3797 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3799 | prefixed_unary_expression OP_OR_ASSIGN expression
3801 $$ = new CompoundAssign (
3802 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3804 | prefixed_unary_expression OP_XOR_ASSIGN expression
3806 $$ = new CompoundAssign (
3807 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3812 : conditional_expression
3813 | assignment_expression
3833 lexer.ConstraintsParsing = true;
3837 MemberName name = MakeName ((MemberName) $6);
3838 int mod_flags = (int) $2;
3840 push_current_class (new Class (
3841 current_namespace, current_class, name,
3842 mod_flags, (Attributes) $1), false, $3);
3845 opt_type_parameter_constraints_clauses
3847 lexer.ConstraintsParsing = false;
3850 if (current_class.Name == "System.Object") {
3851 Report.Error (537, current_class.Location,
3852 "The class System.Object cannot have a base " +
3853 "class or implement an interface.");
3855 current_container.AddBasesForPart (current_class, (ArrayList) $8);
3858 current_class.SetParameterInfo ((ArrayList) $9);
3860 if (RootContext.Documentation != null) {
3861 current_container.DocComment = Lexer.consume_doc_comment ();
3862 Lexer.doc_state = XmlCommentState.Allowed;
3867 if (RootContext.Documentation != null)
3868 Lexer.doc_state = XmlCommentState.Allowed;
3872 $$ = pop_current_class ();
3880 { $$ = $1; } // location
3884 : /* empty */ { $$ = (int) 0; }
3890 | modifiers modifier
3895 if ((m1 & m2) != 0) {
3896 Location l = lexer.Location;
3897 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
3899 $$ = (int) (m1 | m2);
3904 : NEW { $$ = Modifiers.NEW; }
3905 | PUBLIC { $$ = Modifiers.PUBLIC; }
3906 | PROTECTED { $$ = Modifiers.PROTECTED; }
3907 | INTERNAL { $$ = Modifiers.INTERNAL; }
3908 | PRIVATE { $$ = Modifiers.PRIVATE; }
3909 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3910 | SEALED { $$ = Modifiers.SEALED; }
3911 | STATIC { $$ = Modifiers.STATIC; }
3912 | READONLY { $$ = Modifiers.READONLY; }
3913 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3914 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3915 | EXTERN { $$ = Modifiers.EXTERN; }
3916 | VOLATILE { $$ = Modifiers.VOLATILE; }
3917 | UNSAFE { $$ = Modifiers.UNSAFE; }
3921 : /* empty */ { $$ = null; }
3922 | class_base { $$ = $1; }
3926 : COLON type_list { $$ = $2; }
3929 opt_type_parameter_constraints_clauses
3930 : /* empty */ { $$ = null; }
3931 | type_parameter_constraints_clauses
3935 type_parameter_constraints_clauses
3936 : type_parameter_constraints_clause {
3937 ArrayList constraints = new ArrayList (1);
3938 constraints.Add ($1);
3941 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3942 ArrayList constraints = (ArrayList) $1;
3943 Constraints new_constraint = (Constraints)$2;
3945 foreach (Constraints c in constraints) {
3946 if (new_constraint.TypeParameter == c.TypeParameter) {
3947 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
3948 new_constraint.TypeParameter);
3952 constraints.Add (new_constraint);
3957 type_parameter_constraints_clause
3958 : WHERE IDENTIFIER COLON type_parameter_constraints {
3959 LocatedToken lt = (LocatedToken) $2;
3960 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
3964 type_parameter_constraints
3965 : type_parameter_constraint {
3966 ArrayList constraints = new ArrayList (1);
3967 constraints.Add ($1);
3970 | type_parameter_constraints COMMA type_parameter_constraint {
3971 ArrayList constraints = (ArrayList) $1;
3973 constraints.Add ($3);
3978 type_parameter_constraint
3980 | NEW OPEN_PARENS CLOSE_PARENS {
3981 $$ = SpecialConstraint.Constructor;
3984 $$ = SpecialConstraint.ReferenceType;
3987 $$ = SpecialConstraint.ValueType;
3996 // A block is "contained" on the following places:
3998 // property_declaration as part of the accessor body (get/set)
3999 // operator_declaration
4000 // constructor_declaration
4001 // destructor_declaration
4002 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4007 if (parsing_anonymous_method) {
4008 top_current_block = new ToplevelBlock (
4009 current_block, current_local_parameters, current_generic_method,
4011 if (current_block != null)
4012 current_block.AddAnonymousChild ((ToplevelBlock) top_current_block);
4013 current_block = top_current_block;
4014 parsing_anonymous_method = false;
4015 } else if (current_block == null) {
4016 current_block = new ToplevelBlock (
4017 (ToplevelBlock) top_current_block, current_local_parameters,
4018 current_generic_method, (Location) $1);
4019 top_current_block = current_block;
4021 current_block = new Block (current_block, (Location) $1, Location.Null);
4024 opt_statement_list CLOSE_BRACE
4026 while (current_block.Implicit)
4027 current_block = current_block.Parent;
4029 current_block.SetEndLocation ((Location) $4);
4030 current_block = current_block.Parent;
4031 if (current_block == null)
4032 top_current_block = null;
4043 | statement_list statement
4047 : declaration_statement
4049 if ($1 != null && (Block) $1 != current_block){
4050 current_block.AddStatement ((Statement) $1);
4051 current_block = (Block) $1;
4054 | valid_declaration_statement
4056 current_block.AddStatement ((Statement) $1);
4061 valid_declaration_statement
4064 | expression_statement
4065 | selection_statement
4066 | iteration_statement
4070 | unchecked_statement
4078 : valid_declaration_statement
4079 | declaration_statement
4081 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4086 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4094 $$ = EmptyStatement.Value;
4101 LocatedToken lt = (LocatedToken) $1;
4102 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4104 if (current_block.AddLabel (labeled))
4105 current_block.AddStatement (labeled);
4110 declaration_statement
4111 : local_variable_declaration SEMICOLON
4113 current_array_type = null;
4115 DictionaryEntry de = (DictionaryEntry) $1;
4116 Expression e = (Expression) de.Key;
4118 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4122 | local_constant_declaration SEMICOLON
4124 current_array_type = null;
4126 DictionaryEntry de = (DictionaryEntry) $1;
4128 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4134 * The following is from Rhys' grammar:
4135 * > Types in local variable declarations must be recognized as
4136 * > expressions to prevent reduce/reduce errors in the grammar.
4137 * > The expressions are converted into types during semantic analysis.
4140 : primary_expression opt_rank_specifier_or_nullable
4142 // FIXME: Do something smart here regarding the composition of the type.
4144 // Ok, the above "primary_expression" is there to get rid of
4145 // both reduce/reduce and shift/reduces in the grammar, it should
4146 // really just be "type_name". If you use type_name, a reduce/reduce
4147 // creeps up. If you use namespace_or_type_name (which is all we need
4148 // really) two shift/reduces appear.
4151 // So the super-trick is that primary_expression
4152 // can only be either a SimpleName or a MemberAccess.
4153 // The MemberAccess case arises when you have a fully qualified type-name like :
4155 // SimpleName is when you have
4158 Expression expr = (Expression) $1;
4159 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4160 Error_ExpectingTypeName (expr);
4164 // So we extract the string corresponding to the SimpleName
4168 if ((string) $2 == "")
4171 $$ = new ComposedCast ((Expression) $1, (string) $2);
4174 | builtin_types opt_rank_specifier_or_nullable
4176 if ((string) $2 == "")
4179 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4183 local_variable_pointer_type
4184 : primary_expression STAR
4186 Expression expr = (Expression) $1;
4188 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4189 Error_ExpectingTypeName (expr);
4193 $$ = new ComposedCast ((Expression) $1, "*");
4195 | builtin_types STAR
4197 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4201 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4203 | local_variable_pointer_type STAR
4205 $$ = new ComposedCast ((Expression) $1, "*");
4209 local_variable_declaration
4210 : local_variable_type variable_declarators
4213 $$ = new DictionaryEntry ($1, $2);
4217 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4222 if ((string) $2 == "")
4223 t = (Expression) $1;
4225 t = new ComposedCast ((Expression) $1, (string) $2);
4226 $$ = new DictionaryEntry (t, $3);
4232 local_constant_declaration
4233 : CONST local_variable_type constant_declarators
4236 $$ = new DictionaryEntry ($2, $3);
4242 expression_statement
4243 : statement_expression SEMICOLON { $$ = $1; }
4247 // We have to do the wrapping here and not in the case above,
4248 // because statement_expression is used for example in for_statement
4250 statement_expression
4253 Expression expr = (Expression) $1;
4254 ExpressionStatement s = expr as ExpressionStatement;
4256 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4259 $$ = new StatementExpression (s);
4263 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4268 object_creation_expression
4269 : object_or_delegate_creation_expression
4270 { note ("complain if this is a delegate maybe?"); }
4279 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4282 Location l = (Location) $1;
4284 $$ = new If ((Expression) $3, (Statement) $5, l);
4286 // FIXME: location for warning should be loc property of $5.
4287 if ($5 == EmptyStatement.Value)
4288 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4291 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4292 embedded_statement ELSE embedded_statement
4294 Location l = (Location) $1;
4296 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4298 // FIXME: location for warning should be loc property of $5 and $7.
4299 if ($5 == EmptyStatement.Value)
4300 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4301 if ($7 == EmptyStatement.Value)
4302 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4307 : SWITCH OPEN_PARENS
4309 if (switch_stack == null)
4310 switch_stack = new Stack (2);
4311 switch_stack.Push (current_block);
4313 expression CLOSE_PARENS
4316 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4317 current_block = (Block) switch_stack.Pop ();
4333 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4334 $$ = new ArrayList ();
4342 ArrayList sections = new ArrayList (4);
4347 | switch_sections switch_section
4349 ArrayList sections = (ArrayList) $1;
4359 current_block = current_block.CreateSwitchBlock (lexer.Location);
4363 Block topmost = current_block;
4365 while (topmost.Implicit)
4366 topmost = topmost.Parent;
4367 $$ = new SwitchSection ((ArrayList) $1, topmost);
4374 ArrayList labels = new ArrayList (4);
4379 | switch_labels switch_label
4381 ArrayList labels = (ArrayList) ($1);
4389 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4390 | DEFAULT COLON { $$ = new SwitchLabel (null, (Location) $2); }
4393 1523, GetLocation ($1),
4394 "The keyword case or default must precede code in switch block");
4406 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4408 Location l = (Location) $1;
4409 $$ = new While ((Expression) $3, (Statement) $5, l);
4414 : DO embedded_statement
4415 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4417 Location l = (Location) $1;
4419 $$ = new Do ((Statement) $2, (Expression) $5, l);
4425 opt_for_initializer SEMICOLON
4427 Block assign_block = new Block (current_block);
4428 current_block = assign_block;
4430 if ($3 is DictionaryEntry){
4431 DictionaryEntry de = (DictionaryEntry) $3;
4433 Expression type = (Expression) de.Key;
4434 ArrayList var_declarators = (ArrayList) de.Value;
4436 foreach (VariableDeclaration decl in var_declarators){
4440 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4444 Location l = lexer.Location;
4445 Expression expr = decl.expression_or_array_initializer;
4447 LocalVariableReference var;
4448 var = new LocalVariableReference (assign_block, decl.identifier, l);
4451 Assign a = new Assign (var, expr, decl.Location);
4453 assign_block.AddStatement (new StatementExpression (a));
4457 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4458 // This can be referred to as $5 below.
4464 opt_for_condition SEMICOLON
4465 opt_for_iterator CLOSE_PARENS
4468 Location l = (Location) $1;
4470 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4472 current_block.AddStatement (f);
4473 while (current_block.Implicit)
4474 current_block = current_block.Parent;
4476 current_block = current_block.Parent;
4481 : /* empty */ { $$ = EmptyStatement.Value; }
4486 : local_variable_declaration
4487 | statement_expression_list
4491 : /* empty */ { $$ = null; }
4492 | boolean_expression
4496 : /* empty */ { $$ = EmptyStatement.Value; }
4501 : statement_expression_list
4504 statement_expression_list
4505 : statement_expression
4507 // CHANGE: was `null'
4508 Statement s = (Statement) $1;
4509 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4514 | statement_expression_list COMMA statement_expression
4516 Block b = (Block) $1;
4518 b.AddStatement ((Statement) $3);
4524 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4526 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4529 | FOREACH OPEN_PARENS type IDENTIFIER IN
4530 expression CLOSE_PARENS
4532 Block foreach_block = new Block (current_block);
4533 current_block = foreach_block;
4535 LocatedToken lt = (LocatedToken) $4;
4536 Location l = lt.Location;
4539 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4541 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4543 // Get a writable reference to this read-only variable.
4545 // Note that the $$ here refers to the value of _this_ code block,
4546 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4547 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4554 LocalVariableReference v = (LocalVariableReference) $8;
4555 Location l = (Location) $1;
4558 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4559 current_block.AddStatement (f);
4562 while (current_block.Implicit)
4563 current_block = current_block.Parent;
4565 current_block = current_block.Parent;
4571 | continue_statement
4581 $$ = new Break ((Location) $1);
4586 : CONTINUE SEMICOLON
4588 $$ = new Continue ((Location) $1);
4593 : GOTO IDENTIFIER SEMICOLON
4595 LocatedToken lt = (LocatedToken) $2;
4596 $$ = new Goto (lt.Value, lt.Location);
4598 | GOTO CASE constant_expression SEMICOLON
4600 $$ = new GotoCase ((Expression) $3, (Location) $1);
4602 | GOTO DEFAULT SEMICOLON
4604 $$ = new GotoDefault ((Location) $1);
4609 : RETURN opt_expression SEMICOLON
4611 $$ = new Return ((Expression) $2, (Location) $1);
4616 : THROW opt_expression SEMICOLON
4618 $$ = new Throw ((Expression) $2, (Location) $1);
4623 : IDENTIFIER RETURN expression SEMICOLON
4625 LocatedToken lt = (LocatedToken) $1;
4626 string s = lt.Value;
4628 Report.Error (1003, lt.Location, "; expected");
4631 if (RootContext.Version == LanguageVersion.ISO_1){
4632 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4635 if (anonymous_host == null){
4636 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4639 anonymous_host.SetYields ();
4640 $$ = new Yield ((Expression) $3, lt.Location);
4643 | IDENTIFIER RETURN SEMICOLON
4645 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4648 | IDENTIFIER BREAK SEMICOLON
4650 LocatedToken lt = (LocatedToken) $1;
4651 string s = lt.Value;
4653 Report.Error (1003, lt.Location, "; expected");
4656 if (RootContext.Version == LanguageVersion.ISO_1){
4657 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4660 if (anonymous_host == null){
4661 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4664 anonymous_host.SetYields ();
4665 $$ = new YieldBreak (lt.Location);
4676 : TRY block catch_clauses
4680 ArrayList c = (ArrayList)$3;
4681 for (int i = 0; i < c.Count; ++i) {
4682 Catch cc = (Catch) c [i];
4684 if (i != c.Count - 1)
4685 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4692 // Now s contains the list of specific catch clauses
4693 // and g contains the general one.
4695 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4697 | TRY block opt_catch_clauses FINALLY block
4700 ArrayList s = new ArrayList (4);
4701 ArrayList catch_list = (ArrayList) $3;
4703 if (catch_list != null){
4704 foreach (Catch cc in catch_list) {
4712 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4716 Report.Error (1524, (Location) $1, "Expected catch or finally");
4722 : /* empty */ { $$ = null; }
4729 ArrayList l = new ArrayList (4);
4734 | catch_clauses catch_clause
4736 ArrayList l = (ArrayList) $1;
4744 : /* empty */ { $$ = null; }
4749 : CATCH opt_catch_args
4751 Expression type = null;
4754 DictionaryEntry cc = (DictionaryEntry) $2;
4755 type = (Expression) cc.Key;
4756 LocatedToken lt = (LocatedToken) cc.Value;
4759 ArrayList one = new ArrayList (4);
4761 one.Add (new VariableDeclaration (lt, null));
4763 current_block = new Block (current_block);
4764 Block b = declare_local_variables (type, one, lt.Location);
4769 Expression type = null;
4771 Block var_block = null;
4774 DictionaryEntry cc = (DictionaryEntry) $2;
4775 type = (Expression) cc.Key;
4776 LocatedToken lt = (LocatedToken) cc.Value;
4780 while (current_block.Implicit)
4781 current_block = current_block.Parent;
4782 var_block = current_block;
4783 current_block = current_block.Parent;
4787 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
4792 : /* empty */ { $$ = null; }
4797 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4799 $$ = new DictionaryEntry ($2, $3);
4807 $$ = new Checked ((Block) $2);
4814 $$ = new Unchecked ((Block) $2);
4821 RootContext.CheckUnsafeOption ((Location) $1);
4823 $$ = new Unsafe ((Block) $3);
4829 type fixed_pointer_declarators
4832 ArrayList list = (ArrayList) $4;
4833 Expression type = (Expression) $3;
4834 Location l = (Location) $1;
4835 int top = list.Count;
4837 Block assign_block = new Block (current_block);
4838 current_block = assign_block;
4840 for (int i = 0; i < top; i++){
4841 Pair p = (Pair) list [i];
4844 v = current_block.AddVariable (type, (string) p.First, l);
4848 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4856 Location l = (Location) $1;
4858 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4860 current_block.AddStatement (f);
4861 while (current_block.Implicit)
4862 current_block = current_block.Parent;
4864 current_block = current_block.Parent;
4868 fixed_pointer_declarators
4869 : fixed_pointer_declarator {
4870 ArrayList declarators = new ArrayList (4);
4872 declarators.Add ($1);
4875 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4877 ArrayList declarators = (ArrayList) $1;
4879 declarators.Add ($3);
4884 fixed_pointer_declarator
4885 : IDENTIFIER ASSIGN expression
4887 LocatedToken lt = (LocatedToken) $1;
4888 // FIXME: keep location
4889 $$ = new Pair (lt.Value, $3);
4893 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
4899 : LOCK OPEN_PARENS expression CLOSE_PARENS
4905 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
4910 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4912 Block assign_block = new Block (current_block);
4913 current_block = assign_block;
4915 if ($3 is DictionaryEntry){
4916 DictionaryEntry de = (DictionaryEntry) $3;
4917 Location l = (Location) $1;
4919 Expression type = (Expression) de.Key;
4920 ArrayList var_declarators = (ArrayList) de.Value;
4922 ArrayList vars = new ArrayList (4);
4924 foreach (VariableDeclaration decl in var_declarators){
4926 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4929 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4931 Expression expr = decl.expression_or_array_initializer;
4933 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4936 LocalVariableReference var;
4938 // Get a writable reference to this read-only variable.
4939 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4941 // This is so that it is not a warning on using variables
4944 vars.Add (new DictionaryEntry (var, expr));
4946 // Assign a = new Assign (var, expr, decl.Location);
4947 // assign_block.AddStatement (new StatementExpression (a));
4950 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4951 // It can be referred to as $5 below.
4952 $$ = new DictionaryEntry (type, vars);
4959 Using u = new Using ($5, (Statement) $6, (Location) $1);
4960 current_block.AddStatement (u);
4961 while (current_block.Implicit)
4962 current_block = current_block.Parent;
4964 current_block = current_block.Parent;
4968 resource_acquisition
4969 : local_variable_declaration
4976 // A class used to pass around variable declarations and constants
4978 public class VariableDeclaration {
4979 public string identifier;
4980 public Expression expression_or_array_initializer;
4981 public Location Location;
4982 public Attributes OptAttributes;
4983 public string DocComment;
4985 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
4987 this.identifier = lt.Value;
4988 if (eoai is ArrayList) {
4989 if (CSharpParser.current_array_type == null)
4990 Report.Error (622, lt.Location,
4991 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
4992 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
4994 this.expression_or_array_initializer = (Expression)eoai;
4996 this.Location = lt.Location;
4997 this.OptAttributes = opt_attrs;
5000 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5006 // A class used to hold info about an indexer declarator
5008 public class IndexerDeclaration {
5009 public Expression type;
5010 public MemberName interface_type;
5011 public Parameters param_list;
5012 public Location location;
5014 public IndexerDeclaration (Expression type, MemberName interface_type,
5015 Parameters param_list, Location loc)
5018 this.interface_type = interface_type;
5019 this.param_list = param_list;
5020 this.location = loc;
5025 // We use this when we do not have an object in advance that is an IAnonymousHost
5027 public class SimpleAnonymousHost : IAnonymousHost {
5028 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5031 ArrayList anonymous_methods;
5033 public static SimpleAnonymousHost GetSimple () {
5034 Simple.yields = false;
5035 Simple.anonymous_methods = null;
5039 public void SetYields ()
5044 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5046 if (anonymous_methods == null)
5047 anonymous_methods = new ArrayList ();
5048 anonymous_methods.Add (anonymous);
5051 public void Propagate (IAnonymousHost real_host)
5054 real_host.SetYields ();
5055 if (anonymous_methods != null) {
5056 foreach (AnonymousMethodExpression ame in anonymous_methods)
5057 real_host.AddAnonymousMethod (ame);
5063 // A class used to hold info about an operator declarator
5065 public class OperatorDeclaration {
5066 public Operator.OpType optype;
5067 public Expression ret_type, arg1type, arg2type;
5068 public string arg1name, arg2name;
5069 public Location location;
5071 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5072 Expression arg1type, string arg1name,
5073 Expression arg2type, string arg2name, Location location)
5076 this.ret_type = ret_type;
5077 this.arg1type = arg1type;
5078 this.arg1name = arg1name;
5079 this.arg2type = arg2type;
5080 this.arg2name = arg2name;
5081 this.location = location;
5086 void Error_ExpectingTypeName (Expression expr)
5088 if (expr is Invocation){
5089 Report.Error (1002, expr.Location, "Expecting `;'");
5091 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5095 void push_current_class (TypeContainer tc, bool is_interface, object partial_token)
5097 if (partial_token != null)
5098 current_container = current_container.AddPartial (tc, is_interface);
5100 current_container = current_container.AddTypeContainer (tc, is_interface);
5104 DeclSpace pop_current_class ()
5106 DeclSpace retval = current_class;
5108 current_class = current_class.Parent;
5109 current_container = current_class.PartialContainer;
5115 // Given the @class_name name, it creates a fully qualified name
5116 // based on the containing declaration space
5119 MakeName (MemberName class_name)
5121 Namespace ns = current_namespace.NS;
5123 if (current_container.Name.Length == 0){
5124 if (ns.Name.Length != 0)
5125 return new MemberName (ns.MemberName, class_name);
5129 return new MemberName (current_container.MemberName, class_name);
5133 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5135 Block implicit_block;
5136 ArrayList inits = null;
5139 // We use the `Used' property to check whether statements
5140 // have been added to the current block. If so, we need
5141 // to create another block to contain the new declaration
5142 // otherwise, as an optimization, we use the same block to
5143 // add the declaration.
5145 // FIXME: A further optimization is to check if the statements
5146 // that were added were added as part of the initialization
5147 // below. In which case, no other statements have been executed
5148 // and we might be able to reduce the number of blocks for
5149 // situations like this:
5151 // int j = 1; int k = j + 1;
5153 if (current_block.Used)
5154 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5156 implicit_block = current_block;
5158 foreach (VariableDeclaration decl in variable_declarators){
5160 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5161 if (decl.expression_or_array_initializer != null){
5163 inits = new ArrayList (4);
5170 return implicit_block;
5172 foreach (VariableDeclaration decl in inits){
5174 Expression expr = decl.expression_or_array_initializer;
5176 LocalVariableReference var;
5177 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5179 assign = new Assign (var, expr, decl.Location);
5181 implicit_block.AddStatement (new StatementExpression (assign));
5184 return implicit_block;
5187 Block declare_local_constants (Expression type, ArrayList declarators)
5189 Block implicit_block;
5191 if (current_block.Used)
5192 implicit_block = new Block (current_block, Block.Flags.Implicit);
5194 implicit_block = current_block;
5196 foreach (VariableDeclaration decl in declarators){
5197 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5200 return implicit_block;
5203 void CheckAttributeTarget (string a, Location l)
5207 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5211 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5217 void CheckUnaryOperator (Operator.OpType op, Location l)
5221 case Operator.OpType.LogicalNot:
5222 case Operator.OpType.OnesComplement:
5223 case Operator.OpType.Increment:
5224 case Operator.OpType.Decrement:
5225 case Operator.OpType.True:
5226 case Operator.OpType.False:
5227 case Operator.OpType.Addition:
5228 case Operator.OpType.Subtraction:
5233 Report.Error (1019, l, "Overloadable unary operator expected");
5239 void CheckBinaryOperator (Operator.OpType op, Location l)
5243 case Operator.OpType.Addition:
5244 case Operator.OpType.Subtraction:
5245 case Operator.OpType.Multiply:
5246 case Operator.OpType.Division:
5247 case Operator.OpType.Modulus:
5248 case Operator.OpType.BitwiseAnd:
5249 case Operator.OpType.BitwiseOr:
5250 case Operator.OpType.ExclusiveOr:
5251 case Operator.OpType.LeftShift:
5252 case Operator.OpType.RightShift:
5253 case Operator.OpType.Equality:
5254 case Operator.OpType.Inequality:
5255 case Operator.OpType.GreaterThan:
5256 case Operator.OpType.LessThan:
5257 case Operator.OpType.GreaterThanOrEqual:
5258 case Operator.OpType.LessThanOrEqual:
5262 Report.Error (1020, l, "Overloadable binary operator expected");
5268 void syntax_error (Location l, string msg)
5270 Report.Error (1003, l, "Syntax error, " + msg);
5273 void note (string s)
5275 // Used to put annotations
5280 public Tokenizer Lexer {
5286 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5288 this.name = file.Name;
5290 current_namespace = new NamespaceEntry (null, file, null);
5291 current_class = current_namespace.SlaveDeclSpace;
5292 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5294 lexer = new Tokenizer (reader, file, defines);
5297 public void parse ()
5299 int errors = Report.Errors;
5301 if (yacc_verbose_flag > 1)
5302 yyparse (lexer, new yydebug.yyDebugSimple ());
5305 Tokenizer tokenizer = lexer as Tokenizer;
5306 tokenizer.cleanup ();
5307 } catch (Exception e){
5309 // Removed for production use, use parser verbose to get the output.
5311 // Console.WriteLine (e);
5312 if (Report.Errors == errors)
5313 Report.Error (-25, lexer.Location, "Parsing error");
5314 if (yacc_verbose_flag > 0)
5315 Console.WriteLine (e);
5318 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5319 throw new InternalErrorException ("who set it?");
5322 static void CheckToken (int error, int yyToken, string msg, Location loc)
5324 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5325 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5327 Report.Error (error, loc, msg);
5330 void CheckIdentifierToken (int yyToken, Location loc)
5332 CheckToken (1041, yyToken, "Identifier expected", loc);
5335 string ConsumeStoredComment ()
5337 string s = tmpComment;
5339 Lexer.doc_state = XmlCommentState.Allowed;
5343 Location GetLocation (object obj)
5345 if (obj is MemberCore)
5346 return ((MemberCore) obj).Location;
5347 if (obj is MemberName)
5348 return ((MemberName) obj).Location;
5349 if (obj is LocatedToken)
5350 return ((LocatedToken) obj).Location;
5351 if (obj is Location)
5352 return (Location) obj;
5353 return lexer.Location;