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
78 /// An out-of-band stack.
87 static public int yacc_verbose_flag;
89 // Name of the file we are parsing
98 /// Temporary Xml documentation cache.
99 /// For enum types, we need one more temporary store.
102 string enumTypeComment;
104 /// Current attribute target
105 string current_attr_target;
107 /// assembly and module attribute definitions are enabled
108 bool global_attrs_enabled = true;
109 bool has_get, has_set;
114 %token NONE /* This token is never returned by our lexer */
115 %token ERROR // This is used not by the parser, but by the tokenizer.
119 *These are the C# keywords
206 /* C# keywords which are not really keywords */
212 /* C# single character operators/punctuation. */
213 %token OPEN_BRACE "{"
214 %token CLOSE_BRACE "}"
215 %token OPEN_BRACKET "["
216 %token CLOSE_BRACKET "]"
217 %token OPEN_PARENS "("
218 %token CLOSE_PARENS ")"
230 %token OP_GENERICS_LT "<"
232 %token OP_GENERICS_GT ">"
233 %token BITWISE_AND "&"
234 %token BITWISE_OR "|"
241 /* C# multi-character operators. */
242 %token DOUBLE_COLON "::"
245 %token OP_SHIFT_LEFT "<<"
246 %token OP_SHIFT_RIGHT ">>"
253 %token OP_MULT_ASSIGN "*="
254 %token OP_DIV_ASSIGN "/="
255 %token OP_MOD_ASSIGN "%="
256 %token OP_ADD_ASSIGN "+="
257 %token OP_SUB_ASSIGN "-="
258 %token OP_SHIFT_LEFT_ASSIGN "<<="
259 %token OP_SHIFT_RIGHT_ASSIGN ">>="
260 %token OP_AND_ASSIGN "&="
261 %token OP_XOR_ASSIGN "^="
262 %token OP_OR_ASSIGN "|="
266 %token LITERAL_INTEGER "int literal"
267 %token LITERAL_FLOAT "float literal"
268 %token LITERAL_DOUBLE "double literal"
269 %token LITERAL_DECIMAL "decimal literal"
270 %token LITERAL_CHARACTER "character literal"
271 %token LITERAL_STRING "string literal"
274 %token CLOSE_PARENS_CAST
275 %token CLOSE_PARENS_NO_CAST
276 %token CLOSE_PARENS_OPEN_PARENS
277 %token CLOSE_PARENS_MINUS
278 %token DEFAULT_OPEN_PARENS
279 %token GENERIC_DIMENSION
281 /* Add precedence rules to solve dangling else s/r conflict */
290 %left OP_SHIFT_LEFT OP_SHIFT_RIGHT
292 %left STAR DIV PERCENT
293 %right BANG CARRET UMINUS
294 %nonassoc OP_INC OP_DEC
296 %left OPEN_BRACKET OPEN_BRACE
300 %start compilation_unit
304 : outer_declarations opt_EOF
305 | outer_declarations global_attributes opt_EOF
306 | global_attributes opt_EOF
307 | opt_EOF /* allow empty files */
313 Lexer.check_incorrect_doc_comment ();
317 Lexer.check_incorrect_doc_comment ();
323 | outer_declarations outer_declaration
327 : extern_alias_directive
329 | namespace_member_declaration
332 extern_alias_directives
333 : extern_alias_directive
334 | extern_alias_directives extern_alias_directive;
336 extern_alias_directive
337 : EXTERN IDENTIFIER IDENTIFIER SEMICOLON
339 LocatedToken lt = (LocatedToken) $2;
342 Report.Error (1003, lt.Location, "'alias' expected");
343 } else if (RootContext.Version == LanguageVersion.ISO_1) {
344 Report.FeatureIsNotStandardized (lt.Location, "external alias");
346 lt = (LocatedToken) $3;
347 current_namespace.UsingExternalAlias (lt.Value, lt.Location);
354 | using_directives using_directive
358 : using_alias_directive
360 if (RootContext.Documentation != null)
361 Lexer.doc_state = XmlCommentState.Allowed;
363 | using_namespace_directive
365 if (RootContext.Documentation != null)
366 Lexer.doc_state = XmlCommentState.Allowed;
370 using_alias_directive
371 : USING IDENTIFIER ASSIGN
372 namespace_or_type_name SEMICOLON
374 LocatedToken lt = (LocatedToken) $2;
375 current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
378 CheckIdentifierToken (yyToken, GetLocation ($2));
382 using_namespace_directive
383 : USING namespace_name SEMICOLON
385 current_namespace.Using ((MemberName) $2, (Location) $1);
390 // Strictly speaking, namespaces don't have attributes but
391 // we parse global attributes along with namespace declarations and then
394 namespace_declaration
395 : opt_attributes NAMESPACE namespace_or_type_name
397 MemberName name = (MemberName) $3;
400 Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
403 if (name.TypeArguments != null)
404 syntax_error (lexer.Location, "namespace name expected");
406 current_namespace = new NamespaceEntry (
407 current_namespace, file, name.GetName ());
408 current_class = current_namespace.SlaveDeclSpace;
409 current_container = current_class.PartialContainer;
411 namespace_body opt_semicolon
413 current_namespace = current_namespace.Parent;
414 current_class = current_namespace.SlaveDeclSpace;
415 current_container = current_class.PartialContainer;
430 : namespace_or_type_name {
431 MemberName name = (MemberName) $1;
433 if (name.TypeArguments != null)
434 syntax_error (lexer.Location, "namespace name expected");
443 if (RootContext.Documentation != null)
444 Lexer.doc_state = XmlCommentState.Allowed;
446 opt_extern_alias_directives
448 opt_namespace_member_declarations
457 opt_extern_alias_directives
459 | extern_alias_directives
462 opt_namespace_member_declarations
464 | namespace_member_declarations
467 namespace_member_declarations
468 : namespace_member_declaration
469 | namespace_member_declarations namespace_member_declaration
472 namespace_member_declaration
476 DeclSpace ds = (DeclSpace)$1;
478 if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
479 Report.Error (1527, ds.Location,
480 "Namespace elements cannot be explicitly declared as private, protected or protected internal");
483 current_namespace.DeclarationFound = true;
485 | namespace_declaration {
486 current_namespace.DeclarationFound = true;
489 | field_declaration {
490 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
492 | method_declaration {
493 Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
500 | interface_declaration
502 | delegate_declaration
504 // Enable this when we have handled all errors, because this acts as a generic fallback
507 // Console.WriteLine ("Token=" + yyToken);
508 // Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
520 CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);
528 global_attrs_enabled = false;
533 global_attrs_enabled = false;
542 ArrayList sect = (ArrayList) $1;
544 if (global_attrs_enabled) {
545 if (current_attr_target == "module") {
546 CodeGen.Module.AddAttributes (sect);
548 } else if (current_attr_target != null && current_attr_target.Length > 0) {
549 CodeGen.Assembly.AddAttributes (sect);
552 $$ = new Attributes (sect);
555 if (RootContext.Documentation != null) {
556 Lexer.check_incorrect_doc_comment ();
558 XmlCommentState.Allowed;
562 $$ = new Attributes (sect);
564 current_attr_target = null;
566 | attribute_sections attribute_section
568 Attributes attrs = $1 as Attributes;
569 ArrayList sect = (ArrayList) $2;
571 if (global_attrs_enabled) {
572 if (current_attr_target == "module") {
573 CodeGen.Module.AddAttributes (sect);
575 } else if (current_attr_target == "assembly") {
576 CodeGen.Assembly.AddAttributes (sect);
580 attrs = new Attributes (sect);
582 attrs.AddAttributes (sect);
586 attrs = new Attributes (sect);
588 attrs.AddAttributes (sect);
591 current_attr_target = null;
596 : OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
600 | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
606 attribute_target_specifier
607 : attribute_target COLON
609 current_attr_target = (string)$1;
617 LocatedToken lt = (LocatedToken) $1;
618 CheckAttributeTarget (lt.Value, lt.Location);
619 $$ = lt.Value; // Location won't be required anymore.
621 | EVENT { $$ = "event"; }
622 | RETURN { $$ = "return"; }
628 ArrayList attrs = new ArrayList (4);
634 | attribute_list COMMA attribute
636 ArrayList attrs = (ArrayList) $1;
644 : attribute_name opt_attribute_arguments
646 MemberName mname = (MemberName) $1;
647 if (mname.IsGeneric) {
648 Report.Error (404, lexer.Location,
649 "'<' unexpected: attributes cannot be generic");
652 object [] arguments = (object []) $2;
653 MemberName left = mname.Left;
654 string identifier = mname.Name;
656 Expression left_expr = left == null ? null : left.GetTypeExpression ();
658 if (current_attr_target == "assembly" || current_attr_target == "module")
659 // FIXME: supply "nameEscaped" parameter here.
660 $$ = new GlobalAttribute (current_namespace, current_attr_target,
661 left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
663 $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
668 : namespace_or_type_name { /* reserved attribute name or identifier: 17.4 */ }
671 opt_attribute_arguments
672 : /* empty */ { $$ = null; }
673 | OPEN_PARENS attribute_arguments CLOSE_PARENS
681 : opt_positional_argument_list
686 $$ = new object [] { $1, null };
689 | positional_argument_list COMMA named_argument_list
691 $$ = new object[] { $1, $3 };
693 | named_argument_list
695 $$ = new object [] { null, $1 };
700 opt_positional_argument_list
701 : /* empty */ { $$ = null; }
702 | positional_argument_list
705 positional_argument_list
708 ArrayList args = new ArrayList (4);
709 args.Add (new Argument ((Expression) $1, Argument.AType.Expression));
713 | positional_argument_list COMMA expression
715 ArrayList args = (ArrayList) $1;
716 args.Add (new Argument ((Expression) $3, Argument.AType.Expression));
725 ArrayList args = new ArrayList (4);
730 | named_argument_list COMMA named_argument
732 ArrayList args = (ArrayList) $1;
737 | named_argument_list COMMA expression
739 Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
745 : IDENTIFIER ASSIGN expression
747 // FIXME: keep location
748 $$ = new DictionaryEntry (
749 ((LocatedToken) $1).Value,
750 new Argument ((Expression) $3, Argument.AType.Expression));
756 : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
759 opt_class_member_declarations
761 | class_member_declarations
764 class_member_declarations
765 : class_member_declaration
766 | class_member_declarations
767 class_member_declaration
770 class_member_declaration
771 : constant_declaration // done
772 | field_declaration // done
773 | method_declaration // done
774 | property_declaration // done
775 | event_declaration // done
776 | indexer_declaration // done
777 | operator_declaration // done
778 | constructor_declaration // done
779 | destructor_declaration // done
789 lexer.ConstraintsParsing = true;
793 MemberName name = MakeName ((MemberName) $6);
794 push_current_class (new Struct (
795 current_namespace, current_class, name, (int) $2,
796 (Attributes) $1), false, $3);
799 opt_type_parameter_constraints_clauses
801 lexer.ConstraintsParsing = false;
804 current_container.AddBasesForPart (current_class, (ArrayList) $8);
806 current_class.SetParameterInfo ((ArrayList) $9);
808 if (RootContext.Documentation != null)
809 current_container.DocComment = Lexer.consume_doc_comment ();
813 if (RootContext.Documentation != null)
814 Lexer.doc_state = XmlCommentState.Allowed;
818 $$ = pop_current_class ();
820 | opt_attributes opt_modifiers opt_partial STRUCT error {
821 CheckIdentifierToken (yyToken, GetLocation ($5));
828 if (RootContext.Documentation != null)
829 Lexer.doc_state = XmlCommentState.Allowed;
831 opt_struct_member_declarations CLOSE_BRACE
834 opt_struct_member_declarations
836 | struct_member_declarations
839 struct_member_declarations
840 : struct_member_declaration
841 | struct_member_declarations struct_member_declaration
844 struct_member_declaration
845 : constant_declaration
848 | property_declaration
850 | indexer_declaration
851 | operator_declaration
852 | constructor_declaration
856 * This is only included so we can flag error 575:
857 * destructors only allowed on class types
859 | destructor_declaration
870 int modflags = (int) $2;
871 foreach (VariableDeclaration constant in (ArrayList) $5){
872 Location l = constant.Location;
873 if ((modflags & Modifiers.STATIC) != 0) {
874 Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
878 Const c = new Const (
879 current_class, (Expression) $4, (string) constant.identifier,
880 (Expression) constant.expression_or_array_initializer, modflags,
883 if (RootContext.Documentation != null) {
884 c.DocComment = Lexer.consume_doc_comment ();
885 Lexer.doc_state = XmlCommentState.Allowed;
887 current_container.AddConstant (c);
893 : constant_declarator
895 ArrayList constants = new ArrayList (4);
900 | constant_declarators COMMA constant_declarator
903 ArrayList constants = (ArrayList) $1;
910 : IDENTIFIER ASSIGN constant_expression
912 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
916 // A const field requires a value to be provided
917 Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
929 Expression type = (Expression) $3;
932 current_array_type = null;
934 foreach (VariableDeclaration var in (ArrayList) $4){
935 Field field = new Field (current_class, type, mod, var.identifier,
936 (Attributes) $1, var.Location);
938 field.Initializer = var.expression_or_array_initializer;
940 if (RootContext.Documentation != null) {
941 field.DocComment = Lexer.consume_doc_comment ();
942 Lexer.doc_state = XmlCommentState.Allowed;
944 current_container.AddField (field);
945 $$ = field; // FIXME: might be better if it points to the top item
952 fixed_variable_declarators
955 Expression type = (Expression) $4;
958 current_array_type = null;
960 foreach (VariableDeclaration var in (ArrayList) $5) {
961 FixedField field = new FixedField (current_class, type, mod, var.identifier,
962 (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
964 if (RootContext.Documentation != null) {
965 field.DocComment = Lexer.consume_doc_comment ();
966 Lexer.doc_state = XmlCommentState.Allowed;
968 current_container.AddField (field);
969 $$ = field; // FIXME: might be better if it points to the top item
977 current_array_type = null;
978 Report.Error (670, (Location) $3, "Fields cannot have void type");
982 fixed_variable_declarators
983 : fixed_variable_declarator
985 ArrayList decl = new ArrayList (2);
989 | fixed_variable_declarators COMMA fixed_variable_declarator
991 ArrayList decls = (ArrayList) $1;
997 fixed_variable_declarator
998 : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
1000 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1002 | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1004 Report.Error (443, lexer.Location, "Value or constant expected");
1005 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1009 variable_declarators
1010 : variable_declarator
1012 ArrayList decl = new ArrayList (4);
1017 | variable_declarators COMMA variable_declarator
1019 ArrayList decls = (ArrayList) $1;
1026 : IDENTIFIER ASSIGN variable_initializer
1028 $$ = new VariableDeclaration ((LocatedToken) $1, $3);
1032 $$ = new VariableDeclaration ((LocatedToken) $1, null);
1034 | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
1036 Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
1037 "To declare a fixed size buffer field, use the fixed keyword before the field type");
1042 variable_initializer
1051 | STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
1053 $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
1057 $$ = new ArglistAccess ((Location) $1);
1061 Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
1068 anonymous_host = (IAnonymousHost) $1;
1069 if (RootContext.Documentation != null)
1070 Lexer.doc_state = XmlCommentState.NotAllowed;
1074 Method method = (Method) $1;
1075 method.Block = (ToplevelBlock) $3;
1076 current_container.AddMethod (method);
1078 anonymous_host = null;
1079 current_generic_method = null;
1080 current_local_parameters = null;
1082 if (RootContext.Documentation != null)
1083 Lexer.doc_state = XmlCommentState.Allowed;
1096 Report.Error (1585, lexer.Location,
1097 "Member modifier `{0}' must precede the member type and name",
1098 Modifiers.Name (i));
1109 type namespace_or_type_name
1110 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1112 lexer.ConstraintsParsing = true;
1114 opt_type_parameter_constraints_clauses
1116 lexer.ConstraintsParsing = false;
1118 MemberName name = (MemberName) $4;
1120 if ($9 != null && name.TypeArguments == null)
1121 Report.Error (80, lexer.Location,
1122 "Constraints are not allowed on non-generic declarations");
1126 GenericMethod generic = null;
1127 if (name.TypeArguments != null) {
1128 generic = new GenericMethod (current_namespace, current_class, name,
1129 (Expression) $3, (Parameters) $6);
1131 generic.SetParameterInfo ((ArrayList) $9);
1134 method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
1135 name, (Parameters) $6, (Attributes) $1);
1137 anonymous_host = method;
1138 current_local_parameters = (Parameters) $6;
1139 current_generic_method = generic;
1141 if (RootContext.Documentation != null)
1142 method.DocComment = Lexer.consume_doc_comment ();
1148 VOID namespace_or_type_name
1149 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1151 lexer.ConstraintsParsing = true;
1153 opt_type_parameter_constraints_clauses
1155 lexer.ConstraintsParsing = false;
1157 MemberName name = (MemberName) $4;
1159 if ($9 != null && name.TypeArguments == null)
1160 Report.Error (80, lexer.Location,
1161 "Constraints are not allowed on non-generic declarations");
1164 GenericMethod generic = null;
1165 if (name.TypeArguments != null) {
1166 generic = new GenericMethod (current_namespace, current_class, name,
1167 TypeManager.system_void_expr, (Parameters) $6);
1169 generic.SetParameterInfo ((ArrayList) $9);
1172 method = new Method (current_class, generic, TypeManager.system_void_expr,
1173 (int) $2, false, name, (Parameters) $6, (Attributes) $1);
1175 anonymous_host = method;
1176 current_local_parameters = (Parameters) $6;
1177 current_generic_method = generic;
1179 if (RootContext.Documentation != null)
1180 method.DocComment = Lexer.consume_doc_comment ();
1187 modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1189 MemberName name = (MemberName) $5;
1190 Report.Error (1585, name.Location,
1191 "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));
1193 Method method = new Method (current_class, null, TypeManager.system_void_expr,
1194 0, false, name, (Parameters) $6, (Attributes) $1);
1196 current_local_parameters = (Parameters) $6;
1198 if (RootContext.Documentation != null)
1199 method.DocComment = Lexer.consume_doc_comment ();
1207 | SEMICOLON { $$ = null; }
1210 opt_formal_parameter_list
1211 : /* empty */ { $$ = Parameters.EmptyReadOnlyParameters; }
1212 | formal_parameter_list
1215 formal_parameter_list
1218 ArrayList pars_list = (ArrayList) $1;
1220 Parameter [] pars = new Parameter [pars_list.Count];
1221 pars_list.CopyTo (pars);
1223 $$ = new Parameters (pars);
1225 | fixed_parameters COMMA parameter_array
1227 ArrayList pars_list = (ArrayList) $1;
1230 Parameter [] pars = new Parameter [pars_list.Count];
1231 pars_list.CopyTo (pars);
1233 $$ = new Parameters (pars);
1235 | fixed_parameters COMMA ARGLIST
1237 ArrayList pars_list = (ArrayList) $1;
1238 //pars_list.Add (new ArglistParameter (GetLocation ($3)));
1240 Parameter [] pars = new Parameter [pars_list.Count];
1241 pars_list.CopyTo (pars);
1243 $$ = new Parameters (pars, true);
1245 | parameter_array COMMA error
1248 Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
1251 | fixed_parameters COMMA parameter_array COMMA error
1254 Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
1257 | ARGLIST COMMA error
1259 Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
1262 | fixed_parameters COMMA ARGLIST COMMA error
1264 Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
1269 $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
1273 $$ = new Parameters (new Parameter[0], true);
1280 ArrayList pars = new ArrayList (4);
1285 | fixed_parameters COMMA fixed_parameter
1287 ArrayList pars = (ArrayList) $1;
1296 opt_parameter_modifier
1300 LocatedToken lt = (LocatedToken) $4;
1301 $$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
1304 opt_parameter_modifier
1306 IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
1308 LocatedToken lt = (LocatedToken) $4;
1309 Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
1313 opt_parameter_modifier
1316 Report.Error (1001, GetLocation ($3), "Identifier expected");
1320 opt_parameter_modifier
1323 CheckIdentifierToken (yyToken, GetLocation ($4));
1327 opt_parameter_modifier
1333 LocatedToken lt = (LocatedToken) $4;
1334 Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
1339 opt_parameter_modifier
1340 : /* empty */ { $$ = Parameter.Modifier.NONE; }
1341 | parameter_modifier
1345 : REF { $$ = Parameter.Modifier.REF; }
1346 | OUT { $$ = Parameter.Modifier.OUT; }
1350 : opt_attributes PARAMS type IDENTIFIER
1352 LocatedToken lt = (LocatedToken) $4;
1353 $$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
1354 note ("type must be a single-dimension array type");
1356 | opt_attributes PARAMS parameter_modifier type IDENTIFIER
1358 Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
1361 | opt_attributes PARAMS type error {
1362 CheckIdentifierToken (yyToken, GetLocation ($4));
1367 property_declaration
1371 namespace_or_type_name
1373 if (RootContext.Documentation != null)
1374 tmpComment = Lexer.consume_doc_comment ();
1378 implicit_value_parameter_type = (Expression) $3;
1380 lexer.PropertyParsing = true;
1382 accessor_declarations
1384 lexer.PropertyParsing = false;
1385 has_get = has_set = false;
1393 Pair pair = (Pair) $8;
1394 Accessor get_block = (Accessor) pair.First;
1395 Accessor set_block = (Accessor) pair.Second;
1397 MemberName name = (MemberName) $4;
1399 if (name.TypeArguments != null)
1400 syntax_error (lexer.Location, "a property can't have type arguments");
1402 prop = new Property (current_class, (Expression) $3, (int) $2, false,
1403 name, (Attributes) $1, get_block, set_block);
1405 current_container.AddProperty (prop);
1406 implicit_value_parameter_type = null;
1408 if (RootContext.Documentation != null)
1409 prop.DocComment = ConsumeStoredComment ();
1414 accessor_declarations
1415 : get_accessor_declaration
1417 $$ = new Pair ($1, null);
1419 | get_accessor_declaration accessor_declarations
1421 Pair pair = (Pair) $2;
1425 | set_accessor_declaration
1427 $$ = new Pair (null, $1);
1429 | set_accessor_declaration accessor_declarations
1431 Pair pair = (Pair) $2;
1437 Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
1442 get_accessor_declaration
1443 : opt_attributes opt_modifiers GET
1445 // If this is not the case, then current_local_parameters has already
1446 // been set in indexer_declaration
1447 if (parsing_indexer == false)
1448 current_local_parameters = null;
1450 current_local_parameters = indexer_parameters;
1451 lexer.PropertyParsing = false;
1453 anonymous_host = SimpleAnonymousHost.GetSimple ();
1458 Report.Error (1007, (Location) $3, "Property accessor already defined");
1461 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1463 current_local_parameters = null;
1464 lexer.PropertyParsing = true;
1466 SimpleAnonymousHost.Simple.Propagate (accessor);
1467 anonymous_host = null;
1469 if (RootContext.Documentation != null)
1470 if (Lexer.doc_state == XmlCommentState.Error)
1471 Lexer.doc_state = XmlCommentState.NotAllowed;
1477 set_accessor_declaration
1478 : opt_attributes opt_modifiers SET
1481 Parameter implicit_value_parameter = new Parameter (
1482 implicit_value_parameter_type, "value",
1483 Parameter.Modifier.NONE, null, (Location) $3);
1485 if (parsing_indexer == false) {
1486 args = new Parameter [1];
1487 args [0] = implicit_value_parameter;
1488 current_local_parameters = new Parameters (args);
1490 Parameter [] fpars = indexer_parameters.FixedParameters;
1493 int count = fpars.Length;
1495 args = new Parameter [count + 1];
1496 fpars.CopyTo (args, 0);
1497 args [count] = implicit_value_parameter;
1500 current_local_parameters = new Parameters (
1504 lexer.PropertyParsing = false;
1506 anonymous_host = SimpleAnonymousHost.GetSimple ();
1511 Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
1514 Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
1516 current_local_parameters = null;
1517 lexer.PropertyParsing = true;
1519 SimpleAnonymousHost.Simple.Propagate (accessor);
1520 anonymous_host = null;
1522 if (RootContext.Documentation != null
1523 && Lexer.doc_state == XmlCommentState.Error)
1524 Lexer.doc_state = XmlCommentState.NotAllowed;
1532 | SEMICOLON { $$ = null; }
1535 interface_declaration
1541 lexer.ConstraintsParsing = true;
1545 MemberName name = MakeName ((MemberName) $6);
1547 push_current_class (new Interface (
1548 current_namespace, current_class, name, (int) $2,
1549 (Attributes) $1), true, $3);
1552 opt_type_parameter_constraints_clauses
1554 lexer.ConstraintsParsing = false;
1557 current_container.AddBasesForPart (current_class, (ArrayList) $8);
1559 current_class.SetParameterInfo ((ArrayList) $9);
1561 if (RootContext.Documentation != null) {
1562 current_container.DocComment = Lexer.consume_doc_comment ();
1563 Lexer.doc_state = XmlCommentState.Allowed;
1568 if (RootContext.Documentation != null)
1569 Lexer.doc_state = XmlCommentState.Allowed;
1573 $$ = pop_current_class ();
1575 | opt_attributes opt_modifiers opt_partial INTERFACE error {
1576 CheckIdentifierToken (yyToken, GetLocation ($5));
1582 opt_interface_member_declarations
1586 opt_interface_member_declarations
1588 | interface_member_declarations
1591 interface_member_declarations
1592 : interface_member_declaration
1593 | interface_member_declarations interface_member_declaration
1596 interface_member_declaration
1597 : interface_method_declaration
1602 Method m = (Method) $1;
1604 if (m.IsExplicitImpl)
1605 Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1606 m.GetSignatureForError ());
1608 current_container.AddMethod (m);
1610 if (RootContext.Documentation != null)
1611 Lexer.doc_state = XmlCommentState.Allowed;
1613 | interface_property_declaration
1618 Property p = (Property) $1;
1620 if (p.IsExplicitImpl)
1621 Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1622 p.GetSignatureForError ());
1624 current_container.AddProperty (p);
1626 if (RootContext.Documentation != null)
1627 Lexer.doc_state = XmlCommentState.Allowed;
1629 | interface_event_declaration
1632 Event e = (Event) $1;
1634 if (e.IsExplicitImpl)
1635 Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1636 e.GetSignatureForError ());
1638 current_container.AddEvent (e);
1641 if (RootContext.Documentation != null)
1642 Lexer.doc_state = XmlCommentState.Allowed;
1644 | interface_indexer_declaration
1649 Indexer i = (Indexer) $1;
1651 if (i.IsExplicitImpl)
1652 Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
1653 i.GetSignatureForError ());
1655 current_container.AddIndexer (i);
1657 if (RootContext.Documentation != null)
1658 Lexer.doc_state = XmlCommentState.Allowed;
1660 | delegate_declaration
1663 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1664 ((MemberCore)$1).GetSignatureForError ());
1670 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1671 ((MemberCore)$1).GetSignatureForError ());
1674 | struct_declaration
1677 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1678 ((MemberCore)$1).GetSignatureForError ());
1684 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1685 ((MemberCore)$1).GetSignatureForError ());
1688 | interface_declaration
1691 Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
1692 ((MemberCore)$1).GetSignatureForError ());
1695 | constant_declaration
1697 Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
1705 val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
1710 interface_method_declaration_body
1713 lexer.ConstraintsParsing = false;
1715 opt_statement_list CLOSE_BRACE
1717 Report.Error (531, lexer.Location,
1718 "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
1724 interface_method_declaration
1725 : opt_attributes opt_new type namespace_or_type_name
1726 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1728 lexer.ConstraintsParsing = true;
1730 opt_type_parameter_constraints_clauses
1732 // Refer to the name as $-1 in interface_method_declaration_body
1735 interface_method_declaration_body
1737 lexer.ConstraintsParsing = false;
1739 MemberName name = (MemberName) $4;
1741 if ($9 != null && name.TypeArguments == null)
1742 Report.Error (80, lexer.Location,
1743 "Constraints are not allowed on non-generic declarations");
1745 GenericMethod generic = null;
1746 if (name.TypeArguments != null) {
1747 generic = new GenericMethod (current_namespace, current_class, name,
1748 (Expression) $3, (Parameters) $6);
1750 generic.SetParameterInfo ((ArrayList) $9);
1753 $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
1754 (Parameters) $6, (Attributes) $1);
1755 if (RootContext.Documentation != null)
1756 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1758 | opt_attributes opt_new VOID namespace_or_type_name
1759 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
1761 lexer.ConstraintsParsing = true;
1763 opt_type_parameter_constraints_clauses
1767 interface_method_declaration_body
1769 lexer.ConstraintsParsing = false;
1771 MemberName name = (MemberName) $4;
1773 if ($9 != null && name.TypeArguments == null)
1774 Report.Error (80, lexer.Location,
1775 "Constraints are not allowed on non-generic declarations");
1777 GenericMethod generic = null;
1778 if (name.TypeArguments != null) {
1779 generic = new GenericMethod (current_namespace, current_class, name,
1780 TypeManager.system_void_expr, (Parameters) $6);
1782 generic.SetParameterInfo ((ArrayList) $9);
1785 $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
1786 true, name, (Parameters) $6, (Attributes) $1);
1787 if (RootContext.Documentation != null)
1788 ((Method) $$).DocComment = Lexer.consume_doc_comment ();
1792 interface_property_declaration
1797 { lexer.PropertyParsing = true; }
1798 accessor_declarations
1800 has_get = has_set = false;
1801 lexer.PropertyParsing = false;
1805 LocatedToken lt = (LocatedToken) $4;
1806 MemberName name = new MemberName (lt.Value, lt.Location);
1808 if ($3 == TypeManager.system_void_expr) {
1809 Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
1815 p = new Property (current_class, (Expression) $3, (int) $2, true,
1816 name, (Attributes) $1,
1819 Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
1823 Pair pair = (Pair) $7;
1824 p = new Property (current_class, (Expression) $3, (int) $2, true,
1825 name, (Attributes) $1,
1826 (Accessor)pair.First, (Accessor)pair.Second);
1828 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1829 Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
1834 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1835 Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
1840 if (RootContext.Documentation != null)
1841 p.DocComment = Lexer.consume_doc_comment ();
1848 CheckIdentifierToken (yyToken, GetLocation ($4));
1854 interface_event_declaration
1855 : opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
1857 LocatedToken lt = (LocatedToken) $5;
1858 $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
1859 new MemberName (lt.Value, lt.Location),
1861 if (RootContext.Documentation != null)
1862 ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
1864 | opt_attributes opt_new EVENT type error {
1865 CheckIdentifierToken (yyToken, GetLocation ($5));
1868 | opt_attributes opt_new EVENT type IDENTIFIER ASSIGN {
1869 LocatedToken lt = (LocatedToken) $5;
1870 Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
1873 | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
1875 lexer.EventParsing = true;
1877 event_accessor_declarations
1879 lexer.EventParsing = false;
1882 Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
1887 interface_indexer_declaration
1888 : opt_attributes opt_new type THIS
1889 OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
1891 { lexer.PropertyParsing = true; }
1892 accessor_declarations
1894 has_get = has_set = false;
1895 lexer.PropertyParsing = false;
1901 i = new Indexer (current_class, (Expression) $3,
1902 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1903 (int) $2, true, (Parameters) $6, (Attributes) $1,
1906 Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
1910 Pair pair = (Pair) $10;
1911 i = new Indexer (current_class, (Expression) $3,
1912 new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
1913 (int) $2, true, (Parameters) $6, (Attributes) $1,
1914 (Accessor)pair.First, (Accessor)pair.Second);
1916 if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
1917 Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
1922 if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
1923 Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
1928 if (RootContext.Documentation != null)
1929 i.DocComment = ConsumeStoredComment ();
1935 operator_declaration
1936 : opt_attributes opt_modifiers operator_declarator
1938 anonymous_host = SimpleAnonymousHost.GetSimple ();
1945 OperatorDeclaration decl = (OperatorDeclaration) $3;
1947 Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
1949 param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
1950 if (decl.arg2type != null)
1951 param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
1953 Operator op = new Operator (
1954 current_class, decl.optype, decl.ret_type, (int) $2,
1955 new Parameters (param_list),
1956 (ToplevelBlock) $5, (Attributes) $1, decl.location);
1958 if (RootContext.Documentation != null) {
1959 op.DocComment = tmpComment;
1960 Lexer.doc_state = XmlCommentState.Allowed;
1963 SimpleAnonymousHost.Simple.Propagate (op);
1964 anonymous_host = null;
1966 // Note again, checking is done in semantic analysis
1967 current_container.AddOperator (op);
1969 current_local_parameters = null;
1975 | SEMICOLON { $$ = null; }
1978 : type OPERATOR overloadable_operator
1979 OPEN_PARENS type IDENTIFIER CLOSE_PARENS
1981 LocatedToken lt = (LocatedToken) $6;
1982 Operator.OpType op = (Operator.OpType) $3;
1983 CheckUnaryOperator (op, lt.Location);
1985 if (op == Operator.OpType.Addition)
1986 op = Operator.OpType.UnaryPlus;
1988 if (op == Operator.OpType.Subtraction)
1989 op = Operator.OpType.UnaryNegation;
1991 Parameter [] pars = new Parameter [1];
1992 Expression type = (Expression) $5;
1994 pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
1996 current_local_parameters = new Parameters (pars);
1998 if (RootContext.Documentation != null) {
1999 tmpComment = Lexer.consume_doc_comment ();
2000 Lexer.doc_state = XmlCommentState.NotAllowed;
2003 $$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
2004 null, null, (Location) $2);
2006 | type OPERATOR overloadable_operator
2008 type IDENTIFIER COMMA
2012 LocatedToken ltParam1 = (LocatedToken) $6;
2013 LocatedToken ltParam2 = (LocatedToken) $9;
2014 CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);
2016 Parameter [] pars = new Parameter [2];
2018 Expression typeL = (Expression) $5;
2019 Expression typeR = (Expression) $8;
2021 pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
2022 pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);
2024 current_local_parameters = new Parameters (pars);
2026 if (RootContext.Documentation != null) {
2027 tmpComment = Lexer.consume_doc_comment ();
2028 Lexer.doc_state = XmlCommentState.NotAllowed;
2031 $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1,
2032 typeL, ltParam1.Value,
2033 typeR, ltParam2.Value, (Location) $2);
2035 | conversion_operator_declarator
2036 | type OPERATOR overloadable_operator
2038 type IDENTIFIER COMMA
2039 type IDENTIFIER COMMA
2043 Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
2044 Operator.GetName ((Operator.OpType) $3));
2047 | type OPERATOR overloadable_operator
2048 OPEN_PARENS CLOSE_PARENS
2050 Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
2051 Operator.GetName ((Operator.OpType) $3));
2056 overloadable_operator
2058 : BANG { $$ = Operator.OpType.LogicalNot; }
2059 | TILDE { $$ = Operator.OpType.OnesComplement; }
2060 | OP_INC { $$ = Operator.OpType.Increment; }
2061 | OP_DEC { $$ = Operator.OpType.Decrement; }
2062 | TRUE { $$ = Operator.OpType.True; }
2063 | FALSE { $$ = Operator.OpType.False; }
2064 // Unary and binary:
2065 | PLUS { $$ = Operator.OpType.Addition; }
2066 | MINUS { $$ = Operator.OpType.Subtraction; }
2068 | STAR { $$ = Operator.OpType.Multiply; }
2069 | DIV { $$ = Operator.OpType.Division; }
2070 | PERCENT { $$ = Operator.OpType.Modulus; }
2071 | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
2072 | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
2073 | CARRET { $$ = Operator.OpType.ExclusiveOr; }
2074 | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
2075 | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
2076 | OP_EQ { $$ = Operator.OpType.Equality; }
2077 | OP_NE { $$ = Operator.OpType.Inequality; }
2078 | OP_GT { $$ = Operator.OpType.GreaterThan; }
2079 | OP_LT { $$ = Operator.OpType.LessThan; }
2080 | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
2081 | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
2084 conversion_operator_declarator
2085 : IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2087 LocatedToken lt = (LocatedToken) $6;
2088 Parameter [] pars = new Parameter [1];
2090 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2092 current_local_parameters = new Parameters (pars);
2094 if (RootContext.Documentation != null) {
2095 tmpComment = Lexer.consume_doc_comment ();
2096 Lexer.doc_state = XmlCommentState.NotAllowed;
2099 $$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
2100 null, null, (Location) $2);
2102 | EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
2104 LocatedToken lt = (LocatedToken) $6;
2105 Parameter [] pars = new Parameter [1];
2107 pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);
2109 current_local_parameters = new Parameters (pars);
2111 if (RootContext.Documentation != null) {
2112 tmpComment = Lexer.consume_doc_comment ();
2113 Lexer.doc_state = XmlCommentState.NotAllowed;
2116 $$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
2117 null, null, (Location) $2);
2121 syntax_error ((Location) $1, "'operator' expected");
2125 syntax_error ((Location) $1, "'operator' expected");
2129 constructor_declaration
2132 constructor_declarator
2135 Constructor c = (Constructor) $3;
2136 c.Block = (ToplevelBlock) $4;
2137 c.OptAttributes = (Attributes) $1;
2138 c.ModFlags = (int) $2;
2140 if (RootContext.Documentation != null)
2141 c.DocComment = ConsumeStoredComment ();
2143 if (c.Name == current_container.Basename){
2144 if ((c.ModFlags & Modifiers.STATIC) != 0){
2145 if ((c.ModFlags & Modifiers.Accessibility) != 0){
2146 Report.Error (515, c.Location,
2147 "`{0}': access modifiers are not allowed on static constructors",
2148 c.GetSignatureForError ());
2151 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2153 if (c.Initializer != null){
2154 Report.Error (514, c.Location,
2155 "`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
2156 c.GetSignatureForError ());
2159 c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
2162 // We let another layer check the validity of the constructor.
2163 //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
2166 current_container.AddConstructor (c);
2168 current_local_parameters = null;
2169 if (RootContext.Documentation != null)
2170 Lexer.doc_state = XmlCommentState.Allowed;
2174 constructor_declarator
2177 if (RootContext.Documentation != null) {
2178 tmpComment = Lexer.consume_doc_comment ();
2179 Lexer.doc_state = XmlCommentState.Allowed;
2182 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2184 current_local_parameters = (Parameters) $4;
2186 opt_constructor_initializer
2188 LocatedToken lt = (LocatedToken) $1;
2189 $$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
2190 (ConstructorInitializer) $7, lt.Location);
2192 anonymous_host = (IAnonymousHost) $$;
2198 | SEMICOLON { $$ = null; }
2201 opt_constructor_initializer
2202 : /* empty */ { $$ = null; }
2203 | constructor_initializer
2206 constructor_initializer
2207 : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
2209 $$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
2211 | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
2213 $$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
2216 Report.Error (1018, (Location) $1, "Keyword this or base expected");
2222 : /* EMPTY */ { $$ = 0; }
2223 | UNSAFE { $$ = Modifiers.UNSAFE; }
2224 | EXTERN { $$ = Modifiers.EXTERN; }
2227 destructor_declaration
2228 : opt_attributes opt_finalizer TILDE
2230 if (RootContext.Documentation != null) {
2231 tmpComment = Lexer.consume_doc_comment ();
2232 Lexer.doc_state = XmlCommentState.NotAllowed;
2235 IDENTIFIER OPEN_PARENS CLOSE_PARENS block
2237 LocatedToken lt = (LocatedToken) $5;
2238 if (lt.Value != current_container.MemberName.Name){
2239 Report.Error (574, lt.Location, "Name of destructor must match name of class");
2240 } else if (current_container.Kind != Kind.Class){
2241 Report.Error (575, lt.Location, "Only class types can contain destructor");
2243 Location l = lt.Location;
2246 if (!RootContext.StdLib && current_container.Name == "System.Object")
2247 m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
2249 m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
2251 Method d = new Destructor (
2252 current_class, TypeManager.system_void_expr, m, "Finalize",
2253 Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
2254 if (RootContext.Documentation != null)
2255 d.DocComment = ConsumeStoredComment ();
2257 d.Block = (ToplevelBlock) $8;
2258 current_container.AddMethod (d);
2266 EVENT type variable_declarators SEMICOLON
2268 current_array_type = null;
2269 foreach (VariableDeclaration var in (ArrayList) $5) {
2271 MemberName name = new MemberName (var.identifier,
2274 EventField e = new EventField (
2275 current_class, (Expression) $4, (int) $2, false, name,
2278 e.Initializer = var.expression_or_array_initializer;
2280 current_container.AddEvent (e);
2282 if (RootContext.Documentation != null) {
2283 e.DocComment = Lexer.consume_doc_comment ();
2284 Lexer.doc_state = XmlCommentState.Allowed;
2290 EVENT type namespace_or_type_name
2293 implicit_value_parameter_type = (Expression) $4;
2294 lexer.EventParsing = true;
2296 event_accessor_declarations
2298 lexer.EventParsing = false;
2302 MemberName name = (MemberName) $5;
2305 Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
2306 current_container.Name, name.ToString ());
2309 Pair pair = (Pair) $8;
2311 if (name.TypeArguments != null)
2312 syntax_error (lexer.Location, "an event can't have type arguments");
2314 if (pair.First == null || pair.Second == null)
2315 // CS0073 is already reported, so no CS0065 here.
2318 Event e = new EventProperty (
2319 current_class, (Expression) $4, (int) $2, false, name,
2320 (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
2321 if (RootContext.Documentation != null) {
2322 e.DocComment = Lexer.consume_doc_comment ();
2323 Lexer.doc_state = XmlCommentState.Allowed;
2326 current_container.AddEvent (e);
2327 implicit_value_parameter_type = null;
2331 | opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
2332 MemberName mn = (MemberName) $5;
2334 if (mn.Left != null)
2335 Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
2337 Report.Error (71, mn.Location, "Event declaration should use property syntax");
2339 if (RootContext.Documentation != null)
2340 Lexer.doc_state = XmlCommentState.Allowed;
2344 event_accessor_declarations
2345 : add_accessor_declaration remove_accessor_declaration
2347 $$ = new Pair ($1, $2);
2349 | remove_accessor_declaration add_accessor_declaration
2351 $$ = new Pair ($2, $1);
2353 | add_accessor_declaration { $$ = null; }
2354 | remove_accessor_declaration { $$ = null; }
2357 Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
2363 add_accessor_declaration
2364 : opt_attributes ADD
2366 Parameter [] args = new Parameter [1];
2367 Parameter implicit_value_parameter = new Parameter (
2368 implicit_value_parameter_type, "value",
2369 Parameter.Modifier.NONE, null, (Location) $2);
2371 args [0] = implicit_value_parameter;
2373 current_local_parameters = new Parameters (args);
2374 lexer.EventParsing = false;
2378 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2379 lexer.EventParsing = true;
2381 | opt_attributes ADD error {
2382 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2385 | opt_attributes modifiers ADD {
2386 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2391 remove_accessor_declaration
2392 : opt_attributes REMOVE
2394 Parameter [] args = new Parameter [1];
2395 Parameter implicit_value_parameter = new Parameter (
2396 implicit_value_parameter_type, "value",
2397 Parameter.Modifier.NONE, null, (Location) $2);
2399 args [0] = implicit_value_parameter;
2401 current_local_parameters = new Parameters (args);
2402 lexer.EventParsing = false;
2406 $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
2407 lexer.EventParsing = true;
2409 | opt_attributes REMOVE error {
2410 Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
2413 | opt_attributes modifiers REMOVE {
2414 Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
2420 : opt_attributes opt_modifiers indexer_declarator
2423 IndexerDeclaration decl = (IndexerDeclaration) $3;
2425 implicit_value_parameter_type = decl.type;
2427 lexer.PropertyParsing = true;
2428 parsing_indexer = true;
2430 indexer_parameters = decl.param_list;
2431 anonymous_host = SimpleAnonymousHost.GetSimple ();
2433 accessor_declarations
2435 lexer.PropertyParsing = false;
2436 has_get = has_set = false;
2437 parsing_indexer = false;
2444 // The signature is computed from the signature of the indexer. Look
2445 // at section 3.6 on the spec
2447 IndexerDeclaration decl = (IndexerDeclaration) $3;
2448 Pair pair = (Pair) $6;
2449 Accessor get_block = (Accessor) pair.First;
2450 Accessor set_block = (Accessor) pair.Second;
2453 if (decl.interface_type != null)
2454 name = new MemberName (
2455 decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
2457 name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);
2459 indexer = new Indexer (current_class, decl.type, name,
2460 (int) $2, false, decl.param_list, (Attributes) $1,
2461 get_block, set_block);
2463 if (RootContext.Documentation != null)
2464 indexer.DocComment = ConsumeStoredComment ();
2466 current_container.AddIndexer (indexer);
2468 current_local_parameters = null;
2469 implicit_value_parameter_type = null;
2470 indexer_parameters = null;
2475 : type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2477 Parameters pars = (Parameters) $4;
2478 if (pars.HasArglist) {
2479 // "__arglist is not valid in this context"
2480 Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
2481 } else if (pars.Empty){
2482 Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
2484 if (RootContext.Documentation != null) {
2485 tmpComment = Lexer.consume_doc_comment ();
2486 Lexer.doc_state = XmlCommentState.Allowed;
2489 $$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
2491 | type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
2493 Parameters pars = (Parameters) $6;
2495 if (pars.HasArglist) {
2496 // "__arglist is not valid in this context"
2497 Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
2498 } else if (pars.Empty){
2499 Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
2502 MemberName name = (MemberName) $2;
2503 $$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);
2505 if (RootContext.Documentation != null) {
2506 tmpComment = Lexer.consume_doc_comment ();
2507 Lexer.doc_state = XmlCommentState.Allowed;
2518 if (RootContext.Documentation != null)
2519 enumTypeComment = Lexer.consume_doc_comment ();
2524 LocatedToken lt = (LocatedToken) $5;
2525 Location enum_location = lt.Location;
2528 Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
2529 break; // assumes that the parser put us in a switch
2532 MemberName name = MakeName (new MemberName (lt.Value, enum_location));
2533 Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
2534 name, (Attributes) $1);
2536 if (RootContext.Documentation != null)
2537 e.DocComment = enumTypeComment;
2540 EnumMember em = null;
2541 foreach (VariableDeclaration ev in (ArrayList) $8) {
2542 em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
2543 new MemberName (ev.identifier, ev.Location), ev.OptAttributes);
2545 // if (RootContext.Documentation != null)
2546 em.DocComment = ev.DocComment;
2548 e.AddEnumMember (em);
2551 current_container.AddEnum (e);
2558 : /* empty */ { $$ = TypeManager.system_int32_expr; }
2559 | COLON type { $$ = $2; }
2565 if (RootContext.Documentation != null)
2566 Lexer.doc_state = XmlCommentState.Allowed;
2568 opt_enum_member_declarations
2570 // here will be evaluated after CLOSE_BLACE is consumed.
2571 if (RootContext.Documentation != null)
2572 Lexer.doc_state = XmlCommentState.Allowed;
2580 opt_enum_member_declarations
2581 : /* empty */ { $$ = new ArrayList (4); }
2582 | enum_member_declarations opt_comma { $$ = $1; }
2585 enum_member_declarations
2586 : enum_member_declaration
2588 ArrayList l = new ArrayList (4);
2593 | enum_member_declarations COMMA enum_member_declaration
2595 ArrayList l = (ArrayList) $1;
2603 enum_member_declaration
2604 : opt_attributes IDENTIFIER
2606 VariableDeclaration vd = new VariableDeclaration (
2607 (LocatedToken) $2, null, (Attributes) $1);
2609 if (RootContext.Documentation != null) {
2610 vd.DocComment = Lexer.consume_doc_comment ();
2611 Lexer.doc_state = XmlCommentState.Allowed;
2616 | opt_attributes IDENTIFIER
2618 if (RootContext.Documentation != null) {
2619 tmpComment = Lexer.consume_doc_comment ();
2620 Lexer.doc_state = XmlCommentState.NotAllowed;
2625 VariableDeclaration vd = new VariableDeclaration (
2626 (LocatedToken) $2, $5, (Attributes) $1);
2628 if (RootContext.Documentation != null)
2629 vd.DocComment = ConsumeStoredComment ();
2635 delegate_declaration
2640 lexer.ConstraintsParsing = true;
2643 OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
2645 MemberName name = MakeName ((MemberName) $6);
2646 Parameters p = (Parameters) $8;
2648 // TODO: wrong location
2649 Report.Error (1669, name.Location, "__arglist is not valid in this context");
2652 Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
2653 (int) $2, name, p, (Attributes) $1);
2655 if (RootContext.Documentation != null) {
2656 del.DocComment = Lexer.consume_doc_comment ();
2657 Lexer.doc_state = XmlCommentState.Allowed;
2660 current_container.AddDelegate (del);
2661 current_delegate = del;
2663 opt_type_parameter_constraints_clauses
2665 lexer.ConstraintsParsing = false;
2669 current_delegate.SetParameterInfo ((ArrayList) $11);
2670 $$ = current_delegate;
2672 current_delegate = null;
2679 lexer.CheckNullable (false);
2684 lexer.CheckNullable (true);
2689 namespace_or_type_name
2691 | IDENTIFIER DOUBLE_COLON IDENTIFIER {
2692 LocatedToken lt1 = (LocatedToken) $1;
2693 LocatedToken lt2 = (LocatedToken) $3;
2694 $$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
2696 | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
2697 LocatedToken lt = (LocatedToken) $3;
2698 $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
2703 : IDENTIFIER opt_type_argument_list {
2704 LocatedToken lt = (LocatedToken) $1;
2705 $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
2709 opt_type_argument_list
2710 : /* empty */ { $$ = null; }
2711 | OP_GENERICS_LT type_arguments OP_GENERICS_GT
2714 if (RootContext.Version == LanguageVersion.ISO_1)
2715 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2719 $$ = new TypeArguments ((int) $1, lexer.Location);
2720 if (RootContext.Version == LanguageVersion.ISO_1)
2721 Report.FeatureIsNotStandardized (lexer.Location, "generics");
2726 : opt_attributes type {
2727 TypeArguments type_args = new TypeArguments (lexer.Location);
2729 SimpleName sn = $2 as SimpleName;
2731 Report.Error (1031, lexer.Location, "Type expected");
2733 $2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
2735 type_args.Add ((Expression) $2);
2738 | type_arguments COMMA opt_attributes type {
2739 TypeArguments type_args = (TypeArguments) $1;
2741 SimpleName sn = $4 as SimpleName;
2743 Report.Error (1031, lexer.Location, "Type expected");
2745 $4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
2747 type_args.Add ((Expression) $4);
2754 * Before you think of adding a return_type, notice that we have been
2755 * using two rules in the places where it matters (one rule using type
2756 * and another identical one that uses VOID as the return type). This
2757 * gets rid of a shift/reduce couple
2760 : namespace_or_type_name opt_nullable
2762 MemberName name = (MemberName) $1;
2763 $$ = name.GetTypeExpression ();
2766 $$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
2768 | builtin_types opt_nullable
2771 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2781 // Note that here only unmanaged types are allowed but we
2782 // can't perform checks during this phase - we do it during
2783 // semantic analysis.
2785 $$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
2789 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
2794 : builtin_types opt_nullable
2797 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
2799 | non_expression_type rank_specifier
2801 Location loc = GetLocation ($1);
2803 loc = lexer.Location;
2804 $$ = new ComposedCast ((Expression) $1, (string) $2, loc);
2806 | non_expression_type STAR
2808 Location loc = GetLocation ($1);
2810 loc = lexer.Location;
2811 $$ = new ComposedCast ((Expression) $1, "*", loc);
2813 | expression rank_specifiers
2815 $$ = new ComposedCast ((Expression) $1, (string) $2);
2819 $$ = new ComposedCast ((Expression) $1, "*");
2823 // We need this because the parser will happily go and reduce IDENTIFIER STAR
2824 // through this different path
2826 | multiplicative_expression STAR
2828 $$ = new ComposedCast ((Expression) $1, "*");
2835 ArrayList types = new ArrayList (4);
2840 | type_list COMMA type
2842 ArrayList types = (ArrayList) $1;
2850 * replaces all the productions for isolating the various
2851 * simple types, but we need this to reuse it easily in local_variable_type
2854 : OBJECT { $$ = TypeManager.system_object_expr; }
2855 | STRING { $$ = TypeManager.system_string_expr; }
2856 | BOOL { $$ = TypeManager.system_boolean_expr; }
2857 | DECIMAL { $$ = TypeManager.system_decimal_expr; }
2858 | FLOAT { $$ = TypeManager.system_single_expr; }
2859 | DOUBLE { $$ = TypeManager.system_double_expr; }
2864 : SBYTE { $$ = TypeManager.system_sbyte_expr; }
2865 | BYTE { $$ = TypeManager.system_byte_expr; }
2866 | SHORT { $$ = TypeManager.system_int16_expr; }
2867 | USHORT { $$ = TypeManager.system_uint16_expr; }
2868 | INT { $$ = TypeManager.system_int32_expr; }
2869 | UINT { $$ = TypeManager.system_uint32_expr; }
2870 | LONG { $$ = TypeManager.system_int64_expr; }
2871 | ULONG { $$ = TypeManager.system_uint64_expr; }
2872 | CHAR { $$ = TypeManager.system_char_expr; }
2873 | VOID { $$ = TypeManager.system_void_expr; }
2877 : type rank_specifiers opt_nullable
2879 string rank_specifiers = (string) $2;
2881 rank_specifiers += "?";
2883 $$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
2888 // Expressions, section 7.5
2897 MemberName mn = (MemberName) $1;
2898 $$ = mn.GetTypeExpression ();
2900 | IDENTIFIER DOUBLE_COLON IDENTIFIER
2902 LocatedToken lt1 = (LocatedToken) $1;
2903 LocatedToken lt2 = (LocatedToken) $3;
2904 $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
2906 | parenthesized_expression
2907 | default_value_expression
2909 | invocation_expression
2913 | post_increment_expression
2914 | post_decrement_expression
2918 | checked_expression
2919 | unchecked_expression
2920 | pointer_member_access
2921 | anonymous_method_expression
2928 | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
2929 | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); }
2930 | NULL { $$ = new NullLiteral (lexer.Location); }
2934 : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
2935 | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
2936 | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
2941 object v = lexer.Value;
2944 $$ = new IntLiteral ((int) v, lexer.Location);
2945 } else if (v is uint)
2946 $$ = new UIntLiteral ((UInt32) v, lexer.Location);
2948 $$ = new LongLiteral ((Int64) v, lexer.Location);
2949 else if (v is ulong)
2950 $$ = new ULongLiteral ((UInt64) v, lexer.Location);
2952 Console.WriteLine ("OOPS. Unexpected result from scanner");
2957 : TRUE { $$ = new BoolLiteral (true, lexer.Location); }
2958 | FALSE { $$ = new BoolLiteral (false, lexer.Location); }
2961 parenthesized_expression_0
2962 : OPEN_PARENS expression CLOSE_PARENS
2965 lexer.Deambiguate_CloseParens ();
2966 // After this, the next token returned is one of
2967 // CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
2968 // or CLOSE_PARENS_MINUS.
2970 | OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
2973 parenthesized_expression
2974 : parenthesized_expression_0 CLOSE_PARENS_NO_CAST
2978 | parenthesized_expression_0 CLOSE_PARENS_MINUS
2980 // If a parenthesized expression is followed by a minus, we need to wrap
2981 // the expression inside a ParenthesizedExpression for the CS0075 check
2982 // in Binary.DoResolve().
2983 $$ = new ParenthesizedExpression ((Expression) $1);
2988 : primary_expression DOT IDENTIFIER opt_type_argument_list
2990 LocatedToken lt = (LocatedToken) $3;
2991 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4);
2993 | predefined_type DOT IDENTIFIER opt_type_argument_list
2995 LocatedToken lt = (LocatedToken) $3;
2996 $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4);
3004 invocation_expression
3005 : primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
3008 Report.Error (1, (Location) $2, "Parse error");
3010 $$ = new Invocation ((Expression) $1, (ArrayList) $3);
3012 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
3014 $$ = new Invocation ((Expression) $1, new ArrayList ());
3016 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
3018 $$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
3020 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
3022 ArrayList args = new ArrayList (1);
3024 $$ = new Invocation ((Expression) $1, args);
3026 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
3028 ArrayList args = ((ArrayList) $4);
3030 $$ = new Invocation ((Expression) $1, args);
3035 : /* empty */ { $$ = null; }
3042 ArrayList list = new ArrayList (4);
3046 | argument_list COMMA argument
3048 ArrayList list = (ArrayList) $1;
3052 | argument_list error {
3053 CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
3061 $$ = new Argument ((Expression) $1, Argument.AType.Expression);
3063 | non_simple_argument
3070 : REF variable_reference
3072 $$ = new Argument ((Expression) $2, Argument.AType.Ref);
3074 | OUT variable_reference
3076 $$ = new Argument ((Expression) $2, Argument.AType.Out);
3078 | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
3080 ArrayList list = (ArrayList) $3;
3081 Argument[] args = new Argument [list.Count];
3082 list.CopyTo (args, 0);
3084 Expression expr = new Arglist (args, (Location) $1);
3085 $$ = new Argument (expr, Argument.AType.Expression);
3089 $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
3094 : expression { note ("section 5.4"); $$ = $1; }
3098 : primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET
3100 $$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
3102 | primary_expression rank_specifiers
3104 // So the super-trick is that primary_expression
3105 // can only be either a SimpleName or a MemberAccess.
3106 // The MemberAccess case arises when you have a fully qualified type-name like :
3108 // SimpleName is when you have
3111 Expression expr = (Expression) $1;
3112 if (expr is ComposedCast){
3113 $$ = new ComposedCast (expr, (string) $2);
3114 } else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
3115 Error_ExpectingTypeName (expr);
3116 $$ = TypeManager.system_object_expr;
3119 // So we extract the string corresponding to the SimpleName
3122 $$ = new ComposedCast (expr, (string) $2);
3124 current_array_type = (Expression)$$;
3131 ArrayList list = new ArrayList (4);
3135 | expression_list COMMA expression
3137 ArrayList list = (ArrayList) $1;
3146 $$ = new This (current_block, (Location) $1);
3151 : BASE DOT IDENTIFIER opt_type_argument_list
3153 LocatedToken lt = (LocatedToken) $3;
3154 $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location);
3156 | BASE OPEN_BRACKET expression_list CLOSE_BRACKET
3158 $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
3161 Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
3166 post_increment_expression
3167 : primary_expression OP_INC
3169 $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
3170 (Expression) $1, (Location) $2);
3174 post_decrement_expression
3175 : primary_expression OP_DEC
3177 $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
3178 (Expression) $1, (Location) $2);
3183 : object_or_delegate_creation_expression
3184 | array_creation_expression
3187 object_or_delegate_creation_expression
3188 : NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
3190 $$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
3194 array_creation_expression
3195 : NEW type OPEN_BRACKET expression_list CLOSE_BRACKET
3197 opt_array_initializer
3199 $$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
3201 | NEW type rank_specifiers array_initializer
3203 $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
3207 Report.Error (1031, (Location) $1, "Type expected");
3212 Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
3228 opt_rank_specifier_or_nullable
3237 | opt_nullable rank_specifiers
3244 | opt_nullable rank_specifiers INTERR
3247 $$ = "?" + $2 + "?";
3254 : rank_specifier opt_rank_specifier
3256 $$ = (string) $2 + (string) $1;
3261 : OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
3263 $$ = "[" + (string) $2 + "]";
3283 | dim_separators COMMA
3285 $$ = (string) $1 + ",";
3289 opt_array_initializer
3301 : OPEN_BRACE CLOSE_BRACE
3303 ArrayList list = new ArrayList (4);
3306 | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
3308 $$ = (ArrayList) $2;
3312 variable_initializer_list
3313 : variable_initializer
3315 ArrayList list = new ArrayList (4);
3319 | variable_initializer_list COMMA variable_initializer
3321 ArrayList list = (ArrayList) $1;
3330 pushed_current_array_type = current_array_type;
3331 lexer.TypeOfParsing = true;
3333 OPEN_PARENS type CLOSE_PARENS
3335 lexer.TypeOfParsing = false;
3336 Expression type = (Expression)$4;
3337 if (type == TypeManager.system_void_expr)
3338 $$ = new TypeOfVoid ((Location) $1);
3340 $$ = new TypeOf (type, (Location) $1);
3341 current_array_type = pushed_current_array_type;
3346 : SIZEOF OPEN_PARENS type CLOSE_PARENS {
3347 $$ = new SizeOf ((Expression) $3, (Location) $1);
3352 : CHECKED OPEN_PARENS expression CLOSE_PARENS
3354 $$ = new CheckedExpr ((Expression) $3, (Location) $1);
3358 unchecked_expression
3359 : UNCHECKED OPEN_PARENS expression CLOSE_PARENS
3361 $$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
3365 pointer_member_access
3366 : primary_expression OP_PTR IDENTIFIER
3369 LocatedToken lt = (LocatedToken) $3;
3371 deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
3372 $$ = new MemberAccess (deref, lt.Value);
3376 anonymous_method_expression
3377 : DELEGATE opt_anonymous_method_signature
3379 if (oob_stack == null)
3380 oob_stack = new Stack (6);
3382 oob_stack.Push (current_anonymous_method);
3383 oob_stack.Push (current_local_parameters);
3384 current_local_parameters = (Parameters)$2;
3386 // Force the next block to be created as a ToplevelBlock
3387 oob_stack.Push (current_block);
3388 oob_stack.Push (top_current_block);
3389 current_block = null;
3391 Location loc = (Location) $1;
3392 current_anonymous_method = new AnonymousMethodExpression (
3393 current_anonymous_method, current_generic_method, current_container,
3394 (Parameters) $2, (ToplevelBlock) top_current_block, loc);
3398 Location loc = (Location) $1;
3399 top_current_block = (Block) oob_stack.Pop ();
3400 current_block = (Block) oob_stack.Pop ();
3401 if (RootContext.Version == LanguageVersion.ISO_1){
3402 Report.FeatureIsNotStandardized (loc, "anonymous methods");
3405 ToplevelBlock anon_block = (ToplevelBlock) $4;
3407 anon_block.Parent = current_block;
3409 Report.Debug (64, "PARSER", anon_block, current_anonymous_method, anonymous_host,
3412 current_anonymous_method.Block = anon_block;
3413 if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
3414 anonymous_host.AddAnonymousMethod (current_anonymous_method);
3416 $$ = current_anonymous_method;
3419 current_local_parameters = (Parameters) oob_stack.Pop ();
3420 current_anonymous_method = (AnonymousMethodExpression) oob_stack.Pop ();
3424 opt_anonymous_method_signature
3425 : /* empty */ { $$ = null; }
3426 | anonymous_method_signature
3429 anonymous_method_signature
3430 : OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS
3433 $$ = Parameters.EmptyReadOnlyParameters;
3435 ArrayList par_list = (ArrayList) $2;
3436 Parameter [] pars = new Parameter [par_list.Count];
3437 par_list.CopyTo (pars);
3438 $$ = new Parameters (pars);
3443 opt_anonymous_method_parameter_list
3444 : /* empty */ { $$ = null; }
3445 | anonymous_method_parameter_list { $$ = $1; }
3448 anonymous_method_parameter_list
3449 : anonymous_method_parameter
3451 ArrayList a = new ArrayList (4);
3455 | anonymous_method_parameter_list COMMA anonymous_method_parameter
3457 ArrayList a = (ArrayList) $1;
3463 anonymous_method_parameter
3464 : opt_parameter_modifier type IDENTIFIER {
3465 LocatedToken lt = (LocatedToken) $3;
3466 $$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
3468 | PARAMS type IDENTIFIER {
3469 Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
3474 default_value_expression
3475 : DEFAULT_OPEN_PARENS type CLOSE_PARENS
3477 $$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
3482 : primary_expression
3483 | BANG prefixed_unary_expression
3485 $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
3487 | TILDE prefixed_unary_expression
3489 $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
3495 : parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
3497 $$ = new Cast ((Expression) $1, (Expression) $3);
3499 | parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
3501 $$ = new Cast ((Expression) $1, (Expression) $3);
3507 | OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
3509 // TODO: wrong location
3510 $$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
3515 // The idea to split this out is from Rhys' grammar
3516 // to solve the problem with casts.
3518 prefixed_unary_expression
3520 | PLUS prefixed_unary_expression
3522 $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
3524 | MINUS prefixed_unary_expression
3526 $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
3528 | OP_INC prefixed_unary_expression
3530 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3531 (Expression) $2, (Location) $1);
3533 | OP_DEC prefixed_unary_expression
3535 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3536 (Expression) $2, (Location) $1);
3538 | STAR prefixed_unary_expression
3540 $$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
3542 | BITWISE_AND prefixed_unary_expression
3544 $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
3548 pre_increment_expression
3549 : OP_INC prefixed_unary_expression
3551 $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
3552 (Expression) $2, (Location) $1);
3556 pre_decrement_expression
3557 : OP_DEC prefixed_unary_expression
3559 $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
3560 (Expression) $2, (Location) $1);
3564 multiplicative_expression
3565 : prefixed_unary_expression
3566 | multiplicative_expression STAR prefixed_unary_expression
3568 $$ = new Binary (Binary.Operator.Multiply,
3569 (Expression) $1, (Expression) $3);
3571 | multiplicative_expression DIV prefixed_unary_expression
3573 $$ = new Binary (Binary.Operator.Division,
3574 (Expression) $1, (Expression) $3);
3576 | multiplicative_expression PERCENT prefixed_unary_expression
3578 $$ = new Binary (Binary.Operator.Modulus,
3579 (Expression) $1, (Expression) $3);
3584 : multiplicative_expression
3585 | additive_expression PLUS multiplicative_expression
3587 $$ = new Binary (Binary.Operator.Addition,
3588 (Expression) $1, (Expression) $3);
3590 | additive_expression MINUS multiplicative_expression
3592 $$ = new Binary (Binary.Operator.Subtraction,
3593 (Expression) $1, (Expression) $3);
3598 : additive_expression
3599 | shift_expression OP_SHIFT_LEFT additive_expression
3601 $$ = new Binary (Binary.Operator.LeftShift,
3602 (Expression) $1, (Expression) $3);
3604 | shift_expression OP_SHIFT_RIGHT additive_expression
3606 $$ = new Binary (Binary.Operator.RightShift,
3607 (Expression) $1, (Expression) $3);
3618 lexer.PutbackNullable ();
3623 nullable_type_or_conditional
3626 if (((bool) $2) && ($1 is ComposedCast))
3627 $$ = ((ComposedCast) $1).RemoveNullable ();
3633 relational_expression
3635 | relational_expression OP_LT shift_expression
3637 $$ = new Binary (Binary.Operator.LessThan,
3638 (Expression) $1, (Expression) $3);
3640 | relational_expression OP_GT shift_expression
3642 $$ = new Binary (Binary.Operator.GreaterThan,
3643 (Expression) $1, (Expression) $3);
3645 | relational_expression OP_LE shift_expression
3647 $$ = new Binary (Binary.Operator.LessThanOrEqual,
3648 (Expression) $1, (Expression) $3);
3650 | relational_expression OP_GE shift_expression
3652 $$ = new Binary (Binary.Operator.GreaterThanOrEqual,
3653 (Expression) $1, (Expression) $3);
3655 | relational_expression IS
3658 } nullable_type_or_conditional
3660 $$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
3662 | relational_expression AS
3665 } nullable_type_or_conditional
3667 $$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
3672 : relational_expression
3673 | equality_expression OP_EQ relational_expression
3675 $$ = new Binary (Binary.Operator.Equality,
3676 (Expression) $1, (Expression) $3);
3678 | equality_expression OP_NE relational_expression
3680 $$ = new Binary (Binary.Operator.Inequality,
3681 (Expression) $1, (Expression) $3);
3686 : equality_expression
3687 | and_expression BITWISE_AND equality_expression
3689 $$ = new Binary (Binary.Operator.BitwiseAnd,
3690 (Expression) $1, (Expression) $3);
3694 exclusive_or_expression
3696 | exclusive_or_expression CARRET and_expression
3698 $$ = new Binary (Binary.Operator.ExclusiveOr,
3699 (Expression) $1, (Expression) $3);
3703 inclusive_or_expression
3704 : exclusive_or_expression
3705 | inclusive_or_expression BITWISE_OR exclusive_or_expression
3707 $$ = new Binary (Binary.Operator.BitwiseOr,
3708 (Expression) $1, (Expression) $3);
3712 conditional_and_expression
3713 : inclusive_or_expression
3714 | conditional_and_expression OP_AND inclusive_or_expression
3716 $$ = new Binary (Binary.Operator.LogicalAnd,
3717 (Expression) $1, (Expression) $3);
3721 conditional_or_expression
3722 : conditional_and_expression
3723 | conditional_or_expression OP_OR conditional_and_expression
3725 $$ = new Binary (Binary.Operator.LogicalOr,
3726 (Expression) $1, (Expression) $3);
3730 conditional_expression
3731 : conditional_or_expression
3732 | conditional_or_expression INTERR expression COLON expression
3734 $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
3736 | conditional_or_expression INTERR INTERR expression
3738 $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
3740 // We'll be resolved into a `parenthesized_expression_0' later on.
3741 | conditional_or_expression INTERR CLOSE_PARENS
3743 $$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
3744 lexer.PutbackCloseParens ();
3748 assignment_expression
3749 : prefixed_unary_expression ASSIGN expression
3751 $$ = new Assign ((Expression) $1, (Expression) $3);
3753 | prefixed_unary_expression OP_MULT_ASSIGN expression
3755 $$ = new CompoundAssign (
3756 Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
3758 | prefixed_unary_expression OP_DIV_ASSIGN expression
3760 $$ = new CompoundAssign (
3761 Binary.Operator.Division, (Expression) $1, (Expression) $3);
3763 | prefixed_unary_expression OP_MOD_ASSIGN expression
3765 $$ = new CompoundAssign (
3766 Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
3768 | prefixed_unary_expression OP_ADD_ASSIGN expression
3770 $$ = new CompoundAssign (
3771 Binary.Operator.Addition, (Expression) $1, (Expression) $3);
3773 | prefixed_unary_expression OP_SUB_ASSIGN expression
3775 $$ = new CompoundAssign (
3776 Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
3778 | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
3780 $$ = new CompoundAssign (
3781 Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
3783 | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
3785 $$ = new CompoundAssign (
3786 Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
3788 | prefixed_unary_expression OP_AND_ASSIGN expression
3790 $$ = new CompoundAssign (
3791 Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
3793 | prefixed_unary_expression OP_OR_ASSIGN expression
3795 $$ = new CompoundAssign (
3796 Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
3798 | prefixed_unary_expression OP_XOR_ASSIGN expression
3800 $$ = new CompoundAssign (
3801 Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
3806 : conditional_expression
3807 | assignment_expression
3827 lexer.ConstraintsParsing = true;
3831 MemberName name = MakeName ((MemberName) $6);
3832 int mod_flags = (int) $2;
3834 push_current_class (new Class (
3835 current_namespace, current_class, name,
3836 mod_flags, (Attributes) $1), false, $3);
3839 opt_type_parameter_constraints_clauses
3841 lexer.ConstraintsParsing = false;
3844 if (current_class.Name == "System.Object") {
3845 Report.Error (537, current_class.Location,
3846 "The class System.Object cannot have a base " +
3847 "class or implement an interface.");
3849 current_container.AddBasesForPart (current_class, (ArrayList) $8);
3852 current_class.SetParameterInfo ((ArrayList) $9);
3854 if (RootContext.Documentation != null) {
3855 current_container.DocComment = Lexer.consume_doc_comment ();
3856 Lexer.doc_state = XmlCommentState.Allowed;
3861 if (RootContext.Documentation != null)
3862 Lexer.doc_state = XmlCommentState.Allowed;
3866 $$ = pop_current_class ();
3874 { $$ = $1; } // location
3878 : /* empty */ { $$ = (int) 0; }
3884 | modifiers modifier
3889 if ((m1 & m2) != 0) {
3890 Location l = lexer.Location;
3891 Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
3893 $$ = (int) (m1 | m2);
3898 : NEW { $$ = Modifiers.NEW; }
3899 | PUBLIC { $$ = Modifiers.PUBLIC; }
3900 | PROTECTED { $$ = Modifiers.PROTECTED; }
3901 | INTERNAL { $$ = Modifiers.INTERNAL; }
3902 | PRIVATE { $$ = Modifiers.PRIVATE; }
3903 | ABSTRACT { $$ = Modifiers.ABSTRACT; }
3904 | SEALED { $$ = Modifiers.SEALED; }
3905 | STATIC { $$ = Modifiers.STATIC; }
3906 | READONLY { $$ = Modifiers.READONLY; }
3907 | VIRTUAL { $$ = Modifiers.VIRTUAL; }
3908 | OVERRIDE { $$ = Modifiers.OVERRIDE; }
3909 | EXTERN { $$ = Modifiers.EXTERN; }
3910 | VOLATILE { $$ = Modifiers.VOLATILE; }
3911 | UNSAFE { $$ = Modifiers.UNSAFE; }
3915 : /* empty */ { $$ = null; }
3916 | class_base { $$ = $1; }
3920 : COLON type_list { $$ = $2; }
3923 opt_type_parameter_constraints_clauses
3924 : /* empty */ { $$ = null; }
3925 | type_parameter_constraints_clauses
3929 type_parameter_constraints_clauses
3930 : type_parameter_constraints_clause {
3931 ArrayList constraints = new ArrayList (1);
3932 constraints.Add ($1);
3935 | type_parameter_constraints_clauses type_parameter_constraints_clause {
3936 ArrayList constraints = (ArrayList) $1;
3937 Constraints new_constraint = (Constraints)$2;
3939 foreach (Constraints c in constraints) {
3940 if (new_constraint.TypeParameter == c.TypeParameter) {
3941 Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'",
3942 new_constraint.TypeParameter);
3946 constraints.Add (new_constraint);
3951 type_parameter_constraints_clause
3952 : WHERE IDENTIFIER COLON type_parameter_constraints {
3953 LocatedToken lt = (LocatedToken) $2;
3954 $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
3958 type_parameter_constraints
3959 : type_parameter_constraint {
3960 ArrayList constraints = new ArrayList (1);
3961 constraints.Add ($1);
3964 | type_parameter_constraints COMMA type_parameter_constraint {
3965 ArrayList constraints = (ArrayList) $1;
3967 constraints.Add ($3);
3972 type_parameter_constraint
3974 | NEW OPEN_PARENS CLOSE_PARENS {
3975 $$ = SpecialConstraint.Constructor;
3978 $$ = SpecialConstraint.ReferenceType;
3981 $$ = SpecialConstraint.ValueType;
3990 // A block is "contained" on the following places:
3992 // property_declaration as part of the accessor body (get/set)
3993 // operator_declaration
3994 // constructor_declaration
3995 // destructor_declaration
3996 // event_declaration as part of add_accessor_declaration or remove_accessor_declaration
4001 if (current_block == null){
4002 current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters,
4003 current_generic_method, (Location) $1);
4004 top_current_block = current_block;
4006 current_block = new Block (current_block, (Location) $1, Location.Null);
4009 opt_statement_list CLOSE_BRACE
4011 while (current_block.Implicit)
4012 current_block = current_block.Parent;
4014 current_block.SetEndLocation ((Location) $4);
4015 current_block = current_block.Parent;
4016 if (current_block == null)
4017 top_current_block = null;
4028 | statement_list statement
4032 : declaration_statement
4034 if ($1 != null && (Block) $1 != current_block){
4035 current_block.AddStatement ((Statement) $1);
4036 current_block = (Block) $1;
4039 | valid_declaration_statement
4041 current_block.AddStatement ((Statement) $1);
4046 valid_declaration_statement
4049 | expression_statement
4050 | selection_statement
4051 | iteration_statement
4055 | unchecked_statement
4063 : valid_declaration_statement
4064 | declaration_statement
4066 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4071 Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
4079 $$ = EmptyStatement.Value;
4086 LocatedToken lt = (LocatedToken) $1;
4087 LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);
4089 if (current_block.AddLabel (labeled))
4090 current_block.AddStatement (labeled);
4095 declaration_statement
4096 : local_variable_declaration SEMICOLON
4098 current_array_type = null;
4100 DictionaryEntry de = (DictionaryEntry) $1;
4101 Expression e = (Expression) de.Key;
4103 $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
4107 | local_constant_declaration SEMICOLON
4109 current_array_type = null;
4111 DictionaryEntry de = (DictionaryEntry) $1;
4113 $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
4119 * The following is from Rhys' grammar:
4120 * > Types in local variable declarations must be recognized as
4121 * > expressions to prevent reduce/reduce errors in the grammar.
4122 * > The expressions are converted into types during semantic analysis.
4125 : primary_expression opt_rank_specifier_or_nullable
4127 // FIXME: Do something smart here regarding the composition of the type.
4129 // Ok, the above "primary_expression" is there to get rid of
4130 // both reduce/reduce and shift/reduces in the grammar, it should
4131 // really just be "type_name". If you use type_name, a reduce/reduce
4132 // creeps up. If you use namespace_or_type_name (which is all we need
4133 // really) two shift/reduces appear.
4136 // So the super-trick is that primary_expression
4137 // can only be either a SimpleName or a MemberAccess.
4138 // The MemberAccess case arises when you have a fully qualified type-name like :
4140 // SimpleName is when you have
4143 Expression expr = (Expression) $1;
4144 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4145 Error_ExpectingTypeName (expr);
4149 // So we extract the string corresponding to the SimpleName
4153 if ((string) $2 == "")
4156 $$ = new ComposedCast ((Expression) $1, (string) $2);
4159 | builtin_types opt_rank_specifier_or_nullable
4161 if ((string) $2 == "")
4164 $$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
4168 local_variable_pointer_type
4169 : primary_expression STAR
4171 Expression expr = (Expression) $1;
4173 if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
4174 Error_ExpectingTypeName (expr);
4178 $$ = new ComposedCast ((Expression) $1, "*");
4180 | builtin_types STAR
4182 $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
4186 $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
4188 | local_variable_pointer_type STAR
4190 $$ = new ComposedCast ((Expression) $1, "*");
4194 local_variable_declaration
4195 : local_variable_type variable_declarators
4198 $$ = new DictionaryEntry ($1, $2);
4202 | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
4207 if ((string) $2 == "")
4208 t = (Expression) $1;
4210 t = new ComposedCast ((Expression) $1, (string) $2);
4211 $$ = new DictionaryEntry (t, $3);
4217 local_constant_declaration
4218 : CONST local_variable_type constant_declarators
4221 $$ = new DictionaryEntry ($2, $3);
4227 expression_statement
4228 : statement_expression SEMICOLON { $$ = $1; }
4232 // We have to do the wrapping here and not in the case above,
4233 // because statement_expression is used for example in for_statement
4235 statement_expression
4238 Expression expr = (Expression) $1;
4239 ExpressionStatement s = expr as ExpressionStatement;
4241 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
4244 $$ = new StatementExpression (s);
4248 Report.Error (1002, GetLocation ($1), "Expecting `;'");
4253 object_creation_expression
4254 : object_or_delegate_creation_expression
4255 { note ("complain if this is a delegate maybe?"); }
4264 : IF OPEN_PARENS boolean_expression CLOSE_PARENS
4267 Location l = (Location) $1;
4269 $$ = new If ((Expression) $3, (Statement) $5, l);
4271 // FIXME: location for warning should be loc property of $5.
4272 if ($5 == EmptyStatement.Value)
4273 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4276 | IF OPEN_PARENS boolean_expression CLOSE_PARENS
4277 embedded_statement ELSE embedded_statement
4279 Location l = (Location) $1;
4281 $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);
4283 // FIXME: location for warning should be loc property of $5 and $7.
4284 if ($5 == EmptyStatement.Value)
4285 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4286 if ($7 == EmptyStatement.Value)
4287 Report.Warning (642, 3, l, "Possible mistaken empty statement");
4292 : SWITCH OPEN_PARENS
4294 if (switch_stack == null)
4295 switch_stack = new Stack (2);
4296 switch_stack.Push (current_block);
4298 expression CLOSE_PARENS
4301 $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
4302 current_block = (Block) switch_stack.Pop ();
4318 Report.Error (1522, lexer.Location, "Empty switch block");
4326 ArrayList sections = new ArrayList (4);
4331 | switch_sections switch_section
4333 ArrayList sections = (ArrayList) $1;
4343 current_block = current_block.CreateSwitchBlock (lexer.Location);
4347 Block topmost = current_block;
4349 while (topmost.Implicit)
4350 topmost = topmost.Parent;
4351 $$ = new SwitchSection ((ArrayList) $1, topmost);
4358 ArrayList labels = new ArrayList (4);
4363 | switch_labels switch_label
4365 ArrayList labels = (ArrayList) ($1);
4373 : CASE constant_expression COLON { $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
4374 | DEFAULT COLON { $$ = new SwitchLabel (null, (Location) $2); }
4377 1523, GetLocation ($1),
4378 "The keyword case or default must precede code in switch block");
4390 : WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
4392 Location l = (Location) $1;
4393 $$ = new While ((Expression) $3, (Statement) $5, l);
4398 : DO embedded_statement
4399 WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
4401 Location l = (Location) $1;
4403 $$ = new Do ((Statement) $2, (Expression) $5, l);
4409 opt_for_initializer SEMICOLON
4411 Block assign_block = new Block (current_block);
4412 current_block = assign_block;
4414 if ($3 is DictionaryEntry){
4415 DictionaryEntry de = (DictionaryEntry) $3;
4417 Expression type = (Expression) de.Key;
4418 ArrayList var_declarators = (ArrayList) de.Value;
4420 foreach (VariableDeclaration decl in var_declarators){
4424 vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4428 Location l = lexer.Location;
4429 Expression expr = decl.expression_or_array_initializer;
4431 LocalVariableReference var;
4432 var = new LocalVariableReference (assign_block, decl.identifier, l);
4435 Assign a = new Assign (var, expr, decl.Location);
4437 assign_block.AddStatement (new StatementExpression (a));
4441 // Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
4442 // This can be referred to as $5 below.
4448 opt_for_condition SEMICOLON
4449 opt_for_iterator CLOSE_PARENS
4452 Location l = (Location) $1;
4454 For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);
4456 current_block.AddStatement (f);
4457 while (current_block.Implicit)
4458 current_block = current_block.Parent;
4460 current_block = current_block.Parent;
4465 : /* empty */ { $$ = EmptyStatement.Value; }
4470 : local_variable_declaration
4471 | statement_expression_list
4475 : /* empty */ { $$ = null; }
4476 | boolean_expression
4480 : /* empty */ { $$ = EmptyStatement.Value; }
4485 : statement_expression_list
4488 statement_expression_list
4489 : statement_expression
4491 // CHANGE: was `null'
4492 Statement s = (Statement) $1;
4493 Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);
4498 | statement_expression_list COMMA statement_expression
4500 Block b = (Block) $1;
4502 b.AddStatement ((Statement) $3);
4508 : FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
4510 Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
4513 | FOREACH OPEN_PARENS type IDENTIFIER IN
4514 expression CLOSE_PARENS
4516 Block foreach_block = new Block (current_block);
4517 current_block = foreach_block;
4519 LocatedToken lt = (LocatedToken) $4;
4520 Location l = lt.Location;
4523 vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
4525 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
4527 // Get a writable reference to this read-only variable.
4529 // Note that the $$ here refers to the value of _this_ code block,
4530 // not the value of the LHS non-terminal. This can be referred to as $8 below.
4531 $$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
4538 LocalVariableReference v = (LocalVariableReference) $8;
4539 Location l = (Location) $1;
4542 Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
4543 current_block.AddStatement (f);
4546 while (current_block.Implicit)
4547 current_block = current_block.Parent;
4549 current_block = current_block.Parent;
4555 | continue_statement
4565 $$ = new Break ((Location) $1);
4570 : CONTINUE SEMICOLON
4572 $$ = new Continue ((Location) $1);
4577 : GOTO IDENTIFIER SEMICOLON
4579 LocatedToken lt = (LocatedToken) $2;
4580 $$ = new Goto (lt.Value, lt.Location);
4582 | GOTO CASE constant_expression SEMICOLON
4584 $$ = new GotoCase ((Expression) $3, (Location) $1);
4586 | GOTO DEFAULT SEMICOLON
4588 $$ = new GotoDefault ((Location) $1);
4593 : RETURN opt_expression SEMICOLON
4595 $$ = new Return ((Expression) $2, (Location) $1);
4600 : THROW opt_expression SEMICOLON
4602 $$ = new Throw ((Expression) $2, (Location) $1);
4607 : IDENTIFIER RETURN expression SEMICOLON
4609 LocatedToken lt = (LocatedToken) $1;
4610 string s = lt.Value;
4612 Report.Error (1003, lt.Location, "; expected");
4615 if (RootContext.Version == LanguageVersion.ISO_1){
4616 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4619 if (anonymous_host == null){
4620 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4623 anonymous_host.SetYields ();
4624 $$ = new Yield ((Expression) $3, lt.Location);
4627 | IDENTIFIER RETURN SEMICOLON
4629 Report.Error (1627, (Location) $2, "Expression expected after yield return");
4632 | IDENTIFIER BREAK SEMICOLON
4634 LocatedToken lt = (LocatedToken) $1;
4635 string s = lt.Value;
4637 Report.Error (1003, lt.Location, "; expected");
4640 if (RootContext.Version == LanguageVersion.ISO_1){
4641 Report.FeatureIsNotStandardized (lt.Location, "yield statement");
4644 if (anonymous_host == null){
4645 Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
4648 anonymous_host.SetYields ();
4649 $$ = new YieldBreak (lt.Location);
4660 : TRY block catch_clauses
4664 ArrayList c = (ArrayList)$3;
4665 for (int i = 0; i < c.Count; ++i) {
4666 Catch cc = (Catch) c [i];
4668 if (i != c.Count - 1)
4669 Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
4676 // Now s contains the list of specific catch clauses
4677 // and g contains the general one.
4679 $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
4681 | TRY block opt_catch_clauses FINALLY block
4684 ArrayList s = new ArrayList (4);
4685 ArrayList catch_list = (ArrayList) $3;
4687 if (catch_list != null){
4688 foreach (Catch cc in catch_list) {
4696 $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
4700 Report.Error (1524, (Location) $1, "Expected catch or finally");
4706 : /* empty */ { $$ = null; }
4713 ArrayList l = new ArrayList (4);
4718 | catch_clauses catch_clause
4720 ArrayList l = (ArrayList) $1;
4728 : /* empty */ { $$ = null; }
4733 : CATCH opt_catch_args
4735 Expression type = null;
4738 DictionaryEntry cc = (DictionaryEntry) $2;
4739 type = (Expression) cc.Key;
4740 LocatedToken lt = (LocatedToken) cc.Value;
4743 ArrayList one = new ArrayList (4);
4745 one.Add (new VariableDeclaration (lt, null));
4747 current_block = new Block (current_block);
4748 Block b = declare_local_variables (type, one, lt.Location);
4753 Expression type = null;
4755 Block var_block = null;
4758 DictionaryEntry cc = (DictionaryEntry) $2;
4759 type = (Expression) cc.Key;
4760 LocatedToken lt = (LocatedToken) cc.Value;
4764 while (current_block.Implicit)
4765 current_block = current_block.Parent;
4766 var_block = current_block;
4767 current_block = current_block.Parent;
4771 $$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
4776 : /* empty */ { $$ = null; }
4781 : OPEN_PARENS type opt_identifier CLOSE_PARENS
4783 $$ = new DictionaryEntry ($2, $3);
4791 $$ = new Checked ((Block) $2);
4798 $$ = new Unchecked ((Block) $2);
4805 RootContext.CheckUnsafeOption ((Location) $1);
4807 $$ = new Unsafe ((Block) $3);
4813 type fixed_pointer_declarators
4816 ArrayList list = (ArrayList) $4;
4817 Expression type = (Expression) $3;
4818 Location l = (Location) $1;
4819 int top = list.Count;
4821 Block assign_block = new Block (current_block);
4822 current_block = assign_block;
4824 for (int i = 0; i < top; i++){
4825 Pair p = (Pair) list [i];
4828 v = current_block.AddVariable (type, (string) p.First, l);
4832 v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
4840 Location l = (Location) $1;
4842 Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
4844 current_block.AddStatement (f);
4845 while (current_block.Implicit)
4846 current_block = current_block.Parent;
4848 current_block = current_block.Parent;
4852 fixed_pointer_declarators
4853 : fixed_pointer_declarator {
4854 ArrayList declarators = new ArrayList (4);
4856 declarators.Add ($1);
4859 | fixed_pointer_declarators COMMA fixed_pointer_declarator
4861 ArrayList declarators = (ArrayList) $1;
4863 declarators.Add ($3);
4868 fixed_pointer_declarator
4869 : IDENTIFIER ASSIGN expression
4871 LocatedToken lt = (LocatedToken) $1;
4872 // FIXME: keep location
4873 $$ = new Pair (lt.Value, $3);
4877 Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
4883 : LOCK OPEN_PARENS expression CLOSE_PARENS
4889 $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
4894 : USING OPEN_PARENS resource_acquisition CLOSE_PARENS
4896 Block assign_block = new Block (current_block);
4897 current_block = assign_block;
4899 if ($3 is DictionaryEntry){
4900 DictionaryEntry de = (DictionaryEntry) $3;
4901 Location l = (Location) $1;
4903 Expression type = (Expression) de.Key;
4904 ArrayList var_declarators = (ArrayList) de.Value;
4906 ArrayList vars = new ArrayList (4);
4908 foreach (VariableDeclaration decl in var_declarators){
4910 LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
4913 vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
4915 Expression expr = decl.expression_or_array_initializer;
4917 Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
4920 LocalVariableReference var;
4922 // Get a writable reference to this read-only variable.
4923 var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);
4925 // This is so that it is not a warning on using variables
4928 vars.Add (new DictionaryEntry (var, expr));
4930 // Assign a = new Assign (var, expr, decl.Location);
4931 // assign_block.AddStatement (new StatementExpression (a));
4934 // Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
4935 // It can be referred to as $5 below.
4936 $$ = new DictionaryEntry (type, vars);
4943 Using u = new Using ($5, (Statement) $6, (Location) $1);
4944 current_block.AddStatement (u);
4945 while (current_block.Implicit)
4946 current_block = current_block.Parent;
4948 current_block = current_block.Parent;
4952 resource_acquisition
4953 : local_variable_declaration
4960 // A class used to pass around variable declarations and constants
4962 public class VariableDeclaration {
4963 public string identifier;
4964 public Expression expression_or_array_initializer;
4965 public Location Location;
4966 public Attributes OptAttributes;
4967 public string DocComment;
4969 public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
4971 this.identifier = lt.Value;
4972 if (eoai is ArrayList) {
4973 if (CSharpParser.current_array_type == null)
4974 Report.Error (622, lt.Location,
4975 "Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
4976 this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
4978 this.expression_or_array_initializer = (Expression)eoai;
4980 this.Location = lt.Location;
4981 this.OptAttributes = opt_attrs;
4984 public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
4990 // A class used to hold info about an indexer declarator
4992 public class IndexerDeclaration {
4993 public Expression type;
4994 public MemberName interface_type;
4995 public Parameters param_list;
4996 public Location location;
4998 public IndexerDeclaration (Expression type, MemberName interface_type,
4999 Parameters param_list, Location loc)
5002 this.interface_type = interface_type;
5003 this.param_list = param_list;
5004 this.location = loc;
5009 // We use this when we do not have an object in advance that is an IAnonymousHost
5011 public class SimpleAnonymousHost : IAnonymousHost {
5012 public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
5015 ArrayList anonymous_methods;
5017 public static SimpleAnonymousHost GetSimple () {
5018 Simple.yields = false;
5019 Simple.anonymous_methods = null;
5023 public void SetYields ()
5028 public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
5030 if (anonymous_methods == null)
5031 anonymous_methods = new ArrayList ();
5032 anonymous_methods.Add (anonymous);
5035 public void Propagate (IAnonymousHost real_host)
5038 real_host.SetYields ();
5039 if (anonymous_methods != null) {
5040 foreach (AnonymousMethodExpression ame in anonymous_methods)
5041 real_host.AddAnonymousMethod (ame);
5047 // A class used to hold info about an operator declarator
5049 public class OperatorDeclaration {
5050 public Operator.OpType optype;
5051 public Expression ret_type, arg1type, arg2type;
5052 public string arg1name, arg2name;
5053 public Location location;
5055 public OperatorDeclaration (Operator.OpType op, Expression ret_type,
5056 Expression arg1type, string arg1name,
5057 Expression arg2type, string arg2name, Location location)
5060 this.ret_type = ret_type;
5061 this.arg1type = arg1type;
5062 this.arg1name = arg1name;
5063 this.arg2type = arg2type;
5064 this.arg2name = arg2name;
5065 this.location = location;
5070 void Error_ExpectingTypeName (Expression expr)
5072 if (expr is Invocation){
5073 Report.Error (1002, expr.Location, "Expecting `;'");
5075 Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
5079 void push_current_class (TypeContainer tc, bool is_interface, object partial_token)
5081 if (partial_token != null)
5082 current_container = current_container.AddPartial (tc, is_interface);
5084 current_container = current_container.AddTypeContainer (tc, is_interface);
5088 DeclSpace pop_current_class ()
5090 DeclSpace retval = current_class;
5092 current_class = current_class.Parent;
5093 current_container = current_class.PartialContainer;
5099 // Given the @class_name name, it creates a fully qualified name
5100 // based on the containing declaration space
5103 MakeName (MemberName class_name)
5105 Namespace ns = current_namespace.NS;
5107 if (current_container.Name.Length == 0){
5108 if (ns.Name.Length != 0)
5109 return new MemberName (ns.MemberName, class_name);
5113 return new MemberName (current_container.MemberName, class_name);
5117 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
5119 Block implicit_block;
5120 ArrayList inits = null;
5123 // We use the `Used' property to check whether statements
5124 // have been added to the current block. If so, we need
5125 // to create another block to contain the new declaration
5126 // otherwise, as an optimization, we use the same block to
5127 // add the declaration.
5129 // FIXME: A further optimization is to check if the statements
5130 // that were added were added as part of the initialization
5131 // below. In which case, no other statements have been executed
5132 // and we might be able to reduce the number of blocks for
5133 // situations like this:
5135 // int j = 1; int k = j + 1;
5137 if (current_block.Used)
5138 implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
5140 implicit_block = current_block;
5142 foreach (VariableDeclaration decl in variable_declarators){
5144 if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
5145 if (decl.expression_or_array_initializer != null){
5147 inits = new ArrayList (4);
5154 return implicit_block;
5156 foreach (VariableDeclaration decl in inits){
5158 Expression expr = decl.expression_or_array_initializer;
5160 LocalVariableReference var;
5161 var = new LocalVariableReference (implicit_block, decl.identifier, loc);
5163 assign = new Assign (var, expr, decl.Location);
5165 implicit_block.AddStatement (new StatementExpression (assign));
5168 return implicit_block;
5171 Block declare_local_constants (Expression type, ArrayList declarators)
5173 Block implicit_block;
5175 if (current_block.Used)
5176 implicit_block = new Block (current_block, Block.Flags.Implicit);
5178 implicit_block = current_block;
5180 foreach (VariableDeclaration decl in declarators){
5181 implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
5184 return implicit_block;
5187 void CheckAttributeTarget (string a, Location l)
5191 case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
5195 Report.Error (658, l, "`" + a + "' is an invalid attribute target");
5201 void CheckUnaryOperator (Operator.OpType op, Location l)
5205 case Operator.OpType.LogicalNot:
5206 case Operator.OpType.OnesComplement:
5207 case Operator.OpType.Increment:
5208 case Operator.OpType.Decrement:
5209 case Operator.OpType.True:
5210 case Operator.OpType.False:
5211 case Operator.OpType.Addition:
5212 case Operator.OpType.Subtraction:
5217 Report.Error (1019, l, "Overloadable unary operator expected");
5223 void CheckBinaryOperator (Operator.OpType op, Location l)
5227 case Operator.OpType.Addition:
5228 case Operator.OpType.Subtraction:
5229 case Operator.OpType.Multiply:
5230 case Operator.OpType.Division:
5231 case Operator.OpType.Modulus:
5232 case Operator.OpType.BitwiseAnd:
5233 case Operator.OpType.BitwiseOr:
5234 case Operator.OpType.ExclusiveOr:
5235 case Operator.OpType.LeftShift:
5236 case Operator.OpType.RightShift:
5237 case Operator.OpType.Equality:
5238 case Operator.OpType.Inequality:
5239 case Operator.OpType.GreaterThan:
5240 case Operator.OpType.LessThan:
5241 case Operator.OpType.GreaterThanOrEqual:
5242 case Operator.OpType.LessThanOrEqual:
5246 Report.Error (1020, l, "Overloadable binary operator expected");
5252 void syntax_error (Location l, string msg)
5254 Report.Error (1003, l, "Syntax error, " + msg);
5257 void note (string s)
5259 // Used to put annotations
5264 public Tokenizer Lexer {
5270 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
5272 this.name = file.Name;
5274 current_namespace = new NamespaceEntry (null, file, null);
5275 current_class = current_namespace.SlaveDeclSpace;
5276 current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
5278 lexer = new Tokenizer (reader, file, defines);
5281 public void parse ()
5283 int errors = Report.Errors;
5285 if (yacc_verbose_flag > 1)
5286 yyparse (lexer, new yydebug.yyDebugSimple ());
5289 Tokenizer tokenizer = lexer as Tokenizer;
5290 tokenizer.cleanup ();
5291 } catch (Exception e){
5293 // Removed for production use, use parser verbose to get the output.
5295 // Console.WriteLine (e);
5296 if (Report.Errors == errors)
5297 Report.Error (-25, lexer.Location, "Parsing error");
5298 if (yacc_verbose_flag > 0)
5299 Console.WriteLine (e);
5302 if (RootContext.ToplevelTypes.NamespaceEntry != null)
5303 throw new InternalErrorException ("who set it?");
5306 static void CheckToken (int error, int yyToken, string msg, Location loc)
5308 if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
5309 Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
5311 Report.Error (error, loc, msg);
5314 void CheckIdentifierToken (int yyToken, Location loc)
5316 CheckToken (1041, yyToken, "Identifier expected", loc);
5319 string ConsumeStoredComment ()
5321 string s = tmpComment;
5323 Lexer.doc_state = XmlCommentState.Allowed;
5327 Location GetLocation (object obj)
5329 if (obj is MemberCore)
5330 return ((MemberCore) obj).Location;
5331 if (obj is MemberName)
5332 return ((MemberName) obj).Location;
5333 if (obj is LocatedToken)
5334 return ((LocatedToken) obj).Location;
5335 if (obj is Location)
5336 return (Location) obj;
5337 return lexer.Location;