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
284 /* Add precedence rules to solve dangling else s/r conflict */
293 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
295 %left STAR DIV PERCENT
296 %right BANG CARRET UMINUS
297 %nonassoc OP_INC OP_DEC
299 %left OPEN_BRACKET OPEN_BRACE
303 %start compilation_unit
307 : outer_declarations opt_EOF
308 | outer_declarations global_attributes opt_EOF
309 | global_attributes opt_EOF
310 | opt_EOF /* allow empty files */
316 Lexer.check_incorrect_doc_comment ();
320 Lexer.check_incorrect_doc_comment ();
326 | outer_declarations outer_declaration
330 : extern_alias_directive
332 | namespace_member_declaration
335 extern_alias_directives
336 : extern_alias_directive
337 | extern_alias_directives extern_alias_directive;
339 extern_alias_directive
340 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
342 LocatedToken lt = (LocatedToken) $2;
345 Report.Error (1003, lt.Location, "'alias' expected");
346 } else if (RootContext.Version == LanguageVersion.ISO_1) {
347 Report.FeatureIsNotStandardized (lt.Location, "external alias");
349 lt = (LocatedToken) $3;
350 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
357 | using_directives using_directive
361 : using_alias_directive
363 if (RootContext.Documentation != null)
364 Lexer.doc_state = XmlCommentState.Allowed;
366 | using_namespace_directive
368 if (RootContext.Documentation != null)
369 Lexer.doc_state = XmlCommentState.Allowed;
373 using_alias_directive
374 : USING IDENTIFIER ASSIGN
375 namespace_or_type_name SEMICOLON
377 LocatedToken lt = (LocatedToken) $2;
378 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
381 CheckIdentifierToken (yyToken, GetLocation ($2));
385 using_namespace_directive
386 : USING namespace_name SEMICOLON
388 current_namespace.Using ((MemberName) $2, (Location) $1);
393 // Strictly speaking, namespaces don't have attributes but
394 // we parse global attributes along with namespace declarations and then
397 namespace_declaration
398 : opt_attributes NAMESPACE namespace_or_type_name
400 MemberName name = (MemberName) $3;
403 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
406 if (name.TypeArguments != null)
407 syntax_error (lexer.Location, "namespace name expected");
409 current_namespace = new NamespaceEntry (
410 current_namespace, file, name.GetName ());
411 current_class = current_namespace.SlaveDeclSpace;
412 current_container = current_class.PartialContainer;
414 namespace_body opt_semicolon
416 current_namespace = current_namespace.Parent;
417 current_class = current_namespace.SlaveDeclSpace;
418 current_container = current_class.PartialContainer;
433 : namespace_or_type_name {
434 MemberName name = (MemberName) $1;
436 if (name.TypeArguments != null)
437 syntax_error (lexer.Location, "namespace name expected");
446 if (RootContext.Documentation != null)
447 Lexer.doc_state = XmlCommentState.Allowed;
449 opt_extern_alias_directives
451 opt_namespace_member_declarations
460 opt_extern_alias_directives
462 | extern_alias_directives
465 opt_namespace_member_declarations
467 | namespace_member_declarations
470 namespace_member_declarations
471 : namespace_member_declaration
472 | namespace_member_declarations namespace_member_declaration
475 namespace_member_declaration
479 DeclSpace ds = (DeclSpace)$1;
481 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
482 Report.Error (1527, ds.Location,
483 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
486 current_namespace.DeclarationFound = true;
488 | namespace_declaration {
489 current_namespace.DeclarationFound = true;
492 | field_declaration {
493 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
495 | method_declaration {
496 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
503 | interface_declaration
505 | delegate_declaration
507 // Enable this when we have handled all errors, because this acts as a generic fallback
510 // Console.WriteLine ("Token=" + yyToken);
511 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
523 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
531 global_attrs_enabled = false;
536 global_attrs_enabled = false;
545 ArrayList sect = (ArrayList) $1;
547 if (global_attrs_enabled) {
548 if (current_attr_target == "module") {
549 CodeGen.Module.AddAttributes (sect);
551 } else if (current_attr_target != null && current_attr_target.Length > 0) {
552 CodeGen.Assembly.AddAttributes (sect);
555 $$ = new Attributes (sect);
558 if (RootContext.Documentation != null) {
559 Lexer.check_incorrect_doc_comment ();
561 XmlCommentState.Allowed;
565 $$ = new Attributes (sect);
567 current_attr_target = null;
569 | attribute_sections attribute_section
571 Attributes attrs = $1 as Attributes;
572 ArrayList sect = (ArrayList) $2;
574 if (global_attrs_enabled) {
575 if (current_attr_target == "module") {
576 CodeGen.Module.AddAttributes (sect);
578 } else if (current_attr_target == "assembly") {
579 CodeGen.Assembly.AddAttributes (sect);
583 attrs = new Attributes (sect);
585 attrs.AddAttributes (sect);
589 attrs = new Attributes (sect);
591 attrs.AddAttributes (sect);
594 current_attr_target = null;
599 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
603 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
609 attribute_target_specifier
610 : attribute_target COLON
612 current_attr_target = (string)$1;
620 LocatedToken lt = (LocatedToken) $1;
621 CheckAttributeTarget (lt.Value, lt.Location);
622 $$ = lt.Value; // Location won't be required anymore.
624 | EVENT { $$ = "event"; }
625 | RETURN { $$ = "return"; }
631 ArrayList attrs = new ArrayList (4);
637 | attribute_list COMMA attribute
639 ArrayList attrs = (ArrayList) $1;
647 : attribute_name opt_attribute_arguments
649 MemberName mname = (MemberName) $1;
650 if (mname.IsGeneric) {
651 Report.Error (404, lexer.Location,
652 "'<' unexpected: attributes cannot be generic");
655 object [] arguments = (object []) $2;
656 MemberName left = mname.Left;
657 string identifier = mname.Name;
659 Expression left_expr = left == null ? null : left.GetTypeExpression ();
661 if (current_attr_target == "assembly" || current_attr_target == "module")
662 // FIXME: supply "nameEscaped" parameter here.
663 $$ = new GlobalAttribute (current_namespace, current_attr_target,
664 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
666 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
671 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
674 opt_attribute_arguments
675 : /* empty */ { $$ = null; }
676 | OPEN_PARENS attribute_arguments CLOSE_PARENS
684 : opt_positional_argument_list
689 $$ = new object [] { $1, null };
692 | positional_argument_list COMMA named_argument_list
694 $$ = new object[] { $1, $3 };
696 | named_argument_list
698 $$ = new object [] { null, $1 };
703 opt_positional_argument_list
704 : /* empty */ { $$ = null; }
705 | positional_argument_list
708 positional_argument_list
711 ArrayList args = new ArrayList (4);
712 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
716 | positional_argument_list COMMA expression
718 ArrayList args = (ArrayList) $1;
719 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
728 ArrayList args = new ArrayList (4);
733 | named_argument_list COMMA named_argument
735 ArrayList args = (ArrayList) $1;
740 | named_argument_list COMMA expression
742 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
748 : IDENTIFIER ASSIGN expression
750 // FIXME: keep location
751 $$ = new DictionaryEntry (
752 ((LocatedToken) $1).Value,
753 new Argument ((Expression) $3, Argument.AType.Expression));
759 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
762 opt_class_member_declarations
764 | class_member_declarations
767 class_member_declarations
768 : class_member_declaration
769 | class_member_declarations
770 class_member_declaration
773 class_member_declaration
774 : constant_declaration // done
775 | field_declaration // done
776 | method_declaration // done
777 | property_declaration // done
778 | event_declaration // done
779 | indexer_declaration // done
780 | operator_declaration // done
781 | constructor_declaration // done
782 | destructor_declaration // done
792 lexer.ConstraintsParsing = true;
796 MemberName name = MakeName ((MemberName) $6);
797 push_current_class (new Struct (
798 current_namespace, current_class, name, (int) $2,
799 (Attributes) $1), false, $3);
802 opt_type_parameter_constraints_clauses
804 lexer.ConstraintsParsing = false;
807 current_container.AddBasesForPart (current_class, (ArrayList) $8);
809 current_class.SetParameterInfo ((ArrayList) $9);
811 if (RootContext.Documentation != null)
812 current_container.DocComment = Lexer.consume_doc_comment ();
816 if (RootContext.Documentation != null)
817 Lexer.doc_state = XmlCommentState.Allowed;
821 $$ = pop_current_class ();
823 | opt_attributes opt_modifiers opt_partial STRUCT error {
824 CheckIdentifierToken (yyToken, GetLocation ($5));
831 if (RootContext.Documentation != null)
832 Lexer.doc_state = XmlCommentState.Allowed;
834 opt_struct_member_declarations CLOSE_BRACE
837 opt_struct_member_declarations
839 | struct_member_declarations
842 struct_member_declarations
843 : struct_member_declaration
844 | struct_member_declarations struct_member_declaration
847 struct_member_declaration
848 : constant_declaration
851 | property_declaration
853 | indexer_declaration
854 | operator_declaration
855 | constructor_declaration
859 * This is only included so we can flag error 575:
860 * destructors only allowed on class types
862 | destructor_declaration
873 int modflags = (int) $2;
874 foreach (VariableDeclaration constant in (ArrayList) $5){
875 Location l = constant.Location;
876 if ((modflags & Modifiers.STATIC) != 0) {
877 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
881 Const c = new Const (
882 current_class, (Expression) $4, (string) constant.identifier,
883 (Expression) constant.expression_or_array_initializer, modflags,
886 if (RootContext.Documentation != null) {
887 c.DocComment = Lexer.consume_doc_comment ();
888 Lexer.doc_state = XmlCommentState.Allowed;
890 current_container.AddConstant (c);
896 : constant_declarator
898 ArrayList constants = new ArrayList (4);
903 | constant_declarators COMMA constant_declarator
906 ArrayList constants = (ArrayList) $1;
913 : IDENTIFIER ASSIGN constant_expression
915 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
919 // A const field requires a value to be provided
920 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
932 Expression type = (Expression) $3;
935 current_array_type = null;
937 foreach (VariableDeclaration var in (ArrayList) $4){
938 Field field = new Field (current_class, type, mod, var.identifier,
939 (Attributes) $1, var.Location);
941 field.Initializer = var.expression_or_array_initializer;
943 if (RootContext.Documentation != null) {
944 field.DocComment = Lexer.consume_doc_comment ();
945 Lexer.doc_state = XmlCommentState.Allowed;
947 current_container.AddField (field);
948 $$ = field; // FIXME: might be better if it points to the top item
955 fixed_variable_declarators
958 Expression type = (Expression) $4;
961 current_array_type = null;
963 foreach (VariableDeclaration var in (ArrayList) $5) {
964 FixedField field = new FixedField (current_class, type, mod, var.identifier,
965 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
967 if (RootContext.Documentation != null) {
968 field.DocComment = Lexer.consume_doc_comment ();
969 Lexer.doc_state = XmlCommentState.Allowed;
971 current_container.AddField (field);
972 $$ = field; // FIXME: might be better if it points to the top item
980 current_array_type = null;
981 Report.Error (670, (Location) $3, "Fields cannot have void type");
985 fixed_variable_declarators
986 : fixed_variable_declarator
988 ArrayList decl = new ArrayList (2);
992 | fixed_variable_declarators COMMA fixed_variable_declarator
994 ArrayList decls = (ArrayList) $1;
1000 fixed_variable_declarator
1001 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1003 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1005 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1007 Report.Error (443, lexer.Location, "Value or constant expected");
1008 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1012 variable_declarators
1013 : variable_declarator
1015 ArrayList decl = new ArrayList (4);
1020 | variable_declarators COMMA variable_declarator
1022 ArrayList decls = (ArrayList) $1;
1029 : IDENTIFIER ASSIGN variable_initializer
1031 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1035 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1037 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1039 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1040 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1045 variable_initializer
1054 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1056 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1060 $$ = new ArglistAccess ((Location) $1);
1064 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1071 anonymous_host = (IAnonymousHost) $1;
1072 if (RootContext.Documentation != null)
1073 Lexer.doc_state = XmlCommentState.NotAllowed;
1077 Method method = (Method) $1;
1078 method.Block = (ToplevelBlock) $3;
1079 current_container.AddMethod (method);
1081 anonymous_host = null;
1082 current_generic_method = null;
1083 current_local_parameters = null;
1085 if (RootContext.Documentation != null)
1086 Lexer.doc_state = XmlCommentState.Allowed;
1099 Report.Error (1585, lexer.Location,
1100 "Member modifier `{0}' must precede the member type and name",
1101 Modifiers.Name (i));
1112 type namespace_or_type_name
1113 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1115 lexer.ConstraintsParsing = true;
1117 opt_type_parameter_constraints_clauses
1119 lexer.ConstraintsParsing = false;
1121 MemberName name = (MemberName) $4;
1123 if ($9 != null && name.TypeArguments == null)
1124 Report.Error (80, lexer.Location,
1125 "Constraints are not allowed on non-generic declarations");
1129 GenericMethod generic = null;
1130 if (name.TypeArguments != null) {
1131 generic = new GenericMethod (current_namespace, current_class, name,
1132 (Expression) $3, (Parameters) $6);
1134 generic.SetParameterInfo ((ArrayList) $9);
1137 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1138 name, (Parameters) $6, (Attributes) $1);
1140 anonymous_host = method;
1141 current_local_parameters = (Parameters) $6;
1142 current_generic_method = generic;
1144 if (RootContext.Documentation != null)
1145 method.DocComment = Lexer.consume_doc_comment ();
1151 VOID namespace_or_type_name
1152 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1154 lexer.ConstraintsParsing = true;
1156 opt_type_parameter_constraints_clauses
1158 lexer.ConstraintsParsing = false;
1160 MemberName name = (MemberName) $4;
1162 if ($9 != null && name.TypeArguments == null)
1163 Report.Error (80, lexer.Location,
1164 "Constraints are not allowed on non-generic declarations");
1167 GenericMethod generic = null;
1168 if (name.TypeArguments != null) {
1169 generic = new GenericMethod (current_namespace, current_class, name,
1170 TypeManager.system_void_expr, (Parameters) $6);
1172 generic.SetParameterInfo ((ArrayList) $9);
1175 method = new Method (current_class, generic, TypeManager.system_void_expr,
1176 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1178 anonymous_host = method;
1179 current_local_parameters = (Parameters) $6;
1180 current_generic_method = generic;
1182 if (RootContext.Documentation != null)
1183 method.DocComment = Lexer.consume_doc_comment ();
1190 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1192 MemberName name = (MemberName) $5;
1193 Report.Error (1585, name.Location,
1194 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1196 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1197 0, false, name, (Parameters) $6, (Attributes) $1);
1199 current_local_parameters = (Parameters) $6;
1201 if (RootContext.Documentation != null)
1202 method.DocComment = Lexer.consume_doc_comment ();
1210 | SEMICOLON { $$ = null; }
1213 opt_formal_parameter_list
1214 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1215 | formal_parameter_list
1218 formal_parameter_list
1221 ArrayList pars_list = (ArrayList) $1;
1223 Parameter [] pars = new Parameter [pars_list.Count];
1224 pars_list.CopyTo (pars);
1226 $$ = new Parameters (pars);
1228 | fixed_parameters COMMA parameter_array
1230 ArrayList pars_list = (ArrayList) $1;
1233 Parameter [] pars = new Parameter [pars_list.Count];
1234 pars_list.CopyTo (pars);
1236 $$ = new Parameters (pars);
1238 | fixed_parameters COMMA ARGLIST
1240 ArrayList pars_list = (ArrayList) $1;
1241 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1243 Parameter [] pars = new Parameter [pars_list.Count];
1244 pars_list.CopyTo (pars);
1246 $$ = new Parameters (pars, true);
1248 | parameter_array COMMA error
1251 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1254 | fixed_parameters COMMA parameter_array COMMA error
1257 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1260 | ARGLIST COMMA error
1262 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1265 | fixed_parameters COMMA ARGLIST COMMA error
1267 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1272 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1276 $$ = new Parameters (new Parameter[0], true);
1283 ArrayList pars = new ArrayList (4);
1288 | fixed_parameters COMMA fixed_parameter
1290 ArrayList pars = (ArrayList) $1;
1299 opt_parameter_modifier
1303 LocatedToken lt = (LocatedToken) $4;
1304 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1307 opt_parameter_modifier
1309 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1311 LocatedToken lt = (LocatedToken) $4;
1312 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1316 opt_parameter_modifier
1319 Report.Error (1001, GetLocation ($3), "Identifier expected");
1323 opt_parameter_modifier
1326 CheckIdentifierToken (yyToken, GetLocation ($4));
1330 opt_parameter_modifier
1336 LocatedToken lt = (LocatedToken) $4;
1337 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1342 opt_parameter_modifier
1343 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1344 | parameter_modifier
1348 : REF { $$ = Parameter.Modifier.REF; }
1349 | OUT { $$ = Parameter.Modifier.OUT; }
1353 : opt_attributes PARAMS type IDENTIFIER
1355 LocatedToken lt = (LocatedToken) $4;
1356 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1357 note ("type must be a single-dimension array type");
1359 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1361 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1364 | opt_attributes PARAMS type error {
1365 CheckIdentifierToken (yyToken, GetLocation ($4));
1370 property_declaration
1374 namespace_or_type_name
1376 if (RootContext.Documentation != null)
1377 tmpComment = Lexer.consume_doc_comment ();
1381 implicit_value_parameter_type = (Expression) $3;
1383 lexer.PropertyParsing = true;
1385 accessor_declarations
1387 lexer.PropertyParsing = false;
1388 has_get = has_set = false;
1396 Pair pair = (Pair) $8;
1397 Accessor get_block = (Accessor) pair.First;
1398 Accessor set_block = (Accessor) pair.Second;
1400 MemberName name = (MemberName) $4;
1402 if (name.TypeArguments != null)
1403 syntax_error (lexer.Location, "a property can't have type arguments");
1405 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1406 name, (Attributes) $1, get_block, set_block);
1408 current_container.AddProperty (prop);
1409 implicit_value_parameter_type = null;
1411 if (RootContext.Documentation != null)
1412 prop.DocComment = ConsumeStoredComment ();
1417 accessor_declarations
1418 : get_accessor_declaration
1420 $$ = new Pair ($1, null);
1422 | get_accessor_declaration accessor_declarations
1424 Pair pair = (Pair) $2;
1428 | set_accessor_declaration
1430 $$ = new Pair (null, $1);
1432 | set_accessor_declaration accessor_declarations
1434 Pair pair = (Pair) $2;
1440 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1445 get_accessor_declaration
1446 : opt_attributes opt_modifiers GET
1448 // If this is not the case, then current_local_parameters has already
1449 // been set in indexer_declaration
1450 if (parsing_indexer == false)
1451 current_local_parameters = null;
1453 current_local_parameters = indexer_parameters;
1454 lexer.PropertyParsing = false;
1456 anonymous_host = SimpleAnonymousHost.GetSimple ();
1461 Report.Error (1007, (Location) $3, "Property accessor already defined");
1464 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1466 current_local_parameters = null;
1467 lexer.PropertyParsing = true;
1469 SimpleAnonymousHost.Simple.Propagate (accessor);
1470 anonymous_host = null;
1472 if (RootContext.Documentation != null)
1473 if (Lexer.doc_state == XmlCommentState.Error)
1474 Lexer.doc_state = XmlCommentState.NotAllowed;
1480 set_accessor_declaration
1481 : opt_attributes opt_modifiers SET
1484 Parameter implicit_value_parameter = new Parameter (
1485 implicit_value_parameter_type, "value",
1486 Parameter.Modifier.NONE, null, (Location) $3);
1488 if (parsing_indexer == false) {
1489 args = new Parameter [1];
1490 args [0] = implicit_value_parameter;
1491 current_local_parameters = new Parameters (args);
1493 Parameter [] fpars = indexer_parameters.FixedParameters;
1496 int count = fpars.Length;
1498 args = new Parameter [count + 1];
1499 fpars.CopyTo (args, 0);
1500 args [count] = implicit_value_parameter;
1503 current_local_parameters = new Parameters (
1507 lexer.PropertyParsing = false;
1509 anonymous_host = SimpleAnonymousHost.GetSimple ();
1514 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1517 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1519 current_local_parameters = null;
1520 lexer.PropertyParsing = true;
1522 SimpleAnonymousHost.Simple.Propagate (accessor);
1523 anonymous_host = null;
1525 if (RootContext.Documentation != null
1526 && Lexer.doc_state == XmlCommentState.Error)
1527 Lexer.doc_state = XmlCommentState.NotAllowed;
1535 | SEMICOLON { $$ = null; }
1538 interface_declaration
1544 lexer.ConstraintsParsing = true;
1548 MemberName name = MakeName ((MemberName) $6);
1550 push_current_class (new Interface (
1551 current_namespace, current_class, name, (int) $2,
1552 (Attributes) $1), true, $3);
1555 opt_type_parameter_constraints_clauses
1557 lexer.ConstraintsParsing = false;
1560 current_container.AddBasesForPart (current_class, (ArrayList) $8);
1562 current_class.SetParameterInfo ((ArrayList) $9);
1564 if (RootContext.Documentation != null) {
1565 current_container.DocComment = Lexer.consume_doc_comment ();
1566 Lexer.doc_state = XmlCommentState.Allowed;
1571 if (RootContext.Documentation != null)
1572 Lexer.doc_state = XmlCommentState.Allowed;
1576 $$ = pop_current_class ();
1578 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1579 CheckIdentifierToken (yyToken, GetLocation ($5));
1585 opt_interface_member_declarations
1589 opt_interface_member_declarations
1591 | interface_member_declarations
1594 interface_member_declarations
1595 : interface_member_declaration
1596 | interface_member_declarations interface_member_declaration
1599 interface_member_declaration
1600 : interface_method_declaration
1605 Method m = (Method) $1;
1607 if (m.IsExplicitImpl)
1608 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1609 m.GetSignatureForError ());
1611 current_container.AddMethod (m);
1613 if (RootContext.Documentation != null)
1614 Lexer.doc_state = XmlCommentState.Allowed;
1616 | interface_property_declaration
1621 Property p = (Property) $1;
1623 if (p.IsExplicitImpl)
1624 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1625 p.GetSignatureForError ());
1627 current_container.AddProperty (p);
1629 if (RootContext.Documentation != null)
1630 Lexer.doc_state = XmlCommentState.Allowed;
1632 | interface_event_declaration
1635 Event e = (Event) $1;
1637 if (e.IsExplicitImpl)
1638 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1639 e.GetSignatureForError ());
1641 current_container.AddEvent (e);
1644 if (RootContext.Documentation != null)
1645 Lexer.doc_state = XmlCommentState.Allowed;
1647 | interface_indexer_declaration
1652 Indexer i = (Indexer) $1;
1654 if (i.IsExplicitImpl)
1655 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1656 i.GetSignatureForError ());
1658 current_container.AddIndexer (i);
1660 if (RootContext.Documentation != null)
1661 Lexer.doc_state = XmlCommentState.Allowed;
1663 | delegate_declaration
1666 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1667 ((MemberCore)$1).GetSignatureForError ());
1673 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1674 ((MemberCore)$1).GetSignatureForError ());
1677 | struct_declaration
1680 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1681 ((MemberCore)$1).GetSignatureForError ());
1687 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1688 ((MemberCore)$1).GetSignatureForError ());
1691 | interface_declaration
1694 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1695 ((MemberCore)$1).GetSignatureForError ());
1698 | constant_declaration
1700 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1708 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1713 interface_method_declaration_body
1716 lexer.ConstraintsParsing = false;
1718 opt_statement_list CLOSE_BRACE
1720 Report.Error (531, lexer.Location,
1721 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1727 interface_method_declaration
1728 : opt_attributes opt_new type namespace_or_type_name
1729 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1731 lexer.ConstraintsParsing = true;
1733 opt_type_parameter_constraints_clauses
1735 // Refer to the name as $-1 in interface_method_declaration_body
1738 interface_method_declaration_body
1740 lexer.ConstraintsParsing = false;
1742 MemberName name = (MemberName) $4;
1744 if ($9 != null && name.TypeArguments == null)
1745 Report.Error (80, lexer.Location,
1746 "Constraints are not allowed on non-generic declarations");
1748 GenericMethod generic = null;
1749 if (name.TypeArguments != null) {
1750 generic = new GenericMethod (current_namespace, current_class, name,
1751 (Expression) $3, (Parameters) $6);
1753 generic.SetParameterInfo ((ArrayList) $9);
1756 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1757 (Parameters) $6, (Attributes) $1);
1758 if (RootContext.Documentation != null)
1759 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1761 | opt_attributes opt_new VOID namespace_or_type_name
1762 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1764 lexer.ConstraintsParsing = true;
1766 opt_type_parameter_constraints_clauses
1770 interface_method_declaration_body
1772 lexer.ConstraintsParsing = false;
1774 MemberName name = (MemberName) $4;
1776 if ($9 != null && name.TypeArguments == null)
1777 Report.Error (80, lexer.Location,
1778 "Constraints are not allowed on non-generic declarations");
1780 GenericMethod generic = null;
1781 if (name.TypeArguments != null) {
1782 generic = new GenericMethod (current_namespace, current_class, name,
1783 TypeManager.system_void_expr, (Parameters) $6);
1785 generic.SetParameterInfo ((ArrayList) $9);
1788 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1789 true, name, (Parameters) $6, (Attributes) $1);
1790 if (RootContext.Documentation != null)
1791 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1795 interface_property_declaration
1800 { lexer.PropertyParsing = true; }
1801 accessor_declarations
1803 has_get = has_set = false;
1804 lexer.PropertyParsing = false;
1808 LocatedToken lt = (LocatedToken) $4;
1809 MemberName name = new MemberName (lt.Value, lt.Location);
1811 if ($3 == TypeManager.system_void_expr) {
1812 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1818 p = new Property (current_class, (Expression) $3, (int) $2, true,
1819 name, (Attributes) $1,
1822 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1826 Pair pair = (Pair) $7;
1827 p = new Property (current_class, (Expression) $3, (int) $2, true,
1828 name, (Attributes) $1,
1829 (Accessor)pair.First, (Accessor)pair.Second);
1831 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1832 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1837 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1838 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1843 if (RootContext.Documentation != null)
1844 p.DocComment = Lexer.consume_doc_comment ();
1851 CheckIdentifierToken (yyToken, GetLocation ($4));
1857 interface_event_declaration
1858 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1860 LocatedToken lt = (LocatedToken) $5;
1861 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1862 new MemberName (lt.Value, lt.Location),
1864 if (RootContext.Documentation != null)
1865 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1867 | opt_attributes opt_new EVENT type error {
1868 CheckIdentifierToken (yyToken, GetLocation ($5));
1871 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1872 LocatedToken lt = (LocatedToken) $5;
1873 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1876 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1878 lexer.EventParsing = true;
1880 event_accessor_declarations
1882 lexer.EventParsing = false;
1885 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
1890 interface_indexer_declaration
1891 : opt_attributes opt_new type THIS
1892 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1894 { lexer.PropertyParsing = true; }
1895 accessor_declarations
1897 has_get = has_set = false;
1898 lexer.PropertyParsing = false;
1904 i = new Indexer (current_class, (Expression) $3,
1905 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1906 (int) $2, true, (Parameters) $6, (Attributes) $1,
1909 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
1913 Pair pair = (Pair) $10;
1914 i = new Indexer (current_class, (Expression) $3,
1915 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1916 (int) $2, true, (Parameters) $6, (Attributes) $1,
1917 (Accessor)pair.First, (Accessor)pair.Second);
1919 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1920 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
1925 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1926 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
1931 if (RootContext.Documentation != null)
1932 i.DocComment = ConsumeStoredComment ();
1938 operator_declaration
1939 : opt_attributes opt_modifiers operator_declarator
1941 anonymous_host = SimpleAnonymousHost.GetSimple ();
1948 OperatorDeclaration decl = (OperatorDeclaration) $3;
1950 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1952 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
1953 if (decl.arg2type != null)
1954 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
1956 Operator op = new Operator (
1957 current_class, decl.optype, decl.ret_type, (int) $2,
1958 new Parameters (param_list),
1959 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1961 if (RootContext.Documentation != null) {
1962 op.DocComment = tmpComment;
1963 Lexer.doc_state = XmlCommentState.Allowed;
1966 SimpleAnonymousHost.Simple.Propagate (op);
1967 anonymous_host = null;
1969 // Note again, checking is done in semantic analysis
1970 current_container.AddOperator (op);
1972 current_local_parameters = null;
1978 | SEMICOLON { $$ = null; }
1981 : type OPERATOR overloadable_operator
1982 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1984 LocatedToken lt = (LocatedToken) $6;
1985 Operator.OpType op = (Operator.OpType) $3;
1986 CheckUnaryOperator (op, lt.Location);
1988 if (op == Operator.OpType.Addition)
1989 op = Operator.OpType.UnaryPlus;
1991 if (op == Operator.OpType.Subtraction)
1992 op = Operator.OpType.UnaryNegation;
1994 Parameter [] pars = new Parameter [1];
1995 Expression type = (Expression) $5;
1997 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
1999 current_local_parameters = new Parameters (pars);
2001 if (RootContext.Documentation != null) {
2002 tmpComment = Lexer.consume_doc_comment ();
2003 Lexer.doc_state = XmlCommentState.NotAllowed;
2006 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2007 null, null, (Location) $2);
2009 | type OPERATOR overloadable_operator
2011 type IDENTIFIER COMMA
2015 LocatedToken ltParam1 = (LocatedToken) $6;
2016 LocatedToken ltParam2 = (LocatedToken) $9;
2017 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2019 Parameter [] pars = new Parameter [2];
2021 Expression typeL = (Expression) $5;
2022 Expression typeR = (Expression) $8;
2024 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
2025 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
2027 current_local_parameters = new Parameters (pars);
2029 if (RootContext.Documentation != null) {
2030 tmpComment = Lexer.consume_doc_comment ();
2031 Lexer.doc_state = XmlCommentState.NotAllowed;
2034 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2035 typeL, ltParam1.Value,
2036 typeR, ltParam2.Value, (Location) $2);
2038 | conversion_operator_declarator
2039 | type OPERATOR overloadable_operator
2041 type IDENTIFIER COMMA
2042 type IDENTIFIER COMMA
2046 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2047 Operator.GetName ((Operator.OpType) $3));
2050 | type OPERATOR overloadable_operator
2051 OPEN_PARENS CLOSE_PARENS
2053 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2054 Operator.GetName ((Operator.OpType) $3));
2059 overloadable_operator
2061 : BANG { $$ = Operator.OpType.LogicalNot; }
2062 | TILDE { $$ = Operator.OpType.OnesComplement; }
2063 | OP_INC { $$ = Operator.OpType.Increment; }
2064 | OP_DEC { $$ = Operator.OpType.Decrement; }
2065 | TRUE { $$ = Operator.OpType.True; }
2066 | FALSE { $$ = Operator.OpType.False; }
2067 // Unary and binary:
2068 | PLUS { $$ = Operator.OpType.Addition; }
2069 | MINUS { $$ = Operator.OpType.Subtraction; }
2071 | STAR { $$ = Operator.OpType.Multiply; }
2072 | DIV { $$ = Operator.OpType.Division; }
2073 | PERCENT { $$ = Operator.OpType.Modulus; }
2074 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2075 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2076 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2077 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2078 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2079 | OP_EQ { $$ = Operator.OpType.Equality; }
2080 | OP_NE { $$ = Operator.OpType.Inequality; }
2081 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2082 | OP_LT { $$ = Operator.OpType.LessThan; }
2083 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2084 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2087 conversion_operator_declarator
2088 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2090 LocatedToken lt = (LocatedToken) $6;
2091 Parameter [] pars = new Parameter [1];
2093 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2095 current_local_parameters = new Parameters (pars);
2097 if (RootContext.Documentation != null) {
2098 tmpComment = Lexer.consume_doc_comment ();
2099 Lexer.doc_state = XmlCommentState.NotAllowed;
2102 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
2103 null, null, (Location) $2);
2105 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2107 LocatedToken lt = (LocatedToken) $6;
2108 Parameter [] pars = new Parameter [1];
2110 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2112 current_local_parameters = new Parameters (pars);
2114 if (RootContext.Documentation != null) {
2115 tmpComment = Lexer.consume_doc_comment ();
2116 Lexer.doc_state = XmlCommentState.NotAllowed;
2119 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
2120 null, null, (Location) $2);
2124 syntax_error ((Location) $1, "'operator' expected");
2128 syntax_error ((Location) $1, "'operator' expected");
2132 constructor_declaration
2135 constructor_declarator
2138 Constructor c = (Constructor) $3;
2139 c.Block = (ToplevelBlock) $4;
2140 c.OptAttributes = (Attributes) $1;
2141 c.ModFlags = (int) $2;
2143 if (RootContext.Documentation != null)
2144 c.DocComment = ConsumeStoredComment ();
2146 if (c.Name == current_container.Basename){
2147 if ((c.ModFlags & Modifiers.STATIC) != 0){
2148 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2149 Report.Error (515, c.Location,
2150 "`{0}': access modifiers are not allowed on static constructors",
2151 c.GetSignatureForError ());
2154 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2156 if (c.Initializer != null){
2157 Report.Error (514, c.Location,
2158 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2159 c.GetSignatureForError ());
2162 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2165 // We let another layer check the validity of the constructor.
2166 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2169 current_container.AddConstructor (c);
2171 current_local_parameters = null;
2172 if (RootContext.Documentation != null)
2173 Lexer.doc_state = XmlCommentState.Allowed;
2177 constructor_declarator
2180 if (RootContext.Documentation != null) {
2181 tmpComment = Lexer.consume_doc_comment ();
2182 Lexer.doc_state = XmlCommentState.Allowed;
2185 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2187 current_local_parameters = (Parameters) $4;
2189 opt_constructor_initializer
2191 LocatedToken lt = (LocatedToken) $1;
2192 $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
2193 (ConstructorInitializer) $7, lt.Location);
2195 anonymous_host = (IAnonymousHost) $$;
2201 | SEMICOLON { $$ = null; }
2204 opt_constructor_initializer
2205 : /* empty */ { $$ = null; }
2206 | constructor_initializer
2209 constructor_initializer
2210 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2212 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2214 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2216 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2219 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2225 : /* EMPTY */ { $$ = 0; }
2226 | UNSAFE { $$ = Modifiers.UNSAFE; }
2227 | EXTERN { $$ = Modifiers.EXTERN; }
2230 destructor_declaration
2231 : opt_attributes opt_finalizer TILDE
2233 if (RootContext.Documentation != null) {
2234 tmpComment = Lexer.consume_doc_comment ();
2235 Lexer.doc_state = XmlCommentState.NotAllowed;
2238 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2240 LocatedToken lt = (LocatedToken) $5;
2241 if (lt.Value != current_container.MemberName.Name){
2242 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2243 } else if (current_container.Kind != Kind.Class){
2244 Report.Error (575, lt.Location, "Only class types can contain destructor");
2246 Location l = lt.Location;
2249 if (!RootContext.StdLib && current_container.Name == "System.Object")
2250 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2252 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2254 Method d = new Destructor (
2255 current_class, TypeManager.system_void_expr, m, "Finalize",
2256 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2257 if (RootContext.Documentation != null)
2258 d.DocComment = ConsumeStoredComment ();
2260 d.Block = (ToplevelBlock) $8;
2261 current_container.AddMethod (d);
2269 EVENT type variable_declarators SEMICOLON
2271 current_array_type = null;
2272 foreach (VariableDeclaration var in (ArrayList) $5) {
2274 MemberName name = new MemberName (var.identifier,
2277 EventField e = new EventField (
2278 current_class, (Expression) $4, (int) $2, false, name,
2281 e.Initializer = var.expression_or_array_initializer;
2283 current_container.AddEvent (e);
2285 if (RootContext.Documentation != null) {
2286 e.DocComment = Lexer.consume_doc_comment ();
2287 Lexer.doc_state = XmlCommentState.Allowed;
2293 EVENT type namespace_or_type_name
2296 implicit_value_parameter_type = (Expression) $4;
2297 lexer.EventParsing = true;
2299 event_accessor_declarations
2301 lexer.EventParsing = false;
2305 MemberName name = (MemberName) $5;
2308 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2309 current_container.Name, name.ToString ());
2312 Pair pair = (Pair) $8;
2314 if (name.TypeArguments != null)
2315 syntax_error (lexer.Location, "an event can't have type arguments");
2317 if (pair.First == null || pair.Second == null)
2318 // CS0073 is already reported, so no CS0065 here.
2321 Event e = new EventProperty (
2322 current_class, (Expression) $4, (int) $2, false, name,
2323 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
2324 if (RootContext.Documentation != null) {
2325 e.DocComment = Lexer.consume_doc_comment ();
2326 Lexer.doc_state = XmlCommentState.Allowed;
2329 current_container.AddEvent (e);
2330 implicit_value_parameter_type = null;
2334 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2335 MemberName mn = (MemberName) $5;
2337 if (mn.Left != null)
2338 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2340 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2342 if (RootContext.Documentation != null)
2343 Lexer.doc_state = XmlCommentState.Allowed;
2347 event_accessor_declarations
2348 : add_accessor_declaration remove_accessor_declaration
2350 $$ = new Pair ($1, $2);
2352 | remove_accessor_declaration add_accessor_declaration
2354 $$ = new Pair ($2, $1);
2356 | add_accessor_declaration { $$ = null; }
2357 | remove_accessor_declaration { $$ = null; }
2360 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2366 add_accessor_declaration
2367 : opt_attributes ADD
2369 Parameter [] args = new Parameter [1];
2370 Parameter implicit_value_parameter = new Parameter (
2371 implicit_value_parameter_type, "value",
2372 Parameter.Modifier.NONE, null, (Location) $2);
2374 args [0] = implicit_value_parameter;
2376 current_local_parameters = new Parameters (args);
2377 lexer.EventParsing = false;
2381 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2382 lexer.EventParsing = true;
2384 | opt_attributes ADD error {
2385 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2388 | opt_attributes modifiers ADD {
2389 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2394 remove_accessor_declaration
2395 : opt_attributes REMOVE
2397 Parameter [] args = new Parameter [1];
2398 Parameter implicit_value_parameter = new Parameter (
2399 implicit_value_parameter_type, "value",
2400 Parameter.Modifier.NONE, null, (Location) $2);
2402 args [0] = implicit_value_parameter;
2404 current_local_parameters = new Parameters (args);
2405 lexer.EventParsing = false;
2409 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2410 lexer.EventParsing = true;
2412 | opt_attributes REMOVE error {
2413 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2416 | opt_attributes modifiers REMOVE {
2417 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2423 : opt_attributes opt_modifiers indexer_declarator
2426 IndexerDeclaration decl = (IndexerDeclaration) $3;
2428 implicit_value_parameter_type = decl.type;
2430 lexer.PropertyParsing = true;
2431 parsing_indexer = true;
2433 indexer_parameters = decl.param_list;
2434 anonymous_host = SimpleAnonymousHost.GetSimple ();
2436 accessor_declarations
2438 lexer.PropertyParsing = false;
2439 has_get = has_set = false;
2440 parsing_indexer = false;
2447 // The signature is computed from the signature of the indexer. Look
2448 // at section 3.6 on the spec
2450 IndexerDeclaration decl = (IndexerDeclaration) $3;
2451 Pair pair = (Pair) $6;
2452 Accessor get_block = (Accessor) pair.First;
2453 Accessor set_block = (Accessor) pair.Second;
2456 if (decl.interface_type != null)
2457 name = new MemberName (
2458 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2460 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2462 indexer = new Indexer (current_class, decl.type, name,
2463 (int) $2, false, decl.param_list, (Attributes) $1,
2464 get_block, set_block);
2466 if (RootContext.Documentation != null)
2467 indexer.DocComment = ConsumeStoredComment ();
2469 current_container.AddIndexer (indexer);
2471 current_local_parameters = null;
2472 implicit_value_parameter_type = null;
2473 indexer_parameters = null;
2478 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2480 Parameters pars = (Parameters) $4;
2481 if (pars.HasArglist) {
2482 // "__arglist is not valid in this context"
2483 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2484 } else if (pars.Empty){
2485 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2487 if (RootContext.Documentation != null) {
2488 tmpComment = Lexer.consume_doc_comment ();
2489 Lexer.doc_state = XmlCommentState.Allowed;
2492 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2494 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2496 Parameters pars = (Parameters) $6;
2498 if (pars.HasArglist) {
2499 // "__arglist is not valid in this context"
2500 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2501 } else if (pars.Empty){
2502 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2505 MemberName name = (MemberName) $2;
2506 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2508 if (RootContext.Documentation != null) {
2509 tmpComment = Lexer.consume_doc_comment ();
2510 Lexer.doc_state = XmlCommentState.Allowed;
2521 if (RootContext.Documentation != null)
2522 enumTypeComment = Lexer.consume_doc_comment ();
2527 LocatedToken lt = (LocatedToken) $5;
2528 Location enum_location = lt.Location;
2531 Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
2532 break; // assumes that the parser put us in a switch
2535 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2536 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2537 name, (Attributes) $1);
2539 if (RootContext.Documentation != null)
2540 e.DocComment = enumTypeComment;
2543 EnumMember em = null;
2544 foreach (VariableDeclaration ev in (ArrayList) $8) {
2545 em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
2546 new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
2548 // if (RootContext.Documentation != null)
2549 em.DocComment = ev.DocComment;
2551 e.AddEnumMember (em);
2554 current_container.AddEnum (e);
2561 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2562 | COLON type { $$ = $2; }
2568 if (RootContext.Documentation != null)
2569 Lexer.doc_state = XmlCommentState.Allowed;
2571 opt_enum_member_declarations
2573 // here will be evaluated after CLOSE_BLACE is consumed.
2574 if (RootContext.Documentation != null)
2575 Lexer.doc_state = XmlCommentState.Allowed;
2583 opt_enum_member_declarations
2584 : /* empty */ { $$ = new ArrayList (4); }
2585 | enum_member_declarations opt_comma { $$ = $1; }
2588 enum_member_declarations
2589 : enum_member_declaration
2591 ArrayList l = new ArrayList (4);
2596 | enum_member_declarations COMMA enum_member_declaration
2598 ArrayList l = (ArrayList) $1;
2606 enum_member_declaration
2607 : opt_attributes IDENTIFIER
2609 VariableDeclaration vd = new VariableDeclaration (
2610 (LocatedToken) $2, null, (Attributes) $1);
2612 if (RootContext.Documentation != null) {
2613 vd.DocComment = Lexer.consume_doc_comment ();
2614 Lexer.doc_state = XmlCommentState.Allowed;
2619 | opt_attributes IDENTIFIER
2621 if (RootContext.Documentation != null) {
2622 tmpComment = Lexer.consume_doc_comment ();
2623 Lexer.doc_state = XmlCommentState.NotAllowed;
2628 VariableDeclaration vd = new VariableDeclaration (
2629 (LocatedToken) $2, $5, (Attributes) $1);
2631 if (RootContext.Documentation != null)
2632 vd.DocComment = ConsumeStoredComment ();
2638 delegate_declaration
2643 lexer.ConstraintsParsing = true;
2646 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2648 MemberName name = MakeName ((MemberName) $6);
2649 Parameters p = (Parameters) $8;
2651 // TODO: wrong location
2652 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2655 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2656 (int) $2, name, p, (Attributes) $1);
2658 if (RootContext.Documentation != null) {
2659 del.DocComment = Lexer.consume_doc_comment ();
2660 Lexer.doc_state = XmlCommentState.Allowed;
2663 current_container.AddDelegate (del);
2664 current_delegate = del;
2666 opt_type_parameter_constraints_clauses
2668 lexer.ConstraintsParsing = false;
2672 current_delegate.SetParameterInfo ((ArrayList) $11);
2673 $$ = current_delegate;
2675 current_delegate = null;
2682 lexer.CheckNullable (false);
2687 lexer.CheckNullable (true);
2692 namespace_or_type_name
2694 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2695 LocatedToken lt1 = (LocatedToken) $1;
2696 LocatedToken lt2 = (LocatedToken) $3;
2697 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2699 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2700 LocatedToken lt = (LocatedToken) $3;
2701 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2706 : IDENTIFIER opt_type_argument_list {
2707 LocatedToken lt = (LocatedToken) $1;
2708 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2712 opt_type_argument_list
2713 : /* empty */ { $$ = null; }
2714 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2717 if (RootContext.Version == LanguageVersion.ISO_1)
2718 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2722 $$ = new TypeArguments ((int) $1, lexer.Location);
2723 if (RootContext.Version == LanguageVersion.ISO_1)
2724 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2729 : opt_attributes type {
2730 TypeArguments type_args = new TypeArguments (lexer.Location);
2732 SimpleName sn = $2 as SimpleName;
2734 Report.Error (1031, lexer.Location, "Type expected");
2736 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2738 type_args.Add ((Expression) $2);
2741 | type_arguments COMMA opt_attributes type {
2742 TypeArguments type_args = (TypeArguments) $1;
2744 SimpleName sn = $4 as SimpleName;
2746 Report.Error (1031, lexer.Location, "Type expected");
2748 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2750 type_args.Add ((Expression) $4);
2757 * Before you think of adding a return_type, notice that we have been
2758 * using two rules in the places where it matters (one rule using type
2759 * and another identical one that uses VOID as the return type). This
2760 * gets rid of a shift/reduce couple
2763 : namespace_or_type_name opt_nullable
2765 MemberName name = (MemberName) $1;
2766 $$ = name.GetTypeExpression ();
2769 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2771 | builtin_types opt_nullable
2774 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2784 // Note that here only unmanaged types are allowed but we
2785 // can't perform checks during this phase - we do it during
2786 // semantic analysis.
2788 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2792 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2797 : builtin_types opt_nullable
2800 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2802 | non_expression_type rank_specifier
2804 Location loc = GetLocation ($1);
2806 loc = lexer.Location;
2807 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2809 | non_expression_type STAR
2811 Location loc = GetLocation ($1);
2813 loc = lexer.Location;
2814 $$ = new ComposedCast ((Expression) $1, "*", loc);
2816 | expression rank_specifiers
2818 $$ = new ComposedCast ((Expression) $1, (string) $2);
2822 $$ = new ComposedCast ((Expression) $1, "*");
2826 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2827 // through this different path
2829 | multiplicative_expression STAR
2831 $$ = new ComposedCast ((Expression) $1, "*");
2838 ArrayList types = new ArrayList (4);
2843 | type_list COMMA type
2845 ArrayList types = (ArrayList) $1;
2853 * replaces all the productions for isolating the various
2854 * simple types, but we need this to reuse it easily in local_variable_type
2857 : OBJECT { $$ = TypeManager.system_object_expr; }
2858 | STRING { $$ = TypeManager.system_string_expr; }
2859 | BOOL { $$ = TypeManager.system_boolean_expr; }
2860 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2861 | FLOAT { $$ = TypeManager.system_single_expr; }
2862 | DOUBLE { $$ = TypeManager.system_double_expr; }
2867 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2868 | BYTE { $$ = TypeManager.system_byte_expr; }
2869 | SHORT { $$ = TypeManager.system_int16_expr; }
2870 | USHORT { $$ = TypeManager.system_uint16_expr; }
2871 | INT { $$ = TypeManager.system_int32_expr; }
2872 | UINT { $$ = TypeManager.system_uint32_expr; }
2873 | LONG { $$ = TypeManager.system_int64_expr; }
2874 | ULONG { $$ = TypeManager.system_uint64_expr; }
2875 | CHAR { $$ = TypeManager.system_char_expr; }
2876 | VOID { $$ = TypeManager.system_void_expr; }
2880 : type rank_specifiers opt_nullable
2882 string rank_specifiers = (string) $2;
2884 rank_specifiers += "?";
2886 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
2891 // Expressions, section 7.5
2900 MemberName mn = (MemberName) $1;
2901 $$ = mn.GetTypeExpression ();
2903 | IDENTIFIER DOUBLE_COLON IDENTIFIER
2905 LocatedToken lt1 = (LocatedToken) $1;
2906 LocatedToken lt2 = (LocatedToken) $3;
2907 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
2909 | parenthesized_expression
2910 | default_value_expression
2912 | invocation_expression
2916 | post_increment_expression
2917 | post_decrement_expression
2921 | checked_expression
2922 | unchecked_expression
2923 | pointer_member_access
2924 | anonymous_method_expression
2931 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2932 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2933 | NULL { $$ = new NullLiteral (lexer.Location); }
2937 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2938 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2939 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2944 object v = lexer.Value;
2947 $$ = new IntLiteral ((int) v, lexer.Location);
2948 } else if (v is uint)
2949 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2951 $$ = new LongLiteral ((Int64) v, lexer.Location);
2952 else if (v is ulong)
2953 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2955 Console.WriteLine ("OOPS. Unexpected result from scanner");
2960 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2961 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2964 parenthesized_expression_0
2965 : OPEN_PARENS expression CLOSE_PARENS
2968 lexer.Deambiguate_CloseParens ($$);
2969 // After this, the next token returned is one of
2970 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST (CLOSE_PARENS), CLOSE_PARENS_OPEN_PARENS
2971 // or CLOSE_PARENS_MINUS.
2973 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
2976 parenthesized_expression
2977 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2981 | parenthesized_expression_0 CLOSE_PARENS
2985 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2987 // If a parenthesized expression is followed by a minus, we need to wrap
2988 // the expression inside a ParenthesizedExpression for the CS0075 check
2989 // in Binary.DoResolve().
2990 $$ = new ParenthesizedExpression ((Expression) $1);
2995 : primary_expression DOT IDENTIFIER opt_type_argument_list
2997 LocatedToken lt = (LocatedToken) $3;
2998 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3000 | predefined_type DOT IDENTIFIER opt_type_argument_list
3002 LocatedToken lt = (LocatedToken) $3;
3003 // TODO: Location is wrong as some predefined types doesn't hold a location
3004 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location);
3012 invocation_expression
3013 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3016 Report.Error (1, (Location) $2, "Parse error");
3018 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3020 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3022 $$ = new Invocation ((Expression) $1, new ArrayList ());
3024 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3026 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3028 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3030 ArrayList args = new ArrayList (1);
3032 $$ = new Invocation ((Expression) $1, args);
3034 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3036 ArrayList args = ((ArrayList) $4);
3038 $$ = new Invocation ((Expression) $1, args);
3043 : /* empty */ { $$ = null; }
3050 ArrayList list = new ArrayList (4);
3054 | argument_list COMMA argument
3056 ArrayList list = (ArrayList) $1;
3060 | argument_list error {
3061 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3069 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3071 | non_simple_argument
3078 : REF variable_reference
3080 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3082 | OUT variable_reference
3084 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3086 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3088 ArrayList list = (ArrayList) $3;
3089 Argument[] args = new Argument [list.Count];
3090 list.CopyTo (args, 0);
3092 Expression expr = new Arglist (args, (Location) $1);
3093 $$ = new Argument (expr, Argument.AType.Expression);
3097 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3102 : expression { note ("section 5.4"); $$ = $1; }
3106 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3108 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3110 | primary_expression rank_specifiers
3112 // So the super-trick is that primary_expression
3113 // can only be either a SimpleName or a MemberAccess.
3114 // The MemberAccess case arises when you have a fully qualified type-name like :
3116 // SimpleName is when you have
3119 Expression expr = (Expression) $1;
3120 if (expr is ComposedCast){
3121 $$ = new ComposedCast (expr, (string) $2);
3122 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3123 Error_ExpectingTypeName (expr);
3124 $$ = TypeManager.system_object_expr;
3127 // So we extract the string corresponding to the SimpleName
3130 $$ = new ComposedCast (expr, (string) $2);
3132 current_array_type = (Expression)$$;
3139 ArrayList list = new ArrayList (4);
3143 | expression_list COMMA expression
3145 ArrayList list = (ArrayList) $1;
3154 $$ = new This (current_block, (Location) $1);
3159 : BASE DOT IDENTIFIER opt_type_argument_list
3161 LocatedToken lt = (LocatedToken) $3;
3162 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3164 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3166 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3169 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3174 post_increment_expression
3175 : primary_expression OP_INC
3177 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3178 (Expression) $1, (Location) $2);
3182 post_decrement_expression
3183 : primary_expression OP_DEC
3185 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3186 (Expression) $1, (Location) $2);
3191 : object_or_delegate_creation_expression
3192 | array_creation_expression
3195 object_or_delegate_creation_expression
3196 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3198 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3202 array_creation_expression
3203 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3205 opt_array_initializer
3207 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3209 | NEW type rank_specifiers array_initializer
3211 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3215 Report.Error (1031, (Location) $1, "Type expected");
3220 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3236 opt_rank_specifier_or_nullable
3245 | opt_nullable rank_specifiers
3252 | opt_nullable rank_specifiers INTERR
3255 $$ = "?" + $2 + "?";
3262 : rank_specifier opt_rank_specifier
3264 $$ = (string) $2 + (string) $1;
3269 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3271 $$ = "[" + (string) $2 + "]";
3291 | dim_separators COMMA
3293 $$ = (string) $1 + ",";
3297 opt_array_initializer
3309 : OPEN_BRACE CLOSE_BRACE
3311 ArrayList list = new ArrayList (4);
3314 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3316 $$ = (ArrayList) $2;
3320 variable_initializer_list
3321 : variable_initializer
3323 ArrayList list = new ArrayList (4);
3327 | variable_initializer_list COMMA variable_initializer
3329 ArrayList list = (ArrayList) $1;
3338 pushed_current_array_type = current_array_type;
3339 lexer.TypeOfParsing = true;
3341 OPEN_PARENS type CLOSE_PARENS
3343 lexer.TypeOfParsing = false;
3344 Expression type = (Expression)$4;
3345 if (type == TypeManager.system_void_expr)
3346 $$ = new TypeOfVoid ((Location) $1);
3348 $$ = new TypeOf (type, (Location) $1);
3349 current_array_type = pushed_current_array_type;
3354 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3355 $$ = new SizeOf ((Expression) $3, (Location) $1);
3360 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3362 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3366 unchecked_expression
3367 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3369 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3373 pointer_member_access
3374 : primary_expression OP_PTR IDENTIFIER
3377 LocatedToken lt = (LocatedToken) $3;
3379 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3380 $$ = new MemberAccess (deref, lt.Value);
3384 anonymous_method_expression
3385 : DELEGATE opt_anonymous_method_signature
3387 if (oob_stack == null)
3388 oob_stack = new Stack (6);
3390 oob_stack.Push (current_anonymous_method);
3391 oob_stack.Push (current_local_parameters);
3392 current_local_parameters = (Parameters)$2;
3394 // Force the next block to be created as a ToplevelBlock
3395 oob_stack.Push (current_block);
3396 oob_stack.Push (top_current_block);
3398 Location loc = (Location) $1;
3399 current_anonymous_method = new AnonymousMethodExpression (
3400 current_anonymous_method, current_generic_method, current_container,
3401 (Parameters) $2, (ToplevelBlock) top_current_block, loc);
3403 parsing_anonymous_method = true;
3407 Location loc = (Location) $1;
3408 top_current_block = (Block) oob_stack.Pop ();
3409 current_block = (Block) oob_stack.Pop ();
3411 if (RootContext.Version == LanguageVersion.ISO_1){
3412 Report.FeatureIsNotStandardized (loc, "anonymous methods");
3415 ToplevelBlock anon_block = (ToplevelBlock) $4;
3417 anon_block.Parent = current_block;
3419 current_anonymous_method.Block = anon_block;
3420 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
3421 anonymous_host.AddAnonymousMethod (current_anonymous_method);
3423 $$ = current_anonymous_method;
3426 current_local_parameters = (Parameters) oob_stack.Pop ();
3427 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
3431 opt_anonymous_method_signature
3432 : /* empty */ { $$ = null; }
3433 | anonymous_method_signature
3436 anonymous_method_signature
3437 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
3440 $$ = Parameters.EmptyReadOnlyParameters;
3442 ArrayList par_list = (ArrayList) $2;
3443 Parameter [] pars = new Parameter [par_list.Count];
3444 par_list.CopyTo (pars);
3445 $$ = new Parameters (pars);
3450 opt_anonymous_method_parameter_list
3451 : /* empty */ { $$ = null; }
3452 | anonymous_method_parameter_list { $$ = $1; }
3455 anonymous_method_parameter_list
3456 : anonymous_method_parameter
3458 ArrayList a = new ArrayList (4);
3462 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3464 ArrayList a = (ArrayList) $1;
3470 anonymous_method_parameter
3471 : opt_parameter_modifier type IDENTIFIER {
3472 LocatedToken lt = (LocatedToken) $3;
3473 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3475 | PARAMS type IDENTIFIER {
3476 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3481 default_value_expression
3482 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3484 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3489 : primary_expression
3490 | BANG prefixed_unary_expression
3492 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3494 | TILDE prefixed_unary_expression
3496 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3502 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3504 $$ = new Cast ((Expression) $1, (Expression) $3);
3506 | parenthesized_expression_0 CLOSE_PARENS_NO_CAST default_value_expression
3508 $$ = new Cast ((Expression) $1, (Expression) $3);
3510 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3512 $$ = new Cast ((Expression) $1, (Expression) $3);
3518 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3520 // TODO: wrong location
3521 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3526 // The idea to split this out is from Rhys' grammar
3527 // to solve the problem with casts.
3529 prefixed_unary_expression
3531 | PLUS prefixed_unary_expression
3533 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3535 | MINUS prefixed_unary_expression
3537 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3539 | OP_INC prefixed_unary_expression
3541 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3542 (Expression) $2, (Location) $1);
3544 | OP_DEC prefixed_unary_expression
3546 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3547 (Expression) $2, (Location) $1);
3549 | STAR prefixed_unary_expression
3551 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3553 | BITWISE_AND prefixed_unary_expression
3555 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3559 pre_increment_expression
3560 : OP_INC prefixed_unary_expression
3562 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3563 (Expression) $2, (Location) $1);
3567 pre_decrement_expression
3568 : OP_DEC prefixed_unary_expression
3570 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3571 (Expression) $2, (Location) $1);
3575 multiplicative_expression
3576 : prefixed_unary_expression
3577 | multiplicative_expression STAR prefixed_unary_expression
3579 $$ = new Binary (Binary.Operator.Multiply,
3580 (Expression) $1, (Expression) $3);
3582 | multiplicative_expression DIV prefixed_unary_expression
3584 $$ = new Binary (Binary.Operator.Division,
3585 (Expression) $1, (Expression) $3);
3587 | multiplicative_expression PERCENT prefixed_unary_expression
3589 $$ = new Binary (Binary.Operator.Modulus,
3590 (Expression) $1, (Expression) $3);
3595 : multiplicative_expression
3596 | additive_expression PLUS multiplicative_expression
3598 $$ = new Binary (Binary.Operator.Addition,
3599 (Expression) $1, (Expression) $3);
3601 | additive_expression MINUS multiplicative_expression
3603 $$ = new Binary (Binary.Operator.Subtraction,
3604 (Expression) $1, (Expression) $3);
3609 : additive_expression
3610 | shift_expression OP_SHIFT_LEFT additive_expression
3612 $$ = new Binary (Binary.Operator.LeftShift,
3613 (Expression) $1, (Expression) $3);
3615 | shift_expression OP_SHIFT_RIGHT additive_expression
3617 $$ = new Binary (Binary.Operator.RightShift,
3618 (Expression) $1, (Expression) $3);
3629 lexer.PutbackNullable ();
3634 nullable_type_or_conditional
3637 if (((bool) $2) && ($1 is ComposedCast))
3638 $$ = ((ComposedCast) $1).RemoveNullable ();
3644 relational_expression
3646 | relational_expression OP_LT shift_expression
3648 $$ = new Binary (Binary.Operator.LessThan,
3649 (Expression) $1, (Expression) $3);
3651 | relational_expression OP_GT shift_expression
3653 $$ = new Binary (Binary.Operator.GreaterThan,
3654 (Expression) $1, (Expression) $3);
3656 | relational_expression OP_LE shift_expression
3658 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3659 (Expression) $1, (Expression) $3);
3661 | relational_expression OP_GE shift_expression
3663 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3664 (Expression) $1, (Expression) $3);
3666 | relational_expression IS
3669 } nullable_type_or_conditional
3671 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3673 | relational_expression AS
3676 } nullable_type_or_conditional
3678 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3683 : relational_expression
3684 | equality_expression OP_EQ relational_expression
3686 $$ = new Binary (Binary.Operator.Equality,
3687 (Expression) $1, (Expression) $3);
3689 | equality_expression OP_NE relational_expression
3691 $$ = new Binary (Binary.Operator.Inequality,
3692 (Expression) $1, (Expression) $3);
3697 : equality_expression
3698 | and_expression BITWISE_AND equality_expression
3700 $$ = new Binary (Binary.Operator.BitwiseAnd,
3701 (Expression) $1, (Expression) $3);
3705 exclusive_or_expression
3707 | exclusive_or_expression CARRET and_expression
3709 $$ = new Binary (Binary.Operator.ExclusiveOr,
3710 (Expression) $1, (Expression) $3);
3714 inclusive_or_expression
3715 : exclusive_or_expression
3716 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3718 $$ = new Binary (Binary.Operator.BitwiseOr,
3719 (Expression) $1, (Expression) $3);
3723 conditional_and_expression
3724 : inclusive_or_expression
3725 | conditional_and_expression OP_AND inclusive_or_expression
3727 $$ = new Binary (Binary.Operator.LogicalAnd,
3728 (Expression) $1, (Expression) $3);
3732 conditional_or_expression
3733 : conditional_and_expression
3734 | conditional_or_expression OP_OR conditional_and_expression
3736 $$ = new Binary (Binary.Operator.LogicalOr,
3737 (Expression) $1, (Expression) $3);
3741 conditional_expression
3742 : conditional_or_expression
3743 | conditional_or_expression INTERR expression COLON expression
3745 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3747 | conditional_or_expression INTERR INTERR expression
3749 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3751 // We'll be resolved into a `parenthesized_expression_0' later on.
3752 | conditional_or_expression INTERR CLOSE_PARENS
3754 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3755 lexer.PutbackCloseParens ();
3759 assignment_expression
3760 : prefixed_unary_expression ASSIGN expression
3762 $$ = new Assign ((Expression) $1, (Expression) $3);
3764 | prefixed_unary_expression OP_MULT_ASSIGN expression
3766 $$ = new CompoundAssign (
3767 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3769 | prefixed_unary_expression OP_DIV_ASSIGN expression
3771 $$ = new CompoundAssign (
3772 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3774 | prefixed_unary_expression OP_MOD_ASSIGN expression
3776 $$ = new CompoundAssign (
3777 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3779 | prefixed_unary_expression OP_ADD_ASSIGN expression
3781 $$ = new CompoundAssign (
3782 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3784 | prefixed_unary_expression OP_SUB_ASSIGN expression
3786 $$ = new CompoundAssign (
3787 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3789 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3791 $$ = new CompoundAssign (
3792 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3794 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3796 $$ = new CompoundAssign (
3797 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3799 | prefixed_unary_expression OP_AND_ASSIGN expression
3801 $$ = new CompoundAssign (
3802 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3804 | prefixed_unary_expression OP_OR_ASSIGN expression
3806 $$ = new CompoundAssign (
3807 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3809 | prefixed_unary_expression OP_XOR_ASSIGN expression
3811 $$ = new CompoundAssign (
3812 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3817 : conditional_expression
3818 | assignment_expression
3838 lexer.ConstraintsParsing = true;
3842 MemberName name = MakeName ((MemberName) $6);
3843 int mod_flags = (int) $2;
3845 push_current_class (new Class (
3846 current_namespace, current_class, name,
3847 mod_flags, (Attributes) $1), false, $3);
3850 opt_type_parameter_constraints_clauses
3852 lexer.ConstraintsParsing = false;
3855 if (current_class.Name == "System.Object") {
3856 Report.Error (537, current_class.Location,
3857 "The class System.Object cannot have a base " +
3858 "class or implement an interface.");
3860 current_container.AddBasesForPart (current_class, (ArrayList) $8);
3863 current_class.SetParameterInfo ((ArrayList) $9);
3865 if (RootContext.Documentation != null) {
3866 current_container.DocComment = Lexer.consume_doc_comment ();
3867 Lexer.doc_state = XmlCommentState.Allowed;
3872 if (RootContext.Documentation != null)
3873 Lexer.doc_state = XmlCommentState.Allowed;
3877 $$ = pop_current_class ();
3885 { $$ = $1; } // location
3889 : /* empty */ { $$ = (int) 0; }
3895 | modifiers modifier
3900 if ((m1 & m2) != 0) {
3901 Location l = lexer.Location;
3902 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
3904 $$ = (int) (m1 | m2);
3909 : NEW { $$ = Modifiers.NEW; }
3910 | PUBLIC { $$ = Modifiers.PUBLIC; }
3911 | PROTECTED { $$ = Modifiers.PROTECTED; }
3912 | INTERNAL { $$ = Modifiers.INTERNAL; }
3913 | PRIVATE { $$ = Modifiers.PRIVATE; }
3914 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3915 | SEALED { $$ = Modifiers.SEALED; }
3916 | STATIC { $$ = Modifiers.STATIC; }
3917 | READONLY { $$ = Modifiers.READONLY; }
3918 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3919 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3920 | EXTERN { $$ = Modifiers.EXTERN; }
3921 | VOLATILE { $$ = Modifiers.VOLATILE; }
3922 | UNSAFE { $$ = Modifiers.UNSAFE; }
3926 : /* empty */ { $$ = null; }
3927 | class_base { $$ = $1; }
3931 : COLON type_list { $$ = $2; }
3934 opt_type_parameter_constraints_clauses
3935 : /* empty */ { $$ = null; }
3936 | type_parameter_constraints_clauses
3940 type_parameter_constraints_clauses
3941 : type_parameter_constraints_clause {
3942 ArrayList constraints = new ArrayList (1);
3943 constraints.Add ($1);
3946 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3947 ArrayList constraints = (ArrayList) $1;
3948 Constraints new_constraint = (Constraints)$2;
3950 foreach (Constraints c in constraints) {
3951 if (new_constraint.TypeParameter == c.TypeParameter) {
3952 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
3953 new_constraint.TypeParameter);
3957 constraints.Add (new_constraint);
3962 type_parameter_constraints_clause
3963 : WHERE IDENTIFIER COLON type_parameter_constraints {
3964 LocatedToken lt = (LocatedToken) $2;
3965 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
3969 type_parameter_constraints
3970 : type_parameter_constraint {
3971 ArrayList constraints = new ArrayList (1);
3972 constraints.Add ($1);
3975 | type_parameter_constraints COMMA type_parameter_constraint {
3976 ArrayList constraints = (ArrayList) $1;
3978 constraints.Add ($3);
3983 type_parameter_constraint
3985 | NEW OPEN_PARENS CLOSE_PARENS {
3986 $$ = SpecialConstraint.Constructor;
3989 $$ = SpecialConstraint.ReferenceType;
3992 $$ = SpecialConstraint.ValueType;
4001 // A block is "contained" on the following places:
4003 // property_declaration as part of the accessor body (get/set)
4004 // operator_declaration
4005 // constructor_declaration
4006 // destructor_declaration
4007 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4012 if (parsing_anonymous_method) {
4013 top_current_block = new ToplevelBlock (
4014 current_block, current_local_parameters, current_generic_method,
4016 if (current_block != null)
4017 current_block.AddAnonymousChild ((ToplevelBlock) top_current_block);
4018 current_block = top_current_block;
4019 parsing_anonymous_method = false;
4020 } else if (current_block == null) {
4021 current_block = new ToplevelBlock (
4022 (ToplevelBlock) top_current_block, current_local_parameters,
4023 current_generic_method, (Location) $1);
4024 top_current_block = current_block;
4026 current_block = new Block (current_block, (Location) $1, Location.Null);
4029 opt_statement_list CLOSE_BRACE
4031 while (current_block.Implicit)
4032 current_block = current_block.Parent;
4034 current_block.SetEndLocation ((Location) $4);
4035 current_block = current_block.Parent;
4036 if (current_block == null)
4037 top_current_block = null;
4048 | statement_list statement
4052 : declaration_statement
4054 if ($1 != null && (Block) $1 != current_block){
4055 current_block.AddStatement ((Statement) $1);
4056 current_block = (Block) $1;
4059 | valid_declaration_statement
4061 current_block.AddStatement ((Statement) $1);
4066 valid_declaration_statement
4069 | expression_statement
4070 | selection_statement
4071 | iteration_statement
4075 | unchecked_statement
4083 : valid_declaration_statement
4084 | declaration_statement
4086 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4091 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4099 $$ = EmptyStatement.Value;
4106 LocatedToken lt = (LocatedToken) $1;
4107 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4109 if (current_block.AddLabel (labeled))
4110 current_block.AddStatement (labeled);
4115 declaration_statement
4116 : local_variable_declaration SEMICOLON
4118 current_array_type = null;
4120 DictionaryEntry de = (DictionaryEntry) $1;
4121 Expression e = (Expression) de.Key;
4123 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4127 | local_constant_declaration SEMICOLON
4129 current_array_type = null;
4131 DictionaryEntry de = (DictionaryEntry) $1;
4133 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4139 * The following is from Rhys' grammar:
4140 * > Types in local variable declarations must be recognized as
4141 * > expressions to prevent reduce/reduce errors in the grammar.
4142 * > The expressions are converted into types during semantic analysis.
4145 : primary_expression opt_rank_specifier_or_nullable
4147 // FIXME: Do something smart here regarding the composition of the type.
4149 // Ok, the above "primary_expression" is there to get rid of
4150 // both reduce/reduce and shift/reduces in the grammar, it should
4151 // really just be "type_name". If you use type_name, a reduce/reduce
4152 // creeps up. If you use namespace_or_type_name (which is all we need
4153 // really) two shift/reduces appear.
4156 // So the super-trick is that primary_expression
4157 // can only be either a SimpleName or a MemberAccess.
4158 // The MemberAccess case arises when you have a fully qualified type-name like :
4160 // SimpleName is when you have
4163 Expression expr = (Expression) $1;
4164 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4165 Error_ExpectingTypeName (expr);
4169 // So we extract the string corresponding to the SimpleName
4173 if ((string) $2 == "")
4176 $$ = new ComposedCast ((Expression) $1, (string) $2);
4179 | builtin_types opt_rank_specifier_or_nullable
4181 if ((string) $2 == "")
4184 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4188 local_variable_pointer_type
4189 : primary_expression STAR
4191 Expression expr = (Expression) $1;
4193 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4194 Error_ExpectingTypeName (expr);
4198 $$ = new ComposedCast ((Expression) $1, "*");
4200 | builtin_types STAR
4202 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4206 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4208 | local_variable_pointer_type STAR
4210 $$ = new ComposedCast ((Expression) $1, "*");
4214 local_variable_declaration
4215 : local_variable_type variable_declarators
4218 $$ = new DictionaryEntry ($1, $2);
4222 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4227 if ((string) $2 == "")
4228 t = (Expression) $1;
4230 t = new ComposedCast ((Expression) $1, (string) $2);
4231 $$ = new DictionaryEntry (t, $3);
4237 local_constant_declaration
4238 : CONST local_variable_type constant_declarators
4241 $$ = new DictionaryEntry ($2, $3);
4247 expression_statement
4248 : statement_expression SEMICOLON { $$ = $1; }
4252 // We have to do the wrapping here and not in the case above,
4253 // because statement_expression is used for example in for_statement
4255 statement_expression
4258 Expression expr = (Expression) $1;
4259 ExpressionStatement s = expr as ExpressionStatement;
4261 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4264 $$ = new StatementExpression (s);
4268 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4273 object_creation_expression
4274 : object_or_delegate_creation_expression
4275 { note ("complain if this is a delegate maybe?"); }
4284 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4287 Location l = (Location) $1;
4289 $$ = new If ((Expression) $3, (Statement) $5, l);
4291 // FIXME: location for warning should be loc property of $5.
4292 if ($5 == EmptyStatement.Value)
4293 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4296 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4297 embedded_statement ELSE embedded_statement
4299 Location l = (Location) $1;
4301 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4303 // FIXME: location for warning should be loc property of $5 and $7.
4304 if ($5 == EmptyStatement.Value)
4305 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4306 if ($7 == EmptyStatement.Value)
4307 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4312 : SWITCH OPEN_PARENS
4314 if (switch_stack == null)
4315 switch_stack = new Stack (2);
4316 switch_stack.Push (current_block);
4318 expression CLOSE_PARENS
4321 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4322 current_block = (Block) switch_stack.Pop ();
4338 Report.Warning (1522, 1, lexer.Location, "Empty switch block");
4339 $$ = new ArrayList ();
4347 ArrayList sections = new ArrayList (4);
4352 | switch_sections switch_section
4354 ArrayList sections = (ArrayList) $1;
4364 current_block = current_block.CreateSwitchBlock (lexer.Location);
4368 Block topmost = current_block;
4370 while (topmost.Implicit)
4371 topmost = topmost.Parent;
4372 $$ = new SwitchSection ((ArrayList) $1, topmost);
4379 ArrayList labels = new ArrayList (4);
4384 | switch_labels switch_label
4386 ArrayList labels = (ArrayList) ($1);
4394 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4395 | DEFAULT_COLON { $$ = new SwitchLabel (null, (Location) $1); }
4398 1523, GetLocation ($1),
4399 "The keyword case or default must precede code in switch block");
4411 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4413 Location l = (Location) $1;
4414 $$ = new While ((Expression) $3, (Statement) $5, l);
4419 : DO embedded_statement
4420 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4422 Location l = (Location) $1;
4424 $$ = new Do ((Statement) $2, (Expression) $5, l);
4430 opt_for_initializer SEMICOLON
4432 Block assign_block = new Block (current_block);
4433 current_block = assign_block;
4435 if ($3 is DictionaryEntry){
4436 DictionaryEntry de = (DictionaryEntry) $3;
4438 Expression type = (Expression) de.Key;
4439 ArrayList var_declarators = (ArrayList) de.Value;
4441 foreach (VariableDeclaration decl in var_declarators){
4445 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4449 Location l = lexer.Location;
4450 Expression expr = decl.expression_or_array_initializer;
4452 LocalVariableReference var;
4453 var = new LocalVariableReference (assign_block, decl.identifier, l);
4456 Assign a = new Assign (var, expr, decl.Location);
4458 assign_block.AddStatement (new StatementExpression (a));
4462 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4463 // This can be referred to as $5 below.
4469 opt_for_condition SEMICOLON
4470 opt_for_iterator CLOSE_PARENS
4473 Location l = (Location) $1;
4475 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4477 current_block.AddStatement (f);
4478 while (current_block.Implicit)
4479 current_block = current_block.Parent;
4481 current_block = current_block.Parent;
4486 : /* empty */ { $$ = EmptyStatement.Value; }
4491 : local_variable_declaration
4492 | statement_expression_list
4496 : /* empty */ { $$ = null; }
4497 | boolean_expression
4501 : /* empty */ { $$ = EmptyStatement.Value; }
4506 : statement_expression_list
4509 statement_expression_list
4510 : statement_expression
4512 // CHANGE: was `null'
4513 Statement s = (Statement) $1;
4514 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4519 | statement_expression_list COMMA statement_expression
4521 Block b = (Block) $1;
4523 b.AddStatement ((Statement) $3);
4529 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4531 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4534 | FOREACH OPEN_PARENS type IDENTIFIER IN
4535 expression CLOSE_PARENS
4537 Block foreach_block = new Block (current_block);
4538 current_block = foreach_block;
4540 LocatedToken lt = (LocatedToken) $4;
4541 Location l = lt.Location;
4544 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4546 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4548 // Get a writable reference to this read-only variable.
4550 // Note that the $$ here refers to the value of _this_ code block,
4551 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4552 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4559 LocalVariableReference v = (LocalVariableReference) $8;
4560 Location l = (Location) $1;
4563 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4564 current_block.AddStatement (f);
4567 while (current_block.Implicit)
4568 current_block = current_block.Parent;
4570 current_block = current_block.Parent;
4576 | continue_statement
4586 $$ = new Break ((Location) $1);
4591 : CONTINUE SEMICOLON
4593 $$ = new Continue ((Location) $1);
4598 : GOTO IDENTIFIER SEMICOLON
4600 LocatedToken lt = (LocatedToken) $2;
4601 $$ = new Goto (lt.Value, lt.Location);
4603 | GOTO CASE constant_expression SEMICOLON
4605 $$ = new GotoCase ((Expression) $3, (Location) $1);
4607 | GOTO DEFAULT SEMICOLON
4609 $$ = new GotoDefault ((Location) $1);
4614 : RETURN opt_expression SEMICOLON
4616 $$ = new Return ((Expression) $2, (Location) $1);
4621 : THROW opt_expression SEMICOLON
4623 $$ = new Throw ((Expression) $2, (Location) $1);
4628 : IDENTIFIER RETURN expression SEMICOLON
4630 LocatedToken lt = (LocatedToken) $1;
4631 string s = lt.Value;
4633 Report.Error (1003, lt.Location, "; expected");
4636 if (RootContext.Version == LanguageVersion.ISO_1){
4637 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4640 if (anonymous_host == null){
4641 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4644 anonymous_host.SetYields ();
4645 $$ = new Yield ((Expression) $3, lt.Location);
4648 | IDENTIFIER RETURN SEMICOLON
4650 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4653 | IDENTIFIER BREAK SEMICOLON
4655 LocatedToken lt = (LocatedToken) $1;
4656 string s = lt.Value;
4658 Report.Error (1003, lt.Location, "; expected");
4661 if (RootContext.Version == LanguageVersion.ISO_1){
4662 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4665 if (anonymous_host == null){
4666 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4669 anonymous_host.SetYields ();
4670 $$ = new YieldBreak (lt.Location);
4681 : TRY block catch_clauses
4685 ArrayList c = (ArrayList)$3;
4686 for (int i = 0; i < c.Count; ++i) {
4687 Catch cc = (Catch) c [i];
4689 if (i != c.Count - 1)
4690 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4697 // Now s contains the list of specific catch clauses
4698 // and g contains the general one.
4700 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4702 | TRY block opt_catch_clauses FINALLY block
4705 ArrayList s = new ArrayList (4);
4706 ArrayList catch_list = (ArrayList) $3;
4708 if (catch_list != null){
4709 foreach (Catch cc in catch_list) {
4717 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4721 Report.Error (1524, (Location) $1, "Expected catch or finally");
4727 : /* empty */ { $$ = null; }
4734 ArrayList l = new ArrayList (4);
4739 | catch_clauses catch_clause
4741 ArrayList l = (ArrayList) $1;
4749 : /* empty */ { $$ = null; }
4754 : CATCH opt_catch_args
4756 Expression type = null;
4759 DictionaryEntry cc = (DictionaryEntry) $2;
4760 type = (Expression) cc.Key;
4761 LocatedToken lt = (LocatedToken) cc.Value;
4764 ArrayList one = new ArrayList (4);
4766 one.Add (new VariableDeclaration (lt, null));
4768 current_block = new Block (current_block);
4769 Block b = declare_local_variables (type, one, lt.Location);
4774 Expression type = null;
4776 Block var_block = null;
4779 DictionaryEntry cc = (DictionaryEntry) $2;
4780 type = (Expression) cc.Key;
4781 LocatedToken lt = (LocatedToken) cc.Value;
4785 while (current_block.Implicit)
4786 current_block = current_block.Parent;
4787 var_block = current_block;
4788 current_block = current_block.Parent;
4792 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
4797 : /* empty */ { $$ = null; }
4802 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4804 $$ = new DictionaryEntry ($2, $3);
4812 $$ = new Checked ((Block) $2);
4819 $$ = new Unchecked ((Block) $2);
4826 RootContext.CheckUnsafeOption ((Location) $1);
4828 $$ = new Unsafe ((Block) $3);
4834 type fixed_pointer_declarators
4837 ArrayList list = (ArrayList) $4;
4838 Expression type = (Expression) $3;
4839 Location l = (Location) $1;
4840 int top = list.Count;
4842 Block assign_block = new Block (current_block);
4843 current_block = assign_block;
4845 for (int i = 0; i < top; i++){
4846 Pair p = (Pair) list [i];
4849 v = current_block.AddVariable (type, (string) p.First, l);
4853 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4861 Location l = (Location) $1;
4863 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4865 current_block.AddStatement (f);
4866 while (current_block.Implicit)
4867 current_block = current_block.Parent;
4869 current_block = current_block.Parent;
4873 fixed_pointer_declarators
4874 : fixed_pointer_declarator {
4875 ArrayList declarators = new ArrayList (4);
4877 declarators.Add ($1);
4880 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4882 ArrayList declarators = (ArrayList) $1;
4884 declarators.Add ($3);
4889 fixed_pointer_declarator
4890 : IDENTIFIER ASSIGN expression
4892 LocatedToken lt = (LocatedToken) $1;
4893 // FIXME: keep location
4894 $$ = new Pair (lt.Value, $3);
4898 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
4904 : LOCK OPEN_PARENS expression CLOSE_PARENS
4910 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
4915 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4917 Block assign_block = new Block (current_block);
4918 current_block = assign_block;
4920 if ($3 is DictionaryEntry){
4921 DictionaryEntry de = (DictionaryEntry) $3;
4922 Location l = (Location) $1;
4924 Expression type = (Expression) de.Key;
4925 ArrayList var_declarators = (ArrayList) de.Value;
4927 ArrayList vars = new ArrayList (4);
4929 foreach (VariableDeclaration decl in var_declarators){
4931 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4934 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4936 Expression expr = decl.expression_or_array_initializer;
4938 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4941 LocalVariableReference var;
4943 // Get a writable reference to this read-only variable.
4944 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4946 // This is so that it is not a warning on using variables
4949 vars.Add (new DictionaryEntry (var, expr));
4951 // Assign a = new Assign (var, expr, decl.Location);
4952 // assign_block.AddStatement (new StatementExpression (a));
4955 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4956 // It can be referred to as $5 below.
4957 $$ = new DictionaryEntry (type, vars);
4964 Using u = new Using ($5, (Statement) $6, (Location) $1);
4965 current_block.AddStatement (u);
4966 while (current_block.Implicit)
4967 current_block = current_block.Parent;
4969 current_block = current_block.Parent;
4973 resource_acquisition
4974 : local_variable_declaration
4981 // A class used to pass around variable declarations and constants
4983 public class VariableDeclaration {
4984 public string identifier;
4985 public Expression expression_or_array_initializer;
4986 public Location Location;
4987 public Attributes OptAttributes;
4988 public string DocComment;
4990 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
4992 this.identifier = lt.Value;
4993 if (eoai is ArrayList) {
4994 if (CSharpParser.current_array_type == null)
4995 Report.Error (622, lt.Location,
4996 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
4997 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
4999 this.expression_or_array_initializer = (Expression)eoai;
5001 this.Location = lt.Location;
5002 this.OptAttributes = opt_attrs;
5005 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
5011 // A class used to hold info about an indexer declarator
5013 public class IndexerDeclaration {
5014 public Expression type;
5015 public MemberName interface_type;
5016 public Parameters param_list;
5017 public Location location;
5019 public IndexerDeclaration (Expression type, MemberName interface_type,
5020 Parameters param_list, Location loc)
5023 this.interface_type = interface_type;
5024 this.param_list = param_list;
5025 this.location = loc;
5030 // We use this when we do not have an object in advance that is an IAnonymousHost
5032 public class SimpleAnonymousHost : IAnonymousHost {
5033 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5036 ArrayList anonymous_methods;
5038 public static SimpleAnonymousHost GetSimple () {
5039 Simple.yields = false;
5040 Simple.anonymous_methods = null;
5044 public void SetYields ()
5049 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5051 if (anonymous_methods == null)
5052 anonymous_methods = new ArrayList ();
5053 anonymous_methods.Add (anonymous);
5056 public void Propagate (IAnonymousHost real_host)
5059 real_host.SetYields ();
5060 if (anonymous_methods != null) {
5061 foreach (AnonymousMethodExpression ame in anonymous_methods)
5062 real_host.AddAnonymousMethod (ame);
5068 // A class used to hold info about an operator declarator
5070 public class OperatorDeclaration {
5071 public Operator.OpType optype;
5072 public Expression ret_type, arg1type, arg2type;
5073 public string arg1name, arg2name;
5074 public Location location;
5076 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5077 Expression arg1type, string arg1name,
5078 Expression arg2type, string arg2name, Location location)
5081 this.ret_type = ret_type;
5082 this.arg1type = arg1type;
5083 this.arg1name = arg1name;
5084 this.arg2type = arg2type;
5085 this.arg2name = arg2name;
5086 this.location = location;
5091 void Error_ExpectingTypeName (Expression expr)
5093 if (expr is Invocation){
5094 Report.Error (1002, expr.Location, "Expecting `;'");
5096 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5100 void push_current_class (TypeContainer tc, bool is_interface, object partial_token)
5102 if (partial_token != null)
5103 current_container = current_container.AddPartial (tc, is_interface);
5105 current_container = current_container.AddTypeContainer (tc, is_interface);
5109 DeclSpace pop_current_class ()
5111 DeclSpace retval = current_class;
5113 current_class = current_class.Parent;
5114 current_container = current_class.PartialContainer;
5120 // Given the @class_name name, it creates a fully qualified name
5121 // based on the containing declaration space
5124 MakeName (MemberName class_name)
5126 Namespace ns = current_namespace.NS;
5128 if (current_container.Name.Length == 0){
5129 if (ns.Name.Length != 0)
5130 return new MemberName (ns.MemberName, class_name);
5134 return new MemberName (current_container.MemberName, class_name);
5138 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5140 Block implicit_block;
5141 ArrayList inits = null;
5144 // We use the `Used' property to check whether statements
5145 // have been added to the current block. If so, we need
5146 // to create another block to contain the new declaration
5147 // otherwise, as an optimization, we use the same block to
5148 // add the declaration.
5150 // FIXME: A further optimization is to check if the statements
5151 // that were added were added as part of the initialization
5152 // below. In which case, no other statements have been executed
5153 // and we might be able to reduce the number of blocks for
5154 // situations like this:
5156 // int j = 1; int k = j + 1;
5158 if (current_block.Used)
5159 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5161 implicit_block = current_block;
5163 foreach (VariableDeclaration decl in variable_declarators){
5165 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5166 if (decl.expression_or_array_initializer != null){
5168 inits = new ArrayList (4);
5175 return implicit_block;
5177 foreach (VariableDeclaration decl in inits){
5179 Expression expr = decl.expression_or_array_initializer;
5181 LocalVariableReference var;
5182 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5184 assign = new Assign (var, expr, decl.Location);
5186 implicit_block.AddStatement (new StatementExpression (assign));
5189 return implicit_block;
5192 Block declare_local_constants (Expression type, ArrayList declarators)
5194 Block implicit_block;
5196 if (current_block.Used)
5197 implicit_block = new Block (current_block, Block.Flags.Implicit);
5199 implicit_block = current_block;
5201 foreach (VariableDeclaration decl in declarators){
5202 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5205 return implicit_block;
5208 void CheckAttributeTarget (string a, Location l)
5212 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5216 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5222 void CheckUnaryOperator (Operator.OpType op, Location l)
5226 case Operator.OpType.LogicalNot:
5227 case Operator.OpType.OnesComplement:
5228 case Operator.OpType.Increment:
5229 case Operator.OpType.Decrement:
5230 case Operator.OpType.True:
5231 case Operator.OpType.False:
5232 case Operator.OpType.Addition:
5233 case Operator.OpType.Subtraction:
5238 Report.Error (1019, l, "Overloadable unary operator expected");
5244 void CheckBinaryOperator (Operator.OpType op, Location l)
5248 case Operator.OpType.Addition:
5249 case Operator.OpType.Subtraction:
5250 case Operator.OpType.Multiply:
5251 case Operator.OpType.Division:
5252 case Operator.OpType.Modulus:
5253 case Operator.OpType.BitwiseAnd:
5254 case Operator.OpType.BitwiseOr:
5255 case Operator.OpType.ExclusiveOr:
5256 case Operator.OpType.LeftShift:
5257 case Operator.OpType.RightShift:
5258 case Operator.OpType.Equality:
5259 case Operator.OpType.Inequality:
5260 case Operator.OpType.GreaterThan:
5261 case Operator.OpType.LessThan:
5262 case Operator.OpType.GreaterThanOrEqual:
5263 case Operator.OpType.LessThanOrEqual:
5267 Report.Error (1020, l, "Overloadable binary operator expected");
5273 void syntax_error (Location l, string msg)
5275 Report.Error (1003, l, "Syntax error, " + msg);
5278 void note (string s)
5280 // Used to put annotations
5285 public Tokenizer Lexer {
5291 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5293 this.name = file.Name;
5295 current_namespace = new NamespaceEntry (null, file, null);
5296 current_class = current_namespace.SlaveDeclSpace;
5297 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5299 lexer = new Tokenizer (reader, file, defines);
5302 public void parse ()
5304 int errors = Report.Errors;
5306 if (yacc_verbose_flag > 1)
5307 yyparse (lexer, new yydebug.yyDebugSimple ());
5310 Tokenizer tokenizer = lexer as Tokenizer;
5311 tokenizer.cleanup ();
5312 } catch (Exception e){
5314 // Removed for production use, use parser verbose to get the output.
5316 // Console.WriteLine (e);
5317 if (Report.Errors == errors)
5318 Report.Error (-25, lexer.Location, "Parsing error");
5319 if (yacc_verbose_flag > 0)
5320 Console.WriteLine (e);
5323 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5324 throw new InternalErrorException ("who set it?");
5327 static void CheckToken (int error, int yyToken, string msg, Location loc)
5329 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5330 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5332 Report.Error (error, loc, msg);
5335 void CheckIdentifierToken (int yyToken, Location loc)
5337 CheckToken (1041, yyToken, "Identifier expected", loc);
5340 string ConsumeStoredComment ()
5342 string s = tmpComment;
5344 Lexer.doc_state = XmlCommentState.Allowed;
5348 Location GetLocation (object obj)
5350 if (obj is MemberCore)
5351 return ((MemberCore) obj).Location;
5352 if (obj is MemberName)
5353 return ((MemberName) obj).Location;
5354 if (obj is LocatedToken)
5355 return ((LocatedToken) obj).Location;
5356 if (obj is Location)
5357 return (Location) obj;
5358 return lexer.Location;